Adam Lesinski | 96917c2 | 2016-03-09 13:11:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Adam Lesinski | 96917c2 | 2016-03-09 13:11:25 -0800 | [diff] [blame] | 17 | #include "util/Files.h" |
| 18 | |
| 19 | #include <sstream> |
| 20 | |
Ryan Mitchell | 0ce8973 | 2018-10-03 09:20:57 -0700 | [diff] [blame] | 21 | #include "android-base/stringprintf.h" |
| 22 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 23 | #include "test/Test.h" |
| 24 | |
Ryan Mitchell | 0ce8973 | 2018-10-03 09:20:57 -0700 | [diff] [blame] | 25 | using ::android::base::StringPrintf; |
| 26 | |
Adam Lesinski | 96917c2 | 2016-03-09 13:11:25 -0800 | [diff] [blame] | 27 | namespace aapt { |
| 28 | namespace file { |
| 29 | |
Ryan Mitchell | 0ce8973 | 2018-10-03 09:20:57 -0700 | [diff] [blame] | 30 | #ifdef _WIN32 |
| 31 | constexpr const char sTestDirSep = '\\'; |
| 32 | #else |
| 33 | constexpr const char sTestDirSep = '/'; |
| 34 | #endif |
| 35 | |
Adam Lesinski | 96917c2 | 2016-03-09 13:11:25 -0800 | [diff] [blame] | 36 | class FilesTest : public ::testing::Test { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 37 | public: |
| 38 | void SetUp() override { |
| 39 | std::stringstream builder; |
| 40 | builder << "hello" << sDirSep << "there"; |
| 41 | expected_path_ = builder.str(); |
| 42 | } |
Adam Lesinski | 96917c2 | 2016-03-09 13:11:25 -0800 | [diff] [blame] | 43 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 44 | protected: |
| 45 | std::string expected_path_; |
Adam Lesinski | 96917c2 | 2016-03-09 13:11:25 -0800 | [diff] [blame] | 46 | }; |
| 47 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 48 | TEST_F(FilesTest, AppendPath) { |
| 49 | std::string base = "hello"; |
| 50 | AppendPath(&base, "there"); |
| 51 | EXPECT_EQ(expected_path_, base); |
Adam Lesinski | 96917c2 | 2016-03-09 13:11:25 -0800 | [diff] [blame] | 52 | } |
| 53 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 54 | TEST_F(FilesTest, AppendPathWithLeadingOrTrailingSeparators) { |
Ryan Mitchell | 0ce8973 | 2018-10-03 09:20:57 -0700 | [diff] [blame] | 55 | std::string base = StringPrintf("hello%c", sTestDirSep); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 56 | AppendPath(&base, "there"); |
| 57 | EXPECT_EQ(expected_path_, base); |
Adam Lesinski | 96917c2 | 2016-03-09 13:11:25 -0800 | [diff] [blame] | 58 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 59 | base = "hello"; |
Ryan Mitchell | 0ce8973 | 2018-10-03 09:20:57 -0700 | [diff] [blame] | 60 | AppendPath(&base, StringPrintf("%cthere", sTestDirSep)); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 61 | EXPECT_EQ(expected_path_, base); |
Adam Lesinski | 96917c2 | 2016-03-09 13:11:25 -0800 | [diff] [blame] | 62 | |
Ryan Mitchell | 0ce8973 | 2018-10-03 09:20:57 -0700 | [diff] [blame] | 63 | base = StringPrintf("hello%c", sTestDirSep); |
| 64 | AppendPath(&base, StringPrintf("%cthere", sTestDirSep)); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 65 | EXPECT_EQ(expected_path_, base); |
Adam Lesinski | 96917c2 | 2016-03-09 13:11:25 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 68 | } // namespace files |
| 69 | } // namespace aapt |