• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025  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 
16 #include <string>
17 #include <gtest/gtest.h>
18 #include "bundle_active_event_reporter.h"
19 #include "file_ex.h"
20 
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace DeviceUsageStats {
25 
26 class BundleActiveEventReporterTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30     void SetUp();
31     void TearDown();
32 };
33 
SetUpTestCase(void)34 void BundleActiveEventReporterTest::SetUpTestCase(void)
35 {
36 }
37 
TearDownTestCase(void)38 void BundleActiveEventReporterTest::TearDownTestCase(void)
39 {
40 }
41 
SetUp(void)42 void BundleActiveEventReporterTest::SetUp(void)
43 {
44 }
45 
TearDown(void)46 void BundleActiveEventReporterTest::TearDown(void)
47 {
48 }
49 
50 /*
51  * @tc.name: ReportFileSizeEvent_001
52  * @tc.desc: test the interface of bundle_active_event_reporter
53  * @tc.type: FUNC
54  * @tc.require: issuesIC2FBU
55  */
56 HWTEST_F(BundleActiveEventReporterTest, ReportFileSizeEvent_001, Function | MediumTest | TestSize.Level0)
57 {
58     BundleActiveEventReporter::GetInstance().isTaskSubmit_ = false;
59     BundleActiveEventReporter::GetInstance().ReportFileSizeEvent();
60     BundleActiveEventReporter::GetInstance().ReportFileSizeEvent();
61     EXPECT_TRUE(BundleActiveEventReporter::GetInstance().isTaskSubmit_);
62 }
63 
64 /*
65  * @tc.name: ReportFileSizeDaily_001
66  * @tc.desc: test the interface of bundle_active_event_reporter
67  * @tc.type: FUNC
68  * @tc.require: issuesIC2FBU
69  */
70 HWTEST_F(BundleActiveEventReporterTest, ReportFileSizeDaily_001, Function | MediumTest | TestSize.Level0)
71 {
72     BundleActiveEventReporter::GetInstance().fileSizeRecorderName_ = "test";
73     BundleActiveEventReporter::GetInstance().ReportFileSizeDaily();
74     BundleActiveEventReporter::GetInstance().fileSizeRecorderName_ =
75         "/data/service/el1/public/bundle_usage/file_size_report_time";
76     BundleActiveEventReporter::GetInstance().ReportFileSizeDaily();
77     BundleActiveEventReporter::GetInstance().ReportFileSizeDaily();
78     SaveStringToFile(BundleActiveEventReporter::GetInstance().fileSizeRecorderName_, std::to_string(-1));
79     BundleActiveEventReporter::GetInstance().ReportFileSizeDaily();
80     SaveStringToFile(BundleActiveEventReporter::GetInstance().fileSizeRecorderName_, std::to_string(1));
81     BundleActiveEventReporter::GetInstance().ReportFileSizeDaily();
82     std::string lastReportTime;
83     LoadStringFromFile(BundleActiveEventReporter::GetInstance().fileSizeRecorderName_, lastReportTime);
84     EXPECT_TRUE(!lastReportTime.empty());
85 }
86 
87 /*
88  * @tc.name: ReportFileSizeDaily_002
89  * @tc.desc: test the interface of bundle_active_event_reporter
90  * @tc.type: FUNC
91  * @tc.require: issuesIC2FBU
92  */
93 HWTEST_F(BundleActiveEventReporterTest, ReportFileSizeDaily_002, Function | MediumTest | TestSize.Level0)
94 {
95     BundleActiveEventReporter::GetInstance().ReportFileSizeInner();
96     std::string lastReportTime;
97     LoadStringFromFile(BundleActiveEventReporter::GetInstance().fileSizeRecorderName_, lastReportTime);
98     EXPECT_TRUE(!lastReportTime.empty());
99 }
100 }
101 }