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 <iostream> 18 19 #include "netstack_common_utils.h" 20 21 namespace OHOS { 22 namespace NetStack { 23 namespace CommonUtils { 24 namespace { 25 using namespace testing::ext; 26 static constexpr const char SPACE = ' '; 27 static constexpr const char *STATUS_LINE_COMMA = ","; 28 static constexpr const char *STATUS_LINE_SEP = " "; 29 static constexpr const size_t STATUS_LINE_ELEM_NUM = 2; 30 } // namespace 31 32 class NetStackCommonUtilsTest : public testing::Test { 33 public: SetUpTestCase()34 static void SetUpTestCase() {} 35 TearDownTestCase()36 static void TearDownTestCase() {} 37 SetUp()38 virtual void SetUp() {} 39 TearDown()40 virtual void TearDown() {} 41 }; 42 43 HWTEST_F(NetStackCommonUtilsTest, CommonUtils, TestSize.Level2) 44 { 45 std::string str = "The,weather,is,fine,today"; 46 std::vector<std::string> subStr = Split(str, STATUS_LINE_COMMA); 47 EXPECT_STREQ(subStr[0].data(), "The"); 48 EXPECT_STREQ(subStr[1].data(), "weather"); 49 EXPECT_STREQ(subStr[2].data(), "is"); 50 EXPECT_STREQ(subStr[3].data(), "fine"); 51 EXPECT_STREQ(subStr[4].data(), "today"); 52 EXPECT_EQ(subStr.size(), 5); 53 } 54 55 HWTEST_F(NetStackCommonUtilsTest, CommonUtils1, TestSize.Level2) 56 { 57 std::string str = " The weather is fine today"; 58 std::string subStr = Strip(str, SPACE); 59 EXPECT_STREQ(subStr.data(), "The weather is fine today"); 60 } 61 62 HWTEST_F(NetStackCommonUtilsTest, CommonUtils2, TestSize.Level2) 63 { 64 std::string str = "HOWDOYOUDO"; 65 std::string strLower = ToLower(str); 66 EXPECT_STREQ(strLower.data(), "howdoyoudo"); 67 } 68 69 HWTEST_F(NetStackCommonUtilsTest, CommonUtils3, TestSize.Level2) 70 { 71 std::string str = "fine today"; 72 std::vector<std::string> strList = Split(str, STATUS_LINE_SEP, STATUS_LINE_ELEM_NUM);; 73 74 EXPECT_STREQ(strList[0].data(), "fine"); 75 EXPECT_STREQ(strList[1].data(), "today"); 76 EXPECT_EQ(strList.size(), 2); 77 } 78 } // namespace CommonUtils 79 } // namespace NetStack 80 } // namespace OHOS