|
|
@@ -48,20 +48,25 @@ template <typename T> identity<T> cast(unsigned int id) {
|
|
|
|
|
|
auto cast_p(unsigned int id) { return cast<graphics::shader_program>(id); }
|
|
|
|
|
|
-struct ManagerTest : testing::Test {
|
|
|
+class ManagerTest : public testing::Test {
|
|
|
+public:
|
|
|
void SetUp() override;
|
|
|
+
|
|
|
mock_manager_impl mock;
|
|
|
+
|
|
|
+private:
|
|
|
+ struct {
|
|
|
+ graphics::texture operator()(math::vec2i const & sz) { return {++i, sz}; }
|
|
|
+ unsigned int i{0};
|
|
|
+ } next_tex;
|
|
|
};
|
|
|
|
|
|
void ManagerTest::SetUp() {
|
|
|
using testing::Invoke;
|
|
|
using testing::WithArg;
|
|
|
// Start with a new set of IDs
|
|
|
- auto next_tex = [](math::vec2i const & sz) mutable {
|
|
|
- static unsigned int i = 0;
|
|
|
- return graphics::texture{++i, sz};
|
|
|
- };
|
|
|
- ON_CALL(mock, compile(_, _, _)).WillByDefault(WithArg<1>(Invoke(next_tex)));
|
|
|
+ ON_CALL(mock, compile(_, _, _))
|
|
|
+ .WillByDefault(WithArg<1>(Invoke(std::ref(next_tex))));
|
|
|
}
|
|
|
|
|
|
TEST_F(ManagerTest, DoesNotGreedilyCompile) {
|
|
|
@@ -79,6 +84,12 @@ using MaterialTest = ManagerTest;
|
|
|
//}
|
|
|
|
|
|
TEST_F(MaterialTest, GeneratesUniformTexturesIfNoTexFile) {
|
|
|
+ using graphics::materials::uniform;
|
|
|
+ EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(3);
|
|
|
+ EXPECT_NO_THROW(mock.get(cast_p(1), "", "u_normalMap"));
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(MaterialTest, CreatedMaterialCanBeRefetched) {
|
|
|
using graphics::materials::uniform;
|
|
|
EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(3);
|
|
|
auto material_id = mock.get(cast_p(1), "", "u_normalMap");
|
|
|
@@ -86,9 +97,20 @@ TEST_F(MaterialTest, GeneratesUniformTexturesIfNoTexFile) {
|
|
|
// Ensure that the material is the 'same one' i.e.
|
|
|
// mock.get(mock.get(id)) == mock.get(id)
|
|
|
EXPECT_THAT(material, Eq(material_id));
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(MaterialTest, UniformMaterialIsOneByOne) {
|
|
|
+ using graphics::materials::uniform;
|
|
|
+ EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(3);
|
|
|
+ auto material = mock.get(mock.get(cast_p(1), "", "u_normalMap"));
|
|
|
// Uniforms are always sized 1x1
|
|
|
EXPECT_THAT(material.size, Eq(make_vector(1, 1)));
|
|
|
+}
|
|
|
|
|
|
+TEST_F(MaterialTest, UniformMaterialHasDataBindingToNormalTex) {
|
|
|
+ using graphics::materials::uniform;
|
|
|
+ EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(3);
|
|
|
+ auto material = mock.get(mock.get(cast_p(1), "", "u_normalMap"));
|
|
|
EXPECT_THAT(material.uniforms, SizeIs(1));
|
|
|
// Because we never initialize any textures, we are within the first three
|
|
|
// texture ID units.
|