1 // Copyright (c) 2009, Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // Unit test for crash dump uploader.
34 #include "common/linux/google_crashdump_uploader.h"
35 #include "breakpad_googletest_includes.h"
36 #include "common/using_std_string.h"
38 namespace google_breakpad {
40 using ::testing::Return;
43 class MockLibcurlWrapper : public LibcurlWrapper {
45 MOCK_METHOD0(Init, bool());
46 MOCK_METHOD2(SetProxy, bool(const string& proxy_host,
47 const string& proxy_userpwd));
48 MOCK_METHOD2(AddFile, bool(const string& upload_file_path,
49 const string& basename));
50 MOCK_METHOD5(SendRequest,
51 bool(const string& url,
52 const std::map<string, string>& parameters,
53 int* http_status_code,
54 string* http_header_data,
55 string* http_response_data));
58 class GoogleCrashdumpUploaderTest : public ::testing::Test {
61 TEST_F(GoogleCrashdumpUploaderTest, InitFailsCausesUploadFailure) {
63 EXPECT_CALL(m, Init()).Times(1).WillOnce(Return(false));
64 GoogleCrashdumpUploader *uploader = new GoogleCrashdumpUploader("foobar",
76 ASSERT_FALSE(uploader->Upload(NULL, NULL, NULL));
79 TEST_F(GoogleCrashdumpUploaderTest, TestSendRequestHappensWithValidParameters) {
81 char tempfn[80] = "/tmp/googletest-upload-XXXXXX";
82 int fd = mkstemp(tempfn);
87 EXPECT_CALL(m, Init()).Times(1).WillOnce(Return(true));
88 EXPECT_CALL(m, AddFile(tempfn, _)).WillOnce(Return(true));
90 SendRequest("http://foo.com",_,_,_,_)).Times(1).WillOnce(Return(true));
91 GoogleCrashdumpUploader *uploader = new GoogleCrashdumpUploader("foobar",
103 ASSERT_TRUE(uploader->Upload(NULL, NULL, NULL));
107 TEST_F(GoogleCrashdumpUploaderTest, InvalidPathname) {
108 MockLibcurlWrapper m;
109 EXPECT_CALL(m, Init()).Times(1).WillOnce(Return(true));
110 EXPECT_CALL(m, SendRequest(_,_,_,_,_)).Times(0);
111 GoogleCrashdumpUploader *uploader = new GoogleCrashdumpUploader("foobar",
123 ASSERT_FALSE(uploader->Upload(NULL, NULL, NULL));
126 TEST_F(GoogleCrashdumpUploaderTest, TestRequiredParametersMustBePresent) {
127 // Test with empty product name.
128 GoogleCrashdumpUploader uploader("",
139 ASSERT_FALSE(uploader.Upload(NULL, NULL, NULL));
141 // Test with empty product version.
142 GoogleCrashdumpUploader uploader1("product",
154 ASSERT_FALSE(uploader1.Upload(NULL, NULL, NULL));
156 // Test with empty client GUID.
157 GoogleCrashdumpUploader uploader2("product",
168 ASSERT_FALSE(uploader2.Upload(NULL, NULL, NULL));