2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <boost/test/unit_test.hpp>
27 /** Test dcp::base64_decode */
28 BOOST_AUTO_TEST_CASE (base64_decode_test)
32 ifstream f ("test/data/base64_test");
33 BOOST_CHECK (f.good ());
41 ifstream g ("test/ref/base64_test_decoded", std::ios::binary);
42 BOOST_CHECK (g.good ());
43 unsigned char ref_decoded[N];
44 for (int i = 0; i < N; ++i) {
47 ref_decoded[i] = static_cast<unsigned char> (c);
50 unsigned char decoded[N];
51 int const r = dcp::base64_decode (s, decoded, N);
52 BOOST_CHECK_EQUAL (r, N);
54 for (int i = 0; i < N; ++i) {
55 BOOST_CHECK_EQUAL (decoded[i], ref_decoded[i]);
59 /** Test dcp::content_kind_from_string */
60 BOOST_AUTO_TEST_CASE (content_kind_test)
62 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("feature"), dcp::FEATURE);
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 ("Short"), dcp::SHORT);
66 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("trailer"), dcp::TRAILER);
67 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("test"), dcp::TEST);
68 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("transitional"), dcp::TRANSITIONAL);
69 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("rating"), dcp::RATING);
70 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("teaser"), dcp::TEASER);
71 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("policy"), dcp::POLICY);
72 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("psa"), dcp::PUBLIC_SERVICE_ANNOUNCEMENT);
73 BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("advertisement"), dcp::ADVERTISEMENT);
76 /** Test dcp::relative_to_root */
77 BOOST_AUTO_TEST_CASE (relative_to_root_test)
80 boost::filesystem::path root = "a";
83 boost::filesystem::path file = "a";
87 boost::optional<boost::filesystem::path> rel = dcp::relative_to_root (root, file);
89 BOOST_CHECK_EQUAL (rel.get(), boost::filesystem::path ("c"));
93 boost::filesystem::path root = "a";
97 boost::filesystem::path file = "a";
100 boost::optional<boost::filesystem::path> rel = dcp::relative_to_root (root, file);
105 boost::filesystem::path root = "a";
107 boost::filesystem::path file = "a";
111 boost::optional<boost::filesystem::path> rel = dcp::relative_to_root (root, file);
114 boost::filesystem::path check = "b";
116 BOOST_CHECK_EQUAL (rel.get(), check);
120 /** Test private_key_fingerprint() */
121 BOOST_AUTO_TEST_CASE (private_key_fingerprint_test)
123 BOOST_CHECK_EQUAL (dcp::private_key_fingerprint (dcp::file_to_string ("test/data/private.key")), "Jdz1bFpCcKI7R16Ccx9JHYytag0=");