Statistics
| Branch: | Revision:

peerstreamer-src / Test / pschannel_bucket_test.c @ c039490c

History | View | Annotate | Download (2.66 KB)

1
/*
2
 *
3
 *  copyright (c) 2017 luca baldesi
4
 *
5
 */
6

    
7
#include<assert.h>
8
#include<stdlib.h>
9
#include<stdio.h>
10
#include<string.h>
11

    
12
#include"pschannel.h"
13

    
14

    
15
void pschannel_bucket_destroy_test()
16
{
17
        struct pschannel_bucket * pb = NULL;
18

    
19
        pschannel_bucket_destroy(NULL);
20
        pschannel_bucket_destroy(&pb);
21

    
22
        pb = pschannel_bucket_new();
23
        pschannel_bucket_destroy(&pb);
24
        fprintf(stderr,"%s successfully passed!\n",__func__);
25
}
26

    
27
void pschannel_bucket_insert_test()
28
{
29
        struct pschannel_bucket * pb = NULL;
30
        uint8_t res;
31

    
32
        res = pschannel_bucket_insert(NULL, NULL, NULL, NULL, NULL, NULL);
33
        assert(res);
34

    
35
        pb = pschannel_bucket_new();
36
        res = pschannel_bucket_insert(pb, NULL, NULL, NULL, NULL, NULL);
37
        assert(res);
38
        res = pschannel_bucket_insert(pb, NULL, "10.0.0.1", "8000", NULL, NULL);
39
        assert(res);
40

    
41
        res = pschannel_bucket_insert(pb, "channel1", "10.0.0.1", "8000", "1Mbps", "localhost/channel.sdp");
42
        assert(res == 0);
43

    
44
        pschannel_bucket_destroy(&pb);
45
        fprintf(stderr,"%s successfully passed!\n",__func__);
46
}
47

    
48
void pschannel_bucket_iter_test()
49
{
50
        struct pschannel_bucket * pb = NULL;
51
        const struct pschannel * iter = NULL;
52

    
53
        iter = pschannel_bucket_iter(NULL, NULL);
54
        assert(iter == NULL);
55

    
56
        pb = pschannel_bucket_new();
57
        iter = pschannel_bucket_iter(pb, iter);
58
        assert(iter == NULL);
59

    
60
        pschannel_bucket_insert(pb, "channel1", "10.0.0.1", "8000", "1Mbps", "localhost/channel.sdp");
61
        iter = pschannel_bucket_iter(pb, iter);
62
        assert(iter);
63
        iter = pschannel_bucket_iter(pb, iter);
64
        assert(iter == NULL);
65

    
66
        pschannel_bucket_destroy(&pb);
67
        fprintf(stderr,"%s successfully passed!\n",__func__);
68
}
69

    
70
void pschannel_bucket_to_json_test()
71
{
72
        struct pschannel_bucket * pb = NULL;
73
        char * s = NULL;
74

    
75
        s = pschannel_bucket_to_json(pb);
76
        assert(s == NULL);
77

    
78
        pb = pschannel_bucket_new();
79

    
80
        s = pschannel_bucket_to_json(pb);
81
        assert(strcmp(s, "[]") == 0);
82
        free(s);
83

    
84
        pschannel_bucket_insert(pb, "channel1", "10.0.0.1", "8000", "1Mbps", "localhost/channel.sdp");
85
        s = pschannel_bucket_to_json(pb);
86
        assert(strcmp(s, "[{\"name\":\"channel1\",\"ipaddr\":\"10.0.0.1\",\"port\":\"8000\",\"quality\":\"1Mbps\"}]") == 0);
87
        free(s);
88

    
89
        pschannel_bucket_insert(pb, "channel2", "10.0.0.1", "8001", "1Mbps", "localhost/channel.sdp");
90
        s = pschannel_bucket_to_json(pb);
91
        assert(strcmp(s, "[{\"name\":\"channel1\",\"ipaddr\":\"10.0.0.1\",\"port\":\"8000\",\"quality\":\"1Mbps\"},{\"name\":\"channel2\",\"ipaddr\":\"10.0.0.1\",\"port\":\"8001\",\"quality\":\"1Mbps\"}]") == 0);
92
        free(s);
93

    
94
        pschannel_bucket_destroy(&pb);
95
        fprintf(stderr,"%s successfully passed!\n",__func__);
96
}
97

    
98
int main(int argv, char ** argc)
99
{
100
        pschannel_bucket_destroy_test();
101
        pschannel_bucket_insert_test();
102
        pschannel_bucket_iter_test();
103
        pschannel_bucket_to_json_test();
104
        return 0;
105
}