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
17 #include "io_delegate.h"
18
19 #include <string>
20
21 #include <gtest/gtest.h>
22
23 using std::string;
24 using testing::internal::CaptureStderr;
25 using testing::internal::GetCapturedStderr;
26
27 namespace android {
28 namespace aidl {
29
TEST(IoDelegateTest,CannotGetAbsolutePathFromEmptyString)30 TEST(IoDelegateTest, CannotGetAbsolutePathFromEmptyString) {
31 string expected_error =
32 "ERROR: : Giving up on finding an absolute path to represent the empty string.\n";
33 CaptureStderr();
34 string absolute_path;
35 EXPECT_FALSE(IoDelegate::GetAbsolutePath("", &absolute_path));
36 EXPECT_TRUE(absolute_path.empty());
37 EXPECT_EQ(expected_error, GetCapturedStderr());
38 }
39
TEST(IoDelegateTest,CurrentlyInfersLinuxAbsolutePath)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
51 } // namespace aidl
52 } // namespace android
53