#include "test_utils.h" UnittestTestResult_t* test_interface_with_implementing_class(void) { UNITTEST_BEGIN_TEST("TestInterfaces", "test_interface_with_implementing_class"); RAVA_TEST_RUN(_unittest_result, "interface Addable {\n" " int add(int a, int b);\n" "}\n" "class Calculator implements Addable {\n" " int add(int a, int b) {\n" " return a + b;\n" " }\n" "}\n" "public class Test {\n" " public static int main() {\n" " Calculator calc = new Calculator();\n" " return calc.add(10, 20);\n" " }\n" "}\n", "Test", "main", 30, "interface with implementing class should return 30"); UNITTEST_END_TEST(); } UnittestTestResult_t* test_multiple_interfaces(void) { UNITTEST_BEGIN_TEST("TestInterfaces", "test_multiple_interfaces"); RAVA_TEST_RUN(_unittest_result, "interface Addable {\n" " int add(int a, int b);\n" "}\n" "interface Subtractable {\n" " int subtract(int a, int b);\n" "}\n" "class Calculator implements Addable, Subtractable {\n" " int add(int a, int b) {\n" " return a + b;\n" " }\n" " int subtract(int a, int b) {\n" " return a - b;\n" " }\n" "}\n" "public class Test {\n" " public static int main() {\n" " Calculator calc = new Calculator();\n" " return calc.add(100, 50) - calc.subtract(30, 10);\n" " }\n" "}\n", "Test", "main", 130, "class implements multiple interfaces should return 130"); UNITTEST_END_TEST(); } UnittestTestResult_t* test_extends_and_implements(void) { UNITTEST_BEGIN_TEST("TestInterfaces", "test_extends_and_implements"); RAVA_TEST_RUN(_unittest_result, "interface Printable {\n" " int getValue();\n" "}\n" "class Base {\n" " int baseValue;\n" " Base() {\n" " this.baseValue = 100;\n" " }\n" "}\n" "class Derived extends Base implements Printable {\n" " int getValue() {\n" " return this.baseValue + 50;\n" " }\n" "}\n" "public class Test {\n" " public static int main() {\n" " Derived d = new Derived();\n" " return d.getValue();\n" " }\n" "}\n", "Test", "main", 150, "class extends and implements should return 150"); UNITTEST_END_TEST(); } UnittestTestResult_t* test_empty_interface(void) { UNITTEST_BEGIN_TEST("TestInterfaces", "test_empty_interface"); RAVA_TEST_RUN(_unittest_result, "interface Empty {\n" "}\n" "class MyClass implements Empty {\n" " int getValue() {\n" " return 42;\n" " }\n" "}\n" "public class Test {\n" " public static int main() {\n" " MyClass obj = new MyClass();\n" " return obj.getValue();\n" " }\n" "}\n", "Test", "main", 42, "empty interface should return 42"); 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("Interface Tests"); UnittestTestCase_t *tc = unittest_test_case_create("TestInterfaces"); unittest_test_case_add_result(tc, test_interface_with_implementing_class()); unittest_test_case_add_result(tc, test_multiple_interfaces()); unittest_test_case_add_result(tc, test_extends_and_implements()); unittest_test_case_add_result(tc, test_empty_interface()); 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; }