• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <iostream>
16 
17 #include <gtest/gtest.h>
18 
19 #include "privacy_controller.h"
20 #include "sys_event.h"
21 
22 using namespace testing::ext;
23 using namespace OHOS::HiviewDFX;
24 
25 class PrivacyControllerTest : public testing::Test {
26 public:
SetUp()27     void SetUp() {}
TearDown()28     void TearDown() {}
29 };
30 
31 namespace {
32 const std::string CRITICAL_LEVEL = "CRITICAL";
33 constexpr uint8_t PUBLIC_PRIVACY = 4;
34 
CreateEvent(const std::string & level,uint8_t privacy,SysEventCreator::EventType type)35 std::shared_ptr<Event> CreateEvent(const std::string& level, uint8_t privacy, SysEventCreator::EventType type)
36 {
37     SysEventCreator sysEventCreator("DEFAULT_DOMAIN", "DEFAULT_NAME", type);
38     auto event = std::make_shared<SysEvent>("", nullptr, sysEventCreator);
39     event->SetLevel(level);
40     event->SetPrivacy(privacy);
41     return event;
42 }
43 }
44 
45 /**
46  * @tc.name: PrivacyControllerTest001
47  * @tc.desc: plugin test.
48  * @tc.type: FUNC
49  * @tc.require: issueI9TJGM
50  */
51 HWTEST_F(PrivacyControllerTest, PrivacyControllerTest001, TestSize.Level0)
52 {
53     PrivacyController plugin;
54     std::shared_ptr<Event> event = nullptr;
55     plugin.OnConfigUpdate("", "");
56     ASSERT_FALSE(plugin.OnEvent(event));
57 
58     auto event1 = CreateEvent(CRITICAL_LEVEL, PUBLIC_PRIVACY, SysEventCreator::FAULT);
59     ASSERT_TRUE(plugin.OnEvent(event1));
60 
61     auto invalidParams = std::make_shared<std::map<std::string, std::shared_ptr<EventParamInfo>>>();
62     auto sysEvent1 = std::static_pointer_cast<SysEvent>(event1);
63     ASSERT_FALSE(sysEvent1 == nullptr);
64     sysEvent1->SetInvalidParams(invalidParams);
65     ASSERT_TRUE(plugin.OnEvent(event1));
66 
67     auto paramInfo = std::make_shared<EventParamInfo>("safe_bundle_name_list", 0);
68     invalidParams->insert(std::make_pair("BUNDLE_NAME", paramInfo));
69     ASSERT_TRUE(plugin.OnEvent(event1));
70 }
71