Back to index

nux  3.0.0
gtest-nuxcore-colorprivate.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Inalogic Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License version 3, as
00006  * published by the  Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00012  * License for more details.
00013  *
00014  * You should have received a copy of both the GNU Lesser General Public
00015  * License version 3 along with this program.  If not, see
00016  * <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Andrea Azzarone <azzaronea@gmail.com>
00019  *
00020  */
00021 
00022 #include "NuxCore/ColorPrivate.h"
00023 using namespace nux::color;
00024 
00025 #include <gmock/gmock.h>
00026 using namespace testing;
00027 
00028 namespace
00029 {
00030 
00031 TEST(TestColorPrivate, TestIsValidHex)
00032 {
00033   EXPECT_TRUE(IsValidHex("#abcdef"));
00034   EXPECT_TRUE(IsValidHex("abcdef"));
00035   EXPECT_TRUE(IsValidHex("#ABCDEF"));
00036   EXPECT_TRUE(IsValidHex("ABCDEF"));
00037 
00038   EXPECT_FALSE(IsValidHex(""));
00039   EXPECT_FALSE(IsValidHex("#"));
00040   EXPECT_FALSE(IsValidHex("#abcde"));
00041   EXPECT_FALSE(IsValidHex("#abcdefa"));
00042   EXPECT_FALSE(IsValidHex("abcde"));
00043   EXPECT_FALSE(IsValidHex("abcdefa"));
00044   EXPECT_FALSE(IsValidHex("#abcdeg"));
00045 }
00046 
00047 
00048 TEST(TestColorPrivate, TestHexToInt)
00049 {
00050   EXPECT_EQ(HexToInt("ab"), 0xab);
00051   EXPECT_EQ(HexToInt("AB"), 0xab);
00052   EXPECT_EQ(HexToInt("01"), 0x01);
00053   EXPECT_EQ(HexToInt("0a"), 0x0a);
00054 }
00055 
00056 TEST(TestColorPrivate, TestHexToRGBA)
00057 {
00058   float r, g, b, a;
00059 
00060   EXPECT_FALSE(HexToRGBA("", r, g, b, a));
00061   EXPECT_FALSE(HexToRGBA("#ubuntu", r, g, b, a));
00062 
00063   EXPECT_TRUE(HexToRGBA("#abc", r, g, b, a));
00064   EXPECT_EQ(r, 0xaa / 255.0f);
00065   EXPECT_EQ(g, 0xbb / 255.0f);
00066   EXPECT_EQ(b, 0xcc / 255.0f);
00067   EXPECT_EQ(a, 1.0f);
00068 
00069   r = g = b = a = 0;
00070   EXPECT_TRUE(HexToRGBA("#abcd", r, g, b, a));
00071   EXPECT_EQ(r, 0xaa / 255.0f);
00072   EXPECT_EQ(g, 0xbb / 255.0f);
00073   EXPECT_EQ(b, 0xcc / 255.0f);
00074   EXPECT_EQ(a, 0xdd / 255.0f);
00075 
00076   r = g = b = a = 0;
00077   EXPECT_TRUE(HexToRGBA("#abcdef", r, g, b, a));
00078   EXPECT_EQ(r, 0xab / 255.0f);
00079   EXPECT_EQ(g, 0xcd / 255.0f);
00080   EXPECT_EQ(b, 0xef / 255.0f);
00081   EXPECT_EQ(a, 1.0f);
00082 
00083    r = g = b = a = 0;
00084   EXPECT_TRUE(HexToRGBA("#abcdefdd", r, g, b, a));
00085   EXPECT_EQ(r, 0xab / 255.0f);
00086   EXPECT_EQ(g, 0xcd / 255.0f);
00087   EXPECT_EQ(b, 0xef / 255.0f);
00088   EXPECT_EQ(a, 0xdd / 255.0f);
00089 
00090   r = g = b = a = 0;
00091   EXPECT_TRUE(HexToRGBA("abcdef", r, g, b, a));
00092   EXPECT_EQ(r, 0xab / 255.0f);
00093   EXPECT_EQ(g, 0xcd / 255.0f);
00094   EXPECT_EQ(b, 0xef / 255.0f);
00095 }
00096 
00097 }
00098