#include "test_utils.h" UnittestTestResult_t* test_super_method_basic(void) { UNITTEST_BEGIN_TEST("TestSuper", "test_super_method_basic"); RAVA_TEST_RUN(_unittest_result, "class Parent {\n" " int getValue() {\n" " return 10;\n" " }\n" "}\n" "class Child extends Parent {\n" " int getValue() {\n" " return super.getValue() + 5;\n" " }\n" "}\n" "public class Test {\n" " public static int main() {\n" " Child c = new Child();\n" " return c.getValue();\n" " }\n" "}\n", "Test", "main", 15, "super.method() should call parent method"); UNITTEST_END_TEST(); } UnittestTestResult_t* test_super_method_with_args(void) { UNITTEST_BEGIN_TEST("TestSuper", "test_super_method_with_args"); RAVA_TEST_RUN(_unittest_result, "class Parent {\n" " int add(int a, int b) {\n" " return a + b;\n" " }\n" "}\n" "class Child extends Parent {\n" " int add(int a, int b) {\n" " return super.add(a, b) * 2;\n" " }\n" "}\n" "public class Test {\n" " public static int main() {\n" " Child c = new Child();\n" " return c.add(3, 4);\n" " }\n" "}\n", "Test", "main", 14, "super.method(args) should pass arguments to parent"); UNITTEST_END_TEST(); } UnittestTestResult_t* test_super_method_chain(void) { UNITTEST_BEGIN_TEST("TestSuper", "test_super_method_chain"); RAVA_TEST_RUN(_unittest_result, "class GrandParent {\n" " int getValue() {\n" " return 100;\n" " }\n" "}\n" "class Parent extends GrandParent {\n" " int getValue() {\n" " return super.getValue() + 10;\n" " }\n" "}\n" "class Child extends Parent {\n" " int getValue() {\n" " return super.getValue() + 1;\n" " }\n" "}\n" "public class Test {\n" " public static int main() {\n" " Child c = new Child();\n" " return c.getValue();\n" " }\n" "}\n", "Test", "main", 111, "super chain should accumulate values"); UNITTEST_END_TEST(); } int main(int argc, char **argv) { UnittestConfig_t *config = unittest_config_create(); config->verbosity = 2; if (argc > 1 && strcmp(argv[1], "--json") == 0) { config->output_format = UNITTEST_FORMAT_JSON; config->use_colors = false; } UnittestTestSuite_t *suite = unittest_test_suite_create("Super Keyword Tests"); UnittestTestCase_t *tc = unittest_test_case_create("TestSuper"); unittest_test_case_add_result(tc, test_super_method_basic()); unittest_test_case_add_result(tc, test_super_method_with_args()); unittest_test_case_add_result(tc, test_super_method_chain()); unittest_test_suite_add_test_case(suite, tc); unittest_generate_report(suite, config); int failures = suite->total_failed + suite->total_errors; unittest_test_suite_destroy(suite); unittest_config_destroy(config); return failures > 0 ? 1 : 0; }