Add FileReaderInterface. Move StringFileWriter to StringFile and

implement the new interface.

The upcoming minidump reader will get minidump data from a
FileReaderInterface. For ease of testing, a string-based implementation
is provided. There wasn’t a good reason to have a separate
StringFileReader and StringFileWriter, so I combined them into a single
StringFile.

TEST=util_test StringFile.*
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/936153002
This commit is contained in:
Mark Mentovai 2015-02-18 14:15:38 -05:00
parent a0f5dc62a4
commit 583233cf78
25 changed files with 1383 additions and 992 deletions

View File

@ -22,14 +22,14 @@
#include "minidump/test/minidump_writable_test_util.h"
#include "snapshot/cpu_context.h"
#include "snapshot/test/test_cpu_context.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
namespace {
TEST(MinidumpContextWriter, MinidumpContextX86Writer) {
StringFileWriter file_writer;
StringFile string_file;
{
// Make sure that a context writer thats untouched writes a zeroed-out
@ -38,11 +38,11 @@ TEST(MinidumpContextWriter, MinidumpContextX86Writer) {
MinidumpContextX86Writer context_writer;
EXPECT_TRUE(context_writer.WriteEverything(&file_writer));
ASSERT_EQ(sizeof(MinidumpContextX86), file_writer.string().size());
EXPECT_TRUE(context_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpContextX86), string_file.string().size());
const MinidumpContextX86* observed =
MinidumpWritableAtRVA<MinidumpContextX86>(file_writer.string(), 0);
MinidumpWritableAtRVA<MinidumpContextX86>(string_file.string(), 0);
ASSERT_TRUE(observed);
ExpectMinidumpContextX86(0, observed, false);
@ -51,17 +51,17 @@ TEST(MinidumpContextWriter, MinidumpContextX86Writer) {
{
SCOPED_TRACE("nonzero");
file_writer.Reset();
string_file.Reset();
const uint32_t kSeed = 0x8086;
MinidumpContextX86Writer context_writer;
InitializeMinidumpContextX86(context_writer.context(), kSeed);
EXPECT_TRUE(context_writer.WriteEverything(&file_writer));
ASSERT_EQ(sizeof(MinidumpContextX86), file_writer.string().size());
EXPECT_TRUE(context_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpContextX86), string_file.string().size());
const MinidumpContextX86* observed =
MinidumpWritableAtRVA<MinidumpContextX86>(file_writer.string(), 0);
MinidumpWritableAtRVA<MinidumpContextX86>(string_file.string(), 0);
ASSERT_TRUE(observed);
ExpectMinidumpContextX86(kSeed, observed, false);
@ -69,7 +69,7 @@ TEST(MinidumpContextWriter, MinidumpContextX86Writer) {
}
TEST(MinidumpContextWriter, MinidumpContextAMD64Writer) {
StringFileWriter file_writer;
StringFile string_file;
{
// Make sure that a context writer thats untouched writes a zeroed-out
@ -78,11 +78,11 @@ TEST(MinidumpContextWriter, MinidumpContextAMD64Writer) {
MinidumpContextAMD64Writer context_writer;
EXPECT_TRUE(context_writer.WriteEverything(&file_writer));
ASSERT_EQ(sizeof(MinidumpContextAMD64), file_writer.string().size());
EXPECT_TRUE(context_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpContextAMD64), string_file.string().size());
const MinidumpContextAMD64* observed =
MinidumpWritableAtRVA<MinidumpContextAMD64>(file_writer.string(), 0);
MinidumpWritableAtRVA<MinidumpContextAMD64>(string_file.string(), 0);
ASSERT_TRUE(observed);
ExpectMinidumpContextAMD64(0, observed, false);
@ -91,17 +91,17 @@ TEST(MinidumpContextWriter, MinidumpContextAMD64Writer) {
{
SCOPED_TRACE("nonzero");
file_writer.Reset();
string_file.Reset();
const uint32_t kSeed = 0x808664;
MinidumpContextAMD64Writer context_writer;
InitializeMinidumpContextAMD64(context_writer.context(), kSeed);
EXPECT_TRUE(context_writer.WriteEverything(&file_writer));
ASSERT_EQ(sizeof(MinidumpContextAMD64), file_writer.string().size());
EXPECT_TRUE(context_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpContextAMD64), string_file.string().size());
const MinidumpContextAMD64* observed =
MinidumpWritableAtRVA<MinidumpContextAMD64>(file_writer.string(), 0);
MinidumpWritableAtRVA<MinidumpContextAMD64>(string_file.string(), 0);
ASSERT_TRUE(observed);
ExpectMinidumpContextAMD64(kSeed, observed, false);
@ -120,11 +120,11 @@ TEST(MinidumpContextWriter, CreateFromSnapshot_X86) {
MinidumpContextWriter::CreateFromSnapshot(&context_snapshot);
ASSERT_TRUE(context_writer);
StringFileWriter file_writer;
ASSERT_TRUE(context_writer->WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(context_writer->WriteEverything(&string_file));
const MinidumpContextX86* observed =
MinidumpWritableAtRVA<MinidumpContextX86>(file_writer.string(), 0);
MinidumpWritableAtRVA<MinidumpContextX86>(string_file.string(), 0);
ASSERT_TRUE(observed);
ExpectMinidumpContextX86(kSeed, observed, true);
@ -142,11 +142,11 @@ TEST(MinidumpContextWriter, CreateFromSnapshot_AMD64) {
MinidumpContextWriter::CreateFromSnapshot(&context_snapshot);
ASSERT_TRUE(context_writer);
StringFileWriter file_writer;
ASSERT_TRUE(context_writer->WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(context_writer->WriteEverything(&string_file));
const MinidumpContextAMD64* observed =
MinidumpWritableAtRVA<MinidumpContextAMD64>(file_writer.string(), 0);
MinidumpWritableAtRVA<MinidumpContextAMD64>(string_file.string(), 0);
ASSERT_TRUE(observed);
ExpectMinidumpContextAMD64(kSeed, observed, true);

View File

@ -30,7 +30,7 @@
#include "minidump/test/minidump_writable_test_util.h"
#include "snapshot/test/test_module_snapshot.h"
#include "snapshot/test/test_process_snapshot.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
@ -69,15 +69,15 @@ TEST(MinidumpCrashpadInfoWriter, Empty) {
minidump_file_writer.AddStream(crashpad_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MinidumpCrashpadInfo* crashpad_info = nullptr;
const MinidumpSimpleStringDictionary* simple_annotations = nullptr;
const MinidumpModuleCrashpadInfoList* module_list = nullptr;
ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream(
file_writer.string(), &crashpad_info, &simple_annotations, &module_list));
string_file.string(), &crashpad_info, &simple_annotations, &module_list));
EXPECT_EQ(MinidumpCrashpadInfo::kVersion, crashpad_info->version);
EXPECT_FALSE(simple_annotations);
@ -108,15 +108,15 @@ TEST(MinidumpCrashpadInfoWriter, SimpleAnnotations) {
minidump_file_writer.AddStream(crashpad_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MinidumpCrashpadInfo* crashpad_info = nullptr;
const MinidumpSimpleStringDictionary* simple_annotations = nullptr;
const MinidumpModuleCrashpadInfoList* module_list = nullptr;
ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream(
file_writer.string(), &crashpad_info, &simple_annotations, &module_list));
string_file.string(), &crashpad_info, &simple_annotations, &module_list));
EXPECT_EQ(MinidumpCrashpadInfo::kVersion, crashpad_info->version);
EXPECT_FALSE(module_list);
@ -125,10 +125,10 @@ TEST(MinidumpCrashpadInfoWriter, SimpleAnnotations) {
ASSERT_EQ(1u, simple_annotations->count);
EXPECT_EQ(kKey,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations->entries[0].key));
string_file.string(), simple_annotations->entries[0].key));
EXPECT_EQ(kValue,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations->entries[0].value));
string_file.string(), simple_annotations->entries[0].value));
}
TEST(MinidumpCrashpadInfoWriter, CrashpadModuleList) {
@ -148,15 +148,15 @@ TEST(MinidumpCrashpadInfoWriter, CrashpadModuleList) {
minidump_file_writer.AddStream(crashpad_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MinidumpCrashpadInfo* crashpad_info = nullptr;
const MinidumpSimpleStringDictionary* simple_annotations = nullptr;
const MinidumpModuleCrashpadInfoList* module_list = nullptr;
ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream(
file_writer.string(), &crashpad_info, &simple_annotations, &module_list));
string_file.string(), &crashpad_info, &simple_annotations, &module_list));
EXPECT_EQ(MinidumpCrashpadInfo::kVersion, crashpad_info->version);
EXPECT_FALSE(simple_annotations);
@ -166,7 +166,7 @@ TEST(MinidumpCrashpadInfoWriter, CrashpadModuleList) {
const MinidumpModuleCrashpadInfo* module =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
file_writer.string(), module_list->children[0]);
string_file.string(), module_list->children[0]);
ASSERT_TRUE(module);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module->version);
@ -212,14 +212,14 @@ TEST(MinidumpCrashpadInfoWriter, InitializeFromSnapshot) {
MinidumpFileWriter minidump_file_writer;
minidump_file_writer.AddStream(info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MinidumpCrashpadInfo* info = nullptr;
const MinidumpSimpleStringDictionary* simple_annotations;
const MinidumpModuleCrashpadInfoList* module_list;
ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream(
file_writer.string(), &info, &simple_annotations, &module_list));
string_file.string(), &info, &simple_annotations, &module_list));
EXPECT_EQ(MinidumpCrashpadInfo::kVersion, info->version);
@ -227,17 +227,17 @@ TEST(MinidumpCrashpadInfoWriter, InitializeFromSnapshot) {
ASSERT_EQ(1u, simple_annotations->count);
EXPECT_EQ(kKey,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations->entries[0].key));
string_file.string(), simple_annotations->entries[0].key));
EXPECT_EQ(kValue,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations->entries[0].value));
string_file.string(), simple_annotations->entries[0].value));
ASSERT_TRUE(module_list);
ASSERT_EQ(1u, module_list->count);
const MinidumpModuleCrashpadInfo* module =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
file_writer.string(), module_list->children[0]);
string_file.string(), module_list->children[0]);
ASSERT_TRUE(module);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module->version);
@ -245,17 +245,17 @@ TEST(MinidumpCrashpadInfoWriter, InitializeFromSnapshot) {
const MinidumpRVAList* list_annotations =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
file_writer.string(), module->list_annotations);
string_file.string(), module->list_annotations);
ASSERT_TRUE(list_annotations);
ASSERT_EQ(1u, list_annotations->count);
EXPECT_EQ(kEntry,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
list_annotations->children[0]));
const MinidumpSimpleStringDictionary* module_simple_annotations =
MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
file_writer.string(), module->simple_annotations);
string_file.string(), module->simple_annotations);
EXPECT_FALSE(module_simple_annotations);
}

View File

@ -33,7 +33,7 @@
#include "minidump/test/minidump_writable_test_util.h"
#include "snapshot/test/test_cpu_context.h"
#include "snapshot/test/test_exception_snapshot.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
@ -107,12 +107,12 @@ TEST(MinidumpExceptionWriter, Minimal) {
minidump_file_writer.AddStream(exception_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetExceptionStream(file_writer.string(), &observed_exception_stream));
GetExceptionStream(string_file.string(), &observed_exception_stream));
MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {};
expected_exception_stream.ThreadContext.DataSize = sizeof(MinidumpContextX86);
@ -120,7 +120,7 @@ TEST(MinidumpExceptionWriter, Minimal) {
const MinidumpContextX86* observed_context = nullptr;
ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream,
observed_exception_stream,
file_writer.string(),
string_file.string(),
&observed_context));
ASSERT_NO_FATAL_FAILURE(
@ -166,12 +166,12 @@ TEST(MinidumpExceptionWriter, Standard) {
minidump_file_writer.AddStream(exception_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetExceptionStream(file_writer.string(), &observed_exception_stream));
GetExceptionStream(string_file.string(), &observed_exception_stream));
MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {};
expected_exception_stream.ThreadId = kThreadID;
@ -191,7 +191,7 @@ TEST(MinidumpExceptionWriter, Standard) {
const MinidumpContextX86* observed_context = nullptr;
ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream,
observed_exception_stream,
file_writer.string(),
string_file.string(),
&observed_context));
ASSERT_NO_FATAL_FAILURE(
@ -238,16 +238,16 @@ TEST(MinidumpExceptionWriter, InitializeFromSnapshot) {
MinidumpFileWriter minidump_file_writer;
minidump_file_writer.AddStream(exception_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_EXCEPTION_STREAM* exception = nullptr;
ASSERT_NO_FATAL_FAILURE(GetExceptionStream(file_writer.string(), &exception));
ASSERT_NO_FATAL_FAILURE(GetExceptionStream(string_file.string(), &exception));
const MinidumpContextX86* observed_context = nullptr;
ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expect_exception,
exception,
file_writer.string(),
string_file.string(),
&observed_context));
ASSERT_NO_FATAL_FAILURE(
@ -260,8 +260,8 @@ TEST(MinidumpExceptionWriterDeathTest, NoContext) {
minidump_file_writer.AddStream(exception_writer.Pass());
StringFileWriter file_writer;
ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_");
StringFile string_file;
ASSERT_DEATH(minidump_file_writer.WriteEverything(&string_file), "context_");
}
TEST(MinidumpExceptionWriterDeathTest, TooMuchInformation) {

View File

@ -32,8 +32,8 @@
#include "snapshot/test/test_process_snapshot.h"
#include "snapshot/test/test_system_snapshot.h"
#include "snapshot/test/test_thread_snapshot.h"
#include "util/file/file_writer.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
@ -41,13 +41,13 @@ namespace {
TEST(MinidumpFileWriter, Empty) {
MinidumpFileWriter minidump_file;
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file.WriteEverything(&file_writer));
ASSERT_EQ(sizeof(MINIDUMP_HEADER), file_writer.string().size());
StringFile string_file;
ASSERT_TRUE(minidump_file.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MINIDUMP_HEADER), string_file.string().size());
const MINIDUMP_DIRECTORY* directory;
const MINIDUMP_HEADER* header =
MinidumpHeaderAtStart(file_writer.string(), &directory);
MinidumpHeaderAtStart(string_file.string(), &directory);
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 0, 0));
EXPECT_FALSE(directory);
}
@ -97,18 +97,18 @@ TEST(MinidumpFileWriter, OneStream) {
make_scoped_ptr(new TestStream(kStreamType, kStreamSize, kStreamValue));
minidump_file.AddStream(stream.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file.WriteEverything(&string_file));
const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
const size_t kStreamOffset = kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY);
const size_t kFileSize = kStreamOffset + kStreamSize;
ASSERT_EQ(kFileSize, file_writer.string().size());
ASSERT_EQ(kFileSize, string_file.string().size());
const MINIDUMP_DIRECTORY* directory;
const MINIDUMP_HEADER* header =
MinidumpHeaderAtStart(file_writer.string(), &directory);
MinidumpHeaderAtStart(string_file.string(), &directory);
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, kTimestamp));
ASSERT_TRUE(directory);
@ -117,7 +117,7 @@ TEST(MinidumpFileWriter, OneStream) {
EXPECT_EQ(kStreamOffset, directory[0].Location.Rva);
const uint8_t* stream_data = MinidumpWritableAtLocationDescriptor<uint8_t>(
file_writer.string(), directory[0].Location);
string_file.string(), directory[0].Location);
ASSERT_TRUE(stream_data);
std::string expected_stream(kStreamSize, kStreamValue);
@ -153,8 +153,8 @@ TEST(MinidumpFileWriter, ThreeStreams) {
new TestStream(kStream2Type, kStream2Size, kStream2Value));
minidump_file.AddStream(stream2.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file.WriteEverything(&string_file));
const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
const size_t kStream0Offset =
@ -165,11 +165,11 @@ TEST(MinidumpFileWriter, ThreeStreams) {
const size_t kStream2Offset = kStream1Offset + kStream1Size + kStream2Padding;
const size_t kFileSize = kStream2Offset + kStream2Size;
ASSERT_EQ(kFileSize, file_writer.string().size());
ASSERT_EQ(kFileSize, string_file.string().size());
const MINIDUMP_DIRECTORY* directory;
const MINIDUMP_HEADER* header =
MinidumpHeaderAtStart(file_writer.string(), &directory);
MinidumpHeaderAtStart(string_file.string(), &directory);
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 3, kTimestamp));
ASSERT_TRUE(directory);
@ -184,7 +184,7 @@ TEST(MinidumpFileWriter, ThreeStreams) {
EXPECT_EQ(kStream2Offset, directory[2].Location.Rva);
const uint8_t* stream0_data = MinidumpWritableAtLocationDescriptor<uint8_t>(
file_writer.string(), directory[0].Location);
string_file.string(), directory[0].Location);
ASSERT_TRUE(stream0_data);
std::string expected_stream0(kStream0Size, kStream0Value);
@ -195,7 +195,7 @@ TEST(MinidumpFileWriter, ThreeStreams) {
EXPECT_EQ(0, memcmp(stream0_data + kStream0Size, kZeroes, kStream1Padding));
const uint8_t* stream1_data = MinidumpWritableAtLocationDescriptor<uint8_t>(
file_writer.string(), directory[1].Location);
string_file.string(), directory[1].Location);
ASSERT_TRUE(stream1_data);
std::string expected_stream1(kStream1Size, kStream1Value);
@ -205,7 +205,7 @@ TEST(MinidumpFileWriter, ThreeStreams) {
EXPECT_EQ(0, memcmp(stream1_data + kStream1Size, kZeroes, kStream2Padding));
const uint8_t* stream2_data = MinidumpWritableAtLocationDescriptor<uint8_t>(
file_writer.string(), directory[2].Location);
string_file.string(), directory[2].Location);
ASSERT_TRUE(stream2_data);
std::string expected_stream2(kStream2Size, kStream2Value);
@ -220,18 +220,18 @@ TEST(MinidumpFileWriter, ZeroLengthStream) {
auto stream = make_scoped_ptr(new TestStream(kStreamType, kStreamSize, 0));
minidump_file.AddStream(stream.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file.WriteEverything(&string_file));
const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
const size_t kStreamOffset = kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY);
const size_t kFileSize = kStreamOffset + kStreamSize;
ASSERT_EQ(kFileSize, file_writer.string().size());
ASSERT_EQ(kFileSize, string_file.string().size());
const MINIDUMP_DIRECTORY* directory;
const MINIDUMP_HEADER* header =
MinidumpHeaderAtStart(file_writer.string(), &directory);
MinidumpHeaderAtStart(string_file.string(), &directory);
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0));
ASSERT_TRUE(directory);
@ -255,34 +255,34 @@ TEST(MinidumpFileWriter, InitializeFromSnapshot_Basic) {
MinidumpFileWriter minidump_file_writer;
minidump_file_writer.InitializeFromSnapshot(&process_snapshot);
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_DIRECTORY* directory;
const MINIDUMP_HEADER* header =
MinidumpHeaderAtStart(file_writer.string(), &directory);
MinidumpHeaderAtStart(string_file.string(), &directory);
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 5, kSnapshotTime));
ASSERT_TRUE(directory);
EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>(
file_writer.string(), directory[0].Location));
string_file.string(), directory[0].Location));
EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>(
file_writer.string(), directory[1].Location));
string_file.string(), directory[1].Location));
EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>(
file_writer.string(), directory[2].Location));
string_file.string(), directory[2].Location));
EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[3].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>(
file_writer.string(), directory[3].Location));
string_file.string(), directory[3].Location));
EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[4].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
file_writer.string(), directory[4].Location));
string_file.string(), directory[4].Location));
}
TEST(MinidumpFileWriter, InitializeFromSnapshot_Exception) {
@ -318,38 +318,38 @@ TEST(MinidumpFileWriter, InitializeFromSnapshot_Exception) {
MinidumpFileWriter minidump_file_writer;
minidump_file_writer.InitializeFromSnapshot(&process_snapshot);
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_DIRECTORY* directory;
const MINIDUMP_HEADER* header =
MinidumpHeaderAtStart(file_writer.string(), &directory);
MinidumpHeaderAtStart(string_file.string(), &directory);
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 6, kSnapshotTime));
ASSERT_TRUE(directory);
EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>(
file_writer.string(), directory[0].Location));
string_file.string(), directory[0].Location));
EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>(
file_writer.string(), directory[1].Location));
string_file.string(), directory[1].Location));
EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>(
file_writer.string(), directory[2].Location));
string_file.string(), directory[2].Location));
EXPECT_EQ(kMinidumpStreamTypeException, directory[3].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_EXCEPTION_STREAM>(
file_writer.string(), directory[3].Location));
string_file.string(), directory[3].Location));
EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[4].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>(
file_writer.string(), directory[4].Location));
string_file.string(), directory[4].Location));
EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[5].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
file_writer.string(), directory[5].Location));
string_file.string(), directory[5].Location));
}
TEST(MinidumpFileWriter, InitializeFromSnapshot_CrashpadInfo) {
@ -382,42 +382,42 @@ TEST(MinidumpFileWriter, InitializeFromSnapshot_CrashpadInfo) {
MinidumpFileWriter minidump_file_writer;
minidump_file_writer.InitializeFromSnapshot(&process_snapshot);
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_DIRECTORY* directory;
const MINIDUMP_HEADER* header =
MinidumpHeaderAtStart(file_writer.string(), &directory);
MinidumpHeaderAtStart(string_file.string(), &directory);
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 7, kSnapshotTime));
ASSERT_TRUE(directory);
EXPECT_EQ(kMinidumpStreamTypeSystemInfo, directory[0].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_SYSTEM_INFO>(
file_writer.string(), directory[0].Location));
string_file.string(), directory[0].Location));
EXPECT_EQ(kMinidumpStreamTypeMiscInfo, directory[1].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MISC_INFO_4>(
file_writer.string(), directory[1].Location));
string_file.string(), directory[1].Location));
EXPECT_EQ(kMinidumpStreamTypeThreadList, directory[2].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>(
file_writer.string(), directory[2].Location));
string_file.string(), directory[2].Location));
EXPECT_EQ(kMinidumpStreamTypeException, directory[3].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_EXCEPTION_STREAM>(
file_writer.string(), directory[3].Location));
string_file.string(), directory[3].Location));
EXPECT_EQ(kMinidumpStreamTypeModuleList, directory[4].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>(
file_writer.string(), directory[4].Location));
string_file.string(), directory[4].Location));
EXPECT_EQ(kMinidumpStreamTypeCrashpadInfo, directory[5].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MinidumpCrashpadInfo>(
file_writer.string(), directory[5].Location));
string_file.string(), directory[5].Location));
EXPECT_EQ(kMinidumpStreamTypeMemoryList, directory[6].StreamType);
EXPECT_TRUE(MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
file_writer.string(), directory[6].Location));
string_file.string(), directory[6].Location));
}
TEST(MinidumpFileWriterDeathTest, SameStreamType) {

View File

@ -19,7 +19,7 @@
#include "gtest/gtest.h"
#include "minidump/test/minidump_location_descriptor_list_test_util.h"
#include "minidump/test/minidump_writable_test_util.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
@ -46,14 +46,14 @@ class TestMinidumpLocationDescriptorListWriter final
TEST(MinidumpLocationDescriptorListWriter, Empty) {
TestMinidumpLocationDescriptorListWriter list_writer;
StringFileWriter file_writer;
StringFile string_file;
ASSERT_TRUE(list_writer.WriteEverything(&file_writer));
ASSERT_TRUE(list_writer.WriteEverything(&string_file));
EXPECT_EQ(sizeof(MinidumpLocationDescriptorList),
file_writer.string().size());
string_file.string().size());
const MinidumpLocationDescriptorList* list =
MinidumpLocationDescriptorListAtStart(file_writer.string(), 0);
MinidumpLocationDescriptorListAtStart(string_file.string(), 0);
ASSERT_TRUE(list);
}
@ -63,16 +63,16 @@ TEST(MinidumpLocationDescriptorListWriter, OneChild) {
const uint32_t kValue = 0;
list_writer.AddChild(kValue);
StringFileWriter file_writer;
StringFile string_file;
ASSERT_TRUE(list_writer.WriteEverything(&file_writer));
ASSERT_TRUE(list_writer.WriteEverything(&string_file));
const MinidumpLocationDescriptorList* list =
MinidumpLocationDescriptorListAtStart(file_writer.string(), 1);
MinidumpLocationDescriptorListAtStart(string_file.string(), 1);
ASSERT_TRUE(list);
const uint32_t* child = MinidumpWritableAtLocationDescriptor<uint32_t>(
file_writer.string(), list->children[0]);
string_file.string(), list->children[0]);
ASSERT_TRUE(child);
EXPECT_EQ(kValue, *child);
}
@ -86,12 +86,12 @@ TEST(MinidumpLocationDescriptorListWriter, ThreeChildren) {
list_writer.AddChild(kValues[1]);
list_writer.AddChild(kValues[2]);
StringFileWriter file_writer;
StringFile string_file;
ASSERT_TRUE(list_writer.WriteEverything(&file_writer));
ASSERT_TRUE(list_writer.WriteEverything(&string_file));
const MinidumpLocationDescriptorList* list =
MinidumpLocationDescriptorListAtStart(file_writer.string(),
MinidumpLocationDescriptorListAtStart(string_file.string(),
arraysize(kValues));
ASSERT_TRUE(list);
@ -99,7 +99,7 @@ TEST(MinidumpLocationDescriptorListWriter, ThreeChildren) {
SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index));
const uint32_t* child = MinidumpWritableAtLocationDescriptor<uint32_t>(
file_writer.string(), list->children[index]);
string_file.string(), list->children[index]);
ASSERT_TRUE(child);
EXPECT_EQ(kValues[index], *child);
}

View File

@ -29,7 +29,7 @@
#include "minidump/test/minidump_memory_writer_test_util.h"
#include "minidump/test/minidump_writable_test_util.h"
#include "snapshot/test/test_memory_snapshot.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
#include "util/stdlib/pointer_container.h"
namespace crashpad {
@ -82,16 +82,16 @@ TEST(MinidumpMemoryWriter, EmptyMemoryList) {
minidump_file_writer.AddStream(memory_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_MEMORY_LIST),
file_writer.string().size());
string_file.string().size());
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetMemoryListStream(file_writer.string(), &memory_list, 1));
GetMemoryListStream(string_file.string(), &memory_list, 1));
EXPECT_EQ(0u, memory_list->NumberOfMemoryRanges);
}
@ -110,12 +110,12 @@ TEST(MinidumpMemoryWriter, OneMemoryRegion) {
minidump_file_writer.AddStream(memory_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetMemoryListStream(file_writer.string(), &memory_list, 1));
GetMemoryListStream(string_file.string(), &memory_list, 1));
MINIDUMP_MEMORY_DESCRIPTOR expected;
expected.StartOfMemoryRange = kBaseAddress;
@ -126,7 +126,7 @@ TEST(MinidumpMemoryWriter, OneMemoryRegion) {
memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
ExpectMinidumpMemoryDescriptorAndContents(&expected,
&memory_list->MemoryRanges[0],
file_writer.string(),
string_file.string(),
kValue,
true);
}
@ -151,12 +151,12 @@ TEST(MinidumpMemoryWriter, TwoMemoryRegions) {
minidump_file_writer.AddStream(memory_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetMemoryListStream(file_writer.string(), &memory_list, 1));
GetMemoryListStream(string_file.string(), &memory_list, 1));
EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
@ -173,7 +173,7 @@ TEST(MinidumpMemoryWriter, TwoMemoryRegions) {
memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
ExpectMinidumpMemoryDescriptorAndContents(&expected,
&memory_list->MemoryRanges[0],
file_writer.string(),
string_file.string(),
kValue0,
false);
}
@ -187,7 +187,7 @@ TEST(MinidumpMemoryWriter, TwoMemoryRegions) {
memory_list->MemoryRanges[0].Memory.DataSize;
ExpectMinidumpMemoryDescriptorAndContents(&expected,
&memory_list->MemoryRanges[1],
file_writer.string(),
string_file.string(),
kValue1,
true);
}
@ -260,12 +260,12 @@ TEST(MinidumpMemoryWriter, ExtraMemory) {
minidump_file_writer.AddStream(memory_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetMemoryListStream(file_writer.string(), &memory_list, 2));
GetMemoryListStream(string_file.string(), &memory_list, 2));
EXPECT_EQ(2u, memory_list->NumberOfMemoryRanges);
@ -282,7 +282,7 @@ TEST(MinidumpMemoryWriter, ExtraMemory) {
memory_list->NumberOfMemoryRanges * sizeof(MINIDUMP_MEMORY_DESCRIPTOR);
ExpectMinidumpMemoryDescriptorAndContents(&expected,
&memory_list->MemoryRanges[0],
file_writer.string(),
string_file.string(),
kValue0,
false);
}
@ -296,7 +296,7 @@ TEST(MinidumpMemoryWriter, ExtraMemory) {
memory_list->MemoryRanges[0].Memory.DataSize;
ExpectMinidumpMemoryDescriptorAndContents(&expected,
&memory_list->MemoryRanges[1],
file_writer.string(),
string_file.string(),
kValue1,
true);
}
@ -338,12 +338,12 @@ TEST(MinidumpMemoryWriter, AddFromSnapshot) {
MinidumpFileWriter minidump_file_writer;
minidump_file_writer.AddStream(memory_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetMemoryListStream(file_writer.string(), &memory_list, 1));
GetMemoryListStream(string_file.string(), &memory_list, 1));
ASSERT_EQ(3u, memory_list->NumberOfMemoryRanges);
@ -352,7 +352,7 @@ TEST(MinidumpMemoryWriter, AddFromSnapshot) {
ExpectMinidumpMemoryDescriptorAndContents(
&expect_memory_descriptors[index],
&memory_list->MemoryRanges[index],
file_writer.string(),
string_file.string(),
values[index],
index == memory_list->NumberOfMemoryRanges - 1);
}

View File

@ -31,7 +31,7 @@
#include "minidump/test/minidump_writable_test_util.h"
#include "snapshot/test/test_process_snapshot.h"
#include "snapshot/test/test_system_snapshot.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
#include "util/stdlib/strlcpy.h"
namespace crashpad {
@ -170,11 +170,11 @@ TEST(MinidumpMiscInfoWriter, Empty) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO expected = {};
@ -191,11 +191,11 @@ TEST(MinidumpMiscInfoWriter, ProcessId) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO expected = {};
expected.Flags1 = MINIDUMP_MISC1_PROCESS_ID;
@ -217,11 +217,11 @@ TEST(MinidumpMiscInfoWriter, ProcessTimes) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO expected = {};
expected.Flags1 = MINIDUMP_MISC1_PROCESS_TIMES;
@ -250,11 +250,11 @@ TEST(MinidumpMiscInfoWriter, ProcessorPowerInfo) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO_2* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO_2 expected = {};
expected.Flags1 = MINIDUMP_MISC1_PROCESSOR_POWER_INFO;
@ -277,11 +277,11 @@ TEST(MinidumpMiscInfoWriter, ProcessIntegrityLevel) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO_3* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO_3 expected = {};
expected.Flags1 = MINIDUMP_MISC3_PROCESS_INTEGRITY;
@ -300,11 +300,11 @@ TEST(MinidumpMiscInfoWriter, ProcessExecuteFlags) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO_3* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO_3 expected = {};
expected.Flags1 = MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS;
@ -323,11 +323,11 @@ TEST(MinidumpMiscInfoWriter, ProtectedProcess) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO_3* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO_3 expected = {};
expected.Flags1 = MINIDUMP_MISC3_PROTECTED_PROCESS;
@ -360,11 +360,11 @@ TEST(MinidumpMiscInfoWriter, TimeZone) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO_3* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO_3 expected = {};
expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
@ -421,11 +421,11 @@ TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO_3* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO_3 expected = {};
expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
@ -462,11 +462,11 @@ TEST(MinidumpMiscInfoWriter, BuildStrings) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO_4* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
@ -499,11 +499,11 @@ TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO_4* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
@ -569,11 +569,11 @@ TEST(MinidumpMiscInfoWriter, Everything) {
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO_4* observed = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &observed));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
MINIDUMP_MISC_INFO_4 expected = {};
expected.Flags1 =
@ -709,11 +709,11 @@ TEST(MinidumpMiscInfoWriter, InitializeFromSnapshot) {
MinidumpFileWriter minidump_file_writer;
minidump_file_writer.AddStream(misc_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MISC_INFO_4* misc_info = nullptr;
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(file_writer.string(), &misc_info));
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &misc_info));
ExpectMiscInfoEqual(&expect_misc_info, misc_info);
}

View File

@ -25,29 +25,29 @@
#include "minidump/test/minidump_string_writer_test_util.h"
#include "minidump/test/minidump_writable_test_util.h"
#include "snapshot/test/test_module_snapshot.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
namespace {
TEST(MinidumpModuleCrashpadInfoWriter, EmptyList) {
StringFileWriter file_writer;
StringFile string_file;
MinidumpModuleCrashpadInfoListWriter module_list_writer;
EXPECT_FALSE(module_list_writer.IsUseful());
EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer));
EXPECT_TRUE(module_list_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList),
file_writer.string().size());
string_file.string().size());
const MinidumpModuleCrashpadInfoList* module_list =
MinidumpLocationDescriptorListAtStart(file_writer.string(), 0);
MinidumpLocationDescriptorListAtStart(string_file.string(), 0);
ASSERT_TRUE(module_list);
}
TEST(MinidumpModuleCrashpadInfoWriter, EmptyModule) {
StringFileWriter file_writer;
StringFile string_file;
MinidumpModuleCrashpadInfoListWriter module_list_writer;
auto module_writer =
@ -57,19 +57,19 @@ TEST(MinidumpModuleCrashpadInfoWriter, EmptyModule) {
EXPECT_TRUE(module_list_writer.IsUseful());
EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer));
EXPECT_TRUE(module_list_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList) +
sizeof(MINIDUMP_LOCATION_DESCRIPTOR) +
sizeof(MinidumpModuleCrashpadInfo),
file_writer.string().size());
string_file.string().size());
const MinidumpModuleCrashpadInfoList* module_list =
MinidumpLocationDescriptorListAtStart(file_writer.string(), 1);
MinidumpLocationDescriptorListAtStart(string_file.string(), 1);
ASSERT_TRUE(module_list);
const MinidumpModuleCrashpadInfo* module =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
file_writer.string(), module_list->children[0]);
string_file.string(), module_list->children[0]);
ASSERT_TRUE(module);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module->version);
@ -87,7 +87,7 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
const char kEntry[] = "entry";
std::vector<std::string> vector(1, std::string(kEntry));
StringFileWriter file_writer;
StringFile string_file;
MinidumpModuleCrashpadInfoListWriter module_list_writer;
@ -110,7 +110,7 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
EXPECT_TRUE(module_list_writer.IsUseful());
EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer));
EXPECT_TRUE(module_list_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpModuleCrashpadInfoList) +
sizeof(MINIDUMP_LOCATION_DESCRIPTOR) +
sizeof(MinidumpModuleCrashpadInfo) +
@ -121,15 +121,15 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
sizeof(MinidumpUTF8String) + arraysize(kEntry) + 2 + // padding
sizeof(MinidumpUTF8String) + arraysize(kKey) +
sizeof(MinidumpUTF8String) + arraysize(kValue),
file_writer.string().size());
string_file.string().size());
const MinidumpModuleCrashpadInfoList* module_list =
MinidumpLocationDescriptorListAtStart(file_writer.string(), 1);
MinidumpLocationDescriptorListAtStart(string_file.string(), 1);
ASSERT_TRUE(module_list);
const MinidumpModuleCrashpadInfo* module =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
file_writer.string(), module_list->children[0]);
string_file.string(), module_list->children[0]);
ASSERT_TRUE(module);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module->version);
@ -141,25 +141,25 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
const MinidumpRVAList* list_annotations =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
file_writer.string(), module->list_annotations);
string_file.string(), module->list_annotations);
ASSERT_TRUE(list_annotations);
ASSERT_EQ(1u, list_annotations->count);
EXPECT_EQ(kEntry, MinidumpUTF8StringAtRVAAsString(
file_writer.string(), list_annotations->children[0]));
string_file.string(), list_annotations->children[0]));
const MinidumpSimpleStringDictionary* simple_annotations =
MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
file_writer.string(), module->simple_annotations);
string_file.string(), module->simple_annotations);
ASSERT_TRUE(simple_annotations);
ASSERT_EQ(1u, simple_annotations->count);
EXPECT_EQ(kKey,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations->entries[0].key));
string_file.string(), simple_annotations->entries[0].key));
EXPECT_EQ(kValue,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations->entries[0].value));
string_file.string(), simple_annotations->entries[0].value));
}
TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
@ -173,7 +173,7 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
const char kKey2B[] = "river";
const char kValue2B[] = "hudson";
StringFileWriter file_writer;
StringFile string_file;
MinidumpModuleCrashpadInfoListWriter module_list_writer;
@ -220,15 +220,15 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
EXPECT_TRUE(module_list_writer.IsUseful());
EXPECT_TRUE(module_list_writer.WriteEverything(&file_writer));
EXPECT_TRUE(module_list_writer.WriteEverything(&string_file));
const MinidumpModuleCrashpadInfoList* module_list =
MinidumpLocationDescriptorListAtStart(file_writer.string(), 3);
MinidumpLocationDescriptorListAtStart(string_file.string(), 3);
ASSERT_TRUE(module_list);
const MinidumpModuleCrashpadInfo* module_0 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
file_writer.string(), module_list->children[0]);
string_file.string(), module_list->children[0]);
ASSERT_TRUE(module_0);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_0->version);
@ -236,25 +236,25 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
const MinidumpRVAList* list_annotations_0 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
file_writer.string(), module_0->list_annotations);
string_file.string(), module_0->list_annotations);
EXPECT_FALSE(list_annotations_0);
const MinidumpSimpleStringDictionary* simple_annotations_0 =
MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
file_writer.string(), module_0->simple_annotations);
string_file.string(), module_0->simple_annotations);
ASSERT_TRUE(simple_annotations_0);
ASSERT_EQ(1u, simple_annotations_0->count);
EXPECT_EQ(kKey0,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_0->entries[0].key));
string_file.string(), simple_annotations_0->entries[0].key));
EXPECT_EQ(kValue0,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_0->entries[0].value));
string_file.string(), simple_annotations_0->entries[0].value));
const MinidumpModuleCrashpadInfo* module_1 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
file_writer.string(), module_list->children[1]);
string_file.string(), module_list->children[1]);
ASSERT_TRUE(module_1);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_1->version);
@ -262,17 +262,17 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
const MinidumpRVAList* list_annotations_1 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
file_writer.string(), module_1->list_annotations);
string_file.string(), module_1->list_annotations);
EXPECT_FALSE(list_annotations_1);
const MinidumpSimpleStringDictionary* simple_annotations_1 =
MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
file_writer.string(), module_1->simple_annotations);
string_file.string(), module_1->simple_annotations);
EXPECT_FALSE(simple_annotations_1);
const MinidumpModuleCrashpadInfo* module_2 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
file_writer.string(), module_list->children[2]);
string_file.string(), module_list->children[2]);
ASSERT_TRUE(module_2);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_2->version);
@ -280,27 +280,27 @@ TEST(MinidumpModuleCrashpadInfoWriter, ThreeModules) {
const MinidumpRVAList* list_annotations_2 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
file_writer.string(), module_2->list_annotations);
string_file.string(), module_2->list_annotations);
EXPECT_FALSE(list_annotations_2);
const MinidumpSimpleStringDictionary* simple_annotations_2 =
MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
file_writer.string(), module_2->simple_annotations);
string_file.string(), module_2->simple_annotations);
ASSERT_TRUE(simple_annotations_2);
ASSERT_EQ(2u, simple_annotations_2->count);
EXPECT_EQ(kKey2A,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_2->entries[0].key));
string_file.string(), simple_annotations_2->entries[0].key));
EXPECT_EQ(kValue2A,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_2->entries[0].value));
string_file.string(), simple_annotations_2->entries[0].value));
EXPECT_EQ(kKey2B,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_2->entries[1].key));
string_file.string(), simple_annotations_2->entries[1].key));
EXPECT_EQ(kValue2B,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_2->entries[1].value));
string_file.string(), simple_annotations_2->entries[1].value));
}
TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) {
@ -344,16 +344,16 @@ TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) {
module_list_writer.InitializeFromSnapshot(module_snapshots);
EXPECT_TRUE(module_list_writer.IsUseful());
StringFileWriter file_writer;
ASSERT_TRUE(module_list_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(module_list_writer.WriteEverything(&string_file));
const MinidumpModuleCrashpadInfoList* module_list =
MinidumpLocationDescriptorListAtStart(file_writer.string(), 3);
MinidumpLocationDescriptorListAtStart(string_file.string(), 3);
ASSERT_TRUE(module_list);
const MinidumpModuleCrashpadInfo* module_0 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
file_writer.string(), module_list->children[0]);
string_file.string(), module_list->children[0]);
ASSERT_TRUE(module_0);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_0->version);
@ -361,31 +361,31 @@ TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) {
const MinidumpRVAList* list_annotations_0 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
file_writer.string(), module_0->list_annotations);
string_file.string(), module_0->list_annotations);
EXPECT_FALSE(list_annotations_0);
const MinidumpSimpleStringDictionary* simple_annotations_0 =
MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
file_writer.string(), module_0->simple_annotations);
string_file.string(), module_0->simple_annotations);
ASSERT_TRUE(simple_annotations_0);
ASSERT_EQ(annotations_simple_map_0.size(), simple_annotations_0->count);
EXPECT_EQ(kKey0B,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_0->entries[0].key));
string_file.string(), simple_annotations_0->entries[0].key));
EXPECT_EQ(kValue0B,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_0->entries[0].value));
string_file.string(), simple_annotations_0->entries[0].value));
EXPECT_EQ(kKey0A,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_0->entries[1].key));
string_file.string(), simple_annotations_0->entries[1].key));
EXPECT_EQ(kValue0A,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_0->entries[1].value));
string_file.string(), simple_annotations_0->entries[1].value));
const MinidumpModuleCrashpadInfo* module_2 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
file_writer.string(), module_list->children[1]);
string_file.string(), module_list->children[1]);
ASSERT_TRUE(module_2);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_2->version);
@ -393,25 +393,25 @@ TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) {
const MinidumpRVAList* list_annotations_2 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
file_writer.string(), module_2->list_annotations);
string_file.string(), module_2->list_annotations);
EXPECT_FALSE(list_annotations_2);
const MinidumpSimpleStringDictionary* simple_annotations_2 =
MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
file_writer.string(), module_2->simple_annotations);
string_file.string(), module_2->simple_annotations);
ASSERT_TRUE(simple_annotations_2);
ASSERT_EQ(annotations_simple_map_2.size(), simple_annotations_2->count);
EXPECT_EQ(kKey2,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_2->entries[0].key));
string_file.string(), simple_annotations_2->entries[0].key));
EXPECT_EQ(kValue2,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), simple_annotations_2->entries[0].value));
string_file.string(), simple_annotations_2->entries[0].value));
const MinidumpModuleCrashpadInfo* module_3 =
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfo>(
file_writer.string(), module_list->children[2]);
string_file.string(), module_list->children[2]);
ASSERT_TRUE(module_3);
EXPECT_EQ(MinidumpModuleCrashpadInfo::kVersion, module_3->version);
@ -419,20 +419,20 @@ TEST(MinidumpModuleCrashpadInfoWriter, InitializeFromSnapshot) {
const MinidumpRVAList* list_annotations_3 =
MinidumpWritableAtLocationDescriptor<MinidumpRVAList>(
file_writer.string(), module_3->list_annotations);
string_file.string(), module_3->list_annotations);
ASSERT_TRUE(list_annotations_3);
ASSERT_EQ(annotations_vector_3.size(), list_annotations_3->count);
EXPECT_EQ(kEntry3A,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), list_annotations_3->children[0]));
string_file.string(), list_annotations_3->children[0]));
EXPECT_EQ(kEntry3B,
MinidumpUTF8StringAtRVAAsString(
file_writer.string(), list_annotations_3->children[1]));
string_file.string(), list_annotations_3->children[1]));
const MinidumpSimpleStringDictionary* simple_annotations_3 =
MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
file_writer.string(), module_3->simple_annotations);
string_file.string(), module_3->simple_annotations);
EXPECT_FALSE(simple_annotations_3);
}

View File

@ -30,7 +30,7 @@
#include "minidump/test/minidump_string_writer_test_util.h"
#include "minidump/test/minidump_writable_test_util.h"
#include "snapshot/test/test_module_snapshot.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
#include "util/misc/uuid.h"
#include "util/stdlib/pointer_container.h"
@ -68,16 +68,16 @@ TEST(MinidumpModuleWriter, EmptyModuleList) {
minidump_file_writer.AddStream(module_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_MODULE_LIST),
file_writer.string().size());
string_file.string().size());
const MINIDUMP_MODULE_LIST* module_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetModuleListStream(file_writer.string(), &module_list));
GetModuleListStream(string_file.string(), &module_list));
EXPECT_EQ(0u, module_list->NumberOfModules);
}
@ -282,23 +282,23 @@ TEST(MinidumpModuleWriter, EmptyModule) {
module_list_writer->AddModule(module_writer.Pass());
minidump_file_writer.AddStream(module_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
ASSERT_GT(file_writer.string().size(),
ASSERT_GT(string_file.string().size(),
sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
const MINIDUMP_MODULE_LIST* module_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetModuleListStream(file_writer.string(), &module_list));
GetModuleListStream(string_file.string(), &module_list));
EXPECT_EQ(1u, module_list->NumberOfModules);
MINIDUMP_MODULE expected = {};
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
string_file.string(),
kModuleName,
nullptr,
nullptr,
@ -373,16 +373,16 @@ TEST(MinidumpModuleWriter, OneModule) {
module_list_writer->AddModule(module_writer.Pass());
minidump_file_writer.AddStream(module_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
ASSERT_GT(file_writer.string().size(),
ASSERT_GT(string_file.string().size(),
sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
const MINIDUMP_MODULE_LIST* module_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetModuleListStream(file_writer.string(), &module_list));
GetModuleListStream(string_file.string(), &module_list));
EXPECT_EQ(1u, module_list->NumberOfModules);
@ -403,7 +403,7 @@ TEST(MinidumpModuleWriter, OneModule) {
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
string_file.string(),
kModuleName,
kPDBName,
&pdb_uuid,
@ -448,16 +448,16 @@ TEST(MinidumpModuleWriter, OneModule_CodeViewUsesPDB20_MiscUsesUTF16) {
module_list_writer->AddModule(module_writer.Pass());
minidump_file_writer.AddStream(module_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
ASSERT_GT(file_writer.string().size(),
ASSERT_GT(string_file.string().size(),
sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
const MINIDUMP_MODULE_LIST* module_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetModuleListStream(file_writer.string(), &module_list));
GetModuleListStream(string_file.string(), &module_list));
EXPECT_EQ(1u, module_list->NumberOfModules);
@ -465,7 +465,7 @@ TEST(MinidumpModuleWriter, OneModule_CodeViewUsesPDB20_MiscUsesUTF16) {
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
string_file.string(),
kModuleName,
kPDBName,
nullptr,
@ -540,16 +540,16 @@ TEST(MinidumpModuleWriter, ThreeModules) {
minidump_file_writer.AddStream(module_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
ASSERT_GT(file_writer.string().size(),
ASSERT_GT(string_file.string().size(),
sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_MODULE_LIST) + 1 * sizeof(MINIDUMP_MODULE));
const MINIDUMP_MODULE_LIST* module_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetModuleListStream(file_writer.string(), &module_list));
GetModuleListStream(string_file.string(), &module_list));
EXPECT_EQ(3u, module_list->NumberOfModules);
@ -563,7 +563,7 @@ TEST(MinidumpModuleWriter, ThreeModules) {
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[0],
file_writer.string(),
string_file.string(),
kModuleName0,
kPDBName0,
&pdb_uuid_0,
@ -582,7 +582,7 @@ TEST(MinidumpModuleWriter, ThreeModules) {
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[1],
file_writer.string(),
string_file.string(),
kModuleName1,
nullptr,
nullptr,
@ -601,7 +601,7 @@ TEST(MinidumpModuleWriter, ThreeModules) {
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expected,
&module_list->Modules[2],
file_writer.string(),
string_file.string(),
kModuleName2,
kPDBName2,
nullptr,
@ -720,12 +720,12 @@ TEST(MinidumpModuleWriter, InitializeFromSnapshot) {
MinidumpFileWriter minidump_file_writer;
minidump_file_writer.AddStream(module_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_MODULE_LIST* module_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetModuleListStream(file_writer.string(), &module_list));
GetModuleListStream(string_file.string(), &module_list));
ASSERT_EQ(3u, module_list->NumberOfModules);
@ -733,7 +733,7 @@ TEST(MinidumpModuleWriter, InitializeFromSnapshot) {
SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index));
ASSERT_NO_FATAL_FAILURE(ExpectModule(&expect_modules[index],
&module_list->Modules[index],
file_writer.string(),
string_file.string(),
module_paths[index],
module_names[index],
&uuids[index],
@ -752,8 +752,8 @@ TEST(MinidumpModuleWriterDeathTest, NoModuleName) {
module_list_writer->AddModule(module_writer.Pass());
minidump_file_writer.AddStream(module_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "name_");
StringFile string_file;
ASSERT_DEATH(minidump_file_writer.WriteEverything(&string_file), "name_");
}
} // namespace

View File

@ -19,7 +19,7 @@
#include "gtest/gtest.h"
#include "minidump/test/minidump_rva_list_test_util.h"
#include "minidump/test/minidump_writable_test_util.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
@ -42,12 +42,12 @@ class TestMinidumpRVAListWriter final : public internal::MinidumpRVAListWriter {
TEST(MinidumpRVAListWriter, Empty) {
TestMinidumpRVAListWriter list_writer;
StringFileWriter file_writer;
StringFile string_file;
ASSERT_TRUE(list_writer.WriteEverything(&file_writer));
EXPECT_EQ(sizeof(MinidumpRVAList), file_writer.string().size());
ASSERT_TRUE(list_writer.WriteEverything(&string_file));
EXPECT_EQ(sizeof(MinidumpRVAList), string_file.string().size());
const MinidumpRVAList* list = MinidumpRVAListAtStart(file_writer.string(), 0);
const MinidumpRVAList* list = MinidumpRVAListAtStart(string_file.string(), 0);
ASSERT_TRUE(list);
}
@ -57,15 +57,15 @@ TEST(MinidumpRVAListWriter, OneChild) {
const uint32_t kValue = 0;
list_writer.AddChild(kValue);
StringFileWriter file_writer;
StringFile string_file;
ASSERT_TRUE(list_writer.WriteEverything(&file_writer));
ASSERT_TRUE(list_writer.WriteEverything(&string_file));
const MinidumpRVAList* list = MinidumpRVAListAtStart(file_writer.string(), 1);
const MinidumpRVAList* list = MinidumpRVAListAtStart(string_file.string(), 1);
ASSERT_TRUE(list);
const uint32_t* child = MinidumpWritableAtRVA<uint32_t>(
file_writer.string(), list->children[0]);
string_file.string(), list->children[0]);
ASSERT_TRUE(child);
EXPECT_EQ(kValue, *child);
}
@ -79,19 +79,19 @@ TEST(MinidumpRVAListWriter, ThreeChildren) {
list_writer.AddChild(kValues[1]);
list_writer.AddChild(kValues[2]);
StringFileWriter file_writer;
StringFile string_file;
ASSERT_TRUE(list_writer.WriteEverything(&file_writer));
ASSERT_TRUE(list_writer.WriteEverything(&string_file));
const MinidumpRVAList* list =
MinidumpRVAListAtStart(file_writer.string(), arraysize(kValues));
MinidumpRVAListAtStart(string_file.string(), arraysize(kValues));
ASSERT_TRUE(list);
for (size_t index = 0; index < arraysize(kValues); ++index) {
SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index));
const uint32_t* child = MinidumpWritableAtRVA<uint32_t>(
file_writer.string(), list->children[index]);
string_file.string(), list->children[index]);
ASSERT_TRUE(child);
EXPECT_EQ(kValues[index], *child);
}

View File

@ -21,7 +21,7 @@
#include "minidump/minidump_extensions.h"
#include "minidump/test/minidump_string_writer_test_util.h"
#include "minidump/test/minidump_writable_test_util.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
@ -40,24 +40,24 @@ const MinidumpSimpleStringDictionary* MinidumpSimpleStringDictionaryAtStart(
}
TEST(MinidumpSimpleStringDictionaryWriter, EmptySimpleStringDictionary) {
StringFileWriter file_writer;
StringFile string_file;
MinidumpSimpleStringDictionaryWriter dictionary_writer;
EXPECT_FALSE(dictionary_writer.IsUseful());
EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
EXPECT_TRUE(dictionary_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary),
file_writer.string().size());
string_file.string().size());
const MinidumpSimpleStringDictionary* dictionary =
MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 0);
MinidumpSimpleStringDictionaryAtStart(string_file.string(), 0);
ASSERT_TRUE(dictionary);
EXPECT_EQ(0u, dictionary->count);
}
TEST(MinidumpSimpleStringDictionaryWriter, EmptyKeyValue) {
StringFileWriter file_writer;
StringFile string_file;
MinidumpSimpleStringDictionaryWriter dictionary_writer;
auto entry_writer =
@ -66,28 +66,28 @@ TEST(MinidumpSimpleStringDictionaryWriter, EmptyKeyValue) {
EXPECT_TRUE(dictionary_writer.IsUseful());
EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
EXPECT_TRUE(dictionary_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
sizeof(MinidumpSimpleStringDictionaryEntry) +
2 * sizeof(MinidumpUTF8String) + 1 + 3 + 1, // 3 for padding
file_writer.string().size());
string_file.string().size());
const MinidumpSimpleStringDictionary* dictionary =
MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1);
MinidumpSimpleStringDictionaryAtStart(string_file.string(), 1);
ASSERT_TRUE(dictionary);
EXPECT_EQ(1u, dictionary->count);
EXPECT_EQ(12u, dictionary->entries[0].key);
EXPECT_EQ(20u, dictionary->entries[0].value);
EXPECT_EQ("",
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[0].key));
EXPECT_EQ("",
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[0].value));
}
TEST(MinidumpSimpleStringDictionaryWriter, OneKeyValue) {
StringFileWriter file_writer;
StringFile string_file;
char kKey[] = "key";
char kValue[] = "value";
@ -100,28 +100,28 @@ TEST(MinidumpSimpleStringDictionaryWriter, OneKeyValue) {
EXPECT_TRUE(dictionary_writer.IsUseful());
EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
EXPECT_TRUE(dictionary_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
sizeof(MinidumpSimpleStringDictionaryEntry) +
2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue),
file_writer.string().size());
string_file.string().size());
const MinidumpSimpleStringDictionary* dictionary =
MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1);
MinidumpSimpleStringDictionaryAtStart(string_file.string(), 1);
ASSERT_TRUE(dictionary);
EXPECT_EQ(1u, dictionary->count);
EXPECT_EQ(12u, dictionary->entries[0].key);
EXPECT_EQ(20u, dictionary->entries[0].value);
EXPECT_EQ(kKey,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[0].key));
EXPECT_EQ(kValue,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[0].value));
}
TEST(MinidumpSimpleStringDictionaryWriter, ThreeKeysValues) {
StringFileWriter file_writer;
StringFile string_file;
char kKey0[] = "m0";
char kValue0[] = "value0";
@ -146,16 +146,16 @@ TEST(MinidumpSimpleStringDictionaryWriter, ThreeKeysValues) {
EXPECT_TRUE(dictionary_writer.IsUseful());
EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
EXPECT_TRUE(dictionary_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
3 * sizeof(MinidumpSimpleStringDictionaryEntry) +
6 * sizeof(MinidumpUTF8String) + sizeof(kKey2) +
sizeof(kValue2) + 3 + sizeof(kKey0) + 1 + sizeof(kValue0) + 1 +
sizeof(kKey1) + 3 + sizeof(kValue1),
file_writer.string().size());
string_file.string().size());
const MinidumpSimpleStringDictionary* dictionary =
MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 3);
MinidumpSimpleStringDictionaryAtStart(string_file.string(), 3);
ASSERT_TRUE(dictionary);
EXPECT_EQ(3u, dictionary->count);
EXPECT_EQ(28u, dictionary->entries[0].key);
@ -172,27 +172,27 @@ TEST(MinidumpSimpleStringDictionaryWriter, ThreeKeysValues) {
// just the easiest way to write this test while the writer will output things
// in a known order.
EXPECT_EQ(kKey2,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[0].key));
EXPECT_EQ(kValue2,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[0].value));
EXPECT_EQ(kKey0,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[1].key));
EXPECT_EQ(kValue0,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[1].value));
EXPECT_EQ(kKey1,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[2].key));
EXPECT_EQ(kValue1,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[2].value));
}
TEST(MinidumpSimpleStringDictionaryWriter, DuplicateKeyValue) {
StringFileWriter file_writer;
StringFile string_file;
char kKey[] = "key";
char kValue0[] = "fake_value";
@ -210,23 +210,23 @@ TEST(MinidumpSimpleStringDictionaryWriter, DuplicateKeyValue) {
EXPECT_TRUE(dictionary_writer.IsUseful());
EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
EXPECT_TRUE(dictionary_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
sizeof(MinidumpSimpleStringDictionaryEntry) +
2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue1),
file_writer.string().size());
string_file.string().size());
const MinidumpSimpleStringDictionary* dictionary =
MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1);
MinidumpSimpleStringDictionaryAtStart(string_file.string(), 1);
ASSERT_TRUE(dictionary);
EXPECT_EQ(1u, dictionary->count);
EXPECT_EQ(12u, dictionary->entries[0].key);
EXPECT_EQ(20u, dictionary->entries[0].value);
EXPECT_EQ(kKey,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[0].key));
EXPECT_EQ(kValue1,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[0].value));
}
@ -248,11 +248,11 @@ TEST(MinidumpSimpleStringDictionaryWriter, InitializeFromMap) {
EXPECT_TRUE(dictionary_writer.IsUseful());
StringFileWriter file_writer;
ASSERT_TRUE(dictionary_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(dictionary_writer.WriteEverything(&string_file));
const MinidumpSimpleStringDictionary* dictionary =
MinidumpSimpleStringDictionaryAtStart(file_writer.string(), map.size());
MinidumpSimpleStringDictionaryAtStart(string_file.string(), map.size());
ASSERT_TRUE(dictionary);
ASSERT_EQ(3u, dictionary->count);
@ -263,22 +263,22 @@ TEST(MinidumpSimpleStringDictionaryWriter, InitializeFromMap) {
// just the easiest way to write this test while the writer will output things
// in a known order.
EXPECT_EQ(kKey1,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[0].key));
EXPECT_EQ(kValue1,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[0].value));
EXPECT_EQ(kKey0,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[1].key));
EXPECT_EQ(kValue0,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[1].value));
EXPECT_EQ(kKey2,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[2].key));
EXPECT_EQ(kValue2,
MinidumpUTF8StringAtRVAAsString(file_writer.string(),
MinidumpUTF8StringAtRVAAsString(string_file.string(),
dictionary->entries[2].value));
}

View File

@ -30,27 +30,27 @@
#include "minidump/test/minidump_rva_list_test_util.h"
#include "minidump/test/minidump_string_writer_test_util.h"
#include "minidump/test/minidump_writable_test_util.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
namespace {
TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) {
StringFileWriter file_writer;
StringFile string_file;
{
SCOPED_TRACE("unset");
file_writer.Reset();
string_file.Reset();
crashpad::internal::MinidumpUTF16StringWriter string_writer;
EXPECT_TRUE(string_writer.WriteEverything(&file_writer));
ASSERT_EQ(6u, file_writer.string().size());
EXPECT_TRUE(string_writer.WriteEverything(&string_file));
ASSERT_EQ(6u, string_file.string().size());
const MINIDUMP_STRING* minidump_string =
MinidumpStringAtRVA(file_writer.string(), 0);
MinidumpStringAtRVA(string_file.string(), 0);
EXPECT_TRUE(minidump_string);
EXPECT_EQ(base::string16(),
MinidumpStringAtRVAAsString(file_writer.string(), 0));
MinidumpStringAtRVAAsString(string_file.string(), 0));
}
const struct {
@ -83,11 +83,11 @@ TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) {
kTestData[index]
.output_string[arraysize(kTestData[index].output_string) - 1]);
file_writer.Reset();
string_file.Reset();
crashpad::internal::MinidumpUTF16StringWriter string_writer;
string_writer.SetUTF8(std::string(kTestData[index].input_string,
kTestData[index].input_length));
EXPECT_TRUE(string_writer.WriteEverything(&file_writer));
EXPECT_TRUE(string_writer.WriteEverything(&string_file));
const size_t expected_utf16_units_with_nul =
kTestData[index].output_length + 1;
@ -96,20 +96,20 @@ TEST(MinidumpStringWriter, MinidumpUTF16StringWriter) {
const size_t expected_utf16_bytes =
expected_utf16_units_with_nul * sizeof(tmp.Buffer[0]);
ASSERT_EQ(sizeof(MINIDUMP_STRING) + expected_utf16_bytes,
file_writer.string().size());
string_file.string().size());
const MINIDUMP_STRING* minidump_string =
MinidumpStringAtRVA(file_writer.string(), 0);
MinidumpStringAtRVA(string_file.string(), 0);
EXPECT_TRUE(minidump_string);
base::string16 expect_string = base::string16(
kTestData[index].output_string, kTestData[index].output_length);
EXPECT_EQ(expect_string,
MinidumpStringAtRVAAsString(file_writer.string(), 0));
MinidumpStringAtRVAAsString(string_file.string(), 0));
}
}
TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) {
StringFileWriter file_writer;
StringFile string_file;
const char* kTestData[] = {
"\200", // continuation byte
@ -123,10 +123,10 @@ TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) {
for (size_t index = 0; index < arraysize(kTestData); ++index) {
SCOPED_TRACE(base::StringPrintf(
"index %" PRIuS ", input %s", index, kTestData[index]));
file_writer.Reset();
string_file.Reset();
crashpad::internal::MinidumpUTF16StringWriter string_writer;
string_writer.SetUTF8(kTestData[index]);
EXPECT_TRUE(string_writer.WriteEverything(&file_writer));
EXPECT_TRUE(string_writer.WriteEverything(&string_file));
// The requirements for conversion of invalid UTF-8 input are lax. Make sure
// that at least enough data was written for a string that has one unit and
@ -134,35 +134,35 @@ TEST(MinidumpStringWriter, ConvertInvalidUTF8ToUTF16) {
// data written, and make sure that at least one U+FFFD replacement
// character was written.
const MINIDUMP_STRING* minidump_string =
MinidumpStringAtRVA(file_writer.string(), 0);
MinidumpStringAtRVA(string_file.string(), 0);
EXPECT_TRUE(minidump_string);
MINIDUMP_STRING tmp = {0};
ALLOW_UNUSED_LOCAL(tmp);
EXPECT_EQ(file_writer.string().size() - sizeof(MINIDUMP_STRING) -
EXPECT_EQ(string_file.string().size() - sizeof(MINIDUMP_STRING) -
sizeof(tmp.Buffer[0]),
minidump_string->Length);
base::string16 output_string =
MinidumpStringAtRVAAsString(file_writer.string(), 0);
MinidumpStringAtRVAAsString(string_file.string(), 0);
EXPECT_FALSE(output_string.empty());
EXPECT_NE(base::string16::npos, output_string.find(0xfffd));
}
}
TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) {
StringFileWriter file_writer;
StringFile string_file;
{
SCOPED_TRACE("unset");
file_writer.Reset();
string_file.Reset();
crashpad::internal::MinidumpUTF8StringWriter string_writer;
EXPECT_TRUE(string_writer.WriteEverything(&file_writer));
ASSERT_EQ(5u, file_writer.string().size());
EXPECT_TRUE(string_writer.WriteEverything(&string_file));
ASSERT_EQ(5u, string_file.string().size());
const MinidumpUTF8String* minidump_string =
MinidumpUTF8StringAtRVA(file_writer.string(), 0);
MinidumpUTF8StringAtRVA(string_file.string(), 0);
EXPECT_TRUE(minidump_string);
EXPECT_EQ(std::string(),
MinidumpUTF8StringAtRVAAsString(file_writer.string(), 0));
MinidumpUTF8StringAtRVAAsString(string_file.string(), 0));
}
const struct {
@ -186,22 +186,22 @@ TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) {
SCOPED_TRACE(base::StringPrintf(
"index %" PRIuS ", input %s", index, kTestData[index].string));
file_writer.Reset();
string_file.Reset();
crashpad::internal::MinidumpUTF8StringWriter string_writer;
std::string test_string(kTestData[index].string, kTestData[index].length);
string_writer.SetUTF8(test_string);
EXPECT_EQ(test_string, string_writer.UTF8());
EXPECT_TRUE(string_writer.WriteEverything(&file_writer));
EXPECT_TRUE(string_writer.WriteEverything(&string_file));
const size_t expected_utf8_bytes_with_nul = kTestData[index].length + 1;
ASSERT_EQ(sizeof(MinidumpUTF8String) + expected_utf8_bytes_with_nul,
file_writer.string().size());
string_file.string().size());
const MinidumpUTF8String* minidump_string =
MinidumpUTF8StringAtRVA(file_writer.string(), 0);
MinidumpUTF8StringAtRVA(string_file.string(), 0);
EXPECT_TRUE(minidump_string);
EXPECT_EQ(test_string,
MinidumpUTF8StringAtRVAAsString(file_writer.string(), 0));
MinidumpUTF8StringAtRVAAsString(string_file.string(), 0));
}
}
@ -240,17 +240,17 @@ void MinidumpStringListTest() {
string_list_writer.InitializeFromVector(strings);
EXPECT_TRUE(string_list_writer.IsUseful());
StringFileWriter file_writer;
StringFile string_file;
ASSERT_TRUE(string_list_writer.WriteEverything(&file_writer));
ASSERT_TRUE(string_list_writer.WriteEverything(&string_file));
const MinidumpRVAList* list =
MinidumpRVAListAtStart(file_writer.string(), strings.size());
MinidumpRVAListAtStart(string_file.string(), strings.size());
ASSERT_TRUE(list);
for (size_t index = 0; index < strings.size(); ++index) {
EXPECT_EQ(Traits::ExpectationForUTF8(strings[index]),
Traits::ObservationAtRVA(file_writer.string(),
Traits::ObservationAtRVA(string_file.string(),
list->children[index]));
}
}

View File

@ -29,7 +29,7 @@
#include "minidump/test/minidump_string_writer_test_util.h"
#include "minidump/test/minidump_writable_test_util.h"
#include "snapshot/test/test_system_snapshot.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
@ -84,14 +84,14 @@ TEST(MinidumpSystemInfoWriter, Empty) {
minidump_file_writer.AddStream(system_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
const MINIDUMP_STRING* csd_version = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version));
GetSystemInfoStream(string_file.string(), 0, &system_info, &csd_version));
EXPECT_EQ(kMinidumpCPUArchitectureUnknown,
system_info->ProcessorArchitecture);
@ -155,14 +155,14 @@ TEST(MinidumpSystemInfoWriter, X86_Win) {
minidump_file_writer.AddStream(system_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
const MINIDUMP_STRING* csd_version = nullptr;
ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(
file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version));
string_file.string(), strlen(kCSDVersion), &system_info, &csd_version));
EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
EXPECT_EQ(kCPULevel, system_info->ProcessorLevel);
@ -215,14 +215,14 @@ TEST(MinidumpSystemInfoWriter, AMD64_Mac) {
minidump_file_writer.AddStream(system_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
const MINIDUMP_STRING* csd_version;
ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(
file_writer.string(), strlen(kCSDVersion), &system_info, &csd_version));
string_file.string(), strlen(kCSDVersion), &system_info, &csd_version));
EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
EXPECT_EQ(kCPULevel, system_info->ProcessorLevel);
@ -257,14 +257,14 @@ TEST(MinidumpSystemInfoWriter, X86_CPUVendorFromRegisters) {
minidump_file_writer.AddStream(system_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
const MINIDUMP_STRING* csd_version;
ASSERT_NO_FATAL_FAILURE(
GetSystemInfoStream(file_writer.string(), 0, &system_info, &csd_version));
GetSystemInfoStream(string_file.string(), 0, &system_info, &csd_version));
EXPECT_EQ(kCPUArchitecture, system_info->ProcessorArchitecture);
EXPECT_EQ(0u, system_info->ProcessorLevel);
@ -337,12 +337,12 @@ TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_X86) {
MinidumpFileWriter minidump_file_writer;
minidump_file_writer.AddStream(system_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
const MINIDUMP_STRING* csd_version = nullptr;
ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(),
ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(string_file.string(),
strlen(kOSVersionBuild),
&system_info,
&csd_version));
@ -432,12 +432,12 @@ TEST(MinidumpSystemInfoWriter, InitializeFromSnapshot_AMD64) {
MinidumpFileWriter minidump_file_writer;
minidump_file_writer.AddStream(system_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_SYSTEM_INFO* system_info = nullptr;
const MINIDUMP_STRING* csd_version = nullptr;
ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(file_writer.string(),
ASSERT_NO_FATAL_FAILURE(GetSystemInfoStream(string_file.string(),
strlen(kOSVersionBuild),
&system_info,
&csd_version));
@ -470,8 +470,8 @@ TEST(MinidumpSystemInfoWriterDeathTest, NoCSDVersion) {
auto system_info_writer = make_scoped_ptr(new MinidumpSystemInfoWriter());
minidump_file_writer.AddStream(system_info_writer.Pass());
StringFileWriter file_writer;
ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer),
StringFile string_file;
ASSERT_DEATH(minidump_file_writer.WriteEverything(&string_file),
"csd_version_");
}

View File

@ -33,7 +33,7 @@
#include "snapshot/test/test_cpu_context.h"
#include "snapshot/test/test_memory_snapshot.h"
#include "snapshot/test/test_thread_snapshot.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
@ -82,16 +82,16 @@ TEST(MinidumpThreadWriter, EmptyThreadList) {
minidump_file_writer.AddStream(thread_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_THREAD_LIST),
file_writer.string().size());
string_file.string().size());
const MINIDUMP_THREAD_LIST* thread_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetThreadListStream(file_writer.string(), &thread_list, nullptr));
GetThreadListStream(string_file.string(), &thread_list, nullptr));
EXPECT_EQ(0u, thread_list->NumberOfThreads);
}
@ -162,17 +162,17 @@ TEST(MinidumpThreadWriter, OneThread_x86_NoStack) {
thread_list_writer->AddThread(thread_writer.Pass());
minidump_file_writer.AddStream(thread_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) +
1 * sizeof(MinidumpContextX86),
file_writer.string().size());
string_file.string().size());
const MINIDUMP_THREAD_LIST* thread_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetThreadListStream(file_writer.string(), &thread_list, nullptr));
GetThreadListStream(string_file.string(), &thread_list, nullptr));
EXPECT_EQ(1u, thread_list->NumberOfThreads);
@ -188,7 +188,7 @@ TEST(MinidumpThreadWriter, OneThread_x86_NoStack) {
ASSERT_NO_FATAL_FAILURE(
ExpectThread(&expected,
&thread_list->Threads[0],
file_writer.string(),
string_file.string(),
nullptr,
reinterpret_cast<const void**>(&observed_context)));
@ -229,17 +229,17 @@ TEST(MinidumpThreadWriter, OneThread_AMD64_Stack) {
thread_list_writer->AddThread(thread_writer.Pass());
minidump_file_writer.AddStream(thread_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) +
1 * sizeof(MinidumpContextAMD64) + kMemorySize,
file_writer.string().size());
string_file.string().size());
const MINIDUMP_THREAD_LIST* thread_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetThreadListStream(file_writer.string(), &thread_list, nullptr));
GetThreadListStream(string_file.string(), &thread_list, nullptr));
EXPECT_EQ(1u, thread_list->NumberOfThreads);
@ -258,14 +258,14 @@ TEST(MinidumpThreadWriter, OneThread_AMD64_Stack) {
ASSERT_NO_FATAL_FAILURE(
ExpectThread(&expected,
&thread_list->Threads[0],
file_writer.string(),
string_file.string(),
&observed_stack,
reinterpret_cast<const void**>(&observed_context)));
ASSERT_NO_FATAL_FAILURE(
ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack,
observed_stack,
file_writer.string(),
string_file.string(),
kMemoryValue,
true));
ASSERT_NO_FATAL_FAILURE(
@ -362,8 +362,8 @@ TEST(MinidumpThreadWriter, ThreeThreads_x86_MemoryList) {
minidump_file_writer.AddStream(thread_list_writer.Pass());
minidump_file_writer.AddStream(memory_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
ASSERT_EQ(sizeof(MINIDUMP_HEADER) + 2 * sizeof(MINIDUMP_DIRECTORY) +
sizeof(MINIDUMP_THREAD_LIST) + 3 * sizeof(MINIDUMP_THREAD) +
@ -371,12 +371,12 @@ TEST(MinidumpThreadWriter, ThreeThreads_x86_MemoryList) {
3 * sizeof(MINIDUMP_MEMORY_DESCRIPTOR) +
3 * sizeof(MinidumpContextX86) + kMemorySize0 + kMemorySize1 +
kMemorySize2 + 12, // 12 for alignment
file_writer.string().size());
string_file.string().size());
const MINIDUMP_THREAD_LIST* thread_list = nullptr;
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetThreadListStream(file_writer.string(), &thread_list, &memory_list));
GetThreadListStream(string_file.string(), &thread_list, &memory_list));
EXPECT_EQ(3u, thread_list->NumberOfThreads);
EXPECT_EQ(3u, memory_list->NumberOfMemoryRanges);
@ -399,14 +399,14 @@ TEST(MinidumpThreadWriter, ThreeThreads_x86_MemoryList) {
ASSERT_NO_FATAL_FAILURE(
ExpectThread(&expected,
&thread_list->Threads[0],
file_writer.string(),
string_file.string(),
&observed_stack,
reinterpret_cast<const void**>(&observed_context)));
ASSERT_NO_FATAL_FAILURE(
ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack,
observed_stack,
file_writer.string(),
string_file.string(),
kMemoryValue0,
false));
ASSERT_NO_FATAL_FAILURE(
@ -433,14 +433,14 @@ TEST(MinidumpThreadWriter, ThreeThreads_x86_MemoryList) {
ASSERT_NO_FATAL_FAILURE(
ExpectThread(&expected,
&thread_list->Threads[1],
file_writer.string(),
string_file.string(),
&observed_stack,
reinterpret_cast<const void**>(&observed_context)));
ASSERT_NO_FATAL_FAILURE(
ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack,
observed_stack,
file_writer.string(),
string_file.string(),
kMemoryValue1,
false));
ASSERT_NO_FATAL_FAILURE(
@ -467,14 +467,14 @@ TEST(MinidumpThreadWriter, ThreeThreads_x86_MemoryList) {
ASSERT_NO_FATAL_FAILURE(
ExpectThread(&expected,
&thread_list->Threads[2],
file_writer.string(),
string_file.string(),
&observed_stack,
reinterpret_cast<const void**>(&observed_context)));
ASSERT_NO_FATAL_FAILURE(
ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack,
observed_stack,
file_writer.string(),
string_file.string(),
kMemoryValue2,
true));
ASSERT_NO_FATAL_FAILURE(
@ -607,13 +607,13 @@ void RunInitializeFromSnapshotTest(bool thread_id_collision) {
minidump_file_writer.AddStream(thread_list_writer.Pass());
minidump_file_writer.AddStream(memory_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
StringFile string_file;
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
const MINIDUMP_THREAD_LIST* thread_list = nullptr;
const MINIDUMP_MEMORY_LIST* memory_list = nullptr;
ASSERT_NO_FATAL_FAILURE(
GetThreadListStream(file_writer.string(), &thread_list, &memory_list));
GetThreadListStream(string_file.string(), &thread_list, &memory_list));
ASSERT_EQ(3u, thread_list->NumberOfThreads);
ASSERT_EQ(2u, memory_list->NumberOfMemoryRanges);
@ -629,7 +629,7 @@ void RunInitializeFromSnapshotTest(bool thread_id_collision) {
ASSERT_NO_FATAL_FAILURE(
ExpectThread(&expect_threads[index],
&thread_list->Threads[index],
file_writer.string(),
string_file.string(),
observed_stack_p,
reinterpret_cast<const void**>(&observed_context)));
@ -640,7 +640,7 @@ void RunInitializeFromSnapshotTest(bool thread_id_collision) {
ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptorAndContents(
&expect_threads[index].Stack,
observed_stack,
file_writer.string(),
string_file.string(),
memory_values[index],
index == thread_list->NumberOfThreads - 1));
@ -673,8 +673,8 @@ TEST(MinidumpThreadWriterDeathTest, NoContext) {
thread_list_writer->AddThread(thread_writer.Pass());
minidump_file_writer.AddStream(thread_list_writer.Pass());
StringFileWriter file_writer;
ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_");
StringFile string_file;
ASSERT_DEATH(minidump_file_writer.WriteEverything(&string_file), "context_");
}
TEST(MinidumpThreadWriterDeathTest, InitializeFromSnapshot_NoContext) {

View File

@ -19,7 +19,7 @@
#include "base/basictypes.h"
#include "gtest/gtest.h"
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
namespace crashpad {
namespace test {
@ -145,101 +145,101 @@ class TestStringMinidumpWritable final : public BaseTestMinidumpWritable {
};
TEST(MinidumpWritable, MinidumpWritable) {
StringFileWriter writer;
StringFile string_file;
{
SCOPED_TRACE("empty");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable string_writable;
EXPECT_TRUE(string_writable.WriteEverything(&writer));
EXPECT_TRUE(writer.string().empty());
EXPECT_TRUE(string_writable.WriteEverything(&string_file));
EXPECT_TRUE(string_file.string().empty());
string_writable.Verify();
}
{
SCOPED_TRACE("childless");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable string_writable;
string_writable.SetData("a");
EXPECT_TRUE(string_writable.WriteEverything(&writer));
EXPECT_EQ(1u, writer.string().size());
EXPECT_EQ("a", writer.string());
EXPECT_TRUE(string_writable.WriteEverything(&string_file));
EXPECT_EQ(1u, string_file.string().size());
EXPECT_EQ("a", string_file.string());
string_writable.Verify();
}
{
SCOPED_TRACE("parent-child");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("b");
TestStringMinidumpWritable child;
child.SetData("c");
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ(std::string("b\0\0\0c", 5), writer.string());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ(std::string("b\0\0\0c", 5), string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("base alignment 2");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("de");
TestStringMinidumpWritable child;
child.SetData("f");
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ(std::string("de\0\0f", 5), writer.string());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ(std::string("de\0\0f", 5), string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("base alignment 3");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("ghi");
TestStringMinidumpWritable child;
child.SetData("j");
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ(std::string("ghi\0j", 5), writer.string());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ(std::string("ghi\0j", 5), string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("base alignment 4");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("klmn");
TestStringMinidumpWritable child;
child.SetData("o");
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ("klmno", writer.string());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ("klmno", string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("base alignment 5");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("pqrst");
TestStringMinidumpWritable child;
child.SetData("u");
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(9u, writer.string().size());
EXPECT_EQ(std::string("pqrst\0\0\0u", 9), writer.string());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(9u, string_file.string().size());
EXPECT_EQ(std::string("pqrst\0\0\0u", 9), string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("two children");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("parent");
TestStringMinidumpWritable child_0;
@ -248,15 +248,15 @@ TEST(MinidumpWritable, MinidumpWritable) {
TestStringMinidumpWritable child_1;
child_1.SetData("child_1");
parent.AddChild(&child_1);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(23u, writer.string().size());
EXPECT_EQ(std::string("parent\0\0child_0\0child_1", 23), writer.string());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(23u, string_file.string().size());
EXPECT_EQ(std::string("parent\0\0child_0\0child_1", 23), string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("grandchild");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("parent");
TestStringMinidumpWritable child;
@ -265,16 +265,16 @@ TEST(MinidumpWritable, MinidumpWritable) {
TestStringMinidumpWritable grandchild;
grandchild.SetData("grandchild");
child.AddChild(&grandchild);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(26u, writer.string().size());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(26u, string_file.string().size());
EXPECT_EQ(std::string("parent\0\0child\0\0\0grandchild", 26),
writer.string());
string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("grandchild with empty parent");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
TestStringMinidumpWritable child;
child.SetData("child");
@ -282,15 +282,15 @@ TEST(MinidumpWritable, MinidumpWritable) {
TestStringMinidumpWritable grandchild;
grandchild.SetData("grandchild");
child.AddChild(&grandchild);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(18u, writer.string().size());
EXPECT_EQ(std::string("child\0\0\0grandchild", 18), writer.string());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(18u, string_file.string().size());
EXPECT_EQ(std::string("child\0\0\0grandchild", 18), string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("grandchild with empty child");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("parent");
TestStringMinidumpWritable child;
@ -298,15 +298,15 @@ TEST(MinidumpWritable, MinidumpWritable) {
TestStringMinidumpWritable grandchild;
grandchild.SetData("grandchild");
child.AddChild(&grandchild);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(18u, writer.string().size());
EXPECT_EQ(std::string("parent\0\0grandchild", 18), writer.string());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(18u, string_file.string().size());
EXPECT_EQ(std::string("parent\0\0grandchild", 18), string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("grandchild with empty grandchild");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("parent");
TestStringMinidumpWritable child;
@ -314,15 +314,15 @@ TEST(MinidumpWritable, MinidumpWritable) {
parent.AddChild(&child);
TestStringMinidumpWritable grandchild;
child.AddChild(&grandchild);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(13u, writer.string().size());
EXPECT_EQ(std::string("parent\0\0child", 13), writer.string());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(13u, string_file.string().size());
EXPECT_EQ(std::string("parent\0\0child", 13), string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("grandchild with late-phase grandchild");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("parent");
TestStringMinidumpWritable child;
@ -332,16 +332,16 @@ TEST(MinidumpWritable, MinidumpWritable) {
grandchild.SetData("grandchild");
grandchild.SetPhaseLate();
child.AddChild(&grandchild);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(26u, writer.string().size());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(26u, string_file.string().size());
EXPECT_EQ(std::string("parent\0\0child\0\0\0grandchild", 26),
writer.string());
string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("grandchild with late-phase child");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("parent");
TestStringMinidumpWritable child;
@ -351,16 +351,16 @@ TEST(MinidumpWritable, MinidumpWritable) {
TestStringMinidumpWritable grandchild;
grandchild.SetData("grandchild");
child.AddChild(&grandchild);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(25u, writer.string().size());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(25u, string_file.string().size());
EXPECT_EQ(std::string("parent\0\0grandchild\0\0child", 25),
writer.string());
string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("family tree");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("P..");
TestStringMinidumpWritable child_0;
@ -381,16 +381,16 @@ TEST(MinidumpWritable, MinidumpWritable) {
TestStringMinidumpWritable grandchild_11;
grandchild_11.SetData("G11");
child_1.AddChild(&grandchild_11);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(27u, writer.string().size());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(27u, string_file.string().size());
EXPECT_EQ(std::string("P..\0C0.\0G00\0G01\0C1.\0G10\0G11", 27),
writer.string());
string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("family tree with C0 late");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("P..");
TestStringMinidumpWritable child_0;
@ -412,16 +412,16 @@ TEST(MinidumpWritable, MinidumpWritable) {
TestStringMinidumpWritable grandchild_11;
grandchild_11.SetData("G11");
child_1.AddChild(&grandchild_11);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(27u, writer.string().size());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(27u, string_file.string().size());
EXPECT_EQ(std::string("P..\0G00\0G01\0C1.\0G10\0G11\0C0.", 27),
writer.string());
string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("family tree with G0 late");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("P..");
TestStringMinidumpWritable child_0;
@ -444,40 +444,40 @@ TEST(MinidumpWritable, MinidumpWritable) {
TestStringMinidumpWritable grandchild_11;
grandchild_11.SetData("G11");
child_1.AddChild(&grandchild_11);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(27u, writer.string().size());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(27u, string_file.string().size());
EXPECT_EQ(std::string("P..\0C0.\0C1.\0G10\0G11\0G00\0G01", 27),
writer.string());
string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("align 1");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("p");
TestStringMinidumpWritable child;
child.SetData("c");
child.SetAlignment(1);
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(2u, writer.string().size());
EXPECT_EQ("pc", writer.string());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(2u, string_file.string().size());
EXPECT_EQ("pc", string_file.string());
parent.Verify();
}
{
SCOPED_TRACE("align 2");
writer.Reset();
string_file.Reset();
TestStringMinidumpWritable parent;
parent.SetData("p");
TestStringMinidumpWritable child;
child.SetData("c");
child.SetAlignment(2);
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_EQ(3u, writer.string().size());
EXPECT_EQ(std::string("p\0c", 3), writer.string());
EXPECT_TRUE(parent.WriteEverything(&string_file));
EXPECT_EQ(3u, string_file.string().size());
EXPECT_EQ(std::string("p\0c", 3), string_file.string());
parent.Verify();
}
}
@ -513,81 +513,81 @@ RVA RVAAtIndex(const std::string& string, size_t index) {
}
TEST(MinidumpWritable, RVA) {
StringFileWriter writer;
StringFile string_file;
{
SCOPED_TRACE("unset");
writer.Reset();
string_file.Reset();
TestRVAMinidumpWritable rva_writable;
EXPECT_TRUE(rva_writable.WriteEverything(&writer));
EXPECT_TRUE(rva_writable.WriteEverything(&string_file));
ASSERT_EQ(sizeof(RVA), writer.string().size());
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(writer.string(), 0));
ASSERT_EQ(sizeof(RVA), string_file.string().size());
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(string_file.string(), 0));
rva_writable.Verify();
}
{
SCOPED_TRACE("self");
writer.Reset();
string_file.Reset();
TestRVAMinidumpWritable rva_writable;
rva_writable.SetRVA(&rva_writable);
EXPECT_TRUE(rva_writable.WriteEverything(&writer));
EXPECT_TRUE(rva_writable.WriteEverything(&string_file));
ASSERT_EQ(sizeof(RVA), writer.string().size());
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(writer.string(), 0));
ASSERT_EQ(sizeof(RVA), string_file.string().size());
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(string_file.string(), 0));
rva_writable.Verify();
}
{
SCOPED_TRACE("parent-child self");
writer.Reset();
string_file.Reset();
TestRVAMinidumpWritable parent;
parent.SetRVA(&parent);
TestRVAMinidumpWritable child;
child.SetRVA(&child);
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_TRUE(parent.WriteEverything(&string_file));
ASSERT_EQ(2 * sizeof(RVA), writer.string().size());
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(writer.string(), 0));
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(writer.string(), 1));
ASSERT_EQ(2 * sizeof(RVA), string_file.string().size());
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(string_file.string(), 0));
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(string_file.string(), 1));
parent.Verify();
}
{
SCOPED_TRACE("parent-child only");
writer.Reset();
string_file.Reset();
TestRVAMinidumpWritable parent;
TestRVAMinidumpWritable child;
parent.SetRVA(&child);
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_TRUE(parent.WriteEverything(&string_file));
ASSERT_EQ(2 * sizeof(RVA), writer.string().size());
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(writer.string(), 0));
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(writer.string(), 1));
ASSERT_EQ(2 * sizeof(RVA), string_file.string().size());
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(string_file.string(), 0));
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(string_file.string(), 1));
parent.Verify();
}
{
SCOPED_TRACE("parent-child circular");
writer.Reset();
string_file.Reset();
TestRVAMinidumpWritable parent;
TestRVAMinidumpWritable child;
parent.SetRVA(&child);
child.SetRVA(&parent);
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_TRUE(parent.WriteEverything(&string_file));
ASSERT_EQ(2 * sizeof(RVA), writer.string().size());
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(writer.string(), 0));
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(writer.string(), 1));
ASSERT_EQ(2 * sizeof(RVA), string_file.string().size());
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(string_file.string(), 0));
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(string_file.string(), 1));
parent.Verify();
}
{
SCOPED_TRACE("grandchildren");
writer.Reset();
string_file.Reset();
TestRVAMinidumpWritable parent;
TestRVAMinidumpWritable child;
parent.SetRVA(&child);
@ -601,14 +601,14 @@ TEST(MinidumpWritable, RVA) {
TestRVAMinidumpWritable grandchild_2;
grandchild_2.SetRVA(&child);
child.AddChild(&grandchild_2);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_TRUE(parent.WriteEverything(&string_file));
ASSERT_EQ(5 * sizeof(RVA), writer.string().size());
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(writer.string(), 0));
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(writer.string(), 1));
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(writer.string(), 2));
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(writer.string(), 3));
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(writer.string(), 4));
ASSERT_EQ(5 * sizeof(RVA), string_file.string().size());
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(string_file.string(), 0));
EXPECT_EQ(0 * sizeof(RVA), RVAAtIndex(string_file.string(), 1));
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(string_file.string(), 2));
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(string_file.string(), 3));
EXPECT_EQ(1 * sizeof(RVA), RVAAtIndex(string_file.string(), 4));
parent.Verify();
}
}
@ -666,16 +666,16 @@ const LocationDescriptorAndData* LDDAtIndex(const std::string& string,
}
TEST(MinidumpWritable, LocationDescriptor) {
StringFileWriter writer;
StringFile string_file;
{
SCOPED_TRACE("unset");
writer.Reset();
string_file.Reset();
TestLocationDescriptorMinidumpWritable location_descriptor_writable;
EXPECT_TRUE(location_descriptor_writable.WriteEverything(&writer));
EXPECT_TRUE(location_descriptor_writable.WriteEverything(&string_file));
ASSERT_EQ(9u, writer.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(writer.string(), 0);
ASSERT_EQ(9u, string_file.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(string_file.string(), 0);
EXPECT_EQ(0u, ldd->location_descriptor.DataSize);
EXPECT_EQ(0u, ldd->location_descriptor.Rva);
location_descriptor_writable.Verify();
@ -683,14 +683,14 @@ TEST(MinidumpWritable, LocationDescriptor) {
{
SCOPED_TRACE("self");
writer.Reset();
string_file.Reset();
TestLocationDescriptorMinidumpWritable location_descriptor_writable;
location_descriptor_writable.SetLocationDescriptor(
&location_descriptor_writable);
EXPECT_TRUE(location_descriptor_writable.WriteEverything(&writer));
EXPECT_TRUE(location_descriptor_writable.WriteEverything(&string_file));
ASSERT_EQ(9u, writer.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(writer.string(), 0);
ASSERT_EQ(9u, string_file.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(string_file.string(), 0);
EXPECT_EQ(9u, ldd->location_descriptor.DataSize);
EXPECT_EQ(0u, ldd->location_descriptor.Rva);
location_descriptor_writable.Verify();
@ -698,15 +698,15 @@ TEST(MinidumpWritable, LocationDescriptor) {
{
SCOPED_TRACE("self with data");
writer.Reset();
string_file.Reset();
TestLocationDescriptorMinidumpWritable location_descriptor_writable;
location_descriptor_writable.SetLocationDescriptor(
&location_descriptor_writable);
location_descriptor_writable.SetString("zz");
EXPECT_TRUE(location_descriptor_writable.WriteEverything(&writer));
EXPECT_TRUE(location_descriptor_writable.WriteEverything(&string_file));
ASSERT_EQ(11u, writer.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(writer.string(), 0);
ASSERT_EQ(11u, string_file.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(string_file.string(), 0);
EXPECT_EQ(11u, ldd->location_descriptor.DataSize);
EXPECT_EQ(0u, ldd->location_descriptor.Rva);
EXPECT_STREQ("zz", ldd->string);
@ -715,7 +715,7 @@ TEST(MinidumpWritable, LocationDescriptor) {
{
SCOPED_TRACE("parent-child self");
writer.Reset();
string_file.Reset();
TestLocationDescriptorMinidumpWritable parent;
parent.SetLocationDescriptor(&parent);
parent.SetString("yy");
@ -723,14 +723,14 @@ TEST(MinidumpWritable, LocationDescriptor) {
child.SetLocationDescriptor(&child);
child.SetString("x");
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_TRUE(parent.WriteEverything(&string_file));
ASSERT_EQ(22u, writer.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(writer.string(), 0);
ASSERT_EQ(22u, string_file.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(string_file.string(), 0);
EXPECT_EQ(11u, ldd->location_descriptor.DataSize);
EXPECT_EQ(0u, ldd->location_descriptor.Rva);
EXPECT_STREQ("yy", ldd->string);
ldd = LDDAtIndex(writer.string(), 12);
ldd = LDDAtIndex(string_file.string(), 12);
EXPECT_EQ(10u, ldd->location_descriptor.DataSize);
EXPECT_EQ(12u, ldd->location_descriptor.Rva);
EXPECT_STREQ("x", ldd->string);
@ -739,21 +739,21 @@ TEST(MinidumpWritable, LocationDescriptor) {
{
SCOPED_TRACE("parent-child only");
writer.Reset();
string_file.Reset();
TestLocationDescriptorMinidumpWritable parent;
TestLocationDescriptorMinidumpWritable child;
parent.SetLocationDescriptor(&child);
parent.SetString("www");
child.SetString("vv");
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_TRUE(parent.WriteEverything(&string_file));
ASSERT_EQ(23u, writer.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(writer.string(), 0);
ASSERT_EQ(23u, string_file.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(string_file.string(), 0);
EXPECT_EQ(11u, ldd->location_descriptor.DataSize);
EXPECT_EQ(12u, ldd->location_descriptor.Rva);
EXPECT_STREQ("www", ldd->string);
ldd = LDDAtIndex(writer.string(), 12);
ldd = LDDAtIndex(string_file.string(), 12);
EXPECT_EQ(0u, ldd->location_descriptor.DataSize);
EXPECT_EQ(0u, ldd->location_descriptor.Rva);
EXPECT_STREQ("vv", ldd->string);
@ -762,7 +762,7 @@ TEST(MinidumpWritable, LocationDescriptor) {
{
SCOPED_TRACE("parent-child circular");
writer.Reset();
string_file.Reset();
TestLocationDescriptorMinidumpWritable parent;
TestLocationDescriptorMinidumpWritable child;
parent.SetLocationDescriptor(&child);
@ -770,14 +770,14 @@ TEST(MinidumpWritable, LocationDescriptor) {
child.SetLocationDescriptor(&parent);
child.SetString("tttt");
parent.AddChild(&child);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_TRUE(parent.WriteEverything(&string_file));
ASSERT_EQ(29u, writer.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(writer.string(), 0);
ASSERT_EQ(29u, string_file.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(string_file.string(), 0);
EXPECT_EQ(13u, ldd->location_descriptor.DataSize);
EXPECT_EQ(16u, ldd->location_descriptor.Rva);
EXPECT_STREQ("uuuu", ldd->string);
ldd = LDDAtIndex(writer.string(), 16);
ldd = LDDAtIndex(string_file.string(), 16);
EXPECT_EQ(13u, ldd->location_descriptor.DataSize);
EXPECT_EQ(0u, ldd->location_descriptor.Rva);
EXPECT_STREQ("tttt", ldd->string);
@ -786,7 +786,7 @@ TEST(MinidumpWritable, LocationDescriptor) {
{
SCOPED_TRACE("grandchildren");
writer.Reset();
string_file.Reset();
TestLocationDescriptorMinidumpWritable parent;
TestLocationDescriptorMinidumpWritable child;
parent.SetLocationDescriptor(&child);
@ -805,26 +805,26 @@ TEST(MinidumpWritable, LocationDescriptor) {
grandchild_2.SetLocationDescriptor(&child);
grandchild_2.SetString("o");
child.AddChild(&grandchild_2);
EXPECT_TRUE(parent.WriteEverything(&writer));
EXPECT_TRUE(parent.WriteEverything(&string_file));
ASSERT_EQ(58u, writer.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(writer.string(), 0);
ASSERT_EQ(58u, string_file.string().size());
const LocationDescriptorAndData* ldd = LDDAtIndex(string_file.string(), 0);
EXPECT_EQ(10u, ldd->location_descriptor.DataSize);
EXPECT_EQ(12u, ldd->location_descriptor.Rva);
EXPECT_STREQ("s", ldd->string);
ldd = LDDAtIndex(writer.string(), 12);
ldd = LDDAtIndex(string_file.string(), 12);
EXPECT_EQ(0u, ldd->location_descriptor.DataSize);
EXPECT_EQ(0u, ldd->location_descriptor.Rva);
EXPECT_STREQ("r", ldd->string);
ldd = LDDAtIndex(writer.string(), 24);
ldd = LDDAtIndex(string_file.string(), 24);
EXPECT_EQ(10u, ldd->location_descriptor.DataSize);
EXPECT_EQ(12u, ldd->location_descriptor.Rva);
EXPECT_STREQ("q", ldd->string);
ldd = LDDAtIndex(writer.string(), 36);
ldd = LDDAtIndex(string_file.string(), 36);
EXPECT_EQ(10u, ldd->location_descriptor.DataSize);
EXPECT_EQ(12u, ldd->location_descriptor.Rva);
EXPECT_STREQ("p", ldd->string);
ldd = LDDAtIndex(writer.string(), 48);
ldd = LDDAtIndex(string_file.string(), 48);
EXPECT_EQ(10u, ldd->location_descriptor.DataSize);
EXPECT_EQ(12u, ldd->location_descriptor.Rva);
EXPECT_STREQ("o", ldd->string);

88
util/file/file_reader.cc Normal file
View File

@ -0,0 +1,88 @@
// 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 "util/file/file_reader.h"
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
namespace crashpad {
WeakFileHandleFileReader::WeakFileHandleFileReader(FileHandle file_handle)
: file_handle_(file_handle) {
}
WeakFileHandleFileReader::~WeakFileHandleFileReader() {
}
ssize_t WeakFileHandleFileReader::Read(void* data, size_t size) {
DCHECK_NE(file_handle_, kInvalidFileHandle);
// Dont use LoggingReadFile(), which insists on a full read and only returns
// a bool. This method permits short reads and returns the number of bytes
// read.
base::checked_cast<ssize_t>(size);
ssize_t rv = ReadFile(file_handle_, data, size);
if (rv < 0) {
PLOG(ERROR) << "read";
return -1;
}
return rv;
}
FileOffset WeakFileHandleFileReader::Seek(FileOffset offset, int whence) {
DCHECK_NE(file_handle_, kInvalidFileHandle);
return LoggingSeekFile(file_handle_, offset, whence);
}
FileReader::FileReader()
: file_(),
weak_file_handle_file_reader_(kInvalidFileHandle) {
}
FileReader::~FileReader() {
}
bool FileReader::Open(const base::FilePath& path,
FileWriteMode write_mode,
FilePermissions permissions) {
CHECK(!file_.is_valid());
file_.reset(LoggingOpenFileForRead(path));
if (!file_.is_valid()) {
return false;
}
weak_file_handle_file_reader_.set_file_handle(file_.get());
return true;
}
void FileReader::Close() {
CHECK(file_.is_valid());
weak_file_handle_file_reader_.set_file_handle(kInvalidFileHandle);
file_.reset();
}
ssize_t FileReader::Read(void* data, size_t size) {
DCHECK(file_.is_valid());
return weak_file_handle_file_reader_.Read(data, size);
}
FileOffset FileReader::Seek(FileOffset offset, int whence) {
DCHECK(file_.is_valid());
return weak_file_handle_file_reader_.Seek(offset, whence);
}
} // namespace crashpad

140
util/file/file_reader.h Normal file
View File

@ -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.
#ifndef CRASHPAD_UTIL_FILE_FILE_READER_H_
#define CRASHPAD_UTIL_FILE_FILE_READER_H_
#include <sys/types.h>
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "util/file/file_io.h"
#include "util/file/file_seeker.h"
namespace crashpad {
//! \brief An interface to read to files and other file-like objects with
//! semantics matching the underlying platform (POSIX or Windows).
class FileReaderInterface : public FileSeekerInterface {
public:
//! \brief Wraps ReadFile(), or provides an implementation with identical
//! semantics.
//!
//! \return The number of bytes actually read if the operation succeeded,
//! which may be `0` or any positive value less than or equal to \a size.
//! `-1` if the operation failed, with an error message logged.
virtual ssize_t Read(void* data, size_t size) = 0;
protected:
~FileReaderInterface() {}
};
//! \brief A file reader backed by a FileHandle.
//!
//! FileReader requires users to provide a FilePath to open, but this class
//! accepts an already-open FileHandle instead. Like FileReader, this class may
//! read from a filesystem-based file, but unlike FileReader, this class is not
//! responsible for opening or closing the file. Users of this class must ensure
//! that the file handle is closed appropriately elsewhere. Objects of this
//! class may be used to read from file handles not associated with
//! filesystem-based files, although special attention should be paid to the
//! Seek() method, which may not function on file handles that do not refer to
//! disk-based files.
//!
//! This class is expected to be used when other code is responsible for
//! opening files and already provides file handles.
class WeakFileHandleFileReader : public FileReaderInterface {
public:
explicit WeakFileHandleFileReader(FileHandle file_handle);
~WeakFileHandleFileReader();
// FileReaderInterface:
ssize_t Read(void* data, size_t size) override;
// FileSeekerInterface:
//! \copydoc FileReaderInterface::Seek()
//!
//! \note This method is only guaranteed to function on file handles referring
//! to disk-based files.
FileOffset Seek(FileOffset offset, int whence) override;
private:
void set_file_handle(FileHandle file_handle) { file_handle_ = file_handle; }
FileHandle file_handle_; // weak
// FileReader uses this class as its internal implementation, and it needs to
// be able to call set_file_handle(). FileReader cannot initialize a
// WeakFileHandleFileReader with a correct file descriptor at the time of
// construction because no file descriptor will be available until
// FileReader::Open() is called.
friend class FileReader;
DISALLOW_COPY_AND_ASSIGN(WeakFileHandleFileReader);
};
//! \brief A file reader implementation that wraps traditional system file
//! operations on files accessed through the filesystem.
class FileReader : public FileReaderInterface {
public:
FileReader();
~FileReader();
// FileReaderInterface:
//! \brief Wraps LoggingOpenFileForRead().
//!
//! \return `true` if the operation succeeded, `false` if it failed, with an
//! error message logged.
//!
//! \note After a successful call, this method cannot be called again until
//! after Close().
bool Open(const base::FilePath& path,
FileWriteMode write_mode,
FilePermissions permissions);
//! \brief Wraps CheckedCloseHandle().
//!
//! \note It is only valid to call this method on an object that has had a
//! successful Open() that has not yet been matched by a subsequent call
//! to this method.
void Close();
// FileReaderInterface:
//! \copydoc FileReaderInterface::Read()
//!
//! \note It is only valid to call this method between a successful Open() and
//! a Close().
ssize_t Read(void* data, size_t size) override;
// FileSeekerInterface:
//! \copydoc FileReaderInterface::Seek()
//!
//! \note It is only valid to call this method between a successful Open() and
//! a Close().
FileOffset Seek(FileOffset offset, int whence) override;
private:
ScopedFileHandle file_;
WeakFileHandleFileReader weak_file_handle_file_reader_;
DISALLOW_COPY_AND_ASSIGN(FileReader);
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_FILE_FILE_READER_H_

39
util/file/file_seeker.h Normal file
View File

@ -0,0 +1,39 @@
// 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.
#ifndef CRASHPAD_UTIL_FILE_FILE_SEEKER_H_
#define CRASHPAD_UTIL_FILE_FILE_SEEKER_H_
#include "util/file/file_io.h"
namespace crashpad {
//! \brief An interface to seek in files and other file-like objects with
//! semantics matching the underlying platform (POSIX or Windows).
class FileSeekerInterface {
public:
//! \brief Wraps LoggingFileSeek() or provides an alternate implementation
//! with identical semantics.
//!
//! \return The return value of LoggingFileSeek(). `-1` on failure,
//! with an error message logged.
virtual FileOffset Seek(FileOffset offset, int whence) = 0;
protected:
~FileSeekerInterface() {}
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_FILE_FILE_SEEKER_H_

View File

@ -19,6 +19,8 @@
#include <limits.h>
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "build/build_config.h"
#if defined(OS_POSIX)
#include <sys/uio.h>
@ -46,18 +48,7 @@ WeakFileHandleFileWriter::~WeakFileHandleFileWriter() {
bool WeakFileHandleFileWriter::Write(const void* data, size_t size) {
DCHECK_NE(file_handle_, kInvalidFileHandle);
// TODO(mark): Write no more than SSIZE_MAX bytes in a single call.
ssize_t written = WriteFile(file_handle_, data, size);
if (written < 0) {
PLOG(ERROR) << "write";
return false;
} else if (written == 0) {
LOG(ERROR) << "write: returned 0";
return false;
}
return true;
return LoggingWriteFile(file_handle_, data, size);
}
bool WeakFileHandleFileWriter::WriteIoVec(std::vector<WritableIoVec>* iovecs) {

View File

@ -15,16 +15,14 @@
#ifndef CRASHPAD_UTIL_FILE_FILE_WRITER_H_
#define CRASHPAD_UTIL_FILE_FILE_WRITER_H_
#include <fcntl.h>
#include <stddef.h>
#include <sys/types.h>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "build/build_config.h"
#include "util/file/file_io.h"
#include "util/file/file_seeker.h"
namespace crashpad {
@ -44,10 +42,10 @@ struct WritableIoVec {
//! \brief An interface to write to files and other file-like objects with
//! semantics matching the underlying platform (POSIX or Windows).
class FileWriterInterface {
class FileWriterInterface : public FileSeekerInterface {
public:
//! \brief Wraps WriteFile(), or provides an implementation with identical
//! semantics.
//! \brief Wraps LoggingWriteFile(), or provides an implementation with
//! identical semantics.
//!
//! \return `true` if the operation succeeded, `false` if it failed, with an
//! error message logged.
@ -64,13 +62,6 @@ class FileWriterInterface {
//! \note The contents of \a iovecs are undefined when this method returns.
virtual bool WriteIoVec(std::vector<WritableIoVec>* iovecs) = 0;
//! \brief Wraps LoggingFileSeek() or provides an alternate implementation
//! with identical semantics.
//!
//! \return The return value of LoggingFileSeek(). `-1` on failure,
//! with an error message logged.
virtual FileOffset Seek(FileOffset offset, int whence) = 0;
protected:
~FileWriterInterface() {}
};
@ -98,6 +89,8 @@ class WeakFileHandleFileWriter : public FileWriterInterface {
bool Write(const void* data, size_t size) override;
bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override;
// FileSeekerInterface:
//! \copydoc FileWriterInterface::Seek()
//!
//! \note This method is only guaranteed to function on file handles referring
@ -110,7 +103,7 @@ class WeakFileHandleFileWriter : public FileWriterInterface {
FileHandle file_handle_; // weak
// FileWriter uses this class as its internal implementation, and it needs to
// be able to call set_file_handle(). FileWriter cannot initialize an
// be able to call set_file_handle(). FileWriter cannot initialize a
// WeakFileHandleFileWriter with a correct file descriptor at the time of
// construction because no file descriptor will be available until
// FileWriter::Open() is called.
@ -126,6 +119,8 @@ class FileWriter : public FileWriterInterface {
FileWriter();
~FileWriter();
// FileWriterInterface:
//! \brief Wraps LoggingOpenFileForWrite().
//!
//! \return `true` if the operation succeeded, `false` if it failed, with an
@ -158,6 +153,8 @@ class FileWriter : public FileWriterInterface {
//! a Close().
bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override;
// FileSeekerInterface:
//! \copydoc FileWriterInterface::Seek()
//!
//! \note It is only valid to call this method between a successful Open() and

View File

@ -12,28 +12,61 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "util/file/string_file_writer.h"
#include "util/file/string_file.h"
#include <string.h>
#include <algorithm>
#include <limits>
#include "base/logging.h"
#include "base/numerics/safe_math.h"
#include "util/numeric/safe_assignment.h"
namespace crashpad {
StringFileWriter::StringFileWriter() : string_(), offset_(0) {
StringFile::StringFile() : string_(), offset_(0) {
}
StringFileWriter::~StringFileWriter() {
StringFile::~StringFile() {
}
void StringFileWriter::Reset() {
void StringFile::SetString(const std::string& string) {
CHECK_LE(string.size(),
implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()));
string_ = string;
offset_ = 0;
}
void StringFile::Reset() {
string_.clear();
offset_ = 0;
}
bool StringFileWriter::Write(const void* data, size_t size) {
ssize_t StringFile::Read(void* data, size_t size) {
DCHECK(offset_.IsValid());
const size_t offset = offset_.ValueOrDie();
if (offset >= string_.size()) {
return 0;
}
const size_t nread = std::min(size, string_.size() - offset);
base::CheckedNumeric<ssize_t> new_offset = offset_;
new_offset += nread;
if (!new_offset.IsValid()) {
LOG(ERROR) << "Read(): file too large";
return -1;
}
memcpy(data, &string_[offset], nread);
offset_ = new_offset;
return nread;
}
bool StringFile::Write(const void* data, size_t size) {
DCHECK(offset_.IsValid());
const size_t offset = offset_.ValueOrDie();
@ -54,7 +87,7 @@ bool StringFileWriter::Write(const void* data, size_t size) {
return true;
}
bool StringFileWriter::WriteIoVec(std::vector<WritableIoVec>* iovecs) {
bool StringFile::WriteIoVec(std::vector<WritableIoVec>* iovecs) {
DCHECK(offset_.IsValid());
if (iovecs->empty()) {
@ -87,7 +120,7 @@ bool StringFileWriter::WriteIoVec(std::vector<WritableIoVec>* iovecs) {
return true;
}
FileOffset StringFileWriter::Seek(FileOffset offset, int whence) {
FileOffset StringFile::Seek(FileOffset offset, int whence) {
DCHECK(offset_.IsValid());
size_t base_offset;

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CRASHPAD_UTIL_FILE_STRING_FILE_WRITER_H_
#define CRASHPAD_UTIL_FILE_STRING_FILE_WRITER_H_
#ifndef CRASHPAD_UTIL_FILE_STRING_FILE_H_
#define CRASHPAD_UTIL_FILE_STRING_FILE_H_
#include <sys/types.h>
@ -21,32 +21,42 @@
#include "base/basictypes.h"
#include "base/numerics/safe_math.h"
#include "util/file/file_reader.h"
#include "util/file/file_writer.h"
namespace crashpad {
//! \brief A file writer backed by a virtual file, as opposed to a file on disk
//! or other operating system file descriptor-based file.
//! \brief A file reader and writer backed by a virtual file, as opposed to a
//! file on disk or other operating system file descriptor-based file.
//!
//! The virtual file is a buffer in memory. This class is convenient for use
//! with other code that normally expects to write files, when it is impractical
//! or inconvenient to write a file. It is expected that tests, in particular,
//! will benefit from using this class.
class StringFileWriter : public FileWriterInterface {
//! with other code that normally expects to read or write files, when it is
//! impractical or inconvenient to read or write a file. It is expected that
//! tests, in particular, will benefit from using this class.
class StringFile : public FileReaderInterface, public FileWriterInterface {
public:
StringFileWriter();
~StringFileWriter();
StringFile();
~StringFile();
//! \brief Returns a string containing the virtual files contents.
const std::string& string() const { return string_; }
//! \brief Sets the virtual files contents to \a string, and resets its file
//! position to `0`.
void SetString(const std::string& string);
//! \brief Resets the virtual files contents to be empty, and resets its file
//! position to `0`.
void Reset();
// FileReaderInterface:
ssize_t Read(void* data, size_t size) override;
// FileWriterInterface:
bool Write(const void* data, size_t size) override;
bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override;
// FileSeekerInterface:
FileOffset Seek(FileOffset offset, int whence) override;
private:
@ -62,9 +72,9 @@ class StringFileWriter : public FileWriterInterface {
//! between these distinct types.
base::CheckedNumeric<size_t> offset_;
DISALLOW_COPY_AND_ASSIGN(StringFileWriter);
DISALLOW_COPY_AND_ASSIGN(StringFile);
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_FILE_STRING_FILE_WRITER_H_
#endif // CRASHPAD_UTIL_FILE_STRING_FILE_H_

View File

@ -0,0 +1,470 @@
// 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 "util/file/string_file.h"
#include <string.h>
#include <algorithm>
#include <limits>
#include "gtest/gtest.h"
namespace crashpad {
namespace test {
namespace {
TEST(StringFile, EmptyFile) {
StringFile string_file;
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.Write("", 0));
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
char c = '6';
EXPECT_EQ(0, string_file.Read(&c, 1));
EXPECT_EQ('6', c);
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.string().empty());
}
TEST(StringFile, OneByteFile) {
StringFile string_file;
EXPECT_TRUE(string_file.Write("a", 1));
EXPECT_EQ(1u, string_file.string().size());
EXPECT_EQ("a", string_file.string());
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
char c = '6';
EXPECT_EQ(1, string_file.Read(&c, 1));
EXPECT_EQ('a', c);
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(0, string_file.Read(&c, 1));
EXPECT_EQ('a', c);
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ("a", string_file.string());
EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
EXPECT_TRUE(string_file.Write("b", 1));
EXPECT_EQ(1u, string_file.string().size());
EXPECT_EQ("b", string_file.string());
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
EXPECT_EQ(1, string_file.Read(&c, 1));
EXPECT_EQ('b', c);
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(0, string_file.Read(&c, 1));
EXPECT_EQ('b', c);
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ("b", string_file.string());
EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
EXPECT_TRUE(string_file.Write("\0", 1));
EXPECT_EQ(1u, string_file.string().size());
EXPECT_EQ('\0', string_file.string()[0]);
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(1u, string_file.string().size());
EXPECT_EQ('\0', string_file.string()[0]);
}
TEST(StringFile, SetString) {
char kString1[] = "Four score";
StringFile string_file;
string_file.SetString(kString1);
EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
char buf[5] = "****";
EXPECT_EQ(4, string_file.Read(buf, 4));
EXPECT_STREQ("Four", buf);
EXPECT_EQ(4, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(static_cast<FileOffset>(strlen(kString1)),
string_file.Seek(0, SEEK_END));
EXPECT_EQ(kString1, string_file.string());
char kString2[] = "and seven years ago";
EXPECT_EQ(4, string_file.Seek(4, SEEK_SET));
EXPECT_EQ(4, string_file.Seek(0, SEEK_CUR));
string_file.SetString(kString2);
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(4, string_file.Read(buf, 4));
EXPECT_STREQ("and ", buf);
EXPECT_EQ(static_cast<FileOffset>(strlen(kString2)),
string_file.Seek(0, SEEK_END));
EXPECT_EQ(kString2, string_file.string());
char kString3[] = "our fathers";
EXPECT_EQ(4, string_file.Seek(4, SEEK_SET));
EXPECT_EQ(4, string_file.Seek(0, SEEK_CUR));
string_file.SetString(kString3);
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(4, string_file.Read(buf, 4));
EXPECT_STREQ("our ", buf);
EXPECT_EQ(static_cast<FileOffset>(strlen(kString3)),
string_file.Seek(0, SEEK_END));
EXPECT_EQ(kString3, string_file.string());
}
TEST(StringFile, Reset) {
StringFile string_file;
EXPECT_TRUE(string_file.Write("abc", 3));
EXPECT_EQ(3u, string_file.string().size());
EXPECT_EQ("abc", string_file.string());
EXPECT_EQ(3, string_file.Seek(0, SEEK_CUR));
char buf[10] = "*********";
EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
EXPECT_EQ(3, string_file.Read(&buf, 10));
EXPECT_STREQ("abc******", buf);
EXPECT_EQ(3, string_file.Seek(0, SEEK_CUR));
EXPECT_FALSE(string_file.string().empty());
string_file.Reset();
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.Write("de", 2));
EXPECT_EQ(2u, string_file.string().size());
EXPECT_EQ("de", string_file.string());
EXPECT_EQ(2, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
EXPECT_EQ(2, string_file.Read(&buf, 10));
EXPECT_STREQ("dec******", buf);
EXPECT_EQ(2, string_file.Seek(0, SEEK_CUR));
EXPECT_FALSE(string_file.string().empty());
string_file.Reset();
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.Write("fghi", 4));
EXPECT_EQ(4u, string_file.string().size());
EXPECT_EQ("fghi", string_file.string());
EXPECT_EQ(4, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
EXPECT_EQ(2, string_file.Read(&buf, 2));
EXPECT_STREQ("fgc******", buf);
EXPECT_EQ(2, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(2, string_file.Read(&buf, 2));
EXPECT_STREQ("hic******", buf);
EXPECT_EQ(4, string_file.Seek(0, SEEK_CUR));
EXPECT_FALSE(string_file.string().empty());
string_file.Reset();
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
// Test resetting after a sparse write.
EXPECT_EQ(1, string_file.Seek(1, SEEK_SET));
EXPECT_TRUE(string_file.Write("j", 1));
EXPECT_EQ(2u, string_file.string().size());
EXPECT_EQ(std::string("\0j", 2), string_file.string());
EXPECT_EQ(2, string_file.Seek(0, SEEK_CUR));
EXPECT_FALSE(string_file.string().empty());
string_file.Reset();
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
}
TEST(StringFile, WriteInvalid) {
StringFile string_file;
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
EXPECT_FALSE(string_file.Write(
"", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()) + 1));
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.Write("a", 1));
EXPECT_FALSE(string_file.Write(
"", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max())));
EXPECT_EQ(1u, string_file.string().size());
EXPECT_EQ("a", string_file.string());
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
}
TEST(StringFile, WriteIoVec) {
StringFile string_file;
std::vector<WritableIoVec> iovecs;
WritableIoVec iov;
iov.iov_base = "";
iov.iov_len = 0;
iovecs.push_back(iov);
EXPECT_TRUE(string_file.WriteIoVec(&iovecs));
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
iovecs.clear();
iov.iov_base = "a";
iov.iov_len = 1;
iovecs.push_back(iov);
EXPECT_TRUE(string_file.WriteIoVec(&iovecs));
EXPECT_EQ(1u, string_file.string().size());
EXPECT_EQ("a", string_file.string());
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
iovecs.clear();
iovecs.push_back(iov);
EXPECT_TRUE(string_file.WriteIoVec(&iovecs));
EXPECT_EQ(2u, string_file.string().size());
EXPECT_EQ("aa", string_file.string());
EXPECT_EQ(2, string_file.Seek(0, SEEK_CUR));
iovecs.clear();
iovecs.push_back(iov);
iov.iov_base = "bc";
iov.iov_len = 2;
iovecs.push_back(iov);
EXPECT_TRUE(string_file.WriteIoVec(&iovecs));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ("aaabc", string_file.string());
EXPECT_EQ(5, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.Write("def", 3));
EXPECT_EQ(8u, string_file.string().size());
EXPECT_EQ("aaabcdef", string_file.string());
EXPECT_EQ(8, string_file.Seek(0, SEEK_CUR));
iovecs.clear();
iov.iov_base = "ghij";
iov.iov_len = 4;
iovecs.push_back(iov);
iov.iov_base = "klmno";
iov.iov_len = 5;
iovecs.push_back(iov);
EXPECT_TRUE(string_file.WriteIoVec(&iovecs));
EXPECT_EQ(17u, string_file.string().size());
EXPECT_EQ("aaabcdefghijklmno", string_file.string());
EXPECT_EQ(17, string_file.Seek(0, SEEK_CUR));
string_file.Reset();
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
iovecs.clear();
iov.iov_base = "abcd";
iov.iov_len = 4;
iovecs.resize(16, iov);
EXPECT_TRUE(string_file.WriteIoVec(&iovecs));
EXPECT_EQ(64u, string_file.string().size());
EXPECT_EQ("abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd",
string_file.string());
EXPECT_EQ(64, string_file.Seek(0, SEEK_CUR));
}
TEST(StringFile, WriteIoVecInvalid) {
StringFile string_file;
std::vector<WritableIoVec> iovecs;
EXPECT_FALSE(string_file.WriteIoVec(&iovecs));
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
WritableIoVec iov;
EXPECT_EQ(1, string_file.Seek(1, SEEK_CUR));
iov.iov_base = "a";
iov.iov_len = std::numeric_limits<ssize_t>::max();
iovecs.push_back(iov);
EXPECT_FALSE(string_file.WriteIoVec(&iovecs));
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
iovecs.clear();
iov.iov_base = "a";
iov.iov_len = 1;
iovecs.push_back(iov);
iov.iov_len = std::numeric_limits<ssize_t>::max() - 1;
iovecs.push_back(iov);
EXPECT_FALSE(string_file.WriteIoVec(&iovecs));
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
}
TEST(StringFile, Seek) {
StringFile string_file;
EXPECT_TRUE(string_file.Write("abcd", 4));
EXPECT_EQ(4u, string_file.string().size());
EXPECT_EQ("abcd", string_file.string());
EXPECT_EQ(4, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
EXPECT_TRUE(string_file.Write("efgh", 4));
EXPECT_EQ(4u, string_file.string().size());
EXPECT_EQ("efgh", string_file.string());
EXPECT_EQ(4, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
EXPECT_TRUE(string_file.Write("ijk", 3));
EXPECT_EQ(4u, string_file.string().size());
EXPECT_EQ("ijkh", string_file.string());
EXPECT_EQ(3, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
EXPECT_TRUE(string_file.Write("lmnop", 5));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ("lmnop", string_file.string());
EXPECT_EQ(5, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(1, string_file.Seek(1, SEEK_SET));
EXPECT_TRUE(string_file.Write("q", 1));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ("lqnop", string_file.string());
EXPECT_EQ(2, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(1, string_file.Seek(-1, SEEK_CUR));
EXPECT_TRUE(string_file.Write("r", 1));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ("lrnop", string_file.string());
EXPECT_EQ(2, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.Write("s", 1));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ("lrsop", string_file.string());
EXPECT_EQ(3, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(2, string_file.Seek(-1, SEEK_CUR));
EXPECT_TRUE(string_file.Write("t", 1));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ("lrtop", string_file.string());
EXPECT_EQ(3, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(4, string_file.Seek(-1, SEEK_END));
EXPECT_TRUE(string_file.Write("u", 1));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ("lrtou", string_file.string());
EXPECT_EQ(5, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(0, string_file.Seek(-5, SEEK_END));
EXPECT_TRUE(string_file.Write("v", 1));
EXPECT_EQ(5u, string_file.string().size());
EXPECT_EQ("vrtou", string_file.string());
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(5, string_file.Seek(0, SEEK_END));
EXPECT_TRUE(string_file.Write("w", 1));
EXPECT_EQ(6u, string_file.string().size());
EXPECT_EQ("vrtouw", string_file.string());
EXPECT_EQ(6, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(8, string_file.Seek(2, SEEK_END));
EXPECT_EQ(6u, string_file.string().size());
EXPECT_EQ("vrtouw", string_file.string());
EXPECT_EQ(6, string_file.Seek(0, SEEK_END));
EXPECT_TRUE(string_file.Write("x", 1));
EXPECT_EQ(7u, string_file.string().size());
EXPECT_EQ("vrtouwx", string_file.string());
EXPECT_EQ(7, string_file.Seek(0, SEEK_CUR));
}
TEST(StringFile, SeekSparse) {
StringFile string_file;
EXPECT_EQ(3, string_file.Seek(3, SEEK_SET));
EXPECT_TRUE(string_file.string().empty());
EXPECT_EQ(3, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.Write("abc", 3));
EXPECT_EQ(6u, string_file.string().size());
EXPECT_EQ(std::string("\0\0\0abc", 6), string_file.string());
EXPECT_EQ(6, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(9, string_file.Seek(3, SEEK_END));
EXPECT_EQ(6u, string_file.string().size());
EXPECT_EQ(9, string_file.Seek(0, SEEK_CUR));
char c;
EXPECT_EQ(0, string_file.Read(&c, 1));
EXPECT_EQ(9, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(6u, string_file.string().size());
EXPECT_TRUE(string_file.Write("def", 3));
EXPECT_EQ(12u, string_file.string().size());
EXPECT_EQ(std::string("\0\0\0abc\0\0\0def", 12), string_file.string());
EXPECT_EQ(12, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(7, string_file.Seek(-5, SEEK_END));
EXPECT_EQ(12u, string_file.string().size());
EXPECT_EQ(7, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.Write("g", 1));
EXPECT_EQ(12u, string_file.string().size());
EXPECT_EQ(std::string("\0\0\0abc\0g\0def", 12), string_file.string());
EXPECT_EQ(8, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(15, string_file.Seek(7, SEEK_CUR));
EXPECT_EQ(12u, string_file.string().size());
EXPECT_EQ(15, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.Write("hij", 3));
EXPECT_EQ(18u, string_file.string().size());
EXPECT_EQ(std::string("\0\0\0abc\0g\0def\0\0\0hij", 18),
string_file.string());
EXPECT_EQ(18, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(1, string_file.Seek(-17, SEEK_CUR));
EXPECT_EQ(18u, string_file.string().size());
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.Write("k", 1));
EXPECT_EQ(18u, string_file.string().size());
EXPECT_EQ(std::string("\0k\0abc\0g\0def\0\0\0hij", 18), string_file.string());
EXPECT_EQ(2, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.Write("l", 1));
EXPECT_TRUE(string_file.Write("mnop", 4));
EXPECT_EQ(18u, string_file.string().size());
EXPECT_EQ(std::string("\0klmnopg\0def\0\0\0hij", 18), string_file.string());
EXPECT_EQ(7, string_file.Seek(0, SEEK_CUR));
}
TEST(StringFile, SeekInvalid) {
StringFile string_file;
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
EXPECT_EQ(1, string_file.Seek(1, SEEK_SET));
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_LT(string_file.Seek(-1, SEEK_SET), 0);
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_LT(string_file.Seek(std::numeric_limits<ssize_t>::min(), SEEK_SET), 0);
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_LT(string_file.Seek(std::numeric_limits<FileOffset>::min(), SEEK_SET),
0);
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.string().empty());
static_assert(SEEK_SET != 3 && SEEK_CUR != 3 && SEEK_END != 3,
"3 must be invalid for whence");
EXPECT_LT(string_file.Seek(0, 3), 0);
string_file.Reset();
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
EXPECT_TRUE(string_file.string().empty());
const FileOffset kMaxOffset = static_cast<FileOffset>(
std::min(implicit_cast<uint64_t>(std::numeric_limits<FileOffset>::max()),
implicit_cast<uint64_t>(std::numeric_limits<size_t>::max())));
EXPECT_EQ(kMaxOffset, string_file.Seek(kMaxOffset, SEEK_SET));
EXPECT_EQ(kMaxOffset, string_file.Seek(0, SEEK_CUR));
EXPECT_LT(string_file.Seek(1, SEEK_CUR), 0);
EXPECT_EQ(1, string_file.Seek(1, SEEK_SET));
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
EXPECT_LT(string_file.Seek(kMaxOffset, SEEK_CUR), 0);
}
} // namespace
} // namespace test
} // namespace crashpad

View File

@ -1,380 +0,0 @@
// 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 "util/file/string_file_writer.h"
#include <algorithm>
#include <limits>
#include "gtest/gtest.h"
namespace crashpad {
namespace test {
namespace {
TEST(StringFileWriter, EmptyFile) {
StringFileWriter writer;
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("", 0));
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
}
TEST(StringFileWriter, OneByteFile) {
StringFileWriter writer;
EXPECT_TRUE(writer.Write("a", 1));
EXPECT_EQ(1u, writer.string().size());
EXPECT_EQ("a", writer.string());
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(0, writer.Seek(0, SEEK_SET));
EXPECT_TRUE(writer.Write("b", 1));
EXPECT_EQ(1u, writer.string().size());
EXPECT_EQ("b", writer.string());
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(0, writer.Seek(0, SEEK_SET));
EXPECT_TRUE(writer.Write("\0", 1));
EXPECT_EQ(1u, writer.string().size());
EXPECT_EQ('\0', writer.string()[0]);
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
}
TEST(StringFileWriter, Reset) {
StringFileWriter writer;
EXPECT_TRUE(writer.Write("abc", 3));
EXPECT_EQ(3u, writer.string().size());
EXPECT_EQ("abc", writer.string());
EXPECT_EQ(3, writer.Seek(0, SEEK_CUR));
writer.Reset();
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("de", 2));
EXPECT_EQ(2u, writer.string().size());
EXPECT_EQ("de", writer.string());
EXPECT_EQ(2, writer.Seek(0, SEEK_CUR));
writer.Reset();
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("fghi", 4));
EXPECT_EQ(4u, writer.string().size());
EXPECT_EQ("fghi", writer.string());
EXPECT_EQ(4, writer.Seek(0, SEEK_CUR));
writer.Reset();
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
// Test resetting after a sparse write.
EXPECT_EQ(1, writer.Seek(1, SEEK_SET));
EXPECT_TRUE(writer.Write("j", 1));
EXPECT_EQ(2u, writer.string().size());
EXPECT_EQ(std::string("\0j", 2), writer.string());
EXPECT_EQ(2, writer.Seek(0, SEEK_CUR));
writer.Reset();
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
}
TEST(StringFileWriter, WriteInvalid) {
StringFileWriter writer;
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
EXPECT_FALSE(writer.Write(
"", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()) + 1));
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("a", 1));
EXPECT_FALSE(writer.Write(
"", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max())));
EXPECT_EQ(1u, writer.string().size());
EXPECT_EQ("a", writer.string());
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
}
TEST(StringFileWriter, WriteIoVec) {
StringFileWriter writer;
std::vector<WritableIoVec> iovecs;
WritableIoVec iov;
iov.iov_base = "";
iov.iov_len = 0;
iovecs.push_back(iov);
EXPECT_TRUE(writer.WriteIoVec(&iovecs));
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
iovecs.clear();
iov.iov_base = "a";
iov.iov_len = 1;
iovecs.push_back(iov);
EXPECT_TRUE(writer.WriteIoVec(&iovecs));
EXPECT_EQ(1u, writer.string().size());
EXPECT_EQ("a", writer.string());
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
iovecs.clear();
iovecs.push_back(iov);
EXPECT_TRUE(writer.WriteIoVec(&iovecs));
EXPECT_EQ(2u, writer.string().size());
EXPECT_EQ("aa", writer.string());
EXPECT_EQ(2, writer.Seek(0, SEEK_CUR));
iovecs.clear();
iovecs.push_back(iov);
iov.iov_base = "bc";
iov.iov_len = 2;
iovecs.push_back(iov);
EXPECT_TRUE(writer.WriteIoVec(&iovecs));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ("aaabc", writer.string());
EXPECT_EQ(5, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("def", 3));
EXPECT_EQ(8u, writer.string().size());
EXPECT_EQ("aaabcdef", writer.string());
EXPECT_EQ(8, writer.Seek(0, SEEK_CUR));
iovecs.clear();
iov.iov_base = "ghij";
iov.iov_len = 4;
iovecs.push_back(iov);
iov.iov_base = "klmno";
iov.iov_len = 5;
iovecs.push_back(iov);
EXPECT_TRUE(writer.WriteIoVec(&iovecs));
EXPECT_EQ(17u, writer.string().size());
EXPECT_EQ("aaabcdefghijklmno", writer.string());
EXPECT_EQ(17, writer.Seek(0, SEEK_CUR));
writer.Reset();
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
iovecs.clear();
iov.iov_base = "abcd";
iov.iov_len = 4;
iovecs.resize(16, iov);
EXPECT_TRUE(writer.WriteIoVec(&iovecs));
EXPECT_EQ(64u, writer.string().size());
EXPECT_EQ("abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd",
writer.string());
EXPECT_EQ(64, writer.Seek(0, SEEK_CUR));
}
TEST(StringFileWriter, WriteIoVecInvalid) {
StringFileWriter writer;
std::vector<WritableIoVec> iovecs;
EXPECT_FALSE(writer.WriteIoVec(&iovecs));
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
WritableIoVec iov;
EXPECT_EQ(1, writer.Seek(1, SEEK_CUR));
iov.iov_base = "a";
iov.iov_len = std::numeric_limits<ssize_t>::max();
iovecs.push_back(iov);
EXPECT_FALSE(writer.WriteIoVec(&iovecs));
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
iovecs.clear();
iov.iov_base = "a";
iov.iov_len = 1;
iovecs.push_back(iov);
iov.iov_len = std::numeric_limits<ssize_t>::max() - 1;
iovecs.push_back(iov);
EXPECT_FALSE(writer.WriteIoVec(&iovecs));
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
}
TEST(StringFileWriter, Seek) {
StringFileWriter writer;
EXPECT_TRUE(writer.Write("abcd", 4));
EXPECT_EQ(4u, writer.string().size());
EXPECT_EQ("abcd", writer.string());
EXPECT_EQ(4, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(0, writer.Seek(0, SEEK_SET));
EXPECT_TRUE(writer.Write("efgh", 4));
EXPECT_EQ(4u, writer.string().size());
EXPECT_EQ("efgh", writer.string());
EXPECT_EQ(4, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(0, writer.Seek(0, SEEK_SET));
EXPECT_TRUE(writer.Write("ijk", 3));
EXPECT_EQ(4u, writer.string().size());
EXPECT_EQ("ijkh", writer.string());
EXPECT_EQ(3, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(0, writer.Seek(0, SEEK_SET));
EXPECT_TRUE(writer.Write("lmnop", 5));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ("lmnop", writer.string());
EXPECT_EQ(5, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(1, writer.Seek(1, SEEK_SET));
EXPECT_TRUE(writer.Write("q", 1));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ("lqnop", writer.string());
EXPECT_EQ(2, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(1, writer.Seek(-1, SEEK_CUR));
EXPECT_TRUE(writer.Write("r", 1));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ("lrnop", writer.string());
EXPECT_EQ(2, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("s", 1));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ("lrsop", writer.string());
EXPECT_EQ(3, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(2, writer.Seek(-1, SEEK_CUR));
EXPECT_TRUE(writer.Write("t", 1));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ("lrtop", writer.string());
EXPECT_EQ(3, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(4, writer.Seek(-1, SEEK_END));
EXPECT_TRUE(writer.Write("u", 1));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ("lrtou", writer.string());
EXPECT_EQ(5, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(0, writer.Seek(-5, SEEK_END));
EXPECT_TRUE(writer.Write("v", 1));
EXPECT_EQ(5u, writer.string().size());
EXPECT_EQ("vrtou", writer.string());
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(5, writer.Seek(0, SEEK_END));
EXPECT_TRUE(writer.Write("w", 1));
EXPECT_EQ(6u, writer.string().size());
EXPECT_EQ("vrtouw", writer.string());
EXPECT_EQ(6, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(8, writer.Seek(2, SEEK_END));
EXPECT_EQ(6u, writer.string().size());
EXPECT_EQ("vrtouw", writer.string());
EXPECT_EQ(6, writer.Seek(0, SEEK_END));
EXPECT_TRUE(writer.Write("x", 1));
EXPECT_EQ(7u, writer.string().size());
EXPECT_EQ("vrtouwx", writer.string());
EXPECT_EQ(7, writer.Seek(0, SEEK_CUR));
}
TEST(StringFileWriter, SeekSparse) {
StringFileWriter writer;
EXPECT_EQ(3, writer.Seek(3, SEEK_SET));
EXPECT_TRUE(writer.string().empty());
EXPECT_EQ(3, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("abc", 3));
EXPECT_EQ(6u, writer.string().size());
EXPECT_EQ(std::string("\0\0\0abc", 6), writer.string());
EXPECT_EQ(6, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(9, writer.Seek(3, SEEK_END));
EXPECT_EQ(6u, writer.string().size());
EXPECT_EQ(9, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("def", 3));
EXPECT_EQ(12u, writer.string().size());
EXPECT_EQ(std::string("\0\0\0abc\0\0\0def", 12), writer.string());
EXPECT_EQ(12, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(7, writer.Seek(-5, SEEK_END));
EXPECT_EQ(12u, writer.string().size());
EXPECT_EQ(7, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("g", 1));
EXPECT_EQ(12u, writer.string().size());
EXPECT_EQ(std::string("\0\0\0abc\0g\0def", 12), writer.string());
EXPECT_EQ(8, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(15, writer.Seek(7, SEEK_CUR));
EXPECT_EQ(12u, writer.string().size());
EXPECT_EQ(15, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("hij", 3));
EXPECT_EQ(18u, writer.string().size());
EXPECT_EQ(std::string("\0\0\0abc\0g\0def\0\0\0hij", 18), writer.string());
EXPECT_EQ(18, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(1, writer.Seek(-17, SEEK_CUR));
EXPECT_EQ(18u, writer.string().size());
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("k", 1));
EXPECT_EQ(18u, writer.string().size());
EXPECT_EQ(std::string("\0k\0abc\0g\0def\0\0\0hij", 18), writer.string());
EXPECT_EQ(2, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.Write("l", 1));
EXPECT_TRUE(writer.Write("mnop", 4));
EXPECT_EQ(18u, writer.string().size());
EXPECT_EQ(std::string("\0klmnopg\0def\0\0\0hij", 18), writer.string());
EXPECT_EQ(7, writer.Seek(0, SEEK_CUR));
}
TEST(StringFileWriter, SeekInvalid) {
StringFileWriter writer;
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
EXPECT_EQ(1, writer.Seek(1, SEEK_SET));
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
EXPECT_LT(writer.Seek(-1, SEEK_SET), 0);
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
EXPECT_LT(writer.Seek(std::numeric_limits<ssize_t>::min(), SEEK_SET), 0);
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
EXPECT_LT(writer.Seek(std::numeric_limits<FileOffset>::min(), SEEK_SET), 0);
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.string().empty());
static_assert(SEEK_SET != 3 && SEEK_CUR != 3 && SEEK_END != 3,
"3 must be invalid for whence");
EXPECT_LT(writer.Seek(0, 3), 0);
writer.Reset();
EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
EXPECT_TRUE(writer.string().empty());
const FileOffset kMaxOffset = static_cast<FileOffset>(
std::min(implicit_cast<uint64_t>(std::numeric_limits<FileOffset>::max()),
implicit_cast<uint64_t>(std::numeric_limits<size_t>::max())));
EXPECT_EQ(kMaxOffset, writer.Seek(kMaxOffset, SEEK_SET));
EXPECT_EQ(kMaxOffset, writer.Seek(0, SEEK_CUR));
EXPECT_LT(writer.Seek(1, SEEK_CUR), 0);
EXPECT_EQ(1, writer.Seek(1, SEEK_SET));
EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
EXPECT_LT(writer.Seek(kMaxOffset, SEEK_CUR), 0);
}
} // namespace
} // namespace test
} // namespace crashpad

View File

@ -30,10 +30,13 @@
'file/file_io.h',
'file/file_io_posix.cc',
'file/file_io_win.cc',
'file/file_reader.cc',
'file/file_reader.h',
'file/file_seeker.h',
'file/file_writer.cc',
'file/file_writer.h',
'file/string_file_writer.cc',
'file/string_file_writer.h',
'file/string_file.cc',
'file/string_file.h',
'mac/checked_mach_address_range.cc',
'mac/checked_mach_address_range.h',
'mac/launchd.h',
@ -258,7 +261,7 @@
'..',
],
'sources': [
'file/string_file_writer_test.cc',
'file/string_file_test.cc',
'mac/checked_mach_address_range_test.cc',
'mac/launchd_test.mm',
'mac/mac_util_test.mm',