diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2012-12-07 01:56:52 +0100 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2012-12-07 01:56:52 +0100 |
| commit | fba2a11fd51ea53990706430023fae34d8876360 (patch) | |
| tree | 270bedfe580e45f378ac7a6ccc3119d5e21bd66c | |
| parent | 8d7af88e79067b9fd425d71bb7b34c2b4cdea5de (diff) | |
Add selftests for object relations.
| -rw-r--r-- | kconfigtest.py | 65 | ||||
| -rw-r--r-- | tests/Krelation | 34 |
2 files changed, 99 insertions, 0 deletions
diff --git a/kconfigtest.py b/kconfigtest.py index 00d06ce..8f67a32 100644 --- a/kconfigtest.py +++ b/kconfigtest.py @@ -167,6 +167,71 @@ def run_selftests(): assert_equals(c["NOT_DEFINED"].get_def_locations(), []) assert_file_and_locations(kl, [6, 15], c["NOT_DEFINED"].get_ref_locations()) + # + # Object relations + # + + c = kconfiglib.Config("Kconfiglib/tests/Krelation") + + A, B, C, D, E, F, G, H, I = c["A"], c["B"], c["C"], c["D"], c["E"], c["F"],\ + c["G"], c["H"], c["I"] + choice_1, choice_2 = c.get_choices() + assert_true([menu.get_title() for menu in c.get_menus()] == + ["m1", "m2", "m3", "m4"], + "menu ordering is broken") + menu_1, menu_2, menu_3, menu_4 = c.get_menus() + + print "Testing object relations..." + assert_true(A.get_parent() is None, "A should not have a parent") + assert_true(B.get_parent() is choice_1, + "B's parent should be the first choice") + assert_true(E.get_parent() is menu_1, + "E's parent should be the first menu") + assert_true(c["E"].get_parent().get_parent() is None, + "E's grandparent should be None") + assert_true(c["G"].get_parent() is choice_2, + "G's parent should be the second choice") + assert_true(c["G"].get_parent().get_parent() is menu_2, + "G's grandparent should be the second menu") + + # + # Object fetching (same test file) + # + + print "Testing object fetching..." + + assert_equals(c.get_symbol("NON_EXISTENT"), None) + assert_true(c.get_symbol("A") is A, "get_symbol() is broken") + + assert_true(c.get_top_level_items() == + [A, choice_1, menu_1, menu_3, menu_4], + "Wrong items at top level") + assert_true(c.get_symbols(False) == [A, B, C, D, E, F, G, H, I], + "get_symbols() is broken") + + assert_true(choice_1.get_items() == [B, C, D], + "Wrong get_items() items in 'choice'") + # Test Kconfig quirk + assert_true(choice_1.get_actual_items() == [B, D], + "Wrong get_actual_items() items in 'choice'") + + assert_true(menu_1.get_items() == [E, menu_2, I], + "Wrong items in first menu") + assert_true(menu_1.get_symbols() == [E, I], + "Wrong symbols in first menu") + assert_true(menu_1.get_items(True) == [E, menu_2, F, choice_2, G, H, I], + "Wrong recursive items in first menu") + assert_true(menu_1.get_symbols(True) == [E, F, G, H, I], + "Wrong recursive symbols in first menu") + assert_true(menu_2.get_items() == [F, choice_2], + "Wrong items in second menu") + assert_true(menu_2.get_symbols() == [F], + "Wrong symbols in second menu") + assert_true(menu_2.get_items(True) == [F, choice_2, G, H], + "Wrong recursive items in second menu") + assert_true(menu_2.get_symbols(True) == [F, G, H], + "Wrong recursive symbols in second menu") + print def run_compatibility_tests(): diff --git a/tests/Krelation b/tests/Krelation new file mode 100644 index 0000000..057b585 --- /dev/null +++ b/tests/Krelation @@ -0,0 +1,34 @@ +config A + bool + +choice + bool "C" +config B + bool "B" +config C + bool "C" if B +config D + bool "D" +endchoice + +menu "m1" +config E + bool +menu "m2" +config F + bool +choice +config G + bool "g" +config H + bool "h" +endchoice +endmenu +config I + bool +endmenu + +menu "m3" +endmenu +menu "m4" +endmenu |
