diff options
| author | Patrick Williams <patrick@stwcx.xyz> | 2016-09-08 15:54:09 -0500 |
|---|---|---|
| committer | Patrick Williams <patrick@stwcx.xyz> | 2016-09-12 21:54:52 -0500 |
| commit | 07e1d6f350370c678419ca2a5fb8b18bf3d8ee67 (patch) | |
| tree | c1dd42d886b6a5ea2f13db10f29f143d8aba0865 | |
| parent | 7802c074960a1707f7b5311a14b018918a71e63e (diff) | |
| download | sdbusplus-07e1d6f350370c678419ca2a5fb8b18bf3d8ee67.tar.gz sdbusplus-07e1d6f350370c678419ca2a5fb8b18bf3d8ee67.zip | |
Add verification to append testcases
Change-Id: Ida08a84e5a7844ed1afd80d3319d2dfc8b77c5e1
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
| -rw-r--r-- | test/message/append.cpp | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/test/message/append.cpp b/test/message/append.cpp index 1cc56ff..836c8ae 100644 --- a/test/message/append.cpp +++ b/test/message/append.cpp @@ -6,6 +6,9 @@ // Global to share the dbus type string between client and server. static std::string verifyTypeString; +using verifyCallback_t = void(*)(sd_bus_message*); +verifyCallback_t verifyCallback = nullptr; + static constexpr auto SERVICE = "sdbusplus.test"; static constexpr auto INTERFACE = SERVICE; static constexpr auto TEST_METHOD = "test"; @@ -39,8 +42,17 @@ void* server(void* b) if (sd_bus_message_is_method_call(m, INTERFACE, TEST_METHOD)) { // Verify the message type matches what the test expects. - // TODO: It would be nice to verify content here as well. assert(verifyTypeString == sd_bus_message_get_signature(m, true)); + if (verifyCallback) + { + verifyCallback(m); + verifyCallback = nullptr; + } + else + { + std::cout << "Warning: No verification for " + << verifyTypeString << std::endl; + } // Reply to client. sd_bus_reply_method_return(m, nullptr); } @@ -70,6 +82,18 @@ void runTests() auto m = newMethodCall__test(b); m.append(1); verifyTypeString = "i"; + + struct verify + { + static void op(sd_bus_message* m) + { + int32_t i = 0; + sd_bus_message_read_basic(m, 'i', &i); + assert(i == 1); + } + }; + verifyCallback = &verify::op; + b.call_noreply(m); } // Test l-value int. @@ -78,6 +102,19 @@ void runTests() int a = 1; m.append(a, a); verifyTypeString = "ii"; + + struct verify + { + static void op(sd_bus_message* m) + { + int32_t a = 0, b = 0; + sd_bus_message_read(m, "ii", &a, &b); + assert(a == 1); + assert(b == 1); + } + }; + verifyCallback = &verify::op; + b.call_noreply(m); } @@ -86,6 +123,22 @@ void runTests() auto m = newMethodCall__test(b); m.append(1, 2, 3, 4, 5); verifyTypeString = "iiiii"; + + struct verify + { + static void op(sd_bus_message* m) + { + int32_t a = 0, b = 0, c = 0, d = 0, e = 0; + sd_bus_message_read(m, "iiiii", &a, &b, &c, &d, &e); + assert(a == 1); + assert(b == 2); + assert(c == 3); + assert(d == 4); + assert(e == 5); + } + }; + verifyCallback = &verify::op; + b.call_noreply(m); } @@ -94,6 +147,18 @@ void runTests() auto m = newMethodCall__test(b); m.append("asdf"s); verifyTypeString = "s"; + + struct verify + { + static void op(sd_bus_message* m) + { + const char* s = nullptr; + sd_bus_message_read_basic(m, 's', &s); + assert(0 == strcmp("asdf", s)); + } + }; + verifyCallback = &verify::op; + b.call_noreply(m); } @@ -105,6 +170,25 @@ void runTests() m.append(1, "asdf", "ASDF"s, str, std::move(str2), 5); verifyTypeString = "issssi"; + + struct verify + { + static void op(sd_bus_message* m) + { + int32_t a = 0, b = 0; + const char *s0 = nullptr, *s1 = nullptr, *s2 = nullptr, + *s3 = nullptr; + sd_bus_message_read(m, "issssi", &a, &s0, &s1, &s2, &s3, &b); + assert(a == 1); + assert(b == 5); + assert(0 == strcmp("asdf", s0)); + assert(0 == strcmp("ASDF", s1)); + assert(0 == strcmp("jkl;", s2)); + assert(0 == strcmp("JKL:", s3)); + } + }; + verifyCallback = &verify::op; + b.call_noreply(m); } @@ -117,6 +201,7 @@ void runTests() int main() { + // Initialize and start server thread. pthread_t t; { |

