Jamoma API  0.6.0.a19
TTMatrixGain.test.cpp
1 /*
2  * Jamoma MatrixProcessingLib: Gain
3  * Copyright © 2011, Timothy Place
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #include "TTMatrixGain.h"
10 
11 
12 TTErr TTMatrixGain::test(TTValue& returnedTestInfo)
13 {
14  int errorCount = 0;
15  int testAssertionCount = 0;
16  int badValueCount = 0;
17  TTMatrixBasePtr x = NULL; // input matrix
18  TTMatrixBasePtr y = NULL; // output matrix
19  TTErr err = kTTErrNone;
20  TTValue v(16, 16);
21  TTValue aColor;
22  TTValue aReturnWeDontCareAbout;
23 
24  err = TTObjectBaseInstantiate(kTTSym_matrix, (TTObjectBasePtr*)&x, kTTValNONE);
25  err = TTObjectBaseInstantiate(kTTSym_matrix, (TTObjectBasePtr*)&y, kTTValNONE);
26 
27  x->setAttributeValue(kTTSym_dimensions, v);
28  x->setAttributeValue(kTTSym_type, kTTSym_uint8);
29  x->setAttributeValue(kTTSym_elementCount, 4);
30  aColor.resize(4);
31  aColor[0] = 200;
32  aColor[1] = 196;
33  aColor[2] = 24;
34  aColor[3] = 240;
35 
36  x->fill(aColor, aReturnWeDontCareAbout);
37 
38  this->setAttributeValue(kTTSym_gain, 0.125);
39  err = this->calculate(x, y);
40 
41  // 1. Assert the correct dimensions, type, etc. for y (should adapt to x)
42 
43  // 2. Iterate through y and check all of the values
44  TTUInt8* data = (TTUInt8*)y->getLockedPointer();
45 
46  for (int i=0; i<(16*16*4); i += 4) {
47  TTUInt8 *pixel = data+i;
48 
49  if (pixel[0] != 25 || pixel[1] != 24 || pixel[2] != 3 || pixel[3] != 30 ) {
50  badValueCount++;
51  TTTestLog("BAD VALUE @ i=%i ( value = [%c,%c,%c,%c] expected = [25,24,3,30]", i, pixel[0], pixel[1], pixel[2], pixel[3]);
52  }
53  }
55 
56  TTTestAssertion("Test 2: All values in a 16x16 matrix (type uint8, element count 4) are properly scaled by 1/8.",
57  badValueCount == 0,
58  testAssertionCount,
59  errorCount);
60  if (badValueCount)
61  TTTestLog("badValueCount is %i", badValueCount);
62 
63 
64  // TODO: test other types, dims, elem counts
65 
66 
69 
70  // Wrap up the test results to pass back to whoever called this test
71  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
72 }
73 
TTBytePtr getLockedPointer()
Return a pointer to the matrix data, and lock the matrix so that others cannot access the data...
Definition: TTMatrixBase.h:547
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTErr fill(const TTValue &anInputValue, TTValue &anOutputValue)
Fill every component in the matrix with the same value.
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
2-dimensional matrix of compound values with N elements each.
Definition: TTMatrixBase.h:41
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
void releaseLockedPointer()
Release a locked pointer obtained using getLockedPointer().
Definition: TTMatrixBase.h:556
TTErr calculate(const TTMatrixArray *inputs, TTMatrixArray *outputs)
No Error.
Definition: TTBase.h:343
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
unsigned char TTUInt8
8 bit unsigned integer (char)
Definition: TTBase.h:174