|
| 1 | +#include <texture.h> |
| 2 | + |
| 3 | +#include "../common.h" |
| 4 | + |
| 5 | +using namespace scratchcpprender; |
| 6 | + |
| 7 | +TEST(TextureTest, Constructors) |
| 8 | +{ |
| 9 | + { |
| 10 | + Texture tex; |
| 11 | + ASSERT_EQ(tex.handle(), 0); |
| 12 | + ASSERT_FALSE(tex.isValid()); |
| 13 | + ASSERT_EQ(tex.size().width(), 0); |
| 14 | + ASSERT_EQ(tex.size().height(), 0); |
| 15 | + ASSERT_EQ(tex.width(), 0); |
| 16 | + ASSERT_EQ(tex.height(), 0); |
| 17 | + } |
| 18 | + |
| 19 | + { |
| 20 | + Texture tex(2, QSize(4, 2)); |
| 21 | + ASSERT_EQ(tex.handle(), 2); |
| 22 | + ASSERT_TRUE(tex.isValid()); |
| 23 | + ASSERT_EQ(tex.size().width(), 4); |
| 24 | + ASSERT_EQ(tex.size().height(), 2); |
| 25 | + ASSERT_EQ(tex.width(), 4); |
| 26 | + ASSERT_EQ(tex.height(), 2); |
| 27 | + } |
| 28 | + |
| 29 | + { |
| 30 | + Texture tex(2, 5, 8); |
| 31 | + ASSERT_EQ(tex.handle(), 2); |
| 32 | + ASSERT_TRUE(tex.isValid()); |
| 33 | + ASSERT_EQ(tex.size().width(), 5); |
| 34 | + ASSERT_EQ(tex.size().height(), 8); |
| 35 | + ASSERT_EQ(tex.width(), 5); |
| 36 | + ASSERT_EQ(tex.height(), 8); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +TEST(TextureTest, Release) |
| 41 | +{ |
| 42 | + QOpenGLContext context; |
| 43 | + context.create(); |
| 44 | + ASSERT_TRUE(context.isValid()); |
| 45 | + |
| 46 | + QOffscreenSurface surface; |
| 47 | + surface.setFormat(context.format()); |
| 48 | + surface.create(); |
| 49 | + Q_ASSERT(surface.isValid()); |
| 50 | + context.makeCurrent(&surface); |
| 51 | + |
| 52 | + QOpenGLFramebufferObject fbo(1, 1); |
| 53 | + GLuint handle = fbo.takeTexture(); |
| 54 | + ASSERT_TRUE(glIsTexture(handle)); |
| 55 | + |
| 56 | + Texture tex(handle, fbo.width(), fbo.height()); |
| 57 | + ASSERT_TRUE(glIsTexture(handle)); |
| 58 | + |
| 59 | + tex.release(); |
| 60 | + ASSERT_FALSE(glIsTexture(handle)); |
| 61 | + |
| 62 | + context.doneCurrent(); |
| 63 | +} |
| 64 | + |
| 65 | +TEST(TextureTest, Operators) |
| 66 | +{ |
| 67 | + Texture t1; |
| 68 | + Texture t2; |
| 69 | + ASSERT_TRUE(t1 == t2); |
| 70 | + ASSERT_FALSE(t1 != t2); |
| 71 | + |
| 72 | + Texture t3(3, 10, 10); |
| 73 | + ASSERT_FALSE(t1 == t3); |
| 74 | + ASSERT_TRUE(t1 != t3); |
| 75 | + |
| 76 | + Texture t4(3, 10, 10); |
| 77 | + ASSERT_TRUE(t3 == t4); |
| 78 | + ASSERT_FALSE(t3 != t4); |
| 79 | + |
| 80 | + Texture t5(2, 10, 10); |
| 81 | + ASSERT_FALSE(t4 == t5); |
| 82 | + ASSERT_TRUE(t4 != t5); |
| 83 | +} |
0 commit comments