qapi: Introduce a first class 'null' type
I expect the 'null' type to be useful mostly for members of alternate
types.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
index 91ffb26..c72dbd8 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -93,7 +93,8 @@
{ 'struct': 'WrapAlternate',
'data': { 'alt': 'UserDefAlternate' } }
{ 'alternate': 'UserDefAlternate',
- 'data': { 'udfu': 'UserDefFlatUnion', 'e': 'EnumOne', 'i': 'int' } }
+ 'data': { 'udfu': 'UserDefFlatUnion', 'e': 'EnumOne', 'i': 'int',
+ 'n': 'null' } }
{ 'struct': 'UserDefC',
'data': { 'string1': 'str', 'string2': 'str' } }
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index b88b8aa..3b1e908 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -64,6 +64,7 @@
case udfu: UserDefFlatUnion
case e: EnumOne
case i: int
+ case n: null
object UserDefB
member intb: int optional=False
member a-b: bool optional=True
diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-visitor.c
index f98caf9..f451844 100644
--- a/tests/test-qobject-input-visitor.c
+++ b/tests/test-qobject-input-visitor.c
@@ -583,6 +583,11 @@
g_assert_cmpint(tmp->u.e, ==, ENUM_ONE_VALUE1);
qapi_free_UserDefAlternate(tmp);
+ v = visitor_input_test_init(data, "null");
+ visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort);
+ g_assert_cmpint(tmp->type, ==, QTYPE_QNULL);
+ qapi_free_UserDefAlternate(tmp);
+
v = visitor_input_test_init(data, "{'integer':1, 'string':'str', "
"'enum1':'value1', 'boolean':true}");
visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort);
diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c
index 8f1fcd4..7eb1620 100644
--- a/tests/test-qobject-output-visitor.c
+++ b/tests/test-qobject-output-visitor.c
@@ -424,6 +424,16 @@
visitor_reset(data);
tmp = g_new0(UserDefAlternate, 1);
+ tmp->type = QTYPE_QNULL;
+ tmp->u.n = qnull();
+
+ visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
+ g_assert_cmpint(qobject_type(visitor_get(data)), ==, QTYPE_QNULL);
+
+ qapi_free_UserDefAlternate(tmp);
+
+ visitor_reset(data);
+ tmp = g_new0(UserDefAlternate, 1);
tmp->type = QTYPE_QDICT;
tmp->u.udfu.integer = 1;
tmp->u.udfu.string = g_strdup("str");