1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include <iostream>
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include "distributed_device_profile_constants.h"
23 #include "distributed_device_profile_errors.h"
24 #include "distributed_device_profile_log.h"
25 #include "static_profile_manager.h"
26 using namespace testing::ext;
27 namespace OHOS {
28 namespace DistributedDeviceProfile {
29 using namespace std;
30 namespace {
31     const std::string TAG = "StaticProfileManagerTest";
32 }
33 class StaticProfileManagerTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp();
38     void TearDown();
39 };
40 
SetUpTestCase()41 void StaticProfileManagerTest::SetUpTestCase()
42 {
43 }
44 
TearDownTestCase()45 void StaticProfileManagerTest::TearDownTestCase()
46 {
47 }
48 
SetUp()49 void StaticProfileManagerTest::SetUp()
50 {
51 }
52 
TearDown()53 void StaticProfileManagerTest::TearDown()
54 {
55 }
56 
57 /*
58  * @tc.name: Init_001
59  * @tc.desc: Init
60  * @tc.type: FUNC
61  * @tc.require: I4NY1T
62  */
63 HWTEST_F(StaticProfileManagerTest, Init_001, TestSize.Level1)
64 {
65     int32_t errCode = StaticProfileManager::GetInstance().Init();
66     EXPECT_EQ(errCode, DP_SUCCESS);
67 }
68 
69 /*
70  * @tc.name: UnInit_001
71  * @tc.desc: UnInit
72  * @tc.type: FUNC
73  * @tc.require: I4NY1T
74  */
75 HWTEST_F(StaticProfileManagerTest, UnInit_001, TestSize.Level1)
76 {
77     StaticProfileManager::GetInstance().Init();
78     int32_t errCode = StaticProfileManager::GetInstance().UnInit();
79     EXPECT_EQ(errCode, DP_SUCCESS);
80 }
81 
82 /*
83  * @tc.name: ReInit_001
84  * @tc.desc: ReInit
85  * @tc.type: FUNC
86  * @tc.require: I4NY1T
87  */
88 HWTEST_F(StaticProfileManagerTest, ReInit_001, TestSize.Level1)
89 {
90     StaticProfileManager::GetInstance().Init();
91     int32_t errCode = StaticProfileManager::GetInstance().ReInit();
92     EXPECT_EQ(errCode, DP_SUCCESS);
93 }
94 
95 /*
96  * @tc.name: PutCharacteristicProfile_001
97  * @tc.desc: PutCharacteristicProfile
98  * @tc.type: FUNC
99  * @tc.require: I4NY1T
100  */
101 HWTEST_F(StaticProfileManagerTest, PutCharacteristicProfile_001, TestSize.Level1)
102 {
103     CharacteristicProfile charProfile;
104     int32_t errCode = StaticProfileManager::GetInstance().PutCharacteristicProfile(charProfile);
105     EXPECT_EQ(errCode, DP_INVALID_PARAMS);
106 }
107 
108 /*
109  * @tc.name: GetCharacteristicProfile_001
110  * @tc.desc: GetCharacteristicProfile
111  * @tc.type: FUNC
112  * @tc.require: I4NY1T
113  */
114 HWTEST_F(StaticProfileManagerTest, GetCharacteristicProfile_001, TestSize.Level1)
115 {
116     std::string deviceId;
117     std::string serviceName;
118     std::string characteristicKey;
119     CharacteristicProfile charProfile;
120     int32_t errCode = StaticProfileManager::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
121         characteristicKey, charProfile);
122     EXPECT_EQ(errCode, DP_INVALID_PARAMS);
123 }
124 
125 #ifdef DEVICE_PROFILE_SWITCH_STATIC_ENABLE
126 /*
127  * @tc.name: GetAllCharacteristicProfile_001
128  * @tc.desc: GetAllCharacteristicProfile
129  * @tc.type: FUNC
130  * @tc.require: I4NY1T
131  */
132 HWTEST_F(StaticProfileManagerTest, GetAllCharacteristicProfile_001, TestSize.Level1)
133 {
134     std::vector<CharacteristicProfile> staticCapabilityProfiles;
135     int32_t errCode = StaticProfileManager::GetInstance().GetAllCharacteristicProfile(staticCapabilityProfiles);
136     EXPECT_EQ(errCode, DP_SUCCESS);
137 }
138 #endif // DEVICE_PROFILE_SWITCH_STATIC_ENABLE
139 
140 /*
141  * @tc.name: GenerateStaticInfoProfile_001
142  * @tc.desc: GenerateStaticInfoProfile
143  * @tc.type: FUNC
144  * @tc.require: I4NY1T
145  */
146 HWTEST_F(StaticProfileManagerTest, GenerateStaticInfoProfile_001, TestSize.Level1)
147 {
148     CharacteristicProfile staticCapabilityProfile;
149     std::unordered_map<std::string, CharacteristicProfile> staticInfoProfiles;
150     int32_t errCode = StaticProfileManager::GetInstance().GenerateStaticInfoProfile(staticCapabilityProfile,
151         staticInfoProfiles);
152     EXPECT_EQ(errCode, DP_PARSE_STATIC_CAP_FAIL);
153 }
154 } // namespace DistributedDeviceProfile
155 } // namespace OHOS
156