Add verification to append testcases
Change-Id: Ida08a84e5a7844ed1afd80d3319d2dfc8b77c5e1
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
int main()
{
+
// Initialize and start server thread.
pthread_t t;
{