@@ -257,3 +257,76 @@ TEST_F(PenLayerTest, DrawLine)
257257 buffer.open (QFile::ReadOnly);
258258 ASSERT_EQ (ref.readAll (), buffer.readAll ());
259259}
260+
261+ TEST_F (PenLayerTest, TextureData)
262+ {
263+ PenLayer penLayer;
264+ penLayer.setAntialiasingEnabled (false );
265+ EngineMock engine;
266+ EXPECT_CALL (engine, stageWidth ()).WillRepeatedly (Return (6 ));
267+ EXPECT_CALL (engine, stageHeight ()).WillRepeatedly (Return (4 ));
268+ penLayer.setEngine (&engine);
269+
270+ PenAttributes attr;
271+ attr.color = QColor (255 , 0 , 0 );
272+ attr.diameter = 1 ;
273+ penLayer.drawLine (attr, -3 , 2 , 3 , -2 );
274+ ASSERT_EQ (penLayer.colorAtScratchPoint (-3 , 2 ), qRgb (255 , 0 , 0 ));
275+ ASSERT_EQ (penLayer.colorAtScratchPoint (0 , 2 ), qRgba (0 , 0 , 0 , 0 ));
276+ ASSERT_EQ (penLayer.colorAtScratchPoint (-1 , 1 ), qRgb (255 , 0 , 0 ));
277+
278+ Rect bounds = penLayer.getBounds ();
279+ ASSERT_EQ (bounds.left (), -3 );
280+ ASSERT_EQ (bounds.top (), 2 );
281+ ASSERT_EQ (bounds.right (), 3 );
282+ ASSERT_EQ (bounds.bottom (), -2 );
283+
284+ attr.color = QColor (0 , 128 , 0 , 128 );
285+ attr.diameter = 2 ;
286+ penLayer.drawLine (attr, -3 , -2 , 3 , 2 );
287+ ASSERT_EQ (penLayer.colorAtScratchPoint (-3 , 2 ), qRgb (255 , 0 , 0 ));
288+ ASSERT_EQ (penLayer.colorAtScratchPoint (0 , 2 ), qRgba (0 , 64 , 0 , 128 ));
289+ ASSERT_EQ (penLayer.colorAtScratchPoint (-1 , 1 ), qRgb (127 , 64 , 0 ));
290+
291+ bounds = penLayer.getBounds ();
292+ ASSERT_EQ (bounds.left (), -3 );
293+ ASSERT_EQ (bounds.top (), 2 );
294+ ASSERT_EQ (bounds.right (), 3 );
295+ ASSERT_EQ (bounds.bottom (), -2 );
296+
297+ penLayer.clear ();
298+ ASSERT_EQ (penLayer.colorAtScratchPoint (-3 , 2 ), 0 );
299+ ASSERT_EQ (penLayer.colorAtScratchPoint (0 , 2 ), 0 );
300+ ASSERT_EQ (penLayer.colorAtScratchPoint (-1 , 1 ), 0 );
301+
302+ bounds = penLayer.getBounds ();
303+ ASSERT_EQ (bounds.left (), 0 );
304+ ASSERT_EQ (bounds.top (), 0 );
305+ ASSERT_EQ (bounds.right (), 0 );
306+ ASSERT_EQ (bounds.bottom (), 0 );
307+
308+ attr.color = QColor (0 , 255 , 0 , 255 );
309+ attr.diameter = 1 ;
310+ penLayer.drawLine (attr, 0 , -1 , 1 , 1 );
311+ ASSERT_EQ (penLayer.colorAtScratchPoint (0 , 1 ), qRgb (0 , 255 , 0 ));
312+ ASSERT_EQ (penLayer.colorAtScratchPoint (0 , 0 ), qRgb (0 , 255 , 0 ));
313+ ASSERT_EQ (penLayer.colorAtScratchPoint (-3 , 1 ), qRgba (0 , 0 , 0 , 0 ));
314+
315+ bounds = penLayer.getBounds ();
316+ ASSERT_EQ (bounds.left (), 0 );
317+ ASSERT_EQ (bounds.top (), 1 );
318+ ASSERT_EQ (bounds.right (), 1 );
319+ ASSERT_EQ (bounds.bottom (), -1 );
320+
321+ attr.diameter = 2 ;
322+ penLayer.drawPoint (attr, -2 , 0 );
323+ ASSERT_EQ (penLayer.colorAtScratchPoint (0 , 1 ), qRgb (0 , 255 , 0 ));
324+ ASSERT_EQ (penLayer.colorAtScratchPoint (0 , 0 ), qRgb (0 , 255 , 0 ));
325+ ASSERT_EQ (penLayer.colorAtScratchPoint (-3 , 1 ), qRgb (0 , 255 , 0 ));
326+
327+ bounds = penLayer.getBounds ();
328+ ASSERT_EQ (bounds.left (), -3 );
329+ ASSERT_EQ (bounds.top (), 1 );
330+ ASSERT_EQ (bounds.right (), 1 );
331+ ASSERT_EQ (bounds.bottom (), -1 );
332+ }
0 commit comments