OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009, Google Inc. | |
2 // All rights reserved. | |
3 // | |
4 // Redistribution and use in source and binary forms, with or without | |
5 // modification, are permitted provided that the following conditions are | |
6 // met: | |
7 // | |
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 | |
13 // distribution. | |
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. | |
17 // | |
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. | |
29 | |
30 // Unit test for crash dump uploader. | |
31 | |
32 #include "common/linux/google_crashdump_uploader.h" | |
33 #include "common/linux/libcurl_wrapper.h" | |
34 #include "breakpad_googletest_includes.h" | |
35 | |
36 namespace google_breakpad { | |
37 | |
38 using ::testing::Return; | |
39 using ::testing::_; | |
40 | |
41 class MockLibcurlWrapper : public LibcurlWrapper { | |
42 public: | |
43 MOCK_METHOD0(Init, bool()); | |
44 MOCK_METHOD2(SetProxy, bool(const std::string& proxy_host, | |
45 const std::string& proxy_userpwd)); | |
46 MOCK_METHOD2(AddFile, bool(const std::string& upload_file_path, | |
47 const std::string& basename)); | |
48 MOCK_METHOD3(SendRequest, | |
49 bool(const std::string& url, | |
50 const std::map<std::string, std::string>& parameters, | |
51 std::string* server_response)); | |
52 }; | |
53 | |
54 class GoogleCrashdumpUploaderTest : public ::testing::Test { | |
55 }; | |
56 | |
57 TEST_F(GoogleCrashdumpUploaderTest, InitFailsCausesUploadFailure) { | |
58 MockLibcurlWrapper m; | |
59 EXPECT_CALL(m, Init()).Times(1).WillOnce(Return(false)); | |
60 GoogleCrashdumpUploader *uploader = new GoogleCrashdumpUploader("foobar", | |
61 "1.0", | |
62 "AAA-BBB", | |
63 "", | |
64 "", | |
65 "test@test.com
", | |
66 "none", | |
67 "/tmp/foo.dmp"
, | |
68 "http://foo.co
m", | |
69 "", | |
70 "", | |
71 &m); | |
72 ASSERT_FALSE(uploader->Upload()); | |
73 } | |
74 | |
75 TEST_F(GoogleCrashdumpUploaderTest, TestSendRequestHappensWithValidParameters) { | |
76 // Create a temp file | |
77 char tempfn[80] = "/tmp/googletest-upload-XXXXXX"; | |
78 int fd = mkstemp(tempfn); | |
79 ASSERT_NE(fd, -1); | |
80 close(fd); | |
81 | |
82 MockLibcurlWrapper m; | |
83 EXPECT_CALL(m, Init()).Times(1).WillOnce(Return(true)); | |
84 EXPECT_CALL(m, AddFile(tempfn, _)).WillOnce(Return(true)); | |
85 EXPECT_CALL(m, | |
86 SendRequest("http://foo.com",_,_)).Times(1).WillOnce(Return(true))
; | |
87 GoogleCrashdumpUploader *uploader = new GoogleCrashdumpUploader("foobar", | |
88 "1.0", | |
89 "AAA-BBB", | |
90 "", | |
91 "", | |
92 "test@test.com
", | |
93 "none", | |
94 tempfn, | |
95 "http://foo.co
m", | |
96 "", | |
97 "", | |
98 &m); | |
99 ASSERT_TRUE(uploader->Upload()); | |
100 } | |
101 | |
102 | |
103 TEST_F(GoogleCrashdumpUploaderTest, InvalidPathname) { | |
104 MockLibcurlWrapper m; | |
105 EXPECT_CALL(m, Init()).Times(1).WillOnce(Return(true)); | |
106 EXPECT_CALL(m, SendRequest(_,_,_)).Times(0); | |
107 GoogleCrashdumpUploader *uploader = new GoogleCrashdumpUploader("foobar", | |
108 "1.0", | |
109 "AAA-BBB", | |
110 "", | |
111 "", | |
112 "test@test.com
", | |
113 "none", | |
114 "/tmp/foo.dmp"
, | |
115 "http://foo.co
m", | |
116 "", | |
117 "", | |
118 &m); | |
119 ASSERT_FALSE(uploader->Upload()); | |
120 } | |
121 | |
122 TEST_F(GoogleCrashdumpUploaderTest, TestRequiredParametersMustBePresent) { | |
123 // Test with empty product name. | |
124 GoogleCrashdumpUploader uploader("", | |
125 "1.0", | |
126 "AAA-BBB", | |
127 "", | |
128 "", | |
129 "test@test.com", | |
130 "none", | |
131 "/tmp/foo.dmp", | |
132 "http://foo.com", | |
133 "", | |
134 ""); | |
135 ASSERT_FALSE(uploader.Upload()); | |
136 | |
137 // Test with empty product version. | |
138 GoogleCrashdumpUploader uploader1("product", | |
139 "", | |
140 "AAA-BBB", | |
141 "", | |
142 "", | |
143 "", | |
144 "", | |
145 "/tmp/foo.dmp", | |
146 "", | |
147 "", | |
148 ""); | |
149 | |
150 ASSERT_FALSE(uploader1.Upload()); | |
151 | |
152 // Test with empty client GUID. | |
153 GoogleCrashdumpUploader uploader2("product", | |
154 "1.0", | |
155 "", | |
156 "", | |
157 "", | |
158 "", | |
159 "", | |
160 "/tmp/foo.dmp", | |
161 "", | |
162 "", | |
163 ""); | |
164 ASSERT_FALSE(uploader2.Upload()); | |
165 } | |
166 } | |
OLD | NEW |