|
|
@@ -9,8 +9,10 @@
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
|
#include "../src/renderer_impl.hpp"
|
|
|
+#include "game/graphics/object.hpp"
|
|
|
#include "game/graphics/renderer.hpp"
|
|
|
#include "game/graphics/vertex.h"
|
|
|
+#include "game/math/shape.hpp"
|
|
|
#include "matrix/matrix.hpp"
|
|
|
|
|
|
struct mock_renderer_impl : graphics::renderer_impl {
|
|
|
@@ -21,6 +23,10 @@ struct mock_renderer_impl : graphics::renderer_impl {
|
|
|
MOCK_METHOD0(flush, void());
|
|
|
};
|
|
|
|
|
|
+identity<graphics::material> cast(unsigned int id) {
|
|
|
+ return *reinterpret_cast<identity<graphics::material> *>(&id);
|
|
|
+}
|
|
|
+
|
|
|
struct DirectRendererTest : testing::Test {
|
|
|
void SetUp() override;
|
|
|
void TearDown() override;
|
|
|
@@ -36,6 +42,31 @@ void DirectRendererTest::SetUp() {
|
|
|
|
|
|
void DirectRendererTest::TearDown() { delete mock; }
|
|
|
|
|
|
+TEST_F(DirectRendererTest, DrawPassesToDraw) {
|
|
|
+ using testing::IsEmpty;
|
|
|
+ EXPECT_CALL(*mock, draw(cast(1), math::matr4(), IsEmpty())).Times(1);
|
|
|
+ renderer->draw(cast(1), math::matr4(), {});
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(DirectRendererTest, DrawObjectHasEmptyTranslation) {
|
|
|
+ using testing::_;
|
|
|
+ math::dim2::rectangle const size{{{-1.f, -1.f}}, {{2.f, 2.f}}};
|
|
|
+ math::dim2::rectangle const tex{{{0.f, 0.f}}, {{1.f, 1.f}}};
|
|
|
+ graphics::object const object{size, size, cast(1), tex};
|
|
|
+ EXPECT_CALL(*mock, draw(cast(1), math::matr4(), _)).Times(1);
|
|
|
+ renderer->draw(object);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(DirectRendererTest, DrawObjectHasSixVertices) {
|
|
|
+ using testing::SizeIs;
|
|
|
+ using testing::_;
|
|
|
+ math::dim2::rectangle const size{{{-1.f, -1.f}}, {{2.f, 2.f}}};
|
|
|
+ math::dim2::rectangle const tex{{{0.f, 0.f}}, {{1.f, 1.f}}};
|
|
|
+ graphics::object const object{size, size, cast(1), tex};
|
|
|
+ EXPECT_CALL(*mock, draw(_, _, SizeIs(6))).Times(1);
|
|
|
+ renderer->draw(object);
|
|
|
+}
|
|
|
+
|
|
|
TEST_F(DirectRendererTest, ClearPassesToClear) {
|
|
|
EXPECT_CALL(*mock, clear()).Times(1);
|
|
|
renderer->clear();
|