summaryrefslogtreecommitdiff
path: root/libicuio/tests
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-12-26 23:05:57 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-01-27 22:47:56 +0300
commit7f235e1d24ce525a2bd032cefa82d96ccfdc8a19 (patch)
treeb0df84d85c53aae6718e76af8ce3bdd557270f0c /libicuio/tests
parentbda94b275036150b568364fe3e5f96e04ed41fc3 (diff)
Add implementation
Diffstat (limited to 'libicuio/tests')
-rw-r--r--libicuio/tests/.gitignore3
-rw-r--r--libicuio/tests/basic/buildfile8
-rw-r--r--libicuio/tests/basic/driver.cpp90
-rw-r--r--libicuio/tests/basic/testscript8
-rw-r--r--libicuio/tests/build/.gitignore3
-rw-r--r--libicuio/tests/build/bootstrap.build9
-rw-r--r--libicuio/tests/build/root.build24
-rw-r--r--libicuio/tests/buildfile5
8 files changed, 150 insertions, 0 deletions
diff --git a/libicuio/tests/.gitignore b/libicuio/tests/.gitignore
new file mode 100644
index 0000000..2e508a9
--- /dev/null
+++ b/libicuio/tests/.gitignore
@@ -0,0 +1,3 @@
+driver
+test/
+test-*/
diff --git a/libicuio/tests/basic/buildfile b/libicuio/tests/basic/buildfile
new file mode 100644
index 0000000..df0f552
--- /dev/null
+++ b/libicuio/tests/basic/buildfile
@@ -0,0 +1,8 @@
+# file : tests/basic/buildfile
+# copyright : Copyright (c) 2009-2019 Code Synthesis Tools CC
+# license : Unicode License; see accompanying LICENSE file
+
+import libs = libicuio%lib{icuio}
+import libs += libicuuc%lib{icuuc}
+
+exe{driver}: {hxx cxx}{*} $libs testscript
diff --git a/libicuio/tests/basic/driver.cpp b/libicuio/tests/basic/driver.cpp
new file mode 100644
index 0000000..8c87b4b
--- /dev/null
+++ b/libicuio/tests/basic/driver.cpp
@@ -0,0 +1,90 @@
+// file : tests/basic/driver.cpp
+// copyright : Copyright (c) 2009-2019 Code Synthesis Tools CC
+// license : Unicode License; see accompanying LICENSE file
+
+#include <ios>
+#include <string>
+#include <cassert>
+#include <cstdint>
+#include <iostream>
+#include <stdexcept> // runtime_error
+
+#include <unicode/ucnv.h>
+#include <unicode/utypes.h>
+#include <unicode/uclean.h>
+#include <unicode/ustdio.h> // u_strFromUTF8()
+#include <unicode/ustring.h> // u_fprintf(), u_get_stdout()
+
+#include <unicode/unistr.h> // UnicodeString
+#include <unicode/ustream.h> // operator<<(std::ostream)
+
+// Usage: argv[0]
+//
+// Read UTF-8 encoded lines from stdin and print them to stdout using C and
+// C++ APIs.
+//
+int
+main ()
+{
+ using namespace std;
+ using namespace icu;
+
+ ucnv_setDefaultName ("UTF-8");
+
+ cin.exceptions (ios::badbit);
+ cout.exceptions (ios::badbit | ios::failbit);
+
+ int r (0);
+
+ try
+ {
+ for (string l; getline (cin, l); )
+ {
+ // Print using C API.
+ //
+ {
+ // Make sure the converted input string is always NUL-terminated.
+ //
+ UChar buf[1024 + 1];
+ buf[1024] = 0x0;
+
+ int32_t n;
+ UErrorCode e (U_ZERO_ERROR);
+
+ auto validate = [&e] (const char* what)
+ {
+ if (U_FAILURE (e))
+ throw runtime_error (
+ string (what) + " failed: " + u_errorName (e));
+ };
+
+ u_strFromUTF8 (buf, 1024, &n,
+ l.c_str (), static_cast<int32_t> (l.size ()),
+ &e);
+
+ validate ("u_strFromUTF8()");
+
+ assert (n <= 1024);
+
+ u_fprintf (u_get_stdout (), "%S\n", buf);
+ }
+
+ // Print using C++ API.
+ //
+ cout << UnicodeString::fromUTF8 (l) << endl;
+ }
+ }
+ catch (const runtime_error& e)
+ {
+ cerr << e.what () << endl;
+
+ r = 1;
+ }
+
+ // Free any heap storage that has been potentially allocated and held by the
+ // ICU library.
+ //
+ u_cleanup ();
+
+ return r;
+}
diff --git a/libicuio/tests/basic/testscript b/libicuio/tests/basic/testscript
new file mode 100644
index 0000000..1d9ea51
--- /dev/null
+++ b/libicuio/tests/basic/testscript
@@ -0,0 +1,8 @@
+# file : tests/basic/testscript
+# copyright : Copyright (c) 2016-2019 Code Synthesis Ltd
+# license : Unicode License; see accompanying LICENSE file
+
+$* <"Mitteleuropäische Sommerzeit" >>EOO
+Mitteleuropäische Sommerzeit
+Mitteleuropäische Sommerzeit
+EOO
diff --git a/libicuio/tests/build/.gitignore b/libicuio/tests/build/.gitignore
new file mode 100644
index 0000000..4a730a3
--- /dev/null
+++ b/libicuio/tests/build/.gitignore
@@ -0,0 +1,3 @@
+config.build
+root/
+bootstrap/
diff --git a/libicuio/tests/build/bootstrap.build b/libicuio/tests/build/bootstrap.build
new file mode 100644
index 0000000..17797c1
--- /dev/null
+++ b/libicuio/tests/build/bootstrap.build
@@ -0,0 +1,9 @@
+# file : tests/build/bootstrap.build
+# copyright : Copyright (c) 2016-2019 Code Synthesis Ltd
+# license : Unicode License; see accompanying LICENSE file
+
+project = # Unnamed subproject.
+
+using config
+using dist
+using test
diff --git a/libicuio/tests/build/root.build b/libicuio/tests/build/root.build
new file mode 100644
index 0000000..e8283ae
--- /dev/null
+++ b/libicuio/tests/build/root.build
@@ -0,0 +1,24 @@
+# file : tests/build/root.build
+# copyright : Copyright (c) 2016-2019 Code Synthesis Ltd
+# license : Unicode License; see accompanying LICENSE file
+
+cxx.std = 14
+
+using cxx
+
+hxx{*}: extension = h
+cxx{*}: extension = cpp
+
+if ($cxx.target.system == 'win32-msvc')
+ cxx.poptions += -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
+
+if ($cxx.class == 'msvc')
+ cxx.coptions += /wd4251 /wd4275 /wd4800
+
+# Every exe{} in this subproject is by default a test.
+#
+exe{*}: test = true
+
+# Specify the test target for cross-testing.
+#
+test.target = $cxx.target
diff --git a/libicuio/tests/buildfile b/libicuio/tests/buildfile
new file mode 100644
index 0000000..d976635
--- /dev/null
+++ b/libicuio/tests/buildfile
@@ -0,0 +1,5 @@
+# file : tests/buildfile
+# copyright : Copyright (c) 2016-2019 Code Synthesis Ltd
+# license : Unicode License; see accompanying LICENSE file
+
+./: {*/ -build/}