1 ! Copyright (C) 2009 Jeremy Hughes.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.inline alien.inline.syntax io.directories io.files
4 kernel namespaces tools.test alien.c-types alien.data alien.structs ;
5 IN: alien.inline.syntax.tests
10 C-FUNCTION: const-int add ( int a, int b )
14 C-TYPEDEF: double bigfloat
16 C-FUNCTION: bigfloat smaller ( bigfloat a )
20 C-STRUCTURE: rectangle
24 C-FUNCTION: int area ( rectangle c )
25 return c.width * c.height;
30 { 2 1 } [ add ] must-infer-as
31 [ 5 ] [ 2 3 add ] unit-test
33 [ t ] [ "double" "bigfloat" [ resolve-typedef ] bi@ = ] unit-test
34 { 1 1 } [ smaller ] must-infer-as
35 [ 1.0 ] [ 10 smaller ] unit-test
37 [ t ] [ "rectangle" resolve-typedef struct-type? ] unit-test
38 { 1 1 } [ area ] must-infer-as
40 "rectangle" <c-object>
41 4 over set-rectangle-width
42 5 over set-rectangle-height
47 DELETE-C-LIBRARY: cpplib
54 C-FUNCTION: const-char* hello ( )
55 std::string s("hello world");
61 { 0 1 } [ hello ] must-infer-as
62 [ "hello world" ] [ hello ] unit-test
65 DELETE-C-LIBRARY: compile-error
66 C-LIBRARY: compile-error
68 C-FUNCTION: char* breakme ( )
72 << [ compile-c-library ] must-fail >>