Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 104 lines (85 sloc) 1.662 kb
120e15b TJ Holowaychuk Initial commit
tj authored
1
2 #include <stdio.h>
3 #include <assert.h>
4 #include <string.h>
5 #include "src/rgba.h"
6
7 /*
8 * Test named colors.
9 */
10
11 void
12 test_named() {
13 short ok;
14 int32_t val = rgba_from_string("olive", &ok);
15 assert(ok);
16 assert(0x808000FF == val);
17 }
18
19 /*
20 * Test rgb()
21 */
22
23 void
24 test_rgb() {
25 short ok;
26 int32_t val = rgba_from_string("rgb(255, 30 , 0)", &ok);
27 assert(ok);
28 assert(0xff1e00ff == val);
29
30 val = rgba_from_string("rgb(0,0,0)", &ok);
31 assert(ok);
32 assert(0x000000ff == val);
33 }
34
35 /*
36 * Test rgba()
37 */
38
39 void
40 test_rgba() {
41 short ok;
42 int32_t val = rgba_from_string("rgba(255, 30 , 0, .5)", &ok);
43 assert(ok);
44 assert(0xff1e007f == val);
45
46 val = rgba_from_string("rgba(0,0,0, 1)", &ok);
47 assert(ok);
48 assert(0x000000ff == val);
49 }
50
51 /*
52 * Test #rgb and #rrggbb
53 */
54
55 void
56 test_hex() {
57 short ok;
58 int32_t val = rgba_from_string("#ff1e00", &ok);
59 assert(ok);
60 assert(0xff1e00ff == val);
61
62 val = rgba_from_string("#ffffff", &ok);
63 assert(ok);
64 assert(0xffffffff == val);
65
66 val = rgba_from_string("#ffcc00", &ok);
67 assert(ok);
68 assert(0xffcc00ff == val);
69
70 val = rgba_from_string("#fco", &ok);
71 assert(ok);
72 assert(0xffcc00ff == val);
73 }
74
75 /*
76 * Test to string.
77 */
78
79 void
80 test_to_string() {
81 char buf[256];
82 rgba_t color = rgba_new(0xffcc00ff);
83 rgba_to_string(color, buf, 256);
84 assert(0 == strcmp("#ffcc00", buf));
85
86 color = rgba_new(0xffcc0050);
87 rgba_to_string(color, buf, 256);
88 assert(0 == strcmp("rgba(255, 204, 0, 0.31)", buf));
89 }
90
91 /*
92 * Run tests.
93 */
94
95 int
96 main(int argc, char **argv){
97 test_named();
98 test_rgb();
99 test_rgba();
100 test_hex();
101 test_to_string();
102 printf("\n \e[32m\u2713 \e[90mok\e[0m\n\n");
103 return 0;
104 }
Something went wrong with that request. Please try again.