Include path: ExampleProxy.
Include path: ExampleClass.

Class name: ExampleClassTest {

Function [ run

	| c s shape shapes |
	ExampleClass initializeModule.

	Transcript nextPutAll:  'Creating some objects:'; cr.
    	c:= ExternalCircle fromRadius: 10.0.
    	Transcript nextPutAll: '    Created circle '; nextPutAll: c printString; cr.
    	s := ExternalSquare fromWidth: 10.0.
    	Transcript nextPutAll: '    Created square '; nextPutAll: s printString; cr.

	"----- Access a static member -----"

	Transcript cr.
	Transcript nextPutAll: 'A total of '; nextPutAll: ExternalShape getNshapes printString; nextPutAll: ' shapes were created'; cr.

	"----- Member data access -----"

	"Notice how we can do this using functions specific to the 'Circle' class."
	c setX: 20.0.
	c setY: 30.0.

	"Now use the same functions in the base class"
	shape := s.
	shape setX: -10.0.
	shape setY: 5.0.

	Transcript cr; nextPutAll: 'Here is their current position:' ; cr.
	Transcript nextPutAll: '    ExternalCircle = ('; nextPutAll: c getX printString; nextPutAll: ' '; nextPutAll:c getY printString; nextPutAll:')'; cr.
	Transcript nextPutAll: '    ExternalSquare = ('; nextPutAll: s getX printString; nextPutAll:' '; nextPutAll: s getY printString; nextPutAll: ')'; cr.

	"----- Call some methods -----"

	Transcript cr; nextPutAll: ' Here are some properties of the shapes:'; cr.

	shapes := Array with: c with: s.
	shapes do:[ :aShape |
		Transcript nextPutAll: '    '; nextPutAll: aShape printString; cr.
		Transcript nextPutAll: '        area      = ' ; nextPutAll: aShape area printString; cr.
		Transcript nextPutAll: '        perimeter = ' ; nextPutAll: aShape perimeter printString; cr.
	].

	"Notice how the area and perimeter methods really invoke the appropriate virtual method on each object.
    ----- Delete everything -----"

    Transcript cr; nextPutAll: 'Guess I''ll clean up now'; cr.

    "Note: this invokes the virtual destructor
    You could leave this to the garbage collector"

    "the following needs to be investigated on VW, some kind of concurrency conflict with finalization?"
    "c delete.
    s delete."

    Transcript nextPutAll: ExternalShape getNshapes printString; nextPutAll: ' shapes remain'; cr.
    Transcript nextPutAll: 'Goodbye'; cr.
    Transcript flush.
]

Function [ testFinalization

	ExampleClass initializeModule.

	"The constructor of BigObject allocates 1024 bytes of C memory.  The destructor frees it.  If we did this many times, this would normally overflow
	the 2GB process space of a 32-bit OS, and likely cause a GPF due to running out of memory.  However, since the VM is garbage collecting the
	SWIG proxies, and the memory is being finalized, we shouldn't run out of memory.  The following allocates 4 GB of of memory.  If you look in the process
	monitor, the VM may fluctuate in memory size some, but it should not have excessive growth."

	1 to: 4000000 do:[ :i |
		BigObject new.
	].
]

}

