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 : #ifndef SYZYGY_KASKO_TESTING_MOCK_SERVICE_H_
16 : #define SYZYGY_KASKO_TESTING_MOCK_SERVICE_H_
17 :
18 : #include <map>
19 : #include <string>
20 : #include <vector>
21 :
22 : #include "base/macros.h"
23 : #include "base/process/process_handle.h"
24 : #include "base/strings/string16.h"
25 : #include "syzygy/kasko/service.h"
26 :
27 m : namespace kasko {
28 m : namespace testing {
29 :
30 : // Handles Kasko RPC invocations by logging their parameters.
31 m : class MockService : public Service {
32 m : public:
33 : // Records the parameters of an RPC invocation.
34 m : struct CallRecord {
35 : // The caller process ID.
36 m : const base::ProcessId client_process_id;
37 :
38 : // The requested minidump type.
39 m : MinidumpType minidump_type;
40 :
41 : // The supplied protobuf.
42 m : const std::string protobuf;
43 :
44 : // The supplied crash keys.
45 m : const std::map<base::string16, base::string16> crash_keys;
46 m : };
47 :
48 : // Instantiates a service that records calls in the provided vector.
49 : // @param call_log The vector in which calls should be recorded.
50 : // @note call_log will be modified in whichever thread the RPC is handled.
51 : // It is the client's responsibility to prevent problems from concurrent
52 : // access.
53 m : explicit MockService(std::vector<CallRecord>* call_log);
54 m : virtual ~MockService();
55 :
56 : // Service implementation.
57 m : virtual void SendDiagnosticReport(
58 m : base::ProcessId client_process_id,
59 m : uint64_t exception_info_address,
60 m : base::PlatformThreadId thread_id,
61 m : MinidumpType minidump_type,
62 m : const char* protobuf,
63 m : size_t protobuf_length,
64 m : const std::map<base::string16, base::string16>& crash_keys) override;
65 :
66 m : private:
67 m : std::vector<CallRecord>* call_log_;
68 :
69 m : DISALLOW_COPY_AND_ASSIGN(MockService);
70 m : };
71 :
72 m : } // namespace testing
73 m : } // namespace kasko
74 :
75 : #endif // SYZYGY_KASKO_TESTING_MOCK_SERVICE_H_
|