summaryrefslogtreecommitdiff
path: root/test/util_test.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-08 19:00:15 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-08 19:00:15 +0100
commit62f94281437fc54f4806cc65e3aecca5cd118f7c (patch)
treebbb44c0266b21f112f4a6d4f64e777d6894b2e8e /test/util_test.cc
parent321d1b056040a472aba7ac43dc4938087124ec2e (diff)
Use openssl's base-64 decoding for KDMs.
Diffstat (limited to 'test/util_test.cc')
-rw-r--r--test/util_test.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/util_test.cc b/test/util_test.cc
new file mode 100644
index 00000000..fa873c75
--- /dev/null
+++ b/test/util_test.cc
@@ -0,0 +1,53 @@
+/*
+ Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <fstream>
+
+using std::ifstream;
+
+BOOST_AUTO_TEST_CASE (bsae64_decode_test)
+{
+ int const N = 256;
+
+ ifstream f ("test/data/base64_test");
+ BOOST_CHECK (f.good ());
+ string s;
+ while (f.good ()) {
+ string l;
+ getline (f, l);
+ s += l;
+ }
+
+ ifstream g ("test/ref/base64_test_decoded", std::ios::binary);
+ BOOST_CHECK (g.good ());
+ unsigned char ref_decoded[N];
+ for (int i = 0; i < N; ++i) {
+ char c;
+ g.get (c);
+ ref_decoded[i] = static_cast<unsigned char> (c);
+ }
+
+ unsigned char decoded[N];
+ int const r = libdcp::base64_decode (s, decoded, N);
+ BOOST_CHECK_EQUAL (r, N);
+
+ for (int i = 0; i < N; ++i) {
+ BOOST_CHECK_EQUAL (decoded[i], ref_decoded[i]);
+ }
+}