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 m : namespace kasko {
23 :
24 m : void ExpectMultipartMimeMessageIsPlausible(
25 m : const base::string16& boundary,
26 m : const std::map<base::string16, base::string16>& parameters,
27 m : const std::string& file,
28 m : const std::string& file_part_name,
29 m : const std::string& body) {
30 m : std::string::const_iterator range_begin = body.begin();
31 m : if (!parameters.empty()) {
32 m : std::string key = base::WideToUTF8(parameters.begin()->first);
33 m : std::string value = base::WideToUTF8(parameters.begin()->second);
34 m : range_begin = std::search(range_begin, body.end(), key.begin(), key.end());
35 m : EXPECT_NE(range_begin, body.end());
36 m : range_begin =
37 m : std::search(range_begin, body.end(), value.begin(), value.end());
38 m : EXPECT_NE(range_begin, body.end());
39 m : }
40 :
41 m : range_begin =
42 m : std::search(range_begin, body.end(), boundary.begin(), boundary.end());
43 m : EXPECT_NE(range_begin, body.end());
44 m : range_begin = std::search(range_begin, body.end(), file_part_name.begin(),
45 m : file_part_name.end());
46 m : EXPECT_NE(range_begin, body.end());
47 m : range_begin = std::search(range_begin, body.end(), file.begin(), file.end());
48 m : EXPECT_NE(range_begin, body.end());
49 m : }
50 :
51 m : } // namespace kasko
|