Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
# Default value means that a failure in one OS cancels all
fail-fast: false
matrix:
smalltalk: [ Pharo64-14, Pharo64-15 ]
os: [ macos-latest, windows-latest ]
smalltalk: [ Pharo64-13, Pharo64-14, Pharo64-15 ]
os: [ windows-latest ] # macos-latest See https://github.com/pharo-graphics/Bloc/issues/872
runs-on: ${{ matrix.os }}
name: ${{ matrix.smalltalk }} on ${{ matrix.os }}
steps:
Expand Down
14 changes: 7 additions & 7 deletions src/BaselineOfBloc/BaselineOfBloc.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ BaselineOfBloc >> baseline: spec [
package: 'Bloc'
with: [ spec requires: #('Bloc-Display') ].

spec
package: 'Bloc-Simulation'
with: [ spec requires: #('Bloc') ].

spec
package: 'Bloc-Animation'
with: [ spec requires: #('Bloc') ].
Expand Down Expand Up @@ -120,7 +124,7 @@ BaselineOfBloc >> baseline: spec [

spec
package: 'Bloc-Layout-Examples'
with: [ spec requires: #('Bloc' 'Bloc-Layout' 'Bloc-Text-Elements') ].
with: [ spec requires: #('Bloc' 'Bloc-Layout' 'Bloc-Tests' 'Bloc-Text-Elements') ].

spec
package: 'Bloc-SVG'
Expand All @@ -147,13 +151,9 @@ BaselineOfBloc >> baseline: spec [
package: 'Bloc-Text-Tests'
with: [ spec requires: #('Bloc' 'Bloc-Text') ].

spec
package: 'BlocHost-Mock'
with: [ spec requires: #('Bloc') ].

spec
package: 'Bloc-Scripter'
with: [ spec requires: #('Bloc' 'Bloc-Layout' 'BlocHost-Mock') ].
with: [ spec requires: #('Bloc' 'Bloc-Simulation' 'Bloc-Layout') ].

spec
package: 'BlocHost-Morphic'
Expand Down Expand Up @@ -206,8 +206,8 @@ BaselineOfBloc >> baseline: spec [
package: 'Bloc-Tests'
with: [ spec requires: #(
'Bloc'
'Bloc-Simulation'
'Bloc-Text-Elements'
'BlocHost-Mock'
'BlocHost-Morphic'
'BlocHost-OSWindow-SDL2') ].

Expand Down
7 changes: 4 additions & 3 deletions src/Bloc-Alexandrie-Exporter/BAExporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ BAExporter >> element: aBlElement [
BAExporter >> export [

| aCanvas aBounds |
element isLayoutRequested ifTrue: [ element forceLayout ].
element isLayoutRequested ifTrue: [
element isAttachedToSceneGraph
ifTrue: [ element space settle ]
ifFalse: [ element forceLayout ] ].

aBounds := element invalidationBoundsInParent.

aCanvas := self newCanvas: aBounds extent * scale.

aCanvas
clear: self background;
pathScale: scale asPoint;
Expand Down
219 changes: 219 additions & 0 deletions src/Bloc-Alexandrie-Tests/BAAbstractExporterTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
Class {
#name : #BAAbstractExporterTest,
#superclass : #TestCase,
#instVars : [
'testDirectory',
'element'
],
#category : #'Bloc-Alexandrie-Tests-Exporter'
}

{ #category : #testing }
BAAbstractExporterTest class >> isAbstract [

^ self == BAAbstractExporterTest
]

{ #category : #running }
BAAbstractExporterTest >> newContainerWithChild [

| child container |
child := BlElement new
extent: 40 @ 20;
background: Color blue;
yourself.
container := BlElement new
extent: 100 @ 50;
background: Color transparent;
addChild: child;
yourself.
^ container
]

{ #category : #running }
BAAbstractExporterTest >> newTestElement [

^ BlElement new
extent: 100 @ 50;
background: Color red;
yourself
]

{ #category : #running }
BAAbstractExporterTest >> prepareElementToExport: anElement [

^ anElement
]

{ #category : #running }
BAAbstractExporterTest >> setUp [

super setUp.
testDirectory := (FileLocator temp / ('bloc-export-tests-' , UUID new asString36)) ensureCreateDirectory.
element := self newTestElement
]

{ #category : #running }
BAAbstractExporterTest >> tearDown [

testDirectory ifNotNil: [
testDirectory ensureDeleteAll.
testDirectory := nil ].
super tearDown
]

{ #category : #tests }
BAAbstractExporterTest >> testBARendererWriteAsPngTo [

| targetFile |
targetFile := testDirectory / 'renderer-write.png'.
BARenderer write: element asPngTo: targetFile.
self assert: targetFile exists.
self assert: targetFile size > 0
]

{ #category : #tests }
BAAbstractExporterTest >> testExportAsForm [

| form |
form := element exportAsForm.
self assert: (form isKindOf: Form).
self assert: form extent equals: 100 @ 50.
self assert: form depth equals: 32.
self assert: (form colorAt: 50 @ 25) equals: Color red
]

{ #category : #tests }
BAAbstractExporterTest >> testExportAsFormWithCustomBackground [

| container form |
container := self prepareElementToExport: self newContainerWithChild.
form := BAExporter form
element: container;
background: Color yellow;
export.
self assert: (form colorAt: 20 @ 10) equals: Color blue.
self assert: (form colorAt: 80 @ 40) equals: Color yellow
]

{ #category : #tests }
BAAbstractExporterTest >> testExportAsFormWithScale [

| form |
form := BAExporter form
element: element;
scale: 2.0;
export.
self assert: form extent equals: 200 @ 100
]

{ #category : #tests }
BAAbstractExporterTest >> testExportAsJPEG [

| targetFile result readForm |
targetFile := testDirectory / 'test.jpg'.
result := BAExporter jpg
element: element;
target: targetFile;
export.
self assert: result equals: targetFile.
self assert: targetFile exists.
self assert: targetFile size > 0.
self assert: (targetFile binaryReadStreamDo: [ :stream | stream next: 3 ]) equals: #[16rFF 16rD8 16rFF].
readForm := ImageReadWriter formFromFileNamed: targetFile fullName.
self assert: readForm extent equals: 100 @ 50
]

{ #category : #tests }
BAAbstractExporterTest >> testExportAsJPEGQualityAndProgressive [

| targetFile |
targetFile := testDirectory / 'quality.jpg'.
BAExporter jpg
element: element;
target: targetFile;
quality: 50;
isProgressive: false;
export.
self assert: targetFile exists.
self assert: targetFile size > 0
]

{ #category : #tests }
BAAbstractExporterTest >> testExportAsPDF [

| targetFile result header |
targetFile := testDirectory / 'test.pdf'.
result := BAExporter pdf
element: element;
target: targetFile;
export.
self assert: result equals: targetFile.
self assert: targetFile exists.
self assert: targetFile size > 0.
header := targetFile binaryReadStreamDo: [ :stream | (stream next: 4) asString ].
self assert: header equals: '%PDF'
]

{ #category : #tests }
BAAbstractExporterTest >> testExportAsPNG [

| targetFile result readForm |
targetFile := testDirectory / 'test.png'.
result := BAExporter png
element: element;
target: targetFile;
export.
self assert: result equals: targetFile.
self assert: targetFile exists.
self assert: targetFile size > 0.
self assert: (targetFile binaryReadStreamDo: [ :stream | stream next: 4 ]) equals: #[16r89 16r50 16r4E 16r47].
readForm := ImageReadWriter formFromFileNamed: targetFile fullName.
self assert: readForm extent equals: 100 @ 50
]

{ #category : #tests }
BAAbstractExporterTest >> testExportAsSVG [

| targetFile result contents |
targetFile := testDirectory / 'test.svg'.
result := BAExporter svg
element: element;
target: targetFile;
export.
self assert: result equals: targetFile.
self assert: targetFile exists.
self assert: targetFile size > 0.
contents := targetFile readStreamDo: [ :stream | stream contents ].
self assert: (contents includesSubstring: '<svg')
]

{ #category : #tests }
BAAbstractExporterTest >> testExportFromForkedProcess [

| sem form |
sem := Semaphore new.
[ form := element exportAsForm. sem signal ] fork.
sem waitTimeoutMilliseconds: 2000.
self assert: form isNotNil.
self assert: form extent equals: 100 @ 50
]

{ #category : #tests }
BAAbstractExporterTest >> testExportMultipleConcurrentForkedProcesses [

| forms mutex sem count |
forms := OrderedCollection new.
mutex := Mutex new.
sem := Semaphore new.
count := 5.
1 to: count do: [ :i |
[ | f |
f := (BlElement new
extent: (30 * i) @ (20 * i);
background: Color blue) exportAsForm.
mutex critical: [ forms add: f ].
sem signal ] fork ].
count timesRepeat: [ sem waitTimeoutMilliseconds: 3000 ].
self assert: forms size equals: count
]
77 changes: 77 additions & 0 deletions src/Bloc-Alexandrie-Tests/BAAttachedExporterTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
Class {
#name : #BAAttachedExporterTest,
#superclass : #BAAbstractExporterTest,
#instVars : [
'space'
],
#category : #'Bloc-Alexandrie-Tests-Exporter'
}

{ #category : #running }
BAAttachedExporterTest >> prepareElementToExport: anElement [

space root addChild: anElement.
space settle.
^ anElement
]

{ #category : #running }
BAAttachedExporterTest >> setUp [

super setUp.
space := BlSpace new.
space host: BlHeadlessHost default.
space root addChild: element.
space show; settle
]

{ #category : #running }
BAAttachedExporterTest >> tearDown [

space ifNotNil: [
space close; settle.
space := nil ].
super tearDown
]

{ #category : #tests }
BAAttachedExporterTest >> testAeAsFormFromHostPulseProcess [

| form |
space deferAndSettle: [ form := element aeAsForm ].
self assert: form isNotNil.
self assert: form extent equals: 100 @ 50
]

{ #category : #tests }
BAAttachedExporterTest >> testAeAsFormWithPendingLayoutFromHostPulseProcessErrors [

| raisedError |
raisedError := false.
space deferAndSettle: [
element requestLayout.
self should: [ element aeAsForm ] raise: Error.
raisedError := true ].
self assert: raisedError
]

{ #category : #tests }
BAAttachedExporterTest >> testExportFromHostPulseProcess [

| form |
space deferAndSettle: [ form := element exportAsForm ].
self assert: form isNotNil.
self assert: form extent equals: 100 @ 50
]

{ #category : #tests }
BAAttachedExporterTest >> testExportWithPendingLayoutFromHostPulseProcessErrors [

| raisedError |
raisedError := false.
space deferAndSettle: [
element requestLayout.
self should: [ element exportAsForm ] raise: Error.
raisedError := true ].
self assert: raisedError
]
Loading
Loading