/* test generated dealloc functions for generated types */ static void test_dealloc_types(void) { UserDefOne *ud1test, *ud1a, *ud1b; UserDefOneList *ud1list; ud1test = g_malloc0(sizeof(UserDefOne)); ud1test->integer = 42; ud1test->string = g_strdup("hi there 42"); qapi_free_UserDefOne(ud1test); ud1a = g_malloc0(sizeof(UserDefOne)); ud1a->integer = 43; ud1a->string = g_strdup("hi there 43"); ud1b = g_malloc0(sizeof(UserDefOne)); ud1b->integer = 44; ud1b->string = g_strdup("hi there 44"); ud1list = g_malloc0(sizeof(UserDefOneList)); ud1list->value = ud1a; ud1list->next = g_malloc0(sizeof(UserDefOneList)); ud1list->next->value = ud1b; qapi_free_UserDefOneList(ud1list); }
static void test_visitor_in_list(TestInputVisitorData *data, const void *unused) { UserDefOneList *item, *head = NULL; Visitor *v; int i; v = visitor_input_test_init(data, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44 } ]"); visit_type_UserDefOneList(v, &head, NULL, &error_abort); g_assert(head != NULL); for (i = 0, item = head; item; item = item->next, i++) { char string[12]; snprintf(string, sizeof(string), "string%d", i); g_assert_cmpstr(item->value->string, ==, string); g_assert_cmpint(item->value->integer, ==, 42 + i); } qapi_free_UserDefOneList(head); head = NULL; /* An empty list is valid */ v = visitor_input_test_init(data, "[]"); visit_type_UserDefOneList(v, &head, NULL, &error_abort); g_assert(!head); }
static void test_validate_list(TestInputVisitorData *data, const void *unused) { UserDefOneList *head = NULL; Visitor *v; v = validate_test_init(data, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44 } ]"); visit_type_UserDefOneList(v, NULL, &head, &error_abort); qapi_free_UserDefOneList(head); }
static void test_validate_fail_list(TestInputVisitorData *data, const void *unused) { UserDefOneList *head = NULL; Error *err = NULL; Visitor *v; v = validate_test_init(data, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44, 'extra': 'ggg' } ]"); visit_type_UserDefOneList(v, &head, NULL, &err); g_assert(err); qapi_free_UserDefOneList(head); }