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_source_stub_test.h"
17 
18 #include "accesstoken_kit.h"
19 #include "ipc_skeleton.h"
20 #include "tokenid_kit.h"
21 
22 #include "daudio_constants.h"
23 #include "daudio_errorcode.h"
24 #include "daudio_ipc_callback_proxy.h"
25 #include "daudio_ipc_interface_code.h"
26 #include "daudio_log.h"
27 
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace DistributedHardware {
SetUpTestCase(void)32 void DAudioSourceStubTest::SetUpTestCase(void) {}
33 
TearDownTestCase(void)34 void DAudioSourceStubTest::TearDownTestCase(void) {}
35 
SetUp()36 void DAudioSourceStubTest::SetUp()
37 {
38     uint32_t saId = 6666;
39     bool runOnCreate = true;
40     sourceStub_ = std::make_shared<DAudioSourceService>(saId, runOnCreate);
41 }
42 
TearDown()43 void DAudioSourceStubTest::TearDown()
44 {
45     sourceStub_ = nullptr;
46 }
47 
48 /**
49  * @tc.name: OnRemoteRequest_001
50  * @tc.desc: Verify the OnRemoteRequest function.
51  * @tc.type: FUNC
52  * @tc.require:
53  */
54 HWTEST_F(DAudioSourceStubTest, OnRemoteRequest_001, TestSize.Level1)
55 {
56     int32_t code = 0;
57     MessageParcel data;
58     MessageParcel reply;
59     MessageOption option;
60     EXPECT_EQ(ERR_DH_AUDIO_SA_INVALID_INTERFACE_TOKEN, sourceStub_->OnRemoteRequest(code, data, reply, option));
61 }
62 
63 /**
64  * @tc.name: VerifyPermission_001
65  * @tc.desc: Verify the VerifyPermission function.
66  * @tc.type: FUNC
67  * @tc.require:
68  */
69 HWTEST_F(DAudioSourceStubTest, VerifyPermission_001, TestSize.Level1)
70 {
71     EXPECT_EQ(false, sourceStub_->VerifyPermission());
72 }
73 
74 /**
75  * @tc.name: InitSourceInner_001
76  * @tc.desc: Verify the InitSourceInner function.
77  * @tc.type: FUNC
78  * @tc.require:
79  */
80 HWTEST_F(DAudioSourceStubTest, InitSourceInner_001, TestSize.Level1)
81 {
82     MessageParcel data;
83     MessageParcel reply;
84     MessageOption option;
85     EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED, sourceStub_->InitSourceInner(data, reply, option));
86     EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED, sourceStub_->ReleaseSourceInner(data, reply, option));
87 }
88 
89 /**
90  * @tc.name: RegisterDistributedHardwareInner_001
91  * @tc.desc: Verify the RegisterDistributedHardwareInner function.
92  * @tc.type: FUNC
93  * @tc.require:
94  */
95 HWTEST_F(DAudioSourceStubTest, RegisterDistributedHardwareInner_001, TestSize.Level1)
96 {
97     MessageParcel data;
98     MessageParcel reply;
99     MessageOption option;
100     sourceStub_->ConfigDistributedHardwareInner(data, reply, option);
101     sourceStub_->DAudioNotifyInner(data, reply, option);
102     EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED, sourceStub_->RegisterDistributedHardwareInner(data, reply, option));
103     EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED, sourceStub_->UnregisterDistributedHardwareInner(data, reply, option));
104 }
105 
106 /**
107  * @tc.name: ConfigDistributedHardwareInner_001
108  * @tc.desc: Verify the ConfigDistributedHardwareInner function.
109  * @tc.type: FUNC
110  * @tc.require:
111  */
112 HWTEST_F(DAudioSourceStubTest, ConfigDistributedHardwareInner_001, TestSize.Level1)
113 {
114     MessageParcel data;
115     MessageParcel reply;
116     MessageOption option;
117     EXPECT_EQ(ERR_DH_AUDIO_SA_PERMISSION_FAIED, sourceStub_->ConfigDistributedHardwareInner(data, reply, option));
118     EXPECT_EQ(DH_SUCCESS, sourceStub_->DAudioNotifyInner(data, reply, option));
119 }
120 } // DistributedHardware
121 } // OHOS
122