@@ -11,31 +11,29 @@ using ::testing::ReturnRef;
11
11
class TargetPainterTest : public testing ::Test
12
12
{
13
13
public:
14
- void createContextAndSurface (QOpenGLContext *context, QOffscreenSurface *surface)
14
+ void SetUp () override
15
15
{
16
- QSurfaceFormat surfaceFormat;
17
- surfaceFormat.setMajorVersion (4 );
18
- surfaceFormat.setMinorVersion (3 );
16
+ m_context.create ();
17
+ ASSERT_TRUE (m_context.isValid ());
19
18
20
- context->setFormat (surfaceFormat);
21
- context->create ();
22
- ASSERT_TRUE (context->isValid ());
23
-
24
- surface->setFormat (surfaceFormat);
25
- surface->create ();
26
- ASSERT_TRUE (surface->isValid ());
19
+ m_surface.setFormat (m_context.format ());
20
+ m_surface.create ();
21
+ Q_ASSERT (m_surface.isValid ());
22
+ m_context.makeCurrent (&m_surface);
23
+ }
27
24
28
- context->makeCurrent (surface);
29
- ASSERT_EQ (QOpenGLContext::currentContext (), context);
25
+ void TearDown () override
26
+ {
27
+ ASSERT_EQ (m_context.surface (), &m_surface);
28
+ m_context.doneCurrent ();
30
29
}
30
+
31
+ QOpenGLContext m_context;
32
+ QOffscreenSurface m_surface;
31
33
};
32
34
33
35
TEST_F (TargetPainterTest, Paint)
34
36
{
35
- QOpenGLContext context;
36
- QOffscreenSurface surface;
37
- createContextAndSurface (&context, &surface);
38
-
39
37
QOpenGLFramebufferObjectFormat format;
40
38
format.setAttachment (QOpenGLFramebufferObject::CombinedDepthStencil);
41
39
@@ -48,8 +46,10 @@ TEST_F(TargetPainterTest, Paint)
48
46
// Paint reference
49
47
refPainter.setAntialias (0 );
50
48
refPainter.setStrokeStyle (QNanoColor (255 , 0 , 0 , 128 ));
49
+ refPainter.setFillStyle (QNanoColor (0 , 255 , 100 , 150 ));
51
50
refPainter.ellipse (refFbo.width () / 2 , refFbo.height () / 2 , refFbo.width () / 2 , refFbo.height () / 2 );
52
51
refPainter.stroke ();
52
+ refPainter.fill ();
53
53
refPainter.endFrame ();
54
54
55
55
// Begin painting
@@ -76,17 +76,38 @@ TEST_F(TargetPainterTest, Paint)
76
76
77
77
// Paint
78
78
Texture texture (refFbo.texture (), refFbo.size ());
79
+ std::unordered_map<ShaderManager::Effect, double > effects;
79
80
EXPECT_CALL (target, texture ()).WillOnce (Return (texture));
81
+ EXPECT_CALL (target, graphicEffects ()).WillOnce (ReturnRef (effects));
80
82
EXPECT_CALL (target, updateHullPoints (&fbo));
81
83
targetPainter.paint (&painter);
82
84
painter.endFrame ();
83
85
84
86
// Compare resulting images
85
87
ASSERT_EQ (fbo.toImage (), refFbo.toImage ());
86
88
89
+ // Paint with color effects
90
+ glClearColor (0 .0f , 0 .0f , 0 .0f , 0 .0f );
91
+ glClear (GL_COLOR_BUFFER_BIT);
92
+ effects[ShaderManager::Effect::Color] = 46.2 ;
93
+ effects[ShaderManager::Effect::Brightness] = 20.4 ;
94
+ effects[ShaderManager::Effect::Ghost] = 84.3 ;
95
+ EXPECT_CALL (target, texture ()).WillOnce (Return (texture));
96
+ EXPECT_CALL (target, graphicEffects ()).WillOnce (ReturnRef (effects));
97
+ EXPECT_CALL (target, updateHullPoints (&fbo));
98
+ targetPainter.paint (&painter);
99
+ painter.endFrame ();
100
+ effects.clear ();
101
+
102
+ // Compare with reference image
103
+ QBuffer refBuffer1;
104
+ fbo.toImage ().save (&refBuffer1, " png" );
105
+ QFile ref1 (" color_effects.png" );
106
+ ref1.open (QFile::ReadOnly);
107
+ refBuffer1.open (QBuffer::ReadOnly);
108
+ ASSERT_EQ (ref1.readAll (), refBuffer1.readAll ());
109
+
87
110
// Release
88
111
fbo.release ();
89
112
refFbo.release ();
90
-
91
- context.doneCurrent ();
92
113
}
0 commit comments