blob: 097e6b0bba658f47b1cf798bc6f08ec09438442d [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"});
Yurii Zubrytskyi1fc44eb2022-09-28 22:52:37 -070031 ASSERT_TRUE((bool)result);
32 ASSERT_EQ(result.status, 0);
33 ASSERT_GE(result.stdout_str.find("usage: date "), 0);
Mårten Kongstad2503a492018-09-27 13:32:30 +020034}
35
36TEST(PosixUtilsTest, RelativePathToBinary) {
37 const auto result = ExecuteBinary({"date", "--help"});
Yurii Zubrytskyi1fc44eb2022-09-28 22:52:37 -070038 ASSERT_TRUE((bool)result);
39 ASSERT_EQ(result.status, 0);
40 ASSERT_GE(result.stdout_str.find("usage: date "), 0);
Mårten Kongstad2503a492018-09-27 13:32:30 +020041}
42
43TEST(PosixUtilsTest, BadParameters) {
44 const auto result = ExecuteBinary({"/bin/date", "--this-parameter-is-not-supported"});
Yurii Zubrytskyi1fc44eb2022-09-28 22:52:37 -070045 ASSERT_TRUE((bool)result);
46 ASSERT_GT(result.status, 0);
Mårten Kongstad2503a492018-09-27 13:32:30 +020047}
48
49TEST(PosixUtilsTest, NoSuchBinary) {
50 const auto result = ExecuteBinary({"/this/binary/does/not/exist"});
Yurii Zubrytskyi1fc44eb2022-09-28 22:52:37 -070051 ASSERT_FALSE((bool)result);
Mårten Kongstad2503a492018-09-27 13:32:30 +020052}
53
54} // android
55} // util