diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-09-28 11:45:33 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-09-28 16:34:22 +0200 |
commit | 3f3fc7b7723698e44427e2a14a2f4906832800bf (patch) | |
tree | 5acadfa4d77817c41f612c89c93925a149cbcfc0 /test/gl/object.test.cpp | |
parent | a8b007daa0e85ea4b1a4898fd591d55d0117cc85 (diff) | |
download | qtlocation-mapboxgl-3f3fc7b7723698e44427e2a14a2f4906832800bf.tar.gz |
[test] add .test.cpp suffix to test case files
Diffstat (limited to 'test/gl/object.test.cpp')
-rw-r--r-- | test/gl/object.test.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/test/gl/object.test.cpp b/test/gl/object.test.cpp new file mode 100644 index 0000000000..2722669e84 --- /dev/null +++ b/test/gl/object.test.cpp @@ -0,0 +1,117 @@ +#include <mbgl/test/util.hpp> + +#include <mbgl/platform/default/headless_display.hpp> +#include <mbgl/platform/default/headless_view.hpp> + +#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/context.hpp> + +#include <memory> + +namespace { + +static bool getFlag = false; +static bool setFlag = false; + +} // namespace + +struct MockGLObject { + using Type = bool; + static const Type Default; + static Type Get() { getFlag = true; return true; } + static void Set(const Type&) { setFlag = true; } +}; + +const bool MockGLObject::Default = false; + +TEST(GLObject, PreserveState) { + getFlag = false; + setFlag = false; + + auto object = std::make_unique<mbgl::gl::PreserveState<MockGLObject>>(); + EXPECT_TRUE(getFlag); + EXPECT_FALSE(setFlag); + + getFlag = false; + object.reset(); + EXPECT_FALSE(getFlag); + EXPECT_TRUE(setFlag); +} + +TEST(GLObject, Value) { + setFlag = false; + + auto object = std::make_unique<mbgl::gl::State<MockGLObject>>(); + EXPECT_EQ(object->getCurrentValue(), false); + EXPECT_FALSE(object->isDirty()); + EXPECT_FALSE(setFlag); + + object->setDirty(); + EXPECT_TRUE(object->isDirty()); + + *object = false; + EXPECT_EQ(object->getCurrentValue(), false); + EXPECT_FALSE(object->isDirty()); + EXPECT_TRUE(setFlag); + + setFlag = false; + *object = true; + EXPECT_EQ(object->getCurrentValue(), true); + EXPECT_FALSE(object->isDirty()); + EXPECT_TRUE(setFlag); + + object->reset(); + EXPECT_EQ(object->getCurrentValue(), false); + EXPECT_FALSE(object->isDirty()); + EXPECT_TRUE(setFlag); +} + +TEST(GLObject, Store) { + mbgl::HeadlessView view(std::make_shared<mbgl::HeadlessDisplay>(), 1); + view.activate(); + + mbgl::gl::Context context; + EXPECT_TRUE(context.empty()); + + mbgl::gl::UniqueProgram program = context.createProgram(); + EXPECT_NE(program.get(), 0u); + program.reset(); + EXPECT_FALSE(context.empty()); + context.performCleanup(); + EXPECT_TRUE(context.empty()); + + mbgl::gl::UniqueShader shader = context.createShader(GL_VERTEX_SHADER); + EXPECT_NE(shader.get(), 0u); + shader.reset(); + EXPECT_FALSE(context.empty()); + context.performCleanup(); + EXPECT_TRUE(context.empty()); + + mbgl::gl::UniqueBuffer buffer = context.createBuffer(); + EXPECT_NE(buffer.get(), 0u); + buffer.reset(); + EXPECT_FALSE(context.empty()); + context.performCleanup(); + EXPECT_TRUE(context.empty()); + + mbgl::gl::UniqueTexture texture = context.createTexture(); + EXPECT_NE(texture.get(), 0u); + texture.reset(); + EXPECT_FALSE(context.empty()); + context.performCleanup(); + EXPECT_FALSE(context.empty()); + context.reset(); + EXPECT_TRUE(context.empty()); + + mbgl::gl::UniqueVAO vao = context.createVAO(); + EXPECT_NE(vao.get(), 0u); + vao.reset(); + EXPECT_FALSE(context.empty()); + context.performCleanup(); + EXPECT_TRUE(context.empty()); + + context.reset(); + EXPECT_TRUE(context.empty()); + + view.deactivate(); +} |