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 "timer.h"
20
21 #define private public
22 #define protected public
23 #include "params_config_operator.h"
24 #undef protected
25 #undef private
26
27 using namespace OHOS;
28 using namespace OHOS::AVSession;
29
30 static std::string g_errLog;
31
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)32 static void MyLogCallback(const LogType type, const LogLevel level,
33 const unsigned int domain, const char *tag, const char *msg)
34 {
35 g_errLog = msg;
36 }
37
38 class ParamsConfigOperatorTest : public testing::Test {
39 public:
40 static void SetUpTestCase(void);
41 static void TearDownTestCase(void);
42 void SetUp();
43 void TearDown();
44 };
45
SetUpTestCase()46 void ParamsConfigOperatorTest::SetUpTestCase()
47 {
48 }
49
TearDownTestCase()50 void ParamsConfigOperatorTest::TearDownTestCase()
51 {
52 }
53
SetUp()54 void ParamsConfigOperatorTest::SetUp()
55 {
56 }
57
TearDown()58 void ParamsConfigOperatorTest::TearDown()
59 {
60 }
61
62 /**
63 * @tc.name: InitConfig001
64 * @tc.desc: Test InitConfig
65 * @tc.type: FUNC
66 */
67 static HWTEST_F(ParamsConfigOperatorTest, InitConfig001, testing::ext::TestSize.Level1)
68 {
69 SLOGI("InitConfig001 begin!");
70 LOG_SetCallback(MyLogCallback);
71 auto paramsConfigOperator = ParamsConfigOperator::GetInstance();
72 paramsConfigOperator.InitConfig();
73 EXPECT_TRUE(g_errLog.find("xxx") == std::string::npos);
74 SLOGI("InitConfig001 end!");
75 }
76
77 /**
78 * @tc.name: GetValueIntByKey001
79 * @tc.desc: Test GetValueIntByKey
80 * @tc.type: FUNC
81 */
82 static HWTEST_F(ParamsConfigOperatorTest, GetValueIntByKey001, testing::ext::TestSize.Level1)
83 {
84 SLOGI("GetValueIntByKey001 begin!");
85 auto paramsConfigOperator = ParamsConfigOperator::GetInstance();
86 int32_t *value = nullptr;
87 int32_t ret = paramsConfigOperator.GetValueIntByKey("test1", value);
88 EXPECT_EQ(ret, AVSESSION_ERROR);
89 SLOGI("GetValueIntByKey001 end!");
90 }
91
92 /**
93 * @tc.name: GetValueIntByKey002
94 * @tc.desc: Test GetValueIntByKey
95 * @tc.type: FUNC
96 */
97 static HWTEST_F(ParamsConfigOperatorTest, GetValueIntByKey002, testing::ext::TestSize.Level1)
98 {
99 SLOGI("GetValueIntByKey002 begin!");
100 auto paramsConfigOperator = ParamsConfigOperator::GetInstance();
101 int32_t *value = nullptr;
102 paramsConfigOperator.configStringParams["test2"] = "test2";
103 int32_t ret = paramsConfigOperator.GetValueIntByKey("test2", value);
104 EXPECT_EQ(ret, AVSESSION_ERROR);
105 SLOGI("GetValueIntByKey002 end!");
106 }
107