aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-06 19:58:15 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-06 19:58:15 +0100
commit9c1fb8b2253149d4a15a94b7ee576a0f9e791033 (patch)
tree666955b4308e2d59f6958119f3efbcbf179c493d /src/test
parente8d9e38b4c265e0efde32c38d01b511cb572a34d (diff)
parent75ca0750dcc07b6ca043320397917e33638e97b4 (diff)
Merge branch 'niels/decoupling_pixel_and_pos' of github.com:lonkaars/crepe
Diffstat (limited to 'src/test')
-rw-r--r--src/test/InputTest.cpp32
-rw-r--r--src/test/RenderSystemTest.cpp21
2 files changed, 25 insertions, 28 deletions
diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp
index cb9833f..a7c0157 100644
--- a/src/test/InputTest.cpp
+++ b/src/test/InputTest.cpp
@@ -60,8 +60,8 @@ protected:
TEST_F(InputTest, MouseDown) {
GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1);
- auto & camera = obj.add_component<Camera>(Color::BLACK, ivec2{0, 0}, vec2{500, 500}, 0.0,
- vec2{0, 0});
+ auto & camera = obj.add_component<Camera>(
+ ivec2{100, 100}, vec2{100, 100}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
camera.active = true;
bool mouse_triggered = false;
EventHandler<MousePressEvent> on_mouse_down = [&](const MousePressEvent & event) {
@@ -90,8 +90,8 @@ TEST_F(InputTest, MouseDown) {
TEST_F(InputTest, MouseUp) {
GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1);
- auto & camera = obj.add_component<Camera>(Color::BLACK, ivec2{0, 0}, vec2{500, 500}, 0.0,
- vec2{0, 0});
+ auto & camera = obj.add_component<Camera>(
+ ivec2{100, 100}, vec2{100, 100}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
camera.active = true;
bool function_triggered = false;
EventHandler<MouseReleaseEvent> on_mouse_release = [&](const MouseReleaseEvent & e) {
@@ -118,8 +118,8 @@ TEST_F(InputTest, MouseUp) {
TEST_F(InputTest, MouseMove) {
GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1);
- auto & camera = obj.add_component<Camera>(Color::BLACK, ivec2{0, 0}, vec2{500, 500}, 0.0,
- vec2{0, 0});
+ auto & camera = obj.add_component<Camera>(
+ ivec2{100, 100}, vec2{100, 100}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
camera.active = true;
bool function_triggered = false;
EventHandler<MouseMoveEvent> on_mouse_move = [&](const MouseMoveEvent & e) {
@@ -148,8 +148,8 @@ TEST_F(InputTest, MouseMove) {
TEST_F(InputTest, KeyDown) {
GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1);
- auto & camera = obj.add_component<Camera>(Color::BLACK, ivec2{0, 0}, vec2{500, 500}, 0.0,
- vec2{0, 0});
+ auto & camera = obj.add_component<Camera>(
+ ivec2{100, 100}, vec2{100, 100}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
camera.active = true;
bool function_triggered = false;
@@ -179,8 +179,8 @@ TEST_F(InputTest, KeyDown) {
TEST_F(InputTest, KeyUp) {
GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1);
- auto & camera = obj.add_component<Camera>(Color::BLACK, ivec2{0, 0}, vec2{500, 500}, 0.0,
- vec2{0, 0});
+ auto & camera = obj.add_component<Camera>(
+ ivec2{100, 100}, vec2{100, 100}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
camera.active = true;
bool function_triggered = false;
EventHandler<KeyReleaseEvent> on_key_release = [&](const KeyReleaseEvent & event) {
@@ -203,8 +203,8 @@ TEST_F(InputTest, KeyUp) {
TEST_F(InputTest, MouseClick) {
GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1);
- auto & camera = obj.add_component<Camera>(Color::BLACK, ivec2{0, 0}, vec2{500, 500}, 0.0,
- vec2{0, 0});
+ auto & camera = obj.add_component<Camera>(
+ ivec2{100, 100}, vec2{100, 100}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
camera.active = true;
bool on_click_triggered = false;
EventHandler<MouseClickEvent> on_mouse_click = [&](const MouseClickEvent & event) {
@@ -224,8 +224,8 @@ TEST_F(InputTest, MouseClick) {
TEST_F(InputTest, testButtonClick) {
GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1);
- auto & camera = obj.add_component<Camera>(Color::BLACK, ivec2{0, 0}, vec2{500, 500}, 0.0,
- vec2{0, 0});
+ auto & camera = obj.add_component<Camera>(
+ ivec2{100, 100}, vec2{100, 100}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
camera.active = true;
GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
bool button_clicked = false;
@@ -251,8 +251,8 @@ TEST_F(InputTest, testButtonClick) {
TEST_F(InputTest, testButtonHover) {
GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1);
- auto & camera = obj.add_component<Camera>(Color::BLACK, ivec2{0, 0}, vec2{500, 500}, 0.0,
- vec2{0, 0});
+ auto & camera = obj.add_component<Camera>(
+ ivec2{100, 100}, vec2{100, 100}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
camera.active = true;
GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
bool button_clicked = false;
diff --git a/src/test/RenderSystemTest.cpp b/src/test/RenderSystemTest.cpp
index 4868ddd..205f534 100644
--- a/src/test/RenderSystemTest.cpp
+++ b/src/test/RenderSystemTest.cpp
@@ -1,3 +1,4 @@
+#include "types.h"
#include <functional>
#include <gtest/gtest.h>
#include <memory>
@@ -141,10 +142,8 @@ TEST_F(RenderSystemTest, sorting_sprites) {
}
TEST_F(RenderSystemTest, Update) {
- entity1.add_component<Camera>(Camera::Data{.bg_color = Color::WHITE,
- .screen = ivec2{1080, 720},
- .viewport_size = vec2{2000, 2000},
- .zoom = 1.0f});
+ entity1.add_component<Camera>(ivec2{100, 100}, vec2{100, 100},
+ Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
{
vector<reference_wrapper<Sprite>> sprites = this->mgr.get_components_by_type<Sprite>();
ASSERT_EQ(sprites.size(), 4);
@@ -172,10 +171,9 @@ TEST_F(RenderSystemTest, Camera) {
EXPECT_NE(cameras.size(), 1);
}
{
- entity1.add_component<Camera>(Camera::Data{.bg_color = Color::WHITE,
- .screen = ivec2{1080, 720},
- .viewport_size = vec2{2000, 2000},
- .zoom = 1.0f});
+ entity1.add_component<Camera>(ivec2{100, 100}, vec2{100, 100},
+ Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
+
auto cameras = this->mgr.get_components_by_type<Camera>();
EXPECT_EQ(cameras.size(), 1);
}
@@ -183,10 +181,9 @@ TEST_F(RenderSystemTest, Camera) {
//TODO improve with newer version
}
TEST_F(RenderSystemTest, Color) {
- entity1.add_component<Camera>(Camera::Data{.bg_color = Color::WHITE,
- .screen = ivec2{1080, 720},
- .viewport_size = vec2{2000, 2000},
- .zoom = 1.0f});
+ entity1.add_component<Camera>(ivec2{100, 100}, vec2{100, 100},
+ Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
+
auto & sprite = this->mgr.get_components_by_id<Sprite>(entity1.id).front().get();
ASSERT_NE(sprite.texture.texture.get(), nullptr);