Revision 3af4c8d7 Test/pstreamer_manager_test.c

View differences:

Test/pstreamer_manager_test.c
9 9
#include<stdio.h>
10 10
#include<string.h>
11 11

  
12
#include<janus_instance.h>
12 13
#include"pstreamer.h"
13 14

  
14 15

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

  
68 69
	json = pstreamer_to_json(ps);
69
	fprintf(stderr, "[DEBUG] %s\n", json);
70 70
	assert(strcmp(json, "{\"id\":\"42\",\"source_ip\":\"10.0.0.1\",\"source_port\":\"6000\",\"janus_streaming_id\":\"0\"}") == 0);
71 71
	free(json);
72 72

  
......
119 119
	fprintf(stderr,"%s successfully passed!\n",__func__);
120 120
}
121 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

  
122 204
int main(int argv, char ** argc)
123 205
{
124 206
	pstreamer_manager_destroy_test();
......
126 208
	pstreamer_to_json_test();
127 209
	pstreamer_manager_destroy_streamer_test();
128 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();
129 215
	return 0;
130 216
}

Also available in: Unified diff