1 // Copyright 2016 The Crashpad Authors. 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 "util/win/initial_client_data.h"
16
17 #include "gtest/gtest.h"
18
19 namespace crashpad {
20 namespace test {
21 namespace {
22
TEST(InitialClientData,Validity)23 TEST(InitialClientData, Validity) {
24 InitialClientData icd1;
25 EXPECT_FALSE(icd1.IsValid());
26
27 InitialClientData icd2(
28 reinterpret_cast<HANDLE>(0x123),
29 reinterpret_cast<HANDLE>(0x456),
30 reinterpret_cast<HANDLE>(0x789),
31 reinterpret_cast<HANDLE>(0xabc),
32 reinterpret_cast<HANDLE>(0xdef),
33 0x7fff000012345678ull,
34 0x100000ull,
35 0xccccddddeeeeffffull);
36 EXPECT_TRUE(icd2.IsValid());
37 }
38
TEST(InitialClientData,RoundTrip)39 TEST(InitialClientData, RoundTrip) {
40 InitialClientData first(
41 reinterpret_cast<HANDLE>(0x123),
42 reinterpret_cast<HANDLE>(0x456),
43 reinterpret_cast<HANDLE>(0x789),
44 reinterpret_cast<HANDLE>(0xabc),
45 reinterpret_cast<HANDLE>(0xdef),
46 0x7fff000012345678ull,
47 0x100000ull,
48 0xccccddddeeeeffffull);
49
50 std::string as_string = first.StringRepresentation();
51 EXPECT_EQ(as_string,
52 "0x123,0x456,0x789,0xabc,0xdef,"
53 "0x7fff000012345678,0x100000,0xccccddddeeeeffff");
54
55 InitialClientData second;
56 ASSERT_TRUE(second.InitializeFromString(as_string));
57 EXPECT_EQ(second.request_crash_dump(), first.request_crash_dump());
58 EXPECT_EQ(second.request_non_crash_dump(), first.request_non_crash_dump());
59 EXPECT_EQ(second.non_crash_dump_completed(),
60 first.non_crash_dump_completed());
61 EXPECT_EQ(second.first_pipe_instance(), first.first_pipe_instance());
62 EXPECT_EQ(second.client_process(), first.client_process());
63 EXPECT_EQ(second.crash_exception_information(),
64 first.crash_exception_information());
65 EXPECT_EQ(second.non_crash_exception_information(),
66 first.non_crash_exception_information());
67 EXPECT_EQ(second.debug_critical_section_address(),
68 first.debug_critical_section_address());
69 }
70
71 } // namespace
72 } // namespace test
73 } // namespace crashpad
74