test/sequence_test.cc
author Volker Birk <vb@pep.foundation>
Mon, 29 Aug 2016 10:50:48 +0200
branchkeysync
changeset 1085 9db2d7650ddc
parent 654 0aa96447e38f
child 1086 3de792de7bba
permissions -rw-r--r--
sequences
vb@637
     1
#include <iostream>
vb@637
     2
#include <string>
vb@637
     3
#include <assert.h>
vb@637
     4
#include "pEpEngine.h"
vb@637
     5
vb@637
     6
using namespace std;
vb@637
     7
vb@637
     8
int main() {
vb@637
     9
    cout << "\n*** sequence_test ***\n\n";
vb@637
    10
vb@637
    11
    PEP_SESSION session;
vb@637
    12
    
vb@637
    13
    cout << "calling init()\n";
vb@637
    14
    PEP_STATUS status1 = init(&session);   
vb@637
    15
    assert(status1 == PEP_STATUS_OK);
vb@637
    16
    assert(session);
vb@637
    17
    cout << "init() completed.\n";
vb@637
    18
vb@637
    19
    // sequence test code
vb@637
    20
vb@1085
    21
    int32_t value1 = 0;
vb@1085
    22
    char *name1 = strdup("test");
vb@1085
    23
    assert(name1);
vb@1085
    24
    PEP_STATUS status2 = sequence_value(session, name1, &value1);
vb@637
    25
    assert(status2 == PEP_STATUS_OK);
vb@637
    26
vb@637
    27
    cout << "test sequence: " << value1 << "\n";
vb@637
    28
vb@1085
    29
    int32_t value2 = 0;
vb@1085
    30
    PEP_STATUS status3 = sequence_value(session, name1, &value2);
vb@637
    31
    assert(status3 == PEP_STATUS_OK);
vb@637
    32
vb@637
    33
    cout << "test sequence: " << value2 << "\n";
vb@637
    34
    assert(value2 == value1 + 1);
vb@1085
    35
    free(name1);
vb@1085
    36
vb@1085
    37
    cout << "testing sequence violation\n";
vb@1085
    38
    int32_t value3 = value2 - 1;
vb@1085
    39
    PEP_STATUS status4 = sequence_value(session, name1, &value3);
vb@1085
    40
    assert(status4 == PEP_SEQUENCE_VIOLATED);
vb@1085
    41
vb@1085
    42
    cout << "testing sequence non-violation\n";
vb@1085
    43
    int32_t value4 = value2 + 1;
vb@1085
    44
    PEP_STATUS status5 = sequence_value(session, name1, &value4);
vb@1085
    45
    assert(status5 == PEP_STATUS_OK);
vb@1085
    46
vb@1085
    47
    cout << "testing UUID generation\n";
vb@1085
    48
    int32_t value5 = 0;
vb@1085
    49
    char name2[37] = { 0, };
vb@1085
    50
    PEP_STATUS status6 = sequence_value(session, name2, &value5);
vb@1085
    51
    assert(status6 == PEP_STATUS_OK);
vb@1085
    52
    cout << "UUID created: " << name2 << "\n";
vb@637
    53
vb@637
    54
    cout << "calling release()\n";
vb@637
    55
    release(session);
vb@637
    56
    return 0;
vb@637
    57
}
vb@637
    58