1 : // Copyright 2015 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/testing/mock_service.h"
16 :
17 : #include <stdint.h>
18 : #include <string>
19 : #include <vector>
20 :
21 : #include "base/process/process_handle.h"
22 : #include "base/threading/platform_thread.h"
23 : #include "gtest/gtest.h"
24 : #include "syzygy/kasko/minidump_request.h"
25 :
26 : namespace kasko {
27 : namespace testing {
28 :
29 E : TEST(MockServiceTest, ParameterMapping) {
30 E : std::vector<testing::MockService::CallRecord> call_log;
31 E : testing::MockService mock_service(&call_log);
32 :
33 E : std::string protobuf = "hello world";
34 E : uint32_t kStreamType = 987;
35 E : uint32_t kExceptionInfoAddress = 1122;
36 E : base::PlatformThreadId kThreadId = 3;
37 E : base::ProcessId kProcessId = 44;
38 :
39 E : MinidumpRequest request;
40 E : request.exception_info_address = kExceptionInfoAddress;
41 E : request.type = MinidumpRequest::SMALL_DUMP_TYPE;
42 E : request.crash_keys.push_back(MinidumpRequest::CrashKey(L"foo", L"bar"));
43 : MinidumpRequest::CustomStream custom_stream = {kStreamType, protobuf.data(),
44 E : protobuf.length()};
45 E : request.custom_streams.push_back(custom_stream);
46 E : MinidumpRequest::MemoryRange memory_range = {0xdeadbeef, 100};
47 E : request.user_selected_memory_ranges.push_back(memory_range);
48 :
49 E : mock_service.SendDiagnosticReport(kProcessId, kThreadId, request);
50 :
51 E : ASSERT_EQ(1u, call_log.size());
52 E : ASSERT_EQ(kExceptionInfoAddress, call_log[0].exception_info_address);
53 E : ASSERT_EQ(kProcessId, call_log[0].client_process_id);
54 E : ASSERT_EQ(kThreadId, call_log[0].thread_id);
55 E : ASSERT_EQ(MinidumpRequest::SMALL_DUMP_TYPE, call_log[0].minidump_type);
56 E : ASSERT_EQ(1u, call_log[0].user_selected_memory_ranges.size());
57 : ASSERT_EQ(memory_range.start(),
58 E : call_log[0].user_selected_memory_ranges[0].start());
59 : ASSERT_EQ(memory_range.size(),
60 E : call_log[0].user_selected_memory_ranges[0].size());
61 E : ASSERT_EQ(1u, call_log[0].crash_keys.size());
62 E : auto crash_keys_entry = call_log[0].crash_keys.find(L"foo");
63 E : ASSERT_NE(call_log[0].crash_keys.end(), crash_keys_entry);
64 E : ASSERT_EQ(L"bar", crash_keys_entry->second);
65 E : ASSERT_EQ(1u, call_log[0].custom_streams.size());
66 E : auto custom_streams_entry = call_log[0].custom_streams.find(kStreamType);
67 E : ASSERT_NE(call_log[0].custom_streams.end(), custom_streams_entry);
68 E : ASSERT_EQ(protobuf, custom_streams_entry->second);
69 E : }
70 :
71 : } // namespace testing
72 : } // namespace kasko
|