Statistics
| Branch: | Revision:

pstreamer / test / transaction_test.c @ ffebdf87

History | View | Annotate | Download (1.21 KB)

1
#include<malloc.h>
2
#include<assert.h>
3
#include<transaction.h>
4

    
5
void transaction_create_test()
6
{
7
        struct service_times_element * head = NULL;
8
        struct nodeID * id;
9
        uint16_t tid;
10

    
11
        tid = transaction_create(NULL, NULL);
12
        assert(tid == 0);
13

    
14
        tid = transaction_create(&head, NULL);
15
        assert(tid == 0);
16

    
17
        id = create_node("127.0.0.1", 6000);
18
        tid = transaction_create(&head, id);
19
        assert(tid == 1);
20

    
21
        tid = transaction_create(&head, id);
22
        assert(tid == 2);
23

    
24
        transaction_destroy(&head);
25
        assert(head == NULL);
26
        nodeid_free(id);
27
        fprintf(stderr,"%s successfully passed!\n",__func__);
28
}
29

    
30
void transaction_reg_accept_test()
31
{
32
        struct service_times_element * head = NULL;
33
        struct nodeID * id = NULL;
34
        uint16_t tid = 1;
35
        bool res;
36

    
37
        res = transaction_reg_accept(head, 0, id);
38
        assert(!res);
39

    
40
        res = transaction_reg_accept(head, tid, id);
41
        assert(!res);
42

    
43
        id = create_node("127.0.0.1", 6000);
44
        tid = transaction_create(&head, id);
45

    
46
        res = transaction_reg_accept(head, tid, id);
47
        assert(res);
48

    
49
        res = transaction_reg_accept(head, tid+1, id);
50
        assert(!res);
51

    
52
        nodeid_free(id);
53
        transaction_destroy(&head);
54
        fprintf(stderr,"%s successfully passed!\n",__func__);
55
}
56

    
57
int main()
58
{
59
        transaction_create_test();
60
        transaction_reg_accept_test();
61
        return 0;
62
}