From b7d325fd2d375a74b4bf2825276c1ce96aba3de6 Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Wed, 4 Feb 2015 15:39:37 +0100 Subject: [PATCH] cunit tests clean --- base/ReStringList.cpp | 7 ++++-- base/ReStringList.hpp | 2 +- base/ReTestUnit.cpp | 3 +++ cunit/cuReStringList.cpp | 15 ++++++----- cunit/cuReStringUtils.cpp | 11 ++++++++ cunit/cuReTraverser.cpp | 53 --------------------------------------- os/ReDirTools.cpp | 15 +++-------- 7 files changed, 32 insertions(+), 74 deletions(-) diff --git a/base/ReStringList.cpp b/base/ReStringList.cpp index e09bd6d..96a45cd 100644 --- a/base/ReStringList.cpp +++ b/base/ReStringList.cpp @@ -156,7 +156,7 @@ const char* ReStringList::strOf(Index index) const{ const char* rc = NULL; if (index < count()){ Sequence* seq = getInfo(index); - rc = m_content.buffer() + seq->m_index; + rc = m_content.str() + seq->m_index; } return rc; } @@ -344,11 +344,12 @@ ReByteBuffer& ReStringList::join(const char* separator, ReByteBuffer& result, * @param filename the name of the file * @param separator this string was put between the substrings. May be NULL * @param mode the file open mode: "w" for truncate and write, "a" for append + * @param endOfFile NULL or a string written at the end of line * * @return true: the file could be opened. false: otherwise */ bool ReStringList::writeToFile(const char* filename, - const char* separator, const char* mode){ + const char* separator, const char* mode, const char* endOfFile){ bool rc = false; FILE* fp = fopen(filename, mode); if (fp){ @@ -358,6 +359,8 @@ bool ReStringList::writeToFile(const char* filename, if (ix != aCount - 1 && separator != NULL) fputs(separator, fp); } + if (endOfFile != NULL) + fputs(endOfFile, fp); fclose(fp); rc = true; } diff --git a/base/ReStringList.hpp b/base/ReStringList.hpp index d77a429..fff0330 100644 --- a/base/ReStringList.hpp +++ b/base/ReStringList.hpp @@ -60,7 +60,7 @@ public: size_t sumOfStrLengths() const; Tag tagOf(Index index) const; bool writeToFile(const char* filename, const char* separator = "\n", - const char* mode = "w"); + const char* mode = "w", const char* endOfFile = "\n"); }; #endif /* RESTRINGLIST_H_ */ diff --git a/base/ReTestUnit.cpp b/base/ReTestUnit.cpp index c2f3a68..7323c6c 100644 --- a/base/ReTestUnit.cpp +++ b/base/ReTestUnit.cpp @@ -20,6 +20,9 @@ ReTestUnit::ReTestUnit(const char* name, const char* sourceFile) m_sourceFile(sourceFile), m_buffer() { + int ix = m_sourceFile.rindexOf(OS_SEPARATOR, 1); + if (ix >= 0) + m_sourceFile.remove(0, ix + 1); logF(false, i18n("Start %s"), name); createTestDir(); } diff --git a/cunit/cuReStringList.cpp b/cunit/cuReStringList.cpp index 1a58df5..3471f55 100644 --- a/cunit/cuReStringList.cpp +++ b/cunit/cuReStringList.cpp @@ -30,11 +30,14 @@ private: line.append("!", -1); list.append(line, -5); checkEqu(2u, list.count()); + checkEqu(99ll, list.tagOf(0)); checkEqu("Hi", list.strOf(0)); checkEqu(-5ll, list.tagOf(1)); checkEqu("Hi!", list.strOf(1)); + + checkN(list.strOf(2)); } void testReplace(){ ReStringList list; @@ -163,12 +166,12 @@ private: checkEqu("99", list2.strOf(5)); list2.clear(); list2.readFromFile(file.str(), false); - checkEqu("1", list2.strOf(0)); - checkEqu("abc", list2.strOf(1)); - checkEqu("xyz", list2.strOf(2)); - checkEqu("4", list2.strOf(3)); - checkEqu("", list2.strOf(4)); - checkEqu("99", list2.strOf(5)); + checkEqu("1\n", list2.strOf(0)); + checkEqu("abc\n", list2.strOf(1)); + checkEqu("xyz\n", list2.strOf(2)); + checkEqu("4\n", list2.strOf(3)); + checkEqu("\n", list2.strOf(4)); + checkEqu("99\n", list2.strOf(5)); checkEqu(-1, list2.firstDiff(list2)); } diff --git a/cunit/cuReStringUtils.cpp b/cunit/cuReStringUtils.cpp index 6a784c1..6839381 100644 --- a/cunit/cuReStringUtils.cpp +++ b/cunit/cuReStringUtils.cpp @@ -15,10 +15,21 @@ public: } private: void run(){ + testLengthOfUnsigned(); testStrnicmp(); testIsInList(); testSplitPath(); } + void testLengthOfUnsigned(){ + unsigned int value; + checkEqu(3, (int) ReStringUtils::lengthOfUnsigned("123.4", -1, &value)); + checkEqu(123, (int) value); + value = 0x47112011; + checkEqu(0, (int)ReStringUtils::lengthOfUnsigned("", 0, &value)); + checkEqu(0x47112011, (int) value); + checkEqu(2, (int) ReStringUtils::lengthOfUnsigned("235", 2, &value)); + checkEqu(23, (int) value); + } void testStrnicmp(){ checkT(ReStringUtils::strnicmp("abc", "abc", 3) == 0); checkT(ReStringUtils::strnicmp("abc", "ab", 3) > 0); diff --git a/cunit/cuReTraverser.cpp b/cunit/cuReTraverser.cpp index c2f66c0..abddd2b 100644 --- a/cunit/cuReTraverser.cpp +++ b/cunit/cuReTraverser.cpp @@ -61,13 +61,9 @@ private: void run(){ initTree(); - testToolSync(); - testToolStatistic(); testBasic(); testDirOptions(); checkSetFilterFromProgramArgs(); - testDirStatistic(); - testCopyFile(); testList(); } void testList(){ @@ -191,55 +187,6 @@ private: checkOneFile("dir1_2", "dir1", hash); checkF(hash.get("cache.txt", buffer)); } - void testDirStatistic(){ - ReDirStatistic stat; - const ReStringList& list = stat.calculate(m_base.str(), 1); - ReByteBuffer buffer; - ReByteBuffer expected; - log(false, list.join("\n", buffer).str()); - checkEqu(4u, list.count()); - // "1 t:\temp\winfried\2\retestunit\dir1\n" - buffer.set(list.strOf(0), list.strLengthOf(0)); - checkT(buffer.startsWith("1\t")); - expected.set(m_base.str(), m_base.length()).append("dir1", -1) - .append(OS_SEPARATOR); - // .append(OS_SEPARATOR, -1) - checkT(buffer.endsWith(expected.str())); - - buffer.setLength(0); - const ReStringList& list2 = stat.calculate(m_base.str(), 1, formatWithSizeFilesAndDirs); - log(false, list2.join("\n", buffer).str()); - - buffer.set(list.strOf(0), list.strLengthOf(0)); - checkT(buffer.startsWith(" 0.000074 MB 3 4\t")); - expected.set(m_base.str(), m_base.length()).append("dir1", -1) - .append(OS_SEPARATOR); - checkT(buffer.endsWith(expected.str())); - - buffer.set(list.strOf(1), list.strLengthOf(1)); - checkT(buffer.startsWith(" 0.000054 MB 2 3\t")); - expected.set(m_base.str(), m_base.length()).append("dir2", -1) - .append(OS_SEPARATOR); - checkT(buffer.endsWith(expected.str())); - - buffer.set(list.strOf(2), list.strLengthOf(2)); - checkT(buffer.startsWith(" 0.000087 MB 5 6\t")); - expected.set(m_base.str(), m_base.length()); - } - void testToolStatistic(){ - ReDirTools tools; - const char* argv[] = { "dt", "stat", "-P;*;-*/cache/*", m_base.str(), "2" }; - tools.main(5, (char**) argv); - } - void testToolSync(){ - ReDirTools tools; - ReByteBuffer source(m_base); - source.append("dir1"); - ReByteBuffer target(makeDir("synctest")); - const char* argv[] = { "dt", "sync", "-P;*;-*/cache/*", "-p;*.txt", - source.str(), target.str() }; - tools.main(6, (char**) argv); - } }; extern void testReTraverser(void); diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 7742d5c..087bf9d 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -604,16 +604,9 @@ ReDirStatistic::ReDirStatistic(int deltaList, int deltaBuffer) : m_traceInterval(0), m_lastTrace(0) { - m_programArgs.addBool("quiet", - i18n("does not show additional information, e.g. runtime"), - 'q', "quiet", false); m_programArgs.addBool("kbyte", i18n("output is ' ' (like unix 'du' command)"), 'k', "kbyte", false); - m_programArgs.addInt("trace", - i18n("trace the current path every seconds.\n" - "0: no trace"), - 't', "trace-interval", 60); addStandardFilterOptions(); } /** @@ -768,7 +761,7 @@ void ReDirStatistic::run(int argc, const char* argv[]){ buffer.set(list.strOf(ix), list.strLengthOf(ix)); fprintf(m_output, "%s\n", buffer.str()); } - if (! m_programArgs.getBool("quiet")){ + if (m_verboseLevel >= V_SUMMARY){ int duration = int(time(NULL) - start); fprintf(m_output, "Duration: "); if (duration >= 3600) @@ -873,7 +866,6 @@ void ReDirList::list(int argc, const char* argv[]){ try { time_t start = time(NULL); m_programArgs.init(argc, argv); - bool verbose = ! m_programArgs.getBool("quiet"); bool shortOutput = m_programArgs.getBool("short"); setFilterFromProgramArgs(filter); bool noPath = m_programArgs.getArgCount() == 0; @@ -909,7 +901,7 @@ void ReDirList::list(int argc, const char* argv[]){ } } } - if (verbose){ + if (m_verboseLevel >= V_SUMMARY){ int duration = int(time(NULL) - start); fprintf(m_output, "+++ %d dirs and %d file(s) with %.6f MByte in %02d:%02d sec\n", dirs, files, sumSizes / 1E6, duration / 60, duration % 60); @@ -1016,7 +1008,6 @@ void ReDirBatch::createBatch(int argc, const char* argv[]){ ReByteBuffer script(m_programArgs.getString("script", buffer), -1); if (arguments.length() + script.length() == 0) help(i18n("one of the option must be set: -a (--arguments) or -c (--script)")); - bool verbose = ! m_programArgs.getBool("quiet"); #if defined __WIN32__ bool isExe = m_programArgs.getBool("isexe"); #endif @@ -1061,7 +1052,7 @@ void ReDirBatch::createBatch(int argc, const char* argv[]){ fprintf(m_output, "%s\n", line.str()); } } - if (verbose){ + if (m_verboseLevel >= V_SUMMARY){ int duration = int(time(NULL) - start); #if defined __linux__ const char* prefix = "#"; -- 2.39.5