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 #include <gtest/gtest.h>
16 #include <thread>
17
18 #include "nfc_sdk_common.h"
19
20 namespace OHOS {
21 namespace NFC {
22 namespace TEST {
23 using namespace testing::ext;
24 using namespace OHOS::NFC::KITS;
25 class NfcSdkCommonTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp();
30 void TearDown();
31 public:
32 std::shared_ptr<NfcSdkCommon> common = std::make_shared<NfcSdkCommon>();
33 };
34
SetUpTestCase()35 void NfcSdkCommonTest::SetUpTestCase()
36 {
37 std::cout << " SetUpTestCase NfcSdkCommonTest." << std::endl;
38 }
39
TearDownTestCase()40 void NfcSdkCommonTest::TearDownTestCase()
41 {
42 std::cout << " TearDownTestCase NfcSdkCommonTest." << std::endl;
43 }
44
SetUp()45 void NfcSdkCommonTest::SetUp()
46 {
47 std::cout << " SetUp NfcSdkCommonTest." << std::endl;
48 }
49
TearDown()50 void NfcSdkCommonTest::TearDown()
51 {
52 std::cout << " TearDown NfcSdkCommonTest." << std::endl;
53 }
54
55 /**
56 * @tc.name: SecureStringToInt001
57 * @tc.desc: Test NfcSdkCommonTest SecureStringToInt.
58 * @tc.type: FUNC
59 */
60 HWTEST_F(NfcSdkCommonTest, SecureStringToInt001, TestSize.Level1)
61 {
62 int32_t value = 0;
63 common->SecureStringToInt("", value, 10);
64 value = 0;
65 common->SecureStringToInt("abc", value, 10);
66 value = 0;
67 common->SecureStringToInt("123", value, 10);
68 value = 0;
69 common->SecureStringToInt("2147483648", value, 10);
70 value = 0;
71 common->SecureStringToInt("-100", value, 10);
72 ASSERT_TRUE(common != nullptr);
73 }
74
75 /**
76 * @tc.name: GetConfigFromJson001
77 * @tc.desc: Test NfcSdkCommonTest GetConfigFromJson.
78 * @tc.type: FUNC
79 */
80 HWTEST_F(NfcSdkCommonTest, GetConfigFromJson001, TestSize.Level1)
81 {
82 std::string key = "";
83 std::string value = "";
84 common->GetConfigFromJson(key, value);
85 ASSERT_TRUE(common != nullptr);
86 }
87
88 /**
89 * @tc.name: GetConfigFromJson002
90 * @tc.desc: Test NfcSdkCommonTest GetConfigFromJson.
91 * @tc.type: FUNC
92 */
93 HWTEST_F(NfcSdkCommonTest, GetConfigFromJson002, TestSize.Level1)
94 {
95 std::string key = "test";
96 std::string value = "";
97 common->GetConfigFromJson(key, value);
98 ASSERT_TRUE(common != nullptr);
99 }
100
101 /**
102 * @tc.name: GetConfigFromJson003
103 * @tc.desc: Test NfcSdkCommonTest GetConfigFromJson.
104 * @tc.type: FUNC
105 */
106 HWTEST_F(NfcSdkCommonTest, GetConfigFromJson003, TestSize.Level1)
107 {
108 std::string key = "report_appId";
109 std::string value = "";
110 common->GetConfigFromJson(key, value);
111 ASSERT_TRUE(common != nullptr);
112 }
113 } // namespace TEST
114 } // namespace NFC
115 } // namespace OHOS