]> 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 5f903c9a3473eb4641c3cc0b6fb795035e3507be..b13faf45c72cf4f819a4464e35ec42ffd6c0370d 100644 (file)
-USING: alien alien.syntax alien.c-types alien.parser
-eval kernel tools.test sequences system libc alien.strings
-io.encodings.utf8 math.constants classes.struct classes
-accessors compiler.units ;
+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
 
-[ 492 ] [ { int xyz } heap-size ] unit-test
-
-[ -1 ] [ -1 <char> *char ] unit-test
-[ -1 ] [ -1 <short> *short ] unit-test
-[ -1 ] [ -1 <int> *int ] unit-test
+{ 492 } [ { int xyz } heap-size ] unit-test
 
 UNION-STRUCT: foo
     { a int }
     { b int } ;
 
-[ t ] [ pointer: void c-type void* c-type eq? ] unit-test
-[ t ] [ pointer: int  c-type void* c-type eq? ] unit-test
-[ t ] [ pointer: int* c-type void* c-type eq? ] unit-test
-[ f ] [ pointer: foo  c-type void* c-type eq? ] unit-test
-[ t ] [ pointer: foo* c-type void* c-type eq? ] unit-test
-
-[ t ] [ pointer: char c-type c-string c-type eq? ] unit-test
+{ t } [ pointer: void lookup-c-type void* lookup-c-type = ] unit-test
+{ t } [ pointer: int  lookup-c-type void* lookup-c-type = ] unit-test
+{ t } [ pointer: int* lookup-c-type void* lookup-c-type = ] unit-test
+{ f } [ pointer: foo  lookup-c-type void* lookup-c-type = ] unit-test
+{ t } [ pointer: foo* lookup-c-type void* lookup-c-type = ] unit-test
 
-[ t ] [ pointer: foo c-type-boxer-quot foo c-type-boxer-quot = ] unit-test
+{ t } [ c-string lookup-c-type c-string lookup-c-type = ] unit-test
 
-[ t ] [ foo heap-size int heap-size = ] unit-test
+{ t } [ foo heap-size int heap-size = ] unit-test
 
 TYPEDEF: int MyInt
 
-[ t ] [ int   c-type          MyInt c-type eq? ] unit-test
-[ t ] [ void* c-type pointer: MyInt c-type eq? ] unit-test
-
-[ 32 ] [ { int 8 } heap-size ] unit-test
+{ t } [ int   lookup-c-type          MyInt lookup-c-type = ] unit-test
+{ t } [ void* lookup-c-type pointer: MyInt lookup-c-type = ] unit-test
 
-TYPEDEF: char* MyString
+{ 32 } [ { int 8 } heap-size ] unit-test
 
-[ t ] [ c-string c-type MyString          c-type eq? ] unit-test
-[ t ] [ void*    c-type pointer: MyString c-type eq? ] unit-test
+{ } [ pointer: { int 8 } heap-size pointer: void heap-size assert= ] unit-test
 
-TYPEDEF: int* MyIntArray
+TYPEDEF: char MyChar
 
-[ t ] [ void* c-type MyIntArray c-type eq? ] unit-test
+{ t } [ pointer: void lookup-c-type pointer: MyChar lookup-c-type = ] unit-test
 
-TYPEDEF: c-string MyLPBYTE
+TYPEDEF: { c-string ascii } MyFunkyString
 
-[ t ] [ { c-string utf8 } c-type MyLPBYTE c-type = ] unit-test
+{ { c-string ascii } } [ MyFunkyString lookup-c-type ] unit-test
 
-[
-    0 B{ 1 2 3 4 } <displaced-alien> <void*>
-] must-fail
+TYPEDEF: c-string MyString
 
-C-TYPE: MyOpaqueType
+{ t } [ c-string lookup-c-type MyString          lookup-c-type = ] unit-test
+{ t } [ void* lookup-c-type pointer: MyString lookup-c-type = ] unit-test
 
-[ f ] [ pointer: MyOpaqueType c-type void* c-type eq? ] unit-test
+TYPEDEF: int* MyIntArray
 
-os windows? cpu x86.64? and [
-    [ -2147467259 ] [ 2147500037 <long> *long ] unit-test
-] when
+{ t } [ void* lookup-c-type MyIntArray lookup-c-type = ] unit-test
 
-[ 0 ] [ -10 uchar c-type-clamp ] unit-test
-[ 12 ] [ 12 uchar c-type-clamp ] unit-test
-[ -10 ] [ -10 char c-type-clamp ] unit-test
-[ 127 ] [ 230 char c-type-clamp ] unit-test
-[ t ] [ pi dup float c-type-clamp = ] unit-test
+{ 0 } [ -10 uchar c-type-clamp ] unit-test
+{ 12 } [ 12 uchar c-type-clamp ] unit-test
+{ -10 } [ -10 char c-type-clamp ] unit-test
+{ 127 } [ 230 char c-type-clamp ] unit-test
+{ t } [ pi dup float c-type-clamp = ] unit-test
 
 C-TYPE: opaque
 
-[ t ] [ void* c-type opaque resolve-pointer-type c-type eq? ] unit-test
-[ opaque c-type ] [ no-c-type? ] must-fail-with
+{ 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* } ;
 STRUCT: forward { x backward* } ;
 
-[ t ] [ forward c-type struct-c-type? ] unit-test
-[ t ] [ backward c-type struct-c-type? ] unit-test
+{ t } [ forward lookup-c-type struct-c-type? ] unit-test
+{ t } [ backward lookup-c-type struct-c-type? ] unit-test
 
 DEFER: struct-redefined
 
-[ f ]
+{ 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
@@ -115,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( -- )