92 lines
2.7 KiB
C
92 lines
2.7 KiB
C
|
|
#include "test_utils.h"
|
||
|
|
|
||
|
|
UnittestTestResult_t* test_autobox_int_to_integer(void) {
|
||
|
|
UNITTEST_BEGIN_TEST("TestAutobox", "test_autobox_int_to_integer");
|
||
|
|
|
||
|
|
RAVA_TEST_RUN(_unittest_result,
|
||
|
|
"public class Test {\n"
|
||
|
|
" public static int main() {\n"
|
||
|
|
" Integer x = 42;\n"
|
||
|
|
" return x.hashCode();\n"
|
||
|
|
" }\n"
|
||
|
|
"}\n",
|
||
|
|
"Test", "main", 42, "int should autobox to Integer");
|
||
|
|
|
||
|
|
UNITTEST_END_TEST();
|
||
|
|
}
|
||
|
|
|
||
|
|
UnittestTestResult_t* test_unbox_integer_to_int(void) {
|
||
|
|
UNITTEST_BEGIN_TEST("TestAutobox", "test_unbox_integer_to_int");
|
||
|
|
|
||
|
|
RAVA_TEST_RUN(_unittest_result,
|
||
|
|
"public class Test {\n"
|
||
|
|
" public static int main() {\n"
|
||
|
|
" Integer x = 10;\n"
|
||
|
|
" int y = x;\n"
|
||
|
|
" return y + 5;\n"
|
||
|
|
" }\n"
|
||
|
|
"}\n",
|
||
|
|
"Test", "main", 15, "Integer should unbox to int");
|
||
|
|
|
||
|
|
UNITTEST_END_TEST();
|
||
|
|
}
|
||
|
|
|
||
|
|
UnittestTestResult_t* test_autobox_long(void) {
|
||
|
|
UNITTEST_BEGIN_TEST("TestAutobox", "test_autobox_long");
|
||
|
|
|
||
|
|
RAVA_TEST_RUN(_unittest_result,
|
||
|
|
"public class Test {\n"
|
||
|
|
" public static int main() {\n"
|
||
|
|
" Long x = 100L;\n"
|
||
|
|
" long y = x;\n"
|
||
|
|
" return (int)y;\n"
|
||
|
|
" }\n"
|
||
|
|
"}\n",
|
||
|
|
"Test", "main", 100, "long should autobox/unbox with Long");
|
||
|
|
|
||
|
|
UNITTEST_END_TEST();
|
||
|
|
}
|
||
|
|
|
||
|
|
UnittestTestResult_t* test_autobox_double(void) {
|
||
|
|
UNITTEST_BEGIN_TEST("TestAutobox", "test_autobox_double");
|
||
|
|
|
||
|
|
RAVA_TEST_RUN(_unittest_result,
|
||
|
|
"public class Test {\n"
|
||
|
|
" public static int main() {\n"
|
||
|
|
" Double x = 3.0;\n"
|
||
|
|
" double y = x;\n"
|
||
|
|
" return (int)(y + 2.0);\n"
|
||
|
|
" }\n"
|
||
|
|
"}\n",
|
||
|
|
"Test", "main", 5, "double should autobox/unbox with Double");
|
||
|
|
|
||
|
|
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("Autoboxing Tests");
|
||
|
|
|
||
|
|
UnittestTestCase_t *tc = unittest_test_case_create("TestAutobox");
|
||
|
|
unittest_test_case_add_result(tc, test_autobox_int_to_integer());
|
||
|
|
unittest_test_case_add_result(tc, test_unbox_integer_to_int());
|
||
|
|
unittest_test_case_add_result(tc, test_autobox_long());
|
||
|
|
unittest_test_case_add_result(tc, test_autobox_double());
|
||
|
|
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;
|
||
|
|
}
|