blob: cf97f87a4163cb71b253f53fd6eff4ed218e90b3 [file] [log] [blame]
MÃ¥rten Kongstad2503a492018-09-27 13:32:30 +02001/*
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
23using ::testing::IsNull;
24using ::testing::NotNull;
25
26namespace android {
27namespace util {
28
29TEST(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
36TEST(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
43TEST(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
49TEST(PosixUtilsTest, NoSuchBinary) {
50 const auto result = ExecuteBinary({"/this/binary/does/not/exist"});
51 ASSERT_THAT(result, IsNull());
52}
53
54} // android
55} // util