[squeak-dev] The Inbox: GraphicsTests-EG.58.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Dec 22 00:09:28 UTC 2021


A new version of GraphicsTests was added to project The Inbox:
http://source.squeak.org/inbox/GraphicsTests-EG.58.mcz

==================== Summary ====================

Name: GraphicsTests-EG.58
Author: EG
Time: 21 December 2021, 7:06:22.53722 pm
UUID: 32f0cb4a-a10f-4263-85da-6d934e567b0d
Ancestors: GraphicsTests-mt.57

Adding actual tests for GIF reading and writing (and reading back in).
  
Note that in this version, the tests are currently failing because -- apparently -- drawing Color black to a FormCanvas actually results in a slightly different color being put at the corresponding pixels of the Form. Therefore the expected values (Color black) are something else.
  
I suspect this is an issue with Form/FormCanvas?

=============== Diff against GraphicsTests-mt.57 ===============

Item was added:
+ TestCase subclass: #GIFReadWriterTest
+ 	instanceVariableNames: ''
+ 	classVariableNames: ''
+ 	poolDictionaries: ''
+ 	category: 'GraphicsTests-Files'!

Item was added:
+ ----- Method: GIFReadWriterTest>>animatedColorFrames (in category 'tests') -----
+ animatedColorFrames
+ 	"Responds with a collection of AnimatedImageFrames
+ 	each containing equal-sized rectangles of green, red, 
+ 	yellow. and black. When animated, these rectangles move
+ 	into each other's positions, then back"
+ 	| frames topLeft topRight bottomLeft bottomRight revFrames |
+ 	frames := OrderedCollection new.
+ 	topLeft := (0 at 0 extent: 200 at 200).
+ 	topRight := (200 at 0 extent: 400 at 200).
+ 	bottomLeft := (0 at 200 extent: 200 at 400).
+ 	bottomRight := (200 at 200 extent: 400 at 400).
+ 	
+ 	0 to: 200 by: 20 do: [ :num |
+ 		| newTopLeft newTopRight newBottomLeft newBottomRight canvas |
+ 		newTopLeft := topLeft translateBy: (num at 0).
+ 		newTopRight := topRight translateBy: (0 at num).
+ 		newBottomLeft := (bottomLeft origin - (0 at num)) corner: (bottomLeft extent - (0 at num)).
+ 		newBottomRight := (bottomRight origin - (num at 0)) extent: (bottomLeft extent - (0 at 0)).
+ 		canvas := FormCanvas extent: 400 at 400 depth: 32.
+ 		canvas
+ 			fillRectangle: newTopLeft color: Color green;
+ 			fillRectangle: newTopRight color: Color red;
+ 			fillRectangle: newBottomLeft color: Color yellow;
+ 			fillRectangle: newBottomRight color: Color black.
+ 		frames add: (AnimatedImageFrame new
+ 			form: canvas form;
+ 			disposal: #restoreBackground;
+ 			delay: 60) ].
+ 
+ 	revFrames := frames reversed.
+ 	revFrames do: [ :f | frames add: f ].
+ 	^ frames!

Item was added:
+ ----- Method: GIFReadWriterTest>>testAnimatedColorsOutIn (in category 'tests') -----
+ testAnimatedColorsOutIn
+ 	"Ensure that the colored rectangles in the created
+ 	animated gif are correct at different frames"
+ 	| frames outBytes writer reader inBytes activeFrame |
+ 	frames := self animatedColorFrames.
+ 	
+ 	"Write out the GIF bytes to the byte stream"
+ 	outBytes := WriteStream on: (ByteArray new).
+ 	writer := GIFReadWriter on: outBytes.
+ 	frames do: [ :f | writer nextPutFrame: f ].
+ 	writer close.
+ 	
+ 	"Read the GIF byte stream back into a GIF"
+ 	inBytes := ReadStream on: (outBytes contents).
+ 	reader := GIFReadWriter on: inBytes.
+ 	reader
+ 		readHeader;
+ 		readBody.
+ 	
+ 	self assert: reader isAnimated equals: true.
+ 	activeFrame := reader frames at: 1.
+ 	self assert: (activeFrame form colorAt: 100 at 100) equals: Color green.
+ 	self assert: (activeFrame form colorAt: 300 at 100) equals: Color red.
+ 	self assert: (activeFrame form colorAt: 100 at 300) equals: Color yellow.
+ 	self assert: (activeFrame form colorAt: 300 at 300) equals: Color black.
+ 	activeFrame := reader frames at: 11.
+ 	self assert: (activeFrame form colorAt: 100 at 100) equals: Color yellow.
+ 	self assert: (activeFrame form colorAt: 300 at 100) equals: Color green.
+ 	self assert: (activeFrame form colorAt: 100 at 300) equals: Color black.
+ 	self assert: (activeFrame form colorAt: 300 at 300) equals: Color red.
+ 	!

Item was added:
+ ----- Method: GIFReadWriterTest>>testColorsFileOutIn (in category 'tests') -----
+ testColorsFileOutIn
+ 	"Ensure that the colors that are written match up
+ 	to the colors that are read in again"
+ 	| canvas form outBytes inBytes writer reader |
+ 	canvas := FormCanvas extent: 400 at 400.
+ 	canvas
+ 		fillRectangle: (0 at 0 extent: 200 at 200) color: Color green;
+ 		fillRectangle: (200 at 0 extent: 400 at 200) color: Color red;
+ 		fillRectangle: (0 at 200 extent: 200 at 400) color: Color yellow;
+ 		fillRectangle: (200 at 200 extent: 400 at 400) color: Color black.
+ 	form := canvas form.
+ 	outBytes := FileStream fileNamed: 'testColorsFileOutIn.gif'.
+ 	writer := GIFReadWriter on: outBytes.
+ 	writer
+ 		nextPutImage: form;
+ 		close.
+ 	inBytes := 'testColorsFileOutIn.gif' asDirectoryEntry readStream binary.
+ 	reader := GIFReadWriter on: inBytes.
+ 	reader
+ 		readHeader;
+ 		readBody.
+ 	inBytes close.
+ 	'testColorsFileOutIn.gif' asDirectoryEntry delete.
+ 	self assert: reader isAnimated equals: false.
+ 	self assert: (reader form colorAt: 50 at 50) equals: Color green.
+ 	self assert: (reader form colorAt: 250 at 50) equals: Color red.
+ 	self assert: (reader form colorAt: 50 at 250) equals: Color yellow.
+ 	self assert: (reader form colorAt: 250 at 250) equals: Color black.!

Item was added:
+ ----- Method: GIFReadWriterTest>>testColorsOutIn (in category 'tests') -----
+ testColorsOutIn
+ 	"Ensure that the colors that are written match up
+ 	to the colors that are read in again"
+ 	| canvas form outBytes inBytes writer reader |
+ 	canvas := FormCanvas extent: 400 at 400.
+ 	canvas
+ 		fillRectangle: (0 at 0 extent: 200 at 200) color: Color green;
+ 		fillRectangle: (200 at 0 extent: 400 at 200) color: Color red;
+ 		fillRectangle: (0 at 200 extent: 200 at 400) color: Color yellow;
+ 		fillRectangle: (200 at 200 extent: 400 at 400) color: Color black.
+ 	form := canvas form.
+ 	outBytes := WriteStream on: (ByteArray new).
+ 	writer := GIFReadWriter on: outBytes.
+ 	writer
+ 		nextPutImage: form;
+ 		close.
+ 	outBytes := outBytes contents.
+ 	inBytes := ReadStream on: outBytes.
+ 	reader := GIFReadWriter on: inBytes.
+ 	reader
+ 		readHeader;
+ 		readBody.
+ 	self assert: reader isAnimated equals: false.
+ 	self assert: (reader form colorAt: 50 at 50) equals: Color green.
+ 	self assert: (reader form colorAt: 250 at 50) equals: Color red.
+ 	self assert: (reader form colorAt: 50 at 250) equals: Color yellow.
+ 	self assert: (reader form colorAt: 250 at 250) equals: Color black.!



More information about the Squeak-dev mailing list