2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
21 #include <boost/test/unit_test.hpp>
28 /** Test dcp::base64_decode */
29 BOOST_AUTO_TEST_CASE (base64_decode_test)
33 ifstream f ("test/data/base64_test");
34 BOOST_CHECK (f.good ());
42 ifstream g ("test/ref/base64_test_decoded", std::ios::binary);
43 BOOST_CHECK (g.good ());
44 unsigned char ref_decoded[N];
45 for (int i = 0; i < N; ++i) {
48 ref_decoded[i] = static_cast<unsigned char> (c);
51 unsigned char decoded[N];
52 int const r = dcp::base64_decode (s, decoded, N);
53 BOOST_CHECK_EQUAL (r, N);
55 for (int i = 0; i < N; ++i) {
56 BOOST_CHECK_EQUAL (decoded[i], ref_decoded[i]);
60 /** Test dcp::content_kind_from_string */
61 BOOST_AUTO_TEST_CASE (content_kind_test)
63 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("feature"), dcp::FEATURE);
64 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("Feature"), dcp::FEATURE);
65 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("FeaturE"), dcp::FEATURE);
66 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("Short"), dcp::SHORT);
67 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("trailer"), dcp::TRAILER);
68 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("test"), dcp::TEST);
69 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("transitional"), dcp::TRANSITIONAL);
70 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("rating"), dcp::RATING);
71 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("teaser"), dcp::TEASER);
72 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("policy"), dcp::POLICY);
73 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("psa"), dcp::PUBLIC_SERVICE_ANNOUNCEMENT);
74 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("advertisement"), dcp::ADVERTISEMENT);
77 /** Test dcp::relative_to_root */
78 BOOST_AUTO_TEST_CASE (relative_to_root_test)
81 boost::filesystem::path root = "a";
84 boost::filesystem::path file = "a";
88 boost::optional<boost::filesystem::path> rel = dcp::relative_to_root (root, file);
90 BOOST_CHECK_EQUAL (rel.get(), boost::filesystem::path ("c"));
94 boost::filesystem::path root = "a";
98 boost::filesystem::path file = "a";
101 boost::optional<boost::filesystem::path> rel = dcp::relative_to_root (root, file);
106 boost::filesystem::path root = "a";
108 boost::filesystem::path file = "a";
112 boost::optional<boost::filesystem::path> rel = dcp::relative_to_root (root, file);
115 boost::filesystem::path check = "b";
117 BOOST_CHECK_EQUAL (rel.get(), check);
121 /** Test private_key_fingerprint() */
122 BOOST_AUTO_TEST_CASE (private_key_fingerprint_test)
124 BOOST_CHECK_EQUAL (dcp::private_key_fingerprint (dcp::file_to_string ("test/data/private.key")), "Jdz1bFpCcKI7R16Ccx9JHYytag0=");
127 BOOST_AUTO_TEST_CASE (unique_string_test)
129 list<string> existing;
130 for (int i = 0; i < 16; i++) {
132 BOOST_CHECK_NO_THROW (s = dcp::unique_string(existing, "foo"));
133 BOOST_CHECK (find(existing.begin(), existing.end(), s) == existing.end());
134 existing.push_back (s);