Breakpad STABS parser: Use a test fixture in StabsReader unit tests.
This patch factors out some of the common code in the StabsReader unit tests into a fixture class. Pretty mechanical. a=jimblandy, r=thestig git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@586 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
parent
deb500f6c8
commit
d3e4bbb9c7
1 changed files with 41 additions and 55 deletions
|
@ -51,6 +51,7 @@ using ::testing::Eq;
|
||||||
using ::testing::InSequence;
|
using ::testing::InSequence;
|
||||||
using ::testing::Return;
|
using ::testing::Return;
|
||||||
using ::testing::StrEq;
|
using ::testing::StrEq;
|
||||||
|
using ::testing::Test;
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
using google_breakpad::StabsHandler;
|
using google_breakpad::StabsHandler;
|
||||||
using google_breakpad::StabsReader;
|
using google_breakpad::StabsReader;
|
||||||
|
@ -223,32 +224,38 @@ class MockStabsReaderHandler: public StabsHandler {
|
||||||
MOCK_METHOD1(MockWarning, void(const char *));
|
MOCK_METHOD1(MockWarning, void(const char *));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a StabsReader to parse the mock stabs data in STABS_ASSEMBLER and
|
struct StabsFixture {
|
||||||
// STRINGS_ASSEMBLER, and pass the parsed information to HANDLER. Use the
|
StabsFixture() : stabs(&strings) { }
|
||||||
// endianness and value size of STABS_ASSEMBLER to parse the data. If all
|
|
||||||
// goes well, return the result of calling the reader's Process member
|
|
||||||
// function. Otherwise, return false.
|
|
||||||
static bool ApplyHandlerToMockStabsData(StabsAssembler *stabs_assembler,
|
|
||||||
StringAssembler *strings_assembler,
|
|
||||||
StabsHandler *handler) {
|
|
||||||
string stab, stabstr;
|
|
||||||
if (!stabs_assembler->GetContents(&stab) ||
|
|
||||||
!strings_assembler->GetContents(&stabstr))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Run the parser on the test input, passing whatever we find to HANDLER.
|
// Create a StabsReader to parse the mock stabs data in stabs and
|
||||||
StabsReader reader(
|
// strings, and pass the parsed information to mock_handler. Use the
|
||||||
reinterpret_cast<const uint8_t *>(stab.data()), stab.size(),
|
// endianness and value size of stabs to parse the data. If all goes
|
||||||
reinterpret_cast<const uint8_t *>(stabstr.data()), stabstr.size(),
|
// well, return the result of calling the reader's Process member
|
||||||
stabs_assembler->endianness() == kBigEndian,
|
// function. Otherwise, return false.
|
||||||
stabs_assembler->value_size(),
|
bool ApplyHandlerToMockStabsData() {
|
||||||
handler);
|
string stabs_contents, stabstr_contents;
|
||||||
return reader.Process();
|
if (!stabs.GetContents(&stabs_contents) ||
|
||||||
}
|
!strings.GetContents(&stabstr_contents))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Run the parser on the test input, passing whatever we find to HANDLER.
|
||||||
|
StabsReader reader(
|
||||||
|
reinterpret_cast<const uint8_t *>(stabs_contents.data()),
|
||||||
|
stabs_contents.size(),
|
||||||
|
reinterpret_cast<const uint8_t *>(stabstr_contents.data()),
|
||||||
|
stabstr_contents.size(),
|
||||||
|
stabs.endianness() == kBigEndian, stabs.value_size(), &mock_handler);
|
||||||
|
return reader.Process();
|
||||||
|
}
|
||||||
|
|
||||||
TEST(StabsReader, MockStabsInput) {
|
|
||||||
StringAssembler strings;
|
StringAssembler strings;
|
||||||
StabsAssembler stabs(&strings);
|
StabsAssembler stabs;
|
||||||
|
MockStabsReaderHandler mock_handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Stabs: public StabsFixture, public Test { };
|
||||||
|
|
||||||
|
TEST_F(Stabs, MockStabsInput) {
|
||||||
stabs.set_endianness(kLittleEndian);
|
stabs.set_endianness(kLittleEndian);
|
||||||
stabs.set_value_size(4);
|
stabs.set_value_size(4);
|
||||||
stabs
|
stabs
|
||||||
|
@ -275,8 +282,6 @@ TEST(StabsReader, MockStabsInput) {
|
||||||
.Stab(N_SO, 152, 7810, 0x11759f10U, "file3.c")
|
.Stab(N_SO, 152, 7810, 0x11759f10U, "file3.c")
|
||||||
.Stab(N_SO, 218, 12447, 0x11cfe4b5U, "");
|
.Stab(N_SO, 218, 12447, 0x11cfe4b5U, "");
|
||||||
|
|
||||||
MockStabsReaderHandler mock_handler;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
InSequence s;
|
InSequence s;
|
||||||
|
|
||||||
|
@ -313,18 +318,14 @@ TEST(StabsReader, MockStabsInput) {
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_TRUE(ApplyHandlerToMockStabsData(&stabs, &strings, &mock_handler));
|
ASSERT_TRUE(ApplyHandlerToMockStabsData());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StabsReader, AbruptCU) {
|
TEST_F(Stabs, AbruptCU) {
|
||||||
StringAssembler strings;
|
|
||||||
StabsAssembler stabs(&strings);
|
|
||||||
stabs.set_endianness(kBigEndian);
|
stabs.set_endianness(kBigEndian);
|
||||||
stabs.set_value_size(4);
|
stabs.set_value_size(4);
|
||||||
stabs.Stab(N_SO, 177, 23446, 0xbf10d5e4, "file2-1.c");
|
stabs.Stab(N_SO, 177, 23446, 0xbf10d5e4, "file2-1.c");
|
||||||
|
|
||||||
MockStabsReaderHandler mock_handler;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
InSequence s;
|
InSequence s;
|
||||||
|
|
||||||
|
@ -335,13 +336,10 @@ TEST(StabsReader, AbruptCU) {
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_TRUE(ApplyHandlerToMockStabsData(&stabs, &strings, &mock_handler));
|
ASSERT_TRUE(ApplyHandlerToMockStabsData());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StabsReader, AbruptFunction) {
|
TEST_F(Stabs, AbruptFunction) {
|
||||||
MockStabsReaderHandler mock_handler;
|
|
||||||
StringAssembler strings;
|
|
||||||
StabsAssembler stabs(&strings);
|
|
||||||
stabs.set_endianness(kLittleEndian);
|
stabs.set_endianness(kLittleEndian);
|
||||||
stabs.set_value_size(8);
|
stabs.set_value_size(8);
|
||||||
stabs
|
stabs
|
||||||
|
@ -362,37 +360,29 @@ TEST(StabsReader, AbruptFunction) {
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_TRUE(ApplyHandlerToMockStabsData(&stabs, &strings, &mock_handler));
|
ASSERT_TRUE(ApplyHandlerToMockStabsData());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StabsReader, NoCU) {
|
TEST_F(Stabs, NoCU) {
|
||||||
StringAssembler strings;
|
|
||||||
StabsAssembler stabs(&strings);
|
|
||||||
stabs.set_endianness(kBigEndian);
|
stabs.set_endianness(kBigEndian);
|
||||||
stabs.set_value_size(8);
|
stabs.set_value_size(8);
|
||||||
stabs.Stab(N_SO, 161, 25673, 0x8f676e7bU, "build-directory/");
|
stabs.Stab(N_SO, 161, 25673, 0x8f676e7bU, "build-directory/");
|
||||||
|
|
||||||
MockStabsReaderHandler mock_handler;
|
|
||||||
|
|
||||||
EXPECT_CALL(mock_handler, StartCompilationUnit(_, _, _))
|
EXPECT_CALL(mock_handler, StartCompilationUnit(_, _, _))
|
||||||
.Times(0);
|
.Times(0);
|
||||||
EXPECT_CALL(mock_handler, StartFunction(_, _))
|
EXPECT_CALL(mock_handler, StartFunction(_, _))
|
||||||
.Times(0);
|
.Times(0);
|
||||||
|
|
||||||
ASSERT_TRUE(ApplyHandlerToMockStabsData(&stabs, &strings, &mock_handler));
|
ASSERT_TRUE(ApplyHandlerToMockStabsData());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StabsReader, NoCUEnd) {
|
TEST_F(Stabs, NoCUEnd) {
|
||||||
StringAssembler strings;
|
|
||||||
StabsAssembler stabs(&strings);
|
|
||||||
stabs.set_endianness(kBigEndian);
|
stabs.set_endianness(kBigEndian);
|
||||||
stabs.set_value_size(8);
|
stabs.set_value_size(8);
|
||||||
stabs
|
stabs
|
||||||
.Stab(N_SO, 116, 58280, 0x2f7493c9U, "file5-1.c")
|
.Stab(N_SO, 116, 58280, 0x2f7493c9U, "file5-1.c")
|
||||||
.Stab(N_SO, 224, 23057, 0xf9f1d50fU, "file5-2.c");
|
.Stab(N_SO, 224, 23057, 0xf9f1d50fU, "file5-2.c");
|
||||||
|
|
||||||
MockStabsReaderHandler mock_handler;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
InSequence s;
|
InSequence s;
|
||||||
|
|
||||||
|
@ -408,12 +398,10 @@ TEST(StabsReader, NoCUEnd) {
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_TRUE(ApplyHandlerToMockStabsData(&stabs, &strings, &mock_handler));
|
ASSERT_TRUE(ApplyHandlerToMockStabsData());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StabsReader, MultipleCUs) {
|
TEST_F(Stabs, MultipleCUs) {
|
||||||
StringAssembler strings;
|
|
||||||
StabsAssembler stabs(&strings);
|
|
||||||
stabs.set_endianness(kBigEndian);
|
stabs.set_endianness(kBigEndian);
|
||||||
stabs.set_value_size(4);
|
stabs.set_value_size(4);
|
||||||
stabs
|
stabs
|
||||||
|
@ -428,8 +416,6 @@ TEST(StabsReader, MultipleCUs) {
|
||||||
.Stab(N_SO, 178, 56949, 0xbffff983U, "")
|
.Stab(N_SO, 178, 56949, 0xbffff983U, "")
|
||||||
.EndCU();
|
.EndCU();
|
||||||
|
|
||||||
MockStabsReaderHandler mock_handler;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
InSequence s;
|
InSequence s;
|
||||||
EXPECT_CALL(mock_handler,
|
EXPECT_CALL(mock_handler,
|
||||||
|
@ -452,7 +438,7 @@ TEST(StabsReader, MultipleCUs) {
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_TRUE(ApplyHandlerToMockStabsData(&stabs, &strings, &mock_handler));
|
ASSERT_TRUE(ApplyHandlerToMockStabsData());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Stabs, FunctionEnd) {
|
TEST_F(Stabs, FunctionEnd) {
|
||||||
|
|
Loading…
Reference in a new issue