• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <string>
16 #include <iostream>
17 #include <gtest/gtest.h>
18 #include "parameter.h"
19 #include "system_ability_definition.h"
20 #include "if_system_ability_manager.h"
21 #include "iservice_registry.h"
22 #include "parcel.h"
23 #include "string_ex.h"
24 #include "device_info_kits.h"
25 #include "idevice_info.h"
26 #include "device_info_stub.h"
27 using namespace testing::ext;
28 using namespace std;
29 using namespace OHOS;
30 using namespace OHOS::device_info;
31 
32 const int UDID_LEN = 65;
33 namespace init_ut {
34 using DeviceInfoServicePtr = DeviceInfoService *;
35 class DeviceInfoUnittest : public testing::Test {
36 public:
DeviceInfoUnittest()37     DeviceInfoUnittest() {};
~DeviceInfoUnittest()38     virtual ~DeviceInfoUnittest() {};
SetUpTestCase(void)39     static void SetUpTestCase(void) {};
TearDownTestCase(void)40     static void TearDownTestCase(void) {};
SetUp()41     void SetUp() {};
TearDown()42     void TearDown() {};
TestBody(void)43     void TestBody(void) {};
GetDeviceInfoService()44     DeviceInfoServicePtr GetDeviceInfoService()
45     {
46         static DeviceInfoServicePtr deviceInfoServicePtr = nullptr;
47         if (deviceInfoServicePtr == nullptr) {
48             deviceInfoServicePtr = new DeviceInfoService(0, true);
49             if (deviceInfoServicePtr == nullptr) {
50                 return nullptr;
51             }
52             deviceInfoServicePtr->OnStart();
53         }
54         return deviceInfoServicePtr;
55     }
56 };
57 
58 HWTEST_F(DeviceInfoUnittest, GetDevUdidTest, TestSize.Level1)
59 {
60     char localDeviceId[UDID_LEN] = {0};
61     AclGetDevUdid(localDeviceId, UDID_LEN);
62     const char *serialNumber = AclGetSerial();
63     EXPECT_NE(nullptr, serialNumber);
64 
65     sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
66     ASSERT_NE(nullptr, samgr);
67     sptr<IRemoteObject> object = samgr->GetSystemAbility(SYSPARAM_DEVICE_SERVICE_ID);
68     ASSERT_NE(nullptr, samgr);
69 }
70 HWTEST_F(DeviceInfoUnittest, StubTest, TestSize.Level1)
71 {
72     string result;
73     DeviceInfoServicePtr deviceInfoService = GetDeviceInfoService();
74     ASSERT_NE(deviceInfoService, nullptr);
75     MessageParcel data;
76     MessageParcel reply;
77     MessageOption option;
78     data.WriteInterfaceToken(DeviceInfoStub::GetDescriptor());
79     deviceInfoService->OnRemoteRequest(IDeviceInfo::COMMAND_GET_UDID, data, reply, option);
80     data.WriteInterfaceToken(DeviceInfoStub::GetDescriptor());
81     deviceInfoService->OnRemoteRequest(IDeviceInfo::COMMAND_GET_SERIAL_ID, data, reply, option);
82     deviceInfoService->GetUdid(result);
83     deviceInfoService->GetSerialID(result);
84     deviceInfoService->OnStop();
85 }
86 }  // namespace init_ut
87