Thanks to visit codestin.com
Credit goes to chromium.googlesource.com

blob: 18cb939e1a5fe7982918d69f31deeab00923d6c4 [file] [log] [blame]
S. Ganesh154e2292024-08-09 23:43:291// Copyright 2024 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/process/launch.h"
6
7#include <string>
8
9#include "base/command_line.h"
10#include "base/files/file_path.h"
11#include "build/build_config.h"
12#include "testing/gtest/include/gtest/gtest.h"
13
14namespace base {
15
16TEST(LaunchTest, GetAppOutputWithInvalidExecutableShouldFail) {
17 CommandLine cl(FilePath(FILE_PATH_LITERAL("executable_does_not_exist")));
18 std::string output;
19 ASSERT_FALSE(GetAppOutput(cl, &output));
20
21#if !BUILDFLAG(IS_IOS)
22 // iOS does not support `GetAppOutputWithExitCode`.
23 int exit_code = {};
24 const bool succeeded = GetAppOutputWithExitCode(cl, &output, &exit_code);
25
26#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_FUCHSIA)
27 ASSERT_FALSE(succeeded);
28#else
29 // Other platforms return code `127` for an executable that does not exist.
30 ASSERT_TRUE(succeeded);
31 ASSERT_EQ(exit_code, 127);
32#endif // #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_FUCHSIA)
33#endif // #if !BUILDFLAG(IS_IOS)
34}
35
36} // namespace base