Chromium Code Reviews| Index: snapshot/minidump/process_snapshot_minidump_test.cc |
| diff --git a/snapshot/minidump/process_snapshot_minidump_test.cc b/snapshot/minidump/process_snapshot_minidump_test.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..12ea6fd9feafa6d698a6293dfa25929730406522 |
| --- /dev/null |
| +++ b/snapshot/minidump/process_snapshot_minidump_test.cc |
| @@ -0,0 +1,140 @@ |
| +// Copyright 2015 The Crashpad Authors. All rights reserved. |
| +// |
| +// Licensed under the Apache License, Version 2.0 (the "License"); |
| +// you may not use this file except in compliance with the License. |
| +// You may obtain a copy of the License at |
| +// |
| +// http://www.apache.org/licenses/LICENSE-2.0 |
| +// |
| +// Unless required by applicable law or agreed to in writing, software |
| +// distributed under the License is distributed on an "AS IS" BASIS, |
| +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| +// See the License for the specific language governing permissions and |
| +// limitations under the License. |
| + |
| +#include "snapshot/minidump/process_snapshot_minidump.h" |
| + |
| +#include <string.h> |
| +#include <windows.h> |
| +#include <dbghelp.h> |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "gtest/gtest.h" |
| +#include "util/file/string_file.h" |
| + |
| +namespace crashpad { |
| +namespace test { |
| +namespace { |
| + |
| +TEST(ProcessSnapshotMinidump, EmptyFile) { |
| + StringFile string_file; |
| + ProcessSnapshotMinidump process_snapshot; |
| + |
| + EXPECT_FALSE(process_snapshot.Initialize(&string_file)); |
| +} |
| + |
| +TEST(ProcessSnapshotMinidump, InvalidSignatureAndVersion) { |
| + StringFile string_file; |
| + |
| + MINIDUMP_HEADER header = {}; |
| + |
| + EXPECT_TRUE(string_file.Write(&header, sizeof(header))); |
| + |
| + ProcessSnapshotMinidump process_snapshot; |
| + EXPECT_FALSE(process_snapshot.Initialize(&string_file)); |
| +} |
| + |
| +TEST(ProcessSnapshotMinidump, Empty) { |
| + StringFile string_file; |
| + |
| + MINIDUMP_HEADER header = {}; |
| + header.Signature = MINIDUMP_SIGNATURE; |
| + header.Version = MINIDUMP_VERSION; |
| + |
| + EXPECT_TRUE(string_file.Write(&header, sizeof(header))); |
| + |
| + ProcessSnapshotMinidump process_snapshot; |
| + EXPECT_TRUE(process_snapshot.Initialize(&string_file)); |
| +} |
| + |
| +TEST(ProcessSnapshotMinidump, AnnotationsSimpleMap) { |
| + StringFile string_file; |
| + |
| + MINIDUMP_HEADER header = {}; |
| + EXPECT_TRUE(string_file.Write(&header, sizeof(header))); |
| + |
| + MinidumpSimpleStringDictionaryEntry entry0 = {}; |
| + entry0.key = string_file.SeekGet(); |
| + const char kKey0[] = "the first key"; |
| + MinidumpUTF8String string = {}; |
| + string.Length = strlen(kKey0); |
| + EXPECT_TRUE(string_file.Write(&string, sizeof(string))); |
| + EXPECT_TRUE(string_file.Write(kKey0, sizeof(kKey0))); |
| + |
| + entry0.value = string_file.SeekGet(); |
| + const char kValue0[] = "THE FIRST VALUE EVER!"; |
| + string.Length = strlen(kValue0); |
| + EXPECT_TRUE(string_file.Write(&string, sizeof(string))); |
| + EXPECT_TRUE(string_file.Write(kValue0, sizeof(kValue0))); |
| + |
| + MinidumpSimpleStringDictionaryEntry entry1 = {}; |
| + entry1.key = string_file.SeekGet(); |
| + const char kKey1[] = "2key"; |
| + string.Length = strlen(kKey1); |
| + EXPECT_TRUE(string_file.Write(&string, sizeof(string))); |
| + EXPECT_TRUE(string_file.Write(kKey1, sizeof(kKey1))); |
| + |
| + entry1.value = string_file.SeekGet(); |
| + const char kValue1[] = "THE FIRST VALUE EVER!"; |
|
Robert Sesek
2015/02/19 15:13:19
SECOND VALUE EVER?
|
| + string.Length = strlen(kValue1); |
| + EXPECT_TRUE(string_file.Write(&string, sizeof(string))); |
| + EXPECT_TRUE(string_file.Write(kValue1, sizeof(kValue1))); |
| + |
| + MinidumpCrashpadInfo crashpad_info = {}; |
| + crashpad_info.version = MinidumpCrashpadInfo::kVersion; |
| + |
| + crashpad_info.simple_annotations.Rva = string_file.SeekGet(); |
| + MinidumpSimpleStringDictionary simple_string_dictionary = {}; |
| + simple_string_dictionary.count = 2; |
| + EXPECT_TRUE(string_file.Write(&simple_string_dictionary, |
| + sizeof(simple_string_dictionary))); |
| + EXPECT_TRUE(string_file.Write(&entry0, sizeof(entry0))); |
| + EXPECT_TRUE(string_file.Write(&entry1, sizeof(entry1))); |
| + crashpad_info.simple_annotations.DataSize = |
| + simple_string_dictionary.count * |
| + sizeof(simple_string_dictionary.entries[0]); |
| + |
| + MINIDUMP_DIRECTORY crashpad_info_directory = {}; |
| + crashpad_info_directory.StreamType = kMinidumpStreamTypeCrashpadInfo; |
| + crashpad_info_directory.Location.Rva = string_file.SeekGet(); |
| + EXPECT_TRUE(string_file.Write(&crashpad_info, sizeof(crashpad_info))); |
| + crashpad_info_directory.Location.DataSize = sizeof(crashpad_info); |
| + |
| + header.StreamDirectoryRva = string_file.SeekGet(); |
| + EXPECT_TRUE(string_file.Write(&crashpad_info_directory, |
| + sizeof(crashpad_info_directory))); |
| + |
| + header.Signature = MINIDUMP_SIGNATURE; |
| + header.Version = MINIDUMP_VERSION; |
| + header.NumberOfStreams = 1; |
| + EXPECT_TRUE(string_file.SeekSet(0)); |
| + EXPECT_TRUE(string_file.Write(&header, sizeof(header))); |
| + |
| + ProcessSnapshotMinidump process_snapshot; |
| + EXPECT_TRUE(process_snapshot.Initialize(&string_file)); |
| + |
| + const auto annotations_simple_map = process_snapshot.AnnotationsSimpleMap(); |
| + EXPECT_EQ(2u, annotations_simple_map.size()); |
| + |
| + auto it = annotations_simple_map.find(kKey0); |
| + ASSERT_NE(it, annotations_simple_map.end()); |
| + EXPECT_EQ(kValue0, it->second); |
| + |
| + it = annotations_simple_map.find(kKey1); |
| + ASSERT_NE(it, annotations_simple_map.end()); |
| + EXPECT_EQ(kValue1, it->second); |
| +} |
| + |
| +} // namespace |
| +} // namespace test |
| +} // namespace crashpad |