summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-08-11 14:12:51 +0100
committerCarl Hetherington <cth@carlh.net>2016-08-11 14:12:51 +0100
commitb80f65a2f7cf3e8a02fe0ad8bebb19640f63b5d2 (patch)
tree94389a7abda5f60e4a888e68984d7015aa81b224 /test
parent4e2d5cca82d19246bd1ebf24bc9e2bf436232f83 (diff)
Add locale_convert. Reimplement raw_convert without stringstream.
Diffstat (limited to 'test')
-rw-r--r--test/raw_convert_test.cc79
-rw-r--r--test/wscript1
2 files changed, 80 insertions, 0 deletions
diff --git a/test/raw_convert_test.cc b/test/raw_convert_test.cc
new file mode 100644
index 00000000..c48ccb0c
--- /dev/null
+++ b/test/raw_convert_test.cc
@@ -0,0 +1,79 @@
+/*
+ Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of libdcp.
+
+ libdcp is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ libdcp is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libdcp. If not, see <http://www.gnu.org/licenses/>.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations
+ including the two.
+
+ You must obey the GNU General Public License in all respects
+ for all of the code used other than OpenSSL. If you modify
+ file(s) with this exception, you may extend this exception to your
+ version of the file(s), but you are not obligated to do so. If you
+ do not wish to do so, delete this exception statement from your
+ version. If you delete this exception statement from all source
+ files in the program, then also delete it here.
+*/
+
+#include "raw_convert.h"
+#include "locale_convert.h"
+#include <boost/test/unit_test.hpp>
+#include <iostream>
+
+using std::string;
+
+BOOST_AUTO_TEST_CASE (raw_convert_test)
+{
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (1), "1");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (12), "12");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (12.3), "12.3");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (12.34), "12.34");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (.34), "0.34");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (-.34), "-0.34");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (0.157123125), "0.157123125");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (0.157123125, 4), "0.1571");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (1e50), "1e+50");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (1e-50), "1e-50");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (1.5e12), "1500000000000");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (0.0086), "0.0086");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (0.00086), "0.00086");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (0.000086), "8.6e-05");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> (0.000086, 10, true), "0.0000860000");
+
+ BOOST_CHECK_EQUAL (dcp::raw_convert<int> ("42"), 42);
+ BOOST_CHECK_EQUAL (dcp::raw_convert<int> ("42.3"), 42);
+ BOOST_CHECK_EQUAL (dcp::raw_convert<int> ("42.7"), 42);
+
+ BOOST_CHECK_EQUAL (dcp::raw_convert<double> ("42"), 42);
+ BOOST_CHECK_EQUAL (dcp::raw_convert<double> ("42.3"), 42.3);
+ BOOST_CHECK_EQUAL (dcp::raw_convert<double> ("42.7"), 42.7);
+ BOOST_CHECK_EQUAL (dcp::raw_convert<double> ("4e8"), 4e8);
+ BOOST_CHECK_EQUAL (dcp::raw_convert<double> ("9.1e9"), 9.1e9);
+ BOOST_CHECK_EQUAL (dcp::raw_convert<double> ("0.005"), 0.005);
+
+ BOOST_CHECK_CLOSE (dcp::raw_convert<float> ("42"), 42, 0.001);
+ BOOST_CHECK_CLOSE (dcp::raw_convert<float> ("42.3"), 42.3, 0.001);
+ BOOST_CHECK_CLOSE (dcp::raw_convert<float> ("42.7"), 42.7, 0.001);
+ BOOST_CHECK_CLOSE (dcp::raw_convert<float> ("4e8"), 4e8, 0.001);
+ BOOST_CHECK_CLOSE (dcp::raw_convert<float> ("9.1e9"), 9.1e9, 0.001);
+ BOOST_CHECK_CLOSE (dcp::raw_convert<float> ("0.005"), 0.005, 0.001);
+
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> ("foo"), "foo");
+ BOOST_CHECK_EQUAL (dcp::raw_convert<string> ("foo bar"), "foo bar");
+}
diff --git a/test/wscript b/test/wscript
index b56de9cb..7c84d982 100644
--- a/test/wscript
+++ b/test/wscript
@@ -81,6 +81,7 @@ def build(bld):
local_time_test.cc
make_digest_test.cc
kdm_test.cc
+ raw_convert_test.cc
read_dcp_test.cc
read_interop_subtitle_test.cc
read_smpte_subtitle_test.cc