#include #include #include #include "uclisp.h" #include "internal.h" #include "state.h" #include "utility.h" #include "testing_helpers.h" /* static struct ucl_parse_result *result; */ static struct ucl_state *state; static struct ucl_object *response; void setUp(void) { state = ucl_state_create(); } void tearDown(void) { ucl_state_delete(state); state = NULL; } static void test_get_empty(void) { response = ucl_state_get(state, "foo"); TEST_ASSERT_OBJ_ERROR(response); } static void test_put_get(void) { ucl_state_put(state, "foo", ucl_t_create()); response = ucl_state_get(state, "foo"); TEST_ASSERT_T(response); } static void test_put2_get(void) { ucl_state_put(state, "foo1", ucl_t_create()); ucl_state_put(state, "foo2", ucl_nil_create()); response = ucl_state_get(state, "foo1"); TEST_ASSERT_T(response); } static void test_put_modify_get(void) { struct ucl_object *obj = ucl_tuple_create( ucl_string_create(strdup("bar")), ucl_string_create(strdup("baz"))); ucl_state_put(state, "foo", obj); ucl_list_append(obj, ucl_string_create(strdup("quux"))); response = ucl_state_get(state, "foo"); TEST_ASSERT_OBJ_STRING(ucl_list_nth(response, 2)); TEST_ASSERT_EQUAL_STRING(ucl_list_nth(response, 2)->string, "quux"); TEST_ASSERT_OBJ_STRING(ucl_list_nth(obj, 2)); TEST_ASSERT_EQUAL_STRING(ucl_list_nth(obj, 2)->string, "quux"); } int main(void) { UNITY_BEGIN(); RUN_TEST(test_get_empty); RUN_TEST(test_put_get); RUN_TEST(test_put2_get); RUN_TEST(test_put_modify_get); return UNITY_END(); }