]> gitweb.hamatoma.de Git - crepublib/commitdiff
Refactoring. Bug: missing FindClose()
authorHamatoma <git.tortouse@hm.f-r-e-i.de>
Wed, 25 Feb 2015 11:20:06 +0000 (12:20 +0100)
committerHamatoma <git.tortouse@hm.f-r-e-i.de>
Wed, 25 Feb 2015 11:20:06 +0000 (12:20 +0100)
18 files changed:
base/ReByteBuffer.cpp
base/ReByteBuffer.hpp
base/ReDirectory.cpp
base/ReDirectory.hpp
base/ReTestUnit.cpp
base/ReTestUnit.hpp
cunit/cuReByteBuffer.cpp
cunit/cuReDirTools.cpp
cunit/cuReHashList.cpp
cunit/cuReMD5.cpp
cunit/cuReSeqArray.cpp
cunit/cuReStringList.cpp
cunit/cuReStringUtils.cpp
cunit/cuReconfig.cpp
cunit/testall.cpp
os/ReDirTools.cpp
os/ReDirTools.hpp
os/ReTraverser.cpp

index 06e6c3e6ea83bc3d985af3cfc9918e4c1f8b8256..4f2802072eb35d32596f0a8549472e93e90e0d58 100644 (file)
@@ -161,6 +161,53 @@ ReByteBuffer& ReByteBuffer::append(double value, const char* format){
        return *this;
 }
 
+/**
+ * Appends a string with minimal/maximal length.
+ *
+ * If the length is greater than the maximal length the string will be cutted
+ * (in the middle) and a separator will set at the cut.
+ *
+ * <pre>Example:
+ * <code>buffer.appendFix("sammy2", -1, 5, 5, "*").appendFix("x", 1, 99, -3);
+ * </code>
+ * Buffer contains: "sa*y2  x"
+ * </pre>
+ *
+ * @param data                 data to append
+ * @param length               length of <code>data</code>. -1: <code>strlen(data)</code>
+ * @param maxLength            the stored length is at most this value
+ * @param minLength            if the length is smaller padding characters will be added<br>
+ *                                             < 0: padding is done at the top
+ * @param separator            NULL or the string used at the separaration point
+ * @param padding              character used for padding (see <code>minLength</code>)
+ * @return                             <code>*this</code> (for chaining)
+ */
+ReByteBuffer& ReByteBuffer::appendFix(const char* data, size_t length, int maxLength, 
+       int minLength, const char* separator, char padding){
+       if (length == (size_t) -1)
+               length = strlen(data);
+       if (length < abs(minLength)){
+               ensureSize(m_length + abs(minLength));
+               if (minLength < 0)
+                       appendChar(padding, - minLength - length);
+               append(data, length);
+               if (minLength > 0)
+                       appendChar(padding, minLength - length); 
+       } else if (length > maxLength){
+               ensureSize(m_length + maxLength);
+               int sepLength = separator == NULL ? 0 : strlen(separator);
+               int lengthPart1 = (maxLength - sepLength + 1) / 2;
+               int lengthPart2 = maxLength - sepLength - lengthPart1;
+               append(data, lengthPart1);
+               if (sepLength > 0)
+                       append(separator, sepLength);
+               append(data + length - lengthPart2, lengthPart2);
+       } else {
+               append(data, length);
+       }
+       return *this;
+}
+
 /**
  * Appends a hexadecimal dump of a memory array.
  *
@@ -183,6 +230,7 @@ ReByteBuffer& ReByteBuffer::append(double value, const char* format){
  * @param gapBehind            behind <code>gapBehind</code> hex bytes a ' ' is appended<br>
  *                                             -1: <code>bytePerLine / 2</code>
  * @param separator            NULL or a string between hex area and ASCII area
+ * @return                             <code>*this</code> (for chaining)
  */
 ReByteBuffer& ReByteBuffer::appendHexDump(const char* data, size_t length,
                int offset, int bytesPerLine, const char* offsetFormat,
index 0769f06c6997132ec636d194968e1331f3651777..849c3f79e37180035665f0ab14385cb7573637af 100644 (file)
@@ -69,6 +69,8 @@ public:
                }
                return *this;
        }
+       ReByteBuffer& appendFix(const char* data, size_t length, int maxLength, 
+               int minLength = 0, const char* separator = "*", char padding = ' ');
        ReByteBuffer& appendHexDump(const char* data, size_t length = -1,
                int offset = 0, int bytePerLine = 16,
                const char* offsetFormat = "%04x: ", bool withAscii = true,
index 64fe2e00902825e78a26b12903b37793e75e5e80..d9daca8127a57b57d57ac1af243c631f5b2a50c4 100644 (file)
@@ -23,7 +23,7 @@ ReDirectory::ReDirectory() :
        m_regExprIsInitialized(false),
        m_isRegExpr(false)
 #elif defined __WIN32__
-    m_handle(0)
+    m_handle(INVALID_HANDLE_VALUE)
     //m_data()
 #endif
 {
@@ -56,6 +56,11 @@ ReDirectory::ReDirectory(const char* path) :
 /** @brief Destructor.
  */
 ReDirectory::~ReDirectory(){
+       close();
+}
+/** @brief Frees the resources.
+*/
+void ReDirectory::close(){
 #if defined __linux__
        if (m_dir != NULL){
                closedir(m_dir);
@@ -65,6 +70,10 @@ ReDirectory::~ReDirectory(){
        if (m_regExprIsInitialized)
                regfree(&m_regExpr);
 #elif defined __WIN32__
+       if (m_handle != INVALID_HANDLE_VALUE){
+               FindClose(m_handle);
+               m_handle = INVALID_HANDLE_VALUE;
+       }
 #endif
 }
 /** @brief Returns the name of the current file found by the last <code>findFirst()</code>
@@ -90,6 +99,7 @@ const char* ReDirectory::currentFile(){
  *                                             false: only the files and subdirs in the dir will be deleted
  */
 void ReDirectory::deleteTree(const char* base, bool deleteBaseToo){
+       if (true){
        ReDirectory dir(base);
        if (dir.findFirst("*", false)){
                ReByteBuffer full;
@@ -105,10 +115,12 @@ void ReDirectory::deleteTree(const char* base, bool deleteBaseToo){
                        }
                } while(dir.findNext());
        }
+       dir.close();
        if (deleteBaseToo){
                _rmdir(base);
        }
 }
+}
 
 /** @brief Returns the name of the directory.
  *
index 0739faca675f5837e5f2125a5a1e158463ef6af7..315dbda2ab4b530b46a40501e49fa549f8ebfc05 100644 (file)
@@ -17,6 +17,7 @@ public:
        ReDirectory(const char* path);
        ~ReDirectory();
 public:
+       void close();
        const char* currentFile();
        bool findFirst(const char* pattern, bool isRegExpr);
        bool findNext();
index b78bcb4972c81d85a8005a302a3f0c7b6b9dd5ae..24ab0c594054f2a4841106cb14244b25c069ae58 100644 (file)
@@ -133,7 +133,24 @@ void ReTestUnit::assertEqual(const char* expected, const char* current, int line
                                expected, current == NULL ? "<null>" : current);
        }
 }
-
+/** @brief Compares a string and a ReByteBuffer. If not equal this will be logged.
+ *
+ * @param expected             the expected value
+ * @param current              the current value
+ * @param lineNo               the line number of the test (for the error message)
+ */
+void ReTestUnit::assertEqual(const char* expected, const ReByteBuffer& current, int lineNo){
+       assertEqual(expected, current.str(), lineNo);
+}
+/** @brief Compares two ReByteBuffer objects. If not equal this will be logged.
+ *
+ * @param expected             the expected value
+ * @param current              the current value
+ * @param lineNo               the line number of the test (for the error message)
+ */
+void ReTestUnit::assertEqual(const ReByteBuffer& expected, const ReByteBuffer& current, int lineNo){
+       assertEqual(expected.str(), current.str(), lineNo);
+}
 /** @brief Compares two string values. If not equal this will be logged.
  *
  * @param expected             the expected value
index e515d8a3c10c15c6d14da5e76d0f04197bc83360..568aebdb3722388b3602d366dc2f86feede17495 100644 (file)
@@ -25,6 +25,8 @@ public:
        void assertEqual(int expected, int current, int lineNo);
        void assertEqual(unsigned int expected, unsigned int current, int lineNo);
        void assertEqual(const char* expected, const char* current, int lineNo);
+       void assertEqual(const char* expected, const ReByteBuffer& current, int lineNo);
+       void assertEqual(const ReByteBuffer& expected, const ReByteBuffer& current, int lineNo);
        void assertEqualIgnoreCase(const char* expected, const char* current, int lineNo);
        void assertEqualFiles(const char* name1, const char* name2, int lineNo);
        void assertFileExists(const char* name, int lineNo);
index 13154800ba0e9255b4180c56c7c2066dc4a421ef..c26110316835b49a83e4b2e2ef1fbaa5088cfb7a 100644 (file)
@@ -15,6 +15,7 @@ public:
        }
 private:
        void run(){
+               testAppendFix();
                testEnsureLastChar();
                testLastChar();
                testReduceLength();
@@ -45,6 +46,41 @@ private:
                testSplice();
                testReplace();
        }
+       void testAppendFix(){
+               ReByteBuffer buffer;
+               // maxLength exceeded
+               // odd maxlength:
+               buffer.appendFix("123456", -1, 5);
+               checkEqu("12*56", buffer);
+               // given separator, even maxLength
+               buffer.appendFix("abcdefg", -1, 4, 4, ".");
+               checkEqu("12*56ab.g", buffer);
+               // given separator with more than one char / no separator
+               buffer.appendFix("ABCDEF", -1, 5, 5, "...").appendFix("xyz", -1, 2, 0, NULL);
+               checkEqu("12*56ab.gA...Fxz", buffer);
+
+               buffer = "x";
+               // minlength not reached: 
+               // data length given, minLength == length
+               buffer.appendFix("123", 2U, 99, 2, NULL, ':');
+               checkEqu("x12", buffer);
+               // positive minLength
+               buffer.appendFix("abc", -1, 99, 4, NULL, ':');
+               checkEqu("x12abc:", buffer);
+               // negative minLength
+               buffer.appendFix("AB", -1, 99, -4, NULL, '.');
+               checkEqu("x12abc:..AB", buffer);
+
+               buffer = "y";
+               // minLength and maxLength not reached:
+               // minLength equal, maxLength equal:
+               buffer.appendFix("1234", 4, 4, 4);
+               checkEqu("y1234", buffer);
+               // minLength smaller, maxLength larger:
+               buffer.appendFix("a", 1, 2, 1);
+               checkEqu("y1234a", buffer);
+
+       }
        void testEnsureLastChar(){
                ReByteBuffer buffer("1/");
                buffer.ensureLastChar('/');
@@ -64,13 +100,13 @@ private:
                ReByteBuffer buffer("12345");
                buffer.reduceLength();
                checkEqu(4U, buffer.length());
-               checkEqu("1234", buffer.str());
+               checkEqu("1234", buffer);
                buffer.reduceLength(2);
                checkEqu(2U, buffer.length());
-               checkEqu("12", buffer.str());
+               checkEqu("12", buffer);
                buffer.reduceLength(0).reduceLength(-1);
                checkEqu(2U, buffer.length());
-               checkEqu("12", buffer.str());
+               checkEqu("12", buffer);
                buffer.reduceLength(99);
                checkEqu(0U, buffer.length());
        }
@@ -78,48 +114,48 @@ private:
                ReByteBuffer buffer("123");
                buffer.removeLastChar('x').removeLastChar('3');
                checkEqu(2U, buffer.length());
-               checkEqu("12", buffer.str());
+               checkEqu("12", buffer);
        }
        void testAppendChar(){
                ReByteBuffer buffer;
                buffer.appendChar('1');
                checkEqu(1U, buffer.length());
-               checkEqu("1", buffer.str());
+               checkEqu("1", buffer);
                buffer.appendChar('2');
                checkEqu(2U, buffer.length());
-               checkEqu("12", buffer.str());
+               checkEqu("12", buffer);
 
                buffer.appendChar('x', 1);
                checkEqu(3U, buffer.length());
-               checkEqu("12x", buffer.str());
+               checkEqu("12x", buffer);
 
                buffer.appendChar('y', 3);
                checkEqu(6U, buffer.length());
-               checkEqu("12xyyy", buffer.str());
+               checkEqu("12xyyy", buffer);
 
                buffer.appendChar('x', 0);
                checkEqu(6U, buffer.length());
-               checkEqu("12xyyy", buffer.str());
+               checkEqu("12xyyy", buffer);
 
                buffer.appendChar('x', -1);
                checkEqu(6U, buffer.length());
-               checkEqu("12xyyy", buffer.str());
+               checkEqu("12xyyy", buffer);
 
        }
        void testAppendFloat(){
                ReByteBuffer buffer;
 
                buffer.append(125 / 100.0);
-               checkEqu("1.250000", buffer.str());
+               checkEqu("1.250000", buffer);
                buffer.append(0.333, "%.2f");
-               checkEqu("1.2500000.33", buffer.str());
+               checkEqu("1.2500000.33", buffer);
        }
        void testAppendInt64(){
                ReByteBuffer buffer;
                buffer.appendInt((int64_t) 12345678901ll);
-               checkEqu("12345678901", buffer.str());
+               checkEqu("12345678901", buffer);
                buffer.appendInt((uint64_t) 0x123456789ll, "%llx");
-               checkEqu("12345678901123456789", buffer.str());
+               checkEqu("12345678901123456789", buffer);
 
        }
        void testEnsureSize2(){
@@ -139,33 +175,33 @@ private:
                buf.appendHexDump("abcdefghijklmnopq");
                checkEqu("0000: 61 62 63 64 65 66 67 68  69 6a 6b 6c 6d 6e 6f 70 | abcdefgh ijklmnop\n"
                                 "0010: 71                                               | q                \n",
-                                buf.str());
+                                buf);
                buf.setLength(0).appendHexDump("abcdefghijklmnopq", 16);
                checkEqu("0000: 61 62 63 64 65 66 67 68  69 6a 6b 6c 6d 6e 6f 70 | abcdefgh ijklmnop\n",
-                                buf.str());
+                                buf);
                buf.setLength(0).appendHexDump("\t\nü23456789x123456", -1, 20, 8, "%3d: ", true,
                        4, 0, NULL);
                checkEqu(" 20: 090ac3bc 32333435....2345\n"
                        " 28: 36373839 783132336789x123\n"
-                       " 36: 343536           456     \n", buf.str());
+                       " 36: 343536           456     \n", buf);
                buf.setLength(0).appendHexDump("abcdefghijk", -1, 0, 8, "%3d: ", true, 2, 4);
                checkEqu("  0: 6162 6364  6566 6768 | abcd efgh\n"
-                            "  8: 696a 6b              | ijk      \n", buf.str());
+                            "  8: 696a 6b              | ijk      \n", buf);
        }
        void testFill(){
                ReByteBuffer buf;
                buf.fill('=', 0, 3);
-               checkEqu("===", buf.str());
+               checkEqu("===", buf);
                buf.fill('x', 1, 2);
-               checkEqu("=x=", buf.str());
+               checkEqu("=x=", buf);
        }
        void testAppendMilliSec(){
                ReByteBuffer buf;
-               checkEqu("5.123", buf.appendMilliSec(5123).str());
+               checkEqu("5.123", buf.appendMilliSec(5123));
                checkEqu("32:45.789", buf.setLength(0)
-                       .appendMilliSec(32*60*1000+45789).str());
+                       .appendMilliSec(32*60*1000+45789));
                checkEqu("17:04:06.976", buf.setLength(0)
-                       .appendMilliSec(17*3600*1000 + 4*60*1000 + 6976).str());
+                       .appendMilliSec(17*3600*1000 + 4*60*1000 + 6976));
        }
        void testSetDelta(){
                ReByteBuffer buf("abcd");
@@ -349,7 +385,7 @@ private:
 
                buffer.append((Byte*)"123", 3);
                checkEqu("123", buffer.buffer());
-               checkEqu("123", buffer.str());
+               checkEqu("123", buffer);
                checkEqu(3u, buffer.length());
                buffer.append((Byte*)"ab", 2);
                checkEqu("123ab", buffer.buffer());
@@ -374,22 +410,22 @@ private:
                checkEqu(3u, buffer.length());
                buffer.append(buffer2);
                checkEqu("abcxyz", buffer.buffer());
-               checkEqu("abcxyz", buffer.str());
+               checkEqu("abcxyz", buffer);
                checkEqu(6u, buffer.length());
 
                buffer.setLength(0);
                buffer.appendInt(-1);
-               checkEqu("-1", buffer.str());
+               checkEqu("-1", buffer);
                checkEqu(2u, buffer.length());
 
                buffer.appendInt(9, "%03d");
-               checkEqu("-1009", buffer.str());
+               checkEqu("-1009", buffer);
                checkEqu(5u, buffer.length());
 
                buffer.setLength(0).appendInt((unsigned int) 123);
-               checkEqu("123", buffer.str());
+               checkEqu("123", buffer);
                buffer.appendInt((unsigned int) 0x87654321, "%x");
-               checkEqu("12387654321", buffer.str());
+               checkEqu("12387654321", buffer);
 
        }
        void testOpAssignCopyConstructor() {
@@ -398,12 +434,12 @@ private:
                ReByteBuffer buf3;
                {
                        ReByteBuffer buf2(buf1);
-                       checkEqu("abc", buf2.str());
+                       checkEqu("abc", buf2);
                        buf3 = buf2;
                        buf2.append("123", 3);
                }
-               checkEqu("abc", buf3.str());
-               checkEqu("abc", buf1.str());
+               checkEqu("abc", buf3);
+               checkEqu("abc", buf1);
        }
        void testAt(){
                ReByteBuffer buf1;
@@ -477,11 +513,11 @@ private:
                checkEqu(10u, buf1.length());
 
                buf1.setLength(5);
-               checkEqu("01234", buf1.str());
+               checkEqu("01234", buf1);
                checkEqu(5u, buf1.length());
 
                buf1.setLengthAndFillOut(8, 'X');
-               checkEqu("01234XXX", buf1.str());
+               checkEqu("01234XXX", buf1);
                checkEqu(8u, buf1.length());
                checkEqu(2000u, buf1.capacity());
        }
@@ -526,19 +562,19 @@ private:
        void testInsert(){
                ReByteBuffer buf1;
                checkT(buf1.insert(0, "123", 2));
-               checkEqu("12", buf1.str());
+               checkEqu("12", buf1);
                checkEqu(2u, buf1.length());
 
                checkT(buf1.insert(0, "abc", 1));
-               checkEqu("a12", buf1.str());
+               checkEqu("a12", buf1);
                checkEqu(3u, buf1.length());
 
                checkT(buf1.insert(1, "x", 1));
-               checkEqu("ax12", buf1.str());
+               checkEqu("ax12", buf1);
                checkEqu(4u, buf1.length());
 
                checkT(buf1.insert(4, "yz", 2));
-               checkEqu("ax12yz", buf1.str());
+               checkEqu("ax12yz", buf1);
                checkEqu(6u, buf1.length());
 
                checkF(buf1.insert(-1, "-", 1));
@@ -549,27 +585,27 @@ private:
                ReByteBuffer buf1;
                buf1.set("1234567890", 10);
                checkT(buf1.remove(0, 2));
-               checkEqu("34567890", buf1.str());
+               checkEqu("34567890", buf1);
                checkEqu(8u, buf1.length());
 
                checkF(buf1.remove(-1, 2));
-               checkEqu("34567890", buf1.str());
+               checkEqu("34567890", buf1);
                checkEqu(8u, buf1.length());
 
                checkF(buf1.remove(9, 2));
-               checkEqu("34567890", buf1.str());
+               checkEqu("34567890", buf1);
                checkEqu(8u, buf1.length());
 
                checkT(buf1.remove(7, 2));
-               checkEqu("3456789", buf1.str());
+               checkEqu("3456789", buf1);
                checkEqu(7u, buf1.length());
 
                checkT(buf1.remove(5, 2));
-               checkEqu("34567", buf1.str());
+               checkEqu("34567", buf1);
                checkEqu(5u, buf1.length());
 
                checkT(buf1.remove(0, 99));
-               checkEqu("", buf1.str());
+               checkEqu("", buf1);
                checkEqu(0u, buf1.length());
        }
        void testReplace(){
@@ -577,14 +613,14 @@ private:
 
                buffer.set("1234", 4);
                buffer.replaceAll("12", 2, "abc", 3);
-               checkEqu("abc34", buffer.str());
+               checkEqu("abc34", buffer);
 
                buffer.replaceAll("c34", 2, "uv", 3);
-               checkEqu("abuv", buffer.str());
+               checkEqu("abuv", buffer);
 
                buffer.set("$$x$$", -1);
                buffer.replaceAll("$", 1, "XX", 2);
-               checkEqu("XXXXxXXXX", buffer.str());
+               checkEqu("XXXXxXXXX", buffer);
        }
        void testSplice(){
                ReByteBuffer buffer;
index 6c5da856d8a22da9cb2741cfb67bfed7f6252b7b..ba878d3e4a9a50582f58997faef5bedef2d152dd 100644 (file)
@@ -22,12 +22,14 @@ public:
         m_base.append("dirtool");\r
         _mkdir(m_base.str(), ALLPERMS);\r
                m_base.append(OS_SEPARATOR, -1);\r
+               m_testAll = true;\r
                run();\r
                ReDirectory::deleteTree(m_base.str(), true);\r
        }\r
 private:\r
     ReByteBuffer m_base;\r
        ReByteBuffer m_buffer;\r
+       bool m_testAll;\r
 private:\r
     const char* makeDir(const char* relPath){\r
         m_buffer = m_base;\r
@@ -65,18 +67,25 @@ private:
     }\r
        void run(){\r
                initTree();\r
-\r
-        testBatch();\r
-\r
-               testToolStatistic();\r
-               testBasic();\r
-               testDirOptions();\r
-               checkSetFilterFromProgramArgs();\r
-               testDirStatistic();\r
-        testCopyFile();\r
-        testList();\r
+               testList2();\r
                testToolSync();\r
-               testBatch();\r
+               if (m_testAll){\r
+                       testToolStatistic();\r
+                       testBasic();\r
+                       testDirOptions();\r
+                       checkSetFilterFromProgramArgs();\r
+                       testDirStatistic();\r
+                       testCopyFile();\r
+                       testList();\r
+                       testToolSync();\r
+                       testBatch();\r
+               }\r
+       }\r
+       // F:\temp\retestunit\dirtool\r
+       void testList2(){\r
+               const char* argv[] = { "dt", "list", m_base.str(), NULL };\r
+               ReDirTools tools;\r
+               tools.main(3, (char**) argv);\r
        }\r
     void testList(){\r
         const char* argv[] = { "list", m_base.str(), NULL };\r
@@ -263,10 +272,10 @@ private:
                        cols.split(expected.strOf(ix), '*');\r
                        const char* col1 = cols.strOf(0);\r
                        if (! line.startsWith(col1))\r
-                               checkEqu(col1, line.str());\r
+                               checkEqu(col1, line);\r
                        const char* col2 = cols.strOf(1);\r
                        if (! line.endsWith(col2)){\r
-                               checkEqu(col2, line.str());\r
+                               checkEqu(col2, line);\r
                        }\r
                }\r
     }\r
index f6820ba217a5bcfe595e8cc9a726cba04f5f57c2..4dbca6760c1155dda5ddf38ae6ae47e37c4b38b3 100644 (file)
@@ -65,28 +65,28 @@ private:
 
                hash.put("abc", "123");
                checkT(hash.get("abc", -1, value));
-               checkEqu("123", value.str());
+               checkEqu("123", value);
 
                hash.put("ab", "999");
                checkT(hash.get("ab", -1, value));
-               checkEqu("999", value.str());
+               checkEqu("999", value);
 
                checkT(hash.get("abc", -1, value));
-               checkEqu("123", value.str());
+               checkEqu("123", value);
 
                hash.put("abc", "!!!");
                checkT(hash.get("abc", -1, value));
-               checkEqu("!!!", value.str());
+               checkEqu("!!!", value);
 
                checkT(hash.get("ab", -1, value));
-               checkEqu("999", value.str());
+               checkEqu("999", value);
 
                hash.put("abc", "longer");
                checkT(hash.get("abc", -1, value));
-               checkEqu("longer", value.str());
+               checkEqu("longer", value);
 
                checkT(hash.get("ab", -1, value));
-               checkEqu("999", value.str());
+               checkEqu("999", value);
        }
        void testNext(){
                ReHashList hash;
index f17df7ceda666d1af3adf5d563e5e897b43db7b2..aa484e496d7d401ef922b7c9567975144c41cb28 100644 (file)
@@ -43,16 +43,16 @@ private:
                const char* text = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVEXYZ01234567890\n";
                md5.update((const uint8_t*)text, strlen(text));
                checkEqu("c0a278c051a6898f6ad05da7fa80a1c4",
-                       md5.hexDigest().str());
+                       md5.hexDigest());
                md5.reset();
                text = "The quick brown fox jumps over the lazy dog";
                md5.update((const uint8_t*) text, -1);
                checkEqu("9e107d9d372bb6826bd81d3542a419d6",
-                       md5.hexDigest().str());
+                       md5.hexDigest());
                md5.reset();
                md5.update((const uint8_t*)"", 0);
                checkEqu("d41d8cd98f00b204e9800998ecf8427e",
-                       md5.hexDigest().str());
+                       md5.hexDigest());
        }
        int testOneLong(ReByteBuffer& text, int seed2 = 0){
                ReMD5 md5;
@@ -74,7 +74,7 @@ private:
                        text.remove(0, part);
                        rc++;
                }
-               checkEqu(digest.str(), md5.hexDigest().str());
+               checkEqu(digest, md5.hexDigest());
                return rc;
        }
        void testLong(){
index 8d5fe540672f71326e7b45f4c5f02365b92839a9..942aa7567c071774df44798b7b2ea764d5d1d36b 100644 (file)
@@ -151,7 +151,7 @@ private:
                        list.add(-1, expectedValue.str(), -1, expectedTag);
                        checkEqu(ix + 1, list.count());
                        checkT(list.get(ix, value, &tag));
-                       checkEqu(expectedValue.str(), value.str());
+                       checkEqu(expectedValue, value);
                        if (expectedTag != tag)
                                checkEqu(expectedTag, tag);
                }
@@ -160,7 +160,7 @@ private:
                        expectedTag = (1ll << ix);
                        expectedValue.appendChar('x');
                        checkT(list.get(ix, value, &tag));
-                       checkEqu(expectedValue.str(), value.str());
+                       checkEqu(expectedValue, value);
                        checkEqu(expectedTag, tag);
                }
 
@@ -177,7 +177,7 @@ private:
                        list.add(-1, expectedValue.str(), -1, expectedTag);
                        checkEqu(ix + 1, list.count());
                        checkT(list.get(ix, value, &tag));
-                       checkEqu(expectedValue.str(), value.str());
+                       checkEqu(expectedValue, value);
                        if (expectedTag != tag)
                                checkEqu(expectedTag, tag);
                }
@@ -200,43 +200,43 @@ private:
                list.add(-1, "xxx", -1, ReSeqArray::Tag(1l) << 31);
                checkT(list.get(0, value, &tag));
                checkEqu(1ll << 31, tag);
-               checkEqu("xxx", value.str());
+               checkEqu("xxx", value);
 
                list.clear();
                list.add(-1, "123", -1, 0x3344556633445566ll);
                checkEqu(1u, list.count());
                checkT(list.get(0, value, &tag));
-               checkEqu("123", value.str());
+               checkEqu("123", value);
                checkEqu((int64_t) 0x3344556633445566ll, tag);
 
                list.add(-1, "ab", -1, 0x345678abcdef3344ll);
                checkEqu(2u, list.count());
                checkT(list.get(0, value));
-               checkEqu("123", value.str());
+               checkEqu("123", value);
                checkT(list.get(1, value, &tag));
-               checkEqu("ab", value.str());
+               checkEqu("ab", value);
                checkEqu(0x345678abcdef3344ll, tag);
 
                list.add(0, "xyz", -1, 300);
                checkEqu(3u, list.count());
                checkT(list.get(0, value, &tag));
-               checkEqu("xyz", value.str());
+               checkEqu("xyz", value);
                checkT(list.get(1, value));
-               checkEqu("123", value.str());
+               checkEqu("123", value);
                checkT(list.get(2, value));
-               checkEqu("ab", value.str());
+               checkEqu("ab", value);
                checkEqu(300ll, tag);
 
                list.add(1, "vw", -1, 400);
                checkEqu(4u, list.count());
                checkT(list.get(0, value));
-               checkEqu("xyz", value.str());
+               checkEqu("xyz", value);
                checkT(list.get(1, value, &tag));
-               checkEqu("vw", value.str());
+               checkEqu("vw", value);
                checkT(list.get(2, value));
-               checkEqu("123", value.str());
+               checkEqu("123", value);
                checkT(list.get(3, value));
-               checkEqu("ab", value.str());
+               checkEqu("ab", value);
                checkEqu(400ll, tag);
 
                list.clear();
@@ -256,29 +256,29 @@ private:
                list.remove(3);
                checkEqu(3u, list.count());
                list.get(0, value, &tag);
-               checkEqu("abc", value.str());
+               checkEqu("abc", value);
                checkEqu(100ll, tag);
                list.get(1, value, &tag);
-               checkEqu("def12", value.str());
+               checkEqu("def12", value);
                checkEqu(200ll, tag);
                list.get(2, value, &tag);
-               checkEqu("ghi", value.str());
+               checkEqu("ghi", value);
                checkEqu(300ll, tag);
 
 
                list.remove(1);
                checkEqu(2u, list.count());
                list.get(0, value, &tag);
-               checkEqu("abc", value.str());
+               checkEqu("abc", value);
                checkEqu(100ll, tag);
                list.get(1, value, &tag);
-               checkEqu("ghi", value.str());
+               checkEqu("ghi", value);
                checkEqu(300ll, tag);
 
                list.remove(0);
                checkEqu(1u, list.count());
                list.get(0, value, &tag);
-               checkEqu("ghi", value.str());
+               checkEqu("ghi", value);
                checkEqu(300ll, tag);
 
        }
index 3471f5523676e1735de93190eec4690b5b46523c..09095c4025d2aa39e0f7d497ec370afb7def53cd 100644 (file)
@@ -139,12 +139,12 @@ private:
                checkEqu("99", list.strOf(5));
                ReByteBuffer value("x");
                list.join(";", value);
-               checkEqu(str, value.str());
+               checkEqu(str, value);
 
                list.split("1\n2", '\n');
                value.set("xxx", 3);
                list.join(";", value, true);
-               checkEqu("xxx1;2", value.str());
+               checkEqu("xxx1;2", value);
        }
        void testFile(){
                if (true){
index 6839381dae4872b81816b0cede8bcc2eefa95746..22ab490f0fc249a95fd11d43eaa531b5bfe2570b 100644 (file)
@@ -77,95 +77,95 @@ private:
                const char* fn = "file:/etc/samba/smb.cnf";
 
                ReStringUtils::splitPath(fn, &protocol, &path, &name, &ext);
-               checkEqu("file:", protocol.str());
-               checkEqu("/etc/samba/", path.str());
-               checkEqu("smb", name.str());
-               checkEqu(".cnf", ext.str());
+               checkEqu("file:", protocol);
+               checkEqu("/etc/samba/", path);
+               checkEqu("smb", name);
+               checkEqu(".cnf", ext);
 
                ReStringUtils::joinPath(fullname, &protocol, &path, &name, &ext);
-               checkEqu(fn, fullname.str());
+               checkEqu(fn, fullname);
 
                fn = "/etc/samba/smb.cnf";
 
                ReStringUtils::splitPath(fn, &protocol, &path, &name, &ext);
-               checkEqu("", protocol.str());
-               checkEqu("/etc/samba/", path.str());
-               checkEqu("smb", name.str());
-               checkEqu(".cnf", ext.str());
+               checkEqu("", protocol);
+               checkEqu("/etc/samba/", path);
+               checkEqu("smb", name);
+               checkEqu(".cnf", ext);
 
                ReStringUtils::joinPath(fullname, &protocol, &path, &name, &ext);
-               checkEqu(fn, fullname.str());
+               checkEqu(fn, fullname);
 
                fn = "smb.cnf";
 
                ReStringUtils::splitPath(fn, &protocol, &path, &name, &ext);
-               checkEqu("", protocol.str());
-               checkEqu("", path.str());
-               checkEqu("smb", name.str());
-               checkEqu(".cnf", ext.str());
+               checkEqu("", protocol);
+               checkEqu("", path);
+               checkEqu("smb", name);
+               checkEqu(".cnf", ext);
 
                ReStringUtils::joinPath(fullname, &protocol, &path, &name, &ext);
-               checkEqu(fn, fullname.str());
+               checkEqu(fn, fullname);
 
                fn = "smb";
 
                ReStringUtils::splitPath(fn, &protocol, &path, &name, &ext);
-               checkEqu("", protocol.str());
-               checkEqu("", path.str());
-               checkEqu("smb", name.str());
-               checkEqu("", ext.str());
+               checkEqu("", protocol);
+               checkEqu("", path);
+               checkEqu("smb", name);
+               checkEqu("", ext);
 
                ReStringUtils::joinPath(fullname, &protocol, &path, &name, &ext);
-               checkEqu(fn, fullname.str());
+               checkEqu(fn, fullname);
 
                fn = "file:smb.003.cnf";
 
                ReStringUtils::splitPath(fn, &protocol, &path, &name, &ext);
-               checkEqu("file:", protocol.str());
-               checkEqu("", path.str());
-               checkEqu("smb.003", name.str());
-               checkEqu(".cnf", ext.str());
+               checkEqu("file:", protocol);
+               checkEqu("", path);
+               checkEqu("smb.003", name);
+               checkEqu(".cnf", ext);
 
                ReStringUtils::joinPath(fullname, &protocol, &path, &name, &ext);
-               checkEqu(fn, fullname.str());
+               checkEqu(fn, fullname);
 
                fn = "file:/etc.bak/smb";
 
                ReStringUtils::splitPath(fn, &protocol, &path, &name, &ext);
-               checkEqu("file:", protocol.str());
-               checkEqu("/etc.bak/", path.str());
-               checkEqu("smb", name.str());
-               checkEqu("", ext.str());
+               checkEqu("file:", protocol);
+               checkEqu("/etc.bak/", path);
+               checkEqu("smb", name);
+               checkEqu("", ext);
 
                ReStringUtils::joinPath(fullname, &protocol, &path, &name, &ext);
-               checkEqu(fn, fullname.str());
+               checkEqu(fn, fullname);
 
                fn = "file:/etc/samba/smb.cnf";
 
                ReStringUtils::splitPath(fn, NULL, &path, &name, &ext);
-               checkEqu("file:", protocol.str());
-               checkEqu("smb", name.str());
-               checkEqu(".cnf", ext.str());
+               checkEqu("file:", protocol);
+               checkEqu("smb", name);
+               checkEqu(".cnf", ext);
 
                ReStringUtils::joinPath(fullname, &protocol, NULL, &name, &ext);
-               checkEqu("file:smb.cnf", fullname.str());
+               checkEqu("file:smb.cnf", fullname);
 
                fn = "file:/etc/samba/smb.cnf";
 
                ReStringUtils::splitPath(fn, NULL, NULL, &name, &ext);
-               checkEqu("smb", name.str());
-               checkEqu(".cnf", ext.str());
+               checkEqu("smb", name);
+               checkEqu(".cnf", ext);
 
                ReStringUtils::joinPath(fullname, NULL, NULL, &name, &ext);
-               checkEqu("smb.cnf", fullname.str());
+               checkEqu("smb.cnf", fullname);
 
                fn = "file:/etc/samba/smb.cnf";
 
                ReStringUtils::splitPath(fn, NULL, NULL, &name, NULL);
-               //checkEqu("", protocol.str());
-               //checkEqu("/etc/samba/", path.str());
-               checkEqu("smb", name.str());
-               //checkEqu(".cnf", ext.str());
+               //checkEqu("", protocol);
+               //checkEqu("/etc/samba/", path);
+               checkEqu("smb", name);
+               //checkEqu(".cnf", ext);
 
                ReStringUtils::joinPath(fullname, NULL, NULL, &name, NULL);
                checkEqu("smb", fullname.str());
@@ -173,28 +173,28 @@ private:
                fn = "file:/etc/samba/smb.cnf";
 
                ReStringUtils::splitPath(fn, NULL, &path, NULL, &ext);
-               //checkEqu("", protocol.str());
-               checkEqu("/etc/samba/", path.str());
-               //checkEqu("smb", name.str());
-               checkEqu(".cnf", ext.str());
+               //checkEqu("", protocol);
+               checkEqu("/etc/samba/", path);
+               //checkEqu("smb", name);
+               checkEqu(".cnf", ext);
 
                ReStringUtils::joinPath(fullname, NULL, &path, NULL, &ext);
-               checkEqu("/etc/samba/.cnf", fullname.str());
+               checkEqu("/etc/samba/.cnf", fullname);
 
                ReStringUtils::joinPath(fullname, "http:", "//any.de/", "name", ".ext");
-               checkEqu("http://any.de/name.ext", fullname.str());
+               checkEqu("http://any.de/name.ext", fullname);
 
                ReStringUtils::joinPath(fullname, NULL, "/any.de/", "name", ".ext");
-               checkEqu("/any.de/name.ext", fullname.str());
+               checkEqu("/any.de/name.ext", fullname);
 
                ReStringUtils::joinPath(fullname, NULL, NULL, "name", ".ext");
-               checkEqu("name.ext", fullname.str());
+               checkEqu("name.ext", fullname);
 
                ReStringUtils::joinPath(fullname, NULL, NULL, "name", NULL);
-               checkEqu("name", fullname.str());
+               checkEqu("name", fullname);
 
                ReStringUtils::joinPath(fullname, "file:", "/", NULL, NULL);
-               checkEqu("file:/", fullname.str());
+               checkEqu("file:/", fullname);
        }
 };
 extern void testReStringUtils(void);
index 798e8844f7eac4c4c0a60e9269a9b99d1a107c37..5b54e21c2e26ee05357d952c8d6f7b43ad505488 100644 (file)
@@ -37,9 +37,9 @@ private:
 
                ReByteBuffer buffer;
                config.getString("string", buffer, "x");
-               checkEqu("abc", buffer.str());
+               checkEqu("abc", buffer);
                config.getString("string1", buffer, "x");
-               checkEqu("x", buffer.str());
+               checkEqu("x", buffer);
        }
 };
 extern void testReConfigFile(void);
index 3ef40e853996f425bf0bff108c647e0a5644f5c5..b2c941e629ec4c3b5113fb597725745da32e2124 100644 (file)
@@ -12,6 +12,8 @@
 #include "net/renet.hpp"
 #endif
 
+static bool s_testAll = true;
+
 void testBase(){
        extern void testReSeqArray(void);
        testReSeqArray();
@@ -59,10 +61,12 @@ void testOs(){
        void testReDirTools();
        testReDirTools();
 
-       void testReTraverser();
-       testReTraverser();
-       void testReDirTools();
-       //testReDirTools();
+       if (s_testAll){
+               void testReTraverser();
+               testReTraverser();
+               void testReDirTools();
+               testReDirTools();
+       }
 }
 void testMath(){
        extern void testReMD5();
@@ -73,23 +77,16 @@ void testMath(){
 void testAll(){
        try
        {
-               testOs();
-
                testBase();
-               testString();
-               testMath();
-               testOs();
+               //testOs();
+               if (s_testAll){
+                       testBase();
+                       testString();
+                       testMath();
+                       testOs();
+               }
        } catch (ReException e){
                fprintf(stderr, "testBase.cpp: unexpected exception: %s\n", e.getMessage());
        }
 
 }
-void testCurrent(){
-       try
-       {
-               void testReByteBuffer();
-               testReByteBuffer();
-       } catch (ReException e){
-               fprintf(stderr, "testBase.cpp: unexpected exception: %s\n", e.getMessage());
-       }
-}
index c0a33e8ffa21eb0f10cba6c3606de146666f19c9..edaca86d10836f9c1f94c61b7ac0964916fdc71d 100644 (file)
@@ -643,7 +643,8 @@ ReTool::ReTool(const char* usage[], const char* example[],
        m_addCurrentDirIfNoArguments(addCurrentDirIfNoArguments),\r
        m_traverser(NULL, this),\r
        m_filter(),\r
-       m_start(time(NULL))\r
+       m_start(time(NULL)),\r
+       m_logger(ReLogger::globalLogger())\r
 {\r
 }\r
 \r
index 4bbac2eb8e5c01df5f8c65953a389cf392acff75..913f1a3b9b192b944928b4ee2d952e6305bb5979 100644 (file)
@@ -124,6 +124,8 @@ protected:
        ReDirEntryFilter_t m_filter;
        int64_t m_start;
        struct stat m_statInfo;
+       ReLogger* m_logger;
+
 };
 
 class ReDirBatch : public ReTool {
index 6c96df616b0a585c323935b05483e279097ff9df..1e68133741cb4b75fe56159ec77693760229365c 100644 (file)
@@ -9,7 +9,11 @@
 \r
 #include "base/rebase.hpp"\r
 #include "os/reos.hpp"\r
-\r
+#if defined __WIN32__\r
+#include "accctrl.h"\r
+#include "aclapi.h"\r
+#pragma comment(lib, "advapi32.lib")\r
+#endif\r
 /**\r
  * Constructor.\r
 */\r
@@ -339,6 +343,71 @@ const char* ReDirStatus_t::rightsAsString(ReByteBuffer& buffer, bool numerical)
                buffer.appendChar(' ');\r
        }\r
 #elif defined __WIN32__\r
+       const char* name = fullName();\r
+       DWORD access = isDirectory() ? 0 : GENERIC_READ;\r
+       DWORD shareFlag = isDirectory() ? 0 : FILE_SHARE_READ;\r
+       DWORD flag = isDirectory() ? FILE_FLAG_BACKUP_SEMANTICS : FILE_ATTRIBUTE_NORMAL;\r
+       HANDLE handle;\r
+       if (! isDirectory()){\r
+               handle = CreateFile(name, GENERIC_READ, FILE_SHARE_READ,\r
+                  NULL, OPEN_EXISTING, flag, NULL);\r
+       } else {\r
+               LUID luidPrivilege;\r
+        DWORD dwErrorCode;\r
+               HANDLE hAccessToken;\r
+        if (! OpenProcessToken (GetCurrentProcess(), \r
+                               TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hAccessToken)){\r
+                       printf("OpenProcessToken(): %d\n", GetLastError());\r
+               }\r
+\r
+        if (! LookupPrivilegeValue (NULL, SE_BACKUP_NAME, &luidPrivilege)) {\r
+                       printf("LookupPrivilegeValue(): %d\n", GetLastError());\r
+               } else {\r
+            TOKEN_PRIVILEGES tpPrivileges;\r
+            tpPrivileges.PrivilegeCount = 1;\r
+            tpPrivileges.Privileges[0].Luid = luidPrivilege;\r
+            tpPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;\r
+            if (AdjustTokenPrivileges (hAccessToken, FALSE, &tpPrivileges, \r
+                                       0, NULL, NULL) != 0){\r
+                               printf("AdjustTokenPrivileges(): %d\n", GetLastError());\r
+                       }\r
+        }\r
+               handle = CreateFile(name, 0, 0, NULL, OPEN_EXISTING, flag, NULL);\r
+       }\r
+       if (handle == INVALID_HANDLE_VALUE){\r
+               int error = GetLastError();\r
+               printf("CreateFile(%s): %d\n", name, error);\r
+       } else {\r
+               PSID pSidOwner = NULL;\r
+               PSECURITY_DESCRIPTOR pSD = NULL;\r
+               DWORD dwRtnCode = GetSecurityInfo(handle, SE_FILE_OBJECT,\r
+                       OWNER_SECURITY_INFORMATION, &pSidOwner, NULL, NULL, NULL, &pSD);\r
+               if (dwRtnCode != ERROR_SUCCESS) {\r
+                       int error = GetLastError();\r
+                       printf("GetSecurityInfo(%s): %d\n", name, error);\r
+               } else {\r
+                       if (numerical){\r
+                               buffer.appendInt((int) pSidOwner, " %08x");\r
+                       } else {\r
+                               char accountName[128];\r
+                               char domainName[128];\r
+                               DWORD dwAcctName = sizeof accountName;\r
+                               DWORD dwDomainName = sizeof domainName;\r
+                               SID_NAME_USE eUse = SidTypeUnknown;\r
+                               BOOL bRtnBool = LookupAccountSid(NULL, // local computer\r
+                                       pSidOwner, accountName, &dwAcctName, domainName,\r
+                                       &dwDomainName, &eUse);\r
+                               if (! bRtnBool){\r
+                                       int error = GetLastError();\r
+                                       printf("LookupAccountSid(%s): %d\n", name, error);\r
+                               } else {\r
+                                       if (domainName[0] != '\0')\r
+                                               buffer.append(domainName, -1).appendChar('/');\r
+                               }\r
+                               buffer.append(accountName, -1);\r
+                       }\r
+               }\r
+       }\r
 #endif\r
     return buffer.str();\r
 }\r