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/poirot/minidump_processor.h"
16 :
17 : #include "gtest/gtest.h"
18 : #include "syzygy/core/unittest_util.h"
19 : #include "syzygy/crashdata/json.h"
20 : #include "syzygy/poirot/unittest_util.h"
21 :
22 : namespace poirot {
23 :
24 : namespace {
25 :
26 : class TestMinidumpProcessor : public MinidumpProcessor {
27 : public:
28 E : explicit TestMinidumpProcessor(base::FilePath minidump_path)
29 E : : MinidumpProcessor(minidump_path) {}
30 : using MinidumpProcessor::input_minidump_;
31 : using MinidumpProcessor::processed_;
32 : using MinidumpProcessor::protobuf_value_;
33 : };
34 :
35 : } // namespace
36 :
37 E : TEST(MinidumpProcessorTest, ProcessingFailsForInvalidFilePath) {
38 E : base::FilePath minidump_path(testing::kMinidumpInvalidPath);
39 E : TestMinidumpProcessor minidump_processor(minidump_path);
40 E : EXPECT_FALSE(minidump_processor.ProcessDump());
41 E : }
42 :
43 E : TEST(MinidumpProcessorTest, ProcessingFailsForMinidumpWithNoKaskoStream) {
44 E : base::FilePath minidump_path(testing::kMinidumpNoKaskoStream);
45 E : TestMinidumpProcessor minidump_processor(minidump_path);
46 E : EXPECT_FALSE(minidump_processor.ProcessDump());
47 E : }
48 :
49 E : TEST(MinidumpProcessorTest, ProcessingSucceedsForValidFile) {
50 E : TestMinidumpProcessor minidump_processor(
51 : testing::GetSrcRelativePath(testing::kMinidumpUAF));
52 E : EXPECT_TRUE(minidump_processor.ProcessDump());
53 E : EXPECT_TRUE(minidump_processor.processed_);
54 E : }
55 :
56 E : TEST(MinidumpProcessorTest, GenerateJsonOutput) {
57 E : TestMinidumpProcessor minidump_processor(
58 : testing::GetSrcRelativePath(testing::kMinidumpUAF));
59 E : EXPECT_TRUE(minidump_processor.ProcessDump());
60 E : EXPECT_TRUE(minidump_processor.processed_);
61 E : std::string protobuf_value;
62 E : EXPECT_TRUE(crashdata::ToJson(true, &minidump_processor.protobuf_value_,
63 E : &protobuf_value));
64 E : EXPECT_FALSE(protobuf_value.empty());
65 E : base::FilePath temp_file;
66 E : EXPECT_TRUE(base::CreateTemporaryFile(&temp_file));
67 : {
68 E : base::ScopedFILE out(base::OpenFile(temp_file, "wb"));
69 E : EXPECT_TRUE(minidump_processor.GenerateJsonOutput(out.get()));
70 E : }
71 E : std::string file_data;
72 E : EXPECT_TRUE(base::ReadFileToString(temp_file, &file_data));
73 E : EXPECT_TRUE(base::DeleteFile(temp_file, false));
74 E : EXPECT_STREQ(protobuf_value.c_str(), file_data.c_str());
75 E : }
76 :
77 : } // namespace poirot
|