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 | |
| 22 | using ::testing::_; |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 23 | using ::testing::Action; |
| 24 | using ::testing::ActionInterface; |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 25 | using ::testing::DoAll; |
| 26 | using ::testing::ElementsAre; |
| 27 | using ::testing::HasSubstr; |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 28 | using ::testing::MakeAction; |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 29 | using ::testing::Return; |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 30 | using ::testing::StrEq; |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 31 | using ::testing::WithArg; |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 32 | using ::testing::internal::CaptureStderr; |
| 33 | using ::testing::internal::GetCapturedStderr; |
| 34 | |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 35 | // 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] | 36 | // SELinux and its transitive dependencies... |
| 37 | bool do_sync_pull(const std::vector<const char*>& srcs, const char* dst, bool copy_attrs, |
| 38 | const char* name) { |
| 39 | ADD_FAILURE() << "do_sync_pull() should have been mocked"; |
| 40 | return false; |
| 41 | } |
| 42 | |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 43 | // Empty functions so tests don't need to be linked against commandline.cpp |
| 44 | DefaultStandardStreamsCallback DEFAULT_STANDARD_STREAMS_CALLBACK(nullptr, nullptr); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 45 | int usage() { |
| 46 | return -42; |
| 47 | } |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 48 | int send_shell_command(TransportType transport_type, const char* serial, const std::string& command, |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 49 | bool disable_shell_protocol, StandardStreamsCallbackInterface* callback) { |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 50 | ADD_FAILURE() << "send_shell_command() should have been mocked"; |
| 51 | return -42; |
| 52 | } |
| 53 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 54 | enum StreamType { |
| 55 | kStreamStdout, |
| 56 | kStreamStderr, |
| 57 | }; |
| 58 | |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 59 | // gmock black magic to provide a WithArg<4>(WriteOnStdout(output)) matcher |
| 60 | typedef void OnStandardStreamsCallbackFunction(StandardStreamsCallbackInterface*); |
| 61 | |
| 62 | class OnStandardStreamsCallbackAction : public ActionInterface<OnStandardStreamsCallbackFunction> { |
| 63 | public: |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 64 | explicit OnStandardStreamsCallbackAction(StreamType type, const std::string& output) |
| 65 | : type_(type), output_(output) { |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 66 | } |
| 67 | virtual Result Perform(const ArgumentTuple& args) { |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 68 | if (type_ == kStreamStdout) { |
| 69 | ::std::tr1::get<0>(args)->OnStdout(output_.c_str(), output_.size()); |
| 70 | } |
| 71 | if (type_ == kStreamStderr) { |
| 72 | ::std::tr1::get<0>(args)->OnStderr(output_.c_str(), output_.size()); |
| 73 | } |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | private: |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 77 | StreamType type_; |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 78 | std::string output_; |
| 79 | }; |
| 80 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 81 | // Matcher used to emulated StandardStreamsCallbackInterface.OnStdout(buffer, |
| 82 | // length) |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 83 | Action<OnStandardStreamsCallbackFunction> WriteOnStdout(const std::string& output) { |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 84 | return MakeAction(new OnStandardStreamsCallbackAction(kStreamStdout, output)); |
| 85 | } |
| 86 | |
| 87 | // Matcher used to emulated StandardStreamsCallbackInterface.OnStderr(buffer, |
| 88 | // length) |
| 89 | Action<OnStandardStreamsCallbackFunction> WriteOnStderr(const std::string& output) { |
| 90 | return MakeAction(new OnStandardStreamsCallbackAction(kStreamStderr, output)); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | typedef int CallbackDoneFunction(StandardStreamsCallbackInterface*); |
| 94 | |
| 95 | class CallbackDoneAction : public ActionInterface<CallbackDoneFunction> { |
| 96 | public: |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 97 | explicit CallbackDoneAction(int status) : status_(status) { |
| 98 | } |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 99 | virtual Result Perform(const ArgumentTuple& args) { |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 100 | int status = ::std::tr1::get<0>(args)->Done(status_); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 101 | return status; |
| 102 | } |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 103 | |
| 104 | private: |
| 105 | int status_; |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 108 | // Matcher used to emulated StandardStreamsCallbackInterface.Done(status) |
| 109 | Action<CallbackDoneFunction> ReturnCallbackDone(int status = -1337) { |
| 110 | return MakeAction(new CallbackDoneAction(status)); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 113 | class BugreportMock : public Bugreport { |
| 114 | public: |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 115 | MOCK_METHOD5(SendShellCommand, |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 116 | int(TransportType transport_type, const char* serial, const std::string& command, |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 117 | bool disable_shell_protocol, StandardStreamsCallbackInterface* callback)); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 118 | MOCK_METHOD4(DoSyncPull, bool(const std::vector<const char*>& srcs, const char* dst, |
| 119 | bool copy_attrs, const char* name)); |
Felipe Leme | 954af84 | 2016-07-27 19:23:09 -0700 | [diff] [blame^] | 120 | MOCK_METHOD3(UpdateProgress, void(const std::string&, int, int)); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | class BugreportTest : public ::testing::Test { |
| 124 | public: |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 125 | void SetBugreportzVersion(const std::string& version) { |
| 126 | EXPECT_CALL(br_, |
| 127 | SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -v", false, _)) |
| 128 | .WillOnce(DoAll(WithArg<4>(WriteOnStderr(version.c_str())), |
| 129 | WithArg<4>(ReturnCallbackDone(0)))); |
| 130 | } |
| 131 | |
Felipe Leme | 954af84 | 2016-07-27 19:23:09 -0700 | [diff] [blame^] | 132 | void ExpectProgress(int progress, int total) { |
| 133 | EXPECT_CALL(br_, UpdateProgress(HasSubstr("file.zip"), progress, total)); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 136 | BugreportMock br_; |
| 137 | }; |
| 138 | |
| 139 | // Tests when called with invalid number of argumnts |
| 140 | TEST_F(BugreportTest, InvalidNumberArgs) { |
| 141 | const char* args[1024] = {"bugreport", "to", "principal"}; |
| 142 | ASSERT_EQ(-42, br_.DoIt(kTransportLocal, "HannibalLecter", 3, args)); |
| 143 | } |
| 144 | |
| 145 | // Tests the legacy 'adb bugreport' option |
| 146 | TEST_F(BugreportTest, FlatFileFormat) { |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 147 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreport", false, _)) |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 148 | .WillOnce(Return(0)); |
| 149 | |
| 150 | const char* args[1024] = {"bugreport"}; |
| 151 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 1, args)); |
| 152 | } |
| 153 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 154 | // Tests 'adb bugreport file.zip' when it succeeds and device does not support |
| 155 | // progress. |
| 156 | TEST_F(BugreportTest, OkLegacy) { |
| 157 | SetBugreportzVersion("1.0"); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 158 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz", false, _)) |
| 159 | .WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip")), |
| 160 | WithArg<4>(ReturnCallbackDone()))); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 161 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 954af84 | 2016-07-27 19:23:09 -0700 | [diff] [blame^] | 162 | true, HasSubstr("file.zip"))) |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 163 | .WillOnce(Return(true)); |
| 164 | |
| 165 | const char* args[1024] = {"bugreport", "file.zip"}; |
| 166 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
| 167 | } |
| 168 | |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 169 | // 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] | 170 | // multiple buffer writers and without progress updates. |
| 171 | TEST_F(BugreportTest, OkLegacySplitBuffer) { |
| 172 | SetBugreportzVersion("1.0"); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 173 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz", false, _)) |
| 174 | .WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device")), |
| 175 | WithArg<4>(WriteOnStdout("/bugreport.zip")), |
| 176 | WithArg<4>(ReturnCallbackDone()))); |
| 177 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 954af84 | 2016-07-27 19:23:09 -0700 | [diff] [blame^] | 178 | true, HasSubstr("file.zip"))) |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 179 | .WillOnce(Return(true)); |
| 180 | |
| 181 | const char* args[1024] = {"bugreport", "file.zip"}; |
| 182 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
| 183 | } |
| 184 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 185 | // Tests 'adb bugreport file.zip' when it succeeds and displays progress. |
| 186 | TEST_F(BugreportTest, Ok) { |
| 187 | SetBugreportzVersion("1.1"); |
| 188 | ExpectProgress(1, 100); |
| 189 | ExpectProgress(10, 100); |
| 190 | ExpectProgress(50, 100); |
| 191 | ExpectProgress(99, 100); |
Felipe Leme | 954af84 | 2016-07-27 19:23:09 -0700 | [diff] [blame^] | 192 | ExpectProgress(100, 100); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 193 | // clang-format off |
| 194 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _)) |
| 195 | .WillOnce(DoAll( |
| 196 | // Progress line in one write |
| 197 | WithArg<4>(WriteOnStdout("PROGRESS:1/100\n")), |
| 198 | // Add some bogus lines |
| 199 | WithArg<4>(WriteOnStdout("\nDUDE:SWEET\n\n")), |
| 200 | // Multiple progress lines in one write |
| 201 | WithArg<4>(WriteOnStdout("PROGRESS:10/100\nPROGRESS:50/100\n")), |
| 202 | // Progress line in multiple writes |
| 203 | WithArg<4>(WriteOnStdout("PROG")), |
| 204 | WithArg<4>(WriteOnStdout("RESS:99")), |
| 205 | WithArg<4>(WriteOnStdout("/100\n")), |
| 206 | // Split last message as well, just in case |
| 207 | WithArg<4>(WriteOnStdout("OK:/device/bugreport")), |
| 208 | WithArg<4>(WriteOnStdout(".zip")), |
| 209 | WithArg<4>(ReturnCallbackDone()))); |
| 210 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 954af84 | 2016-07-27 19:23:09 -0700 | [diff] [blame^] | 211 | true, HasSubstr("file.zip"))) |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 212 | .WillOnce(Return(true)); |
| 213 | |
| 214 | const char* args[1024] = {"bugreport", "file.zip"}; |
| 215 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
| 216 | } |
| 217 | |
| 218 | // Tests 'adb bugreport file' when it succeeds |
| 219 | TEST_F(BugreportTest, OkNoExtension) { |
| 220 | SetBugreportzVersion("1.1"); |
Felipe Leme | 954af84 | 2016-07-27 19:23:09 -0700 | [diff] [blame^] | 221 | ExpectProgress(100, 100); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 222 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _)) |
| 223 | .WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip\n")), |
| 224 | WithArg<4>(ReturnCallbackDone()))); |
| 225 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 954af84 | 2016-07-27 19:23:09 -0700 | [diff] [blame^] | 226 | true, HasSubstr("file.zip"))) |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 227 | .WillOnce(Return(true)); |
| 228 | |
| 229 | const char* args[1024] = {"bugreport", "file"}; |
| 230 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
| 231 | } |
| 232 | |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 233 | // Tests 'adb bugreport file.zip' when the bugreport itself failed |
| 234 | TEST_F(BugreportTest, BugreportzReturnedFail) { |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 235 | SetBugreportzVersion("1.1"); |
| 236 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _)) |
| 237 | .WillOnce( |
| 238 | DoAll(WithArg<4>(WriteOnStdout("FAIL:D'OH!\n")), WithArg<4>(ReturnCallbackDone()))); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 239 | |
| 240 | CaptureStderr(); |
| 241 | const char* args[1024] = {"bugreport", "file.zip"}; |
| 242 | ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 243 | ASSERT_THAT(GetCapturedStderr(), HasSubstr("D'OH!")); |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | // Tests 'adb bugreport file.zip' when the bugreport itself failed but response |
| 247 | // was sent in |
| 248 | // multiple buffer writes |
| 249 | TEST_F(BugreportTest, BugreportzReturnedFailSplitBuffer) { |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 250 | SetBugreportzVersion("1.1"); |
| 251 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _)) |
| 252 | .WillOnce(DoAll(WithArg<4>(WriteOnStdout("FAIL")), WithArg<4>(WriteOnStdout(":D'OH!\n")), |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 253 | WithArg<4>(ReturnCallbackDone()))); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 254 | |
| 255 | CaptureStderr(); |
| 256 | const char* args[1024] = {"bugreport", "file.zip"}; |
| 257 | ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 258 | ASSERT_THAT(GetCapturedStderr(), HasSubstr("D'OH!")); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | // Tests 'adb bugreport file.zip' when the bugreportz returned an unsupported |
| 262 | // response. |
| 263 | TEST_F(BugreportTest, BugreportzReturnedUnsupported) { |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 264 | SetBugreportzVersion("1.1"); |
| 265 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _)) |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 266 | .WillOnce(DoAll(WithArg<4>(WriteOnStdout("bugreportz? What am I, a zombie?")), |
| 267 | WithArg<4>(ReturnCallbackDone()))); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 268 | |
| 269 | CaptureStderr(); |
| 270 | const char* args[1024] = {"bugreport", "file.zip"}; |
| 271 | ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
| 272 | ASSERT_THAT(GetCapturedStderr(), HasSubstr("bugreportz? What am I, a zombie?")); |
| 273 | } |
| 274 | |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 275 | // Tests 'adb bugreport file.zip' when the bugreportz -v command failed |
| 276 | TEST_F(BugreportTest, BugreportzVersionFailed) { |
| 277 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -v", false, _)) |
| 278 | .WillOnce(Return(666)); |
| 279 | |
| 280 | const char* args[1024] = {"bugreport", "file.zip"}; |
| 281 | ASSERT_EQ(666, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
| 282 | } |
| 283 | |
| 284 | // Tests 'adb bugreport file.zip' when the main bugreportz command failed |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 285 | TEST_F(BugreportTest, BugreportzFailed) { |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 286 | SetBugreportzVersion("1.1"); |
| 287 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _)) |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 288 | .WillOnce(Return(666)); |
| 289 | |
| 290 | const char* args[1024] = {"bugreport", "file.zip"}; |
| 291 | ASSERT_EQ(666, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
| 292 | } |
| 293 | |
| 294 | // Tests 'adb bugreport file.zip' when the bugreport could not be pulled |
| 295 | TEST_F(BugreportTest, PullFails) { |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 296 | SetBugreportzVersion("1.1"); |
Felipe Leme | 954af84 | 2016-07-27 19:23:09 -0700 | [diff] [blame^] | 297 | ExpectProgress(100, 100); |
Felipe Leme | e53b12b | 2016-07-26 12:23:40 -0700 | [diff] [blame] | 298 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _)) |
Felipe Leme | 60192aa | 2016-07-26 12:14:39 -0700 | [diff] [blame] | 299 | .WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip")), |
| 300 | WithArg<4>(ReturnCallbackDone()))); |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 301 | EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"), |
Felipe Leme | 954af84 | 2016-07-27 19:23:09 -0700 | [diff] [blame^] | 302 | true, HasSubstr("file.zip"))) |
Felipe Leme | 042c351 | 2016-07-19 17:07:22 -0700 | [diff] [blame] | 303 | .WillOnce(Return(false)); |
| 304 | |
| 305 | const char* args[1024] = {"bugreport", "file.zip"}; |
| 306 | ASSERT_EQ(1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
| 307 | } |