386 CX_TEST_ASSERT(cc.data == 2); |
386 CX_TEST_ASSERT(cc.data == 2); |
387 CX_TEST_ASSERT(cba.data == 2); |
387 CX_TEST_ASSERT(cba.data == 2); |
388 } |
388 } |
389 } |
389 } |
390 |
390 |
|
391 typedef struct test_xml_node { |
|
392 struct test_xml_node *parent; |
|
393 struct test_xml_node *next; |
|
394 struct test_xml_node *prev; |
|
395 struct test_xml_node *children; |
|
396 char const* name; |
|
397 } test_xml_node; |
|
398 |
|
399 CX_TEST(test_tree_iterator_xml) { |
|
400 test_xml_node project = {0}; |
|
401 test_xml_node config = {0}; |
|
402 test_xml_node var1 = {0}; |
|
403 test_xml_node var2 = {0}; |
|
404 test_xml_node var3 = {0}; |
|
405 test_xml_node dependency1 = {0}; |
|
406 test_xml_node dependency1make = {0}; |
|
407 test_xml_node dependency2 = {0}; |
|
408 test_xml_node dependency2lang = {0}; |
|
409 test_xml_node dependency2make = {0}; |
|
410 test_xml_node target = {0}; |
|
411 test_xml_node target_feature = {0}; |
|
412 test_xml_node target_feature_dependencies = {0}; |
|
413 test_xml_node target_dependencies = {0}; |
|
414 |
|
415 project.name = "project"; |
|
416 config.name = "config"; |
|
417 var1.name = "var"; |
|
418 var2.name = "var"; |
|
419 var3.name = "var"; |
|
420 dependency1.name = "dependency"; |
|
421 dependency1make.name = "make"; |
|
422 dependency2.name = "dependency"; |
|
423 dependency2lang.name = "lang"; |
|
424 dependency2make.name = "make"; |
|
425 target.name = "target"; |
|
426 target_feature.name = "feature"; |
|
427 target_dependencies.name = "dependencies"; |
|
428 target_feature_dependencies.name = "dependencies"; |
|
429 |
|
430 cx_tree_link(&project, &target, tree_node_layout); |
|
431 cx_tree_link(&project, &dependency2, tree_node_layout); |
|
432 cx_tree_link(&project, &dependency1, tree_node_layout); |
|
433 cx_tree_link(&project, &config, tree_node_layout); |
|
434 cx_tree_link(&config, &var3, tree_node_layout); |
|
435 cx_tree_link(&config, &var2, tree_node_layout); |
|
436 cx_tree_link(&config, &var1, tree_node_layout); |
|
437 cx_tree_link(&dependency1, &dependency1make, tree_node_layout); |
|
438 cx_tree_link(&dependency2, &dependency2make, tree_node_layout); |
|
439 cx_tree_link(&dependency2, &dependency2lang, tree_node_layout); |
|
440 cx_tree_link(&target, &target_dependencies, tree_node_layout); |
|
441 cx_tree_link(&target, &target_feature, tree_node_layout); |
|
442 cx_tree_link(&target_feature, &target_feature_dependencies, tree_node_layout); |
|
443 |
|
444 char const *expected = |
|
445 "<project><config><var></var><var></var><var></var></config>" |
|
446 "<dependency><make></make></dependency><dependency><lang></lang><make></make></dependency>" |
|
447 "<target><feature><dependencies></dependencies></feature><dependencies></dependencies></target></project>"; |
|
448 char *actual = malloc(512); |
|
449 CX_TEST_DO { |
|
450 CxTreeIterator iter = cx_tree_iterator(&project, true, tree_child_list); |
|
451 size_t i = 0; |
|
452 cx_foreach(test_xml_node*, node, iter) { |
|
453 size_t len = strlen(node->name); |
|
454 actual[i++] = '<'; |
|
455 if (iter.exiting) { |
|
456 actual[i++] = '/'; |
|
457 } |
|
458 memcpy(actual+i, node->name, len); |
|
459 i += len; |
|
460 actual[i++] = '>'; |
|
461 } |
|
462 actual[i] = '\0'; |
|
463 CX_TEST_ASSERT(0 == strcmp(expected, actual)); |
|
464 } |
|
465 free(actual); |
|
466 } |
|
467 |
391 CxTestSuite *cx_test_suite_tree_low_level(void) { |
468 CxTestSuite *cx_test_suite_tree_low_level(void) { |
392 CxTestSuite *suite = cx_test_suite_new("tree (low level)"); |
469 CxTestSuite *suite = cx_test_suite_new("tree (low level)"); |
393 |
470 |
394 cx_test_register(suite, test_tree_link_new_child); |
471 cx_test_register(suite, test_tree_link_new_child); |
395 cx_test_register(suite, test_tree_link_add_child); |
472 cx_test_register(suite, test_tree_link_add_child); |