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