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 "common/linux/libcurl_wrapper.h"
36 #include "breakpad_googletest_includes.h"
37 #include "common/using_std_string.h"
39 namespace google_breakpad {
41 using ::testing::Return;
44 class MockLibcurlWrapper : public LibcurlWrapper {
46 MOCK_METHOD0(Init, bool());
47 MOCK_METHOD2(SetProxy, bool(const string& proxy_host,
48 const string& proxy_userpwd));
49 MOCK_METHOD2(AddFile, bool(const string& upload_file_path,
50 const string& basename));
51 MOCK_METHOD3(SendRequest,
52 bool(const string& url,
53 const std::map<string, string>& parameters,
54 string* server_response));
57 class GoogleCrashdumpUploaderTest : public ::testing::Test {
60 TEST_F(GoogleCrashdumpUploaderTest, InitFailsCausesUploadFailure) {
62 EXPECT_CALL(m, Init()).Times(1).WillOnce(Return(false));
63 GoogleCrashdumpUploader *uploader = new GoogleCrashdumpUploader("foobar",
75 ASSERT_FALSE(uploader->Upload());
78 TEST_F(GoogleCrashdumpUploaderTest, TestSendRequestHappensWithValidParameters) {
80 char tempfn[80] = "/tmp/googletest-upload-XXXXXX";
81 int fd = mkstemp(tempfn);
86 EXPECT_CALL(m, Init()).Times(1).WillOnce(Return(true));
87 EXPECT_CALL(m, AddFile(tempfn, _)).WillOnce(Return(true));
89 SendRequest("http://foo.com",_,_)).Times(1).WillOnce(Return(true));
90 GoogleCrashdumpUploader *uploader = new GoogleCrashdumpUploader("foobar",
102 ASSERT_TRUE(uploader->Upload());
106 TEST_F(GoogleCrashdumpUploaderTest, InvalidPathname) {
107 MockLibcurlWrapper m;
108 EXPECT_CALL(m, Init()).Times(1).WillOnce(Return(true));
109 EXPECT_CALL(m, SendRequest(_,_,_)).Times(0);
110 GoogleCrashdumpUploader *uploader = new GoogleCrashdumpUploader("foobar",
122 ASSERT_FALSE(uploader->Upload());
125 TEST_F(GoogleCrashdumpUploaderTest, TestRequiredParametersMustBePresent) {
126 // Test with empty product name.
127 GoogleCrashdumpUploader uploader("",
138 ASSERT_FALSE(uploader.Upload());
140 // Test with empty product version.
141 GoogleCrashdumpUploader uploader1("product",
153 ASSERT_FALSE(uploader1.Upload());
155 // Test with empty client GUID.
156 GoogleCrashdumpUploader uploader2("product",
167 ASSERT_FALSE(uploader2.Upload());