Jamoma API  0.6.0.a19
ColorDataspace.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief Unit tests for the #ColorDataspace.
6  *
7  * @authors Trond Lossius, Tim Place, Nils Peters, ...
8  *
9  * @copyright Copyright © 2011 Trond Lossius @n
10  * This code is licensed under the terms of the "New BSD License" @n
11  * http://creativecommons.org/licenses/BSD/
12  */
13 
14 
15 // Dataspaces and Units employ C++ double-inheritance and are thus unsuitable for direct use
16 // through the usual TTObject API
17 #define TT_NO_DEPRECATION_WARNINGS
18 
19 #include "ColorDataspace.h"
20 
21 
22 TTErr ColorDataspace::test(TTValue& returnedTestInfo)
23 {
24  int errorCount = 0;
25  int testAssertionCount = 0;
26 
27  // Create dataspace object and set to color
28  try {
29 
30  TTObject myDataspace("dataspace");
31 
32  myDataspace.set(TT("dataspace"), TT("color"));
33 
34  TTValue v;
35  TTValue expected;
36 
37 
38  /************************************************/
39  /* */
40  /* Test conversions to neutral unit */
41  /* */
42  /************************************************/
43 
44  // rgb => rgb
45 
46  myDataspace.set(TT("inputUnit"), TT("rgb"));
47  myDataspace.set(TT("outputUnit"), TT("rgb"));
48 
49  v.resize(3);
50  v[0] = TTFloat64(124.2);
51  v[1] = TTFloat64(162.9);
52  v[2] = TTFloat64(13.163);
53 
54  expected.resize(3);
55  expected[0] = TTFloat64(124.2);
56  expected[1] = TTFloat64(162.9);
57  expected[2] = TTFloat64(13.163);
58 
59  myDataspace.send(TT("convert"), v, v);
60 
61  TTTestAssertion("rgb to rgb",
62  TTTestFloat64ArrayEquivalence(v, expected),
63  testAssertionCount,
64  errorCount);
65 
66 
67  // cmy => rgb
68 
69  myDataspace.set(TT("inputUnit"), TT("cmy"));
70  myDataspace.set(TT("outputUnit"), TT("rgb"));
71 
72  v.resize(3);
73  v[0] = TTFloat64(255.);
74  v[1] = TTFloat64(127.5);
75  v[2] = TTFloat64(0.);
76 
77  expected.resize(3);
78  expected[0] = TTFloat64(0.);
79  expected[1] = TTFloat64(0.5);
80  expected[2] = TTFloat64(1.0);
81 
82  myDataspace.send(TT("convert"), v, v);
83 
84  TTTestAssertion("cmy to rgb",
85  TTTestFloat64ArrayEquivalence(v, expected),
86  testAssertionCount,
87  errorCount);
88 
89 
90  // hsl => rgb
91 
92  myDataspace.set(TT("inputUnit"), TT("hsl"));
93  myDataspace.set(TT("outputUnit"), TT("rgb"));
94 
95  v.resize(3);
96  v[0] = TTFloat64(120.);
97  v[1] = TTFloat64(100.);
98  v[2] = TTFloat64(50.);
99 
100  expected.resize(3);
101  expected[0] = TTFloat64(0.);
102  expected[1] = TTFloat64(1.0);
103  expected[2] = TTFloat64(0.);
104 
105  myDataspace.send(TT("convert"), v, v);
106 
107  TTTestAssertion("hsl to rgb",
108  TTTestFloat64ArrayEquivalence(v, expected),
109  testAssertionCount,
110  errorCount);
111 
112 
113  // rgb8 => rgb
114 
115  myDataspace.set(TT("inputUnit"), TT("rgb8"));
116  myDataspace.set(TT("outputUnit"), TT("rgb"));
117 
118  v.resize(3);
119  v[0] = TTFloat64(255.);
120  v[1] = TTFloat64(127.5);
121  v[2] = TTFloat64(0.);
122 
123  expected.resize(3);
124  expected[0] = TTFloat64(1.);
125  expected[1] = TTFloat64(0.5);
126  expected[2] = TTFloat64(0.0);
127 
128  myDataspace.send(TT("convert"), v, v);
129 
130  TTTestAssertion("rgb8 to rgb",
131  TTTestFloat64ArrayEquivalence(v, expected),
132  testAssertionCount,
133  errorCount);
134 
135 
136  // hsv => rgb
137 
138  myDataspace.set(TT("inputUnit"), TT("hsv"));
139  myDataspace.set(TT("outputUnit"), TT("rgb"));
140 
141  v.resize(3);
142  v[0] = TTFloat64(120.);
143  v[1] =TTFloat64(100.);
144  v[2] = TTFloat64(100.);
145 
146  expected.resize(3);
147  expected[0] = TTFloat64(0.);
148  expected[1] = TTFloat64(1.0);
149  expected[2] = TTFloat64(0.);
150 
151  myDataspace.send(TT("convert"), v, v);
152 
153  TTTestAssertion("hsv to rgb",
154  TTTestFloat64ArrayEquivalence(v, expected),
155  testAssertionCount,
156  errorCount);
157 
158 
159 
160  /************************************************/
161  /* */
162  /* Test conversions from neutral unit */
163  /* */
164  /************************************************/
165 
166 
167  // rgb => cmy
168 
169  myDataspace.set(TT("inputUnit"), TT("rgb"));
170  myDataspace.set(TT("outputUnit"), TT("cmy"));
171 
172  v.resize(3);
173  v[0] = TTFloat64(0.);
174  v[1] = TTFloat64(0.5);
175  v[2] = TTFloat64(1.);
176 
177  expected.resize(3);
178  expected[0] = TTFloat64(255.);
179  expected[1] = TTFloat64(127.5);
180  expected[2] = TTFloat64(0.0);
181 
182  myDataspace.send(TT("convert"), v, v);
183 
184  TTTestAssertion("rgb to cmy",
185  TTTestFloat64ArrayEquivalence(v, expected),
186  testAssertionCount,
187  errorCount);
188 
189 
190  // rgb => hsl
191 
192  myDataspace.set(TT("inputUnit"), TT("rgb"));
193  myDataspace.set(TT("outputUnit"), TT("hsl"));
194 
195  v.resize(3);
196  v[0] = TTFloat64(0.);
197  v[1] = TTFloat64(1.);
198  v[2] = TTFloat64(0.);
199 
200  expected.resize(3);
201  expected[0] = TTFloat64(120.);
202  expected[1] = TTFloat64(100.0);
203  expected[2] = TTFloat64(50.);
204 
205  myDataspace.send(TT("convert"), v, v);
206 
207  TTTestAssertion("rgb to hsl",
208  TTTestFloat64ArrayEquivalence(v, expected),
209  testAssertionCount,
210  errorCount);
211 
212 
213  // rgb => rgb8
214 
215  myDataspace.set(TT("inputUnit"), TT("rgb"));
216  myDataspace.set(TT("outputUnit"), TT("rgb8"));
217 
218  v.resize(3);
219  v[0] = TTFloat64(1.);
220  v[1] = TTFloat64(0.5);
221  v[2] = TTFloat64(0.);
222 
223  expected.resize(3);
224  expected[0] = TTFloat64(255.);
225  expected[1] = TTFloat64(127.5);
226  expected[2] = TTFloat64(0.0);
227 
228  myDataspace.send(TT("convert"), v, v);
229 
230  TTTestAssertion("rgb to rgb8",
231  TTTestFloat64ArrayEquivalence(v, expected),
232  testAssertionCount,
233  errorCount);
234 
235 
236  // rgb => hsv
237 
238  myDataspace.set(TT("inputUnit"), TT("rgb"));
239  myDataspace.set(TT("outputUnit"), TT("hsv"));
240 
241  v.resize(3);
242  v[0] = TTFloat64(0.);
243  v[1] = TTFloat64(1.);
244  v[2] = TTFloat64(0.);
245 
246  expected.resize(3);
247  expected[0] = TTFloat64(120.);
248  expected[1] = TTFloat64(100.0);
249  expected[2] = TTFloat64(100.);
250 
251  myDataspace.send(TT("convert"), v, v);
252 
253  TTTestAssertion("rgb to hsv",
254  TTTestFloat64ArrayEquivalence(v, expected),
255  testAssertionCount,
256  errorCount);
257 
258  }
259  catch (...) {
260  TTLogMessage("ColorDataspace::test TOTAL FAILURE");
261  errorCount = 1;
262  testAssertionCount = 1;
263  }
264 
265  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
266 }
Create and use Jamoma object instances.
Definition: TTObject.h:29
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
The ColorDataspace converts between different measurement units describing colors.
void set(const TTUInt16 index, const T &anElementValue)
DEPRECATED.
Definition: TTValue.h:569
void TTFOUNDATION_EXPORT TTLogMessage(TTImmutableCString message,...)
Platform and host independent method for posting log messages.
Definition: TTBase.cpp:534
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34