1 /*
2 * Copyright (c) 2025 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 "securec.h"
17
18 #include "parameter_mock.h"
19
20
21 static const char* CHINESE_LANGUAGE = "zh-Hans";
22 static const char* TRADITIONAL_CHINESE_LANGUAGE = "zh-Hant";
23 static const char* NON_CHINESE_LANGUAGE = "English";
24 ParameterMock *ParameterMock::parameterMock = nullptr;
25
ParameterMock()26 ParameterMock::ParameterMock()
27 {
28 ParameterMock::parameterMock = this;
29 }
30
~ParameterMock()31 ParameterMock::~ParameterMock()
32 {
33 ParameterMock::parameterMock = nullptr;
34 }
35
GetMock()36 ParameterMock *ParameterMock::GetMock()
37 {
38 return parameterMock;
39 }
40
GetParameter(const char * key,const char * def,char * value,uint32_t len)41 int GetParameter(const char *key, const char *def, char *value, uint32_t len)
42 {
43 return ParameterMock::GetMock()->GetParameter(key, def, value, len);
44 }
45
ActionOfGetParameter1(const char * key,const char * def,char * value,uint32_t len)46 int ParameterMock::ActionOfGetParameter1(const char *key, const char *def, char *value, uint32_t len)
47 {
48 (void)key;
49 (void)def;
50 (void)value;
51 (void)len;
52 return -1;
53 }
54
ActionOfGetParameter2(const char * key,const char * def,char * value,uint32_t len)55 int ParameterMock::ActionOfGetParameter2(const char *key, const char *def, char *value, uint32_t len)
56 {
57 (void)key;
58 (void)def;
59 (void)strcpy_s(value, len, CHINESE_LANGUAGE);
60 return 1;
61 }
62
ActionOfGetParameter3(const char * key,const char * def,char * value,uint32_t len)63 int ParameterMock::ActionOfGetParameter3(const char *key, const char *def, char *value, uint32_t len)
64 {
65 (void)key;
66 (void)def;
67 (void)strcpy_s(value, len, TRADITIONAL_CHINESE_LANGUAGE);
68 return 1;
69 }
70
ActionOfGetParameter4(const char * key,const char * def,char * value,uint32_t len)71 int ParameterMock::ActionOfGetParameter4(const char *key, const char *def, char *value, uint32_t len)
72 {
73 (void)key;
74 (void)def;
75 (void)strcpy_s(value, len, NON_CHINESE_LANGUAGE);
76 return 1;
77 }