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 "bt_protocol_utils_test.h"
18 #include "utils.h"
19
20 using namespace testing::ext;
21 using namespace testing;
22
23 namespace OHOS {
24 namespace EDM {
25 namespace TEST {
26
SetUpTestSuite(void)27 void BtProtocolUtilsTest::SetUpTestSuite(void)
28 {
29 Utils::SetEdmInitialEnv();
30 }
31
TearDownTestSuite(void)32 void BtProtocolUtilsTest::TearDownTestSuite(void)
33 {
34 Utils::ResetTokenTypeAndUid();
35 ASSERT_TRUE(Utils::IsOriginalUTEnv());
36 std::cout << "now ut process is original ut env : " << Utils::IsOriginalUTEnv() << std::endl;
37 }
38
39 /**
40 * @tc.name: TestIntToProtocolStr
41 * @tc.desc: Test BtProtocolUtils::IntToProtocolStr
42 * @tc.type: FUNC
43 */
44 HWTEST_F(BtProtocolUtilsTest, TestIntToProtocolStr, TestSize.Level1)
45 {
46 int32_t gatt = 0;
47 std::string str0;
48 bool ret = BtProtocolUtils::IntToProtocolStr(gatt, str0);
49 ASSERT_TRUE(ret);
50 ASSERT_TRUE(str0 == "GATT");
51
52 int32_t spp = 1;
53 std::string str1;
54 ret = BtProtocolUtils::IntToProtocolStr(spp, str1);
55 ASSERT_TRUE(ret);
56 ASSERT_TRUE(str1 == "SPP");
57
58 int32_t opp = 2;
59 std::string str2;
60 ret = BtProtocolUtils::IntToProtocolStr(opp, str2);
61 ASSERT_TRUE(ret);
62 ASSERT_TRUE(str2 == "OPP");
63 }
64
65 /**
66 * @tc.name: TestIntToProtocolStrFail
67 * @tc.desc: Test BtProtocolUtils::IntToProtocolStr
68 * @tc.type: FUNC
69 */
70 HWTEST_F(BtProtocolUtilsTest, TestIntToProtocolStrFail, TestSize.Level1)
71 {
72 int32_t num = 99;
73 std::string str;
74 bool ret = BtProtocolUtils::IntToProtocolStr(num, str);
75 ASSERT_FALSE(ret);
76 }
77
78 /**
79 * @tc.name: TestStrToProtocolInt
80 * @tc.desc: Test BtProtocolUtils::StrToProtocolInt
81 * @tc.type: FUNC
82 */
83 HWTEST_F(BtProtocolUtilsTest, TestStrToProtocolInt, TestSize.Level1)
84 {
85 int32_t gatt;
86 std::string str0 = "GATT";
87 bool ret = BtProtocolUtils::StrToProtocolInt(str0, gatt);
88 ASSERT_TRUE(ret);
89 ASSERT_TRUE(gatt == 0);
90
91 int32_t spp;
92 std::string str1 = "SPP";
93 ret = BtProtocolUtils::StrToProtocolInt(str1, spp);
94 ASSERT_TRUE(ret);
95 ASSERT_TRUE(spp == 1);
96
97 int32_t opp;
98 std::string str2 = "OPP";
99 ret = BtProtocolUtils::StrToProtocolInt(str2, opp);
100 ASSERT_TRUE(ret);
101 ASSERT_TRUE(opp == 2);
102 }
103
104 /**
105 * @tc.name: TestStrToProtocolIntFail
106 * @tc.desc: Test BtProtocolUtils::StrToProtocolInt
107 * @tc.type: FUNC
108 */
109 HWTEST_F(BtProtocolUtilsTest, TestStrToProtocolIntFail, TestSize.Level1)
110 {
111 int32_t num;
112 std::string str = "error";
113 bool ret = BtProtocolUtils::StrToProtocolInt(str, num);
114 ASSERT_FALSE(ret);
115 }
116 }
117 }
118 }