Jamoma API  0.6.0.a19
TTSymbol.test.cpp
1 /*
2  * Unit tests for the TTValue object
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 "TTSymbol.test.h"
10 
11 #define thisTTClass TTSymbolTest
12 #define thisTTClassName "symbol.test"
13 #define thisTTClassTags "test, foundation"
14 
15 
17 {;}
18 
19 
20 TTSymbolTest::~TTSymbolTest()
21 {;}
22 
23 
24 void TTSymbolTestBasic(int& errorCount, int&testAssertionCount)
25 {
26 /*
27  // TEST: empty string init
28 
29  TTTestLog("\n");
30  TTTestLog("Testing empty string assigment");
31 
32  TTString empty;
33 
34  TTTestAssertion("created static const char* arg with correct size",
35  empty.size() == 0,
36  testAssertionCount,
37  errorCount);
38  TTTestAssertion("created from static const char* arg with correct length",
39  empty.length() == 0,
40  testAssertionCount,
41  errorCount);
42  TTTestAssertion("created from static const char* arg correctly null terminated",
43  empty.at(0) == 0,
44  testAssertionCount,
45  errorCount);
46 
47 
48  // TEST: c-string init
49 
50  TTTestLog("\n");
51  TTTestLog("Testing basic string assigment");
52 
53  TTString foo("foo");
54 
55  TTTestAssertion("created from static const char* arg with correct size",
56  foo.size() == 3,
57  testAssertionCount,
58  errorCount);
59  TTTestAssertion("created from static const char* arg with correct length",
60  foo.length() == 3,
61  testAssertionCount,
62  errorCount);
63  TTTestAssertion("created from static const char* arg with correct chars",
64  foo.at(0) == 'f' && foo.at(1) == 'o' && foo.at(2) == 'o',
65  testAssertionCount,
66  errorCount);
67  TTTestAssertion("created from static const char* arg correctly null terminated",
68  foo.at(3) == 0,
69  testAssertionCount,
70  errorCount);
71 */
72  // TEST: random
73 
74  TTTestLog("\n");
75  TTTestLog("Testing random symbol generation");
76 
77  TTSymbol r = TTSymbol("foo");
78 
79  TTTestAssertion("created from = with correct size",
80  r.string().size() == 3,
81  testAssertionCount,
82  errorCount);
83  TTTestAssertion("created from = with correct length",
84  r.string().length() == 3,
85  testAssertionCount,
86  errorCount);
87  TTTestAssertion("created from = with correct chars",
88  r.string().at(0) == 'f' && r.string().at(1) == 'o' && r.string().at(2) == 'o',
89  testAssertionCount,
90  errorCount);
91  TTTestAssertion("created from = correctly null terminated",
92  r.string().at(3) == 0,
93  testAssertionCount,
94  errorCount);
95 
96  TTTestLog("\n");
97  TTTestLog("Testing == operator for symbols");
98 
99  TTSymbol my_symbol_ref = TTSymbol("puppies");
100  TTSymbol my_symbol_ref2 = TTSymbol("puppies");
101 
102  TTTestAssertion("two symbols created together are equivalent",
103  my_symbol_ref == my_symbol_ref2,
104  testAssertionCount,
105  errorCount);
106 
107  my_symbol_ref2 = TTSymbol("sine");
108 
109  TTTestAssertion("symbol matching item in global symbol table is equivalent",
110  kTTSym_sine == my_symbol_ref2,
111  testAssertionCount,
112  errorCount);
113 
114 }
115 
116 
117 // TODO: Benchmarking
118 
119 
120 TTErr TTSymbolTest::test(TTValue& returnedTestInfo)
121 {
122  int errorCount = 0;
123  int testAssertionCount = 0;
124 
125  TTSymbolTestBasic(errorCount, testAssertionCount);
126 
127  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
128 }
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
size_t length() const
Find out the length of a string.
Definition: TTString.h:151
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
size_t size() const
Find out the length of a string.
Definition: TTString.h:144
TT_OBJECT_CONSTRUCTOR
Constructor macro.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34