1 /* 2 * Copyright (c) 2023 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 <iostream> 17 #include <string> 18 19 #include "gtest/gtest.h" 20 21 #if defined(PANDA_TARGET_UNIX) 22 #include "unix/libpandabase/file.h" 23 #elif defined(PANDA_TARGET_WINDOWS) 24 #include "windows/libpandabase/file.h" 25 #else 26 #error "Unsupported platform" 27 #endif 28 29 namespace panda::os::file { 30 31 #if defined(PANDA_TARGET_UNIX) 32 using File = panda::os::unix::file::File; 33 #elif defined(PANDA_TARGET_WINDOWS) 34 using File = panda::os::windows::file::File; 35 #endif 36 37 class FileTest : public testing::Test { 38 public: SetUpTestCase(void)39 static void SetUpTestCase(void) {}; TearDownTestCase(void)40 static void TearDownTestCase(void) {}; SetUp()41 void SetUp() {}; TearDown()42 void TearDown() {}; 43 }; 44 45 HWTEST_F(FileTest, get_extended_file_path, testing::ext::TestSize.Level0) 46 { 47 #if defined(PANDA_TARGET_UNIX) 48 const std::string pathStr = "/test/test/test/test/test/test/test/test/test/test/test/test/test/test/test/test"; 49 std::string filePath = pathStr; 50 std::string longFilePath = pathStr + pathStr + pathStr + pathStr + pathStr; 51 52 std::string expectFilePath = pathStr; 53 std::string expectLongFilePath = longFilePath; 54 55 EXPECT_EQ(File::GetExtendedFilePath(filePath), expectFilePath); 56 EXPECT_EQ(File::GetExtendedFilePath(longFilePath), expectLongFilePath); 57 #elif defined(PANDA_TARGET_WINDOWS) 58 const std::string pathStr = "\\test\\test\\test\\test\\test\\test\\test\\test\\test\\test\\test\\test\\test"; 59 std::string filePath = "D:"; 60 filePath += pathStr; 61 std::string longFilePath = "D:"; 62 longFilePath += pathStr + pathStr + pathStr + pathStr + pathStr; 63 64 std::string expectFilePath = "D:"; 65 expectFilePath += pathStr; 66 std::string expectLongFilePath = "\\\\?\\D:"; 67 expectLongFilePath += pathStr + pathStr + pathStr + pathStr + pathStr; 68 69 EXPECT_EQ(File::GetExtendedFilePath(filePath), expectFilePath); 70 EXPECT_EQ(File::GetExtendedFilePath(longFilePath), expectLongFilePath); 71 #endif 72 } 73 } // namespace panda 74