Christopher Wiley | 8decf95 | 2016-06-02 16:27:26 -0700 | [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 | |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 17 | #include "io_delegate.h" |
| 18 | |
Christopher Wiley | 8decf95 | 2016-06-02 16:27:26 -0700 | [diff] [blame] | 19 | #include <string> |
| 20 | |
| 21 | #include <gtest/gtest.h> |
| 22 | |
Christopher Wiley | 8decf95 | 2016-06-02 16:27:26 -0700 | [diff] [blame] | 23 | using std::string; |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 24 | using testing::internal::CaptureStderr; |
| 25 | using testing::internal::GetCapturedStderr; |
Christopher Wiley | 8decf95 | 2016-06-02 16:27:26 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | namespace aidl { |
| 29 | |
| 30 | TEST(IoDelegateTest, CannotGetAbsolutePathFromEmptyString) { |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 31 | string expected_error = |
| 32 | "ERROR: : Giving up on finding an absolute path to represent the empty string.\n"; |
| 33 | CaptureStderr(); |
Christopher Wiley | 8decf95 | 2016-06-02 16:27:26 -0700 | [diff] [blame] | 34 | string absolute_path; |
| 35 | EXPECT_FALSE(IoDelegate::GetAbsolutePath("", &absolute_path)); |
| 36 | EXPECT_TRUE(absolute_path.empty()); |
Jooyung Han | c522ac8 | 2020-10-23 14:24:12 +0900 | [diff] [blame] | 37 | EXPECT_EQ(expected_error, GetCapturedStderr()); |
Christopher Wiley | 8decf95 | 2016-06-02 16:27:26 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | TEST(IoDelegateTest, CurrentlyInfersLinuxAbsolutePath) { |
| 41 | string absolute_path; |
| 42 | EXPECT_TRUE(IoDelegate::GetAbsolutePath("foo", &absolute_path)); |
| 43 | ASSERT_FALSE(absolute_path.empty()); |
| 44 | // Should find our desired file at the end of |absolute_path| |
| 45 | // But we don't know the prefix, since it's the current working directory |
| 46 | EXPECT_TRUE(absolute_path.rfind("/foo") == absolute_path.length() - 4); |
| 47 | // Whatever our current working directory, the path is absolute. |
| 48 | EXPECT_EQ(absolute_path[0], '/'); |
| 49 | } |
| 50 | |
Christopher Wiley | 8decf95 | 2016-06-02 16:27:26 -0700 | [diff] [blame] | 51 | } // namespace aidl |
Steven Moreland | f4c64df | 2019-07-29 19:54:04 -0700 | [diff] [blame] | 52 | } // namespace android |