diff options
author | Björn-Egil Dahlberg <[email protected]> | 2009-12-15 10:33:33 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2009-12-15 12:24:17 +0100 |
commit | fe272a8454d2379c2ed5b0f9f04b493574316a8d (patch) | |
tree | 38e09b9529109886886241b03a20f589c3559d04 /lib/erl_interface/test/ei_print_SUITE_data | |
parent | de4639e46760493bad61ae48a5d894001216720e (diff) | |
download | otp-fe272a8454d2379c2ed5b0f9f04b493574316a8d.tar.gz otp-fe272a8454d2379c2ed5b0f9f04b493574316a8d.tar.bz2 otp-fe272a8454d2379c2ed5b0f9f04b493574316a8d.zip |
Include the test suites for erl_interface
Diffstat (limited to 'lib/erl_interface/test/ei_print_SUITE_data')
3 files changed, 238 insertions, 0 deletions
diff --git a/lib/erl_interface/test/ei_print_SUITE_data/Makefile.first b/lib/erl_interface/test/ei_print_SUITE_data/Makefile.first new file mode 100644 index 0000000000..e36d4364dc --- /dev/null +++ b/lib/erl_interface/test/ei_print_SUITE_data/Makefile.first @@ -0,0 +1,21 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2001-2009. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved online at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# %CopyrightEnd% +# + +ei_print_test_decl.c: ei_print_test.c + erl -noinput -pa ../all_SUITE_data -s init_tc run ei_print_test -s erlang halt diff --git a/lib/erl_interface/test/ei_print_SUITE_data/Makefile.src b/lib/erl_interface/test/ei_print_SUITE_data/Makefile.src new file mode 100644 index 0000000000..6eec4b1990 --- /dev/null +++ b/lib/erl_interface/test/ei_print_SUITE_data/Makefile.src @@ -0,0 +1,42 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 2001-2009. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved online at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# %CopyrightEnd% +# + +include @erl_interface_mk_include@@[email protected] + +CC0 = @CC@ +CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)" +LD = @LD@ +LIBPATH = @erl_interface_libpath@ +LIBEI = $(LIBPATH)/@erl_interface_eilib@ +LIBFLAGS = ../all_SUITE_data/ei_runner@obj@ \ + $(LIBEI) @LIBS@ @erl_interface_sock_libs@ \ + @erl_interface_threadlib@ +CFLAGS = @EI_CFLAGS@ $(THR_DEFS) -I@erl_interface_include@ -I../all_SUITE_data +EI_PRINT_OBJS = ei_print_test@obj@ ei_print_test_decl@obj@ + +all: ei_print_test@exe@ + +clean: + $(RM) $(EI_PRINT_OBJS) + $(RM) ei_print_test@exe@ + +ei_print_test@exe@: $(EI_PRINT_OBJS) $(LIBEI) + $(LD) @CROSSLDFLAGS@ -o $@ $(EI_PRINT_OBJS) $(LIBFLAGS) + + diff --git a/lib/erl_interface/test/ei_print_SUITE_data/ei_print_test.c b/lib/erl_interface/test/ei_print_SUITE_data/ei_print_test.c new file mode 100644 index 0000000000..cc9b8048ca --- /dev/null +++ b/lib/erl_interface/test/ei_print_SUITE_data/ei_print_test.c @@ -0,0 +1,175 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 2001-2009. All Rights Reserved. + * + * The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved online at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * %CopyrightEnd% + */ + +#include "ei_runner.h" + +/* + * Purpose: Tests the ei_print() function. + * Author: Jakob + */ + +static void +send_printed3(char* format, char* p1, char* p2, int fl) +{ + char* b = NULL; + char fn[100], * tmp = getenv("temp"); + FILE* f; + int n, index = 0, ver; + ei_x_buff x; + + ei_x_new(&x); + if (fl) { + ei_x_format(&x, format, *(float*)p1, *(float*)p2); + } else { + ei_x_format(&x, format, p1, p2); + } +#ifdef VXWORKS + tmp = "."; +#else + if (tmp == NULL) tmp = "/tmp"; +#endif + strcpy(fn, tmp); + strcat(fn, "/ei_print_test.txt"); + f = fopen(fn, "w+"); + ei_decode_version(x.buff, &index, &ver); + n = ei_print_term(f, x.buff, &index); + fseek(f, 0, SEEK_SET); + b = malloc(n+1); + fread(b, 1, n, f); + b[n] = '\0'; + fclose(f); + x.index = 0; + ei_x_format(&x, "~s", b); + send_bin_term(&x); + free(b); + ei_x_free(&x); +} + +static void +send_printed(char* format) +{ + send_printed3(format, NULL, NULL, 0); +} + +static void +send_printed2(char* format, char* p) +{ + send_printed3(format, p, NULL, 0); +} + +static void send_printed3f(char* format, float f1, float f2) +{ + send_printed3(format, (char*)&f1, (char*)&f2, 1); +} + +TESTCASE(atoms) +{ + send_printed("''"); + send_printed("'a'"); + send_printed("'A'"); + send_printed("'abc'"); + send_printed("'Abc'"); + send_printed("'ab@c'"); + send_printed("'The rain in Spain stays mainly in the plains'"); + + send_printed("a"); + send_printed("ab"); + send_printed("abc"); + send_printed("ab@c"); + send_printed(" abcdefghijklmnopq "); + + send_printed2("~a", ""); + send_printed2("~a", "a"); + send_printed2("~a", "A"); + send_printed2("~a", "abc"); + send_printed2("~a", "Abc"); + send_printed2("~a", "ab@c"); + send_printed2("~a", "The rain in Spain stays mainly in the plains"); + + send_printed2("~a", "a"); + send_printed2("~a", "ab"); + send_printed2("~a", "abc"); + send_printed2("~a","ab@c"); + send_printed2("~a", " abcdefghijklmnopq "); + + + report(1); +} + +TESTCASE(tuples) +{ + send_printed("{}"); + send_printed("{a}"); + send_printed("{a, b}"); + send_printed("{a, b, c}"); + send_printed("{1}"); + send_printed("{[]}"); + send_printed("{[], []}"); + send_printed("{[], a, b, c}"); + send_printed("{[], a, [], b, c}"); + send_printed("{[], a, '', b, c}"); + + report(1); +} + + + +TESTCASE(lists) +{ + ei_x_buff x; + + send_printed("[]"); + send_printed("[a]"); + send_printed("[a, b]"); + send_printed("[a, b, c]"); + send_printed("[1]"); + send_printed("[[]]"); + send_printed("[[], []]"); + send_printed("[[], a, b, c]"); + send_printed("[[], a, [], b, c]"); + send_printed("[[], a, '', b, c]"); + send_printed("[[x, 2], [y, 3], [z, 4]]"); + + /* more tests needed */ + send_printed3f("[{pi, ~f}, {'cos(70)', ~f}]", + (float)3.1415, (float)0.34202); + send_printed3f("[[pi, ~f], ['cos(70)', ~f]]", + (float)3.1415, (float)0.34202); + + send_printed2("[~i]", (char*)-1); + report(1); +} + +TESTCASE(strings) +{ + ei_x_buff x; + + send_printed("\"\n\""); + send_printed("\"\r\n\""); + send_printed("\"a\""); + send_printed("\"A\""); + send_printed("\"0\""); + send_printed("\"9\""); + send_printed("\"The rain in Spain stays mainly in the plains\""); + send_printed("\" abcdefghijklmnopq \""); + + report(1); +} + + |