blob: a24502b284e153c27ead8de1e8bbda99e94b640b [file] [log] [blame]
From 678483e7fe8e429d37d1449a4a796a14ea3d784a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber@ubuntu.com>
Date: Thu, 6 Dec 2012 23:34:48 +0000
Subject: [PATCH 2/3] Update tests
---
.../test_method_reply_function_deprecated.c | 22 +-
.../test_method_reply_function_standard.c | 22 +-
nih-dbus-tool/tests/test_marshal.c | 242 +++++++++---------
3 files changed, 152 insertions(+), 134 deletions(-)
diff --git a/nih-dbus-tool/tests/expected/test_method_reply_function_deprecated.c b/nih-dbus-tool/tests/expected/test_method_reply_function_deprecated.c
index f3c9b08..24c7ccb 100644
--- a/nih-dbus-tool/tests/expected/test_method_reply_function_deprecated.c
+++ b/nih-dbus-tool/tests/expected/test_method_reply_function_deprecated.c
@@ -27,16 +27,18 @@ my_async_method_reply (NihDBusMessage *message,
return -1;
}
- for (size_t output_i = 0; output[output_i]; output_i++) {
- const char *output_element;
-
- output_element = output[output_i];
-
- /* Marshal a char * onto the message */
- if (! dbus_message_iter_append_basic (&output_iter, DBUS_TYPE_STRING, &output_element)) {
- dbus_message_iter_abandon_container (&iter, &output_iter);
- dbus_message_unref (reply);
- return -1;
+ if (output) {
+ for (size_t output_i = 0; output[output_i]; output_i++) {
+ const char *output_element;
+
+ output_element = output[output_i];
+
+ /* Marshal a char * onto the message */
+ if (! dbus_message_iter_append_basic (&output_iter, DBUS_TYPE_STRING, &output_element)) {
+ dbus_message_iter_abandon_container (&iter, &output_iter);
+ dbus_message_unref (reply);
+ return -1;
+ }
}
}
diff --git a/nih-dbus-tool/tests/expected/test_method_reply_function_standard.c b/nih-dbus-tool/tests/expected/test_method_reply_function_standard.c
index f3c9b08..24c7ccb 100644
--- a/nih-dbus-tool/tests/expected/test_method_reply_function_standard.c
+++ b/nih-dbus-tool/tests/expected/test_method_reply_function_standard.c
@@ -27,16 +27,18 @@ my_async_method_reply (NihDBusMessage *message,
return -1;
}
- for (size_t output_i = 0; output[output_i]; output_i++) {
- const char *output_element;
-
- output_element = output[output_i];
-
- /* Marshal a char * onto the message */
- if (! dbus_message_iter_append_basic (&output_iter, DBUS_TYPE_STRING, &output_element)) {
- dbus_message_iter_abandon_container (&iter, &output_iter);
- dbus_message_unref (reply);
- return -1;
+ if (output) {
+ for (size_t output_i = 0; output[output_i]; output_i++) {
+ const char *output_element;
+
+ output_element = output[output_i];
+
+ /* Marshal a char * onto the message */
+ if (! dbus_message_iter_append_basic (&output_iter, DBUS_TYPE_STRING, &output_element)) {
+ dbus_message_iter_abandon_container (&iter, &output_iter);
+ dbus_message_unref (reply);
+ return -1;
+ }
}
}
diff --git a/nih-dbus-tool/tests/test_marshal.c b/nih-dbus-tool/tests/test_marshal.c
index 10cdd16..064371e 100644
--- a/nih-dbus-tool/tests/test_marshal.c
+++ b/nih-dbus-tool/tests/test_marshal.c
@@ -1479,39 +1479,41 @@ test_marshal (void)
"\treturn -1;\n"
"}\n"
"\n"
- "for (size_t value_i = 0; value[value_i]; value_i++) {\n"
- "\tDBusMessageIter value_element_iter;\n"
- "\tconst int16_t * value_element;\n"
- "\tsize_t value_element_len;\n"
+ "if (value) {\n"
+ "\tfor (size_t value_i = 0; value[value_i]; value_i++) {\n"
+ "\t\tDBusMessageIter value_element_iter;\n"
+ "\t\tconst int16_t * value_element;\n"
+ "\t\tsize_t value_element_len;\n"
"\n"
- "\tvalue_element = value[value_i];\n"
- "\tvalue_element_len = value_len[value_i];\n"
+ "\t\tvalue_element = value[value_i];\n"
+ "\t\tvalue_element_len = value_len[value_i];\n"
"\n"
- "\t/* Marshal an array onto the message */\n"
- "\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_ARRAY, \"n\", &value_element_iter)) {\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
- "\t}\n"
+ "\t\t/* Marshal an array onto the message */\n"
+ "\t\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_ARRAY, \"n\", &value_element_iter)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\n"
- "\tfor (size_t value_element_i = 0; value_element_i < value_element_len; value_element_i++) {\n"
- "\t\tint16_t value_element_element;\n"
+ "\t\tfor (size_t value_element_i = 0; value_element_i < value_element_len; value_element_i++) {\n"
+ "\t\t\tint16_t value_element_element;\n"
"\n"
- "\t\tvalue_element_element = value_element[value_element_i];\n"
+ "\t\t\tvalue_element_element = value_element[value_element_i];\n"
"\n"
- "\t\t/* Marshal a int16_t onto the message */\n"
- "\t\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_INT16, &value_element_element)) {\n"
- "\t\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
+ "\t\t\t/* Marshal a int16_t onto the message */\n"
+ "\t\t\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_INT16, &value_element_element)) {\n"
+ "\t\t\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
+ "\t\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\t\treturn -1;\n"
+ "\t\t\t}\n"
+ "\t\t}\n"
+ "\n"
+ "\t\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n"
"\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
"\t\t\treturn -1;\n"
"\t\t}\n"
- "\t}\n"
- "\n"
- "\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
- "\t}\n"
+ "\t}\n"
"}\n"
"\n"
"if (! dbus_message_iter_close_container (&iter, &value_iter)) {\n"
@@ -1766,15 +1768,17 @@ test_marshal (void)
"\treturn -1;\n"
"}\n"
"\n"
- "for (size_t value_i = 0; value[value_i]; value_i++) {\n"
- "\tconst char *value_element;\n"
+ "if (value) {\n"
+ "\tfor (size_t value_i = 0; value[value_i]; value_i++) {\n"
+ "\t\tconst char *value_element;\n"
"\n"
- "\tvalue_element = value[value_i];\n"
+ "\t\tvalue_element = value[value_i];\n"
"\n"
- "\t/* Marshal a char * onto the message */\n"
- "\tif (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_element)) {\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
+ "\t\t/* Marshal a char * onto the message */\n"
+ "\t\tif (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_element)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\t}\n"
"}\n"
"\n"
@@ -1933,35 +1937,39 @@ test_marshal (void)
"\treturn -1;\n"
"}\n"
"\n"
- "for (size_t value_i = 0; value[value_i]; value_i++) {\n"
- "\tDBusMessageIter value_element_iter;\n"
- "\tchar * const * value_element;\n"
+ "if (value) {\n"
+ "\tfor (size_t value_i = 0; value[value_i]; value_i++) {\n"
+ "\t\tDBusMessageIter value_element_iter;\n"
+ "\t\tchar * const * value_element;\n"
"\n"
- "\tvalue_element = value[value_i];\n"
+ "\t\tvalue_element = value[value_i];\n"
"\n"
- "\t/* Marshal an array onto the message */\n"
- "\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_ARRAY, \"s\", &value_element_iter)) {\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
- "\t}\n"
+ "\t\t/* Marshal an array onto the message */\n"
+ "\t\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_ARRAY, \"s\", &value_element_iter)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\n"
- "\tfor (size_t value_element_i = 0; value_element[value_element_i]; value_element_i++) {\n"
- "\t\tconst char *value_element_element;\n"
+ "\t\tif (value_element) {\n"
+ "\t\t\tfor (size_t value_element_i = 0; value_element[value_element_i]; value_element_i++) {\n"
+ "\t\t\t\tconst char *value_element_element;\n"
"\n"
- "\t\tvalue_element_element = value_element[value_element_i];\n"
+ "\t\t\t\tvalue_element_element = value_element[value_element_i];\n"
"\n"
- "\t\t/* Marshal a char * onto the message */\n"
- "\t\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_STRING, &value_element_element)) {\n"
- "\t\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
+ "\t\t\t\t/* Marshal a char * onto the message */\n"
+ "\t\t\t\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_STRING, &value_element_element)) {\n"
+ "\t\t\t\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
+ "\t\t\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\t\t\treturn -1;\n"
+ "\t\t\t\t}\n"
+ "\t\t\t}\n"
+ "\t\t}\n"
+ "\n"
+ "\t\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n"
"\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
"\t\t\treturn -1;\n"
"\t\t}\n"
"\t}\n"
- "\n"
- "\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
- "\t}\n"
"}\n"
"\n"
"if (! dbus_message_iter_close_container (&iter, &value_iter)) {\n"
@@ -2194,16 +2202,18 @@ test_marshal (void)
"\treturn -1;\n"
"}\n"
"\n"
- "for (size_t value_item2_i = 0; value_item2[value_item2_i]; value_item2_i++) {\n"
- "\tconst char *value_item2_element;\n"
+ "if (value_item2) {\n"
+ "\tfor (size_t value_item2_i = 0; value_item2[value_item2_i]; value_item2_i++) {\n"
+ "\t\tconst char *value_item2_element;\n"
"\n"
- "\tvalue_item2_element = value_item2[value_item2_i];\n"
+ "\t\tvalue_item2_element = value_item2[value_item2_i];\n"
"\n"
- "\t/* Marshal a char * onto the message */\n"
- "\tif (! dbus_message_iter_append_basic (&value_item2_iter, DBUS_TYPE_STRING, &value_item2_element)) {\n"
- "\t\tdbus_message_iter_abandon_container (&value_iter, &value_item2_iter);\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
+ "\t\t/* Marshal a char * onto the message */\n"
+ "\t\tif (! dbus_message_iter_append_basic (&value_item2_iter, DBUS_TYPE_STRING, &value_item2_element)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&value_iter, &value_item2_iter);\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\t}\n"
"}\n"
"\n"
@@ -2642,41 +2652,43 @@ test_marshal (void)
"\treturn -1;\n"
"}\n"
"\n"
- "for (size_t value_i = 0; value[value_i]; value_i++) {\n"
- "\tDBusMessageIter value_element_iter;\n"
- "\tconst char * value_element_item0;\n"
- "\tuint32_t value_element_item1;\n"
- "\tconst MyStructArrayValueElement *value_element;\n"
+ "if (value) {\n"
+ "\tfor (size_t value_i = 0; value[value_i]; value_i++) {\n"
+ "\t\tDBusMessageIter value_element_iter;\n"
+ "\t\tconst char * value_element_item0;\n"
+ "\t\tuint32_t value_element_item1;\n"
+ "\t\tconst MyStructArrayValueElement *value_element;\n"
"\n"
- "\tvalue_element = value[value_i];\n"
+ "\t\tvalue_element = value[value_i];\n"
"\n"
- "\t/* Marshal a structure onto the message */\n"
- "\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_STRUCT, NULL, &value_element_iter)) {\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
- "\t}\n"
+ "\t\t/* Marshal a structure onto the message */\n"
+ "\t\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_STRUCT, NULL, &value_element_iter)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\n"
- "\tvalue_element_item0 = value_element->item0;\n"
+ "\t\tvalue_element_item0 = value_element->item0;\n"
"\n"
- "\t/* Marshal a char * onto the message */\n"
- "\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_STRING, &value_element_item0)) {\n"
- "\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
- "\t}\n"
+ "\t\t/* Marshal a char * onto the message */\n"
+ "\t\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_STRING, &value_element_item0)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\n"
- "\tvalue_element_item1 = value_element->item1;\n"
+ "\t\tvalue_element_item1 = value_element->item1;\n"
"\n"
- "\t/* Marshal a uint32_t onto the message */\n"
- "\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_UINT32, &value_element_item1)) {\n"
- "\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
- "\t}\n"
+ "\t\t/* Marshal a uint32_t onto the message */\n"
+ "\t\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_UINT32, &value_element_item1)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\n"
- "\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
+ "\t\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\t}\n"
"}\n"
"\n"
@@ -2912,41 +2924,43 @@ test_marshal (void)
"\treturn -1;\n"
"}\n"
"\n"
- "for (size_t value_i = 0; value[value_i]; value_i++) {\n"
- "\tDBusMessageIter value_element_iter;\n"
- "\tconst char * value_element_item0;\n"
- "\tuint32_t value_element_item1;\n"
- "\tconst MyDictEntryArrayValueElement *value_element;\n"
+ "if (value) {\n"
+ "\tfor (size_t value_i = 0; value[value_i]; value_i++) {\n"
+ "\t\tDBusMessageIter value_element_iter;\n"
+ "\t\tconst char * value_element_item0;\n"
+ "\t\tuint32_t value_element_item1;\n"
+ "\t\tconst MyDictEntryArrayValueElement *value_element;\n"
"\n"
- "\tvalue_element = value[value_i];\n"
+ "\t\tvalue_element = value[value_i];\n"
"\n"
- "\t/* Marshal a structure onto the message */\n"
- "\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_DICT_ENTRY, NULL, &value_element_iter)) {\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
- "\t}\n"
+ "\t\t/* Marshal a structure onto the message */\n"
+ "\t\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_DICT_ENTRY, NULL, &value_element_iter)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\n"
- "\tvalue_element_item0 = value_element->item0;\n"
+ "\t\tvalue_element_item0 = value_element->item0;\n"
"\n"
- "\t/* Marshal a char * onto the message */\n"
- "\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_STRING, &value_element_item0)) {\n"
- "\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
- "\t}\n"
+ "\t\t/* Marshal a char * onto the message */\n"
+ "\t\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_STRING, &value_element_item0)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\n"
- "\tvalue_element_item1 = value_element->item1;\n"
+ "\t\tvalue_element_item1 = value_element->item1;\n"
"\n"
- "\t/* Marshal a uint32_t onto the message */\n"
- "\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_UINT32, &value_element_item1)) {\n"
- "\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
- "\t}\n"
+ "\t\t/* Marshal a uint32_t onto the message */\n"
+ "\t\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_UINT32, &value_element_item1)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\n"
- "\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n"
- "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
- "\t\treturn -1;\n"
+ "\t\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n"
+ "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n"
+ "\t\t\treturn -1;\n"
+ "\t\t}\n"
"\t}\n"
"}\n"
"\n"
--
2.36.1.476.g0c4daa206d-goog