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 "json_utils.h"
18 #include "avsession_log.h"
19 #include "av_session.h"
20 #include "avcontrol_command.h"
21 
22 using namespace testing::ext;
23 using namespace OHOS::AVSession;
24 
25 class RemoteUtilsTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp() override;
30     void TearDown() override;
31 };
32 
SetUpTestCase()33 void RemoteUtilsTest::SetUpTestCase()
34 {}
35 
TearDownTestCase()36 void RemoteUtilsTest::TearDownTestCase()
37 {}
38 
SetUp()39 void RemoteUtilsTest::SetUp()
40 {}
41 
TearDown()42 void RemoteUtilsTest::TearDown()
43 {}
44 
45 /**
46 * @tc.name: ConvertSessionType001
47 * @tc.desc: set sessionType_ as SESSION_TYPE_AUDIO
48 * @tc.type: FUNC
49 * @tc.require: AR000H55F4
50 */
51 HWTEST_F(RemoteUtilsTest, ConvertSessionType001, TestSize.Level1)
52 {
53     SLOGI("ConvertSessionType001 begin!");
54     std::string sessionInfo;
55     AVSessionDescriptor descriptor;
56     AVSessionDescriptor descriptorOut;
57     AVSessionBasicInfo basicInfo;
58     descriptor.sessionId_ = "123";
59     descriptor.sessionType_ = AVSession::SESSION_TYPE_AUDIO;
60     descriptor.elementName_.SetBundleName("test.ohos.avsession");
61     descriptor.elementName_.SetAbilityName("test.ability");
62     descriptor.sessionTag_ = "tag";
63     descriptor.isThirdPartyApp_ = false;
64     EXPECT_EQ(JsonUtils::SetSessionBasicInfo(sessionInfo, basicInfo), AVSESSION_SUCCESS);
65     EXPECT_EQ(JsonUtils::SetSessionDescriptor(sessionInfo, descriptor), AVSESSION_SUCCESS);
66     EXPECT_EQ(JsonUtils::GetSessionDescriptor(sessionInfo, descriptorOut), AVSESSION_SUCCESS);
67     SLOGI("ConvertSessionType001 end!");
68 }
69 
70 /**
71 * @tc.name: ConvertSessionType002
72 * @tc.desc: set sessionType_ as SESSION_TYPE_VIDEO
73 * @tc.type: FUNC
74 * @tc.require: AR000H55F4
75 */
76 HWTEST_F(RemoteUtilsTest, ConvertSessionType002, TestSize.Level1)
77 {
78     SLOGI("ConvertSessionType002 begin!");
79     std::string sessionInfo;
80     AVSessionDescriptor descriptor;
81     AVSessionDescriptor descriptorOut;
82     AVSessionBasicInfo basicInfo;
83     descriptor.sessionId_ = "123";
84     descriptor.sessionType_ = AVSession::SESSION_TYPE_VIDEO;
85     descriptor.elementName_.SetBundleName("test.ohos.avsession");
86     descriptor.elementName_.SetAbilityName("test.ability");
87     descriptor.sessionTag_ = "tag";
88     descriptor.isThirdPartyApp_ = false;
89     EXPECT_EQ(JsonUtils::SetSessionBasicInfo(sessionInfo, basicInfo), AVSESSION_SUCCESS);
90     EXPECT_EQ(JsonUtils::SetSessionDescriptor(sessionInfo, descriptor), AVSESSION_SUCCESS);
91     EXPECT_EQ(JsonUtils::GetSessionDescriptor(sessionInfo, descriptorOut), AVSESSION_SUCCESS);
92     SLOGI("ConvertSessionType002 end!");
93 }
94 
95 /**
96 * @tc.name: ConvertSessionType003
97 * @tc.desc: set sessionType_ as SESSION_TYPE_INVALID
98 * @tc.type: FUNC
99 * @tc.require: AR000H55F4
100 */
101 HWTEST_F(RemoteUtilsTest, ConvertSessionType003, TestSize.Level1)
102 {
103     SLOGI("ConvertSessionType003 begin!");
104     std::string sessionInfo;
105     AVSessionDescriptor descriptor;
106     AVSessionDescriptor descriptorOut;
107     AVSessionBasicInfo basicInfo;
108     descriptor.sessionId_ = "123";
109     descriptor.sessionType_ = AVSession::SESSION_TYPE_INVALID;
110     descriptor.elementName_.SetBundleName("test.ohos.avsession");
111     descriptor.elementName_.SetAbilityName("test.ability");
112     descriptor.sessionTag_ = "tag";
113     descriptor.isThirdPartyApp_ = false;
114     EXPECT_EQ(JsonUtils::SetSessionBasicInfo(sessionInfo, basicInfo), AVSESSION_SUCCESS);
115     EXPECT_EQ(JsonUtils::SetSessionDescriptor(sessionInfo, descriptor), AVSESSION_SUCCESS);
116     EXPECT_EQ(JsonUtils::GetSessionDescriptor(sessionInfo, descriptorOut), AVSESSION_SUCCESS);
117     SLOGI("ConvertSessionType003 end!");
118 }
119 
120 /**
121 * @tc.name: GetJsonCapability001
122 * @tc.desc: get metaData or playbackState or controlCommand capability
123 * @tc.type: FUNC
124 * @tc.require: AR000H55F4
125 */
126 HWTEST_F(RemoteUtilsTest, GetJsonCapability001, TestSize.Level1)
127 {
128     SLOGI("GetJsonCapability001 begin!");
129     std::vector<std::vector<int32_t>> localCapability(4);
130     localCapability[SESSION_DATA_META] = AVMetaData::localCapability;
131     localCapability[SESSION_DATA_PLAYBACK_STATE] = AVPlaybackState::localCapability;
132     localCapability[SESSION_DATA_CONTROL_COMMAND] = AVControlCommand::localCapability;
133     std::string jsonSinkCap;
134     EXPECT_EQ(JsonUtils::GetJsonCapability(localCapability, jsonSinkCap), AVSESSION_SUCCESS);
135     SLOGI("GetJsonCapability001 end!");
136 }