test/sequence_test.cc
author Krista Grothoff <krista@pep-project.org>
Tue, 04 Oct 2016 11:30:55 +0200
branchkeysync
changeset 1239 641f4e51e0fb
parent 1202 0d89f70f9e73
child 1513 e7f7e42385b5
permissions -rw-r--r--
ENGINE-102: test used name1 directly after freeing it causing the crash.
vb@637
     1
#include <iostream>
vb@637
     2
#include <string>
roker@1202
     3
#include <cstring> // for std::strdup()
vb@637
     4
#include <assert.h>
vb@637
     5
#include "pEpEngine.h"
vb@637
     6
vb@637
     7
using namespace std;
vb@637
     8
vb@637
     9
int main() {
vb@637
    10
    cout << "\n*** sequence_test ***\n\n";
vb@637
    11
vb@637
    12
    PEP_SESSION session;
vb@637
    13
    
vb@637
    14
    cout << "calling init()\n";
vb@637
    15
    PEP_STATUS status1 = init(&session);   
vb@637
    16
    assert(status1 == PEP_STATUS_OK);
vb@637
    17
    assert(session);
vb@637
    18
    cout << "init() completed.\n";
vb@637
    19
vb@637
    20
    // sequence test code
vb@637
    21
vb@1085
    22
    int32_t value1 = 0;
vb@1085
    23
    char *name1 = strdup("test");
vb@1085
    24
    assert(name1);
vb@1085
    25
    PEP_STATUS status2 = sequence_value(session, name1, &value1);
vb@637
    26
    assert(status2 == PEP_STATUS_OK);
vb@637
    27
vb@637
    28
    cout << "test sequence: " << value1 << "\n";
vb@637
    29
vb@1085
    30
    int32_t value2 = 0;
vb@1085
    31
    PEP_STATUS status3 = sequence_value(session, name1, &value2);
vb@637
    32
    assert(status3 == PEP_STATUS_OK);
vb@637
    33
vb@637
    34
    cout << "test sequence: " << value2 << "\n";
vb@637
    35
    assert(value2 == value1 + 1);
krista@1239
    36
//    free(name1);
vb@1085
    37
vb@1085
    38
    cout << "testing sequence violation\n";
vb@1085
    39
    int32_t value3 = value2 - 1;
vb@1085
    40
    PEP_STATUS status4 = sequence_value(session, name1, &value3);
vb@1085
    41
    assert(status4 == PEP_SEQUENCE_VIOLATED);
vb@1085
    42
vb@1085
    43
    cout << "testing sequence non-violation\n";
vb@1085
    44
    int32_t value4 = value2 + 1;
vb@1085
    45
    PEP_STATUS status5 = sequence_value(session, name1, &value4);
vb@1085
    46
    assert(status5 == PEP_STATUS_OK);
vb@1085
    47
vb@1085
    48
    cout << "testing UUID generation\n";
vb@1085
    49
    int32_t value5 = 0;
vb@1085
    50
    char name2[37] = { 0, };
vb@1085
    51
    PEP_STATUS status6 = sequence_value(session, name2, &value5);
vb@1086
    52
    assert(status6 == PEP_OWN_SEQUENCE);
vb@1085
    53
    cout << "UUID created: " << name2 << "\n";
vb@637
    54
vb@1088
    55
    cout << "set sequence value\n";
vb@1088
    56
    int32_t value6 = value2 + 10;
vb@1088
    57
    PEP_STATUS status7 = sequence_value(session, name1, &value6);
vb@1088
    58
    assert(status7 == PEP_STATUS_OK);
vb@1088
    59
    cout << "value set to " << value6 << "\n";
vb@1088
    60
vb@637
    61
    cout << "calling release()\n";
vb@637
    62
    release(session);
vb@637
    63
    return 0;
vb@637
    64
}
vb@637
    65