]> gitweb.factorcode.org Git - factor.git/blob - basis/cocoa/cocoa-tests.factor
Merge branch 'gtk' of git://github.com/Blei/factor
[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
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 Bar [
32     -> alloc -> init
33     dup -> bar "x" set
34     -> release
35 ] compile-call
36
37 [ 1.0 ] [ "x" get CGRect-x ] unit-test
38 [ 2.0 ] [ "x" get CGRect-y ] unit-test
39 [ 101.0 ] [ "x" get CGRect-w ] unit-test
40 [ 102.0 ] [ "x" get CGRect-h ] unit-test
41
42 ! Make sure that we can add methods
43 CLASS: Bar < NSObject
44 [
45     METHOD: NSRect bar [ test-foo "x" get ]
46
47     METHOD: int babb: int x [ x sq ]
48 ]
49
50 [ 144 ] [
51     Bar [
52         -> alloc -> init
53         dup 12 -> babb:
54         swap -> release
55     ] compile-call
56 ] unit-test