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