From b5fb84aa1963b0838144c7e425f30e8f0bf39904 Mon Sep 17 00:00:00 2001 From: "hyunuk.tak" Date: Fri, 25 Mar 2022 19:12:46 +0900 Subject: [PATCH] Add jointer test case for joiner start async Change-Id: I75a232293fb181a58411bb36baa2e7fd9444595d Signed-off-by: hyunuk.tak --- tests/unittest/mocks/thread-mock-dummy.cpp | 28 ++++++++++++++++++++++++++++ tests/unittest/thread-unittest-joiner.cpp | 13 +++++++++++-- tests/unittest/thread-unittest-network.cpp | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/tests/unittest/mocks/thread-mock-dummy.cpp b/tests/unittest/mocks/thread-mock-dummy.cpp index c9ed50f..2a778e5 100644 --- a/tests/unittest/mocks/thread-mock-dummy.cpp +++ b/tests/unittest/mocks/thread-mock-dummy.cpp @@ -107,6 +107,29 @@ static GVariant *__method_detach(GVariant *parameters) return g_variant_new("(i)", THREAD_ERROR_NONE); } +static GVariant *__make_joiner_start_result() +{ + const char *pskd = "Passkey"; + const char *provUrl = "ProvUrl"; + const char *vendorName = "VendorName"; + const char *vendorModel = "VendorModel"; + const char *vendorSwVersion = "VendorSwVersion"; + const char *vendorData = "VendorData"; + + return g_variant_new("(ssssss)", pskd, provUrl, + vendorName, vendorModel, vendorSwVersion, vendorData); +} + +static void __method_joiner_start(GVariant *parameters, + GAsyncReadyCallback callback, gpointer user_data) +{ + _gdbus_async_result.callback = callback; + _gdbus_async_result.result = __make_joiner_start_result(); + _gdbus_async_result.user_data = user_data; + _gdbus_async_result.timeout_id = g_timeout_add( + ASYNC_RESULT_DELAY, __reply_async_method, &_gdbus_async_result); +} + static GVariant *__property_device_role() { return g_variant_new("(v)", g_variant_new("s", "child")); @@ -191,6 +214,11 @@ struct { NULL, }, { + THREAD_DBUS_JOINER_START_METHOD, + NULL, + __method_joiner_start, + }, + { NULL, NULL, NULL, diff --git a/tests/unittest/thread-unittest-joiner.cpp b/tests/unittest/thread-unittest-joiner.cpp index 6c12fd4..0fc22fa 100644 --- a/tests/unittest/thread-unittest-joiner.cpp +++ b/tests/unittest/thread-unittest-joiner.cpp @@ -17,6 +17,7 @@ #include #include "thread.h" +#include "mocks/thread-mock-util.h" class ThreadJoinerTest : public ::testing::Test { @@ -31,7 +32,7 @@ public: thread_instance_h instance; public: - static void joinerStartCallback(int result, void* user_data) {}; + static void joinerStartCallback(int result, void* user_data); protected: void SetUp() override @@ -46,6 +47,12 @@ protected: } }; +void ThreadJoinerTest::joinerStartCallback(int result, void* user_data) +{ + if (result == true) + QUIT_GMAIN_LOOP; +} + TEST_F(ThreadJoinerTest, JoinerStartNotInitialized) { EXPECT_EQ(THREAD_ERROR_NONE, thread_deinitialize()); @@ -63,11 +70,13 @@ TEST_F(ThreadJoinerTest, JoinerStartInvalidParameter) vendorData, joinerStartCallback, nullptr)); } -TEST_F(ThreadJoinerTest, JoinerStartAttachErrorNone) +TEST_F(ThreadJoinerTest, JoinerStartErrorNone) { EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance)); EXPECT_EQ(THREAD_ERROR_NONE, thread_joiner_start(instance, pskd, provUrl, vendorName, vendorModel, vendorSwVersion, vendorData, joinerStartCallback, nullptr)); + + RUN_GMAIN_LOOP; } \ No newline at end of file diff --git a/tests/unittest/thread-unittest-network.cpp b/tests/unittest/thread-unittest-network.cpp index 09d7861..08c6b87 100644 --- a/tests/unittest/thread-unittest-network.cpp +++ b/tests/unittest/thread-unittest-network.cpp @@ -25,7 +25,7 @@ "fffe00208763d64768c8f3ecf0708fdd10ceaadb65a7b05105e1ec3e" \ "16d3e0aee52fb7e618a759973030f4f70656e5468726561642d34633" \ "33801024c3804103044b2dc6512dce13b11d3386eb2ce7e0c0402a0fff8" -#define DUMMY_TLVS_SIZE (sizeof(DUMMY_TLVS_STR) / 2) +#define DUMMY_TLVS_SIZE ((int)(sizeof(DUMMY_TLVS_STR) / 2)) #define DUMMY_IPV6_ADDRESS "fe80::1ee5:a5a9:8bd2:68de" class ThreadNetworkTest : public ::testing::Test -- 2.7.4