mirror of
https://github.com/yuzu-emu/breakpad.git
synced 2024-11-28 08:24:17 +01:00
Breakpad unit tests: Add support for clipped-size null-terminated strings
to TestAssembler::Section. This patch helps the TestAssembler classes generate Mach-O object files for use as test input. This patch adds a new AppendCString overloading to TestAssembler::Section for emitting null-terminated strings in fixed-length buffers, where the string is truncated and the terminating null character omitted if the string is too large for the buffer. The patch includes unit tests for the new AppendCString overloading. It also provides some for the existing overloading, which had been neglected. a=jimblandy, r=mark git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@590 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
parent
52a508dfe2
commit
073a7f6695
@ -324,6 +324,15 @@ class Section {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Append at most SIZE bytes from DATA; if DATA is less than SIZE bytes
|
||||
// long, pad with '\0' characters.
|
||||
Section &AppendCString(const string &data, size_t size) {
|
||||
contents_.append(data, 0, size);
|
||||
if (data.size() < size)
|
||||
Append(size - data.size(), 0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Append VALUE or LABEL to this section, with the given bit width and
|
||||
// endianness. Return a reference to this section.
|
||||
//
|
||||
|
@ -788,6 +788,24 @@ TEST_F(Append, String) {
|
||||
ASSERT_STREQ(contents.c_str(), "howdy there");
|
||||
}
|
||||
|
||||
TEST_F(Append, CString) {
|
||||
section.AppendCString("howdy");
|
||||
section.AppendCString("");
|
||||
section.AppendCString("there");
|
||||
ASSERT_TRUE(section.GetContents(&contents));
|
||||
ASSERT_EQ(string("howdy\0\0there\0", 13), contents);
|
||||
}
|
||||
|
||||
TEST_F(Append, CStringSize) {
|
||||
section.AppendCString("howdy", 3);
|
||||
section.AppendCString("there", 5);
|
||||
section.AppendCString("fred", 6);
|
||||
section.AppendCString("natalie", 0);
|
||||
section.AppendCString("", 10);
|
||||
ASSERT_TRUE(section.GetContents(&contents));
|
||||
ASSERT_EQ(string("howtherefred\0\0\0\0\0\0\0\0\0\0\0\0", 24), contents);
|
||||
}
|
||||
|
||||
TEST_F(Append, RepeatedBytes) {
|
||||
section.Append((size_t) 10, '*');
|
||||
ASSERT_TRUE(section.GetContents(&contents));
|
||||
|
Loading…
Reference in New Issue
Block a user