2 #include "opensrf/osrf_json.h"
3 #include "opensrf/osrf_message.h"
7 //Set up the test fixture
9 o = osrf_message_init(CONNECT, 1, 1);
12 //Clean up the test fixture
19 START_TEST(test_osrf_message_init)
20 fail_if (o == NULL, "osrfMessage not created");
23 START_TEST(test_osrf_message_get_last_locale)
24 fail_unless(osrf_message_get_last_locale() == NULL,
25 "osrf_message_get_last_locale should return the value of current_locale");
28 START_TEST(test_osrf_message_set_locale)
29 const char* new_locale = "en-CA";
30 fail_unless(osrf_message_set_locale(o, NULL) == NULL,
31 "osrf_message_set_locale should return NULL if locale is NULL");
32 fail_unless(osrf_message_set_locale(NULL, new_locale) == NULL,
33 "osrf_message_set_locale should return NULL if msg is NULL");
34 const char* l = osrf_message_set_locale(o, new_locale);
35 fail_unless(strcmp(l, "en-CA") == 0,
36 "osrf_message_set_locale should return the new locale");
37 fail_unless(strcmp(o->sender_locale, "en-CA") == 0,
38 "osrf_message_set_locale should set osrfMessage->sender_locale to the new locale");
41 START_TEST(test_osrf_message_set_default_locale)
42 fail_unless(osrf_message_set_default_locale(NULL) == NULL,
43 "osrf_message_set_default_locale should return NULL if given a NULL arg");
44 fail_unless(osrf_message_set_default_locale("This string is \
45 longer than 16 characters for sure") == NULL,
46 "osrf_message_set_default_locale should return NULL if locale arg is longer than 16 chars");
47 fail_unless(strcmp(osrf_message_set_default_locale("fr-CA"),
49 "osrf_message_set_default_locale should return the new default locale if successful");
52 START_TEST(test_osrf_message_set_method)
53 osrf_message_set_method(o, NULL);
54 fail_unless(o->method_name == NULL,
55 "osrf_message_set_method should return NULL if given a NULL method_name arg");
56 osrf_message_set_method(o, "add");
57 fail_unless(strcmp(o->method_name, "add") == 0,
58 "osrf_message_set_method should set osrfMessage->method_name if successful");
61 START_TEST(test_osrf_message_set_params)
62 osrf_message_set_params(o, NULL);
63 fail_unless(o->_params == NULL,
64 "osrf_message_set_params should set msg->_params to NULL when passed a NULL o arg");
65 jsonObject *testJSONObject;
66 testJSONObject = jsonNewObject("test");
67 osrf_message_set_params(o, testJSONObject);
68 fail_unless(strcmp(jsonObjectGetIndex(o->_params, 0)->value.s, "test") == 0,
69 "osrf_message_set_params should set msg->_params to an array containing the\
71 jsonObjectFree(testJSONObject);
76 Suite *osrf_message_suite(void) {
77 //Create test suite, test case, initialize fixture
78 Suite *s = suite_create("osrf_message");
79 TCase *tc_core = tcase_create("Core");
80 tcase_add_checked_fixture (tc_core, setup, teardown);
82 //Add tests to test case
83 tcase_add_test(tc_core, test_osrf_message_init);
84 tcase_add_test(tc_core, test_osrf_message_get_last_locale);
85 tcase_add_test(tc_core, test_osrf_message_set_locale);
86 tcase_add_test(tc_core, test_osrf_message_set_default_locale);
87 tcase_add_test(tc_core, test_osrf_message_set_method);
88 tcase_add_test(tc_core, test_osrf_message_set_params);
90 //Add test case to test suite
91 suite_add_tcase(s, tc_core);
96 void run_tests(SRunner *sr) {
97 srunner_add_suite(sr, osrf_message_suite());