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 <fcntl.h> 17 #include <gtest/gtest.h> 18 #include <memory> 19 #include <sys/ioctl.h> 20 #include "securec.h" 21 #include "daemon/flashd_utils.h" 22 #include "updater/updater.h" 23 #include "updater/updater_const.h" 24 25 using namespace std; 26 using namespace Flashd; 27 using namespace Updater; 28 using namespace testing::ext; 29 30 namespace { 31 32 class FLashServiceUnitTest : public testing::Test { 33 public: FLashServiceUnitTest()34 FLashServiceUnitTest() 35 { 36 std::cout<<"FLashServiceUnitTest()"; 37 } ~FLashServiceUnitTest()38 ~FLashServiceUnitTest() {} 39 SetUpTestCase(void)40 static void SetUpTestCase(void) {} TearDownTestCase(void)41 static void TearDownTestCase(void) {} SetUp()42 void SetUp() {} TearDown()43 void TearDown() {} TestBody()44 void TestBody() {} 45 }; 46 47 HWTEST_F(FLashServiceUnitTest, Split, TestSize.Level1) 48 { 49 std::string input = ""; 50 std::vector<std::string> output = Split(input, { "-f" }); 51 std::string res = ""; 52 for (auto s : output) { 53 res += s; 54 } 55 EXPECT_EQ("", res); 56 input = "flash updater updater.img"; 57 output = Split(input, { "-f" }); 58 res = ""; 59 for (auto s : output) { 60 res += s; 61 } 62 EXPECT_EQ("flashupdaterupdater.img", res); 63 } 64 65 HWTEST_F(FLashServiceUnitTest, GetPathRootTest, TestSize.Level1) 66 { 67 std::string path = "/"; 68 std::string root = GetPathRoot(path); 69 EXPECT_EQ("/", root); 70 71 path = ""; 72 root = GetPathRoot(path); 73 EXPECT_EQ("", root); 74 75 path = "/usr/local/bin"; 76 root = GetPathRoot(path); 77 EXPECT_EQ("/usr", root); 78 } 79 80 HWTEST_F(FLashServiceUnitTest, GetFileNameTest, TestSize.Level1) 81 { 82 std::string testStr = "data/test/test.zip"; 83 std::string res = GetFileName(testStr); 84 EXPECT_EQ("test.zip", res); 85 86 testStr = "D:\\test\\test.zip"; 87 res = GetFileName(testStr); 88 EXPECT_EQ("test.zip", res); 89 90 testStr = "test.zip"; 91 res = GetFileName(testStr); 92 EXPECT_EQ("", res); 93 } 94 } // namespace