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