|
|
@@ -35,7 +35,6 @@ protected:
|
|
|
mock_scene & scene() const { return *scene_; }
|
|
|
engine::game_dispatch & game() const { return *dispatch_; }
|
|
|
|
|
|
-private:
|
|
|
std::shared_ptr<stub_renderer> renderer_;
|
|
|
std::shared_ptr<engine::game_dispatch> dispatch_;
|
|
|
std::shared_ptr<mock_scene> scene_;
|
|
|
@@ -57,11 +56,18 @@ void GameDispatchTest::TearDown() {
|
|
|
}
|
|
|
|
|
|
using testing::AnyNumber;
|
|
|
+using testing::Eq;
|
|
|
using testing::Field;
|
|
|
+using testing::FloatNear;
|
|
|
using testing::Ge;
|
|
|
using testing::Lt;
|
|
|
using testing::_;
|
|
|
|
|
|
+TEST_F(GameDispatchTest, ManagerIsFetchedFromRenderer) {
|
|
|
+ EXPECT_THAT(&game().graphics_manager(), Eq(renderer_->manager().get()));
|
|
|
+}
|
|
|
+
|
|
|
+// TODO: Set FPS to a much smaller value for testing purposes (e.g. 512fps)
|
|
|
TEST_F(GameDispatchTest, UpdateDispatchesToCurrentScene) {
|
|
|
EXPECT_CALL(scene(), update(_)).Times(1);
|
|
|
game().update();
|
|
|
@@ -76,6 +82,21 @@ TEST_F(GameDispatchTest, UpdateIsCappedInFrequencyByFPSParam) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+TEST_F(GameDispatchTest, UpdateHasNoUpperBoundOnTime) {
|
|
|
+ EXPECT_CALL(scene(), update(Ge(0.03))).Times(1);
|
|
|
+ usleep(300000);
|
|
|
+ game().update();
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(GameDispatchTest, SetCurrentTimestampOverridesWaiting) {
|
|
|
+ auto fps60 = 1.0 / 60.0;
|
|
|
+ EXPECT_CALL(scene(), update(Ge(0.03))).Times(0);
|
|
|
+ EXPECT_CALL(scene(), update(FloatNear(fps60, 1E-2))).Times(1);
|
|
|
+ usleep(300000);
|
|
|
+ game().set_current_timestamp();
|
|
|
+ game().update();
|
|
|
+}
|
|
|
+
|
|
|
TEST_F(GameDispatchTest, RenderDispatchesToCurrentScene) {
|
|
|
EXPECT_CALL(scene(), render(_)).Times(1);
|
|
|
game().render();
|
|
|
@@ -89,8 +110,25 @@ TEST_F(MouseEventTest, DispatchesToCurrentScene) {
|
|
|
}
|
|
|
|
|
|
TEST_F(MouseEventTest, TranslatesFrameOfRef) {
|
|
|
+ // TODO: Actually set the local scene size element...
|
|
|
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);
|
|
|
}
|
|
|
+
|
|
|
+using KeyEventTest = GameDispatchTest;
|
|
|
+
|
|
|
+TEST_F(KeyEventTest, DoesNotDispatchUnmappedKeys) {
|
|
|
+ EXPECT_CALL(scene(), handle_key_event(_)).Times(0);
|
|
|
+ game().process_key_event('A', true);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(KeyEventTest, RemapsKeyWhenForwarding) {
|
|
|
+ // TODO: Properly set this instead of using this garbage
|
|
|
+ const_cast<engine::key_binding &>(scene().keys()).emplace('A', 'B');
|
|
|
+ auto key_value = &engine::event::key_event::key;
|
|
|
+ EXPECT_CALL(scene(), handle_key_event(Field(key_value, 'A'))).Times(0);
|
|
|
+ EXPECT_CALL(scene(), handle_key_event(Field(key_value, 'B'))).Times(1);
|
|
|
+ game().process_key_event('A', true);
|
|
|
+}
|