• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 <functional>
16 #include <chrono>
17 #include <thread>
18 #include <message_parcel.h>
19 
20 #include "gtest/gtest.h"
21 #include "singleton.h"
22 
23 #include "allow_type.h"
24 #include "standby_service_client.h"
25 #include "standby_service_proxy.h"
26 #include "standby_service_subscriber_stub.h"
27 #include "mock_sa_service.h"
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace DevStandbyMgr {
32 class StandbyServiceClientUnitTest : public testing::Test {
33 public:
SetUpTestCase()34     static void SetUpTestCase() {}
TearDownTestCase()35     static void TearDownTestCase() {}
SetUp()36     void SetUp() override {}
TearDown()37     void TearDown() override {}
38 };
39 
40 /**
41  * @tc.name: MockStandbyServiceClientUnitTest_001
42  * @tc.desc: test MockFunction.
43  * @tc.type: FUNC
44  * @tc.require:
45  */
46 HWTEST_F(StandbyServiceClientUnitTest, MockStandbyServiceClientUnitTest_001, TestSize.Level1)
47 {
48     MockSaService::MockGetSystemAbilityManager(false);
49     sptr<IStandbyServiceSubscriber> nullSubscriber = nullptr;
50     EXPECT_NE(StandbyServiceClient::GetInstance().SubscribeStandbyCallback(nullSubscriber), ERR_OK);
51     EXPECT_NE(StandbyServiceClient::GetInstance().UnsubscribeStandbyCallback(nullSubscriber), ERR_OK);
52     ResourceRequest* nullRequest = nullptr;
53     EXPECT_NE(StandbyServiceClient::GetInstance().ApplyAllowResource(nullRequest), ERR_OK);
54     EXPECT_NE(StandbyServiceClient::GetInstance().UnapplyAllowResource(nullRequest), ERR_OK);
55     std::vector<AllowInfo> allowInfoList;
56     nullRequest = nullptr;
57     EXPECT_NE(StandbyServiceClient::GetInstance().GetAllowList(AllowType::NETWORK, allowInfoList, 0), ERR_OK);
58     EXPECT_NE(StandbyServiceClient::GetInstance().GetAllowList(0, allowInfoList, 0), ERR_OK);
59     bool isStandby {false};
60     EXPECT_NE(StandbyServiceClient::GetInstance().IsDeviceInStandby(isStandby), ERR_OK);
61     uint32_t type = 1;
62     bool enable = true;
63     uint32_t interval = 300;
64     EXPECT_NE(StandbyServiceClient::GetInstance().SetNatInterval(type, enable, interval), ERR_OK);
65     StandbyServiceClient::GetInstance().ReportWorkSchedulerStatus(false, -1, "");
66     MockSaService::MockGetSystemAbilityManager(true);
67     StandbyServiceClient::GetInstance().IsDeviceInStandby(isStandby);
68     StandbyServiceClient::GetInstance().SetNatInterval(type, enable, interval);
69     StandbyServiceClient::GetInstance().ReportWorkSchedulerStatus(true, -1, "");
70     int64_t timestamp = 100;
71     EXPECT_NE(StandbyServiceClient::GetInstance().DelayHeartBeat(timestamp), ERR_OK);
72 }
73 }  // namespace DevStandbyMgr
74 }  // namespace OHOS
75