1 /*
2 * Copyright (c) 2022 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 "capacity_shutdown_test.h"
17 #include <csignal>
18 #include <iostream>
19 #include "battery_thread_test.h"
20 #include "power_supply_provider.h"
21
22 using namespace testing::ext;
23 using namespace OHOS::HDI::Battery::V1_1;
24 using namespace std;
25
26 namespace CapacityShutdownTest {
SetUpTestCase(void)27 void CapacityShutdownTest::SetUpTestCase(void)
28 {
29 }
30
TearDownTestCase(void)31 void CapacityShutdownTest::TearDownTestCase(void)
32 {
33 }
34
SetUp(void)35 void CapacityShutdownTest::SetUp(void)
36 {
37 }
38
TearDown(void)39 void CapacityShutdownTest::TearDown(void)
40 {
41 }
42
43 /**
44 * @tc.name: HdiServiceShutdown001
45 * @tc.desc: capacity shutdown test
46 * @tc.type: FUNC
47 */
48 HWTEST_F (CapacityShutdownTest, HdiServiceShutdown001, TestSize.Level1)
49 {
50 const int32_t CHARGE_STATE_NONE = 0;
51
52 ChargerThread ct;
53 ChargerThreadInitTest(ct);
54 SetChargeStateTest(CHARGE_STATE_NONE, ct);
55 int32_t state = GetChargeStateTest(ct);
56 ASSERT_TRUE(state == CHARGE_STATE_NONE);
57
58 HandleCapacityTest(4, ct); // Do not ShutDown
59
60 const int32_t CHARGE_STATE_ENABLE = 1;
61 SetChargeStateTest(CHARGE_STATE_ENABLE, ct);
62 state = GetChargeStateTest(ct);
63 ASSERT_TRUE(state == CHARGE_STATE_ENABLE);
64 HandleCapacityTest(4, ct); // Do not ShutDown
65
66 SetChargeStateTest(CHARGE_STATE_ENABLE, ct);
67 state = GetChargeStateTest(ct);
68 ASSERT_TRUE(state == CHARGE_STATE_ENABLE);
69 HandleCapacityTest(3, ct); // Do not ShutDown
70
71 SetChargeStateTest(CHARGE_STATE_NONE, ct);
72 state = GetChargeStateTest(ct);
73 ASSERT_TRUE(state == CHARGE_STATE_NONE);
74 if (false) {
75 HandleCapacityTest(3, ct); // ShutDown
76 }
77 }
78 }
79