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 "xpower_event_test.h"
16
17 #include <iostream>
18 #include "xpower_event.h"
19 #include "xpower_event_common.h"
20 #include <parameters.h>
21
22 using namespace testing::ext;
23 using namespace OHOS::HiviewDFX;
24
SetUp()25 void ReportXPowerEventTest::SetUp()
26 {
27 /**
28 * @tc.setup: create work directories
29 */
30 printf("SetUp.\n");
31 }
SetUpTestCase()32 void ReportXPowerEventTest::SetUpTestCase()
33 {
34 printf("SetUpTestCase.\n");
35 }
36
TearDownTestCase()37 void ReportXPowerEventTest::TearDownTestCase()
38 {
39 printf("TearDownTestCase.\n");
40 }
41
TearDown()42 void ReportXPowerEventTest::TearDown()
43 {
44 printf("TearDown.\n");
45 }
46
47 /**
48 * @tc.name: ReportXPowerEventTest001
49 * @tc.desc: used to test ReportXPowerStackSysEvent
50 * @tc.type: FUNC
51 */
52 HWTEST_F(ReportXPowerEventTest, ReportXPowerEventTest001, TestSize.Level1)
53 {
54 printf("disable parameter and test.\n");
55 bool succ = OHOS::system::SetParameter(PROP_XPOWER_OPTIMIZE_ENABLE, "0");
56 ASSERT_TRUE(succ);
57 sleep(1);
58 int param = OHOS::system::GetIntParameter(PROP_XPOWER_OPTIMIZE_ENABLE, 0);
59 ASSERT_EQ(param, 0);
60 int ret = ReportXPowerStackSysEvent("XPOWER_HIVIEW_API_TEST", "info=1,succ=true");
61 ASSERT_EQ(ret, ERR_PROP_NOT_ENABLE);
62
63 printf("enable parameter and test.\n");
64 succ = OHOS::system::SetParameter(PROP_XPOWER_OPTIMIZE_ENABLE, "1");
65 ASSERT_TRUE(succ);
66 sleep(1);
67 param = OHOS::system::GetIntParameter(PROP_XPOWER_OPTIMIZE_ENABLE, 0);
68 ASSERT_EQ(param, 1);
69 ret = ReportXPowerStackSysEvent("XPOWER_HIVIEW_API_TEST", "info=2,succ=true");
70 ASSERT_EQ(ret, ERR_SUCCESS);
71
72 printf("enable parameter and test default info.\n");
73 ret = ReportXPowerStackSysEvent("XPOWER_HIVIEW_API_TEST");
74 ASSERT_EQ(ret, ERR_SUCCESS);
75 }
76