]> gitweb.factorcode.org Git - factor.git/blob - basis/cocoa/cocoa-tests.factor
factor: Retrying on the unit tests. Also normalize some syntax with FUNCTION:.
[factor.git] / basis / cocoa / cocoa-tests.factor
1 USING: cocoa cocoa.messages cocoa.subclassing cocoa.types
2 compiler.test kernel namespaces cocoa.classes cocoa.runtime
3 tools.test memory compiler.units math core-graphics.types ;
4 FROM: alien.c-types => int void ;
5 IN: cocoa.tests
6
7 CLASS: Foo < NSObject
8 [
9     METHOD: void foo: NSRect rect [
10         gc rect "x" set
11     ]
12 ]
13
14 : test-foo ( -- )
15     Foo -> alloc -> init
16     dup 1.0 2.0 101.0 102.0 <CGRect> -> foo:
17     -> release ;
18
19 { } [ test-foo ] unit-test
20
21 { 1.0 } [ "x" get CGRect-x ] unit-test
22 { 2.0 } [ "x" get CGRect-y ] unit-test
23 { 101.0 } [ "x" get CGRect-w ] unit-test
24 { 102.0 } [ "x" get CGRect-h ] unit-test
25
26 CLASS: Bar < NSObject
27 [
28     METHOD: NSRect bar [ test-foo "x" get ]
29 ]
30
31 { } [
32     Bar [
33         -> alloc -> init
34         dup -> bar "x" set
35         -> release
36     ] compile-call
37 ] unit-test
38
39 { 1.0 } [ "x" get CGRect-x ] unit-test
40 { 2.0 } [ "x" get CGRect-y ] unit-test
41 { 101.0 } [ "x" get CGRect-w ] unit-test
42 { 102.0 } [ "x" get CGRect-h ] unit-test
43
44 ! Make sure that we can add methods
45 CLASS: Bar < NSObject
46 [
47     METHOD: NSRect bar [ test-foo "x" get ]
48
49     METHOD: int babb: int x [ x sq ]
50 ]
51
52 { 144 } [
53     Bar [
54         -> alloc -> init
55         dup 12 -> babb:
56         swap -> release
57     ] compile-call
58 ] unit-test