Skip to content

Commit

Permalink
fixed window gtest
Browse files Browse the repository at this point in the history
  • Loading branch information
durkisneer1 committed Jan 22, 2024
1 parent 8520192 commit 05c9bc3
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 38 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,31 +174,31 @@ if (WIN32)
add_custom_command(
TARGET ${TESTING}
COMMENT "Copy gtest dlls"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/bld/bin/libgtest.dll ${CMAKE_SOURCE_DIR}/bin/
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bin/libgtest.dll ${CMAKE_SOURCE_DIR}/bin/
VERBATIM
)
endif()
if (WIN32)
add_custom_command(
TARGET ${TESTING}
COMMENT "Copy gtest dlls"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/bld/bin/libgmock.dll ${CMAKE_SOURCE_DIR}/bin/
COMMENT "Copy gmock dlls"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bin/libgmock.dll ${CMAKE_SOURCE_DIR}/bin/
VERBATIM
)
endif()
if (WIN32)
add_custom_command(
TARGET ${TESTING}
COMMENT "Copy gtest dlls"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/bld/bin/libgtest_main.dll ${CMAKE_SOURCE_DIR}/bin/
COMMENT "Copy gtest_main dlls"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bin/libgtest_main.dll ${CMAKE_SOURCE_DIR}/bin/
VERBATIM
)
endif()
if (WIN32)
add_custom_command(
TARGET ${TESTING}
COMMENT "Copy gtest dlls"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/bld/bin/libgmock_main.dll ${CMAKE_SOURCE_DIR}/bin/
COMMENT "Copy gmock_main dlls"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bin/libgmock_main.dll ${CMAKE_SOURCE_DIR}/bin/
VERBATIM
)
endif()
Expand Down
7 changes: 7 additions & 0 deletions include/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ math::Vec2 getSize();
*/
void setTitle(const std::string& newTitle);

/**
* @brief Get the title of the window.
*
* @return The title of the window.
*/
std::string getTitle();

/**
* @brief Set whether the window is fullscreen or not.
*
Expand Down
22 changes: 22 additions & 0 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void quit()
SDL_DestroyRenderer(_renderer);
if (_window)
SDL_DestroyWindow(_window);
_events.clear();
_event = Event();
Mix_CloseAudio();
IMG_Quit();
TTF_Quit();
Expand Down Expand Up @@ -210,9 +212,29 @@ void setTitle(const std::string& newTitle)
if (!_window)
WARN("Cannot set title before creating the window");

if (newTitle.empty())
{
WARN("Cannot set title to empty string");
return;
}

if (newTitle.size() > 255)
{
WARN("Cannot set title to string longer than 255 characters");
return;
}

SDL_SetWindowTitle(_window, newTitle.c_str());
}

std::string getTitle()
{
if (!_window)
WARN("Cannot get title before creating the window");

return std::string(SDL_GetWindowTitle(_window));
}

void setFullscreen(bool fullscreen)
{
if (!_window)
Expand Down
1 change: 1 addition & 0 deletions test/test_Overflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace
{

using kn::float32_t;
using kn::float64_t;
using kn::overflow::isProductValid;
Expand Down
31 changes: 0 additions & 31 deletions test/test_RenderWindow.cpp

This file was deleted.

43 changes: 43 additions & 0 deletions test/test_Window.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <string>

#include "gtest/gtest.h"

#include "ErrorLogger.hpp"
#include "Window.hpp"

namespace
{

class WindowTest : public ::testing::Test
{
protected:
WindowTest() : m_size(320, 240), m_scale(2) {}

virtual ~WindowTest() {}

virtual void SetUp() { kn::window::init(m_size, m_scale); }

virtual void TearDown() { kn::window::quit(); }

kn::math::Vec2 m_size;
int m_scale;
};

TEST_F(WindowTest, WindowInit)
{
EXPECT_EQ(kn::window::getSize().x, m_size.x);
EXPECT_EQ(kn::window::getSize().y, m_size.y);
EXPECT_EQ(kn::window::getScale(), m_scale);
EXPECT_EQ(kn::window::getTitle(), std::string("Kraken Window"));
}

TEST_F(WindowTest, WindowFullscreen)
{
kn::window::setFullscreen(true);
EXPECT_EQ(kn::window::getFullscreen(), true);
kn::window::setFullscreen(false);
EXPECT_EQ(kn::window::getFullscreen(), false);
}

} // namespace

0 comments on commit 05c9bc3

Please sign in to comment.