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 <string>
18 
19 #include <gtest/gtest.h>
20 
21 #include "io_delegate.h"
22 
23 using std::string;
24 
25 namespace android {
26 namespace aidl {
27 
TEST(IoDelegateTest,CannotGetAbsolutePathFromEmptyString)28 TEST(IoDelegateTest, CannotGetAbsolutePathFromEmptyString) {
29   string absolute_path;
30   EXPECT_FALSE(IoDelegate::GetAbsolutePath("", &absolute_path));
31   EXPECT_TRUE(absolute_path.empty());
32 }
33 
TEST(IoDelegateTest,CurrentlyInfersLinuxAbsolutePath)34 TEST(IoDelegateTest, CurrentlyInfersLinuxAbsolutePath) {
35   string absolute_path;
36   EXPECT_TRUE(IoDelegate::GetAbsolutePath("foo", &absolute_path));
37   ASSERT_FALSE(absolute_path.empty());
38   // Should find our desired file at the end of |absolute_path|
39   // But we don't know the prefix, since it's the current working directory
40   EXPECT_TRUE(absolute_path.rfind("/foo") == absolute_path.length() - 4);
41   // Whatever our current working directory, the path is absolute.
42   EXPECT_EQ(absolute_path[0], '/');
43 }
44 
45 }  // namespace aidl
46 }  // namespace android
47