Add thread_network_set_panid API with unittest 36/273136/1
authorhyunuk.tak <hyunuk.tak@samsung.com>
Wed, 30 Mar 2022 02:16:43 +0000 (11:16 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Thu, 31 Mar 2022 01:00:03 +0000 (10:00 +0900)
Change-Id: I42a71133a17c03c83cf9ae51cd4d3c6895afdc56
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
include/thread.h
src/thread-network.c
tests/unittest/thread-unittest-network.cpp

index 7489465..b0745ac 100644 (file)
@@ -682,7 +682,7 @@ int thread_network_set_extended_panid(thread_network_h network, uint64_t extende
  *
  * @pre thread API must be initialized with thread_initialize().
  */
-int thread_network_set_panid(thread_network_h network, uint64_t panid);
+int thread_network_set_panid(thread_network_h network, uint16_t panid);
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_NETWORK_MODULE
index acd3cf2..24aa234 100644 (file)
@@ -199,6 +199,22 @@ int thread_network_set_extended_panid(thread_network_h network, uint64_t extende
        return THREAD_ERROR_NONE;
 }
 
+int thread_network_set_panid(thread_network_h network, uint16_t panid)
+{
+       FUNC_ENTRY;
+       THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
+       THREAD_CHECK_INIT_STATUS();
+       THREAD_VALIDATE_INPUT_PARAMETER(network);
+
+       THREAD_DBG("Network panid: %u", panid);
+
+       thread_network_s *current_network = network;
+       current_network->panid = panid;
+
+       FUNC_EXIT;
+       return THREAD_ERROR_NONE;
+}
+
 /* Network leader/Creator */
 int thread_network_create_operational_network(thread_instance_h instance,
        const char *name, const char *key, const char *pskc, uint32_t channel,
index ffe4086..416bb5a 100644 (file)
@@ -36,6 +36,7 @@ public:
        const char *NETWORK_DUMMY_PSKC = "19d3bd4ee76baad7ff2da29c87c67452";
        const uint32_t NETWORK_DUMMY_CHANNEL = 15;
        const uint64_t NETWORK_DUMMY_EXTENDED_PANID = 0xeea0d4484e93db7a;
+       const uint16_t NETWORK_DUMMY_PANID = 0x68a0;
 
        thread_instance_h instance;
        thread_network_h network;
@@ -462,4 +463,24 @@ TEST_F(ThreadNetworkTest, SetExtendedPanidErrorNone)
        EXPECT_EQ(THREAD_ERROR_NONE, thread_network_create(&network));
        EXPECT_EQ(THREAD_ERROR_NONE,
                thread_network_set_extended_panid(network, NETWORK_DUMMY_EXTENDED_PANID));
+}
+
+TEST_F(ThreadNetworkTest, SetPanidNotInitialized)
+{
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_deinitialize());
+       EXPECT_EQ(THREAD_ERROR_NOT_INITIALIZED,
+               thread_network_set_panid(network, NETWORK_DUMMY_PANID));
+}
+
+TEST_F(ThreadNetworkTest, SetPanidInvalidParameter)
+{
+       EXPECT_EQ(THREAD_ERROR_INVALID_PARAMETER,
+               thread_network_set_panid(nullptr, NETWORK_DUMMY_PANID));
+}
+
+TEST_F(ThreadNetworkTest, SetPanidErrorNone)
+{
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_network_create(&network));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_network_set_panid(network, NETWORK_DUMMY_PANID));
 }
\ No newline at end of file