1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use sinkDev_ 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 "daudio_sink_stub_test.h"
17
18 #include "accesstoken_kit.h"
19 #include "ipc_skeleton.h"
20 #include "tokenid_kit.h"
21
22 #include "audio_event.h"
23 #include "daudio_constants.h"
24 #include "daudio_errorcode.h"
25 #include "daudio_ipc_interface_code.h"
26 #include "daudio_sink_ipc_callback_proxy.h"
27 #include "daudio_sink_load_callback.h"
28
29 using namespace testing::ext;
30
31 namespace OHOS {
32 namespace DistributedHardware {
SetUpTestCase(void)33 void DAudioSinkStubTest::SetUpTestCase(void) {}
34
TearDownTestCase(void)35 void DAudioSinkStubTest::TearDownTestCase(void) {}
36
SetUp()37 void DAudioSinkStubTest::SetUp()
38 {
39 uint32_t saId = 6666;
40 bool runOnCreate = true;
41 sinkStub_ = std::make_shared<DAudioSinkService>(saId, runOnCreate);
42 }
43
TearDown()44 void DAudioSinkStubTest::TearDown()
45 {
46 sinkStub_ = nullptr;
47 }
48
49 /**
50 * @tc.name: OnRemoteRequest_001
51 * @tc.desc: Verify the OnRemoteRequest function.
52 * @tc.type: FUNC
53 * @tc.require:
54 */
55 HWTEST_F(DAudioSinkStubTest, OnRemoteRequest_001, TestSize.Level1)
56 {
57 int32_t code = 0;
58 MessageParcel data;
59 MessageParcel reply;
60 MessageOption option;
61 EXPECT_EQ(ERR_DH_AUDIO_SA_INVALID_INTERFACE_TOKEN, sinkStub_->OnRemoteRequest(code, data, reply, option));
62 }
63
64 /**
65 * @tc.name: VerifyPermission_001
66 * @tc.desc: Verify the VerifyPermission function.
67 * @tc.type: FUNC
68 * @tc.require:
69 */
70 HWTEST_F(DAudioSinkStubTest, VerifyPermission_001, TestSize.Level1)
71 {
72 EXPECT_EQ(false, sinkStub_->VerifyPermission());
73 }
74
75 /**
76 * @tc.name: InitSinkInner_001
77 * @tc.desc: Verify the InitSinkInner function.
78 * @tc.type: FUNC
79 * @tc.require:
80 */
81 HWTEST_F(DAudioSinkStubTest, InitSinkInner_001, TestSize.Level1)
82 {
83 MessageParcel data;
84 MessageParcel reply;
85 MessageOption option;
86 EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED, sinkStub_->InitSinkInner(data, reply, option));
87 EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED, sinkStub_->ReleaseSinkInner(data, reply, option));
88 }
89
90 /**
91 * @tc.name: PauseDistributedHardwareInner_001
92 * @tc.desc: Verify the PauseDistributedHardwareInner function.
93 * @tc.type: FUNC
94 * @tc.require:
95 */
96 HWTEST_F(DAudioSinkStubTest, PauseDistributedHardwareInner_001, TestSize.Level1)
97 {
98 MessageParcel data;
99 MessageParcel reply;
100 MessageOption option;
101 EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED,
102 sinkStub_->PauseDistributedHardwareInner(data, reply, option));
103 EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED,
104 sinkStub_->ResumeDistributedHardwareInner(data, reply, option));
105 EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED,
106 sinkStub_->StopDistributedHardwareInner(data, reply, option));
107 }
108
109 /**
110 * @tc.name: SubscribeLocalHardwareInner_001
111 * @tc.desc: Verify the SubscribeLocalHardwareInner function.
112 * @tc.type: FUNC
113 * @tc.require:
114 */
115 HWTEST_F(DAudioSinkStubTest, SubscribeLocalHardwareInner_001, TestSize.Level1)
116 {
117 MessageParcel data;
118 MessageParcel reply;
119 MessageOption option;
120 EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED, sinkStub_->SubscribeLocalHardwareInner(data, reply, option));
121 EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED, sinkStub_->UnsubscribeLocalHardwareInner(data, reply, option));
122 EXPECT_EQ(DH_SUCCESS, sinkStub_->DAudioNotifyInner(data, reply, option));
123 }
124 } // DistributedHardware
125 } // OHOS
126