• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright (C) 2018 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 <utility>
18  
19  #include "androidfw/PosixUtils.h"
20  
21  #include "TestHelpers.h"
22  
23  using ::testing::IsNull;
24  using ::testing::NotNull;
25  
26  namespace android {
27  namespace util {
28  
TEST(PosixUtilsTest,AbsolutePathToBinary)29  TEST(PosixUtilsTest, AbsolutePathToBinary) {
30    const auto result = ExecuteBinary({"/bin/date", "--help"});
31    ASSERT_THAT(result, NotNull());
32    ASSERT_EQ(result->status, 0);
33    ASSERT_EQ(result->stdout.find("usage: date "), 0);
34  }
35  
TEST(PosixUtilsTest,RelativePathToBinary)36  TEST(PosixUtilsTest, RelativePathToBinary) {
37    const auto result = ExecuteBinary({"date", "--help"});
38    ASSERT_THAT(result, NotNull());
39    ASSERT_EQ(result->status, 0);
40    ASSERT_EQ(result->stdout.find("usage: date "), 0);
41  }
42  
TEST(PosixUtilsTest,BadParameters)43  TEST(PosixUtilsTest, BadParameters) {
44    const auto result = ExecuteBinary({"/bin/date", "--this-parameter-is-not-supported"});
45    ASSERT_THAT(result, NotNull());
46    ASSERT_NE(result->status, 0);
47  }
48  
TEST(PosixUtilsTest,NoSuchBinary)49  TEST(PosixUtilsTest, NoSuchBinary) {
50    const auto result = ExecuteBinary({"/this/binary/does/not/exist"});
51    ASSERT_THAT(result, IsNull());
52  }
53  
54  } // android
55  } // util
56