Statistics
| Branch: | Revision:

peerstreamer-src / Test / pstreamer_manager_test.c @ 3af4c8d7

History | View | Annotate | Download (5.87 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<janus_instance.h>
13
#include"pstreamer.h"
14

    
15

    
16
void pstreamer_manager_destroy_test()
17
{
18
        struct pstreamer_manager * psm = NULL;
19

    
20
        pstreamer_manager_destroy(NULL);
21
        pstreamer_manager_destroy(&psm);
22

    
23
        psm = pstreamer_manager_new(6000, NULL);
24

    
25
        pstreamer_manager_destroy(&psm);
26

    
27
        fprintf(stderr,"%s successfully passed!\n",__func__);
28
}
29

    
30
void pstreamer_manager_create_streamer_test()
31
{
32
        struct pstreamer_manager * psm = NULL;
33
        const struct pstreamer * ps = NULL;
34

    
35
        ps = pstreamer_manager_create_streamer(NULL, NULL, NULL, NULL, NULL, NULL);
36
        assert(ps == NULL);
37

    
38
        psm = pstreamer_manager_new(6000, NULL);
39

    
40
        ps = pstreamer_manager_create_streamer(psm, NULL, NULL, NULL, NULL, NULL);
41
        assert(ps == NULL);
42

    
43
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42", "127.0.0.1", NULL);
44
        assert(ps);
45

    
46
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "24", "127.0.0.1", NULL);
47
        assert(ps);
48

    
49
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42", "127.0.0.1", NULL);
50
        assert(ps == NULL);
51

    
52
        pstreamer_manager_destroy(&psm);
53

    
54
        fprintf(stderr,"%s successfully passed!\n",__func__);
55
}
56

    
57
void pstreamer_to_json_test()
58
{
59
        struct pstreamer_manager * psm = NULL;
60
        const struct pstreamer * ps = NULL;
61
        char * json = NULL;
62

    
63
        json = pstreamer_to_json(NULL);
64
        assert(json == NULL);
65

    
66
        psm = pstreamer_manager_new(6000, NULL);
67
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42", "127.0.0.1", NULL);
68

    
69
        json = pstreamer_to_json(ps);
70
        assert(strcmp(json, "{\"id\":\"42\",\"source_ip\":\"10.0.0.1\",\"source_port\":\"6000\",\"janus_streaming_id\":\"0\"}") == 0);
71
        free(json);
72

    
73
        pstreamer_manager_destroy(&psm);
74
        fprintf(stderr,"%s successfully passed!\n",__func__);
75
}
76

    
77
void pstreamer_manager_destroy_streamer_test()
78
{
79
        struct pstreamer_manager * psm = NULL;
80
        const struct pstreamer * ps = NULL;
81
        uint8_t res;
82

    
83
        res = pstreamer_manager_destroy_streamer(NULL, NULL);
84
        assert(res);
85

    
86
        psm = pstreamer_manager_new(6000, NULL);
87
        res = pstreamer_manager_destroy_streamer(psm, NULL);
88
        assert(res);
89

    
90
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42", "127.0.0.1", NULL);
91
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "24", "127.0.0.1", NULL);
92

    
93
        res = pstreamer_manager_destroy_streamer(psm, ps);
94
        assert(res == 0);
95

    
96
        pstreamer_manager_destroy(&psm);
97

    
98
        fprintf(stderr,"%s successfully passed!\n",__func__);
99
}
100

    
101
void pstreamer_manager_set_streamer_options_test()
102
{
103
        struct pstreamer_manager * psm = NULL;
104
        int8_t res;
105

    
106
        res = pstreamer_manager_set_streamer_options(psm, NULL);
107
        assert(res == -1);
108

    
109
        psm = pstreamer_manager_new(6000, NULL);
110

    
111
        res = pstreamer_manager_set_streamer_options(psm, NULL);
112
        assert(res == -1);
113

    
114
        res = pstreamer_manager_set_streamer_options(psm, "iface=lo");
115
        assert(res == 0);
116

    
117
        pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42", "127.0.0.1", NULL);
118
        pstreamer_manager_destroy(&psm);
119
        fprintf(stderr,"%s successfully passed!\n",__func__);
120
}
121

    
122
void pstreamer_manager_create_source_streamer_test()
123
{
124
        struct pstreamer_manager * psm = NULL;
125
        const struct pstreamer * ps = NULL;
126

    
127
        ps = pstreamer_manager_create_source_streamer(NULL, NULL, NULL, NULL);
128
        assert(ps == NULL);
129

    
130
        psm = pstreamer_manager_new(6000, NULL);
131

    
132
        ps = pstreamer_manager_create_source_streamer(psm, NULL, NULL, NULL);
133
        assert(ps == NULL);
134

    
135
        ps = pstreamer_manager_create_source_streamer(psm, "room1", "127.0.0.1", NULL);
136
        assert(ps);
137

    
138
        ps = pstreamer_manager_create_source_streamer(psm, "room1", "127.0.0.1", NULL);
139
        assert(ps == NULL);
140

    
141
        pstreamer_manager_destroy(&psm);
142
        fprintf(stderr,"%s successfully passed!\n",__func__);
143
}
144

    
145
void pstreamer_is_source_test()
146
{
147
        struct pstreamer_manager * psm = NULL;
148
        const struct pstreamer * ps = NULL;
149

    
150
        psm = pstreamer_manager_new(6000, NULL);
151

    
152
        assert(pstreamer_is_source(NULL) == 0);
153

    
154
        ps = pstreamer_manager_create_source_streamer(psm, "room1", "127.0.0.1", NULL);
155
        assert(ps);
156
        assert(pstreamer_is_source(ps));
157

    
158
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42", "127.0.0.1", NULL);
159
        assert(ps);
160
        assert(pstreamer_is_source(ps) == 0);
161

    
162
        pstreamer_manager_destroy(&psm);
163
        fprintf(stderr,"%s successfully passed!\n",__func__);
164
}
165

    
166
void pstreamer_manager_sources_to_json_test()
167
{
168
        struct pstreamer_manager * psm = NULL;
169
        char * res;
170

    
171
        res = pstreamer_manager_sources_to_json(NULL);
172
        assert(res == NULL);
173

    
174
        psm = pstreamer_manager_new(6000, NULL);
175

    
176
        res = pstreamer_manager_sources_to_json(psm);
177
        assert(res);
178
        assert(strcmp(res,"[]")==0);
179
        free(res);
180

    
181
        pstreamer_manager_create_source_streamer(psm, "room1", "127.0.0.1", NULL);
182
        res = pstreamer_manager_sources_to_json(psm);
183
        assert(res);
184
        assert(strcmp(res,"[{\"id\":\"room1\",\"source_ip\":\"127.0.0.1\",\"source_port\":\"0\",\"janus_streaming_id\":\"0\"}]")==0);
185
        free(res);
186

    
187
        pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42", "127.0.0.1", NULL);
188
        res = pstreamer_manager_sources_to_json(psm);
189
        assert(res);
190
        assert(strcmp(res,"[{\"id\":\"room1\",\"source_ip\":\"127.0.0.1\",\"source_port\":\"0\",\"janus_streaming_id\":\"0\"}]")==0);
191
        free(res);
192

    
193
        pstreamer_manager_create_source_streamer(psm, "room2", "127.0.0.1", NULL);
194
        res = pstreamer_manager_sources_to_json(psm);
195
        assert(res);
196
        assert(strcmp(res,"[{\"id\":\"room1\",\"source_ip\":\"127.0.0.1\",\"source_port\":\"0\",\"janus_streaming_id\":\"0\"},\
197
{\"id\":\"room2\",\"source_ip\":\"127.0.0.1\",\"source_port\":\"0\",\"janus_streaming_id\":\"0\"}]")==0);
198
        free(res);
199

    
200
        pstreamer_manager_destroy(&psm);
201
        fprintf(stderr,"%s successfully passed!\n",__func__);
202
}
203

    
204
int main(int argv, char ** argc)
205
{
206
        pstreamer_manager_destroy_test();
207
        pstreamer_manager_create_streamer_test();
208
        pstreamer_to_json_test();
209
        pstreamer_manager_destroy_streamer_test();
210
        pstreamer_manager_set_streamer_options_test();
211

    
212
        pstreamer_manager_create_source_streamer_test();
213
        pstreamer_is_source_test();
214
        pstreamer_manager_sources_to_json_test();
215
        return 0;
216
}