summaryrefslogtreecommitdiff
path: root/libicui18n/tests/basic/driver.cpp
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 /libicui18n/tests/basic/driver.cpp
parentbda94b275036150b568364fe3e5f96e04ed41fc3 (diff)
Add implementation
Diffstat (limited to 'libicui18n/tests/basic/driver.cpp')
-rw-r--r--libicui18n/tests/basic/driver.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/libicui18n/tests/basic/driver.cpp b/libicui18n/tests/basic/driver.cpp
new file mode 100644
index 0000000..f9bf704
--- /dev/null
+++ b/libicui18n/tests/basic/driver.cpp
@@ -0,0 +1,85 @@
+// file : tests/basic/driver.cpp
+// copyright : Copyright (c) 2009-2019 Code Synthesis Tools CC
+// license : Unicode License; see accompanying LICENSE file
+
+#include <string>
+#include <memory> // unique_ptr
+#include <cassert>
+#include <iostream>
+#include <stdexcept> // runtime_error
+
+#include <unicode/utypes.h>
+#include <unicode/uclean.h>
+
+#include <unicode/datefmt.h>
+#include <unicode/calendar.h>
+#include <unicode/timezone.h>
+#include <unicode/bytestream.h>
+
+// Usage: argv[0] <locale>
+//
+// Print the full 01/01/2020 00:00 time in Berlin's timezone using the
+// specified locale.
+//
+int
+main (int argc, char* argv[])
+{
+ using namespace std;
+ using namespace icu;
+
+ assert (argc == 2);
+ const char* locale (argv[1]);
+
+ UErrorCode e (U_ZERO_ERROR);
+
+ auto validate = [&e] (const char* what)
+ {
+ if (U_FAILURE (e))
+ throw runtime_error (string (what) + " failed: " + u_errorName (e));
+ };
+
+ int r (0);
+
+ try
+ {
+ unique_ptr<Calendar> cal (Calendar::createInstance (e));
+ validate ("Calendar::createInstance()");
+
+ cal->adoptTimeZone (TimeZone::createTimeZone ("Europe/Berlin"));
+ cal->clear ();
+ cal->set (2020, Calendar::JANUARY, 1);
+
+ UDate date (cal->getTime (e));
+ validate ("Calendar::getTime()");
+
+ unique_ptr<DateFormat> fmt (
+ DateFormat::createDateTimeInstance (DateFormat::kFull,
+ DateFormat::kFull,
+ locale));
+
+ fmt->setCalendar (*cal);
+
+ UnicodeString us;
+ fmt->format(date, us, e);
+ validate ("DateFormat::format()");
+
+ string s;
+ StringByteSink<string> bs (&s);
+ us.toUTF8 (bs);
+
+ cout << s << 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;
+}