>From b897b24223c8a4b6dee709dd98cb316cf7f39e74 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Thu, 15 May 2014 23:11:54 +0200 Subject: [PATCH 7/9] SBUS: Return / if an object path getter returns NULL --- 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(-) diff --git a/src/sbus/sbus_codegen b/src/sbus/sbus_codegen index b671e939fcc7c29a2ba424e785e967111d32323c..6507753f2797b354da8aaa2503b7d9bd701668c8 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 e92c5f78411e7c09d41e24ceb920a0bcb9955337..c7da414fe30f46d9d317f3a4205ab38c4e905081 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 c44f38305a9a2e6eb1fb402a45ce6002e103639d..90e27425414167f025c34da3ae5c06dc5a36f165 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 211ad8967f4c3cf3d00c6b53004c42dd15fbe715..70302daff7c7a7f5b042428be7d994fa0cdd660a 100644 --- a/src/tests/sbus_codegen_tests_generated.c +++ b/src/tests/sbus_codegen_tests_generated.c @@ -372,6 +372,15 @@ const struct sbus_property_meta test_pilot__properties[] = { 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 */ SBUS_PROPERTY_READABLE, @@ -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 7dc817edf9bac331ec8d5647721cb4fd9e737d55..e6fb10c5ef5724c865735ed5938f7a7b96b995aa 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 *); -- 1.9.0