@@ -29,6 +29,18 @@ using ::testing::_;
29
29
class RenderedTargetTest : public testing ::Test
30
30
{
31
31
public:
32
+ void SetUp () override
33
+ {
34
+ // Create OpenGL context
35
+ createContextAndSurface (&m_context, &m_surface);
36
+ }
37
+
38
+ void TearDown () override
39
+ {
40
+ emit m_context.aboutToBeDestroyed ();
41
+ m_context.doneCurrent ();
42
+ }
43
+
32
44
void createContextAndSurface (QOpenGLContext *context, QOffscreenSurface *surface)
33
45
{
34
46
QSurfaceFormat surfaceFormat;
@@ -46,6 +58,9 @@ class RenderedTargetTest : public testing::Test
46
58
context->makeCurrent (surface);
47
59
ASSERT_EQ (QOpenGLContext::currentContext (), context);
48
60
}
61
+
62
+ QOpenGLContext m_context;
63
+ QOffscreenSurface m_surface;
49
64
};
50
65
51
66
TEST_F (RenderedTargetTest, Constructors)
@@ -58,9 +73,6 @@ TEST_F(RenderedTargetTest, Constructors)
58
73
59
74
TEST_F (RenderedTargetTest, UpdateMethods)
60
75
{
61
- QOpenGLContext context;
62
- QOffscreenSurface surface;
63
- createContextAndSurface (&context, &surface);
64
76
RenderedTarget parent; // a parent item is needed for setVisible() to work
65
77
RenderedTarget target (&parent);
66
78
EngineMock engine;
@@ -325,8 +337,6 @@ TEST_F(RenderedTargetTest, UpdateMethods)
325
337
ASSERT_TRUE (texture.isValid ());
326
338
ASSERT_EQ (texture.width (), 13 );
327
339
ASSERT_EQ (texture.height (), 13 );
328
-
329
- context.doneCurrent ();
330
340
}
331
341
332
342
TEST_F (RenderedTargetTest, DeinitClone)
@@ -358,11 +368,6 @@ TEST_F(RenderedTargetTest, CpuRendering)
358
368
target.setEngine (&engine);
359
369
target.setSpriteModel (&model);
360
370
361
- // Create OpenGL context
362
- QOpenGLContext context;
363
- QOffscreenSurface surface;
364
- createContextAndSurface (&context, &surface);
365
-
366
371
// Load costume
367
372
EXPECT_CALL (engine, stageWidth ()).WillRepeatedly (Return (480 ));
368
373
EXPECT_CALL (engine, stageHeight ()).WillRepeatedly (Return (360 ));
@@ -467,9 +472,6 @@ TEST_F(RenderedTargetTest, CpuRendering)
467
472
target.setGraphicEffect (ShaderManager::Effect::Color, 0 );
468
473
469
474
// TODO: Test point transform (graphic effects that change shape)
470
-
471
- // Cleanup
472
- context.doneCurrent ();
473
475
}
474
476
475
477
TEST_F (RenderedTargetTest, SpriteDragging)
@@ -738,9 +740,6 @@ TEST_F(RenderedTargetTest, GraphicEffects)
738
740
739
741
TEST_F (RenderedTargetTest, GetBounds)
740
742
{
741
- QOpenGLContext context;
742
- QOffscreenSurface surface;
743
- createContextAndSurface (&context, &surface);
744
743
RenderedTarget target;
745
744
746
745
Sprite sprite;
@@ -826,16 +825,11 @@ TEST_F(RenderedTargetTest, GetBounds)
826
825
ASSERT_EQ (std::round (bubbleBounds.top () * 100 ) / 100 , 1294.13 );
827
826
ASSERT_EQ (std::round (bubbleBounds.right () * 100 ) / 100 , -405.87 );
828
827
ASSERT_EQ (std::round (bubbleBounds.bottom () * 100 ) / 100 , 1286.13 );
829
-
830
- context.doneCurrent ();
831
828
}
832
829
833
830
TEST_F (RenderedTargetTest, GetFastBounds)
834
831
{
835
- QOpenGLContext context;
836
- QOffscreenSurface surface;
837
- createContextAndSurface (&context, &surface);
838
- QOpenGLExtraFunctions glF (&context);
832
+ QOpenGLExtraFunctions glF (&m_context);
839
833
glF.initializeOpenGLFunctions ();
840
834
RenderedTarget target;
841
835
@@ -898,8 +892,6 @@ TEST_F(RenderedTargetTest, GetFastBounds)
898
892
ASSERT_EQ (std::round (bounds.top () * 100 ) / 100 , 1324.22 );
899
893
ASSERT_EQ (std::round (bounds.right () * 100 ) / 100 , -375.77 );
900
894
ASSERT_EQ (std::round (bounds.bottom () * 100 ) / 100 , 1143.65 );
901
-
902
- context.doneCurrent ();
903
895
}
904
896
905
897
TEST_F (RenderedTargetTest, TouchingClones)
@@ -923,11 +915,6 @@ TEST_F(RenderedTargetTest, TouchingClones)
923
915
model1.setRenderedTarget (&target1);
924
916
model2.setRenderedTarget (&target2);
925
917
926
- // Create OpenGL context
927
- QOpenGLContext context;
928
- QOffscreenSurface surface;
929
- createContextAndSurface (&context, &surface);
930
-
931
918
// Load costume
932
919
EXPECT_CALL (engine, stageWidth ()).WillRepeatedly (Return (480 ));
933
920
EXPECT_CALL (engine, stageHeight ()).WillRepeatedly (Return (360 ));
@@ -1074,9 +1061,6 @@ TEST_F(RenderedTargetTest, TouchingClones)
1074
1061
EXPECT_CALL (target1, containsScratchPoint).Times (0 );
1075
1062
EXPECT_CALL (target2, containsScratchPoint).Times (0 );
1076
1063
ASSERT_FALSE (target.touchingClones ({ &clone1, &clone2 }));
1077
-
1078
- // Cleanup
1079
- context.doneCurrent ();
1080
1064
}
1081
1065
1082
1066
TEST_F (RenderedTargetTest, TouchingColor)
@@ -1146,11 +1130,6 @@ TEST_F(RenderedTargetTest, TouchingColor)
1146
1130
model1.setRenderedTarget (&target1);
1147
1131
model2.setRenderedTarget (&target2);
1148
1132
1149
- // Create OpenGL context
1150
- QOpenGLContext context;
1151
- QOffscreenSurface surface;
1152
- createContextAndSurface (&context, &surface);
1153
-
1154
1133
// Load costume
1155
1134
EXPECT_CALL (engine, stageWidth ()).WillRepeatedly (Return (480 ));
1156
1135
EXPECT_CALL (engine, stageHeight ()).WillRepeatedly (Return (360 ));
@@ -1330,7 +1309,4 @@ TEST_F(RenderedTargetTest, TouchingColor)
1330
1309
EXPECT_CALL (penLayer, colorAtScratchPoint).Times (0 );
1331
1310
EXPECT_CALL (stageTarget, colorAtScratchPoint).Times (0 );
1332
1311
ASSERT_FALSE (target.touchingColor (color1));
1333
-
1334
- // Cleanup
1335
- context.doneCurrent ();
1336
1312
}
0 commit comments