正在显示
2 个修改的文件
包含
242 行增加
和
0 行删除
@@ -26,6 +26,32 @@ using namespace std; | @@ -26,6 +26,32 @@ using namespace std; | ||
26 | 26 | ||
27 | #include <srs_app_config.hpp> | 27 | #include <srs_app_config.hpp> |
28 | #include <srs_kernel_consts.hpp> | 28 | #include <srs_kernel_consts.hpp> |
29 | +#include <srs_kernel_error.hpp> | ||
30 | + | ||
31 | +MockSrsConfigBuffer::MockSrsConfigBuffer(string buf) | ||
32 | +{ | ||
33 | + // read all. | ||
34 | + int filesize = (int)buf.length(); | ||
35 | + | ||
36 | + if (filesize <= 0) { | ||
37 | + return; | ||
38 | + } | ||
39 | + | ||
40 | + // create buffer | ||
41 | + pos = last = start = new char[filesize]; | ||
42 | + end = start + filesize; | ||
43 | + | ||
44 | + memcpy(start, buf.data(), filesize); | ||
45 | +} | ||
46 | + | ||
47 | +MockSrsConfigBuffer::~MockSrsConfigBuffer() | ||
48 | +{ | ||
49 | +} | ||
50 | + | ||
51 | +int MockSrsConfigBuffer::fullfill(const char* /*filename*/) | ||
52 | +{ | ||
53 | + return ERROR_SUCCESS; | ||
54 | +} | ||
29 | 55 | ||
30 | VOID TEST(ConfigTest, CheckMacros) | 56 | VOID TEST(ConfigTest, CheckMacros) |
31 | { | 57 | { |
@@ -159,3 +185,208 @@ VOID TEST(ConfigTest, CheckMacros) | @@ -159,3 +185,208 @@ VOID TEST(ConfigTest, CheckMacros) | ||
159 | EXPECT_TRUE(false); | 185 | EXPECT_TRUE(false); |
160 | #endif | 186 | #endif |
161 | } | 187 | } |
188 | + | ||
189 | +VOID TEST(ConfigDirectiveTest, ParseEmpty) | ||
190 | +{ | ||
191 | + MockSrsConfigBuffer buf(""); | ||
192 | + SrsConfDirective conf; | ||
193 | + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); | ||
194 | + EXPECT_EQ(0, (int)conf.name.length()); | ||
195 | + EXPECT_EQ(0, (int)conf.args.size()); | ||
196 | + EXPECT_EQ(0, (int)conf.directives.size()); | ||
197 | +} | ||
198 | + | ||
199 | +VOID TEST(ConfigDirectiveTest, ParseNameOnly) | ||
200 | +{ | ||
201 | + MockSrsConfigBuffer buf("winlin;"); | ||
202 | + SrsConfDirective conf; | ||
203 | + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); | ||
204 | + EXPECT_EQ(0, (int)conf.name.length()); | ||
205 | + EXPECT_EQ(0, (int)conf.args.size()); | ||
206 | + EXPECT_EQ(1, (int)conf.directives.size()); | ||
207 | + | ||
208 | + SrsConfDirective& dir = *conf.directives.at(0); | ||
209 | + EXPECT_STREQ("winlin", dir.name.c_str()); | ||
210 | + EXPECT_EQ(0, (int)dir.args.size()); | ||
211 | + EXPECT_EQ(0, (int)dir.directives.size()); | ||
212 | +} | ||
213 | + | ||
214 | +VOID TEST(ConfigDirectiveTest, ParseNameArg0Only) | ||
215 | +{ | ||
216 | + MockSrsConfigBuffer buf("winlin arg0;"); | ||
217 | + SrsConfDirective conf; | ||
218 | + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); | ||
219 | + EXPECT_EQ(0, (int)conf.name.length()); | ||
220 | + EXPECT_EQ(0, (int)conf.args.size()); | ||
221 | + EXPECT_EQ(1, (int)conf.directives.size()); | ||
222 | + | ||
223 | + SrsConfDirective& dir = *conf.directives.at(0); | ||
224 | + EXPECT_STREQ("winlin", dir.name.c_str()); | ||
225 | + EXPECT_EQ(1, (int)dir.args.size()); | ||
226 | + EXPECT_STREQ("arg0", dir.arg0().c_str()); | ||
227 | + EXPECT_EQ(0, (int)dir.directives.size()); | ||
228 | +} | ||
229 | + | ||
230 | +VOID TEST(ConfigDirectiveTest, ParseNameArg1Only) | ||
231 | +{ | ||
232 | + MockSrsConfigBuffer buf("winlin arg0 arg1;"); | ||
233 | + SrsConfDirective conf; | ||
234 | + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); | ||
235 | + EXPECT_EQ(0, (int)conf.name.length()); | ||
236 | + EXPECT_EQ(0, (int)conf.args.size()); | ||
237 | + EXPECT_EQ(1, (int)conf.directives.size()); | ||
238 | + | ||
239 | + SrsConfDirective& dir = *conf.directives.at(0); | ||
240 | + EXPECT_STREQ("winlin", dir.name.c_str()); | ||
241 | + EXPECT_EQ(2, (int)dir.args.size()); | ||
242 | + EXPECT_STREQ("arg0", dir.arg0().c_str()); | ||
243 | + EXPECT_STREQ("arg1", dir.arg1().c_str()); | ||
244 | + EXPECT_EQ(0, (int)dir.directives.size()); | ||
245 | +} | ||
246 | + | ||
247 | +VOID TEST(ConfigDirectiveTest, ParseNameArg2Only) | ||
248 | +{ | ||
249 | + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2;"); | ||
250 | + SrsConfDirective conf; | ||
251 | + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); | ||
252 | + EXPECT_EQ(0, (int)conf.name.length()); | ||
253 | + EXPECT_EQ(0, (int)conf.args.size()); | ||
254 | + EXPECT_EQ(1, (int)conf.directives.size()); | ||
255 | + | ||
256 | + SrsConfDirective& dir = *conf.directives.at(0); | ||
257 | + EXPECT_STREQ("winlin", dir.name.c_str()); | ||
258 | + EXPECT_EQ(3, (int)dir.args.size()); | ||
259 | + EXPECT_STREQ("arg0", dir.arg0().c_str()); | ||
260 | + EXPECT_STREQ("arg1", dir.arg1().c_str()); | ||
261 | + EXPECT_STREQ("arg2", dir.arg2().c_str()); | ||
262 | + EXPECT_EQ(0, (int)dir.directives.size()); | ||
263 | +} | ||
264 | + | ||
265 | +VOID TEST(ConfigDirectiveTest, ParseNameArg2Dir0) | ||
266 | +{ | ||
267 | + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2 {dir0;}"); | ||
268 | + SrsConfDirective conf; | ||
269 | + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); | ||
270 | + EXPECT_EQ(0, (int)conf.name.length()); | ||
271 | + EXPECT_EQ(0, (int)conf.args.size()); | ||
272 | + EXPECT_EQ(1, (int)conf.directives.size()); | ||
273 | + | ||
274 | + SrsConfDirective& dir = *conf.directives.at(0); | ||
275 | + EXPECT_STREQ("winlin", dir.name.c_str()); | ||
276 | + EXPECT_EQ(3, (int)dir.args.size()); | ||
277 | + EXPECT_STREQ("arg0", dir.arg0().c_str()); | ||
278 | + EXPECT_STREQ("arg1", dir.arg1().c_str()); | ||
279 | + EXPECT_STREQ("arg2", dir.arg2().c_str()); | ||
280 | + EXPECT_EQ(1, (int)dir.directives.size()); | ||
281 | + | ||
282 | + SrsConfDirective& dir0 = *dir.directives.at(0); | ||
283 | + EXPECT_STREQ("dir0", dir0.name.c_str()); | ||
284 | + EXPECT_EQ(0, (int)dir0.args.size()); | ||
285 | + EXPECT_EQ(0, (int)dir0.directives.size()); | ||
286 | +} | ||
287 | + | ||
288 | +VOID TEST(ConfigDirectiveTest, ParseNameArg2Dir0NoEmpty) | ||
289 | +{ | ||
290 | + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2{dir0;}"); | ||
291 | + SrsConfDirective conf; | ||
292 | + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); | ||
293 | + EXPECT_EQ(0, (int)conf.name.length()); | ||
294 | + EXPECT_EQ(0, (int)conf.args.size()); | ||
295 | + EXPECT_EQ(1, (int)conf.directives.size()); | ||
296 | + | ||
297 | + SrsConfDirective& dir = *conf.directives.at(0); | ||
298 | + EXPECT_STREQ("winlin", dir.name.c_str()); | ||
299 | + EXPECT_EQ(3, (int)dir.args.size()); | ||
300 | + EXPECT_STREQ("arg0", dir.arg0().c_str()); | ||
301 | + EXPECT_STREQ("arg1", dir.arg1().c_str()); | ||
302 | + EXPECT_STREQ("arg2", dir.arg2().c_str()); | ||
303 | + EXPECT_EQ(1, (int)dir.directives.size()); | ||
304 | + | ||
305 | + SrsConfDirective& dir0 = *dir.directives.at(0); | ||
306 | + EXPECT_STREQ("dir0", dir0.name.c_str()); | ||
307 | + EXPECT_EQ(0, (int)dir0.args.size()); | ||
308 | + EXPECT_EQ(0, (int)dir0.directives.size()); | ||
309 | +} | ||
310 | + | ||
311 | +VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0) | ||
312 | +{ | ||
313 | + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2 {dir0 dir_arg0;}"); | ||
314 | + SrsConfDirective conf; | ||
315 | + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); | ||
316 | + EXPECT_EQ(0, (int)conf.name.length()); | ||
317 | + EXPECT_EQ(0, (int)conf.args.size()); | ||
318 | + EXPECT_EQ(1, (int)conf.directives.size()); | ||
319 | + | ||
320 | + SrsConfDirective& dir = *conf.directives.at(0); | ||
321 | + EXPECT_STREQ("winlin", dir.name.c_str()); | ||
322 | + EXPECT_EQ(3, (int)dir.args.size()); | ||
323 | + EXPECT_STREQ("arg0", dir.arg0().c_str()); | ||
324 | + EXPECT_STREQ("arg1", dir.arg1().c_str()); | ||
325 | + EXPECT_STREQ("arg2", dir.arg2().c_str()); | ||
326 | + EXPECT_EQ(1, (int)dir.directives.size()); | ||
327 | + | ||
328 | + SrsConfDirective& dir0 = *dir.directives.at(0); | ||
329 | + EXPECT_STREQ("dir0", dir0.name.c_str()); | ||
330 | + EXPECT_EQ(1, (int)dir0.args.size()); | ||
331 | + EXPECT_STREQ("dir_arg0", dir0.arg0().c_str()); | ||
332 | + EXPECT_EQ(0, (int)dir0.directives.size()); | ||
333 | +} | ||
334 | + | ||
335 | +VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0_Dir0) | ||
336 | +{ | ||
337 | + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2 {dir0 dir_arg0 {ddir0;}}"); | ||
338 | + SrsConfDirective conf; | ||
339 | + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); | ||
340 | + EXPECT_EQ(0, (int)conf.name.length()); | ||
341 | + EXPECT_EQ(0, (int)conf.args.size()); | ||
342 | + EXPECT_EQ(1, (int)conf.directives.size()); | ||
343 | + | ||
344 | + SrsConfDirective& dir = *conf.directives.at(0); | ||
345 | + EXPECT_STREQ("winlin", dir.name.c_str()); | ||
346 | + EXPECT_EQ(3, (int)dir.args.size()); | ||
347 | + EXPECT_STREQ("arg0", dir.arg0().c_str()); | ||
348 | + EXPECT_STREQ("arg1", dir.arg1().c_str()); | ||
349 | + EXPECT_STREQ("arg2", dir.arg2().c_str()); | ||
350 | + EXPECT_EQ(1, (int)dir.directives.size()); | ||
351 | + | ||
352 | + SrsConfDirective& dir0 = *dir.directives.at(0); | ||
353 | + EXPECT_STREQ("dir0", dir0.name.c_str()); | ||
354 | + EXPECT_EQ(1, (int)dir0.args.size()); | ||
355 | + EXPECT_STREQ("dir_arg0", dir0.arg0().c_str()); | ||
356 | + EXPECT_EQ(1, (int)dir0.directives.size()); | ||
357 | + | ||
358 | + SrsConfDirective& ddir0 = *dir0.directives.at(0); | ||
359 | + EXPECT_STREQ("ddir0", ddir0.name.c_str()); | ||
360 | + EXPECT_EQ(0, (int)ddir0.args.size()); | ||
361 | + EXPECT_EQ(0, (int)ddir0.directives.size()); | ||
362 | +} | ||
363 | + | ||
364 | +VOID TEST(ConfigDirectiveTest, ParseNameArg2_Dir0Arg0_Dir0Arg0) | ||
365 | +{ | ||
366 | + MockSrsConfigBuffer buf("winlin arg0 arg1 arg2 {dir0 dir_arg0 {ddir0 ddir_arg0;}}"); | ||
367 | + SrsConfDirective conf; | ||
368 | + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(&buf)); | ||
369 | + EXPECT_EQ(0, (int)conf.name.length()); | ||
370 | + EXPECT_EQ(0, (int)conf.args.size()); | ||
371 | + EXPECT_EQ(1, (int)conf.directives.size()); | ||
372 | + | ||
373 | + SrsConfDirective& dir = *conf.directives.at(0); | ||
374 | + EXPECT_STREQ("winlin", dir.name.c_str()); | ||
375 | + EXPECT_EQ(3, (int)dir.args.size()); | ||
376 | + EXPECT_STREQ("arg0", dir.arg0().c_str()); | ||
377 | + EXPECT_STREQ("arg1", dir.arg1().c_str()); | ||
378 | + EXPECT_STREQ("arg2", dir.arg2().c_str()); | ||
379 | + EXPECT_EQ(1, (int)dir.directives.size()); | ||
380 | + | ||
381 | + SrsConfDirective& dir0 = *dir.directives.at(0); | ||
382 | + EXPECT_STREQ("dir0", dir0.name.c_str()); | ||
383 | + EXPECT_EQ(1, (int)dir0.args.size()); | ||
384 | + EXPECT_STREQ("dir_arg0", dir0.arg0().c_str()); | ||
385 | + EXPECT_EQ(1, (int)dir0.directives.size()); | ||
386 | + | ||
387 | + SrsConfDirective& ddir0 = *dir0.directives.at(0); | ||
388 | + EXPECT_STREQ("ddir0", ddir0.name.c_str()); | ||
389 | + EXPECT_EQ(1, (int)ddir0.args.size()); | ||
390 | + EXPECT_STREQ("ddir_arg0", ddir0.arg0().c_str()); | ||
391 | + EXPECT_EQ(0, (int)ddir0.directives.size()); | ||
392 | +} |
@@ -31,4 +31,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,4 +31,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
31 | 31 | ||
32 | #include <string> | 32 | #include <string> |
33 | 33 | ||
34 | +#include <srs_app_config.hpp> | ||
35 | + | ||
36 | +class MockSrsConfigBuffer : public _srs_internal::SrsConfigBuffer | ||
37 | +{ | ||
38 | +public: | ||
39 | + MockSrsConfigBuffer(std::string buf); | ||
40 | + virtual ~MockSrsConfigBuffer(); | ||
41 | +public: | ||
42 | + virtual int fullfill(const char* filename); | ||
43 | +}; | ||
44 | + | ||
34 | #endif | 45 | #endif |
-
请 注册 或 登录 后发表评论