• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 
16 #include "devicestatus_module_test.h"
17 
18 #include <iostream>
19 #include <chrono>
20 #include <thread>
21 #include <gtest/gtest.h>
22 #include <if_system_ability_manager.h>
23 #include <ipc_skeleton.h>
24 #include <string_ex.h>
25 
26 #include "devicestatus_common.h"
27 #include "devicestatus_client.h"
28 
29 using namespace testing::ext;
30 using namespace OHOS::Msdp;
31 using namespace OHOS;
32 using namespace std;
33 
OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData & devicestatusData)34 void DevicestatusModuleTest::DevicestatusModuleTestCallback::OnDevicestatusChanged(const \
35     DevicestatusDataUtils::DevicestatusData& devicestatusData)
36 {
37     GTEST_LOG_(INFO) << "DevicestatusModuleTestCallback type: " << devicestatusData.type;
38     GTEST_LOG_(INFO) << "DevicestatusModuleTestCallback value: " << devicestatusData.value;
39     EXPECT_EQ(true, devicestatusData.type == DevicestatusDataUtils::DevicestatusType::TYPE_RELATIVE_STILL && \
40         devicestatusData.value >= DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << \
41         "DevicestatusModuleTestCallback failed";
42 }
43 
44 /**
45  * @tc.name: DevicestatusCallbackTest
46  * @tc.desc: test devicestatus callback in proxy
47  * @tc.type: FUNC
48  */
49 HWTEST_F (DevicestatusModuleTest, DevicestatusCallbackTest, TestSize.Level0)
50 {
51     DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_RELATIVE_STILL;
52     auto& devicestatusClient = DevicestatusClient::GetInstance();
53     sptr<IdevicestatusCallback> cb = new DevicestatusModuleTestCallback();
54     GTEST_LOG_(INFO) << "Start register";
55     devicestatusClient.SubscribeCallback(type, cb);
56     GTEST_LOG_(INFO) << "Cancell register";
57     devicestatusClient.UnSubscribeCallback(type, cb);
58 }
59 
60 /**
61  * @tc.name: GetDevicestatusDataTest
62  * @tc.desc: test get devicestatus data in proxy
63  * @tc.type: FUNC
64  */
65 HWTEST_F (DevicestatusModuleTest, GetDevicestatusDataTest001, TestSize.Level0)
66 {
67     DEV_HILOGI(SERVICE, "GetDevicestatusDataTest001 Enter");
68     DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_STILL;
69     auto& devicestatusClient = DevicestatusClient::GetInstance();
70     DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
71     GTEST_LOG_(INFO) << "type: " << data.type;
72     GTEST_LOG_(INFO) << "value: " << data.value;
73     EXPECT_EQ(true, data.type == DevicestatusDataUtils::DevicestatusType::TYPE_STILL && \
74         data.value >= DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusData failed";
75 }
76 
77 /**
78  * @tc.name: GetDevicestatusDataTest
79  * @tc.desc: test get devicestatus data in proxy
80  * @tc.type: FUNC
81  */
82 HWTEST_F (DevicestatusModuleTest, GetDevicestatusDataTest002, TestSize.Level0)
83 {
84     DEV_HILOGI(SERVICE, "GetDevicestatusDataTest002 Enter");
85     DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_RELATIVE_STILL;
86     auto& devicestatusClient = DevicestatusClient::GetInstance();
87     DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
88     GTEST_LOG_(INFO) << "type: " << data.type;
89     GTEST_LOG_(INFO) << "value: " << data.value;
90     EXPECT_EQ(true, data.type == DevicestatusDataUtils::DevicestatusType::TYPE_RELATIVE_STILL && \
91         data.value >= DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusData failed";
92 }
93 
94 /**
95  * @tc.name: GetDevicestatusDataTest
96  * @tc.desc: test get devicestatus data in proxy
97  * @tc.type: FUNC
98  */
99 HWTEST_F (DevicestatusModuleTest, GetDevicestatusDataTest003, TestSize.Level0)
100 {
101     DEV_HILOGI(SERVICE, "GetDevicestatusDataTest003 Enter");
102     DevicestatusDataUtils::DevicestatusType type = DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH;
103     auto& devicestatusClient = DevicestatusClient::GetInstance();
104     DevicestatusDataUtils::DevicestatusData data = devicestatusClient.GetDevicestatusData(type);
105     GTEST_LOG_(INFO) << "type: " << data.type;
106     GTEST_LOG_(INFO) << "value: " << data.value;
107     EXPECT_EQ(true, data.type == DevicestatusDataUtils::DevicestatusType::TYPE_CAR_BLUETOOTH && \
108         data.value == DevicestatusDataUtils::DevicestatusValue::VALUE_INVALID) << "GetDevicestatusData failed";
109 }
110