1 : // Copyright 2014 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/kasko/internet_unittest_helpers.h"
16 :
17 : #include <algorithm>
18 :
19 : #include "base/strings/utf_string_conversions.h"
20 : #include "gtest/gtest.h"
21 :
22 : namespace kasko {
23 :
24 : void ExpectMultipartMimeMessageIsPlausible(
25 : const base::string16& boundary,
26 : const std::map<base::string16, base::string16>& parameters,
27 : const std::string& file,
28 : const std::string& file_part_name,
29 E : const std::string& body) {
30 E : std::string::const_iterator range_begin = body.begin();
31 E : if (!parameters.empty()) {
32 E : std::string key = base::WideToUTF8(parameters.begin()->first);
33 E : std::string value = base::WideToUTF8(parameters.begin()->second);
34 E : range_begin = std::search(range_begin, body.end(), key.begin(), key.end());
35 E : EXPECT_NE(range_begin, body.end());
36 : range_begin =
37 E : std::search(range_begin, body.end(), value.begin(), value.end());
38 E : EXPECT_NE(range_begin, body.end());
39 E : }
40 :
41 : range_begin =
42 E : std::search(range_begin, body.end(), boundary.begin(), boundary.end());
43 E : EXPECT_NE(range_begin, body.end());
44 : range_begin = std::search(range_begin, body.end(), file_part_name.begin(),
45 E : file_part_name.end());
46 E : EXPECT_NE(range_begin, body.end());
47 E : range_begin = std::search(range_begin, body.end(), file.begin(), file.end());
48 E : EXPECT_NE(range_begin, body.end());
49 E : }
50 :
51 : } // namespace kasko
|