summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/sbus/sbus_codegen5
-rw-r--r--src/tests/sbus_codegen_tests.c13
-rwxr-xr-xsrc/tests/sbus_codegen_tests.xml3
-rw-r--r--src/tests/sbus_codegen_tests_generated.c11
-rw-r--r--src/tests/sbus_codegen_tests_generated.h2
5 files changed, 32 insertions, 2 deletions
diff --git a/src/sbus/sbus_codegen b/src/sbus/sbus_codegen
index a8f91b784..b671e939f 100755
--- a/src/sbus/sbus_codegen
+++ b/src/sbus/sbus_codegen
@@ -318,7 +318,10 @@ def source_getter_invoker(prop):
out(");")
out("")
- out(" out_val = prop_val;")
+ if prop.type == "s":
+ out(" out_val = prop_val == NULL ? \"\" : prop_val;")
+ else:
+ out(" out_val = prop_val;")
if prop.is_array:
out(" return sbus_request_return_array_as_variant(dbus_req, %s, (uint8_t*)out_val, prop_len, sizeof(%s));", prop.dbus_constant, prop.sssd_type)
else:
diff --git a/src/tests/sbus_codegen_tests.c b/src/tests/sbus_codegen_tests.c
index fa31ad64d..e92c5f784 100644
--- a/src/tests/sbus_codegen_tests.c
+++ b/src/tests/sbus_codegen_tests.c
@@ -434,6 +434,13 @@ void pilot_get_objpath_handler(struct sbus_request *dbus_req,
*path_val = pilot_path;
}
+void pilot_get_null_string_handler(struct sbus_request *dbus_req,
+ void *instance_data,
+ const char **string_val)
+{
+ *string_val = NULL;
+}
+
#define array_getter_body(in, out, outlen) do { \
ck_assert(dbus_req != NULL); \
ck_assert(out != NULL); \
@@ -540,6 +547,7 @@ struct test_pilot pilot_iface = {
.test_pilot_get_double = pilot_get_double_handler,
.test_pilot_get_string = pilot_get_string_handler,
.test_pilot_get_object_path = pilot_get_objpath_handler,
+ .test_pilot_get_null_string = pilot_get_null_string_handler,
.test_pilot_get_byte_array = pilot_get_byte_array_handler,
.test_pilot_get_int16_array = pilot_get_int16_array_handler,
@@ -844,6 +852,11 @@ START_TEST(test_get_basic_types)
call_get(client, "/test/leela", test_pilot_meta.name, "object_path",
DBUS_TYPE_OBJECT_PATH, &path_val);
ck_assert_str_eq(path_val, pilot_path);
+
+ /* If a string getter returns NULL, the caller should receive "" */
+ call_get(client, "/test/leela", test_pilot_meta.name, "null_string",
+ DBUS_TYPE_STRING, &string_val);
+ ck_assert_str_eq(string_val, "");
}
END_TEST
diff --git a/src/tests/sbus_codegen_tests.xml b/src/tests/sbus_codegen_tests.xml
index 74037cc40..c44f38305 100755
--- a/src/tests/sbus_codegen_tests.xml
+++ b/src/tests/sbus_codegen_tests.xml
@@ -120,6 +120,9 @@
<property name="string" type="s" access="read"/>
<property name="object_path" type="o" access="read"/>
+ <!-- Special properties to test error codes -->
+ <property name="null_string" type="s" access="read"/>
+
<!-- Property arrays with every type of basic argument except boolean
which we can't do (yet) -->
<property name="byte_array" type="ay" access="read"/>
diff --git a/src/tests/sbus_codegen_tests_generated.c b/src/tests/sbus_codegen_tests_generated.c
index 4ace03650..211ad8967 100644
--- a/src/tests/sbus_codegen_tests_generated.c
+++ b/src/tests/sbus_codegen_tests_generated.c
@@ -363,6 +363,15 @@ const struct sbus_property_meta test_pilot__properties[] = {
NULL, /* no invoker */
},
{
+ "null_string", /* name */
+ "s", /* type */
+ SBUS_PROPERTY_READABLE,
+ offsetof(struct test_pilot, test_pilot_get_null_string),
+ invoke_get_s,
+ 0, /* not writable */
+ NULL, /* no invoker */
+ },
+ {
"byte_array", /* name */
"ay", /* type */
SBUS_PROPERTY_READABLE,
@@ -764,7 +773,7 @@ static int invoke_get_s(struct sbus_request *dbus_req, void *function_ptr)
(handler)(dbus_req, dbus_req->intf->instance_data, &prop_val);
- out_val = prop_val;
+ out_val = prop_val == NULL ? "" : prop_val;
return sbus_request_return_as_variant(dbus_req, DBUS_TYPE_STRING, &out_val);
}
diff --git a/src/tests/sbus_codegen_tests_generated.h b/src/tests/sbus_codegen_tests_generated.h
index 9599091dd..7dc817edf 100644
--- a/src/tests/sbus_codegen_tests_generated.h
+++ b/src/tests/sbus_codegen_tests_generated.h
@@ -35,6 +35,7 @@
#define TEST_PILOT_DOUBLE "double"
#define TEST_PILOT_STRING "string"
#define TEST_PILOT_OBJECT_PATH "object_path"
+#define TEST_PILOT_NULL_STRING "null_string"
#define TEST_PILOT_BYTE_ARRAY "byte_array"
#define TEST_PILOT_INT16_ARRAY "int16_array"
#define TEST_PILOT_UINT16_ARRAY "uint16_array"
@@ -96,6 +97,7 @@ struct test_pilot {
void (*test_pilot_get_double)(struct sbus_request *, void *data, double *);
void (*test_pilot_get_string)(struct sbus_request *, void *data, const char * *);
void (*test_pilot_get_object_path)(struct sbus_request *, void *data, const char * *);
+ void (*test_pilot_get_null_string)(struct sbus_request *, void *data, const char * *);
void (*test_pilot_get_byte_array)(struct sbus_request *, void *data, uint8_t * *, int *);
void (*test_pilot_get_int16_array)(struct sbus_request *, void *data, int16_t * *, int *);
void (*test_pilot_get_uint16_array)(struct sbus_request *, void *data, uint16_t * *, int *);