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 17 #include "hiview_shutdown_callback.h" 18 #include "usage_event_report.h" 19 20 using namespace testing::ext; 21 22 namespace OHOS { 23 namespace HiviewDFX { 24 class UsageEventReportTest : public testing::Test { 25 public: SetUpTestCase()26 static void SetUpTestCase() {} TearDownTestCase()27 static void TearDownTestCase() {} SetUp()28 void SetUp() {} TearDown()29 void TearDown() {} 30 }; 31 32 /** 33 * @tc.name: UsageEventReportTest001 34 * @tc.desc: check the plugin loading function. 35 * @tc.type: FUNC 36 * @tc.require: 37 */ 38 HWTEST_F(UsageEventReportTest, UsageEventReportTest001, TestSize.Level1) 39 { 40 UsageEventReport plugin; 41 // load plugin 42 plugin.OnLoad(); 43 EXPECT_TRUE(plugin.IsRunning()); 44 45 // start task 46 plugin.TimeOut(); 47 EXPECT_TRUE(plugin.IsRunning()); 48 49 // unload plugin 50 plugin.OnUnload(); 51 EXPECT_FALSE(plugin.IsRunning()); 52 } 53 54 /** 55 * @tc.name: UsageEventReportTest002 56 * @tc.desc: check functions to process events. 57 * @tc.type: FUNC 58 * @tc.require: 59 */ 60 HWTEST_F(UsageEventReportTest, UsageEventReportTest002, TestSize.Level1) 61 { 62 UsageEventReport plugin; 63 // load plugin 64 plugin.OnLoad(); 65 EXPECT_TRUE(plugin.IsRunning()); 66 67 std::shared_ptr<Event> event = nullptr; 68 plugin.OnEvent(event); 69 event = plugin.GetEvent(Event::SYS_EVENT); 70 ASSERT_NE(event, nullptr); 71 ASSERT_TRUE(plugin.OnEvent(event)); 72 73 plugin.SaveEventToDb(); 74 auto callback = new (std::nothrow) HiViewShutdownCallback(); 75 callback->OnAsyncShutdown(); 76 // unload plugin 77 plugin.OnUnload(); 78 EXPECT_FALSE(plugin.IsRunning()); 79 } 80 } // namespace HiviewDFX 81 } // namespace OHOS 82