• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Level0)
63 {
64     SLOGI("GetAllSessionDescriptors001, start");
65 
66     int32_t ret = AVSESSION_ERROR;
67 
68     sptr<ISystemAbilityManager> mgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
69     ASSERT_NE(mgr, nullptr);
70     sptr<IRemoteObject> sessionService = mgr->GetSystemAbility(AVSESSION_SERVICE_ID);
71     ASSERT_NE(sessionService, nullptr);
72 
73     std::string tag = "tag";
74     int32_t type = OHOS::AVSession::AVSession::SESSION_TYPE_VOICE_CALL;
75     std::string deviceId = "deviceId";
76     std::string bundleName = "bundleName";
77     std::string abilityName = "abilityName";
78     std::string moduleName = "moduleName";
79     AppExecFwk::ElementName elementName(deviceId, bundleName, abilityName, moduleName);
80 
81     std::shared_ptr<AVSessionServiceProxy> avSessionServiceProxy =
82         std::make_shared<AVSessionServiceProxy>(sessionService);
83 
84     std::shared_ptr<OHOS::AVSession::AVSession> session;
85     ret = avSessionServiceProxy->CreateSession(tag, type, elementName, session);
86     EXPECT_EQ(ret, AVSESSION_SUCCESS);
87     EXPECT_TRUE(session != nullptr);
88 
89     std::vector<AVSessionDescriptor> descriptors;
90     ret = avSessionServiceProxy->GetAllSessionDescriptors(descriptors);
91     EXPECT_EQ(ret, AVSESSION_SUCCESS);
92     EXPECT_TRUE(descriptors[0].sessionId_ != "");
93 
94     session = nullptr;
95     sessionService = nullptr;
96     avSessionServiceProxy = nullptr;
97     SLOGI("GetAllSessionDescriptors001, end");
98 }
99