From 67c7df2653ca81a8b91bbd48f24dfe99f30e0495 Mon Sep 17 00:00:00 2001 From: Jeremy Hughes Date: Wed, 15 Jul 2009 16:43:42 +1200 Subject: [PATCH] alien.marshall.syntax: add more tests --- .../alien/marshall/syntax/syntax-tests.factor | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/extra/alien/marshall/syntax/syntax-tests.factor b/extra/alien/marshall/syntax/syntax-tests.factor index fe62e6d334..6ea6488167 100644 --- a/extra/alien/marshall/syntax/syntax-tests.factor +++ b/extra/alien/marshall/syntax/syntax-tests.factor @@ -7,12 +7,17 @@ IN: alien.marshall.syntax.tests DELETE-C-LIBRARY: test C-LIBRARY: test +C-INCLUDE: +C-INCLUDE: + +C-TYPEDEF: char bool + CM-FUNCTION: void outarg1 ( int* a ) *a += 2; ; CM-FUNCTION: unsigned-long* outarg2 ( unsigned-long a, unsigned-long* b ) - unsigned long* x = (unsigned long*) malloc(sizeof(unsigned long)); + unsigned long* x = malloc(sizeof(unsigned long*)); *b = 10 + *b; *x = a + *b; return x; @@ -33,10 +38,26 @@ CM-FUNCTION: void change_time ( double hours, sundial* d ) d->wedge.degrees = hours * 30; ; +CM-FUNCTION: bool c_not ( bool p ) + return !p; +; + +CM-FUNCTION: char* upcase ( const-char* s ) + int len = strlen(s); + char* t = malloc(sizeof(char) * len); + int i; + for (i = 0; i < len; i++) + t[i] = toupper(s[i]); + t[i] = '\0'; + return t; +; + ;C-LIBRARY { 1 1 } [ outarg1 ] must-infer-as [ 3 ] [ 1 outarg1 ] unit-test +[ 3 ] [ t outarg1 ] unit-test +[ 2 ] [ f outarg1 ] unit-test { 2 2 } [ outarg2 ] must-infer-as [ 18 15 ] [ 3 5 outarg2 ] unit-test @@ -46,3 +67,10 @@ CM-FUNCTION: void change_time ( double hours, sundial* d ) { 2 0 } [ change_time ] must-infer-as [ 150.0 ] [ 5 11 >>degrees >>wedge [ change_time ] keep wedge>> degrees>> ] unit-test + +{ 1 1 } [ c_not ] must-infer-as +[ f ] [ "x" c_not ] unit-test +[ f ] [ 0 c_not ] unit-test + +{ 1 1 } [ upcase ] must-infer-as +[ "ABC" ] [ "abc" upcase ] unit-test