source: trunk/test/color_test.cc @ 1127

Last change on this file since 1127 was 1127, checked in by Peter Johansson, 11 years ago

updating copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1// $Id: color_test.cc 1127 2010-07-15 22:01:38Z peter $
2
3/*
4  Copyright (C) 2009 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2010 Peter Johansson
6
7  This file is part of svndigest, http://dev.thep.lu.se/svndigest
8
9  svndigest is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 3 of the License, or
12  (at your option) any later version.
13
14  svndigest is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "lib/Colors.h"
24
25#include <iostream>
26#include <sstream>
27
28int main(int argc, char* argv[])
29{
30  using namespace theplu::svndigest;
31  bool ok=true;
32
33  // The loop adds new authors to the author color map until all
34  // colors are use. The color map contains 12 colors and black
35  // (total 13). The loop is 14 iterations and therefore the first
36  // color is reused for the last author. This test checks that
37  // colors are reused. If the color map size changes, then the loop
38  // must be adjusted accordingly
39  unsigned char r_first, g_first, b_first;
40  r_first = g_first = b_first = '\0';
41  unsigned char r, g, b;
42  for (unsigned int i=0; i<14; ++i) {
43    std::stringstream ss;
44    ss << i;
45    Colors::instance().get_color(ss.str(), r, g, b);
46    if (!i) r_first=r, g_first=g, b_first=b;  // remember first color
47  }
48  // Test first and last color, expected to be the same.
49  if (r!=r_first || g!=g_first || b!=b_first) {
50    ok=false;
51    std::cerr << "Expected r,g,b "
52              << static_cast<int>(r_first) << ','
53              << static_cast<int>(g_first) << ','
54              << static_cast<int>(b_first) << std::endl;
55    std::cerr << "     got r,g,b "
56              << static_cast<int>(r) << ','
57              << static_cast<int>(g) << ','
58              << static_cast<int>(b) << std::endl;
59  }
60
61  if (ok)
62    return 0;
63  return -1;
64}
Note: See TracBrowser for help on using the repository browser.