• 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 
18 #include "util/string_util.h"
19 
20 using namespace testing::ext;
21 using namespace panda::guard;
22 
23 /**
24  * @tc.name: string_util_test_001
25  * @tc.desc: test string util split function
26  * @tc.type: FUNC
27  * @tc.require:
28  */
29 HWTEST(StringUtilUnitTest, string_util_test_001, TestSize.Level4)
30 {
31     std::string delimiter = "#";
32 
33     std::string str = "##a#";
34     auto result = StringUtil::Split(str, delimiter);
35     EXPECT_EQ(result.size(), 1);
36     EXPECT_EQ(result[0], "a");
37 
38     str = "error";
39     result = StringUtil::Split(str, delimiter);
40     EXPECT_EQ(result.size(), 1);
41     EXPECT_EQ(result[0], "error");
42 }
43 
44 /**
45  * @tc.name: string_util_test_002
46  * @tc.desc: test string util strict split function
47  * @tc.type: FUNC
48  * @tc.require:
49  */
50 HWTEST(StringUtilUnitTest, string_util_test_002, TestSize.Level4)
51 {
52     std::string str = "##a#";
53     std::string delimiter = "#";
54     auto result = StringUtil::StrictSplit(str, delimiter);
55     EXPECT_EQ(result.size(), 4);
56     EXPECT_EQ(result[0], "");
57     EXPECT_EQ(result[1], "");
58     EXPECT_EQ(result[2], "a");
59     EXPECT_EQ(result[3], "");
60 }