@@ -404,3 +404,94 @@ TEST_F(LooksBlocksTest, ChangeEffectBy)
404404 builder.run ();
405405 }
406406}
407+
408+ TEST_F (LooksBlocksTest, SetEffectTo)
409+ {
410+ // Fisheye
411+ {
412+ auto stage = std::make_shared<Stage>();
413+ stage->setEngine (m_engine);
414+
415+ ScriptBuilder builder (m_extension.get (), m_engine, stage);
416+ IGraphicsEffect *effect = ScratchConfiguration::getGraphicsEffect (" FISHEYE" );
417+ ASSERT_TRUE (effect);
418+
419+ builder.addBlock (" looks_seteffectto" );
420+ builder.addDropdownField (" EFFECT" , " FISHEYE" );
421+ builder.addValueInput (" VALUE" , 45.2 );
422+ auto block = builder.currentBlock ();
423+
424+ Compiler compiler (m_engine, stage.get ());
425+ auto code = compiler.compile (block);
426+ Script script (stage.get (), block, m_engine);
427+ script.setCode (code);
428+ Thread thread (stage.get (), m_engine, &script);
429+
430+ stage->setGraphicsEffectValue (effect, 86.84 );
431+ thread.run ();
432+ ASSERT_EQ (std::round (stage->graphicsEffectValue (effect) * 100 ) / 100 , 45.2 );
433+ }
434+
435+ // Pixelate
436+ {
437+ auto stage = std::make_shared<Stage>();
438+ stage->setEngine (m_engine);
439+
440+ ScriptBuilder builder (m_extension.get (), m_engine, stage);
441+ IGraphicsEffect *effect = ScratchConfiguration::getGraphicsEffect (" PIXELATE" );
442+ ASSERT_TRUE (effect);
443+
444+ builder.addBlock (" looks_seteffectto" );
445+ builder.addDropdownField (" EFFECT" , " PIXELATE" );
446+ builder.addValueInput (" VALUE" , 12.05 );
447+ auto block = builder.currentBlock ();
448+
449+ Compiler compiler (m_engine, stage.get ());
450+ auto code = compiler.compile (block);
451+ Script script (stage.get (), block, m_engine);
452+ script.setCode (code);
453+ Thread thread (stage.get (), m_engine, &script);
454+
455+ thread.run ();
456+ ASSERT_EQ (std::round (stage->graphicsEffectValue (effect) * 100 ) / 100 , 12.05 );
457+ }
458+
459+ // Mosaic
460+ {
461+ auto stage = std::make_shared<Stage>();
462+ stage->setEngine (m_engine);
463+
464+ ScriptBuilder builder (m_extension.get (), m_engine, stage);
465+ IGraphicsEffect *effect = ScratchConfiguration::getGraphicsEffect (" MOSAIC" );
466+ ASSERT_TRUE (effect);
467+
468+ builder.addBlock (" looks_seteffectto" );
469+ builder.addDropdownField (" EFFECT" , " MOSAIC" );
470+ builder.addValueInput (" VALUE" , -8.06 );
471+ auto block = builder.currentBlock ();
472+
473+ Compiler compiler (m_engine, stage.get ());
474+ auto code = compiler.compile (block);
475+ Script script (stage.get (), block, m_engine);
476+ script.setCode (code);
477+ Thread thread (stage.get (), m_engine, &script);
478+
479+ stage->setGraphicsEffectValue (effect, 13.12 );
480+ thread.run ();
481+ ASSERT_EQ (std::round (stage->graphicsEffectValue (effect) * 100 ) / 100 , -8.06 );
482+ }
483+
484+ // Invalid
485+ {
486+ auto stage = std::make_shared<Stage>();
487+ stage->setEngine (m_engine);
488+
489+ ScriptBuilder builder (m_extension.get (), m_engine, stage);
490+ builder.addBlock (" looks_seteffectto" );
491+ builder.addDropdownField (" EFFECT" , " INVALID" );
492+ builder.addValueInput (" VALUE" , 8.3 );
493+
494+ builder.build ();
495+ builder.run ();
496+ }
497+ }
0 commit comments