blob: d952b838aa60864e05ded7e9ef157883f9ec81fc [file] [log] [blame]
Christopher Wiley8decf952016-06-02 16:27:26 -07001/*
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 Hanc522ac82020-10-23 14:24:12 +090017#include "io_delegate.h"
18
Christopher Wiley8decf952016-06-02 16:27:26 -070019#include <string>
20
21#include <gtest/gtest.h>
22
Christopher Wiley8decf952016-06-02 16:27:26 -070023using std::string;
Jooyung Hanc522ac82020-10-23 14:24:12 +090024using testing::internal::CaptureStderr;
25using testing::internal::GetCapturedStderr;
Christopher Wiley8decf952016-06-02 16:27:26 -070026
27namespace android {
28namespace aidl {
29
30TEST(IoDelegateTest, CannotGetAbsolutePathFromEmptyString) {
Jooyung Hanc522ac82020-10-23 14:24:12 +090031 string expected_error =
32 "ERROR: : Giving up on finding an absolute path to represent the empty string.\n";
33 CaptureStderr();
Christopher Wiley8decf952016-06-02 16:27:26 -070034 string absolute_path;
35 EXPECT_FALSE(IoDelegate::GetAbsolutePath("", &absolute_path));
36 EXPECT_TRUE(absolute_path.empty());
Jooyung Hanc522ac82020-10-23 14:24:12 +090037 EXPECT_EQ(expected_error, GetCapturedStderr());
Christopher Wiley8decf952016-06-02 16:27:26 -070038}
39
40TEST(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 Wiley8decf952016-06-02 16:27:26 -070051} // namespace aidl
Steven Morelandf4c64df2019-07-29 19:54:04 -070052} // namespace android