1 /*
2 * Copyright (C) 2025 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 #define MLOG_TAG "MediaRefreshControllerServiceTest"
17
18 #include "media_refresh_controller_service_test.h"
19
20 #include "medialibrary_business_code.h"
21 #include "user_define_ipc.h"
22
23 #define protected public
24 #define private public
25 #include "media_refresh_controller_service.h"
26 #undef protected
27 #undef private
28
29 using namespace std;
30 using namespace testing::ext;
31
32 namespace OHOS {
33 namespace Media {
34
SetUpTestCase(void)35 void MediaRefreshControllerServiceTest::SetUpTestCase(void) {}
36
TearDownTestCase(void)37 void MediaRefreshControllerServiceTest::TearDownTestCase(void) {}
38
SetUp(void)39 void MediaRefreshControllerServiceTest::SetUp(void) {}
40
TearDown(void)41 void MediaRefreshControllerServiceTest::TearDown(void) {}
42
43 HWTEST_F(MediaRefreshControllerServiceTest, Accept_test_001, TestSize.Level0)
44 {
45 auto testService = std::make_shared<MediaRefreshControllerService>();
46 uint32_t businessCode = static_cast<uint32_t>(MediaLibraryBusinessCode::NOTIFY_FOR_RECHECK);
47 EXPECT_TRUE(testService->Accept(businessCode));
48 businessCode = static_cast<uint32_t>(MediaLibraryBusinessCode::MEDIA_BUSINESS_CODE_START);
49 EXPECT_FALSE(testService->Accept(businessCode));
50 }
51
52 HWTEST_F(MediaRefreshControllerServiceTest, OnRemoteRequest_test_001, TestSize.Level0)
53 {
54 auto testService = std::make_shared<MediaRefreshControllerService>();
55 MessageParcel data;
56 MessageParcel reply;
57 IPC::IPCContext context(MessageOption(), 0);
58 uint32_t businessCode = static_cast<uint32_t>(MediaLibraryBusinessCode::NOTIFY_FOR_RECHECK);
59 testService->OnRemoteRequest(businessCode, data, reply, context);
60 IPC::MediaRespVo<IPC::MediaEmptyObjVo> respVo;
61 ASSERT_EQ(respVo.Unmarshalling(reply), true);
62 EXPECT_EQ(respVo.GetErrCode(), 0);
63 }
64
65 HWTEST_F(MediaRefreshControllerServiceTest, OnRemoteRequest_test_002, TestSize.Level0)
66 {
67 auto testService = std::make_shared<MediaRefreshControllerService>();
68 MessageParcel data;
69 MessageParcel reply;
70 IPC::IPCContext context(MessageOption(), 0);
71 uint32_t businessCode = static_cast<uint32_t>(MediaLibraryBusinessCode::MEDIA_BUSINESS_CODE_START);
72 testService->OnRemoteRequest(businessCode, data, reply, context);
73 IPC::MediaRespVo<IPC::MediaEmptyObjVo> respVo;
74 ASSERT_EQ(respVo.Unmarshalling(reply), true);
75 EXPECT_EQ(respVo.GetErrCode(), E_IPC_SEVICE_NOT_FOUND);
76 }
77
78 HWTEST_F(MediaRefreshControllerServiceTest, GetPermissionPolicy_test_001, TestSize.Level0)
79 {
80 auto testService = std::make_shared<MediaRefreshControllerService>();
81 uint32_t businessCode = static_cast<uint32_t>(MediaLibraryBusinessCode::NOTIFY_FOR_RECHECK);
82 std::vector<std::vector<PermissionType>> permissionPolicy;
83 bool isBypass = false;
84 EXPECT_EQ(testService->GetPermissionPolicy(businessCode, permissionPolicy, isBypass), E_SUCCESS);
85 businessCode = static_cast<uint32_t>(MediaLibraryBusinessCode::MEDIA_BUSINESS_CODE_START);
86 EXPECT_EQ(testService->GetPermissionPolicy(businessCode, permissionPolicy, isBypass), E_FAIL);
87 }
88 } // namespace Media
89 } // namespace OHOS