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