Jamoma API  0.6.0.a19
TTRegex.test.cpp
1 /*
2  * Unit tests for the TTRegex object
3  * Copyright © 2015, Théo de la Hogue
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 "TTRegex.test.h"
10 
11 #define thisTTClass TTRegexTest
12 #define thisTTClassName "regex.test"
13 #define thisTTClassTags "test, foundation"
14 
15 
17 {;}
18 
19 
20 TTRegexTest::~TTRegexTest()
21 {;}
22 
23 
24 void TTRegexTestBasic(int& errorCount, int&testAssertionCount)
25 {
26  TTTestLog("\n");
27  TTTestLog("Testing regex parsing");
28 
29  TTString s_toParse("directory:/parent/name.instance:attribute");
30  TTString s_directory;
31  TTString s_attribute;
32  TTString s_parent;
33  TTString s_instance;
34  TTString s_name;
35 
36  // parse directory
37  if (!ttRegexForDirectory->parse(s_toParse.begin(), s_toParse.end()))
38  {
39  s_directory = TTString(ttRegexForDirectory->begin(), ttRegexForDirectory->end());
40  s_toParse.erase(ttRegexForDirectory->begin(), ttRegexForDirectory->end()+1); // +1 to remove ":"
41  }
42 
43  TTTestAssertion("correct parsing of directory",
44  s_directory == "directory",
45  testAssertionCount,
46  errorCount);
47 
48  // parse attribute
49  if (!ttRegexForAttribute->parse(s_toParse.begin(), s_toParse.end()))
50  {
51  s_attribute = TTString(ttRegexForAttribute->end(), s_toParse.end());
52  s_toParse.erase(ttRegexForAttribute->begin(), s_toParse.end()-1); // -1 to remove ":" and not erase the last \0
53  }
54 
55  TTTestAssertion("correct parsing of attribute",
56  s_attribute == "attribute",
57  testAssertionCount,
58  errorCount);
59 
60  // parse parent
61  if (!ttRegexForParent->parse(s_toParse.begin(), s_toParse.end()))
62  {
63  s_parent = TTString(ttRegexForParent->begin()+1, ttRegexForParent->end()); // +1 to remove leading "/"
64  s_toParse.erase(ttRegexForParent->begin(), ttRegexForParent->end()+1); // +1 to remove "/" after parent
65  }
66 
67  TTTestAssertion("correct parsing of parent",
68  s_parent == "parent",
69  testAssertionCount,
70  errorCount);
71 
72  // parse instance
73  if (!ttRegexForInstance->parse(s_toParse.begin(), s_toParse.end()))
74  {
75  s_instance = TTString(ttRegexForInstance->end(), s_toParse.end()-1);
76  s_toParse.erase(ttRegexForInstance->begin(), s_toParse.end()-1); // -1 to remove "." and not erase the last \0
77  }
78 
79  TTTestAssertion("correct parsing of instance",
80  s_instance == "instance",
81  testAssertionCount,
82  errorCount);
83 
84  s_name = s_toParse;
85 
86  TTTestAssertion("correct parsing of name",
87  s_name == "name",
88  testAssertionCount,
89  errorCount);
90 }
91 
92 TTErr TTRegexTest::test(TTValue& returnedTestInfo)
93 {
94  int errorCount = 0;
95  int testAssertionCount = 0;
96 
97  TTRegexTestBasic(errorCount, testAssertionCount);
98 
99  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
100 }
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
The TTString class is used to represent a string.
Definition: TTString.h:34
TT_OBJECT_CONSTRUCTOR
Constructor macro.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34