|
#include "test_utils.h"
|
|
|
|
UnittestTestResult_t* test_instanceof_true(void) {
|
|
UNITTEST_BEGIN_TEST("TestInstanceof", "test_instanceof_true");
|
|
|
|
RAVA_TEST_RUN(_unittest_result,
|
|
"public class Animal {}\n"
|
|
"public class Test {\n"
|
|
" public static int main() {\n"
|
|
" Animal a = new Animal();\n"
|
|
" if (a instanceof Animal) { return 1; }\n"
|
|
" return 0;\n"
|
|
" }\n"
|
|
"}\n",
|
|
"Test", "main", 1, "instanceof true should return 1");
|
|
|
|
UNITTEST_END_TEST();
|
|
}
|
|
|
|
UnittestTestResult_t* test_instanceof_false(void) {
|
|
UNITTEST_BEGIN_TEST("TestInstanceof", "test_instanceof_false");
|
|
|
|
RAVA_TEST_RUN(_unittest_result,
|
|
"public class Animal {}\n"
|
|
"public class Dog {}\n"
|
|
"public class Test {\n"
|
|
" public static int main() {\n"
|
|
" Dog d = new Dog();\n"
|
|
" if (d instanceof Animal) { return 1; }\n"
|
|
" return 0;\n"
|
|
" }\n"
|
|
"}\n",
|
|
"Test", "main", 0, "instanceof false should return 0");
|
|
|
|
UNITTEST_END_TEST();
|
|
}
|
|
|
|
UnittestTestResult_t* test_instanceof_in_expression(void) {
|
|
UNITTEST_BEGIN_TEST("TestInstanceof", "test_instanceof_in_expression");
|
|
|
|
RAVA_TEST_RUN(_unittest_result,
|
|
"public class Person {}\n"
|
|
"public class Test {\n"
|
|
" public static int main() {\n"
|
|
" Person p = new Person();\n"
|
|
" int result = 0;\n"
|
|
" if (p instanceof Person) { result = 42; }\n"
|
|
" return result;\n"
|
|
" }\n"
|
|
"}\n",
|
|
"Test", "main", 42, "instanceof in expression 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("Instanceof Tests");
|
|
|
|
UnittestTestCase_t *tc = unittest_test_case_create("TestInstanceof");
|
|
unittest_test_case_add_result(tc, test_instanceof_true());
|
|
unittest_test_case_add_result(tc, test_instanceof_false());
|
|
unittest_test_case_add_result(tc, test_instanceof_in_expression());
|
|
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;
|
|
}
|