Factored out HandlerTest as a base class

This commit is contained in:
Jesse Beder
2014-03-23 16:26:44 -05:00
parent 066b71a755
commit ebf14ec83a
3 changed files with 37 additions and 53 deletions

32
test/handler_test.h Normal file
View File

@@ -0,0 +1,32 @@
#include "mock_event_handler.h"
#include "yaml-cpp/yaml.h" // IWYU pragma: keep
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::InSequence;
using ::testing::NiceMock;
using ::testing::StrictMock;
namespace YAML {
class HandlerTest : public ::testing::Test {
protected:
void Parse(const std::string& example) {
std::stringstream stream(example);
Parser parser(stream);
while (parser.HandleNextDocument(handler)) {
}
}
void IgnoreParse(const std::string& example) {
std::stringstream stream(example);
Parser parser(stream);
while (parser.HandleNextDocument(nice_handler)) {
}
}
InSequence sequence;
StrictMock<MockEventHandler> handler;
NiceMock<MockEventHandler> nice_handler;
};
}

View File

@@ -1,15 +1,11 @@
#include "mock_event_handler.h"
#include "specexamples.h" // IWYU pragma: keep
#include "yaml-cpp/eventhandler.h"
#include "handler_test.h"
#include "specexamples.h" // IWYU pragma: keep
#include "yaml-cpp/yaml.h" // IWYU pragma: keep
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::_;
using ::testing::InSequence;
using ::testing::NiceMock;
using ::testing::StrictMock;
#define EXPECT_THROW_PARSER_EXCEPTION(statement, message) \
ASSERT_THROW(statement, ParserException); \
@@ -23,26 +19,7 @@ using ::testing::StrictMock;
namespace YAML {
namespace {
class HandlerSpecTest : public ::testing::Test {
protected:
void Parse(const std::string& example) {
std::stringstream stream(example);
Parser parser(stream);
while (parser.HandleNextDocument(handler)) {
}
}
void IgnoreParse(const std::string& example) {
std::stringstream stream(example);
Parser parser(stream);
while (parser.HandleNextDocument(nice_handler)) {
}
}
InSequence sequence;
StrictMock<MockEventHandler> handler;
NiceMock<MockEventHandler> nice_handler;
};
typedef HandlerTest HandlerSpecTest;
TEST_F(HandlerSpecTest, Ex2_1_SeqScalars) {
EXPECT_CALL(handler, OnDocumentStart(_));

View File

@@ -1,15 +1,11 @@
#include "mock_event_handler.h"
#include "specexamples.h" // IWYU pragma: keep
#include "yaml-cpp/eventhandler.h"
#include "handler_test.h"
#include "specexamples.h" // IWYU pragma: keep
#include "yaml-cpp/yaml.h" // IWYU pragma: keep
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::_;
using ::testing::InSequence;
using ::testing::NiceMock;
using ::testing::StrictMock;
#define EXPECT_THROW_PARSER_EXCEPTION(statement, message) \
ASSERT_THROW(statement, ParserException); \
@@ -23,27 +19,6 @@ using ::testing::StrictMock;
namespace YAML {
namespace {
class HandlerTest : public ::testing::Test {
protected:
void Parse(const std::string& example) {
std::stringstream stream(example);
Parser parser(stream);
while (parser.HandleNextDocument(handler)) {
}
}
void IgnoreParse(const std::string& example) {
std::stringstream stream(example);
Parser parser(stream);
while (parser.HandleNextDocument(nice_handler)) {
}
}
InSequence sequence;
StrictMock<MockEventHandler> handler;
NiceMock<MockEventHandler> nice_handler;
};
TEST_F(HandlerTest, NoEndOfMapFlow) {
EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse("---{header: {id: 1"),
ErrorMsg::END_OF_MAP_FLOW);