]> gitweb.hamatoma.de Git - crepublib/commitdiff
cunit tests clean
authorHamatoma <git.tortouse@hm.f-r-e-i.de>
Wed, 4 Feb 2015 14:39:37 +0000 (15:39 +0100)
committerHamatoma <git.tortouse@hm.f-r-e-i.de>
Wed, 4 Feb 2015 14:39:37 +0000 (15:39 +0100)
base/ReStringList.cpp
base/ReStringList.hpp
base/ReTestUnit.cpp
cunit/cuReStringList.cpp
cunit/cuReStringUtils.cpp
cunit/cuReTraverser.cpp
os/ReDirTools.cpp

index e09bd6d14e3e1c4850e86470b45add6278f0e2dd..96a45cde8f0c55c93d3743bb1d9ea235092cceb8 100644 (file)
@@ -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;
        }
index d77a429aa87527439e0eab3f3f787ec1c55a1e20..fff0330d105e1c6876f47b34d0bfbba4f84e33b4 100644 (file)
@@ -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_ */
index c2f3a684eee5f877094ac7281f3736d7360d8d38..7323c6c1055cbf12fc06a4556856d1abf990e92a 100644 (file)
@@ -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();
 }
index 1a58df58ddb031e9d256ede04e51d4673e7e0202..3471f5523676e1735de93190eec4690b5b46523c 100644 (file)
@@ -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));
                }
index 6a784c1d1f218c41758627b2b51a6b9831b81688..6839381dae4872b81816b0cede8bcc2eefa95746 100644 (file)
@@ -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);
index c2f66c0725a8743c28a3651c616c96a18a9644b9..abddd2bf26ab4496af4732c6a136266a0bbe2e96 100644 (file)
@@ -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);
 
index 7742d5cef996f40de86c2886a81f7887480626ec..087bf9d07fe4a434f3d1cd8e8597b1efd949ebc2 100644 (file)
@@ -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 '<kbyte> <path>' (like unix 'du' command)"),
         'k', "kbyte", false);
-    m_programArgs.addInt("trace", 
-        i18n("trace the current path every <number> 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 = "#";