[919] | 1 | // $Id: color_test.cc 1127 2010-07-15 22:01:38Z peter $ |
---|
| 2 | |
---|
| 3 | /* |
---|
[978] | 4 | Copyright (C) 2009 Jari Häkkinen, Peter Johansson |
---|
[1127] | 5 | Copyright (C) 2010 Peter Johansson |
---|
[919] | 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 | |
---|
[1119] | 23 | #include "lib/Colors.h" |
---|
[919] | 24 | |
---|
| 25 | #include <iostream> |
---|
| 26 | #include <sstream> |
---|
| 27 | |
---|
| 28 | int main(int argc, char* argv[]) |
---|
| 29 | { |
---|
| 30 | using namespace theplu::svndigest; |
---|
| 31 | bool ok=true; |
---|
| 32 | |
---|
[929] | 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 |
---|
[919] | 35 | // (total 13). The loop is 14 iterations and therefore the first |
---|
[929] | 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 |
---|
[919] | 38 | // must be adjusted accordingly |
---|
| 39 | unsigned char r_first, g_first, b_first; |
---|
[962] | 40 | r_first = g_first = b_first = '\0'; |
---|
[919] | 41 | unsigned char r, g, b; |
---|
| 42 | for (unsigned int i=0; i<14; ++i) { |
---|
| 43 | std::stringstream ss; |
---|
| 44 | ss << i; |
---|
[929] | 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 |
---|
[919] | 47 | } |
---|
[929] | 48 | // Test first and last color, expected to be the same. |
---|
[919] | 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 | } |
---|