Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * QMP Input Visitor unit-tests (strict mode). |
| 3 | * |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 4 | * Copyright (C) 2011-2012, 2015 Red Hat Inc. |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 5 | * |
| 6 | * Authors: |
| 7 | * Luiz Capitulino <lcapitulino@redhat.com> |
| 8 | * Paolo Bonzini <pbonzini@redhat.com> |
| 9 | * |
| 10 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 11 | * See the COPYING file in the top-level directory. |
| 12 | */ |
| 13 | |
Peter Maydell | 681c28a | 2016-02-08 18:08:51 +0000 | [diff] [blame] | 14 | #include "qemu/osdep.h" |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 15 | #include <glib.h> |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 16 | |
Paolo Bonzini | 79ee7df | 2012-12-06 11:22:34 +0100 | [diff] [blame] | 17 | #include "qemu-common.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 18 | #include "qapi/error.h" |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 19 | #include "qapi/qmp-input-visitor.h" |
| 20 | #include "test-qapi-types.h" |
| 21 | #include "test-qapi-visit.h" |
Paolo Bonzini | 7b1b5d1 | 2012-12-17 18:19:43 +0100 | [diff] [blame] | 22 | #include "qapi/qmp/types.h" |
Markus Armbruster | 39a1815 | 2015-09-16 13:06:28 +0200 | [diff] [blame] | 23 | #include "test-qmp-introspect.h" |
| 24 | #include "qmp-introspect.h" |
| 25 | #include "qapi-visit.h" |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 26 | |
| 27 | typedef struct TestInputVisitorData { |
| 28 | QObject *obj; |
| 29 | QmpInputVisitor *qiv; |
| 30 | } TestInputVisitorData; |
| 31 | |
| 32 | static void validate_teardown(TestInputVisitorData *data, |
| 33 | const void *unused) |
| 34 | { |
| 35 | qobject_decref(data->obj); |
| 36 | data->obj = NULL; |
| 37 | |
| 38 | if (data->qiv) { |
| 39 | qmp_input_visitor_cleanup(data->qiv); |
| 40 | data->qiv = NULL; |
| 41 | } |
| 42 | } |
| 43 | |
Eric Blake | 0920a17 | 2015-11-05 23:35:28 -0700 | [diff] [blame] | 44 | /* The various test_init functions are provided instead of a test setup |
| 45 | function so that the JSON string used by the tests are kept in the test |
| 46 | functions (and not in main()). */ |
| 47 | static Visitor *validate_test_init_internal(TestInputVisitorData *data, |
| 48 | const char *json_string, |
| 49 | va_list *ap) |
| 50 | { |
| 51 | Visitor *v; |
| 52 | |
Eric Blake | b18f114 | 2015-11-05 23:35:29 -0700 | [diff] [blame] | 53 | validate_teardown(data, NULL); |
| 54 | |
Eric Blake | 0920a17 | 2015-11-05 23:35:28 -0700 | [diff] [blame] | 55 | data->obj = qobject_from_jsonv(json_string, ap); |
| 56 | g_assert(data->obj); |
| 57 | |
Eric Blake | fc471c1 | 2016-04-28 15:45:13 -0600 | [diff] [blame] | 58 | data->qiv = qmp_input_visitor_new(data->obj, true); |
Eric Blake | 0920a17 | 2015-11-05 23:35:28 -0700 | [diff] [blame] | 59 | g_assert(data->qiv); |
| 60 | |
| 61 | v = qmp_input_get_visitor(data->qiv); |
| 62 | g_assert(v); |
| 63 | |
| 64 | return v; |
| 65 | } |
| 66 | |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 67 | static GCC_FMT_ATTR(2, 3) |
| 68 | Visitor *validate_test_init(TestInputVisitorData *data, |
| 69 | const char *json_string, ...) |
| 70 | { |
| 71 | Visitor *v; |
| 72 | va_list ap; |
| 73 | |
| 74 | va_start(ap, json_string); |
Eric Blake | 0920a17 | 2015-11-05 23:35:28 -0700 | [diff] [blame] | 75 | v = validate_test_init_internal(data, json_string, &ap); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 76 | va_end(ap); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 77 | return v; |
| 78 | } |
| 79 | |
Markus Armbruster | 39a1815 | 2015-09-16 13:06:28 +0200 | [diff] [blame] | 80 | /* similar to validate_test_init(), but does not expect a string |
| 81 | * literal/format json_string argument and so can be used for |
| 82 | * programatically generated strings (and we can't pass in programatically |
| 83 | * generated strings via %s format parameters since qobject_from_jsonv() |
| 84 | * will wrap those in double-quotes and treat the entire object as a |
| 85 | * string) |
| 86 | */ |
| 87 | static Visitor *validate_test_init_raw(TestInputVisitorData *data, |
| 88 | const char *json_string) |
| 89 | { |
Eric Blake | 0920a17 | 2015-11-05 23:35:28 -0700 | [diff] [blame] | 90 | return validate_test_init_internal(data, json_string, NULL); |
Markus Armbruster | 39a1815 | 2015-09-16 13:06:28 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 93 | |
| 94 | static void test_validate_struct(TestInputVisitorData *data, |
| 95 | const void *unused) |
| 96 | { |
| 97 | TestStruct *p = NULL; |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 98 | Visitor *v; |
| 99 | |
| 100 | v = validate_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }"); |
| 101 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 102 | visit_type_TestStruct(v, NULL, &p, &error_abort); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 103 | g_free(p->string); |
| 104 | g_free(p); |
| 105 | } |
| 106 | |
| 107 | static void test_validate_struct_nested(TestInputVisitorData *data, |
| 108 | const void *unused) |
| 109 | { |
Eric Blake | b6fcf32 | 2015-05-04 09:05:29 -0600 | [diff] [blame] | 110 | UserDefTwo *udp = NULL; |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 111 | Visitor *v; |
| 112 | |
Eric Blake | b6fcf32 | 2015-05-04 09:05:29 -0600 | [diff] [blame] | 113 | v = validate_test_init(data, "{ 'string0': 'string0', " |
| 114 | "'dict1': { 'string1': 'string1', " |
| 115 | "'dict2': { 'userdef': { 'integer': 42, " |
| 116 | "'string': 'string' }, 'string': 'string2'}}}"); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 117 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 118 | visit_type_UserDefTwo(v, NULL, &udp, &error_abort); |
Eric Blake | b6fcf32 | 2015-05-04 09:05:29 -0600 | [diff] [blame] | 119 | qapi_free_UserDefTwo(udp); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static void test_validate_list(TestInputVisitorData *data, |
| 123 | const void *unused) |
| 124 | { |
| 125 | UserDefOneList *head = NULL; |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 126 | Visitor *v; |
| 127 | |
| 128 | v = validate_test_init(data, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44 } ]"); |
| 129 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 130 | visit_type_UserDefOneList(v, NULL, &head, &error_abort); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 131 | qapi_free_UserDefOneList(head); |
| 132 | } |
| 133 | |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 134 | static void test_validate_union_native_list(TestInputVisitorData *data, |
| 135 | const void *unused) |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 136 | { |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 137 | UserDefNativeListUnion *tmp = NULL; |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 138 | Visitor *v; |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 139 | |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 140 | v = validate_test_init(data, "{ 'type': 'integer', 'data' : [ 1, 2 ] }"); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 141 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 142 | visit_type_UserDefNativeListUnion(v, NULL, &tmp, &error_abort); |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 143 | qapi_free_UserDefNativeListUnion(tmp); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Markus Armbruster | 2fc0043 | 2014-03-01 08:40:33 +0100 | [diff] [blame] | 146 | static void test_validate_union_flat(TestInputVisitorData *data, |
| 147 | const void *unused) |
| 148 | { |
| 149 | UserDefFlatUnion *tmp = NULL; |
| 150 | Visitor *v; |
Markus Armbruster | 2fc0043 | 2014-03-01 08:40:33 +0100 | [diff] [blame] | 151 | |
Wenchao Xia | 5223070 | 2014-03-04 18:44:39 -0800 | [diff] [blame] | 152 | v = validate_test_init(data, |
| 153 | "{ 'enum1': 'value1', " |
Markus Armbruster | 441cbac | 2015-09-16 13:06:10 +0200 | [diff] [blame] | 154 | "'integer': 41, " |
Wenchao Xia | 5223070 | 2014-03-04 18:44:39 -0800 | [diff] [blame] | 155 | "'string': 'str', " |
| 156 | "'boolean': true }"); |
Markus Armbruster | 2fc0043 | 2014-03-01 08:40:33 +0100 | [diff] [blame] | 157 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 158 | visit_type_UserDefFlatUnion(v, NULL, &tmp, &error_abort); |
Markus Armbruster | 2fc0043 | 2014-03-01 08:40:33 +0100 | [diff] [blame] | 159 | qapi_free_UserDefFlatUnion(tmp); |
| 160 | } |
| 161 | |
Eric Blake | ab04526 | 2015-05-04 09:05:11 -0600 | [diff] [blame] | 162 | static void test_validate_alternate(TestInputVisitorData *data, |
| 163 | const void *unused) |
Markus Armbruster | 2c38b60 | 2014-03-01 08:40:30 +0100 | [diff] [blame] | 164 | { |
Eric Blake | ab04526 | 2015-05-04 09:05:11 -0600 | [diff] [blame] | 165 | UserDefAlternate *tmp = NULL; |
Markus Armbruster | 2c38b60 | 2014-03-01 08:40:30 +0100 | [diff] [blame] | 166 | Visitor *v; |
Markus Armbruster | 2c38b60 | 2014-03-01 08:40:30 +0100 | [diff] [blame] | 167 | |
| 168 | v = validate_test_init(data, "42"); |
| 169 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 170 | visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort); |
Eric Blake | ab04526 | 2015-05-04 09:05:11 -0600 | [diff] [blame] | 171 | qapi_free_UserDefAlternate(tmp); |
Markus Armbruster | 2c38b60 | 2014-03-01 08:40:30 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 174 | static void test_validate_fail_struct(TestInputVisitorData *data, |
| 175 | const void *unused) |
| 176 | { |
| 177 | TestStruct *p = NULL; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 178 | Error *err = NULL; |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 179 | Visitor *v; |
| 180 | |
| 181 | v = validate_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo', 'extra': 42 }"); |
| 182 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 183 | visit_type_TestStruct(v, NULL, &p, &err); |
Eric Blake | a12a5a1 | 2015-11-05 23:35:31 -0700 | [diff] [blame] | 184 | error_free_or_abort(&err); |
Eric Blake | 68ab47e | 2016-04-28 15:45:32 -0600 | [diff] [blame] | 185 | g_assert(!p); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static void test_validate_fail_struct_nested(TestInputVisitorData *data, |
| 189 | const void *unused) |
| 190 | { |
Eric Blake | b6fcf32 | 2015-05-04 09:05:29 -0600 | [diff] [blame] | 191 | UserDefTwo *udp = NULL; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 192 | Error *err = NULL; |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 193 | Visitor *v; |
| 194 | |
| 195 | v = validate_test_init(data, "{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string', 'extra': [42, 23, {'foo':'bar'}] }, 'string2': 'string2'}}}"); |
| 196 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 197 | visit_type_UserDefTwo(v, NULL, &udp, &err); |
Eric Blake | a12a5a1 | 2015-11-05 23:35:31 -0700 | [diff] [blame] | 198 | error_free_or_abort(&err); |
Eric Blake | 68ab47e | 2016-04-28 15:45:32 -0600 | [diff] [blame] | 199 | g_assert(!udp); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static void test_validate_fail_list(TestInputVisitorData *data, |
| 203 | const void *unused) |
| 204 | { |
| 205 | UserDefOneList *head = NULL; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 206 | Error *err = NULL; |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 207 | Visitor *v; |
| 208 | |
| 209 | v = validate_test_init(data, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44, 'extra': 'ggg' } ]"); |
| 210 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 211 | visit_type_UserDefOneList(v, NULL, &head, &err); |
Eric Blake | a12a5a1 | 2015-11-05 23:35:31 -0700 | [diff] [blame] | 212 | error_free_or_abort(&err); |
Eric Blake | 68ab47e | 2016-04-28 15:45:32 -0600 | [diff] [blame] | 213 | g_assert(!head); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 216 | static void test_validate_fail_union_native_list(TestInputVisitorData *data, |
| 217 | const void *unused) |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 218 | { |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 219 | UserDefNativeListUnion *tmp = NULL; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 220 | Error *err = NULL; |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 221 | Visitor *v; |
| 222 | |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 223 | v = validate_test_init(data, |
| 224 | "{ 'type': 'integer', 'data' : [ 'string' ] }"); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 225 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 226 | visit_type_UserDefNativeListUnion(v, NULL, &tmp, &err); |
Eric Blake | a12a5a1 | 2015-11-05 23:35:31 -0700 | [diff] [blame] | 227 | error_free_or_abort(&err); |
Eric Blake | 68ab47e | 2016-04-28 15:45:32 -0600 | [diff] [blame] | 228 | g_assert(!tmp); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 229 | } |
| 230 | |
Markus Armbruster | 2fc0043 | 2014-03-01 08:40:33 +0100 | [diff] [blame] | 231 | static void test_validate_fail_union_flat(TestInputVisitorData *data, |
| 232 | const void *unused) |
| 233 | { |
| 234 | UserDefFlatUnion *tmp = NULL; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 235 | Error *err = NULL; |
Markus Armbruster | 2fc0043 | 2014-03-01 08:40:33 +0100 | [diff] [blame] | 236 | Visitor *v; |
| 237 | |
| 238 | v = validate_test_init(data, "{ 'string': 'c', 'integer': 41, 'boolean': true }"); |
| 239 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 240 | visit_type_UserDefFlatUnion(v, NULL, &tmp, &err); |
Eric Blake | a12a5a1 | 2015-11-05 23:35:31 -0700 | [diff] [blame] | 241 | error_free_or_abort(&err); |
Eric Blake | 68ab47e | 2016-04-28 15:45:32 -0600 | [diff] [blame] | 242 | g_assert(!tmp); |
Markus Armbruster | 2fc0043 | 2014-03-01 08:40:33 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Michael Roth | cb55111 | 2014-09-18 15:36:42 -0500 | [diff] [blame] | 245 | static void test_validate_fail_union_flat_no_discrim(TestInputVisitorData *data, |
| 246 | const void *unused) |
| 247 | { |
| 248 | UserDefFlatUnion2 *tmp = NULL; |
| 249 | Error *err = NULL; |
| 250 | Visitor *v; |
| 251 | |
| 252 | /* test situation where discriminator field ('enum1' here) is missing */ |
Markus Armbruster | 441cbac | 2015-09-16 13:06:10 +0200 | [diff] [blame] | 253 | v = validate_test_init(data, "{ 'integer': 42, 'string': 'c', 'string1': 'd', 'string2': 'e' }"); |
Michael Roth | cb55111 | 2014-09-18 15:36:42 -0500 | [diff] [blame] | 254 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 255 | visit_type_UserDefFlatUnion2(v, NULL, &tmp, &err); |
Eric Blake | a12a5a1 | 2015-11-05 23:35:31 -0700 | [diff] [blame] | 256 | error_free_or_abort(&err); |
Eric Blake | 68ab47e | 2016-04-28 15:45:32 -0600 | [diff] [blame] | 257 | g_assert(!tmp); |
Michael Roth | cb55111 | 2014-09-18 15:36:42 -0500 | [diff] [blame] | 258 | } |
| 259 | |
Eric Blake | ab04526 | 2015-05-04 09:05:11 -0600 | [diff] [blame] | 260 | static void test_validate_fail_alternate(TestInputVisitorData *data, |
| 261 | const void *unused) |
Markus Armbruster | 2c38b60 | 2014-03-01 08:40:30 +0100 | [diff] [blame] | 262 | { |
Eric Blake | e58d695 | 2016-04-28 15:45:10 -0600 | [diff] [blame] | 263 | UserDefAlternate *tmp; |
Markus Armbruster | 2c38b60 | 2014-03-01 08:40:30 +0100 | [diff] [blame] | 264 | Visitor *v; |
Markus Armbruster | e940f54 | 2014-05-02 13:26:29 +0200 | [diff] [blame] | 265 | Error *err = NULL; |
Markus Armbruster | 2c38b60 | 2014-03-01 08:40:30 +0100 | [diff] [blame] | 266 | |
| 267 | v = validate_test_init(data, "3.14"); |
| 268 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 269 | visit_type_UserDefAlternate(v, NULL, &tmp, &err); |
Eric Blake | a12a5a1 | 2015-11-05 23:35:31 -0700 | [diff] [blame] | 270 | error_free_or_abort(&err); |
Eric Blake | 68ab47e | 2016-04-28 15:45:32 -0600 | [diff] [blame] | 271 | g_assert(!tmp); |
Markus Armbruster | 2c38b60 | 2014-03-01 08:40:30 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Markus Armbruster | 39a1815 | 2015-09-16 13:06:28 +0200 | [diff] [blame] | 274 | static void do_test_validate_qmp_introspect(TestInputVisitorData *data, |
| 275 | const char *schema_json) |
| 276 | { |
| 277 | SchemaInfoList *schema = NULL; |
Markus Armbruster | 39a1815 | 2015-09-16 13:06:28 +0200 | [diff] [blame] | 278 | Visitor *v; |
| 279 | |
| 280 | v = validate_test_init_raw(data, schema_json); |
| 281 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 282 | visit_type_SchemaInfoList(v, NULL, &schema, &error_abort); |
Markus Armbruster | 39a1815 | 2015-09-16 13:06:28 +0200 | [diff] [blame] | 283 | g_assert(schema); |
| 284 | |
| 285 | qapi_free_SchemaInfoList(schema); |
| 286 | } |
| 287 | |
| 288 | static void test_validate_qmp_introspect(TestInputVisitorData *data, |
| 289 | const void *unused) |
| 290 | { |
| 291 | do_test_validate_qmp_introspect(data, test_qmp_schema_json); |
| 292 | do_test_validate_qmp_introspect(data, qmp_schema_json); |
| 293 | } |
| 294 | |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 295 | static void validate_test_add(const char *testpath, |
| 296 | TestInputVisitorData *data, |
| 297 | void (*test_func)(TestInputVisitorData *data, const void *user_data)) |
| 298 | { |
| 299 | g_test_add(testpath, TestInputVisitorData, data, NULL, test_func, |
| 300 | validate_teardown); |
| 301 | } |
| 302 | |
| 303 | int main(int argc, char **argv) |
| 304 | { |
| 305 | TestInputVisitorData testdata; |
| 306 | |
| 307 | g_test_init(&argc, &argv, NULL); |
| 308 | |
| 309 | validate_test_add("/visitor/input-strict/pass/struct", |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 310 | &testdata, test_validate_struct); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 311 | validate_test_add("/visitor/input-strict/pass/struct-nested", |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 312 | &testdata, test_validate_struct_nested); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 313 | validate_test_add("/visitor/input-strict/pass/list", |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 314 | &testdata, test_validate_list); |
Markus Armbruster | 2fc0043 | 2014-03-01 08:40:33 +0100 | [diff] [blame] | 315 | validate_test_add("/visitor/input-strict/pass/union-flat", |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 316 | &testdata, test_validate_union_flat); |
Eric Blake | ab04526 | 2015-05-04 09:05:11 -0600 | [diff] [blame] | 317 | validate_test_add("/visitor/input-strict/pass/alternate", |
| 318 | &testdata, test_validate_alternate); |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 319 | validate_test_add("/visitor/input-strict/pass/union-native-list", |
| 320 | &testdata, test_validate_union_native_list); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 321 | validate_test_add("/visitor/input-strict/fail/struct", |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 322 | &testdata, test_validate_fail_struct); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 323 | validate_test_add("/visitor/input-strict/fail/struct-nested", |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 324 | &testdata, test_validate_fail_struct_nested); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 325 | validate_test_add("/visitor/input-strict/fail/list", |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 326 | &testdata, test_validate_fail_list); |
Markus Armbruster | 2fc0043 | 2014-03-01 08:40:33 +0100 | [diff] [blame] | 327 | validate_test_add("/visitor/input-strict/fail/union-flat", |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 328 | &testdata, test_validate_fail_union_flat); |
Michael Roth | cb55111 | 2014-09-18 15:36:42 -0500 | [diff] [blame] | 329 | validate_test_add("/visitor/input-strict/fail/union-flat-no-discriminator", |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 330 | &testdata, test_validate_fail_union_flat_no_discrim); |
Eric Blake | ab04526 | 2015-05-04 09:05:11 -0600 | [diff] [blame] | 331 | validate_test_add("/visitor/input-strict/fail/alternate", |
| 332 | &testdata, test_validate_fail_alternate); |
Eric Blake | 805017b | 2015-05-04 09:05:06 -0600 | [diff] [blame] | 333 | validate_test_add("/visitor/input-strict/fail/union-native-list", |
| 334 | &testdata, test_validate_fail_union_native_list); |
Markus Armbruster | 39a1815 | 2015-09-16 13:06:28 +0200 | [diff] [blame] | 335 | validate_test_add("/visitor/input-strict/pass/qmp-introspect", |
| 336 | &testdata, test_validate_qmp_introspect); |
Paolo Bonzini | e38ac96 | 2012-03-22 12:51:10 +0100 | [diff] [blame] | 337 | |
| 338 | g_test_run(); |
| 339 | |
| 340 | return 0; |
| 341 | } |