瀏覽代碼

Add trivial tests for graphics::direct_renderer.

Some degree of tomfoolery is needed to test drawing functions without invoking openGL code, and the init functions still are directly tied to them.
Sam Jaffe 6 年之前
父節點
當前提交
31273d05b9

+ 27 - 0
graphics/graphics.xcodeproj/project.pbxproj

@@ -24,6 +24,8 @@
 		CD62FD232292C76B00376440 /* renderer_impl.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD62FD212292C76B00376440 /* renderer_impl.cxx */; };
 		CDA34D9A22517A3D008036A7 /* libmath.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA34D9922517A3D008036A7 /* libmath.dylib */; };
 		CDED9C1922A2D6CE00AE5CE5 /* libgraphics.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CD3AC6E21D2C0364002B4BB0 /* libgraphics.dylib */; };
+		CDED9C4322A2FACB00AE5CE5 /* renderer_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDED9C4222A2FACB00AE5CE5 /* renderer_test.cxx */; };
+		CDED9C4622A2FCA100AE5CE5 /* GoogleMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD62FCDF22904AD100376440 /* GoogleMock.framework */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -62,6 +64,13 @@
 			remoteGlobalIDString = CD3AC6E11D2C0364002B4BB0;
 			remoteInfo = graphics;
 		};
+		CDED9C4422A2FC9C00AE5CE5 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = CD62FCD722904AD100376440 /* GoogleMock.xcodeproj */;
+			proxyType = 1;
+			remoteGlobalIDString = 05818F851A685AEA0072A469;
+			remoteInfo = GoogleMock;
+		};
 /* End PBXContainerItemProxy section */
 
 /* Begin PBXFileReference section */
@@ -87,6 +96,7 @@
 		CDA34D9922517A3D008036A7 /* libmath.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; path = libmath.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 		CDED9C1422A2D6CD00AE5CE5 /* graphics-test.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "graphics-test.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
 		CDED9C1822A2D6CE00AE5CE5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+		CDED9C4222A2FACB00AE5CE5 /* renderer_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = renderer_test.cxx; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -104,6 +114,7 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CDED9C4622A2FCA100AE5CE5 /* GoogleMock.framework in Frameworks */,
 				CDED9C1922A2D6CE00AE5CE5 /* libgraphics.dylib in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
@@ -127,6 +138,7 @@
 				CD62FCD722904AD100376440 /* GoogleMock.xcodeproj */,
 				CDA34D86225171AA008036A7 /* game */,
 				CD3AC6E41D2C0364002B4BB0 /* src */,
+				CDED9C3D22A2F52500AE5CE5 /* test */,
 				CDED9C1522A2D6CE00AE5CE5 /* graphics-test */,
 				CD3AC6E31D2C0364002B4BB0 /* Products */,
 				CDA34D9822517A3D008036A7 /* Frameworks */,
@@ -206,6 +218,14 @@
 			path = "graphics-test";
 			sourceTree = "<group>";
 		};
+		CDED9C3D22A2F52500AE5CE5 /* test */ = {
+			isa = PBXGroup;
+			children = (
+				CDED9C4222A2FACB00AE5CE5 /* renderer_test.cxx */,
+			);
+			path = test;
+			sourceTree = "<group>";
+		};
 /* End PBXGroup section */
 
 /* Begin PBXHeadersBuildPhase section */
@@ -250,6 +270,7 @@
 			buildRules = (
 			);
 			dependencies = (
+				CDED9C4522A2FC9C00AE5CE5 /* PBXTargetDependency */,
 				CDED9C1B22A2D6CE00AE5CE5 /* PBXTargetDependency */,
 			);
 			name = "graphics-test";
@@ -383,6 +404,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CDED9C4322A2FACB00AE5CE5 /* renderer_test.cxx in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -394,6 +416,11 @@
 			target = CD3AC6E11D2C0364002B4BB0 /* graphics */;
 			targetProxy = CDED9C1A22A2D6CE00AE5CE5 /* PBXContainerItemProxy */;
 		};
+		CDED9C4522A2FC9C00AE5CE5 /* PBXTargetDependency */ = {
+			isa = PBXTargetDependency;
+			name = GoogleMock;
+			targetProxy = CDED9C4422A2FC9C00AE5CE5 /* PBXContainerItemProxy */;
+		};
 /* End PBXTargetDependency section */
 
 /* Begin XCBuildConfiguration section */

+ 1 - 0
graphics/include/game/graphics/renderer.hpp

@@ -31,6 +31,7 @@ namespace graphics {
   class direct_renderer : public renderer {
   public:
     direct_renderer(driver d);
+    direct_renderer(class renderer_impl * pi);
     std::shared_ptr<class manager const> manager() const override;
     void draw(object const & obj) override;
     void draw(identity<material>, math::matr4 const &,

+ 2 - 0
graphics/src/renderer.cxx

@@ -28,6 +28,8 @@ renderer_impl * get_renderer_impl(driver d) {
 
 direct_renderer::direct_renderer(driver d) : pimpl(::get_renderer_impl(d)) {}
 
+direct_renderer::direct_renderer(renderer_impl * pi) : pimpl(pi) {}
+
 std::shared_ptr<class manager const> direct_renderer::manager() const {
   return pimpl->manager();
 }

+ 47 - 0
graphics/test/renderer_test.cxx

@@ -0,0 +1,47 @@
+//
+//  direct_renderer_test.cxx
+//  graphics-test
+//
+//  Created by Sam Jaffe on 6/1/19.
+//  Copyright © 2019 Sam Jaffe. All rights reserved.
+//
+
+#include <gmock/gmock.h>
+
+#include "../src/renderer_impl.hpp"
+#include "game/graphics/renderer.hpp"
+#include "game/graphics/vertex.h"
+#include "matrix/matrix.hpp"
+
+struct mock_renderer_impl : graphics::renderer_impl {
+  MOCK_CONST_METHOD0(manager, std::shared_ptr<graphics::manager const>());
+  MOCK_METHOD3(draw, void(identity<graphics::material>, math::matr4 const &,
+                          std::vector<graphics::vertex> const &));
+  MOCK_METHOD0(clear, void());
+  MOCK_METHOD0(flush, void());
+};
+
+struct DirectRendererTest : testing::Test {
+  void SetUp() override;
+  void TearDown() override;
+
+  std::unique_ptr<graphics::direct_renderer> renderer;
+  mock_renderer_impl * mock;
+};
+
+void DirectRendererTest::SetUp() {
+  mock = new mock_renderer_impl;
+  renderer.reset(new graphics::direct_renderer(mock));
+}
+
+void DirectRendererTest::TearDown() { delete mock; }
+
+TEST_F(DirectRendererTest, ClearPassesToClear) {
+  EXPECT_CALL(*mock, clear()).Times(1);
+  renderer->clear();
+}
+
+TEST_F(DirectRendererTest, FlushPassesToFlush) {
+  EXPECT_CALL(*mock, flush()).Times(1);
+  renderer->flush();
+}