Jelajahi Sumber

Testing Mouse Release and Scene graphics.

Sam Jaffe 6 tahun lalu
induk
melakukan
9a70e6beba
2 mengubah file dengan 17 tambahan dan 0 penghapusan
  1. 12 0
      engine/test/game_dispatch_test.cxx
  2. 5 0
      engine/test/scene_test.cxx

+ 12 - 0
engine/test/game_dispatch_test.cxx

@@ -65,6 +65,7 @@ using testing::Field;
 using testing::FloatNear;
 using testing::Ge;
 using testing::Lt;
+using testing::Not;
 using testing::_;
 
 TEST_F(GameDispatchTest, ManagerIsFetchedFromRenderer) {
@@ -123,6 +124,17 @@ TEST_F(MouseEventTest, DispatchesToCurrentScene) {
   game().process_mouse_event({{0.f, 0.f}}, true);
 }
 
+MATCHER(WasPressed, "") {
+  return (arg.type & engine::event::PRESSED_MASK) != 0;
+}
+
+TEST_F(MouseEventTest, CanPressAndRelease) {
+  EXPECT_CALL(scene(), handle_mouse_event(WasPressed())).Times(1);
+  game().process_mouse_event({}, true);
+  EXPECT_CALL(scene(), handle_mouse_event(Not(WasPressed()))).Times(1);
+  game().process_mouse_event({}, false);
+}
+
 TEST_F(MouseEventTest, TranslatesFrameOfRef) {
   // Resize the scene (not a supported operation)
   scene_.reset(new mock_scene(dispatch_, make_vector(10.f, 10.f)));

+ 5 - 0
engine/test/scene_test.cxx

@@ -27,6 +27,7 @@ struct test_scene : engine::scene {
   void handle_mouse_event(engine::event::mouse_event) override {}
   bool in_bounds(math::dim2::point c) const { return engine::scene::in_bounds(c); }
   bool in_bounds(engine::collidable * c) const { return engine::scene::in_bounds(c); }
+  graphics::manager const & graphics_manager() const { return engine::scene::graphics_manager(); }
 
   void add_with(engine::collision_t t, engine::collidable & c) {
     colliders[t].push_back(&c);
@@ -72,6 +73,10 @@ void SceneTest::TearDown() {
 using testing::Eq;
 using testing::Ref;
 
+TEST_F(SceneTest, SharedGraphicsManagerWithDispatch) {
+  EXPECT_THAT(&scene().graphics_manager(), &game().graphics_manager());
+}
+
 TEST_F(SceneTest, WillCollideOverlappingObjects) {
   math::dim2::rectangle bnds{{{0.f, 0.f}}, {{1.f, 1.f}}};
   mock_collidable one{bnds}, two{bnds};