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