From 5de968e80ade1c02d1907834dcff95e9fc9ad10a Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Thu, 15 May 2014 23:11:54 +0200 Subject: SBUS: Return / if an object path getter returns NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Stef Walter Reviewed-by: Pavel Březina --- src/sbus/sbus_codegen | 2 ++ src/tests/sbus_codegen_tests.c | 14 ++++++++++++++ src/tests/sbus_codegen_tests.xml | 1 + src/tests/sbus_codegen_tests_generated.c | 11 ++++++++++- src/tests/sbus_codegen_tests_generated.h | 2 ++ 5 files changed, 29 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sbus/sbus_codegen b/src/sbus/sbus_codegen index b671e939f..6507753f2 100755 --- a/src/sbus/sbus_codegen +++ b/src/sbus/sbus_codegen @@ -320,6 +320,8 @@ def source_getter_invoker(prop): out("") if prop.type == "s": out(" out_val = prop_val == NULL ? \"\" : prop_val;") + elif prop.type == "o": + out(" out_val = prop_val == NULL ? \"/\" : prop_val;") else: out(" out_val = prop_val;") if prop.is_array: diff --git a/src/tests/sbus_codegen_tests.c b/src/tests/sbus_codegen_tests.c index e92c5f784..c7da414fe 100644 --- a/src/tests/sbus_codegen_tests.c +++ b/src/tests/sbus_codegen_tests.c @@ -441,6 +441,13 @@ void pilot_get_null_string_handler(struct sbus_request *dbus_req, *string_val = NULL; } +void pilot_get_null_path_handler(struct sbus_request *dbus_req, + void *instance_data, + const char **path_val) +{ + *path_val = NULL; +} + #define array_getter_body(in, out, outlen) do { \ ck_assert(dbus_req != NULL); \ ck_assert(out != NULL); \ @@ -548,6 +555,7 @@ struct test_pilot pilot_iface = { .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_null_path = pilot_get_null_path_handler, .test_pilot_get_byte_array = pilot_get_byte_array_handler, .test_pilot_get_int16_array = pilot_get_int16_array_handler, @@ -857,6 +865,12 @@ START_TEST(test_get_basic_types) call_get(client, "/test/leela", test_pilot_meta.name, "null_string", DBUS_TYPE_STRING, &string_val); ck_assert_str_eq(string_val, ""); + + /* If a string getter returns NULL, the caller should receive "/" */ + call_get(client, "/test/leela", test_pilot_meta.name, "null_path", + DBUS_TYPE_OBJECT_PATH, &path_val); + ck_assert_str_eq(path_val, "/"); + } END_TEST diff --git a/src/tests/sbus_codegen_tests.xml b/src/tests/sbus_codegen_tests.xml index c44f38305..90e274254 100755 --- a/src/tests/sbus_codegen_tests.xml +++ b/src/tests/sbus_codegen_tests.xml @@ -122,6 +122,7 @@ + diff --git a/src/tests/sbus_codegen_tests_generated.c b/src/tests/sbus_codegen_tests_generated.c index 211ad8967..70302daff 100644 --- a/src/tests/sbus_codegen_tests_generated.c +++ b/src/tests/sbus_codegen_tests_generated.c @@ -371,6 +371,15 @@ const struct sbus_property_meta test_pilot__properties[] = { 0, /* not writable */ NULL, /* no invoker */ }, + { + "null_path", /* name */ + "o", /* type */ + SBUS_PROPERTY_READABLE, + offsetof(struct test_pilot, test_pilot_get_null_path), + invoke_get_o, + 0, /* not writable */ + NULL, /* no invoker */ + }, { "byte_array", /* name */ "ay", /* type */ @@ -716,7 +725,7 @@ static int invoke_get_o(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_OBJECT_PATH, &out_val); } diff --git a/src/tests/sbus_codegen_tests_generated.h b/src/tests/sbus_codegen_tests_generated.h index 7dc817edf..e6fb10c5e 100644 --- a/src/tests/sbus_codegen_tests_generated.h +++ b/src/tests/sbus_codegen_tests_generated.h @@ -36,6 +36,7 @@ #define TEST_PILOT_STRING "string" #define TEST_PILOT_OBJECT_PATH "object_path" #define TEST_PILOT_NULL_STRING "null_string" +#define TEST_PILOT_NULL_PATH "null_path" #define TEST_PILOT_BYTE_ARRAY "byte_array" #define TEST_PILOT_INT16_ARRAY "int16_array" #define TEST_PILOT_UINT16_ARRAY "uint16_array" @@ -98,6 +99,7 @@ struct test_pilot { 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_null_path)(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 *); -- cgit