/* * author: Patrick-Christopher Mattulat * e-mail: webmaster@lynarstudios.com */ #include #include #include #include #include #include #include #include using ls::atlantis::glossary::StatusCodes; using ls::atlantis::interfaces::AStatusCode; using ls::atlantis::interfaces::ISdlApi; using ls::atlantis::window::SdlWindowApi; using ls::atlantis::window::test::SdlApiMock; using ls::std::core::IllegalArgumentException; using ::std::make_shared; using ::std::shared_ptr; using ::std::string; using ::testing::Return; using ::testing::StrEq; using ::testing::Test; namespace { class SdlWindowApiTest : public Test { public: SdlWindowApiTest() = default; ~SdlWindowApiTest() override = default; shared_ptr sdlApiMock = make_shared(); }; TEST_F(SdlWindowApiTest, constructor_nullPointer) { ASSERT_THROW(SdlWindowApi(nullptr), IllegalArgumentException); } TEST_F(SdlWindowApiTest, init) { int dummyWindowHandle = 0; auto *fakeWindow = static_cast(static_cast(&dummyWindowHandle)); EXPECT_CALL(*sdlApiMock, Init(SDL_INIT_VIDEO)).WillOnce(Return(1)); EXPECT_CALL(*sdlApiMock, CreateWindow(StrEq(""), 0, 0, SDL_WINDOW_FULLSCREEN)).WillOnce(Return(fakeWindow)); EXPECT_CALL(*sdlApiMock, DestroyWindow(fakeWindow)); EXPECT_CALL(*sdlApiMock, Quit()); ASSERT_EQ(StatusCodes::OK, SdlWindowApi(sdlApiMock).init()->getCode()); } TEST_F(SdlWindowApiTest, init_failed) { const string hint = "Upsi Dupsi"; EXPECT_CALL(*sdlApiMock, Init(SDL_INIT_VIDEO)).WillOnce(Return(0)); EXPECT_CALL(*sdlApiMock, GetError()).WillOnce(Return(hint.c_str())); EXPECT_CALL(*sdlApiMock, Quit()); const shared_ptr statusCode = SdlWindowApi(sdlApiMock).init(); ASSERT_EQ(StatusCodes::WINDOW_API_LOADING_FAILED, statusCode->getCode()); ASSERT_EQ(1, statusCode->getHints().size()); ASSERT_STREQ(hint.c_str(), statusCode->getHints()[0].c_str()); } TEST_F(SdlWindowApiTest, init_windowCreationFailed) { const string hint = "Upsi Dupsi"; EXPECT_CALL(*sdlApiMock, Init(SDL_INIT_VIDEO)).WillOnce(Return(1)); EXPECT_CALL(*sdlApiMock, CreateWindow(StrEq(""), 0, 0, SDL_WINDOW_FULLSCREEN)).WillOnce(Return(nullptr)); EXPECT_CALL(*sdlApiMock, GetError()).WillOnce(Return(hint.c_str())); EXPECT_CALL(*sdlApiMock, Quit()); const shared_ptr statusCode = SdlWindowApi(sdlApiMock).init(); ASSERT_EQ(StatusCodes::WINDOW_CREATION_FAILED, statusCode->getCode()); ASSERT_EQ(1, statusCode->getHints().size()); ASSERT_STREQ(hint.c_str(), statusCode->getHints()[0].c_str()); } }