@@ -304,14 +304,90 @@ TEST_F(RenderedTargetTest, LoadPngCostume)
304
304
305
305
TEST_F (RenderedTargetTest, LoadSvgCostume)
306
306
{
307
+ // Get maximum viewport dimensions
308
+ QOpenGLContext context;
309
+ context.create ();
310
+ Q_ASSERT (context.isValid ());
311
+
312
+ QOffscreenSurface surface;
313
+ surface.create ();
314
+ Q_ASSERT (surface.isValid ());
315
+
316
+ context.makeCurrent (&surface);
317
+ GLint dims[2 ];
318
+ glGetIntegerv (GL_MAX_VIEWPORT_DIMS, dims);
319
+ double maxWidth = dims[0 ] * 0.25 ;
320
+ double maxHeight = dims[1 ] * 0.25 ;
321
+ double maxSize = std::min (maxWidth / (1143 / 90.0 ), maxHeight / (1143 / 90.0 ));
322
+ context.doneCurrent ();
323
+
307
324
std::string str = readFileStr (" image.svg" );
308
- Costume costume (" " , " abc" , " svg" );
309
- costume.setData (str.size (), static_cast <void *>(const_cast <char *>(str.c_str ())));
310
- costume.setBitmapResolution (3 );
325
+ auto costume = std::make_shared<Costume>(" " , " abc" , " svg" );
326
+ costume->setData (str.size (), static_cast <void *>(const_cast <char *>(str.c_str ())));
327
+ costume->setBitmapResolution (1 );
328
+
329
+ EngineMock engine;
330
+ SpriteModel model;
331
+ Sprite sprite;
332
+ sprite.setSize (maxSize * 100 );
333
+ sprite.setX (49.7 );
334
+ sprite.setY (-64.15 );
335
+ costume->setRotationCenterX (-84 );
336
+ costume->setRotationCenterY (53 );
337
+ model.init (&sprite);
311
338
312
339
RenderedTarget target;
340
+ target.setEngine (&engine);
341
+ target.setSpriteModel (&model);
313
342
314
- target.loadCostume (&costume);
343
+ target.loadCostume (costume.get ());
344
+ ASSERT_TRUE (target.isSvg ());
345
+ ASSERT_FALSE (target.bitmapBuffer ()->isOpen ());
346
+ target.bitmapBuffer ()->open (QBuffer::ReadOnly);
347
+ ASSERT_TRUE (target.bitmapBuffer ()->readAll ().toStdString ().empty ());
348
+ ASSERT_TRUE (target.bitmapUniqueKey ().toStdString ().empty ());
349
+ target.bitmapBuffer ()->close ();
350
+
351
+ EXPECT_CALL (engine, stageWidth ()).WillOnce (Return (480 ));
352
+ EXPECT_CALL (engine, stageHeight ()).WillOnce (Return (360 ));
353
+ target.loadProperties ();
354
+ ASSERT_TRUE (target.isSvg ());
355
+ ASSERT_FALSE (target.bitmapBuffer ()->isOpen ());
356
+ target.bitmapBuffer ()->open (QBuffer::ReadOnly);
357
+ ASSERT_TRUE (target.bitmapBuffer ()->readAll ().toStdString ().empty ());
358
+ ASSERT_TRUE (target.bitmapUniqueKey ().toStdString ().empty ());
359
+ target.bitmapBuffer ()->close ();
360
+
361
+ target.updateProperties ();
362
+ ASSERT_TRUE (target.isSvg ());
363
+ ASSERT_FALSE (target.bitmapBuffer ()->isOpen ());
364
+ target.bitmapBuffer ()->open (QBuffer::ReadOnly);
365
+ ASSERT_TRUE (target.bitmapBuffer ()->readAll ().toStdString ().empty ());
366
+ ASSERT_TRUE (target.bitmapUniqueKey ().toStdString ().empty ());
367
+ target.bitmapBuffer ()->close ();
368
+
369
+ ASSERT_EQ (std::round (target.width () * 100 ) / 100 , maxWidth);
370
+ ASSERT_EQ (std::round (target.height () * 100 ) / 100 , maxHeight);
371
+ ASSERT_EQ (target.scale (), 1 );
372
+ ASSERT_EQ (std::round (target.x () * 100 ) / 100 , 27381.35 );
373
+ ASSERT_EQ (std::round (target.y () * 100 ) / 100 , -16849.39 );
374
+ ASSERT_EQ (std::round (target.transformOriginPoint ().x () * 100 ) / 100 , -27091.65 );
375
+ ASSERT_EQ (std::round (target.transformOriginPoint ().y () * 100 ) / 100 , 17093.54 );
376
+
377
+ // Test scale limit
378
+ sprite.setSize (maxSize * 250 );
379
+
380
+ target.loadCostume (costume.get ());
381
+ ASSERT_TRUE (target.isSvg ());
382
+ ASSERT_FALSE (target.bitmapBuffer ()->isOpen ());
383
+ target.bitmapBuffer ()->open (QBuffer::ReadOnly);
384
+ ASSERT_TRUE (target.bitmapBuffer ()->readAll ().toStdString ().empty ());
385
+ ASSERT_TRUE (target.bitmapUniqueKey ().toStdString ().empty ());
386
+ target.bitmapBuffer ()->close ();
387
+
388
+ EXPECT_CALL (engine, stageWidth ()).WillOnce (Return (480 ));
389
+ EXPECT_CALL (engine, stageHeight ()).WillOnce (Return (360 ));
390
+ target.loadProperties ();
315
391
ASSERT_TRUE (target.isSvg ());
316
392
ASSERT_FALSE (target.bitmapBuffer ()->isOpen ());
317
393
target.bitmapBuffer ()->open (QBuffer::ReadOnly);
@@ -326,6 +402,14 @@ TEST_F(RenderedTargetTest, LoadSvgCostume)
326
402
ASSERT_TRUE (target.bitmapBuffer ()->readAll ().toStdString ().empty ());
327
403
ASSERT_TRUE (target.bitmapUniqueKey ().toStdString ().empty ());
328
404
target.bitmapBuffer ()->close ();
405
+
406
+ ASSERT_EQ (std::round (target.width () * 100 ) / 100 , maxWidth);
407
+ ASSERT_EQ (std::round (target.height () * 100 ) / 100 , maxHeight);
408
+ ASSERT_EQ (target.scale (), 2.5 );
409
+ ASSERT_EQ (std::round (target.x () * 100 ) / 100 , 27381.35 );
410
+ ASSERT_EQ (std::round (target.y () * 100 ) / 100 , -16849.39 );
411
+ ASSERT_EQ (std::round (target.transformOriginPoint ().x () * 100 ) / 100 , -27091.65 );
412
+ ASSERT_EQ (std::round (target.transformOriginPoint ().y () * 100 ) / 100 , 17093.54 );
329
413
}
330
414
331
415
TEST_F (RenderedTargetTest, PaintSvg)
0 commit comments