diff --git a/test/handler_test.h b/test/handler_test.h new file mode 100644 index 0000000..668a58d --- /dev/null +++ b/test/handler_test.h @@ -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 handler; + NiceMock nice_handler; +}; +} diff --git a/test/integration/handler_spec_test.cpp b/test/integration/handler_spec_test.cpp index 55d3966..3567cf7 100644 --- a/test/integration/handler_spec_test.cpp +++ b/test/integration/handler_spec_test.cpp @@ -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 handler; - NiceMock nice_handler; -}; +typedef HandlerTest HandlerSpecTest; TEST_F(HandlerSpecTest, Ex2_1_SeqScalars) { EXPECT_CALL(handler, OnDocumentStart(_)); diff --git a/test/integration/handler_test.cpp b/test/integration/handler_test.cpp index 6a13e68..680e695 100644 --- a/test/integration/handler_test.cpp +++ b/test/integration/handler_test.cpp @@ -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 handler; - NiceMock nice_handler; -}; - TEST_F(HandlerTest, NoEndOfMapFlow) { EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse("---{header: {id: 1"), ErrorMsg::END_OF_MAP_FLOW);