@@ -11,31 +11,29 @@ using ::testing::ReturnRef;
1111class TargetPainterTest : public testing ::Test
1212{
1313 public:
14- void createContextAndSurface (QOpenGLContext *context, QOffscreenSurface *surface)
14+ void SetUp () override
1515 {
16- QSurfaceFormat surfaceFormat;
17- surfaceFormat.setMajorVersion (4 );
18- surfaceFormat.setMinorVersion (3 );
16+ m_context.create ();
17+ ASSERT_TRUE (m_context.isValid ());
1918
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+ }
2724
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 ();
3029 }
30+
31+ QOpenGLContext m_context;
32+ QOffscreenSurface m_surface;
3133};
3234
3335TEST_F (TargetPainterTest, Paint)
3436{
35- QOpenGLContext context;
36- QOffscreenSurface surface;
37- createContextAndSurface (&context, &surface);
38-
3937 QOpenGLFramebufferObjectFormat format;
4038 format.setAttachment (QOpenGLFramebufferObject::CombinedDepthStencil);
4139
@@ -48,8 +46,10 @@ TEST_F(TargetPainterTest, Paint)
4846 // Paint reference
4947 refPainter.setAntialias (0 );
5048 refPainter.setStrokeStyle (QNanoColor (255 , 0 , 0 , 128 ));
51- refPainter.ellipse (refFbo.width () / 2 , refFbo.height () / 2 , refFbo.width () / 2 , refFbo.height () / 2 );
49+ refPainter.setFillStyle (QNanoColor (0 , 0 , 100 , 150 ));
50+ refPainter.rect (5 , 5 , refFbo.width () - 10 , refFbo.height () - 10 );
5251 refPainter.stroke ();
52+ refPainter.fill ();
5353 refPainter.endFrame ();
5454
5555 // Begin painting
@@ -76,17 +76,38 @@ TEST_F(TargetPainterTest, Paint)
7676
7777 // Paint
7878 Texture texture (refFbo.texture (), refFbo.size ());
79+ std::unordered_map<ShaderManager::Effect, double > effects;
7980 EXPECT_CALL (target, texture ()).WillOnce (Return (texture));
81+ EXPECT_CALL (target, graphicEffects ()).WillOnce (ReturnRef (effects));
8082 EXPECT_CALL (target, updateHullPoints (&fbo));
8183 targetPainter.paint (&painter);
8284 painter.endFrame ();
8385
8486 // Compare resulting images
8587 ASSERT_EQ (fbo.toImage (), refFbo.toImage ());
8688
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 ;
93+ effects[ShaderManager::Effect::Brightness] = 20 ;
94+ effects[ShaderManager::Effect::Ghost] = 84 ;
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+
87110 // Release
88111 fbo.release ();
89112 refFbo.release ();
90-
91- context.doneCurrent ();
92113}
0 commit comments