]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/alien/c-types/c-types-tests.factor
alien.c-types: not necessary to import `short` differently anymore
[factor.git] / basis / alien / c-types / c-types-tests.factor
index 1417433678d53572f6ba597a326fdb19b42f7acd..b13faf45c72cf4f819a4464e35ec42ffd6c0370d 100644 (file)
@@ -1,8 +1,6 @@
-USING: alien alien.syntax alien.c-types alien.parser
-eval kernel tools.test sequences system libc alien.strings
-io.encodings.ascii io.encodings.utf8 math.constants classes.struct classes
-accessors compiler.units ;
-FROM: alien.c-types => short ;
+USING: accessors alien.c-types alien.syntax classes
+classes.struct compiler.units eval io.encodings.ascii kernel
+math.constants tools.test ;
 IN: alien.c-types.tests
 
 CONSTANT: xyz 123
@@ -60,11 +58,28 @@ C-TYPE: opaque
 { t } [ void* lookup-c-type pointer: opaque lookup-c-type = ] unit-test
 [ opaque lookup-c-type ] [ no-c-type? ] must-fail-with
 
-[ """
+! c-type-string
+{
+    "c-string[ascii]"
+    "foo*"
+    "int[5]"
+    "int**"
+    "MyFunkyString*"
+    "opaque*"
+} [
+    { c-string ascii } c-type-string
+    pointer: foo c-type-string
+    { int 5 } c-type-string
+    pointer: pointer: int c-type-string
+    pointer: MyFunkyString c-type-string
+    pointer: opaque c-type-string
+] unit-test
+
+[ "
     USING: alien.syntax ;
     IN: alien.c-types.tests
     FUNCTION: opaque return_opaque ( ) ;
-""" eval( -- ) ] [ no-c-type? ] must-fail-with
+" eval( -- ) ] [ no-c-type? ] must-fail-with
 
 C-TYPE: forward
 STRUCT: backward { x forward* } ;
@@ -78,19 +93,19 @@ DEFER: struct-redefined
 { f }
 [
 
-    """
+    "
     USING: alien.c-types classes.struct ;
     IN: alien.c-types.tests
 
     STRUCT: struct-redefined { x int } ;
-    """ eval( -- )
+    " eval( -- )
 
-    """
+    "
     USING: alien.syntax ;
     IN: alien.c-types.tests
 
     C-TYPE: struct-redefined
-    """ eval( -- )
+    " eval( -- )
 
     \ struct-redefined class?
 ] unit-test
@@ -104,3 +119,49 @@ DEFER: struct-redefined
 ]
 [ error>> error>> redefine-error? ]
 must-fail-with
+
+[
+    "IN: alien.c-types.tests
+    USE: alien.syntax
+    USE: alien.c-types
+    CALLBACK: void cb987 ( )
+    CALLBACK: void cb987 ( )" eval( -- )
+]
+[ error>> error>> redefine-error? ]
+must-fail-with
+
+[
+    "IN: alien.c-types.tests
+    USE: alien.syntax
+    USE: alien.c-types
+    FUNCTION: void func987 ( )
+    FUNCTION: void func987 ( )" eval( -- )
+]
+[ error>> error>> redefine-error? ]
+must-fail-with
+
+! generic -> callback
+"IN: alien.c-types.tests
+USE: alien.syntax
+USE: alien.c-types
+GENERIC: foo-func ( x -- )
+" eval( -- )
+
+"IN: alien.c-types.tests
+USE: alien.syntax
+USE: alien.c-types
+CALLBACK: void foo-func ( )
+" eval( -- )
+
+! generic -> typedef
+"IN: alien.c-types.tests
+USE: alien.syntax
+USE: alien.c-types
+GENERIC: foo-func ( x -- )
+" eval( -- )
+
+"IN: alien.c-types.tests
+USE: alien.syntax
+USE: alien.c-types
+TYPEDEF: void* foo-func
+" eval( -- )