Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Unified Diff: minidump/minidump_string_writer_test_util.cc

Issue 654573003: Add MinidumpCrashpadInfoWriter and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: minidump/minidump_string_writer_test_util.cc
diff --git a/minidump/minidump_string_writer_test_util.cc b/minidump/minidump_string_writer_test_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7914c68ab5c31d6048e516ec5dedc9d504615bf6
--- /dev/null
+++ b/minidump/minidump_string_writer_test_util.cc
@@ -0,0 +1,56 @@
+// Copyright 2014 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 "minidump/minidump_string_writer_test_util.h"
+
+#include "gtest/gtest.h"
+#include "minidump/minidump_extensions.h"
+
+namespace crashpad {
+namespace test {
+
+std::string MinidumpUTF8StringAtRVA(const StringFileWriter& file_writer,
+ RVA rva) {
+ const std::string& contents = file_writer.string();
+ if (rva == 0) {
+ return std::string();
+ }
+
+ if (rva + sizeof(MinidumpUTF8String) > contents.size()) {
+ ADD_FAILURE()
+ << "rva " << rva << " too large for contents " << contents.size();
+ return std::string();
+ }
+
+ const MinidumpUTF8String* minidump_string =
+ reinterpret_cast<const MinidumpUTF8String*>(&contents[rva]);
+
+ // Verify that the file has enough data for the string’s stated length plus
+ // its required NUL terminator.
+ if (rva + sizeof(MinidumpUTF8String) + minidump_string->Length + 1 >
+ contents.size()) {
+ ADD_FAILURE()
+ << "rva " << rva << ", length " << minidump_string->Length
+ << " too large for contents " << contents.size();
+ return std::string();
+ }
+
+ std::string minidump_string_data(
+ reinterpret_cast<const char*>(&minidump_string->Buffer[0]),
+ minidump_string->Length);
+ return minidump_string_data;
+}
+
+} // namespace test
+} // namespace crashpad
« minidump/minidump_string_writer_test_util.h ('K') | « minidump/minidump_string_writer_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698