summaryrefslogtreecommitdiff
path: root/lib/erl_interface/test/erl_format_SUITE_data
diff options
context:
space:
mode:
Diffstat (limited to 'lib/erl_interface/test/erl_format_SUITE_data')
-rw-r--r--lib/erl_interface/test/erl_format_SUITE_data/Makefile.first21
-rw-r--r--lib/erl_interface/test/erl_format_SUITE_data/Makefile.src43
-rw-r--r--lib/erl_interface/test/erl_format_SUITE_data/format_test.c132
3 files changed, 196 insertions, 0 deletions
diff --git a/lib/erl_interface/test/erl_format_SUITE_data/Makefile.first b/lib/erl_interface/test/erl_format_SUITE_data/Makefile.first
new file mode 100644
index 0000000000..2cd313a324
--- /dev/null
+++ b/lib/erl_interface/test/erl_format_SUITE_data/Makefile.first
@@ -0,0 +1,21 @@
+#
+# %CopyrightBegin%
+#
+# Copyright Ericsson AB 2000-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%
+#
+
+format_test_decl.c: format_test.c
+ erl -noinput -pa ../all_SUITE_data -s init_tc run format_test -s erlang halt
diff --git a/lib/erl_interface/test/erl_format_SUITE_data/Makefile.src b/lib/erl_interface/test/erl_format_SUITE_data/Makefile.src
new file mode 100644
index 0000000000..0cd1ab512d
--- /dev/null
+++ b/lib/erl_interface/test/erl_format_SUITE_data/Makefile.src
@@ -0,0 +1,43 @@
+#
+# %CopyrightBegin%
+#
+# Copyright Ericsson AB 1997-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@@DS@eidefs.mk
+
+CC0 = @CC@
+CC = ..@DS@all_SUITE_data@DS@gccifier@exe@ -CC"$(CC0)"
+LD = @LD@
+LIBPATH = @erl_interface_libpath@
+LIBERL = $(LIBPATH)/@erl_interface_lib@
+LIBEI = $(LIBPATH)/@erl_interface_eilib@
+LIBFLAGS = ../all_SUITE_data/runner@obj@ \
+ $(LIBERL) $(LIBEI) @LIBS@ @erl_interface_sock_libs@ \
+ @erl_interface_threadlib@
+CFLAGS = @EI_CFLAGS@ $(THR_DEFS) -I@erl_interface_include@ -I../all_SUITE_data
+FORMAT_OBJS = format_test@obj@ format_test_decl@obj@
+
+all: format_test@exe@
+
+clean:
+ $(RM) $(FORMAT_OBJS)
+ $(RM) format_test@exe@
+
+format_test@exe@: $(FORMAT_OBJS) $(LIBERL) $(LIBEI)
+ $(LD) @CROSSLDFLAGS@ -o $@ $(FORMAT_OBJS) $(LIBFLAGS)
+
+
diff --git a/lib/erl_interface/test/erl_format_SUITE_data/format_test.c b/lib/erl_interface/test/erl_format_SUITE_data/format_test.c
new file mode 100644
index 0000000000..75e73b6df5
--- /dev/null
+++ b/lib/erl_interface/test/erl_format_SUITE_data/format_test.c
@@ -0,0 +1,132 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1997-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 "runner.h"
+
+/*
+ * Purpose: Tests the erl_format() function.
+ * Author: Bjorn Gustavsson
+ */
+
+static void
+send_format(char* format)
+{
+ send_term(erl_format(format));
+}
+
+TESTCASE(atoms)
+{
+ erl_init(NULL, 0);
+
+ send_format("''");
+ send_format("'a'");
+ send_format("'A'");
+ send_format("'abc'");
+ send_format("'Abc'");
+ send_format("'ab@c'");
+ send_format("'The rain in Spain stays mainly in the plains'");
+
+ send_format("a");
+ send_format("ab");
+ send_format("abc");
+ send_format("ab@c");
+ send_format(" abcdefghijklmnopq ");
+
+ send_term(erl_format("~a", ""));
+ send_term(erl_format("~a", "a"));
+ send_term(erl_format("~a", "A"));
+ send_term(erl_format("~a", "abc"));
+ send_term(erl_format("~a", "Abc"));
+ send_term(erl_format("~a", "ab@c"));
+ send_term(erl_format("~a", "The rain in Spain stays mainly in the plains"));
+
+ send_term(erl_format("~a", "a"));
+ send_term(erl_format("~a", "ab"));
+ send_term(erl_format("~a", "abc"));
+ send_term(erl_format("~a","ab@c"));
+ send_term(erl_format("~a", " abcdefghijklmnopq "));
+
+
+ report(1);
+}
+
+TESTCASE(tuples)
+{
+ erl_init(NULL, 0);
+
+ send_format("{}");
+ send_format("{a}");
+ send_format("{a, b}");
+ send_format("{a, b, c}");
+ send_format("{1}");
+ send_format("{[]}");
+ send_format("{[], []}");
+ send_format("{[], a, b, c}");
+ send_format("{[], a, [], b, c}");
+ send_format("{[], a, '', b, c}");
+
+ report(1);
+}
+
+
+
+TESTCASE(lists)
+{
+ ETERM* a;
+ ETERM* b;
+ ETERM* c;
+
+ erl_init(NULL, 0);
+
+ send_format("[]");
+ send_format("[a]");
+ send_format("[a, b]");
+ send_format("[a, b, c]");
+ send_format("[1]");
+ send_format("[[]]");
+ send_format("[[], []]");
+ send_format("[[], a, b, c]");
+ send_format("[[], a, [], b, c]");
+ send_format("[[], a, '', b, c]");
+
+ b = erl_format("[{addr, ~s, ~i}]", "E-street", 42);
+ a = erl_format("[{name, ~a}, {age, ~i}, {data, ~w}]", "Madonna", 21, b);
+ send_term(a);
+ erl_free_term(b);
+
+ send_term(erl_format("[{pi, ~f}, {'cos(70)', ~f}]", 3.1415, 0.34202));
+
+ a = erl_mk_float(3.1415);
+ b = erl_mk_float(0.34202);
+ send_term(erl_format("[[pi, ~w], ['cos(70)', ~w]]", a, b));
+ erl_free_term(a);
+ erl_free_term(b);
+
+ a = erl_mk_float(3.1415);
+ b = erl_mk_float(0.34202);
+ c = erl_mk_empty_list();
+ send_term(erl_format("[[~a, ~w], ~w, [~s, ~w]]", "pi", a, c, "cos(70)", b));
+ erl_free_term(a);
+ erl_free_term(b);
+ erl_free_term(c);
+
+ send_term(erl_format("[~i]", -1));
+
+ report(1);
+}