Basics of allowing custom filenames for DCP components.
[libdcp.git] / test / colour_test.cc
1 /*
2     Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
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.
10
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.
15
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/>.
18 */
19
20 #include "util.h"
21 #include "exceptions.h"
22 #include <locked_sstream.h>
23 #include <boost/test/unit_test.hpp>
24
25 /** Check that dcp::Colour works */
26 BOOST_AUTO_TEST_CASE (colour)
27 {
28         dcp::Colour z;
29
30         BOOST_CHECK_EQUAL (z.r, 0);
31         BOOST_CHECK_EQUAL (z.g, 0);
32         BOOST_CHECK_EQUAL (z.b, 0);
33         BOOST_CHECK_EQUAL (z.to_argb_string(), "FF000000");
34
35         dcp::Colour c ("FFFF0000");
36
37         BOOST_CHECK_EQUAL (c.r, 255);
38         BOOST_CHECK_EQUAL (c.g, 0);
39         BOOST_CHECK_EQUAL (c.b, 0);
40         BOOST_CHECK_EQUAL (c.to_argb_string(), "FFFF0000");
41
42         dcp::Colour d = dcp::Colour ("FF00FF00");
43
44         BOOST_CHECK_EQUAL (d.r, 0);
45         BOOST_CHECK_EQUAL (d.g, 255);
46         BOOST_CHECK_EQUAL (d.b, 0);
47         BOOST_CHECK_EQUAL (d.to_argb_string(), "FF00FF00");
48
49         dcp::Colour e = dcp::Colour ("FF0000FF");
50
51         BOOST_CHECK_EQUAL (e.r, 0);
52         BOOST_CHECK_EQUAL (e.g, 0);
53         BOOST_CHECK_EQUAL (e.b, 255);
54         BOOST_CHECK_EQUAL (e.to_argb_string(), "FF0000FF");
55
56         BOOST_CHECK (c != d);
57
58         BOOST_CHECK_THROW (dcp::Colour ("001234"), dcp::XMLError);
59
60         locked_stringstream s;
61         s << c;
62         BOOST_CHECK_EQUAL (s.str(), "(255, 0, 0)");
63 }