test/sequence_test.cc
author Roker <roker@pep-project.org>
Tue, 27 Sep 2016 21:46:03 +0200
branchkeysync
changeset 1202 0d89f70f9e73
parent 1088 f90f74a12d49
child 1239 641f4e51e0fb
permissions -rw-r--r--
add #include <cstring> for strdup()
     1 #include <iostream>
     2 #include <string>
     3 #include <cstring> // for std::strdup()
     4 #include <assert.h>
     5 #include "pEpEngine.h"
     6 
     7 using namespace std;
     8 
     9 int main() {
    10     cout << "\n*** sequence_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     // sequence test code
    21 
    22     int32_t value1 = 0;
    23     char *name1 = strdup("test");
    24     assert(name1);
    25     PEP_STATUS status2 = sequence_value(session, name1, &value1);
    26     assert(status2 == PEP_STATUS_OK);
    27 
    28     cout << "test sequence: " << value1 << "\n";
    29 
    30     int32_t value2 = 0;
    31     PEP_STATUS status3 = sequence_value(session, name1, &value2);
    32     assert(status3 == PEP_STATUS_OK);
    33 
    34     cout << "test sequence: " << value2 << "\n";
    35     assert(value2 == value1 + 1);
    36     free(name1);
    37 
    38     cout << "testing sequence violation\n";
    39     int32_t value3 = value2 - 1;
    40     PEP_STATUS status4 = sequence_value(session, name1, &value3);
    41     assert(status4 == PEP_SEQUENCE_VIOLATED);
    42 
    43     cout << "testing sequence non-violation\n";
    44     int32_t value4 = value2 + 1;
    45     PEP_STATUS status5 = sequence_value(session, name1, &value4);
    46     assert(status5 == PEP_STATUS_OK);
    47 
    48     cout << "testing UUID generation\n";
    49     int32_t value5 = 0;
    50     char name2[37] = { 0, };
    51     PEP_STATUS status6 = sequence_value(session, name2, &value5);
    52     assert(status6 == PEP_OWN_SEQUENCE);
    53     cout << "UUID created: " << name2 << "\n";
    54 
    55     cout << "set sequence value\n";
    56     int32_t value6 = value2 + 10;
    57     PEP_STATUS status7 = sequence_value(session, name1, &value6);
    58     assert(status7 == PEP_STATUS_OK);
    59     cout << "value set to " << value6 << "\n";
    60 
    61     cout << "calling release()\n";
    62     release(session);
    63     return 0;
    64 }
    65