a752c7ab
elopes
add first test an...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*
* Copyright (C) 2016 Cenk Gündoğan <mail@cgundogan.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @{
*
* @file
*/
#include <errno.h>
#include <stdint.h>
#include "embUnit/embUnit.h"
#include "color.h"
#include "tests-color.h"
static void test_str2rgb_upper_case__success(void)
{
const char *color_str = "F09A1D";
color_rgb_t rgb;
color_str2rgb(color_str, &rgb);
TEST_ASSERT_EQUAL_INT(0xF0, rgb.r);
TEST_ASSERT_EQUAL_INT(0x9A, rgb.g);
TEST_ASSERT_EQUAL_INT(0x1D, rgb.b);
}
static void test_str2rgb_lower_case__success(void)
{
const char *color_str = "f09a1d";
color_rgb_t rgb;
color_str2rgb(color_str, &rgb);
TEST_ASSERT_EQUAL_INT(0xF0, rgb.r);
TEST_ASSERT_EQUAL_INT(0x9A, rgb.g);
TEST_ASSERT_EQUAL_INT(0x1D, rgb.b);
}
static void test_rgb2str__success(void)
{
char color_str[7] = { 0 };
const color_rgb_t rgb = { .r = 0x0A, .g = 0xB1, .b = 0x3C };
color_rgb2str(&rgb, color_str);
TEST_ASSERT_EQUAL_STRING("0AB13C", (char *) color_str);
}
static void test_hex2rgb__success(void)
{
const uint32_t hex = 0x8Fa1b9;
color_rgb_t rgb;
color_hex2rgb(hex, &rgb);
TEST_ASSERT_EQUAL_INT(0x8F, rgb.r);
TEST_ASSERT_EQUAL_INT(0xA1, rgb.g);
TEST_ASSERT_EQUAL_INT(0xB9, rgb.b);
}
static void test_rgb2hex__success(void)
{
uint32_t hex = 0x0;
const color_rgb_t rgb = { .r = 0x0A, .g = 0xB1, .b = 0x3C };
color_rgb2hex(&rgb, &hex);
TEST_ASSERT_EQUAL_INT(0x000AB13C, hex);
}
static void test_rgb_invert__success(void)
{
const color_rgb_t col = {.r = 100, .g = 128, .b = 0};
const color_rgb_t res = {.r = 155, .g = 127, .b = 255};
color_rgb_t tmp;
color_rgb_invert(&col, &tmp);
TEST_ASSERT_EQUAL_INT(res.r, tmp.r);
TEST_ASSERT_EQUAL_INT(res.g, tmp.g);
TEST_ASSERT_EQUAL_INT(res.b, tmp.b);
}
static void test_rgb_complementary__success(void)
{
/* See example: https://helpx.adobe.com/illustrator/using/adjusting-colors.html */
const color_rgb_t col = {.r = 102, .g = 153, .b = 51};
const color_rgb_t res = {.r = 102, .g = 51, .b = 153};
color_rgb_t tmp;
color_rgb_complementary(&col, &tmp);
TEST_ASSERT_EQUAL_INT(res.r, tmp.r);
TEST_ASSERT_EQUAL_INT(res.g, tmp.g);
TEST_ASSERT_EQUAL_INT(res.b, tmp.b);
}
Test *tests_color_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_str2rgb_upper_case__success),
new_TestFixture(test_str2rgb_lower_case__success),
new_TestFixture(test_hex2rgb__success),
new_TestFixture(test_rgb2hex__success),
new_TestFixture(test_rgb2str__success),
new_TestFixture(test_rgb_invert__success),
new_TestFixture(test_rgb_complementary__success),
};
EMB_UNIT_TESTCALLER(color_tests, NULL, NULL, fixtures);
return (Test *)&color_tests;
}
void tests_color(void)
{
TESTS_RUN(tests_color_tests());
}
/** @} */
|