test/sequence_test.cc
author Krista Bennett <krista@pep-project.org>
Fri, 01 Jun 2018 10:30:21 +0200
branchENGINE-217
changeset 2732 2d177ec3804b
parent 1602 904da6719597
permissions -rw-r--r--
close branch
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include <iostream>
     5 #include <string>
     6 #include <cstring> // for std::strdup()
     7 #include <assert.h>
     8 #include "pEpEngine.h"
     9 
    10 using namespace std;
    11 
    12 int main() {
    13     cout << "\n*** sequence_test ***\n\n";
    14 
    15     PEP_SESSION session;
    16     
    17     cout << "calling init()\n";
    18     PEP_STATUS status1 = init(&session);   
    19     assert(status1 == PEP_STATUS_OK);
    20     assert(session);
    21     cout << "init() completed.\n";
    22 
    23     // sequence test code
    24 
    25     int32_t value1 = 0;
    26     char *name1 = strdup("test");
    27     assert(name1);
    28     PEP_STATUS status2 = sequence_value(session, name1, &value1);
    29     assert(status2 == PEP_STATUS_OK);
    30 
    31     cout << "test sequence: " << value1 << "\n";
    32 
    33     int32_t value2 = 0;
    34     PEP_STATUS status3 = sequence_value(session, name1, &value2);
    35     assert(status3 == PEP_STATUS_OK);
    36 
    37     cout << "test sequence: " << value2 << "\n";
    38     assert(value2 == value1 + 1);
    39 //    free(name1);
    40 
    41     cout << "testing sequence violation\n";
    42     int32_t value3 = value2;
    43     PEP_STATUS status4 = sequence_value(session, name1, &value3);
    44     assert(status4 == PEP_SEQUENCE_VIOLATED);
    45 
    46     cout << "testing sequence non-violation\n";
    47     int32_t value4 = value2 + 1;
    48     PEP_STATUS status5 = sequence_value(session, name1, &value4);
    49     assert(status5 == PEP_STATUS_OK);
    50 
    51     cout << "testing UUID generation\n";
    52     int32_t value5 = 0;
    53     char name2[37] = { 0, };
    54     PEP_STATUS status6 = sequence_value(session, name2, &value5);
    55     assert(status6 == PEP_OWN_SEQUENCE);
    56     cout << "UUID created: " << name2 << "\n";
    57 
    58     cout << "set sequence value\n";
    59     int32_t value6 = value2 + 10;
    60     PEP_STATUS status7 = sequence_value(session, name1, &value6);
    61     assert(status7 == PEP_STATUS_OK);
    62     cout << "value set to " << value6 << "\n";
    63 
    64     cout << "calling release()\n";
    65     release(session);
    66     return 0;
    67 }
    68