• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <thread>
17 #include <gtest/gtest.h>
18 #include <cstdint>
19 
20 #include "if_system_ability_manager.h"
21 #include "iservice_registry.h"
22 #include "idevice_info.h"
23 #include "parameter.h"
24 #include "system_ability_definition.h"
25 #include "sysparam_errno.h"
26 
27 using namespace std;
28 using namespace testing::ext;
29 using namespace OHOS;
30 
31 namespace initModuleTest {
32 class DeviceInfoModuleTest : public testing::Test {
33 public:
SetUpTestCase(void)34     static void SetUpTestCase(void) {};
TearDownTestCase(void)35     static void TearDownTestCase(void) {};
SetUp(void)36     void SetUp(void) {};
TearDown(void)37     void TearDown(void) {};
38 };
39 
40 HWTEST_F(DeviceInfoModuleTest, DeviceInfoGetUdid_001, TestSize.Level0)
41 {
42     GTEST_LOG_(INFO) << "DeviceInfoGetUdid_001 start";
43     char udid[65] = {}; // 65 udid len
44     int ret = AclGetDevUdid(udid, sizeof(udid));
45     EXPECT_EQ(ret, SYSPARAM_PERMISSION_DENIED);
46 
47     sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
48     BEGET_ERROR_CHECK(samgr != nullptr, return, "Get samgr failed");
49     sptr<IRemoteObject> object = samgr->GetSystemAbility(SYSPARAM_DEVICE_SERVICE_ID);
50     BEGET_ERROR_CHECK(object != nullptr, return, "Get deviceinfo manager object from samgr failed");
51 
52     std::this_thread::sleep_for(std::chrono::seconds(20)); // wait sa died 20s
53 
54     object = samgr->GetSystemAbility(SYSPARAM_DEVICE_SERVICE_ID);
55     BEGET_ERROR_CHECK(object == nullptr, return, "Get deviceinfo manager object from samgr failed");
56 
57     ret = AclGetDevUdid(udid, sizeof(udid));
58     EXPECT_EQ(ret, SYSPARAM_PERMISSION_DENIED);
59 
60     object = samgr->GetSystemAbility(SYSPARAM_DEVICE_SERVICE_ID);
61     BEGET_ERROR_CHECK(object != nullptr, return, "Get deviceinfo manager object from samgr failed");
62 
63     GTEST_LOG_(INFO) << "DeviceInfoGetUdid_001 end";
64 }
65 
66 HWTEST_F(DeviceInfoModuleTest, DeviceInfoGetSerial_001, TestSize.Level0)
67 {
68     GTEST_LOG_(INFO) << "DeviceInfoGetSerial_001 start";
69     const char *serial = AclGetSerial();
70     EXPECT_EQ(serial != nullptr, 1);
71 
72     sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
73     BEGET_ERROR_CHECK(samgr != nullptr, return, "Get samgr failed");
74     sptr<IRemoteObject> object = samgr->GetSystemAbility(SYSPARAM_DEVICE_SERVICE_ID);
75     BEGET_ERROR_CHECK(object != nullptr, return, "Get deviceinfo manager object from samgr failed");
76 
77     std::this_thread::sleep_for(std::chrono::seconds(20)); // wait sa died 20s
78 
79     object = samgr->GetSystemAbility(SYSPARAM_DEVICE_SERVICE_ID);
80     BEGET_ERROR_CHECK(object == nullptr, return, "Get deviceinfo manager object from samgr failed");
81 
82     serial = AclGetSerial();
83     EXPECT_EQ(serial != nullptr, 1);
84 
85     object = samgr->GetSystemAbility(SYSPARAM_DEVICE_SERVICE_ID);
86     BEGET_ERROR_CHECK(object != nullptr, return, "Get deviceinfo manager object from samgr failed");
87 
88     GTEST_LOG_(INFO) << "DeviceInfoGetSerial_001 end";
89 }
90 }