source: trunk/test/color_test.cc @ 1162

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

new function exit_status in Suite and use it in all C++ tests

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1// $Id: color_test.cc 1162 2010-08-13 17:30:03Z 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 "Suite.h"
24
25#include "lib/Colors.h"
26
27#include <iostream>
28#include <sstream>
29
30int main(int argc, char* argv[])
31{
32  using namespace theplu::svndigest;
33  test::Suite suite(argc, argv);
34
35  // The loop adds new authors to the author color map until all
36  // colors are use. The color map contains 12 colors and black
37  // (total 13). The loop is 14 iterations and therefore the first
38  // color is reused for the last author. This test checks that
39  // colors are reused. If the color map size changes, then the loop
40  // must be adjusted accordingly
41  unsigned char r_first, g_first, b_first;
42  r_first = g_first = b_first = '\0';
43  unsigned char r, g, b;
44  for (unsigned int i=0; i<14; ++i) {
45    std::stringstream ss;
46    ss << i;
47    Colors::instance().get_color(ss.str(), r, g, b);
48    if (!i) r_first=r, g_first=g, b_first=b;  // remember first color
49  }
50  // Test first and last color, expected to be the same.
51  if (r!=r_first || g!=g_first || b!=b_first) {
52    suite.add(false);
53    std::cerr << "Expected r,g,b "
54              << static_cast<int>(r_first) << ','
55              << static_cast<int>(g_first) << ','
56              << static_cast<int>(b_first) << std::endl;
57    std::cerr << "     got r,g,b "
58              << static_cast<int>(r) << ','
59              << static_cast<int>(g) << ','
60              << static_cast<int>(b) << std::endl;
61  }
62
63 
64  return suite.exit_status();
65}
Note: See TracBrowser for help on using the repository browser.