blob: 202cc261ad8913c232e525c91b4b48c28c928125 [file] [log] [blame]
Adam Lesinski96917c22016-03-09 13:11:25 -08001/*
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 Lesinski96917c22016-03-09 13:11:25 -080017#include "util/Files.h"
18
19#include <sstream>
20
Ryan Mitchell0ce89732018-10-03 09:20:57 -070021#include "android-base/stringprintf.h"
22
Adam Lesinskice5e56e2016-10-21 17:56:45 -070023#include "test/Test.h"
24
Ryan Mitchell0ce89732018-10-03 09:20:57 -070025using ::android::base::StringPrintf;
26
Adam Lesinski96917c22016-03-09 13:11:25 -080027namespace aapt {
28namespace file {
29
Ryan Mitchell0ce89732018-10-03 09:20:57 -070030#ifdef _WIN32
31constexpr const char sTestDirSep = '\\';
32#else
33constexpr const char sTestDirSep = '/';
34#endif
35
Adam Lesinski96917c22016-03-09 13:11:25 -080036class FilesTest : public ::testing::Test {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070037 public:
38 void SetUp() override {
39 std::stringstream builder;
40 builder << "hello" << sDirSep << "there";
41 expected_path_ = builder.str();
42 }
Adam Lesinski96917c22016-03-09 13:11:25 -080043
Adam Lesinskice5e56e2016-10-21 17:56:45 -070044 protected:
45 std::string expected_path_;
Adam Lesinski96917c22016-03-09 13:11:25 -080046};
47
Adam Lesinskice5e56e2016-10-21 17:56:45 -070048TEST_F(FilesTest, AppendPath) {
49 std::string base = "hello";
50 AppendPath(&base, "there");
51 EXPECT_EQ(expected_path_, base);
Adam Lesinski96917c22016-03-09 13:11:25 -080052}
53
Adam Lesinskice5e56e2016-10-21 17:56:45 -070054TEST_F(FilesTest, AppendPathWithLeadingOrTrailingSeparators) {
Ryan Mitchell0ce89732018-10-03 09:20:57 -070055 std::string base = StringPrintf("hello%c", sTestDirSep);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070056 AppendPath(&base, "there");
57 EXPECT_EQ(expected_path_, base);
Adam Lesinski96917c22016-03-09 13:11:25 -080058
Adam Lesinskice5e56e2016-10-21 17:56:45 -070059 base = "hello";
Ryan Mitchell0ce89732018-10-03 09:20:57 -070060 AppendPath(&base, StringPrintf("%cthere", sTestDirSep));
Adam Lesinskice5e56e2016-10-21 17:56:45 -070061 EXPECT_EQ(expected_path_, base);
Adam Lesinski96917c22016-03-09 13:11:25 -080062
Ryan Mitchell0ce89732018-10-03 09:20:57 -070063 base = StringPrintf("hello%c", sTestDirSep);
64 AppendPath(&base, StringPrintf("%cthere", sTestDirSep));
Adam Lesinskice5e56e2016-10-21 17:56:45 -070065 EXPECT_EQ(expected_path_, base);
Adam Lesinski96917c22016-03-09 13:11:25 -080066}
67
Adam Lesinskice5e56e2016-10-21 17:56:45 -070068} // namespace files
69} // namespace aapt