Browse Source

Add tests for RGB/RGBA channels.
Uncomment test for 'throw when no texture or uniform provided' and fix sigabrt error in that case.

Sam Jaffe 6 years ago
parent
commit
a14bbe512b

+ 2 - 2
graphics/src/manager.cxx

@@ -76,8 +76,8 @@ identity<material> manager::get(identity<shader_program> program,
   if (found != cache.values.end()) { return found->second; }
 
   std::vector<struct uniform> uniforms;
-  uniforms.push_back(
-      {texture_or_uniform(texture, uniform), uniform_id(uniform)});
+  auto id = uniform_id(uniform);
+  uniforms.push_back({texture_or_uniform(texture, uniform), id});
   math::vec2i size = get(uniforms[0].texture).size;
   //  if (!uniforms.empty()) { size = ...; }
   return cache.emplace(key, material(program, size, uniforms));

+ 18 - 5
graphics/test/manager_test.cxx

@@ -9,6 +9,7 @@
 #include <gmock/gmock.h>
 
 #include "../src/helper.hpp"
+#include "game/graphics/exception.h"
 #include "game/graphics/manager.hpp"
 #include "game/graphics/material.hpp"
 #include "game/graphics/shader.hpp"
@@ -135,13 +136,25 @@ TEST_F(TextureTest, SizeOfTexturePassedIntoCompile) {
   mock.get("resources/black2.bmp");
 }
 
+TEST_F(TextureTest, CanReadRGBFormat) {
+  using graphics::textures::format;
+  EXPECT_CALL(mock, compile(format::RGB, make_vector(1, 1), _)).Times(1);
+  mock.get("resources/black_rgb.png");
+}
+
+TEST_F(TextureTest, CanReadRGBAFormat) {
+  using graphics::textures::format;
+  EXPECT_CALL(mock, compile(format::RGBA, make_vector(1, 1), _)).Times(1);
+  mock.get("resources/black_rgba.png");
+}
+
 using MaterialTest = ManagerTest;
 
-// TEST_F(MaterialTest, ThrowsExceptionIfNoTexOrUniform) {
-//  EXPECT_CALL(mock, compile(_, _, _)).Times(AnyNumber());
-//  // TODO (sjaffe): Throw a specific exception here, since throw; kills us
-//  EXPECT_ANY_THROW(mock.get(cast_p(1), "", ""));
-//}
+TEST_F(MaterialTest, ThrowsExceptionIfNoTexOrUniform) {
+  EXPECT_CALL(mock, compile(_, _, _)).Times(AnyNumber());
+  EXPECT_THROW(mock.get(cast_p(1), "", ""),
+               graphics::unmapped_enum<graphics::materials::uniform>);
+}
 
 TEST_F(MaterialTest, GeneratesUniformTexturesIfNoTexFile) {
   using graphics::materials::uniform;

BIN
graphics/test/resources/black_rgb.png


BIN
graphics/test/resources/black_rgba.png