OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 void Verify() { | 54 void Verify() { |
55 verified_ = true; | 55 verified_ = true; |
56 EXPECT_EQ(kStateWritten, state()); | 56 EXPECT_EQ(kStateWritten, state()); |
57 for (BaseTestMinidumpWritable* child : children_) { | 57 for (BaseTestMinidumpWritable* child : children_) { |
58 child->Verify(); | 58 child->Verify(); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 protected: | 62 protected: |
63 virtual bool Freeze() override { | 63 bool Freeze() override { |
64 EXPECT_EQ(kStateMutable, state()); | 64 EXPECT_EQ(kStateMutable, state()); |
65 bool rv = MinidumpWritable::Freeze(); | 65 bool rv = MinidumpWritable::Freeze(); |
66 EXPECT_TRUE(rv); | 66 EXPECT_TRUE(rv); |
67 EXPECT_EQ(kStateFrozen, state()); | 67 EXPECT_EQ(kStateFrozen, state()); |
68 return rv; | 68 return rv; |
69 } | 69 } |
70 | 70 |
71 virtual size_t Alignment() override { | 71 size_t Alignment() override { |
72 EXPECT_GE(state(), kStateFrozen); | 72 EXPECT_GE(state(), kStateFrozen); |
73 return has_alignment_ ? alignment_ : MinidumpWritable::Alignment(); | 73 return has_alignment_ ? alignment_ : MinidumpWritable::Alignment(); |
74 } | 74 } |
75 | 75 |
76 virtual std::vector<MinidumpWritable*> Children() override { | 76 std::vector<MinidumpWritable*> Children() override { |
77 EXPECT_GE(state(), kStateFrozen); | 77 EXPECT_GE(state(), kStateFrozen); |
78 if (!children_.empty()) { | 78 if (!children_.empty()) { |
79 std::vector<MinidumpWritable*> children; | 79 std::vector<MinidumpWritable*> children; |
80 for (BaseTestMinidumpWritable* child : children_) { | 80 for (BaseTestMinidumpWritable* child : children_) { |
81 children.push_back(child); | 81 children.push_back(child); |
82 } | 82 } |
83 return children; | 83 return children; |
84 } | 84 } |
85 return MinidumpWritable::Children(); | 85 return MinidumpWritable::Children(); |
86 } | 86 } |
87 | 87 |
88 virtual Phase WritePhase() override { | 88 Phase WritePhase() override { |
89 return has_phase_ ? phase_ : MinidumpWritable::Phase(); | 89 return has_phase_ ? phase_ : MinidumpWritable::Phase(); |
90 } | 90 } |
91 | 91 |
92 virtual bool WillWriteAtOffsetImpl(off_t offset) override { | 92 bool WillWriteAtOffsetImpl(off_t offset) override { |
93 EXPECT_EQ(state(), kStateFrozen); | 93 EXPECT_EQ(state(), kStateFrozen); |
94 expected_offset_ = offset; | 94 expected_offset_ = offset; |
95 bool rv = MinidumpWritable::WillWriteAtOffsetImpl(offset); | 95 bool rv = MinidumpWritable::WillWriteAtOffsetImpl(offset); |
96 EXPECT_TRUE(rv); | 96 EXPECT_TRUE(rv); |
97 return rv; | 97 return rv; |
98 } | 98 } |
99 | 99 |
100 virtual bool WriteObject(FileWriterInterface* file_writer) override { | 100 bool WriteObject(FileWriterInterface* file_writer) override { |
101 EXPECT_EQ(state(), kStateWritable); | 101 EXPECT_EQ(state(), kStateWritable); |
102 EXPECT_EQ(expected_offset_, file_writer->Seek(0, SEEK_CUR)); | 102 EXPECT_EQ(expected_offset_, file_writer->Seek(0, SEEK_CUR)); |
103 | 103 |
104 // Subclasses must override this. | 104 // Subclasses must override this. |
105 return false; | 105 return false; |
106 } | 106 } |
107 | 107 |
108 private: | 108 private: |
109 std::vector<BaseTestMinidumpWritable*> children_; | 109 std::vector<BaseTestMinidumpWritable*> children_; |
110 off_t expected_offset_; | 110 off_t expected_offset_; |
111 size_t alignment_; | 111 size_t alignment_; |
112 Phase phase_; | 112 Phase phase_; |
113 bool has_alignment_; | 113 bool has_alignment_; |
114 bool has_phase_; | 114 bool has_phase_; |
115 bool verified_; | 115 bool verified_; |
116 | 116 |
117 DISALLOW_COPY_AND_ASSIGN(BaseTestMinidumpWritable); | 117 DISALLOW_COPY_AND_ASSIGN(BaseTestMinidumpWritable); |
118 }; | 118 }; |
119 | 119 |
120 class TestStringMinidumpWritable final : public BaseTestMinidumpWritable { | 120 class TestStringMinidumpWritable final : public BaseTestMinidumpWritable { |
121 public: | 121 public: |
122 TestStringMinidumpWritable() : BaseTestMinidumpWritable(), data_() {} | 122 TestStringMinidumpWritable() : BaseTestMinidumpWritable(), data_() {} |
123 | 123 |
124 ~TestStringMinidumpWritable() {} | 124 ~TestStringMinidumpWritable() {} |
125 | 125 |
126 void SetData(const std::string& string) { data_ = string; } | 126 void SetData(const std::string& string) { data_ = string; } |
127 | 127 |
128 protected: | 128 protected: |
129 virtual size_t SizeOfObject() override { | 129 size_t SizeOfObject() override { |
130 EXPECT_GE(state(), kStateFrozen); | 130 EXPECT_GE(state(), kStateFrozen); |
131 return data_.size(); | 131 return data_.size(); |
132 } | 132 } |
133 | 133 |
134 virtual bool WriteObject(FileWriterInterface* file_writer) override { | 134 bool WriteObject(FileWriterInterface* file_writer) override { |
135 BaseTestMinidumpWritable::WriteObject(file_writer); | 135 BaseTestMinidumpWritable::WriteObject(file_writer); |
136 bool rv = file_writer->Write(&data_[0], data_.size()); | 136 bool rv = file_writer->Write(&data_[0], data_.size()); |
137 EXPECT_TRUE(rv); | 137 EXPECT_TRUE(rv); |
138 return rv; | 138 return rv; |
139 } | 139 } |
140 | 140 |
141 private: | 141 private: |
142 std::string data_; | 142 std::string data_; |
143 | 143 |
144 DISALLOW_COPY_AND_ASSIGN(TestStringMinidumpWritable); | 144 DISALLOW_COPY_AND_ASSIGN(TestStringMinidumpWritable); |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 484 |
485 class TestRVAMinidumpWritable final : public BaseTestMinidumpWritable { | 485 class TestRVAMinidumpWritable final : public BaseTestMinidumpWritable { |
486 public: | 486 public: |
487 TestRVAMinidumpWritable() : BaseTestMinidumpWritable(), rva_() {} | 487 TestRVAMinidumpWritable() : BaseTestMinidumpWritable(), rva_() {} |
488 | 488 |
489 ~TestRVAMinidumpWritable() {} | 489 ~TestRVAMinidumpWritable() {} |
490 | 490 |
491 void SetRVA(MinidumpWritable* other) { other->RegisterRVA(&rva_); } | 491 void SetRVA(MinidumpWritable* other) { other->RegisterRVA(&rva_); } |
492 | 492 |
493 protected: | 493 protected: |
494 virtual size_t SizeOfObject() override { | 494 size_t SizeOfObject() override { |
495 EXPECT_GE(state(), kStateFrozen); | 495 EXPECT_GE(state(), kStateFrozen); |
496 return sizeof(rva_); | 496 return sizeof(rva_); |
497 } | 497 } |
498 | 498 |
499 virtual bool WriteObject(FileWriterInterface* file_writer) override { | 499 bool WriteObject(FileWriterInterface* file_writer) override { |
500 BaseTestMinidumpWritable::WriteObject(file_writer); | 500 BaseTestMinidumpWritable::WriteObject(file_writer); |
501 EXPECT_TRUE(file_writer->Write(&rva_, sizeof(rva_))); | 501 EXPECT_TRUE(file_writer->Write(&rva_, sizeof(rva_))); |
502 return true; | 502 return true; |
503 } | 503 } |
504 | 504 |
505 private: | 505 private: |
506 RVA rva_; | 506 RVA rva_; |
507 | 507 |
508 DISALLOW_COPY_AND_ASSIGN(TestRVAMinidumpWritable); | 508 DISALLOW_COPY_AND_ASSIGN(TestRVAMinidumpWritable); |
509 }; | 509 }; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 | 621 |
622 ~TestLocationDescriptorMinidumpWritable() {} | 622 ~TestLocationDescriptorMinidumpWritable() {} |
623 | 623 |
624 void SetLocationDescriptor(MinidumpWritable* other) { | 624 void SetLocationDescriptor(MinidumpWritable* other) { |
625 other->RegisterLocationDescriptor(&location_descriptor_); | 625 other->RegisterLocationDescriptor(&location_descriptor_); |
626 } | 626 } |
627 | 627 |
628 void SetString(const std::string& string) { string_ = string; } | 628 void SetString(const std::string& string) { string_ = string; } |
629 | 629 |
630 protected: | 630 protected: |
631 virtual size_t SizeOfObject() override { | 631 size_t SizeOfObject() override { |
632 EXPECT_GE(state(), kStateFrozen); | 632 EXPECT_GE(state(), kStateFrozen); |
633 // NUL-terminate. | 633 // NUL-terminate. |
634 return sizeof(location_descriptor_) + string_.size() + 1; | 634 return sizeof(location_descriptor_) + string_.size() + 1; |
635 } | 635 } |
636 | 636 |
637 virtual bool WriteObject(FileWriterInterface* file_writer) override { | 637 bool WriteObject(FileWriterInterface* file_writer) override { |
638 BaseTestMinidumpWritable::WriteObject(file_writer); | 638 BaseTestMinidumpWritable::WriteObject(file_writer); |
639 WritableIoVec iov; | 639 WritableIoVec iov; |
640 iov.iov_base = &location_descriptor_; | 640 iov.iov_base = &location_descriptor_; |
641 iov.iov_len = sizeof(location_descriptor_); | 641 iov.iov_len = sizeof(location_descriptor_); |
642 std::vector<WritableIoVec> iovecs(1, iov); | 642 std::vector<WritableIoVec> iovecs(1, iov); |
643 // NUL-terminate. | 643 // NUL-terminate. |
644 iov.iov_base = &string_[0]; | 644 iov.iov_base = &string_[0]; |
645 iov.iov_len = string_.size() + 1; | 645 iov.iov_len = string_.size() + 1; |
646 iovecs.push_back(iov); | 646 iovecs.push_back(iov); |
647 EXPECT_TRUE(file_writer->WriteIoVec(&iovecs)); | 647 EXPECT_TRUE(file_writer->WriteIoVec(&iovecs)); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 EXPECT_EQ(10u, ldd->location_descriptor.DataSize); | 828 EXPECT_EQ(10u, ldd->location_descriptor.DataSize); |
829 EXPECT_EQ(12u, ldd->location_descriptor.Rva); | 829 EXPECT_EQ(12u, ldd->location_descriptor.Rva); |
830 EXPECT_STREQ("o", ldd->string); | 830 EXPECT_STREQ("o", ldd->string); |
831 parent.Verify(); | 831 parent.Verify(); |
832 } | 832 } |
833 } | 833 } |
834 | 834 |
835 } // namespace | 835 } // namespace |
836 } // namespace test | 836 } // namespace test |
837 } // namespace crashpad | 837 } // namespace crashpad |
OLD | NEW |