]> gitweb.factorcode.org Git - factor.git/blob - extra/alien/handles/handles-tests.factor
Update some copyright headers to follow the current convention
[factor.git] / extra / alien / handles / handles-tests.factor
1 ! Copyright (C) 2010 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.c-types alien.handles alien.syntax
4 destructors kernel math tools.test ;
5 IN: alien.handles.tests
6
7 TUPLE: thingy { x integer } ;
8 C: <thingy> thingy
9
10 CALLBACK: int thingy-callback ( uint thingy-handle )
11 CALLBACK: int thingy-ptr-callback ( void* thingy-handle )
12
13 : test-thingy-callback ( -- alien )
14     [ alien-handle> x>> 1 + ] thingy-callback ;
15
16 : test-thingy-ptr-callback ( -- alien )
17     [ alien-handle-ptr> x>> 1 + ] thingy-ptr-callback ;
18
19 : invoke-test-thingy-callback ( thingy -- n )
20     test-thingy-callback int { uint } cdecl alien-indirect ;
21 : invoke-test-thingy-ptr-callback ( thingy -- n )
22     test-thingy-ptr-callback int { void* } cdecl alien-indirect ;
23
24 { t f } [
25     [ 5 <thingy> <alien-handle> &release-alien-handle [ alien-handle? ] keep ] with-destructors
26     alien-handle?
27 ] unit-test
28
29 { t f } [
30     [ 5 <thingy> <alien-handle-ptr> &release-alien-handle-ptr [ alien-handle-ptr? ] keep ] with-destructors
31     alien-handle-ptr?
32 ] unit-test
33
34 { 6 } [
35     [
36         5 <thingy> <alien-handle> &release-alien-handle
37         invoke-test-thingy-callback
38     ] with-destructors
39 ] unit-test
40
41 { 6 } [
42     [
43         5 <thingy> <alien-handle-ptr> &release-alien-handle-ptr
44         invoke-test-thingy-ptr-callback
45     ] with-destructors
46 ] unit-test