• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 
16 #include "gtest/gtest.h"
17 #include "gmock/gmock.h"
18 
19 #include "storage_manager_ipc_interface_code.h"
20 #include "storage_manager_proxy.h"
21 #include "ipc/storage_manager_stub.h"
22 #include "storage_manager_stub_mock.h"
23 
24 #include "storage_service_errno.h"
25 #include "storage_service_log.h"
26 
27 namespace OHOS {
28 namespace StorageManager {
29 using namespace testing::ext;
30 
31 namespace {
32     int32_t g_code[] = {
33         static_cast<int32_t>(StorageManagerInterfaceCode::PREPARE_ADD_USER),
34         static_cast<int32_t>(StorageManagerInterfaceCode::REMOVE_USER),
35         static_cast<int32_t>(StorageManagerInterfaceCode::PREPARE_START_USER),
36         static_cast<int32_t>(StorageManagerInterfaceCode::STOP_USER),
37         static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_VOLUME_CREATED),
38         static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_VOLUME_MOUNTED),
39         static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_VOLUME_STATE_CHANGED),
40         static_cast<int32_t>(StorageManagerInterfaceCode::MOUNT),
41         static_cast<int32_t>(StorageManagerInterfaceCode::UNMOUNT),
42         static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_DISK_CREATED),
43         static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_DISK_DESTROYED),
44         static_cast<int32_t>(StorageManagerInterfaceCode::PARTITION),
45         static_cast<int32_t>(StorageManagerInterfaceCode::CREATE_USER_KEYS),
46         static_cast<int32_t>(StorageManagerInterfaceCode::DELETE_USER_KEYS),
47         static_cast<int32_t>(StorageManagerInterfaceCode::UPDATE_USER_AUTH),
48         static_cast<int32_t>(StorageManagerInterfaceCode::ACTIVE_USER_KEY),
49         static_cast<int32_t>(StorageManagerInterfaceCode::INACTIVE_USER_KEY),
50         static_cast<int32_t>(StorageManagerInterfaceCode::UPDATE_KEY_CONTEXT),
51         static_cast<int32_t>(StorageManagerInterfaceCode::GET_VOL_BY_UUID),
52         static_cast<int32_t>(StorageManagerInterfaceCode::GET_VOL_BY_ID),
53         static_cast<int32_t>(StorageManagerInterfaceCode::SET_VOL_DESC),
54         static_cast<int32_t>(StorageManagerInterfaceCode::FORMAT),
55         static_cast<int32_t>(StorageManagerInterfaceCode::GET_DISK_BY_ID),
56         static_cast<int32_t>(StorageManagerInterfaceCode::GET_TOTAL),
57         static_cast<int32_t>(StorageManagerInterfaceCode::GET_FREE),
58         static_cast<int32_t>(StorageManagerInterfaceCode::GET_SYSTEM_SIZE),
59         static_cast<int32_t>(StorageManagerInterfaceCode::GET_TOTAL_SIZE),
60         static_cast<int32_t>(StorageManagerInterfaceCode::GET_FREE_SIZE),
61         static_cast<int32_t>(StorageManagerInterfaceCode::GET_BUNDLE_STATUS),
62         static_cast<int32_t>(StorageManagerInterfaceCode::GET_CURR_USER_STATS),
63         static_cast<int32_t>(StorageManagerInterfaceCode::GET_USER_STATS),
64         static_cast<int32_t>(StorageManagerInterfaceCode::GET_USER_STATS_BY_TYPE),
65         static_cast<int32_t>(StorageManagerInterfaceCode::GET_ALL_VOLUMES),
66         static_cast<int32_t>(StorageManagerInterfaceCode::GET_ALL_DISKS),
67         static_cast<int32_t>(StorageManagerInterfaceCode::LOCK_USER_SCREEN),
68         static_cast<int32_t>(StorageManagerInterfaceCode::UNLOCK_USER_SCREEN),
69         static_cast<int32_t>(StorageManagerInterfaceCode::GENERATE_APP_KEY),
70         static_cast<int32_t>(StorageManagerInterfaceCode::DELETE_APP_KEY),
71         static_cast<int32_t>(StorageManagerInterfaceCode::LOCK_SCREEN_STATUS),
72         static_cast<int32_t>(StorageManagerInterfaceCode::SET_BUNDLE_QUOTA),
73         static_cast<int32_t>(StorageManagerInterfaceCode::CREATE_SHARE_FILE),
74         static_cast<int32_t>(StorageManagerInterfaceCode::DELETE_SHARE_FILE),
75         static_cast<int32_t>(StorageManagerInterfaceCode::GET_USER_STATS_BY_TYPE),
76         static_cast<int32_t>(StorageManagerInterfaceCode::UPDATE_MEM_PARA),
77         static_cast<int32_t>(StorageManagerInterfaceCode::GET_BUNDLE_STATS_INCREASE),
78         static_cast<int32_t>(StorageManagerInterfaceCode::MOUNT_DFS_DOCS),
79         static_cast<int32_t>(StorageManagerInterfaceCode::UMOUNT_DFS_DOCS)
80     };
81 
82 } // namespace
83 
84 class StorageManagerStubTest : public testing::Test {
85 public:
SetUpTestCase(void)86     static void SetUpTestCase(void) {};
TearDownTestCase(void)87     static void TearDownTestCase(void) {};
SetUp()88     void SetUp() {};
TearDown()89     void TearDown() {};
90 };
91 
92 /**
93  * @tc.name: Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001
94  * @tc.desc: Verify the OnRemoteRequest function.
95  * @tc.type: FUNC
96  * @tc.require: AR000GK4HB
97  */
98 HWTEST_F(StorageManagerStubTest, Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001, TestSize.Level1)
99 {
100     GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001 start";
101 
102     StorageManagerStubMock mock;
103 
104     for (auto c : g_code) {
105         MessageParcel data;
106         MessageParcel reply;
107         MessageOption option(MessageOption::TF_SYNC);
108         bool bRet = data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor());
109         EXPECT_TRUE(bRet) << "write token error";
110         int32_t ret = mock.OnRemoteRequest(c, data, reply, option);
111         EXPECT_EQ(ret, E_PERMISSION_DENIED);
112     }
113 
114     GTEST_LOG_(INFO) << "Storage_Manager_StorageManagerStubTest_OnRemoteRequest_001 end";
115 }
116 } // STORAGE_MANAGER
117 } // OHOS
118