]> gitweb.hamatoma.de Git - reqt/commitdiff
ReFile, cuReFile
authorhama <hama@siduction.net>
Sun, 17 May 2015 22:43:30 +0000 (00:43 +0200)
committerhama <hama@siduction.net>
Sun, 17 May 2015 22:43:30 +0000 (00:43 +0200)
13 files changed:
appl/refind/dialogoptions.cpp
appl/refind/dialogoptions.hpp
appl/refind/mainwindow.cpp
base/ReFile.cpp [new file with mode: 0644]
base/ReFile.hpp [new file with mode: 0644]
base/rebase.hpp
cunit/allTests.cpp
cunit/cuReByteStorage.cpp
cunit/cuReFile.cpp [new file with mode: 0644]
cunit/cuReQStringUtil.cpp
cunit/cunit.pro [new file with mode: 0644]
cunit/main.cpp [new file with mode: 0644]
cunit/unittests.pro

index 82eebbd6d1d8f210b93ca5b93327f04cbc15ccf6..75bfb199dae1d5abe728b3af16c17e03e895b7bf 100644 (file)
@@ -32,7 +32,7 @@ DialogOptions::DialogOptions(ContextHandlerList& handlers, QWidget *parent) :
       SLOT(selectProgram()));
    connect(ui->pushButtonUp, SIGNAL(clicked()), this, SLOT(up()));
    connect(ui->tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(cellEntered(int,int)));
-   connect(ui->tableWidget, SIGNAL(cellActivated(int,int)), this, SLOT(cellEntered(int,int)));
+   connect(ui->tableWidget, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
    for (int ix = 0; ix < ui->comboBoxFileType->count(); ix++)
       m_fileTypes.append(ui->comboBoxFileType->itemText(ix));
    for (int ix = 0; ix < ui->comboBoxDirMode->count(); ix++)
@@ -228,7 +228,18 @@ void DialogOptions::selectProgram(){
    QString file = QFileDialog::getOpenFileName(NULL, tr("Select Program File"),
       ui->comboBoxProgram->currentText());
    if (!file.isEmpty())
-      ui->comboBoxProgram->setCurrentText(file);
+       ui->comboBoxProgram->setCurrentText(file);
+}
+
+void DialogOptions::selectionChanged()
+{
+    QList<QTableWidgetSelectionRange> selections = ui->tableWidget->selectedRanges();
+    QList<QTableWidgetSelectionRange>::const_iterator it = selections.begin();
+    if (it != selections.end()){
+        int row = (*it).topRow();
+        if (row != m_selectedRow)
+            selectRow(row);
+    }
 }
 /**
  * Handles the event "pushed button up".
index 4e978b8fa01ad405f6fbcbc68a8b4b1d660ed838..da9d9ec79e8e2caa406cbf96fb4b1e06e2ea008c 100644 (file)
@@ -20,13 +20,15 @@ class DialogOptions: public QDialog {
 
 public:
    explicit DialogOptions(ContextHandlerList& handlers, QWidget *parent = 0);
-   ~DialogOptions();private slots:
+   ~DialogOptions();
+private slots:
    void accepted();
    void add();
    void cellEntered(int row, int column);
    void del();
    void down();
    void selectProgram();
+   void selectionChanged();
    void up();
 private:
    void currentToTable(int row);
index 78d5a772fa000bbe15ea13a18b32fb5222b6822e..f2011d9b0179fe53a81d01b34a7d225009e8043e 100644 (file)
@@ -50,7 +50,7 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir,
             m_contextHandlers(){
    ui->setupUi(this);
    initializeHome();
-   m_statusMessage = new QLabel(tr("Willkommen bei refind"));
+   m_statusMessage = new QLabel(tr("Welcome at reviewer"));
    if (!startDir.isEmpty())
       ui->comboBoxDirectory->setCurrentText(startDir);
    if (ui->comboBoxDirectory->currentText().isEmpty())
diff --git a/base/ReFile.cpp b/base/ReFile.cpp
new file mode 100644 (file)
index 0000000..ee56731
--- /dev/null
@@ -0,0 +1,376 @@
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+ */
+
+#include "base/rebase.hpp"
+#include "ReFile.hpp"
+
+/**
+ * Constructor.
+ *
+ * @param filename  name of the file
+ */
+ReFile::ReFile(const QString& filename) :
+         m_filename(filename), m_file(filename), m_block(NULL),
+         // in 32-bit address space we allocate only 10 MByte, in 64-bit environments 100 GByte
+            m_blocksize(
+               sizeof(void*) <= 4 ?
+                  10 * 1024 * 1024ll : 0x100ll * 0x10000 * 0x10000),
+            m_blockOffset(0),
+            m_filesize(0),
+            m_startOfLine(NULL),
+            m_lineLength(0),
+            m_lineOffset(0),
+            m_lineNo(0),
+            m_maxLineLength(0x10000){
+   m_file.open(QIODevice::ReadOnly);
+   m_filesize = m_file.size();
+}
+
+/**
+ * Destructor.
+ */
+ReFile::~ReFile(){
+   m_file.close();
+}
+
+/**
+ * Returns the blocksize.
+ *
+ * @return the blocksize
+ */
+int64_t ReFile::blocksize() const{
+   return m_blocksize;
+}
+#ifdef __linux__
+void* memichr(void* heap, int cc, size_t length){
+   const char* heap2 = reinterpret_cast<const char*>(heap);
+   int cc2 = tolower(cc);
+   void* rc = NULL;
+   while(length > 0){
+      if (cc2 == tolower(*heap2++)){
+         rc = heap - 1;
+         break;
+      }
+   }
+   return rc;
+}
+
+int memicmp(const void* str1, const void* str2, size_t length){
+   const char* str12 = reinterpret_cast<const char*>(str1);
+   const char* str22 = reinterpret_cast<const char*>(str2);
+   int rc = 0;
+   for (int ix = 0; ix < length; ix++){
+      int diff = tolower(*str12++) - tolower(*str22++);
+      if (diff != 0){
+         rc = diff;
+         break;
+      }
+   }
+   return rc;
+}
+#endif /* __linux__ */
+
+/**
+ * Finds the next line with the string.
+ *
+ * @param toFind            the string to find    "" or the pattern matching the result
+ * @param ignoreCase        true: the search is case insensitive
+ * @param lineNo            OUT: 0 or the line number
+ * @param line              OUT: "" or the found line
+ * @return                  true: a line has been found<br>
+ *                          false: a line has not been found
+ */
+bool ReFile::findLine(const char* toFind, bool ignoreCase, int& lineNo,
+   QString* line){
+   bool rc = false;
+   int length;
+   int sourceLength = strlen(toFind);
+   char* start;
+
+   char first = toFind[0];
+   while (!rc && (start = nextLine(length)) != NULL){
+      const char* ptr = start;
+      int restLength = length - sourceLength + 1;
+      while (restLength > 0
+         && (ptr =
+                  ignoreCase ?
+                     memchr(start, first, restLength) :
+                     memichr(start, cc, restLength)) != NULL){
+         if ((ignoreCase ?
+            memicmp(ptr, toFind, sourceLength) :
+            memcmp(ptr, toFind, sourceLength)) == 0){
+            rc = true;
+            lineNo = m_lineNo;
+            line = QString::fromUtf8(QByteBuffer(m_startOfLine, m_lineLength));
+            break;
+         }
+         restLength = length - (ptr - start) - sourceLength + 1;
+      }
+   }
+   return rc;
+}
+
+/**
+ * Finds the next line with the given conditions.
+ *
+ * @param includePattern    "" or the pattern matching the result
+ * @param includeIsRegExpr  true: the pattern is a regular expression<br>
+ *                          false: the pattern is a string without meta chars
+ * @param excludePattern    "" or the pattern wich must not match the result
+ * @param excludeIsRegExpr  true: the exclude pattern is a regular expression<br>
+ *                          false: the pattern is a string without meta chars
+
+ * @param lineNo            OUT: 0 or the line number
+ * @param line              OUT: "" or the found line
+ * @return                  true: a line has been found<br>
+ *                          false: a line has not been found
+ */
+bool ReFile::findLine(const QString& includePattern, bool includeIsRegExpr,
+   const QString& excludePattern, bool excludeIsRegExpr, int& lineNo,
+   QString* line){
+   line = "";
+   lineNo = 0;
+   if (!includePattern.isEmpty()){
+
+   }
+}
+/**
+ * @brief Gets the line behind the current line.
+ *
+ * @param length    OUT: the line length
+ * @return          NULL: end of file reached<br>
+ *                  otherwise: the pointer to the next line
+ */
+char* ReFile::nextLine(int& length){
+   char* rc = NULL;
+   length = 0;
+   if (m_lineOffset + m_lineLength < m_filesize){
+      int lineLength;
+      if (m_lineNo == 65639)
+         m_lineNo += 0;
+      rc = m_startOfLine = remap(m_lineOffset += m_lineLength, m_maxLineLength,
+         lineLength);
+      const char* ptr = reinterpret_cast <const char*>(memchr(rc, '\n',
+         lineLength));
+      if (ptr != NULL)
+         lineLength = ptr - rc + 1;
+      length = m_lineLength = lineLength;
+      m_lineNo++;
+   }
+   return rc;
+}
+
+/**
+ * @brief Gets the line in top of the current line.
+ *
+ *
+ * @param length    OUT: the line length
+ * @return          NULL: begin of file reached<br>
+ *                  otherwise: the pointer to the previous line
+ */
+char* ReFile::previousLine(int& length){
+   char* rc = NULL;
+   length = 0;
+   if (m_lineOffset > 0){
+      int lineLength;
+      rc = remap(m_lineOffset - m_lineLength, m_maxLineLength, lineLength);
+      m_startOfLine = rc + lineLength - 1;
+      m_lineLength = 0;
+      while (m_startOfLine > rc && m_startOfLine[-1] != '\n'){
+         m_lineLength++;
+         m_startOfLine--;
+      }
+      rc = m_startOfLine;
+      length = m_lineLength;
+   }
+   return rc;
+}
+
+/**
+ * Reads a string from a given file.
+ *
+ * @param filename      name of the file to read
+ * @param buffer        OUT: the buffer to write
+ * @return              <code>buffer</code> (for chaining)
+ */
+QByteArray& ReFile::readFromFile(const char* filename, QByteArray& buffer){
+   FILE* fp = fopen(filename, "r");
+   if (fp != NULL){
+      struct stat info;
+      stat(filename, &info);
+      buffer.resize(info.st_size);
+      size_t newLength = fread(buffer.data(), 1, info.st_size, fp);
+      if (newLength != (size_t) info.st_size)
+         buffer.truncate(newLength == (size_t) - 1 ? 0 : newLength);
+      fclose(fp);
+   }
+   return buffer;
+}
+
+/**
+ * Creates an IO mapping for a block of a given size at a given offset.
+ *
+ * IO mapping allows to access file data in a very efficient way: the os
+ * automatically loads the accessed data.
+ *
+ * The instance administrates an internal block independent from the requested
+ * block which is normally much larger.
+ *
+ * @param offset    the distance of the blockstart to the begin of the file
+ * @param size      the requested block size
+ * @param length    OUT: the length of the returned block.
+ *                  May be smaller than requested size
+ * @return          NULL: wrong parameters<br>
+ *                  otherwise: a pointer to the block
+ */
+char* ReFile::remap(int64_t offset, int size, int& length){
+   char* rc = NULL;
+   length = 0;
+   // valid block?
+   if (offset >= 0 && offset < m_filesize){
+      if (size > m_blocksize)
+         size = m_blocksize;
+      if (offset + size > m_filesize)
+         // fs=3, o=1, => s= 2 = fs - o
+         size = m_filesize - offset;
+      // Note: size <= m_blocksize
+      if (m_block != NULL && offset >= m_blockOffset
+         && offset + size <= m_blockOffset + m_blocksize){
+         // new block is inside the internal block:
+         // no remapping needed
+         rc = m_block + (offset - m_blockOffset);
+         length = size;
+      }else{
+         // the new block will be surrounded by the internal block
+         m_blockOffset = offset - m_blocksize / 2;
+         if (m_blockOffset < 0)
+            m_blockOffset = 0;
+         else if (m_blockOffset + m_blocksize > m_filesize)
+            m_blockOffset = m_filesize - m_blocksize;
+         if (m_block != NULL)
+            m_file.unmap(reinterpret_cast <uchar*>(m_block));
+         m_block = reinterpret_cast <char*>(m_file.map(m_blockOffset,
+            m_blocksize));
+         rc = m_block + (offset - m_blockOffset);
+         length = m_blocksize - (rc - m_block);
+         if (length > size)
+            length = size;
+      }
+   }
+   return rc;
+}
+
+/**
+ * Sets the read position prior to the begin of file.
+ */
+void ReFile::rewind(){
+   m_lineNo = 0;
+   m_lineLength = 0;
+   m_lineOffset = 0;
+   m_startOfLine = NULL;
+}
+
+/**
+ * Sets the internal blocksize.
+ *
+ * @param blocksize the blocksize to set
+ */
+void ReFile::setBlocksize(const int64_t& blocksize){
+   m_blocksize = blocksize;
+   if (m_maxLineLength > blocksize / 2)
+      m_maxLineLength = blocksize / 2;
+}
+
+/**
+ * @brief Returns the name of a directory in the temp dir.
+ *
+ * If the named directory does not exist it will be created.
+ *
+ * @param node          NULL or the node (name without path)
+ * @param parent        NULL or a node of the parent
+ * @param withSeparator true: the result ends with slash/backslash
+ * @return              the name of an existing directory
+ */
+QByteArray ReFile::tempDir(const char* node, const char* parent,
+   bool withSeparator){
+#if defined __linux__
+   QByteArray temp("/tmp");
+   static const char* firstVar = "TMP";
+   static const char* secondVar = "TEMP";
+#elif defined WIN32
+   QByteArray temp("c:\\temp");
+   static const char* firstVar = "TEMP";
+   static const char* secondVar = "TMP";
+#endif
+   struct stat info;
+   const char* ptr;
+   if ((ptr = getenv(firstVar)) != NULL)
+      temp = ptr;
+   else if ((ptr = getenv(secondVar)) != NULL)
+      temp = ptr;
+#if defined WIN32
+   temp.replace('\\', '/');
+#endif
+   if (temp.at(temp.length() - 1) != '/')
+      temp += '/';
+   if (parent != NULL){
+      temp += parent;
+      if (stat(temp.constData(), &info) != 0)
+         mkdir(temp.constData(), (-1));
+      temp += '/';
+   }
+   if (node != NULL){
+      temp += node;
+      if (stat(temp.data(), &info) != 0)
+         mkdir(temp.data(), -1);
+      temp += '/';
+   }
+   if (!withSeparator)
+      temp.resize(temp.length() - 1);
+   return temp;
+}
+
+/**
+ * @brief Returns a name of a file in a temporary directory.
+ *
+ * @param node              the file's name without path
+ * @param parent            NULL or the name of a subdirectory the file will be inside
+ * @param deleteIfExists    true: if the file exists it will be removed
+ * @return                  the full name of a temporary file
+ */
+QByteArray ReFile::tempFile(const char* node, const char* parent,
+   bool deleteIfExists){
+   QByteArray rc(tempDir(parent));
+   if (!rc.endsWith('/'))
+      rc += '/';
+   rc += node;
+   struct stat info;
+   if (deleteIfExists && stat(rc.constData(), &info) == 0)
+      unlink(rc.constData());
+   return rc;
+}
+
+/**
+ * Writes a string into a given file.
+ *
+ * @param filename      name of the file to write
+ * @param content       the content to write
+ * @param contentLength -1: <code>strlen(content)</code><br>
+ *                      otherwise: the length of <code>content</code>
+ * @param mode          file write mode: "w" (write) or "a" (append)
+ */
+void ReFile::writeToFile(const char* filename, const char* content,
+   size_t contentLength, const char* mode){
+   FILE* fp = fopen(filename, mode);
+   if (fp != NULL){
+      if (contentLength == (size_t) - 1)
+         contentLength = strlen(content);
+      fwrite(content, 1, contentLength, fp);
+      fclose(fp);
+   }
+}
diff --git a/base/ReFile.hpp b/base/ReFile.hpp
new file mode 100644 (file)
index 0000000..1b6ddc7
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+ */
+
+#ifndef REFILE_HPP
+#define REFILE_HPP
+
+class ReFile {
+public:
+   ReFile(const QString& filename);
+   ~ReFile();
+public:
+   int64_t blocksize() const;
+   bool findLine(const char* toFind, bool ignoreCase, int& lineNo,
+      QString* line);
+   bool findLine(const QString& includePattern, bool includeIsRegExpr,
+      const QString& excludePattern, bool excludeIsRegExpr, int& lineNo,
+      QString* line);
+   /**
+    * Returns the current line number.
+    * @return the current line number
+    */
+   inline uint32_t lineNo() const{
+      return m_lineNo;
+   }
+   char* nextLine(int& length);
+   char* previousLine(int& length);
+   char* remap(int64_t offset, int size, int& length);
+   void setBlocksize(const int64_t& blocksize);
+   void rewind();
+public:
+   static QByteArray tempDir(const char* node, const char* parent = NULL,
+      bool withSeparator = true);
+   static QByteArray tempFile(const char* node, const char* parent = NULL,
+      bool deleteIfExists = true);
+   static QByteArray& readFromFile(const char* filename, QByteArray& buffer);
+   static void writeToFile(const char* filename, const char* content,
+      size_t contentLength = (size_t) - 1, const char* mode = "w");
+
+private:
+   QString m_filename;
+   QFile m_file;
+   char* m_block;
+   int64_t m_blocksize;
+   int64_t m_blockOffset;
+   int64_t m_filesize;
+   char* m_startOfLine;
+   int m_lineLength;
+   int64_t m_lineOffset;
+   uint32_t m_lineNo;
+   int m_maxLineLength;
+};
+
+#endif // REFILE_HPP
index 2286b23623cfc04b8e54400859b3eb2d17ad05d8..a9311352047186e8c25c2e8d2b811263af1ba92d 100644 (file)
@@ -49,8 +49,12 @@ typedef QString ReString;
 
 #ifdef __linux__
 #define _strcasecmp strcasecmp
+#define OS_SEPARATOR '/'
+#define OS_SEPARATOR_STR "/"
 #else
 #define _strcasecmp _stricmp
+#define OS_SEPARATOR '\\'
+#define OS_SEPARATOR_STR "\\"
 #endif
 
 #define UNUSED_VAR(var) (void) var
@@ -67,6 +71,7 @@ typedef QString ReString;
 #include "base/ReConfigurator.hpp"
 #include "base/ReConfig.hpp"
 #include "base/ReTerminator.hpp"
+#include "base/ReFile.hpp"
 #include "base/ReTest.hpp"
 
 #endif // REBASE_HPP
index 588f08534140eb548a7ca5b665a5c0865c491077..0a575c2d7a5754608b5bdf2a90813ac1c783f6d2 100644 (file)
@@ -8,12 +8,12 @@
  * You also can use the license from http://www.wtfpl.net/.
  * The latest sources: https://github.com/republib
  */
-#include "base/rebase.hpp"
-#include "math/remath.hpp"
-#include "net/renet.hpp"
+#include "../base/rebase.hpp"
+#include "../math/remath.hpp"
+#include "../net/renet.hpp"
 //#include "os/reos.hpp"
 
-static bool s_allTest = true;
+static bool s_allTest = false;
 
 static void testBase(){
    void testReByteStorage();
@@ -24,9 +24,11 @@ static void testBase(){
    void testReQStringUtil();
    void testReStringUtil();
    void testReWriter();
+   void testReFile();
 
-   testReQStringUtil();
+   testReFile();
    if (s_allTest){
+      testReQStringUtil();
       testReByteStorage();
       testReCharPtrMap();
       testReConfig();
@@ -41,6 +43,7 @@ static void testMath(){
 
 }
 static void testExpr(){
+    /*
    extern void testReMFParser();
    extern void testRplBenchmark();
    extern void testReVM();
@@ -59,6 +62,7 @@ static void testExpr(){
       testReASTree();
       testReVM();
    }
+   */
 }
 static void testNet(){
 
index 985546bf4983e798495395368500625237e9a5f4..96d3b095a19a76b716ecbcb2a289c5d48bc0bfc4 100644 (file)
@@ -62,7 +62,6 @@ private:
          buffer[1] = 'A' + ii % 26;
          store.allocateBytes(buffer, 1);
       }
-      int a = 1;
    }
 
 public:
diff --git a/cunit/cuReFile.cpp b/cunit/cuReFile.cpp
new file mode 100644 (file)
index 0000000..ccecbf5
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * rplexception_test.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+#include "base/rebase.hpp"
+
+/** @file
+ * @brief Unit test of the basic exceptions.
+ */
+
+class TestReFile: public ReTest {
+public:
+   TestReFile() :
+            ReTest("ReFile"){
+      doIt();
+   }
+
+public:
+   void testBasic(){
+      QByteArray fn(ReFile::tempFile("big.txt", NULL, true));
+      const char* content =
+         "123456789 123456789 123456789 123456789 123456789\n";
+      int contentLength = strlen(content);
+      ReFile::writeToFile(fn.constData(), content);
+      ReFile file(fn.constData());
+      int size = 4;
+      file.setBlocksize(2 * size);
+      int length = -2;
+      char* ptr = file.remap(0, size, length);
+      checkNN(ptr);
+      checkEqu(4, length);
+      checkEqu(0,
+         strncmp(content, reinterpret_cast <const char*>(ptr), length));
+      int part = size / 2;
+      ptr = file.remap(contentLength - part, size, length);
+      checkEqu(size / 2, length);
+      checkEqu(content + contentLength - part,
+         reinterpret_cast <const char*>(ptr));
+      for (int ix = 0; ix < contentLength - size; ix++){
+         ptr = file.remap(ix, size, length);
+         checkNN(ptr);
+         checkEqu(length, size);
+         checkEqu(0,
+            strncmp(content + ix, reinterpret_cast <const char*>(ptr), length));
+      }
+
+   }
+   void testTempFile(){
+      QByteArray fn(ReFile::tempFile("node.txt", "subdir", true));
+      QByteArray content;
+      ReFile::writeToFile(fn, "123");
+      struct stat info;
+      checkEqu(0, stat(fn.constData(), &info));
+      checkEqu(3, (int ) info.st_size);
+      ReFile::tempFile("node.txt", "subdir", true);
+      checkEqu(-1, stat(fn.constData(), &info));
+   }
+   void testTempDir(){
+      QByteArray dir(ReFile::tempDir("subdir", "curefile", false));
+      checkT(dir.endsWith("subdir"));
+      checkT(dir.endsWith("curefile/subdir"));
+      struct stat info;
+      checkEqu(0, stat(dir, &info));
+      checkT(S_ISDIR(info.st_mode));
+   }
+   void testWriteRead(){
+      QByteArray fn(ReFile::tempFile("node.txt", "subdir", true));
+      ReFile::writeToFile(fn, "123");
+      QByteArray content;
+      ReFile::readFromFile(fn, content);
+      checkEqu("123", content);
+      ReFile::writeToFile(fn, "abcdef", 2);
+      ReFile::readFromFile(fn, content);
+      checkEqu("ab", content);
+   }
+   void countLinesReFile(const char* filename, int64_t blocksize){
+      clock_t start = clock();
+      int lines = 0;
+      { // enforce the destructor inside measurement:
+         ReFile file(filename);
+         file.setBlocksize(blocksize);
+         int length;
+         while (file.nextLine(length)){
+            lines++;
+         }
+      }
+      double duration = double(clock() - start) / CLOCKS_PER_SEC;
+      printf("linecount (ReFile, %d kB): %d lines %.3f sec\n",
+         int(blocksize / 1024), lines, duration);
+
+   }
+   void countLinesFopen(const char* filename){
+      clock_t start = clock();
+      FILE* fp = fopen(filename, "r");
+      int lines = 0;
+      char line[64000];
+      if (fp != NULL){
+         while (fgets(line, sizeof line, fp) != NULL)
+            lines++;
+      }
+      fclose(fp);
+      double duration = double(clock() - start) / CLOCKS_PER_SEC;
+      printf("linecount (fopen): %d lines %.3f sec\n", lines, duration);
+
+   }
+
+   void testPerformance(){
+      const char* fn = "/opt/bench/long_html.txt";
+      if (QFileInfo(fn).exists()){
+         countLinesReFile(fn, 60 * 1024 * 1024);
+         countLinesFopen(fn);
+         countLinesReFile(fn, 100 * 1024);
+         countLinesReFile(fn, 1024 * 1024);
+         countLinesReFile(fn, 10 * 1024 * 1024);
+      }
+   }
+
+   virtual void run(){
+      testPerformance();
+      testBasic();
+      testTempDir();
+      testTempFile();
+      testWriteRead();
+   }
+};
+void testReFile(){
+   TestReFile test;
+}
+
index 67058aaa6038d1a6abf11e7b36bdce483a3c9eba..109797302253f72282c40744b3c8fc66dfca50ec 100644 (file)
@@ -12,7 +12,7 @@
  * @brief Unit test of the ReString tools.
  */
 
-#include "base/rebase.hpp"
+#include "../base/rebase.hpp"
 
 class TestReQStringUtil: public ReTest {
 public:
diff --git a/cunit/cunit.pro b/cunit/cunit.pro
new file mode 100644 (file)
index 0000000..cf972ff
--- /dev/null
@@ -0,0 +1,45 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2015-05-10T13:56:15
+#
+#-------------------------------------------------
+
+QT       += core network
+
+QT       -= gui
+
+TARGET = cunit
+CONFIG   += console
+CONFIG   -= app_bundle
+
+TEMPLATE = app
+
+INCLUDEPATH = ..
+
+SOURCES += main.cpp \
+        cuReQStringUtil.cpp \
+        cuReStringUtil.cpp \
+        cuReByteStorage.cpp \
+        allTests.cpp \
+        cuReException.cpp \
+    ../base/ReByteStorage.cpp \
+    ../base/ReCharPtrMap.cpp \
+    ../base/ReConfig.cpp \
+    ../base/ReContainer.cpp \
+    ../base/ReException.cpp \
+    ../base/ReQStringUtil.cpp \
+    ../base/ReLogger.cpp \
+    ../base/ReStringUtil.cpp \
+    ../base/ReTerminator.cpp \
+    ../base/ReTest.cpp \
+    ../base/ReWriter.cpp \
+    cuReConfig.cpp \
+    cuReContainer.cpp \
+    cuReWriter.cpp \
+    cuReCharPtrMap.cpp \
+    ../base/ReFile.cpp \
+    cuReFile.cpp
+
+HEADERS += \
+    ../base/ReFile.hpp \
+    ../base/rebase.hpp
diff --git a/cunit/main.cpp b/cunit/main.cpp
new file mode 100644 (file)
index 0000000..c98779d
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+
+#include <QCoreApplication>
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+    void allTests();
+    allTests();
+    return a.exec();
+}
index 0104a977fab436d2f2523ee438831b1de69fc2ce..2aa8d277a839c38c1adbcc604f3943a4aca8d5a0 100644 (file)
@@ -17,33 +17,33 @@ INCLUDEPATH = ..
 TEMPLATE = app
 
 SOURCES += main.cpp \
-    ../rplcore/rpllogger.cpp \
-    ../rplcore/rpltest.cpp \
-    ../rplcore/rplstring.cpp \
-    ../rplcore/rplexception.cpp \
-    ../rplmath/rplmatrix.cpp \
-    ../rplexpr/rplsource.cpp \
-    ../rplexpr/rpllexer.cpp \
-    ../rplexpr/rplastree.cpp \
-    ../rplexpr/rplparser.cpp \
-    ../rplexpr/rplmfparser.cpp \
-    ../rplcore/rplqstring.cpp \
-    ../rplexpr/rplasclasses.cpp \
-    ../rplcore/rplbytestorage.cpp \
-    ../rplexpr/rplvm.cpp \
-    ../rplcore/rplwriter.cpp \
-    rplmatrix_test.cpp \
-    rplexception_test.cpp \
-    rplstring_test.cpp \
-    rplsource_test.cpp \
-    rpllexer_test.cpp \
-    rplqstring_test.cpp \
-    rplastree_test.cpp \
-    rplmfparser_test.cpp \
-    rplvm_test.cpp \
-    rplbytestorage_test.cpp \
-    rplwriter_test.cpp \
-    rplbench.cpp \
-    rplcharptrmap_test.cpp \
-    ../rplcore/rplcharptrmap.cpp
+        ../base/ReLogger.cpp \
+        ../base/ReTest.cpp \
+        ../base/ReString.cpp \
+        ../base/ReException.cpp \
+        ../math/ReMatrix.cpp \
+        ../expr/ReSource.cpp \
+        ../expr/ReLexer.cpp \
+        ../expr/ReASTree.cpp \
+        ../expr/ReParser.cpp \
+        ../expr/ReMFParser.cpp \
+        ../base/ReQString.cpp \
+        ../expr/ReASClasses.cpp \
+        ../base/ReByteStorage.cpp \
+        ../expr/ReVM.cpp \
+        ../base/ReWriter.cpp \
+        rplmatrix_test.cpp \
+        rplexception_test.cpp \
+        rplstring_test.cpp \
+        rplsource_test.cpp \
+        rpllexer_test.cpp \
+        rplqstring_test.cpp \
+        rplastree_test.cpp \
+        rplmfparser_test.cpp \
+        rplvm_test.cpp \
+        rplbytestorage_test.cpp \
+        rplwriter_test.cpp \
+        rplbench.cpp \
+        rplcharptrmap_test.cpp \
+        ../base/rplcharptrmap.cpp