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