source: trunk/test/color_test.cc @ 1119

Last change on this file since 1119 was 1119, checked in by Peter Johansson, 13 years ago

move lib/yat to yat. close #461

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