Nim-Tests.st 2.44 KB
TestCase subclass: #FFINimTest	instanceVariableNames: 'nim'	classVariableNames: ''	poolDictionaries: ''	category: 'Nim-Tests'!!FFINimTest methodsFor: 'as yet unclassified' stamp: 'gk 11/2/2014 15:08'!setUp	nim := FFINimTestLibrary ! !!FFINimTest methodsFor: 'as yet unclassified' stamp: 'gk 11/3/2014 01:11'!testBasics	"getting an int back"	self assert: (nim ffiHello = 42).	"sending ints and getting back too"	self assert: ((nim ffiAdd: 3 with: 4) = 7).	"getting a string"	self assert: (nim ffiFoo = 'hey').	"sending a string and getting an int back"	self assert: ((nim ffiLength: 'abc') = 3) .	! !"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!FFINimTest class	instanceVariableNames: ''!!FFINimTest class methodsFor: 'as yet unclassified' stamp: 'gk 11/3/2014 01:12'!stress	"self stress"		| rand |	rand := Random new.	^[10000000 timesRepeat: [		FFINimTestLibrary			ffiHello;			ffiFoo;			ffiAdd: rand next with: rand next;			ffiConcat: 'abc' with: '123';			ffiLength: 'abcde']] timeToRun! !ExternalLibrary subclass: #FFINimTestLibrary	instanceVariableNames: 'nim'	classVariableNames: ''	poolDictionaries: ''	category: 'Nim-Tests'!"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!FFINimTestLibrary class	instanceVariableNames: ''!!FFINimTestLibrary class methodsFor: 'primitives' stamp: 'gk 11/2/2014 13:05'!ffiAdd: a with: b	"self ffiAdd: 13 with: 29"		<cdecl: long 'add' (long long) module: 'testlib'>	^self externalCallFailed! !!FFINimTestLibrary class methodsFor: 'primitives' stamp: 'gk 11/2/2014 22:49'!ffiConcat: a with: b	"self ffiConcat: 'a' with: 'b' "		<cdecl: char* 'concat' (char* char*) module: 'testlib'>	^self externalCallFailed! !!FFINimTestLibrary class methodsFor: 'primitives' stamp: 'gk 11/3/2014 01:10'!ffiFoo	"self ffiFoo"		<cdecl: char* 'foo' () module: 'testlib'>	^self externalCallFailed! !!FFINimTestLibrary class methodsFor: 'primitives' stamp: 'gk 11/2/2014 13:06'!ffiHello	"self ffiHello"		"long is int in Nim"		<cdecl: long 'hello' () module: 'testlib'>	^self externalCallFailed! !!FFINimTestLibrary class methodsFor: 'primitives' stamp: 'gk 11/3/2014 01:10'!ffiLength: x	"self ffiLen: 'hey' "		<cdecl: long 'length' (char*) module: 'testlib'>	^self externalCallFailed! !!FFINimTestLibrary class methodsFor: 'accessing' stamp: 'gk 10/31/2014 21:45'!moduleName	"Use the fully qualified VM name so we ensure testing loading a library"	^'testlib'! !