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 <gtest/gtest.h>
17 #include "session_stack.h"
18 #include "avsession_log.h"
19 #include "system_ability_definition.h"
20 
21 #define private public
22 #include "avsession_service.h"
23 #undef private
24 
25 using namespace testing::ext;
26 using namespace OHOS::AVSession;
27 
28 class SessionStackTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 };
35 
SetUpTestCase()36 void SessionStackTest::SetUpTestCase()
37 {}
38 
TearDownTestCase()39 void SessionStackTest::TearDownTestCase()
40 {}
41 
SetUp()42 void SessionStackTest::SetUp()
43 {}
44 
TearDown()45 void SessionStackTest::TearDown()
46 {}
47 
48 /**
49 * @tc.name: RemoveSession001
50 * @tc.desc: verifying session stack remove session
51 * @tc.type: FUNC
52 * @tc.require: AR000H31KJ
53 */
54 static HWTEST(SessionStackTest, RemoveSession001, TestSize.Level1)
55 {
56     SLOGI("RemoveSession001 begin!");
57     OHOS::AppExecFwk::ElementName elementName;
58     AVSessionService* avSessionService_ = new AVSessionService(OHOS::AVSESSION_SERVICE_ID);
59     elementName.SetBundleName("test.ohos.avsession");
60     elementName.SetAbilityName("test.ability");
61     OHOS::sptr <AVSessionItem> item =
62         avSessionService_->CreateSessionInner("test", AVSession::SESSION_TYPE_AUDIO, false, elementName);
63     SLOGI("RemoveSession001 doSessionCreate done!");
64     sleep(1);
65     item->SetPid(1234);
66     item->SetUid(1234);
67     std::string sessionId = item->GetDescriptor().sessionId_;
68     SessionStack sessionStack;
69     sessionStack.AddSession(1234, elementName.GetAbilityName(), item);
70     OHOS::sptr<AVSessionItem> actual = sessionStack.RemoveSession(sessionId);
71     EXPECT_NE(actual, nullptr);
72     SLOGI("RemoveSession001 end!");
73 }