From: hama Date: Sun, 8 Feb 2015 09:33:01 +0000 (+0100) Subject: testcode MD5 X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=5a70e6ff9bdf8f91f740fe52ea32e47571d539f0;p=crepublib testcode MD5 --- diff --git a/cunit/cuReDirTools.cpp b/cunit/cuReDirTools.cpp index 032ddd8..0ee0a79 100644 --- a/cunit/cuReDirTools.cpp +++ b/cunit/cuReDirTools.cpp @@ -61,7 +61,8 @@ private: void run(){ initTree(); - testToolSync(); + testDirStatistic(); + testToolStatistic(); testBasic(); testDirOptions(); @@ -69,6 +70,7 @@ private: testDirStatistic(); testCopyFile(); testList(); + testToolSync(); } void testList(){ ReDirTools tools; @@ -171,7 +173,7 @@ private: ReTraverser traverser(m_base.str()); RePatternList patterns; // exclude */cache/* - ReByteBuffer buffer(";*;-*/cache"); + ReByteBuffer buffer(";*;-cache"); patterns.set(buffer.str()); traverser.setDirPattern(&patterns); int level = 0; @@ -197,7 +199,7 @@ private: ReByteBuffer buffer; ReByteBuffer expected; log(false, list.join("\n", buffer).str()); - checkEqu(4u, list.count()); + checkEqu(3u, list.count()); // "1 t:\temp\winfried\2\retestunit\dir1\n" buffer.set(list.strOf(0), list.strLengthOf(0)); checkT(buffer.startsWith("1\t")); @@ -228,7 +230,7 @@ private: } void testToolStatistic(){ ReDirTools tools; - const char* argv[] = { "dt", "stat", "-P;*;-*/cache/*", m_base.str(), "2" }; + const char* argv[] = { "dt", "stat", "-P;*;-cache", m_base.str(), "2" }; tools.main(5, (char**) argv); } void testToolSync(){ @@ -236,7 +238,7 @@ private: ReByteBuffer source(m_base); source.append("dir1"); ReByteBuffer target(makeDir("synctest")); - const char* argv[] = { "dt", "sync", "-P;*;-*/cache/*", "-p;*.txt", + const char* argv[] = { "dt", "sync", "-P;*;-cache", "-p;*.txt", source.str(), target.str() }; tools.main(6, (char**) argv); } diff --git a/cunit/cuReMD5.cpp b/cunit/cuReMD5.cpp index 3bac001..bb0c990 100644 --- a/cunit/cuReMD5.cpp +++ b/cunit/cuReMD5.cpp @@ -18,7 +18,7 @@ #include "base/rebase.hpp" #include "math/remath.hpp" -//#include "math/md5.hpp" +#include "math/md5.hpp" class TestReMd5 : public ReTestUnit { public: @@ -31,7 +31,7 @@ private: testBase(); } void testOld(){ -#if 0 +#if 1 MD5 md5; md5.update("", 0); md5.finalize(); diff --git a/cunit/testall.cpp b/cunit/testall.cpp index f9ca28a..cabbccf 100644 --- a/cunit/testall.cpp +++ b/cunit/testall.cpp @@ -73,7 +73,7 @@ void testMath(){ void testAll(){ try { - testOs(); + testMath(); testBase(); testString(); diff --git a/math/ReMD5.cpp b/math/ReMD5.cpp index 403522e..6dbf609 100644 --- a/math/ReMD5.cpp +++ b/math/ReMD5.cpp @@ -180,8 +180,12 @@ void ReMD5::processChunk(const uint8_t block[64]){ uint32_t C = m_c0; uint32_t D = m_d0; //Main loop: + int F, g; for (int i = 0; i < 64; i++){ +#if defined TRACE_MD5 + printf("%2d: A: %08x B: %08x C: %08x D%08x\n", i, A, B, C, D); +#endif if (i < 16){ // F := (B and C) or ((not B) and D) F = (B & C) | (~ B & D); @@ -202,6 +206,10 @@ void ReMD5::processChunk(const uint8_t block[64]){ // g := (7×i) mod 16 g = (7*i) % 16; } +#if defined TRACE_MD5 + printf(" K[%2d]: %08x M[%2d]: %08x shift: %02d\n", + i, m_K[i], g, M[g], m_s[i]); +#endif uint32_t dTemp = D; D = C; C = B; diff --git a/math/md5.cpp b/math/md5.cpp index f90e5b3..9ca7a97 100644 --- a/math/md5.cpp +++ b/math/md5.cpp @@ -79,11 +79,16 @@ inline MD5::uint4 MD5::I(uint4 x, uint4 y, uint4 z) { inline MD5::uint4 MD5::rotate_left(uint4 x, int n) { return (x << n) | (x >> (32-n)); } - +static int s_ix = 0; // FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. // Rotation is separate from addition to prevent recomputation. inline void MD5::FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { - a = rotate_left(a+ F(b,c,d) + x + ac, s) + b; +#if defined TRACE_MD5 + printf("%2d: A: %08x B: %08x C: %08x D%08x\n", s_ix++ % 16, a, b, c, d); + printf(" K[%2d]: %08x M[?]: %08x shift: %02d ac: %08x\n", + s_ix - 1, 0xd76aa478, x, s, ac); +#endif + a = rotate_left(a+ F(b,c,d) + x + ac, s) + b; } inline void MD5::GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 193b94c..d865cf9 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -361,7 +361,7 @@ const char* ReDirOptions::checkPatternList(const char* value){ value); if (strchr(value, OS_SEPARATOR_CHAR) != NULL) throw ReOptionException(&m_programArgs, - i18n("slash not allowed in pattern list: $2"), value); + i18n("slash not allowed in pattern list: $1"), value); return value; } /** @@ -531,9 +531,6 @@ void ReDirOptions::optimizePathPattern(ReByteBuffer& buffer){ * @param filter OUT: the filter to set */ void ReDirOptions::setFilterFromProgramArgs(ReDirEntryFilter_t& filter){ -{ ReByteBuffer buf; -const char* ptr = m_programArgs.getString("pathpattern", buf); -} ReByteBuffer buffer; if (m_programArgs.getString("younger", buffer)[0] != '\0') filter.m_maxAge = checkDate(buffer.str()); diff --git a/os/ReTraverser.cpp b/os/ReTraverser.cpp index c934cb0..2194d27 100644 --- a/os/ReTraverser.cpp +++ b/os/ReTraverser.cpp @@ -328,8 +328,8 @@ void ReDirStatus_t::timeToFiletime(time_t time, FileTime_t& filetime){ */ ReDirEntryFilter_t::ReDirEntryFilter_t() : m_types(ReDirStatus_t::TC_ALL), - m_nodePatterns(), - m_pathPatterns(), + m_nodePatterns(NULL), + m_pathPatterns(NULL), m_minSize(0), m_maxSize(-1), m_minAge(0), diff --git a/os/ReTraverser.hpp b/os/ReTraverser.hpp index 1013d29..9f6ff78 100644 --- a/os/ReTraverser.hpp +++ b/os/ReTraverser.hpp @@ -156,7 +156,10 @@ public: * @param pattern pattern list for the subdirs to be entered */ void setDirPattern(RePatternList* pattern) - { m_dirPatterns = pattern; m_dirPatterns->setIgnoreCase(true); } + { m_dirPatterns = pattern; + if (pattern != NULL) + m_dirPatterns->setIgnoreCase(true); + } /** Sets the maximal depth. * @param value the value to set */