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 "daudio_source_dev_ctrl_manager_test.h"
17 
18 #include "accesstoken_kit.h"
19 #include "nativetoken_kit.h"
20 #include "token_setproc.h"
21 
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace DistributedHardware {
SetUpTestCase(void)26 void DAudioSourceDevCtrlMgrTest::SetUpTestCase(void) {}
27 
TearDownTestCase(void)28 void DAudioSourceDevCtrlMgrTest::TearDownTestCase(void) {}
29 
SetUp(void)30 void DAudioSourceDevCtrlMgrTest::SetUp(void)
31 {
32     uint64_t tokenId;
33     const char** perms = new const char *[2];
34     perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC";
35     perms[1] = "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER";
36     NativeTokenInfoParams infoInstance = {
37         .dcapsNum = 0,
38         .permsNum = 2,
39         .aclsNum = 0,
40         .dcaps = nullptr,
41         .perms = perms,
42         .acls = nullptr,
43         .processName = "daudio_source_dev_ctrl_manager_test",
44         .aplStr = "system_basic",
45     };
46     tokenId = GetAccessTokenId(&infoInstance);
47     SetSelfTokenID(tokenId);
48 
49     std::string networkId = "devId";
50     std::shared_ptr<IAudioEventCallback> audioEventCallback = nullptr;
51     sourceDevCtrl_ = std::make_shared<DAudioSourceDevCtrlMgr>(networkId, audioEventCallback);
52 }
53 
TearDown(void)54 void DAudioSourceDevCtrlMgrTest::TearDown(void)
55 {
56     sourceDevCtrl_ = nullptr;
57 }
58 
59 /**
60  * @tc.name: SetUp_001
61  * @tc.desc: Verify the SetUp function.
62  * @tc.type: FUNC
63  * @tc.require: AR000H0E5F
64  */
65 HWTEST_F(DAudioSourceDevCtrlMgrTest, SetUp_001, TestSize.Level1)
66 {
67     EXPECT_EQ(DH_SUCCESS, sourceDevCtrl_->SetUp());
68 }
69 
70 /**
71  * @tc.name: Start_001
72  * @tc.desc: Verify the Start function.
73  * @tc.type: FUNC
74  * @tc.require: AR000H0E5F
75  */
76 HWTEST_F(DAudioSourceDevCtrlMgrTest, Start_001, TestSize.Level1)
77 {
78     EXPECT_EQ(DH_SUCCESS, sourceDevCtrl_->Start());
79 }
80 
81 /**
82  * @tc.name: Stop_001
83  * @tc.desc: Verify the Stop function.
84  * @tc.type: FUNC
85  * @tc.require: AR000H0E5F
86  */
87 HWTEST_F(DAudioSourceDevCtrlMgrTest, Stop_001, TestSize.Level1)
88 {
89     EXPECT_EQ(DH_SUCCESS, sourceDevCtrl_->Stop());
90 }
91 
92 /**
93  * @tc.name: Release_001
94  * @tc.desc: Verify the Release function.
95  * @tc.type: FUNC
96  * @tc.require: AR000H0E5F
97  */
98 HWTEST_F(DAudioSourceDevCtrlMgrTest, Release_001, TestSize.Level1)
99 {
100     EXPECT_EQ(DH_SUCCESS, sourceDevCtrl_->Release());
101 }
102 
103 /**
104  * @tc.name: IsOpened_001
105  * @tc.desc: Verify the IsOpened function.
106  * @tc.type: FUNC
107  * @tc.require: AR000H0E5F
108  */
109 HWTEST_F(DAudioSourceDevCtrlMgrTest, IsOpened_001, TestSize.Level1)
110 {
111     EXPECT_EQ(true, sourceDevCtrl_->IsOpened());
112 }
113 
114 /**
115  * @tc.name: SendAudioEvent_001
116  * @tc.desc: Verify the SendAudioEvent function.
117  * @tc.type: FUNC
118  * @tc.require: AR000H0E5F
119  */
120 HWTEST_F(DAudioSourceDevCtrlMgrTest, SendAudioEvent_001, TestSize.Level1)
121 {
122     AudioEvent event;
123     EXPECT_EQ(DH_SUCCESS, sourceDevCtrl_->SendAudioEvent(event));
124 }
125 } // namespace DistributedHardware
126 } // namespace OHOS
127