awtk/tests/color_test.cc

61 lines
1.3 KiB
C++
Raw Normal View History

#include "tkc/color.h"
#include "tkc/color_parser.h"
2018-08-22 15:51:49 +08:00
#include "gtest/gtest.h"
#include <string>
using std::string;
TEST(Color, basic) {
2019-03-18 17:45:49 +08:00
char hex[TK_COLOR_HEX_LEN + 1];
2018-08-22 15:51:49 +08:00
const char* str = "#AABBCC";
2018-12-27 17:39:26 +08:00
color_t c = color_parse(str);
2018-08-22 15:51:49 +08:00
color_hex_str(c, hex);
ASSERT_EQ(string(hex), string(str));
2018-12-18 09:49:09 +08:00
str = "#AABBCCDD";
2018-12-27 17:39:26 +08:00
c = color_parse(str);
2018-12-18 09:49:09 +08:00
ASSERT_EQ(c.color, 0xddccbbaa);
2018-08-22 15:51:49 +08:00
}
2019-01-09 16:24:14 +08:00
TEST(Color, dynamic) {
color_t* c = color_create(1, 2, 3, 4);
ASSERT_EQ(color_r(c), c->rgba.r);
ASSERT_EQ(color_g(c), c->rgba.g);
ASSERT_EQ(color_b(c), c->rgba.b);
ASSERT_EQ(color_a(c), c->rgba.a);
ASSERT_EQ(color_r(c), 1);
ASSERT_EQ(color_g(c), 2);
ASSERT_EQ(color_b(c), 3);
ASSERT_EQ(color_a(c), 4);
color_destroy(c);
}
TEST(Color, dynamic1) {
const char* str = "#01020304";
2019-01-13 18:39:30 +08:00
color_t* c = color_create(0, 0, 0, 0);
color_from_str(c, str);
2019-01-09 16:24:14 +08:00
ASSERT_EQ(color_r(c), c->rgba.r);
ASSERT_EQ(color_g(c), c->rgba.g);
ASSERT_EQ(color_b(c), c->rgba.b);
ASSERT_EQ(color_a(c), c->rgba.a);
ASSERT_EQ(color_r(c), 1);
ASSERT_EQ(color_g(c), 2);
ASSERT_EQ(color_b(c), 3);
ASSERT_EQ(color_a(c), 4);
color_destroy(c);
}
2019-03-18 17:45:49 +08:00
TEST(Color, rgba) {
char str[TK_COLOR_RGBA_LEN + 1];
color_t c = color_init(1, 2, 3, 0xff);
ASSERT_STREQ(color_rgba_str(c, str), "rgba(1,2,3,1.0)");
}