|
|
@@ -14,6 +14,7 @@
|
|
|
#include "game/engine/game_dispatch.hpp"
|
|
|
#include "game/engine/scene.hpp"
|
|
|
#include "game/graphics/renderer.hpp"
|
|
|
+#include "game/util/env.hpp"
|
|
|
|
|
|
#include "mock_renderer.h"
|
|
|
|
|
|
@@ -41,6 +42,7 @@ private:
|
|
|
};
|
|
|
|
|
|
void GameDispatchTest::SetUp() {
|
|
|
+ env::resize_screen({{100, 100}});
|
|
|
renderer_.reset(new stub_renderer);
|
|
|
dispatch_.reset(new engine::game_dispatch(renderer_));
|
|
|
scene_.reset(new mock_scene(dispatch_));
|
|
|
@@ -55,6 +57,7 @@ void GameDispatchTest::TearDown() {
|
|
|
}
|
|
|
|
|
|
using testing::AnyNumber;
|
|
|
+using testing::Field;
|
|
|
using testing::Ge;
|
|
|
using testing::Lt;
|
|
|
using testing::_;
|
|
|
@@ -65,8 +68,9 @@ TEST_F(GameDispatchTest, UpdateDispatchesToCurrentScene) {
|
|
|
}
|
|
|
|
|
|
TEST_F(GameDispatchTest, UpdateIsCappedInFrequencyByFPSParam) {
|
|
|
- EXPECT_CALL(scene(), update(Ge(1.0 / 60.0))).Times(AnyNumber());
|
|
|
- EXPECT_CALL(scene(), update(Lt(1.0 / 60.0))).Times(0);
|
|
|
+ auto fps60 = 1.0 / 60.0;
|
|
|
+ EXPECT_CALL(scene(), update(Ge(fps60))).Times(AnyNumber());
|
|
|
+ EXPECT_CALL(scene(), update(Lt(fps60))).Times(0);
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
game().update();
|
|
|
}
|
|
|
@@ -76,3 +80,17 @@ TEST_F(GameDispatchTest, RenderDispatchesToCurrentScene) {
|
|
|
EXPECT_CALL(scene(), render(_)).Times(1);
|
|
|
game().render();
|
|
|
}
|
|
|
+
|
|
|
+using MouseEventTest = GameDispatchTest;
|
|
|
+
|
|
|
+TEST_F(MouseEventTest, DispatchesToCurrentScene) {
|
|
|
+ EXPECT_CALL(scene(), handle_mouse_event(_)).Times(1);
|
|
|
+ game().process_mouse_event({{0.f, 0.f}}, true);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(MouseEventTest, TranslatesFrameOfRef) {
|
|
|
+ auto mouse_pos = &engine::event::mouse_event::current_mouse_position;
|
|
|
+ auto const where = make_vector(5.f, 5.f);
|
|
|
+ EXPECT_CALL(scene(), handle_mouse_event(Field(mouse_pos, where))).Times(1);
|
|
|
+ game().process_mouse_event({{50.f, 50.f}}, true);
|
|
|
+}
|