1 /* 2 * Copyright (C) 2021 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 "dhcp_s_define.h" 18 #include "common_util.h" 19 #include "dhcp_logger.h" 20 21 DEFINE_DHCPLOG_DHCP_LABEL("CommonUtilTest"); 22 23 using namespace testing::ext; 24 namespace OHOS { 25 namespace Wifi { 26 HWTEST(CommonUtilTest, LeftTirmTest, TestSize.Level1) 27 { 28 DHCP_LOGE("enter LeftTirmTest"); 29 char src1[] = " aabbccdd"; 30 LeftTrim(src1); 31 EXPECT_STREQ("aabbccdd", src1); 32 } 33 34 HWTEST(CommonUtilTest, RightTrimTest, TestSize.Level1) 35 { 36 char src1[] = "aabbccdd "; 37 RightTrim(src1); 38 EXPECT_STREQ("aabbccdd", src1); 39 } 40 41 HWTEST(CommonUtilTest, TrimStringTest, TestSize.Level1) 42 { 43 char src1[] = "aabbccdd "; 44 char src2[] = " aabbccdd"; 45 char src3[] = " aabbccdd "; 46 TrimString(src1); 47 TrimString(src2); 48 TrimString(src3); 49 EXPECT_STREQ("aabbccdd", src1); 50 EXPECT_STREQ("aabbccdd", src2); 51 EXPECT_STREQ("aabbccdd", src3); 52 } 53 54 HWTEST(CommonUtilTest, GetFilePathTest, TestSize.Level1) 55 { 56 const char *testPath = "/etc/dhcp/dhcp_server.conf"; 57 EXPECT_TRUE(GetFilePath(NULL) == NULL); 58 EXPECT_TRUE(GetFilePath("") == NULL); 59 EXPECT_STREQ("/etc/dhcp", GetFilePath(testPath)); 60 } 61 62 HWTEST(CommonUtilTest, GetLeaseFileTest, TestSize.Level1) 63 { 64 const char *leaseFile = "/etc/dhcp/dhcp_server.lease"; 65 const char *ifname = "test_if0"; 66 EXPECT_TRUE(GetLeaseFile(leaseFile, NULL) == NULL); 67 EXPECT_TRUE(GetLeaseFile(NULL, NULL) == NULL); 68 EXPECT_STREQ("/etc/dhcp/dhcp_server.lease.test_if0", GetLeaseFile(leaseFile, ifname)); 69 const char *leaseFile1 = ""; 70 const char *ifname1 = ""; 71 EXPECT_EQ(0, GetLeaseFile(leaseFile1, ifname1)); 72 } 73 74 HWTEST(CommonUtilTest, CreatePathTest, TestSize.Level1) 75 { 76 const char *testPath = "./test/data/testpath"; 77 ASSERT_EQ(RET_FAILED, CreatePath(NULL)); 78 ASSERT_EQ(RET_FAILED, CreatePath("")); 79 ASSERT_EQ(RET_SUCCESS, CreatePath(testPath)); 80 EXPECT_EQ(0, remove(testPath)); 81 } 82 83 HWTEST(CommonUtilTest, RemoveSpaceCharactersTest, TestSize.Level1) 84 { 85 char buf[] = "0"; 86 size_t bufSize = 0; 87 int result = RemoveSpaceCharacters(buf, bufSize); 88 EXPECT_EQ(0, result); 89 } 90 } 91 }