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 #include "app_data_parser.h"
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;
25 class AppDataParserTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp();
30 void TearDown();
31 public:
32 static constexpr const auto TECH_MASK = 4;
33 };
34
SetUpTestCase()35 void AppDataParserTest::SetUpTestCase()
36 {
37 std::cout << " SetUpTestCase AppDataParserTest." << std::endl;
38 }
39
TearDownTestCase()40 void AppDataParserTest::TearDownTestCase()
41 {
42 std::cout << " TearDownTestCase AppDataParserTest." << std::endl;
43 }
44
SetUp()45 void AppDataParserTest::SetUp()
46 {
47 std::cout << " SetUp AppDataParserTest." << std::endl;
48 }
49
TearDown()50 void AppDataParserTest::TearDown()
51 {
52 std::cout << " TearDown AppDataParserTest." << std::endl;
53 }
54
55 /**
56 * @tc.name: GetTechMask001
57 * @tc.desc: Test AppDataParser GetTechMask.
58 * @tc.type: FUNC
59 */
60 HWTEST_F(AppDataParserTest, GetTechMask001, TestSize.Level1)
61 {
62 AAFwk::Want want;
63 want.SetAction(KITS::ACTION_TAG_FOUND);
64 EventFwk::CommonEventData data;
65 data.SetWant(want);
66 const std::shared_ptr<EventFwk::CommonEventData> mdata =
67 std::make_shared<EventFwk::CommonEventData>(data);
68 AppDataParser parser = AppDataParser::GetInstance();
69 parser.HandleAppAddOrChangedEvent(nullptr);
70 parser.HandleAppAddOrChangedEvent(mdata);
71
72 parser.HandleAppRemovedEvent(nullptr);
73 parser.HandleAppRemovedEvent(mdata);
74
75 parser.InitAppList();
76
77 // no given tag technologies
78 std::vector<int> discTechList;
79 ASSERT_TRUE(parser.GetDispatchTagAppsByTech(discTechList).size() == 0);
80 }
81 /**
82 * @tc.name: GetTechMask002
83 * @tc.desc: Test AppDataParser GetTechMask.
84 * @tc.type: FUNC
85 */
86 HWTEST_F(AppDataParserTest, GetTechMask002, TestSize.Level1)
87 {
88 AppExecFwk::ElementName element;
89 element.SetBundleName(KITS::ACTION_TAG_FOUND);
90 AAFwk::Want want;
91 want.SetElement(element);
92 EventFwk::CommonEventData data;
93 data.SetWant(want);
94 const std::shared_ptr<EventFwk::CommonEventData> mdata =
95 std::make_shared<EventFwk::CommonEventData>(data);
96 AppDataParser parser = AppDataParser::GetInstance();
97 parser.HandleAppAddOrChangedEvent(mdata);
98
99 parser.HandleAppRemovedEvent(mdata);
100
101 std::vector<int> discTechList;
102 // no app installed, or has app installed to matched with the given tag technologies.
103 discTechList.push_back(static_cast<int>(KITS::TagTechnology::NFC_A_TECH));
104 discTechList.push_back(static_cast<int>(KITS::TagTechnology::NFC_ISODEP_TECH));
105 ASSERT_TRUE(parser.GetDispatchTagAppsByTech(discTechList).size() >= 0);
106 }
107 }
108 }
109 }