Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 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 "bugreport.h" |
| 18 | |
| 19 | #include <gmock/gmock.h> |
| 20 | #include <gtest/gtest.h> |
| 21 | |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 22 | #include <android-base/strings.h> |
| 23 | #include <android-base/test_utils.h> |
| 24 | |
| 25 | #include "sysdeps.h" |
| 26 | #include "adb_utils.h" |
| 27 | |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 28 | using ::testing::_; |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 29 | using ::testing::Action; |
| 30 | using ::testing::ActionInterface; |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 31 | using ::testing::DoAll; |
| 32 | using ::testing::ElementsAre; |
| 33 | using ::testing::HasSubstr; |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 34 | using ::testing::MakeAction; |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 35 | using ::testing::Return; |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 36 | using ::testing::StrEq; |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 37 | using ::testing::WithArg; |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 38 | using ::testing::internal::CaptureStderr; |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 39 | using ::testing::internal::CaptureStdout; |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 40 | using ::testing::internal::GetCapturedStderr; |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 41 | using ::testing::internal::GetCapturedStdout; |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 42 | |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 43 | // Empty function so tests don't need to be linked against file_sync_service.cpp, which requires |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 44 | // SELinux and its transitive dependencies... |
| 45 | bool do_sync_pull(const std::vector<const char*>& srcs, const char* dst, bool copy_attrs, |
| 46 | const char* name) { |
| 47 | ADD_FAILURE() << "do_sync_pull() should have been mocked"; |
| 48 | return false; |
| 49 | } |
| 50 | |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 51 | // Empty functions so tests don't need to be linked against commandline.cpp |
| 52 | DefaultStandardStreamsCallback DEFAULT_STANDARD_STREAMS_CALLBACK(nullptr, nullptr); |
Felipe Leme | 5dab2b4 | 2017-03-20 11:00:11 -0700 | [diff] [blame] | 53 | |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 54 | int send_shell_command(const std::string& command, bool disable_shell_protocol, |
| 55 | StandardStreamsCallbackInterface* callback) { |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 56 | ADD_FAILURE() << "send_shell_command() should have been mocked"; |
| 57 | return -42; |
| 58 | } |
| 59 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 60 | enum StreamType { |
| 61 | kStreamStdout, |
| 62 | kStreamStderr, |
| 63 | }; |
| 64 | |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 65 | // gmock black magic to provide a WithArg<2>(WriteOnStdout(output)) matcher |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 66 | typedef void OnStandardStreamsCallbackFunction(StandardStreamsCallbackInterface*); |
| 67 | |
| 68 | class OnStandardStreamsCallbackAction : public ActionInterface<OnStandardStreamsCallbackFunction> { |
| 69 | public: |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 70 | explicit OnStandardStreamsCallbackAction(StreamType type, const std::string& output) |
| 71 | : type_(type), output_(output) { |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 72 | } |
| 73 | virtual Result Perform(const ArgumentTuple& args) { |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 74 | if (type_ == kStreamStdout) { |
| 75 | ::std::tr1::get<0>(args)->OnStdout(output_.c_str(), output_.size()); |
| 76 | } |
| 77 | if (type_ == kStreamStderr) { |
| 78 | ::std::tr1::get<0>(args)->OnStderr(output_.c_str(), output_.size()); |
| 79 | } |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | private: |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 83 | StreamType type_; |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 84 | std::string output_; |
| 85 | }; |
| 86 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 87 | // Matcher used to emulated StandardStreamsCallbackInterface.OnStdout(buffer, |
| 88 | // length) |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 89 | Action<OnStandardStreamsCallbackFunction> WriteOnStdout(const std::string& output) { |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 90 | return MakeAction(new OnStandardStreamsCallbackAction(kStreamStdout, output)); |
| 91 | } |
| 92 | |
| 93 | // Matcher used to emulated StandardStreamsCallbackInterface.OnStderr(buffer, |
| 94 | // length) |
| 95 | Action<OnStandardStreamsCallbackFunction> WriteOnStderr(const std::string& output) { |
| 96 | return MakeAction(new OnStandardStreamsCallbackAction(kStreamStderr, output)); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | typedef int CallbackDoneFunction(StandardStreamsCallbackInterface*); |
| 100 | |
| 101 | class CallbackDoneAction : public ActionInterface<CallbackDoneFunction> { |
| 102 | public: |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 103 | explicit CallbackDoneAction(int status) : status_(status) { |
| 104 | } |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 105 | virtual Result Perform(const ArgumentTuple& args) { |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 106 | int status = ::std::tr1::get<0>(args)->Done(status_); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 107 | return status; |
| 108 | } |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 109 | |
| 110 | private: |
| 111 | int status_; |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 114 | // Matcher used to emulated StandardStreamsCallbackInterface.Done(status) |
| 115 | Action<CallbackDoneFunction> ReturnCallbackDone(int status = -1337) { |
| 116 | return MakeAction(new CallbackDoneAction(status)); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 119 | class BugreportMock : public Bugreport { |
| 120 | public: |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 121 | MOCK_METHOD3(SendShellCommand, int(const std::string& command, bool disable_shell_protocol, |
| 122 | StandardStreamsCallbackInterface* callback)); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 123 | MOCK_METHOD4(DoSyncPull, bool(const std::vector<const char*>& srcs, const char* dst, |
| 124 | bool copy_attrs, const char* name)); |
Felipe Leme | 0aa2ce3 | 2017-05-02 10:06:33 -0700 | [diff] [blame] | 125 | MOCK_METHOD2(UpdateProgress, void(const std::string&, int)); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | class BugreportTest : public ::testing::Test { |
| 129 | public: |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 130 | void SetUp() { |
| 131 | if (!getcwd(&cwd_)) { |
| 132 | ADD_FAILURE() << "getcwd failed: " << strerror(errno); |
| 133 | return; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | void ExpectBugreportzVersion(const std::string& version) { |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 138 | EXPECT_CALL(br_, SendShellCommand("bugreportz -v", false, _)) |
Greg Kaiser | e2f3234 | 2019-03-26 11:58:53 -0700 | [diff] [blame] | 139 | .WillOnce(DoAll(WithArg<2>(WriteOnStderr(version)), |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 140 | WithArg<2>(ReturnCallbackDone(0)))); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Felipe Leme | 0aa2ce3 | 2017-05-02 10:06:33 -0700 | [diff] [blame] | 143 | void ExpectProgress(int progress_percentage, const std::string& file = "file.zip") { |
| 144 | EXPECT_CALL(br_, UpdateProgress(StrEq("generating " + file), progress_percentage)); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 147 | BugreportMock br_; |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 148 | std::string cwd_; // TODO: make it static |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 151 | // Tests when called with invalid number of arguments |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 152 | TEST_F(BugreportTest, InvalidNumberArgs) { |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 153 | const char* args[] = {"bugreport", "to", "principal"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 154 | ASSERT_EQ(1, br_.DoIt(3, args)); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 157 | // Tests the 'adb bugreport' option when the device does not support 'bugreportz' - it falls back |
| 158 | // to the flat-file format ('bugreport' binary on device) |
| 159 | TEST_F(BugreportTest, NoArgumentsPreNDevice) { |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 160 | // clang-format off |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 161 | EXPECT_CALL(br_, SendShellCommand("bugreportz -v", false, _)) |
| 162 | .WillOnce(DoAll(WithArg<2>(WriteOnStderr("")), |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 163 | // Write some bogus output on stdout to make sure it's ignored |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 164 | WithArg<2>(WriteOnStdout("Dude, where is my bugreportz?")), |
| 165 | WithArg<2>(ReturnCallbackDone(0)))); |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 166 | // clang-format on |
| 167 | std::string bugreport = "Reported the bug was."; |
| 168 | CaptureStdout(); |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 169 | EXPECT_CALL(br_, SendShellCommand("bugreport", false, _)) |
| 170 | .WillOnce(DoAll(WithArg<2>(WriteOnStdout(bugreport)), Return(0))); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 171 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 172 | const char* args[] = {"bugreport"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 173 | ASSERT_EQ(0, br_.DoIt(1, args)); |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 174 | ASSERT_THAT(GetCapturedStdout(), StrEq(bugreport)); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 177 | // Tests the 'adb bugreport' option when the device supports 'bugreportz' version 1.0 - it will |
| 178 | // save the bugreport in the current directory with the name provided by the device. |
| 179 | TEST_F(BugreportTest, NoArgumentsNDevice) { |
| 180 | ExpectBugreportzVersion("1.0"); |
| 181 | |
| 182 | std::string dest_file = |
| 183 | android::base::StringPrintf("%s%cda_bugreport.zip", cwd_.c_str(), OS_PATH_SEPARATOR); |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 184 | EXPECT_CALL(br_, SendShellCommand("bugreportz", false, _)) |
| 185 | .WillOnce(DoAll(WithArg<2>(WriteOnStdout("OK:/device/da_bugreport.zip")), |
| 186 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 187 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/da_bugreport.zip")), StrEq(dest_file), |
Felipe Leme | 8c9a27c | 2017-08-15 18:09:54 -0700 | [diff] [blame] | 188 | false, StrEq("pulling da_bugreport.zip"))) |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 189 | .WillOnce(Return(true)); |
| 190 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 191 | const char* args[] = {"bugreport"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 192 | ASSERT_EQ(0, br_.DoIt(1, args)); |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | // Tests the 'adb bugreport' option when the device supports 'bugreportz' version 1.1 - it will |
| 196 | // save the bugreport in the current directory with the name provided by the device. |
| 197 | TEST_F(BugreportTest, NoArgumentsPostNDevice) { |
| 198 | ExpectBugreportzVersion("1.1"); |
| 199 | std::string dest_file = |
| 200 | android::base::StringPrintf("%s%cda_bugreport.zip", cwd_.c_str(), OS_PATH_SEPARATOR); |
Felipe Leme | 0aa2ce3 | 2017-05-02 10:06:33 -0700 | [diff] [blame] | 201 | ExpectProgress(50, "da_bugreport.zip"); |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 202 | EXPECT_CALL(br_, SendShellCommand("bugreportz -p", false, _)) |
| 203 | .WillOnce(DoAll(WithArg<2>(WriteOnStdout("BEGIN:/device/da_bugreport.zip\n")), |
| 204 | WithArg<2>(WriteOnStdout("PROGRESS:50/100\n")), |
| 205 | WithArg<2>(WriteOnStdout("OK:/device/da_bugreport.zip\n")), |
| 206 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 207 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/da_bugreport.zip")), StrEq(dest_file), |
Felipe Leme | 8c9a27c | 2017-08-15 18:09:54 -0700 | [diff] [blame] | 208 | false, StrEq("pulling da_bugreport.zip"))) |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 209 | .WillOnce(Return(true)); |
| 210 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 211 | const char* args[] = {"bugreport"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 212 | ASSERT_EQ(0, br_.DoIt(1, args)); |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | // Tests 'adb bugreport file.zip' when it succeeds and device does not support progress. |
| 216 | TEST_F(BugreportTest, OkNDevice) { |
| 217 | ExpectBugreportzVersion("1.0"); |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 218 | EXPECT_CALL(br_, SendShellCommand("bugreportz", false, _)) |
| 219 | .WillOnce(DoAll(WithArg<2>(WriteOnStdout("OK:/device/bugreport.zip")), |
| 220 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 221 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 8c9a27c | 2017-08-15 18:09:54 -0700 | [diff] [blame] | 222 | false, StrEq("pulling file.zip"))) |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 223 | .WillOnce(Return(true)); |
| 224 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 225 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 226 | ASSERT_EQ(0, br_.DoIt(2, args)); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 229 | // Tests 'adb bugreport file.zip' when it succeeds but response was sent in |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 230 | // multiple buffer writers and without progress updates. |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 231 | TEST_F(BugreportTest, OkNDeviceSplitBuffer) { |
| 232 | ExpectBugreportzVersion("1.0"); |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 233 | EXPECT_CALL(br_, SendShellCommand("bugreportz", false, _)) |
| 234 | .WillOnce(DoAll(WithArg<2>(WriteOnStdout("OK:/device")), |
| 235 | WithArg<2>(WriteOnStdout("/bugreport.zip")), |
| 236 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 237 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 8c9a27c | 2017-08-15 18:09:54 -0700 | [diff] [blame] | 238 | false, StrEq("pulling file.zip"))) |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 239 | .WillOnce(Return(true)); |
| 240 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 241 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 242 | ASSERT_EQ(0, br_.DoIt(2, args)); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 245 | // Tests 'adb bugreport file.zip' when it succeeds and displays progress. |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 246 | TEST_F(BugreportTest, OkProgress) { |
| 247 | ExpectBugreportzVersion("1.1"); |
Felipe Leme | 0aa2ce3 | 2017-05-02 10:06:33 -0700 | [diff] [blame] | 248 | ExpectProgress(1); |
| 249 | ExpectProgress(10); |
| 250 | ExpectProgress(50); |
| 251 | ExpectProgress(99); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 252 | // clang-format off |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 253 | EXPECT_CALL(br_, SendShellCommand("bugreportz -p", false, _)) |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 254 | // NOTE: DoAll accepts at most 10 arguments, and we're almost reached that limit... |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 255 | .WillOnce(DoAll( |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 256 | // Name might change on OK, so make sure the right one is picked. |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 257 | WithArg<2>(WriteOnStdout("BEGIN:/device/bugreport___NOT.zip\n")), |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 258 | // Progress line in one write |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 259 | WithArg<2>(WriteOnStdout("PROGRESS:1/100\n")), |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 260 | // Add some bogus lines |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 261 | WithArg<2>(WriteOnStdout("\nDUDE:SWEET\n\nBLA\n\nBLA\nBLA\n\n")), |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 262 | // Multiple progress lines in one write |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 263 | WithArg<2>(WriteOnStdout("PROGRESS:10/100\nPROGRESS:50/100\n")), |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 264 | // Progress line in multiple writes |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 265 | WithArg<2>(WriteOnStdout("PROG")), |
| 266 | WithArg<2>(WriteOnStdout("RESS:99")), |
| 267 | WithArg<2>(WriteOnStdout("/100\n")), |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 268 | // Split last message as well, just in case |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 269 | WithArg<2>(WriteOnStdout("OK:/device/bugreport")), |
| 270 | WithArg<2>(WriteOnStdout(".zip")), |
| 271 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | ab62b55 | 2016-07-29 15:47:00 -0700 | [diff] [blame] | 272 | // clang-format on |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 273 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 8c9a27c | 2017-08-15 18:09:54 -0700 | [diff] [blame] | 274 | false, StrEq("pulling file.zip"))) |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 275 | .WillOnce(Return(true)); |
| 276 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 277 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 278 | ASSERT_EQ(0, br_.DoIt(2, args)); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Felipe Leme | 5dab2b4 | 2017-03-20 11:00:11 -0700 | [diff] [blame] | 281 | // Tests 'adb bugreport file.zip' when it succeeds and displays progress, even if progress recedes. |
| 282 | TEST_F(BugreportTest, OkProgressAlwaysForward) { |
| 283 | ExpectBugreportzVersion("1.1"); |
Felipe Leme | 0aa2ce3 | 2017-05-02 10:06:33 -0700 | [diff] [blame] | 284 | ExpectProgress(1); |
| 285 | ExpectProgress(50); |
| 286 | ExpectProgress(75); |
Felipe Leme | 5dab2b4 | 2017-03-20 11:00:11 -0700 | [diff] [blame] | 287 | // clang-format off |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 288 | EXPECT_CALL(br_, SendShellCommand("bugreportz -p", false, _)) |
Felipe Leme | 5dab2b4 | 2017-03-20 11:00:11 -0700 | [diff] [blame] | 289 | // NOTE: DoAll accepts at most 10 arguments, and we're almost reached that limit... |
| 290 | .WillOnce(DoAll( |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 291 | WithArg<2>(WriteOnStdout("BEGIN:/device/bugreport.zip\n")), |
| 292 | WithArg<2>(WriteOnStdout("PROGRESS:1/100\n")), // 1% |
| 293 | WithArg<2>(WriteOnStdout("PROGRESS:50/100\n")), // 50% |
Felipe Leme | 0aa2ce3 | 2017-05-02 10:06:33 -0700 | [diff] [blame] | 294 | // 25% should be ignored becaused it receded. |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 295 | WithArg<2>(WriteOnStdout("PROGRESS:25/100\n")), // 25% |
| 296 | WithArg<2>(WriteOnStdout("PROGRESS:75/100\n")), // 75% |
Felipe Leme | 0aa2ce3 | 2017-05-02 10:06:33 -0700 | [diff] [blame] | 297 | // 75% should be ignored becaused it didn't change. |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 298 | WithArg<2>(WriteOnStdout("PROGRESS:75/100\n")), // 75% |
Felipe Leme | 0aa2ce3 | 2017-05-02 10:06:33 -0700 | [diff] [blame] | 299 | // Try a receeding percentage with a different max progress |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 300 | WithArg<2>(WriteOnStdout("PROGRESS:700/1000\n")), // 70% |
| 301 | WithArg<2>(WriteOnStdout("OK:/device/bugreport.zip")), |
| 302 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | 5dab2b4 | 2017-03-20 11:00:11 -0700 | [diff] [blame] | 303 | // clang-format on |
| 304 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 8c9a27c | 2017-08-15 18:09:54 -0700 | [diff] [blame] | 305 | false, StrEq("pulling file.zip"))) |
Felipe Leme | 5dab2b4 | 2017-03-20 11:00:11 -0700 | [diff] [blame] | 306 | .WillOnce(Return(true)); |
| 307 | |
| 308 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 309 | ASSERT_EQ(0, br_.DoIt(2, args)); |
Felipe Leme | 5dab2b4 | 2017-03-20 11:00:11 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Felipe Leme | 222fae0 | 2017-05-23 16:56:47 -0700 | [diff] [blame] | 312 | // Tests 'adb bugreport file.zip' when it succeeds and displays the initial progress of 0% |
| 313 | TEST_F(BugreportTest, OkProgressZeroPercentIsNotIgnored) { |
| 314 | ExpectBugreportzVersion("1.1"); |
| 315 | ExpectProgress(0); |
| 316 | ExpectProgress(1); |
| 317 | // clang-format off |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 318 | EXPECT_CALL(br_, SendShellCommand("bugreportz -p", false, _)) |
Felipe Leme | 222fae0 | 2017-05-23 16:56:47 -0700 | [diff] [blame] | 319 | // NOTE: DoAll accepts at most 10 arguments, and we're almost reached that limit... |
| 320 | .WillOnce(DoAll( |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 321 | WithArg<2>(WriteOnStdout("BEGIN:/device/bugreport.zip\n")), |
| 322 | WithArg<2>(WriteOnStdout("PROGRESS:1/100000\n")), |
| 323 | WithArg<2>(WriteOnStdout("PROGRESS:1/100\n")), // 1% |
| 324 | WithArg<2>(WriteOnStdout("OK:/device/bugreport.zip")), |
| 325 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | 222fae0 | 2017-05-23 16:56:47 -0700 | [diff] [blame] | 326 | // clang-format on |
| 327 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 8c9a27c | 2017-08-15 18:09:54 -0700 | [diff] [blame] | 328 | false, StrEq("pulling file.zip"))) |
Felipe Leme | 222fae0 | 2017-05-23 16:56:47 -0700 | [diff] [blame] | 329 | .WillOnce(Return(true)); |
| 330 | |
| 331 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 332 | ASSERT_EQ(0, br_.DoIt(2, args)); |
Felipe Leme | 222fae0 | 2017-05-23 16:56:47 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 335 | // Tests 'adb bugreport dir' when it succeeds and destination is a directory. |
| 336 | TEST_F(BugreportTest, OkDirectory) { |
| 337 | ExpectBugreportzVersion("1.1"); |
| 338 | TemporaryDir td; |
| 339 | std::string dest_file = |
| 340 | android::base::StringPrintf("%s%cda_bugreport.zip", td.path, OS_PATH_SEPARATOR); |
| 341 | |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 342 | EXPECT_CALL(br_, SendShellCommand("bugreportz -p", false, _)) |
| 343 | .WillOnce(DoAll(WithArg<2>(WriteOnStdout("BEGIN:/device/da_bugreport.zip\n")), |
| 344 | WithArg<2>(WriteOnStdout("OK:/device/da_bugreport.zip")), |
| 345 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 346 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/da_bugreport.zip")), StrEq(dest_file), |
Felipe Leme | 8c9a27c | 2017-08-15 18:09:54 -0700 | [diff] [blame] | 347 | false, StrEq("pulling da_bugreport.zip"))) |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 348 | .WillOnce(Return(true)); |
| 349 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 350 | const char* args[] = {"bugreport", td.path}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 351 | ASSERT_EQ(0, br_.DoIt(2, args)); |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 354 | // Tests 'adb bugreport file' when it succeeds |
| 355 | TEST_F(BugreportTest, OkNoExtension) { |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 356 | ExpectBugreportzVersion("1.1"); |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 357 | EXPECT_CALL(br_, SendShellCommand("bugreportz -p", false, _)) |
| 358 | .WillOnce(DoAll(WithArg<2>(WriteOnStdout("OK:/device/bugreport.zip\n")), |
| 359 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 360 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 8c9a27c | 2017-08-15 18:09:54 -0700 | [diff] [blame] | 361 | false, StrEq("pulling file.zip"))) |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 362 | .WillOnce(Return(true)); |
| 363 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 364 | const char* args[] = {"bugreport", "file"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 365 | ASSERT_EQ(0, br_.DoIt(2, args)); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 368 | // Tests 'adb bugreport dir' when it succeeds and destination is a directory and device runs N. |
| 369 | TEST_F(BugreportTest, OkNDeviceDirectory) { |
| 370 | ExpectBugreportzVersion("1.0"); |
| 371 | TemporaryDir td; |
| 372 | std::string dest_file = |
| 373 | android::base::StringPrintf("%s%cda_bugreport.zip", td.path, OS_PATH_SEPARATOR); |
| 374 | |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 375 | EXPECT_CALL(br_, SendShellCommand("bugreportz", false, _)) |
| 376 | .WillOnce(DoAll(WithArg<2>(WriteOnStdout("BEGIN:/device/da_bugreport.zip\n")), |
| 377 | WithArg<2>(WriteOnStdout("OK:/device/da_bugreport.zip")), |
| 378 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 379 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/da_bugreport.zip")), StrEq(dest_file), |
Felipe Leme | 8c9a27c | 2017-08-15 18:09:54 -0700 | [diff] [blame] | 380 | false, StrEq("pulling da_bugreport.zip"))) |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 381 | .WillOnce(Return(true)); |
| 382 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 383 | const char* args[] = {"bugreport", td.path}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 384 | ASSERT_EQ(0, br_.DoIt(2, args)); |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 387 | // Tests 'adb bugreport file.zip' when the bugreport itself failed |
| 388 | TEST_F(BugreportTest, BugreportzReturnedFail) { |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 389 | ExpectBugreportzVersion("1.1"); |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 390 | EXPECT_CALL(br_, SendShellCommand("bugreportz -p", false, _)) |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 391 | .WillOnce( |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 392 | DoAll(WithArg<2>(WriteOnStdout("FAIL:D'OH!\n")), WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 393 | |
| 394 | CaptureStderr(); |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 395 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 396 | ASSERT_EQ(-1, br_.DoIt(2, args)); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 397 | ASSERT_THAT(GetCapturedStderr(), HasSubstr("D'OH!")); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | // Tests 'adb bugreport file.zip' when the bugreport itself failed but response |
| 401 | // was sent in |
| 402 | // multiple buffer writes |
| 403 | TEST_F(BugreportTest, BugreportzReturnedFailSplitBuffer) { |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 404 | ExpectBugreportzVersion("1.1"); |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 405 | EXPECT_CALL(br_, SendShellCommand("bugreportz -p", false, _)) |
| 406 | .WillOnce(DoAll(WithArg<2>(WriteOnStdout("FAIL")), WithArg<2>(WriteOnStdout(":D'OH!\n")), |
| 407 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 408 | |
| 409 | CaptureStderr(); |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 410 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 411 | ASSERT_EQ(-1, br_.DoIt(2, args)); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 412 | ASSERT_THAT(GetCapturedStderr(), HasSubstr("D'OH!")); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | // Tests 'adb bugreport file.zip' when the bugreportz returned an unsupported |
| 416 | // response. |
| 417 | TEST_F(BugreportTest, BugreportzReturnedUnsupported) { |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 418 | ExpectBugreportzVersion("1.1"); |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 419 | EXPECT_CALL(br_, SendShellCommand("bugreportz -p", false, _)) |
| 420 | .WillOnce(DoAll(WithArg<2>(WriteOnStdout("bugreportz? What am I, a zombie?")), |
| 421 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 422 | |
| 423 | CaptureStderr(); |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 424 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 425 | ASSERT_EQ(-1, br_.DoIt(2, args)); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 426 | ASSERT_THAT(GetCapturedStderr(), HasSubstr("bugreportz? What am I, a zombie?")); |
| 427 | } |
| 428 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 429 | // Tests 'adb bugreport file.zip' when the bugreportz -v command failed |
| 430 | TEST_F(BugreportTest, BugreportzVersionFailed) { |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 431 | EXPECT_CALL(br_, SendShellCommand("bugreportz -v", false, _)).WillOnce(Return(666)); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 432 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 433 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 434 | ASSERT_EQ(666, br_.DoIt(2, args)); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Felipe Leme | ab62b55 | 2016-07-29 15:47:00 -0700 | [diff] [blame] | 437 | // Tests 'adb bugreport file.zip' when the bugreportz -v returns status 0 but with no output. |
| 438 | TEST_F(BugreportTest, BugreportzVersionEmpty) { |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 439 | ExpectBugreportzVersion(""); |
Felipe Leme | ab62b55 | 2016-07-29 15:47:00 -0700 | [diff] [blame] | 440 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 441 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 442 | ASSERT_EQ(-1, br_.DoIt(2, args)); |
Felipe Leme | ab62b55 | 2016-07-29 15:47:00 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 445 | // Tests 'adb bugreport file.zip' when the main bugreportz command failed |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 446 | TEST_F(BugreportTest, BugreportzFailed) { |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 447 | ExpectBugreportzVersion("1.1"); |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 448 | EXPECT_CALL(br_, SendShellCommand("bugreportz -p", false, _)).WillOnce(Return(666)); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 449 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 450 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 451 | ASSERT_EQ(666, br_.DoIt(2, args)); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | // Tests 'adb bugreport file.zip' when the bugreport could not be pulled |
| 455 | TEST_F(BugreportTest, PullFails) { |
Felipe Leme | e4893a2 | 2016-07-29 17:57:00 -0700 | [diff] [blame] | 456 | ExpectBugreportzVersion("1.1"); |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 457 | EXPECT_CALL(br_, SendShellCommand("bugreportz -p", false, _)) |
| 458 | .WillOnce(DoAll(WithArg<2>(WriteOnStdout("OK:/device/bugreport.zip")), |
| 459 | WithArg<2>(ReturnCallbackDone()))); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 460 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 8c9a27c | 2017-08-15 18:09:54 -0700 | [diff] [blame] | 461 | false, HasSubstr("file.zip"))) |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 462 | .WillOnce(Return(false)); |
| 463 | |
Felipe Leme | fa236de | 2016-08-04 12:03:06 -0700 | [diff] [blame] | 464 | const char* args[] = {"bugreport", "file.zip"}; |
Josh Gao | b39e415 | 2017-08-16 16:57:01 -0700 | [diff] [blame] | 465 | ASSERT_EQ(1, br_.DoIt(2, args)); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 466 | } |