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.
*
* @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,
}
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,
m_regExprIsInitialized(false),
m_isRegExpr(false)
#elif defined __WIN32__
- m_handle(0)
+ m_handle(INVALID_HANDLE_VALUE)
//m_data()
#endif
{
/** @brief Destructor.
*/
ReDirectory::~ReDirectory(){
+ close();
+}
+/** @brief Frees the resources.
+*/
+void ReDirectory::close(){
#if defined __linux__
if (m_dir != NULL){
closedir(m_dir);
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>
* 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;
}
} while(dir.findNext());
}
+ dir.close();
if (deleteBaseToo){
_rmdir(base);
}
}
+}
/** @brief Returns the name of the directory.
*
ReDirectory(const char* path);
~ReDirectory();
public:
+ void close();
const char* currentFile();
bool findFirst(const char* pattern, bool isRegExpr);
bool findNext();
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
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);
}
private:
void run(){
+ testAppendFix();
testEnsureLastChar();
testLastChar();
testReduceLength();
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('/');
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());
}
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(){
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");
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());
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() {
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;
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());
}
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));
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(){
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;
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
}\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
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
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;
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;
text.remove(0, part);
rc++;
}
- checkEqu(digest.str(), md5.hexDigest().str());
+ checkEqu(digest, md5.hexDigest());
return rc;
}
void testLong(){
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);
}
expectedTag = (1ll << ix);
expectedValue.appendChar('x');
checkT(list.get(ix, value, &tag));
- checkEqu(expectedValue.str(), value.str());
+ checkEqu(expectedValue, value);
checkEqu(expectedTag, tag);
}
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);
}
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();
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);
}
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){
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());
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);
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);
#include "net/renet.hpp"
#endif
+static bool s_testAll = true;
+
void testBase(){
extern void testReSeqArray(void);
testReSeqArray();
void testReDirTools();
testReDirTools();
- void testReTraverser();
- testReTraverser();
- void testReDirTools();
- //testReDirTools();
+ if (s_testAll){
+ void testReTraverser();
+ testReTraverser();
+ void testReDirTools();
+ testReDirTools();
+ }
}
void testMath(){
extern void testReMD5();
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());
- }
-}
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
ReDirEntryFilter_t m_filter;
int64_t m_start;
struct stat m_statInfo;
+ ReLogger* m_logger;
+
};
class ReDirBatch : public ReTool {
\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
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