Jamoma API  0.6.0.a19
PositionDataspace.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief Unit tests for the #PositionDataspace.
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 "PositionDataspace.h"
20 
21 
22 TTErr PositionDataspace::test(TTValue& returnedTestInfo)
23 {
24  int errorCount = 0;
25  int testAssertionCount = 0;
26 
27  // Create dataspace object and set to angle
28  try {
29 
30  TTObject myDataspace("dataspace");
31  myDataspace.set(TT("dataspace"), TT("position"));
32 
33  TTValue v;
34  TTValue expected;
35 
36 
37  /************************************************/
38  /* */
39  /* Test conversions to neutral unit */
40  /* */
41  /************************************************/
42 
43 
44  // xyz => xyz
45 
46  myDataspace.set(TT("inputUnit"), TT("xyz"));
47  myDataspace.set(TT("outputUnit"), TT("xyz"));
48 
49  v.resize(3);
50  v[0] = TTFloat64(1.0);
51  v[1] = TTFloat64(2.0);
52  v[2] = TTFloat64(3.0);
53 
54  expected.resize(3);
55  expected[0] = TTFloat64(1.0);
56  expected[1] = TTFloat64(2.0);
57  expected[2] = TTFloat64(3.0);
58 
59  myDataspace.send(TT("convert"), v, v);
60 
61  TTTestAssertion("xyz to xyz",
62  TTTestFloat64ArrayEquivalence(v, expected),
63  testAssertionCount,
64  errorCount);
65 
66 
67  // xy => xyz
68 
69  myDataspace.set(TT("inputUnit"), TT("xy"));
70  myDataspace.set(TT("outputUnit"), TT("xyz"));
71 
72  v.resize(2);
73  v[0] = TTFloat64(1.0);
74  v[1] = TTFloat64(-1.0);
75 
76  expected.resize(3);
77  expected[0] = TTFloat64(1.0);
78  expected[1] = TTFloat64(-1.0);
79  expected[2] = TTFloat64(0.0);
80 
81  myDataspace.send(TT("convert"), v, v);
82 
83  TTTestAssertion("xy to xyz",
84  TTTestFloat64ArrayEquivalence(v, expected),
85  testAssertionCount,
86  errorCount);
87 
88 
89  // aed => xyz
90 
91  myDataspace.set(TT("inputUnit"), TT("aed"));
92  myDataspace.set(TT("outputUnit"), TT("xyz"));
93 
94  v.resize(3);
95  v[0] = TTFloat64(-90.0);
96  v[1] = TTFloat64(0.0);
97  v[2] = TTFloat64(2.0);
98 
99  expected.resize(3);
100  expected[0] = TTFloat64(-2.0);
101  expected[1] = TTFloat64(0.0);
102  expected[2] = TTFloat64(0.0);
103 
104  myDataspace.send(TT("convert"), v, v);
105 
106  TTTestAssertion("aed to xyz",
107  TTTestFloat64ArrayEquivalence(v, expected),
108  testAssertionCount,
109  errorCount);
110 
111  // openGL => xyz
112 
113  myDataspace.set(TT("inputUnit"), TT("openGL"));
114  myDataspace.set(TT("outputUnit"), TT("xyz"));
115 
116  v.resize(3);
117  v[0] = TTFloat64(1.0);
118  v[1] = TTFloat64(3.0);
119  v[2] = TTFloat64(2.0);
120 
121  expected.resize(3);
122  expected[0] = TTFloat64(1.0);
123  expected[1] = TTFloat64(-2.0);
124  expected[2] = TTFloat64(3.0);
125 
126  myDataspace.send(TT("convert"), v, v);
127 
128  TTTestAssertion("openGL to xyz",
129  TTTestFloat64ArrayEquivalence(v, expected),
130  testAssertionCount,
131  errorCount);
132 
133 
134  myDataspace.set(TT("inputUnit"), TT("polar"));
135  myDataspace.set(TT("outputUnit"), TT("xyz"));
136 
137  v.resize(2);
138  v[0] = TTFloat64(-45.0);
139  v[1] = TTFloat64(2.0);
140 
141  expected.resize(3);
142  expected[0] = TTFloat64(-sqrt(2.0));
143  expected[1] = TTFloat64(sqrt(2.0));
144  expected[2] = TTFloat64(0.0);
145 
146  myDataspace.send(TT("convert"), v, v);
147 
148  TTTestAssertion("polar to xyz",
149  TTTestFloat64ArrayEquivalence(v, expected),
150  testAssertionCount,
151  errorCount);
152 
153  myDataspace.set(TT("inputUnit"), TT("daz"));
154  myDataspace.set(TT("outputUnit"), TT("xyz"));
155 
156  v.resize(3);
157  v[0] = TTFloat64(2.0);
158  v[1] = TTFloat64(45.0);
159  v[2] = TTFloat64(2.0);
160 
161  expected.resize(3);
162  expected[0] = TTFloat64(sqrt(2.0));
163  expected[1] = TTFloat64(sqrt(2.0));
164  expected[2] = TTFloat64(2.0);
165 
166  myDataspace.send(TT("convert"), v, v);
167 
168  TTTestAssertion("cylindrical to xyz",
169  TTTestFloat64ArrayEquivalence(v, expected),
170  testAssertionCount,
171  errorCount);
172 
173  /************************************************/
174  /* */
175  /* Test conversions from neutral unit */
176  /* */
177  /************************************************/
178 
179 
180  // xyz => xy
181 
182  myDataspace.set(TT("inputUnit"), TT("xyz"));
183  myDataspace.set(TT("outputUnit"), TT("xy"));
184 
185  v.resize(3);
186  v[0] = TTFloat64(1.0);
187  v[1] = TTFloat64(-1.0);
188  v[2] = TTFloat64(0.0);
189 
190  expected.resize(2);
191  expected[0] = TTFloat64(1.0);
192  expected[1] = TTFloat64(-1.0);
193 
194  myDataspace.send(TT("convert"), v, v);
195 
196  TTTestAssertion("xyz to xy",
197  TTTestFloat64ArrayEquivalence(v, expected),
198  testAssertionCount,
199  errorCount);
200 
201  // xyz => aed
202 
203  myDataspace.set(TT("inputUnit"), TT("xyz"));
204  myDataspace.set(TT("outputUnit"), TT("aed"));
205 
206  expected.resize(3);
207  expected[0] = TTFloat64(-90.0);
208  expected[1] = TTFloat64(0.0);
209  expected[2] = TTFloat64(2.0);
210 
211  v.resize(3);
212  v[0] = TTFloat64(-2.0);
213  v[1] = TTFloat64(0.0);
214  v[2] = TTFloat64(0.0);
215 
216  myDataspace.send(TT("convert"), v, v);
217 
218  TTTestAssertion("xyz to aed",
219  TTTestFloat64ArrayEquivalence(v, expected),
220  testAssertionCount,
221  errorCount);
222 
223  // xyz => openGL
224 
225  myDataspace.set(TT("inputUnit"), TT("xyz"));
226  myDataspace.set(TT("outputUnit"), TT("openGL"));
227 
228  v.resize(3);
229  v[0] = TTFloat64(1.0);
230  v[1] = TTFloat64(-2.0);
231  v[2] = TTFloat64(3.0);
232 
233  expected.resize(3);
234  expected[0] = TTFloat64(1.0);
235  expected[1] = TTFloat64(3.0);
236  expected[2] = TTFloat64(2.0);
237 
238  myDataspace.send(TT("convert"), v, v);
239 
240  TTTestAssertion("xyz to openGL",
241  TTTestFloat64ArrayEquivalence(v, expected),
242  testAssertionCount,
243  errorCount);
244 
245 
246  myDataspace.set(TT("inputUnit"), TT("xyz"));
247  myDataspace.set(TT("outputUnit"), TT("polar"));
248 
249  v.resize(3);
250  v[0] = TTFloat64(-sqrt(2.0));
251  v[1] = TTFloat64(sqrt(2.0));
252  v[2] = TTFloat64(0.0);
253 
254  expected.resize(2);
255  expected[0] = TTFloat64(-45.0);
256  expected[1] = TTFloat64(2.0);
257 
258  myDataspace.send(TT("convert"), v, v);
259 
260 
261  TTTestAssertion("xyz to polar",
262  TTTestFloat64ArrayEquivalence(v, expected),
263  testAssertionCount,
264  errorCount);
265 
266  // xyz => cylindric
267 
268  myDataspace.set(TT("inputUnit"), TT("xyz"));
269  myDataspace.set(TT("outputUnit"), TT("daz"));
270 
271  v.resize(3);
272  v[0] = TTFloat64(sqrt(2.0));
273  v[1] = TTFloat64(sqrt(2.0));
274  v[2] = TTFloat64(2.0);
275 
276  expected.resize(3);
277  expected[0] = TTFloat64(2.0);
278  expected[1] = TTFloat64(45.0);
279  expected[2] = TTFloat64(2.0);
280 
281  myDataspace.send(TT("convert"), v, v);
282 
283  TTTestAssertion("xyz to cylindrical",
284  TTTestFloat64ArrayEquivalence(v, expected),
285  testAssertionCount,
286  errorCount);
287 
288  /************************************************/
289  /* */
290  /* Tests across different units */
291  /* */
292  /************************************************/
293 
294  myDataspace.set(TT("inputUnit"), TT("daz"));
295  myDataspace.set(TT("outputUnit"), TT("xy"));
296 
297  v.resize(3);
298  v[0] = TTFloat64(2.0);
299  v[1] = TTFloat64(45.0);
300  v[2] = TTFloat64(10.0);
301 
302  expected.resize(2);
303  expected[0] = TTFloat64(sqrt(2.0));
304  expected[1] = TTFloat64(sqrt(2.0));
305 
306 
307  myDataspace.send(TT("convert"), v, v);
308 
309  TTTestAssertion("cylindrical to xy",
310  TTTestFloat64ArrayEquivalence(v, expected),
311  testAssertionCount,
312  errorCount);
313 
314  }
315  catch (...) {
316  TTLogMessage("PositionDataspace::test TOTAL FAILURE");
317  errorCount = 1;
318  testAssertionCount = 1;
319  }
320 
321  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
322 }
Create and use Jamoma object instances.
Definition: TTObject.h:29
The PositionDataspace converts between different untis describing position.
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
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