test/blacklist_test.cc
author Lars Rohwedder <roker@pep-project.org>
Wed, 06 Apr 2016 16:46:06 +0200
changeset 526 b8b302ec9330
parent 494 ddf4130d00a0
child 1275 39dfd55d21ee
permissions -rw-r--r--
strcmp() is in the C++ header <cstring>
     1 #include <iostream>
     2 #include <string>
     3 #include <cstring> // for strcmp()
     4 #include <assert.h>
     5 #include "blacklist.h"
     6 
     7 using namespace std;
     8 
     9 int main() {
    10     cout << "\n*** blacklist_test ***\n\n";
    11 
    12     PEP_SESSION session;
    13     
    14     cout << "calling init()\n";
    15     PEP_STATUS status1 = init(&session);   
    16     assert(status1 == PEP_STATUS_OK);
    17     assert(session);
    18     cout << "init() completed.\n";
    19 
    20     // blacklist test code
    21 
    22     cout << "adding 23 to blacklist\n";
    23     PEP_STATUS status2 = blacklist_add(session, "23");
    24     assert(status2 == PEP_STATUS_OK);
    25     cout << "added.\n";
    26 
    27     bool listed;
    28     PEP_STATUS status3 = blacklist_is_listed(session, "23", &listed);
    29     assert(status3 == PEP_STATUS_OK);
    30     assert(listed);
    31     cout << "23 is listed.\n";
    32 
    33     stringlist_t *blacklist;
    34     PEP_STATUS status6 = blacklist_retrieve(session, &blacklist);
    35     assert(status6 == PEP_STATUS_OK);
    36     assert(blacklist);
    37 
    38     bool in23 = false;
    39     cout << "the blacklist contains now: ";
    40     for (stringlist_t *bl = blacklist; bl && bl->value; bl = bl->next) {
    41         cout << bl->value << ", ";
    42         if (std::strcmp(bl->value, "23") == 0)
    43             in23 = true;
    44     }
    45     cout << "END\n";
    46     assert(in23);
    47     free_stringlist(blacklist);
    48 
    49     cout << "deleting 23 from blacklist\n";
    50     PEP_STATUS status4 = blacklist_delete(session, "23");
    51     assert(status4 == PEP_STATUS_OK);
    52     cout << "deleted.\n";
    53     
    54     PEP_STATUS status5 = blacklist_is_listed(session, "23", &listed);
    55     assert(status5 == PEP_STATUS_OK);
    56     assert(!listed);
    57     cout << "23 is not listed any more.\n";
    58 
    59     cout << "calling release()\n";
    60     release(session);
    61     return 0;
    62 }
    63