Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / cunit / test_color.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * Color Conversion Unit Tests
4  *
5  * Copyright 2010 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <freerdp/freerdp.h>
23 #include <freerdp/gdi/gdi.h>
24 #include <freerdp/codec/color.h>
25 #include "test_color.h"
26
27 int init_color_suite(void)
28 {
29         return 0;
30 }
31
32 int clean_color_suite(void)
33 {
34         return 0;
35 }
36
37 int add_color_suite(void)
38 {
39         add_test_suite(color);
40
41         add_test_function(color_GetRGB32);
42         add_test_function(color_GetBGR32);
43         add_test_function(color_GetRGB_565);
44         add_test_function(color_GetRGB16);
45         add_test_function(color_GetBGR_565);
46         add_test_function(color_GetBGR16);
47
48         return 0;
49 }
50
51 /* GDI Color Space Conversions: http://msdn.microsoft.com/en-us/library/ff566496(VS.85).aspx */
52
53 void test_color_GetRGB32(void)
54 {
55         int r, g, b;
56         uint32 rgb32 = 0x00AABBCC;
57         GetRGB32(r, g, b, rgb32);
58
59         CU_ASSERT(r == 0xAA);
60         CU_ASSERT(g == 0xBB);
61         CU_ASSERT(b == 0xCC);
62 }
63
64 void test_color_GetBGR32(void)
65 {
66         int r, g, b;
67         uint32 bgr32 = 0x00CCBBAA;
68         GetBGR32(r, g, b, bgr32);
69
70         CU_ASSERT(r == 0xAA);
71         CU_ASSERT(g == 0xBB);
72         CU_ASSERT(b == 0xCC);
73 }
74
75 void test_color_GetRGB_565(void)
76 {
77         /*
78                 R: 0x15, 10101
79                 G: 0x33, 110011
80                 B: 0x1D, 11101
81
82                 0xAE7D, 10101110 01111101
83         */
84         
85         int r, g, b;
86         uint16 rgb16 = 0xAE7D;
87         GetRGB_565(r, g, b, rgb16);
88         
89         CU_ASSERT(r == 0x15);
90         CU_ASSERT(g == 0x33);
91         CU_ASSERT(b == 0x1D);
92 }
93
94 void test_color_GetRGB16(void)
95 {
96         /*
97                 R: 0x15 -> 0xAD, 10101 -> 10101101
98                 G: 0x33 -> 0xCF, 110011 -> 11001111
99                 B: 0x1D -> 0xEF, 11101 -> 11101101
100
101                 0xAE7D -> 0xADCFEF
102                 10101110 01111101 -> 10101101 11001111 11101101
103         */
104         
105         int r, g, b;
106         uint16 rgb16 = 0xAE7D;
107         GetRGB16(r, g, b, rgb16);
108         
109         CU_ASSERT(r == 0xAD);
110         CU_ASSERT(g == 0xCF);
111         CU_ASSERT(b == 0xEF);
112 }
113
114 void test_color_GetBGR_565(void)
115 {
116         /*
117                 B: 0x1D, 11101
118                 G: 0x33, 110011
119                 R: 0x15, 10101
120
121                 0xEE75, 11101110 01110101
122         */
123                 
124         int r, g, b;
125         uint16 bgr16 = 0xEE75;
126         GetBGR_565(r, g, b, bgr16);
127         
128         CU_ASSERT(r == 0x15);
129         CU_ASSERT(g == 0x33);
130         CU_ASSERT(b == 0x1D);
131 }
132
133 void test_color_GetBGR16(void)
134 {
135         /*
136                 B: 0x1D -> 0xEF, 11101 -> 11101101
137                 G: 0x33 -> 0xCF, 110011 -> 11001111
138                 R: 0x15 -> 0xAD, 10101 -> 10101101
139
140                 0xEE75 -> 0xADCFEF
141                 11101110 01110101 -> 10101101 11001111 11101101
142         */
143                 
144         int r, g, b;
145         uint16 bgr16 = 0xEE75;
146         GetBGR16(r, g, b, bgr16);
147         
148         CU_ASSERT(r == 0xAD);
149         CU_ASSERT(g == 0xCF);
150         CU_ASSERT(b == 0xEF);
151 }
152