1 /*
2 * Copyright (c) 2023 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_preferences.h"
19
20 namespace OHOS {
21 namespace NFC {
22 namespace TEST {
23 using namespace testing::ext;
24 using namespace OHOS::NFC;
25 class NfcPreferencesTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp();
30 void TearDown();
31 };
32
SetUpTestCase()33 void NfcPreferencesTest::SetUpTestCase()
34 {
35 std::cout << " SetUpTestCase NfcPreferencesTest." << std::endl;
36 }
37
TearDownTestCase()38 void NfcPreferencesTest::TearDownTestCase()
39 {
40 std::cout << " TearDownTestCase NfcPreferencesTest." << std::endl;
41 }
42
SetUp()43 void NfcPreferencesTest::SetUp()
44 {
45 std::cout << " SetUp NfcPreferencesTest." << std::endl;
46 }
47
TearDown()48 void NfcPreferencesTest::TearDown()
49 {
50 std::cout << " TearDown NfcPreferencesTest." << std::endl;
51 }
52
53 /**
54 * @tc.name: SetInt001
55 * @tc.desc: Test NfcPreferencesTest SetInt.
56 * @tc.type: FUNC
57 */
58 HWTEST_F(NfcPreferencesTest, SetInt001, TestSize.Level1)
59 {
60 std::string key = "123";
61 int value = 456;
62 std::shared_ptr<NfcPreferences> nfcPreferences = std::make_shared<NfcPreferences>();
63 nfcPreferences->SetInt(key, value);
64 int getNfcState = nfcPreferences->GetNfcState();
65 ASSERT_TRUE(getNfcState != 0);
66 }
67
68 /**
69 * @tc.name: UpdateNfcState001
70 * @tc.desc: Test NfcPreferencesTest UpdateNfcState.
71 * @tc.type: FUNC
72 */
73 HWTEST_F(NfcPreferencesTest, UpdateNfcState001, TestSize.Level1)
74 {
75 int newState = 1;
76 std::shared_ptr<NfcPreferences> nfcPreferences = std::make_shared<NfcPreferences>();
77 nfcPreferences->UpdateNfcState(newState);
78 int getNfcState = nfcPreferences->GetNfcState();
79 ASSERT_TRUE(getNfcState != 0);
80 }
81
82 /**
83 * @tc.name: GetNfcState001
84 * @tc.desc: Test NfcPreferencesTest GetNfcState.
85 * @tc.type: FUNC
86 */
87 HWTEST_F(NfcPreferencesTest, GetNfcState001, TestSize.Level1)
88 {
89 std::shared_ptr<NfcPreferences> nfcPreferences = std::make_shared<NfcPreferences>();
90 int getNfcState = nfcPreferences->GetNfcState();
91 ASSERT_TRUE(getNfcState != 0);
92 }
93 }
94 }
95 }