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 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 "avsession_log.h"
18 #include "avsession_errors.h"
19 #include "accesstoken_kit.h"
20 #include "nativetoken_kit.h"
21 #include "token_setproc.h"
22 #include "iservice_registry.h"
23 #include "avmedia_description.h"
24 #include "av_file_descriptor.h"
25 #include "system_ability_definition.h"
26 #include "avsession_service.h"
27 #include "avsession_service_proxy.h"
28
29 using namespace OHOS;
30 using namespace OHOS::AVSession;
31 using namespace OHOS::Security::AccessToken;
32
33 class AVSessionServiceProxyTest : public testing::Test {
34 public:
35 static void SetUpTestCase(void);
36 static void TearDownTestCase(void);
37 void SetUp();
38 void TearDown();
39 };
40
SetUpTestCase()41 void AVSessionServiceProxyTest::SetUpTestCase()
42 {
43 }
44
TearDownTestCase()45 void AVSessionServiceProxyTest::TearDownTestCase()
46 {
47 }
48
SetUp()49 void AVSessionServiceProxyTest::SetUp()
50 {
51 }
52
TearDown()53 void AVSessionServiceProxyTest::TearDown()
54 {
55 }
56
57 /**
58 * @tc.name: GetAllSessionDescriptors001
59 * @tc.desc: Test GetAllSessionDescriptors
60 * @tc.type: FUNC
61 */
62 static HWTEST_F(AVSessionServiceProxyTest, GetAllSessionDescriptors001, testing::ext::TestSize.Level1)
63 {
64 SLOGI("GetAllSessionDescriptors001, start");
65
66 int32_t ret = AVSESSION_ERROR;
67
68 sptr<ISystemAbilityManager> mgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
69 if (mgr == nullptr) {
70 SLOGE("failed to get sa mgr");
71 }
72 sptr<IRemoteObject> sessionService = mgr->GetSystemAbility(AVSESSION_SERVICE_ID);
73 if (sessionService == nullptr) {
74 SLOGE("failed to get service");
75 }
76
77 std::string tag = "tag";
78 int32_t type = OHOS::AVSession::AVSession::SESSION_TYPE_VOICE_CALL;
79 std::string deviceId = "deviceId";
80 std::string bundleName = "bundleName";
81 std::string abilityName = "abilityName";
82 std::string moduleName = "moduleName";
83 AppExecFwk::ElementName elementName(deviceId, bundleName, abilityName, moduleName);
84
85 std::shared_ptr<AVSessionServiceProxy> avSessionServiceProxy =
86 std::make_shared<AVSessionServiceProxy>(sessionService);
87
88 std::shared_ptr<OHOS::AVSession::AVSession> session;
89 ret = avSessionServiceProxy->CreateSession(tag, type, elementName, session);
90 EXPECT_EQ(ret, AVSESSION_SUCCESS);
91 EXPECT_TRUE(session != nullptr);
92
93 std::vector<AVSessionDescriptor> descriptors;
94 ret = avSessionServiceProxy->GetAllSessionDescriptors(descriptors);
95 EXPECT_EQ(ret, AVSESSION_SUCCESS);
96 EXPECT_TRUE(descriptors[0].sessionId_ != "");
97
98 session = nullptr;
99 sessionService = nullptr;
100 avSessionServiceProxy = nullptr;
101 SLOGI("GetAllSessionDescriptors001, end");
102 }
103