62a8ff1c773ca435805b4d22672e95b8ed0f88bf
[platform/core/api/thread.git] / tests / unittest / thread-unittest-commissioner.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <gtest/gtest.h>
18
19 #include "thread.h"
20
21 class ThreadCommissionerTest : public ::testing::Test
22 {
23 public:
24         thread_instance_h instance;
25
26 protected:
27         void SetUp() override
28         {
29                 thread_initialize();
30                 instance = nullptr;
31         }
32
33         void TearDown() override
34         {
35                 if (instance)
36                         thread_disable(instance);
37                 thread_deinitialize();
38         }
39 };
40
41 TEST_F(ThreadCommissionerTest, CommissionerStartNotInitialized)
42 {
43         EXPECT_EQ(THREAD_ERROR_NONE, thread_deinitialize());
44         EXPECT_EQ(THREAD_ERROR_NOT_INITIALIZED, thread_commissioner_start(instance));
45 }
46
47 TEST_F(ThreadCommissionerTest, CommissionerStartInvalidParameter)
48 {
49         EXPECT_EQ(THREAD_ERROR_INVALID_PARAMETER, thread_commissioner_start(instance));
50 }
51
52 TEST_F(ThreadCommissionerTest, CommissionerStartErrorNone)
53 {
54         EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
55         EXPECT_EQ(THREAD_ERROR_NONE, thread_commissioner_start(instance));
56 }