File indexing completed on 2024-03-24 05:50:37
0001 /***************************************************************************** 0002 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU Lesser General Public License as * 0006 * published by the Free Software Foundation; either version 2.1 of the * 0007 * License, or (at your option) version 3, or any later version accepted * 0008 * by the membership of KDE e.V. (or its successor approved by the * 0009 * membership of KDE e.V.), which shall act as a proxy defined in * 0010 * Section 6 of version 3 of the license. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, * 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0015 * Lesser General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU Lesser General Public * 0018 * License along with this library. If not, * 0019 * see <http://www.gnu.org/licenses/>. * 0020 *****************************************************************************/ 0021 0022 #include <qtcurve-utils/color.h> 0023 #include <assert.h> 0024 0025 static void 0026 test_short() 0027 { 0028 char origin[10]; 0029 char res[10]; 0030 QtcColor color; 0031 for (int r = 0;r < 16;r++) { 0032 for (int g = 0;g < 16;g++) { 0033 for (int b = 0;b < 16;b++) { 0034 sprintf(origin, "#%01X%01X%01X", r, g, b); 0035 qtcColorFromStr(&color, origin); 0036 assert(color.red == r / 15.0); 0037 assert(color.green == g / 15.0); 0038 assert(color.blue == b / 15.0); 0039 qtcColorToStr(&color, res); 0040 sprintf(origin, "#%02X%02X%02X", r * 255 / 15, g * 255 / 15, 0041 b * 255 / 15); 0042 assert(strcmp(origin, res) == 0); 0043 } 0044 } 0045 } 0046 } 0047 0048 static void 0049 test_long() 0050 { 0051 char origin[10]; 0052 char res[10]; 0053 QtcColor color; 0054 for (int r = 0;r < 256;r++) { 0055 for (int g = 0;g < 256;g++) { 0056 for (int b = 0;b < 256;b++) { 0057 sprintf(origin, "#%02X%02X%02X", r, g, b); 0058 qtcColorFromStr(&color, origin); 0059 assert(color.red == r / 255.0); 0060 assert(color.green == g / 255.0); 0061 assert(color.blue == b / 255.0); 0062 qtcColorToStr(&color, res); 0063 assert(strcmp(origin, res) == 0); 0064 } 0065 } 0066 } 0067 } 0068 0069 int 0070 main() 0071 { 0072 test_short(); 0073 test_long(); 0074 return 0; 0075 }