*/
ReTestUnit::ReTestUnit(const char* name, const char* sourceFile)
:
- m_name(_strdup(name)),
m_errorCount(0),
- m_sourceFile(_strdup(sourceFile))
+ m_name(name),
+ m_sourceFile(sourceFile),
+ m_buffer()
{
logF(false, i18n("Start %s"), name);
}
*/
ReTestUnit::~ReTestUnit() {
if (m_errorCount > 0)
- logF(false, i18n("+++ %s: %d error(s)"), m_name, m_errorCount);
- free((void*) m_name);
- free((void*) m_sourceFile);
+ logF(false, i18n("+++ %s: %d error(s)"), m_name.str(), m_errorCount);
}
/** @brief Checks a boolean expression. A false value will be logged.
*
void ReTestUnit::assertTrue(bool condition, int lineNo)
{
if (! condition){
- logF(true, i18n("%s-%d: not true!"), m_sourceFile, lineNo);
+ logF(true, i18n("%s-%d: not true!"), m_sourceFile.str(), lineNo);
}
}
/** @brief Checks a boolean expression. A true value will be logged.
void ReTestUnit::assertFalse(bool condition, int lineNo)
{
if (condition){
- logF(true, i18n("%s-%d: not false!"), m_sourceFile, lineNo);
+ logF(true, i18n("%s-%d: not false!"), m_sourceFile.str(), lineNo);
}
}
/** @brief Checks a pointer expression. A not <code>null</code> value will be logged.
*/
void ReTestUnit::assertNull(void* pointer, int lineNo){
if (pointer != NULL){
- logF(true, "%s-%d: is not null %lx", m_sourceFile, lineNo, pointer);
+ logF(true, "%s-%d: is not null %llx", m_sourceFile.str(), lineNo, (int64_t) pointer);
}
}
/** @brief Checks a pointer expression. A <code>null</code> value will be logged.
*/
void ReTestUnit::assertNotNull(void* pointer, int lineNo){
if (pointer == NULL){
- logF(true, i18n("%s-%d: is null"), m_sourceFile, lineNo);
+ logF(true, i18n("%s-%d: is null"), m_sourceFile.str(), lineNo);
}
}
/** @brief Compares two integer values. If not equal this will be logged.
void ReTestUnit::assertEqual(int expected, int current, int lineNo){
if (expected != current){
logF(true, i18n("%s-%d: expected: %ld (%lx) current: %ld (%lx)"),
- m_sourceFile, lineNo, expected, expected, current, current);
+ m_sourceFile.str(), lineNo, expected, expected, current, current);
}
}
/** @brief Compares two integer values. If not equal this will be logged.
void ReTestUnit::assertEqual(unsigned int expected, unsigned int current, int lineNo){
if (expected != current){
logF(true, i18n("%s-%d: expected: %ld (%lx) current: %ld (%lx)"),
- m_sourceFile, lineNo, expected, expected, current, current);
+ m_sourceFile.str(), lineNo, expected, expected, current, current);
}
}
/** @brief Compares two integer values. If not equal this will be logged.
void ReTestUnit::assertEqual(int64_t expected, int64_t current, int lineNo){
if (expected != current){
logF(true, i18n("%s-%d: expected: %lld (%llx) current: %lld (%llx)"),
- m_sourceFile, lineNo, expected, expected, current, current);
+ m_sourceFile.str(), lineNo, expected, expected, current, current);
}
}
/** @brief Compares two string values. If not equal this will be logged.
void ReTestUnit::assertEqual(const char* expected, const char* current, int lineNo){
if (current == NULL || strcmp(expected, current) != 0){
logF(true, i18n("%s-%d: expected / current: length: %d / %d\n%.512s\n%.512s"),
- m_sourceFile, lineNo, strlen(expected), current == NULL ? 0 : strlen(current),
+ m_sourceFile.str(), lineNo, strlen(expected), current == NULL ? 0 : strlen(current),
expected, current == NULL ? "<null>" : current);
}
}
struct stat info;
if (stat(name, &info) != 0){
logF(true, i18n("%s-%d: File does not exist: %s"),
- m_sourceFile, lineNo, name);
+ m_sourceFile.str(), lineNo, name);
} else if (S_ISDIR(info.st_mode)){
logF(true, i18n("%s-%d: File does exist but this is a directory: %s"),
- m_sourceFile, lineNo, name);
+ m_sourceFile.str(), lineNo, name);
}
}
/** @brief Checks whether two files have the same content. If not this will be logged.
ReByteBuffer line1(list1.strOf(ix), list1.strLengthOf(ix));
int ixLine = line1.firstDifference(list2.strOf(ix), list2.strLengthOf(ix));
logF(true, i18n("%s-%d: Files differ in line %d-%d\n%s\n%s\n%s"),
- m_sourceFile, lineNo, ix, ixLine, list1.strOf(ix), list2.strOf(ix),
+ m_sourceFile.str(), lineNo, ix, ixLine,
+ list1.count() > ix ? list1.strOf(ix) : "",
+ list2.count() > ix ? list2.strOf(ix) : "",
colMarker(ixLine));
}
_snprintf(cmd, sizeof cmd, "rm -Rf %s*", name);
system(cmd);
}
- strcpy(m_tempDir, name);
+ m_tempDir.set(name, -1);
}
/** @brief Returns the temporary directory.
*
* @return the name of a temporary directory
*/
const char* ReTestUnit::getTestDir(){
- return (const char*) m_tempDir;
+ return m_tempDir.str();
}
/** @brief Creates a file and fills it with an given content.
*
struct stat info;
if (stat(dir, &info) != 0){
logF(true, i18n("%s-%d: Directory does not exist: %s"),
- m_sourceFile, lineNo, dir);
+ m_sourceFile.str(), lineNo, dir);
} else if (! S_ISDIR(info.st_mode)){
logF(true, i18n("%s-%d: File exists but this is not a directory: %s"),
- m_sourceFile, lineNo, dir);
+ m_sourceFile.str(), lineNo, dir);
}
}
}
private:
void run(){
+#if 0
testAppendByteBuffer();
testBase();
testReplace();
testJoin();
testEqu();
testFile();
+#endif
}
void testAppendByteBuffer(){
ReStringList list;
}
void testFile(){
- createTestDir();
- ReByteBuffer file;
- file.set(getTestDir(), -1).append("abc.csv", -1);
-
- ReStringList list;
- const char* str = "1;abc;xyz;4;;99";
- list.split(str, ';');
- list.writeToFile(file.str(), "\n");
-
- ReStringList list2;
- list2.readFromFile(file.str(), true);
-
- checkEqu(-1, list2.firstDiff(list2));
+ if (true){
+ createTestDir();
+ ReByteBuffer file;
+ file.set(getTestDir(), -1).append("abc.csv", -1);
+
+ ReStringList list;
+ const char* str = "1;abc;xyz;4;;99";
+ list.split(str, ';');
+ list.writeToFile(file.str(), "\n");
+
+ ReStringList list2;
+ list2.readFromFile(file.str(), true);
+
+ checkEqu(-1, list2.firstDiff(list2));
+ }
+ //log(false, "end of testFile()");
}
void testBase(){
- ReStringList list;
- ReByteBuffer value;
-
- list.append("123", 100);
- checkEqu(0U, list.indexOf("123"));
- list.append("a", 200);
- list.append("vwxyz", 300);
-
- checkEqu(3U, list.count());
- int index = 0;
- checkEqu("123", list.strOf(index));
- checkEqu(4U, list.sizeOf(index));
- checkEqu((int64_t) 100, list.tagOf(index));
-
- index++;
- checkEqu("a", list.strOf(index));
- checkEqu(2U, list.sizeOf(index));
- checkEqu((int64_t) 200, list.tagOf(index));
-
- index++;
- checkEqu("vwxyz", list.strOf(index));
- checkEqu(6U, list.sizeOf(index));
- checkEqu((int64_t) 300, list.tagOf(index));
-
- checkEqu(12U, list.sumOfSizes());
-
- list.insert(0, "0", 50);
- checkEqu(4U, list.count());
- checkEqu(14U, list.sumOfSizes());
-
- index = 0;
- checkEqu("0", list.strOf(index));
- checkEqu(2U, list.sizeOf(index));
- checkEqu((int64_t) 50, list.tagOf(index));
-
- index++;
- checkEqu("123", list.strOf(index));
- checkEqu(4U, list.sizeOf(index));
- checkEqu((int64_t) 100, list.tagOf(index));
-
- index++;
- checkEqu("a", list.strOf(index));
- checkEqu(2U, list.sizeOf(index));
- checkEqu((int64_t) 200, list.tagOf(index));
-
- index++;
- checkEqu("vwxyz", list.strOf(index));
- checkEqu(6U, list.sizeOf(index));
- checkEqu((int64_t) 300, list.tagOf(index));
-
- checkEqu(0U, list.indexOf("0"));
- checkEqu(1U, list.indexOf("123"));
- checkEqu(2u, list.indexOf("a"));
- checkEqu(2u, list.indexOf("A", true));
- checkEqu(3u, list.indexOf("vwxyz"));
- checkEqu(3u, list.indexOf("VwXyz", true));
-
- checkEqu(0u, list.indexOf("0", false, 0));
- checkEqu(1u, list.indexOf("123", false, 1));
- checkEqu(2u, list.indexOf("a", false, 1));
- checkEqu(2u, list.indexOf("a", false, 2));
- checkEqu(2u, list.indexOf("A", true, 2));
- checkEqu(3u, list.indexOf("vwxyz", false, 2));
- checkEqu(3u, list.indexOf("vwxyz", false, 3));
- checkEqu(3u, list.indexOf("VwXyz", true, 3));
-
- checkEqu((ReStringList::Index) -1, list.indexOf("A"));
- checkEqu((ReStringList::Index) -1, list.indexOf("0123"));
- checkEqu((ReStringList::Index) -1, list.indexOf("a", false, 3));
- checkEqu((ReStringList::Index) -1, list.indexOf("A", true, 3));
-
- checkEqu(0u, list.nextStartingWith(0, "0"));
- checkEqu(1u, list.nextStartingWith(0, "12"));
- checkEqu(2u, list.nextStartingWith(0, "a"));
- checkEqu(2u, list.nextStartingWith(1, "a"));
- checkEqu(2u, list.nextStartingWith(2, "a"));
- checkEqu(2u, list.nextStartingWith(0, "A", true));
- checkEqu((ReStringList::Index) -1, list.nextStartingWith(2, "Ab", true));
- checkEqu((ReStringList::Index) -1, list.nextStartingWith(0, "b", true));
-
- checkEqu(3u, list.nextStartingWith(0, "vwxy", false));
- checkEqu(3u, list.nextStartingWith(0, "vwxy", true));
- checkEqu((ReStringList::Index) -1, list.nextStartingWith(0, "vWxY", false));
-
- ReStringList list2;
- list2.append("a", 100);
- list2.append("b", 200);
- list2.append("c", 300);
- ReStringList list3;
- list3.append("x", 1000);
- list3.append("y", 2000);
-
- list2.append(list3);
- checkEqu(5u, list2.count());
- checkEqu("a", list2.strOf(0));
- checkEqu(100ll, list2.tagOf(0));
- checkEqu("b", list2.strOf(1));
- checkEqu(200ll, list2.tagOf(1));
- checkEqu("c", list2.strOf(2));
- checkEqu(300ll, list2.tagOf(2));
- checkEqu("x", list2.strOf(3));
- checkEqu(1000ll, list2.tagOf(3));
- checkEqu("y", list2.strOf(4));
- checkEqu(2000ll, list2.tagOf(4));
+ if (true){
+ ReStringList list;
+ ReByteBuffer value;
+
+ list.append("123", 100);
+ checkEqu(0U, list.indexOf("123"));
+ list.append("a", 200);
+ list.append("vwxyz", 300);
+
+ checkEqu(3U, list.count());
+ int index = 0;
+ checkEqu("123", list.strOf(index));
+ checkEqu(4U, list.sizeOf(index));
+ checkEqu((int64_t) 100, list.tagOf(index));
+
+ index++;
+ checkEqu("a", list.strOf(index));
+ checkEqu(2U, list.sizeOf(index));
+ checkEqu((int64_t) 200, list.tagOf(index));
+
+ index++;
+ checkEqu("vwxyz", list.strOf(index));
+ checkEqu(6U, list.sizeOf(index));
+ checkEqu((int64_t) 300, list.tagOf(index));
+
+ checkEqu(12U, list.sumOfSizes());
+
+ list.insert(0, "0", 50);
+ checkEqu(4U, list.count());
+ checkEqu(14U, list.sumOfSizes());
+
+ index = 0;
+ checkEqu("0", list.strOf(index));
+ checkEqu(2U, list.sizeOf(index));
+ checkEqu((int64_t) 50, list.tagOf(index));
+
+ index++;
+ checkEqu("123", list.strOf(index));
+ checkEqu(4U, list.sizeOf(index));
+ checkEqu((int64_t) 100, list.tagOf(index));
+
+ index++;
+ checkEqu("a", list.strOf(index));
+ checkEqu(2U, list.sizeOf(index));
+ checkEqu((int64_t) 200, list.tagOf(index));
+
+ index++;
+ checkEqu("vwxyz", list.strOf(index));
+ checkEqu(6U, list.sizeOf(index));
+ checkEqu((int64_t) 300, list.tagOf(index));
+
+ checkEqu(0U, list.indexOf("0"));
+ checkEqu(1U, list.indexOf("123"));
+ checkEqu(2u, list.indexOf("a"));
+ checkEqu(2u, list.indexOf("A", true));
+ checkEqu(3u, list.indexOf("vwxyz"));
+ checkEqu(3u, list.indexOf("VwXyz", true));
+
+ checkEqu(0u, list.indexOf("0", false, 0));
+ checkEqu(1u, list.indexOf("123", false, 1));
+ checkEqu(2u, list.indexOf("a", false, 1));
+ checkEqu(2u, list.indexOf("a", false, 2));
+ checkEqu(2u, list.indexOf("A", true, 2));
+ checkEqu(3u, list.indexOf("vwxyz", false, 2));
+ checkEqu(3u, list.indexOf("vwxyz", false, 3));
+ checkEqu(3u, list.indexOf("VwXyz", true, 3));
+
+ checkEqu((ReStringList::Index) -1, list.indexOf("A"));
+ checkEqu((ReStringList::Index) -1, list.indexOf("0123"));
+ checkEqu((ReStringList::Index) -1, list.indexOf("a", false, 3));
+ checkEqu((ReStringList::Index) -1, list.indexOf("A", true, 3));
+
+ checkEqu(0u, list.nextStartingWith(0, "0"));
+ checkEqu(1u, list.nextStartingWith(0, "12"));
+ checkEqu(2u, list.nextStartingWith(0, "a"));
+ checkEqu(2u, list.nextStartingWith(1, "a"));
+ checkEqu(2u, list.nextStartingWith(2, "a"));
+ checkEqu(2u, list.nextStartingWith(0, "A", true));
+ checkEqu((ReStringList::Index) -1, list.nextStartingWith(2, "Ab", true));
+ checkEqu((ReStringList::Index) -1, list.nextStartingWith(0, "b", true));
+
+ checkEqu(3u, list.nextStartingWith(0, "vwxy", false));
+ checkEqu(3u, list.nextStartingWith(0, "vwxy", true));
+ checkEqu((ReStringList::Index) -1, list.nextStartingWith(0, "vWxY", false));
+
+ ReStringList list2;
+ list2.append("a", 100);
+ list2.append("b", 200);
+ list2.append("c", 300);
+ ReStringList list3;
+ list3.append("x", 1000);
+ list3.append("y", 2000);
+
+ list2.append(list3);
+ checkEqu(5u, list2.count());
+ checkEqu("a", list2.strOf(0));
+ checkEqu(100ll, list2.tagOf(0));
+ checkEqu("b", list2.strOf(1));
+ checkEqu(200ll, list2.tagOf(1));
+ checkEqu("c", list2.strOf(2));
+ checkEqu(300ll, list2.tagOf(2));
+ checkEqu("x", list2.strOf(3));
+ checkEqu(1000ll, list2.tagOf(3));
+ checkEqu("y", list2.strOf(4));
+ checkEqu(2000ll, list2.tagOf(4));
+ }
+ //log(false, "end of testbase");
}
};
extern void testReStringList(void);