Author: cfinck
Date: Sun Mar 22 12:35:08 2015
New Revision: 66855

URL: http://svn.reactos.org/svn/reactos?rev=66855&view=rev
Log:
[ROSAUTOTEST]
Make outputting a string as easy as it should be. Now that our StringOut 
internally uses OutputDebugStringA instead of DbgPrint, we don't need to output 
in 512 byte chunks anymore.
Additionally, do an explicit flush when using std::cout to not lose debug 
output.

ROSTESTS-158 #resolve #comment Committed in r66855

Modified:
    trunk/rostests/rosautotest/CWineTest.cpp
    trunk/rostests/rosautotest/precomp.h
    trunk/rostests/rosautotest/tools.cpp

Modified: trunk/rostests/rosautotest/CWineTest.cpp
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/rosautotest/CWineTest.cpp?rev=66855&r1=66854&r2=66855&view=diff
==============================================================================
--- trunk/rostests/rosautotest/CWineTest.cpp    [iso-8859-1] (original)
+++ trunk/rostests/rosautotest/CWineTest.cpp    [iso-8859-1] Sun Mar 22 
12:35:08 2015
@@ -276,7 +276,6 @@
     stringstream ss, ssFinish;
     DWORD StartTime;
     float TotalTime;
-    string tailString;
     CPipe Pipe;
     char Buffer[1024];
 
@@ -295,7 +294,7 @@
         {
             /* Output text through StringOut, even while the test is still 
running */
             Buffer[BytesAvailable] = 0;
-            tailString = StringOut(tailString.append(string(Buffer)), false);
+            StringOut(string(Buffer));
 
             if(Configuration.DoSubmit())
                 TestInfo->Log += Buffer;
@@ -305,16 +304,9 @@
     }
     catch(CTestException& e)
     {
-        if(!tailString.empty())
-            StringOut(tailString);
-        tailString.clear();
         StringOut(e.GetMessage());
         TestInfo->Log += e.GetMessage();
     }
-
-    /* Print what's left */
-    if(!tailString.empty())
-        StringOut(tailString);
 
     TotalTime = ((float)GetTickCount() - StartTime)/1000;
     ssFinish << "Test " << TestInfo->Test << " completed in ";

Modified: trunk/rostests/rosautotest/precomp.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/rosautotest/precomp.h?rev=66855&r1=66854&r2=66855&view=diff
==============================================================================
--- trunk/rostests/rosautotest/precomp.h        [iso-8859-1] (original)
+++ trunk/rostests/rosautotest/precomp.h        [iso-8859-1] Sun Mar 22 
12:35:08 2015
@@ -69,7 +69,7 @@
 string EscapeString(const string& Input);
 string GetINIValue(PCWCH AppName, PCWCH KeyName, PCWCH FileName);
 bool IsNumber(const char* Input);
-string StringOut(const string& String, bool forcePrint = true);
+void StringOut(const string& InputString);
 string UnicodeToAscii(PCWSTR UnicodeString);
 string UnicodeToAscii(const wstring& UnicodeString);
 

Modified: trunk/rostests/rosautotest/tools.cpp
URL: 
http://svn.reactos.org/svn/reactos/trunk/rostests/rosautotest/tools.cpp?rev=66855&r1=66854&r2=66855&view=diff
==============================================================================
--- trunk/rostests/rosautotest/tools.cpp        [iso-8859-1] (original)
+++ trunk/rostests/rosautotest/tools.cpp        [iso-8859-1] Sun Mar 22 
12:35:08 2015
@@ -2,12 +2,11 @@
  * PROJECT:     ReactOS Automatic Testing Utility
  * LICENSE:     GNU GPLv2 or any later version as published by the Free 
Software Foundation
  * PURPOSE:     Various helper functions
- * COPYRIGHT:   Copyright 2008-2009 Colin Finck <co...@reactos.org>
+ * COPYRIGHT:   Copyright 2008-2015 Colin Finck <co...@reactos.org>
  */
 
 #include "precomp.h"
 
-#define DBGPRINT_BUFSIZE   511
 static const char HexCharacters[] = "0123456789ABCDEF";
 
 /**
@@ -87,85 +86,43 @@
 
 /**
  * Outputs a string through the standard output and the debug output.
- * The string may have LF or CRLF line endings.
- *
- * @param String
+ * The input string may have LF or CRLF line endings.
+ *
+ * @param InputString
  * The std::string to output
  */
-string
-StringOut(const string& String, bool forcePrint)
-{
-    char DbgString[DBGPRINT_BUFSIZE + 1];
-    size_t i, start = 0, last_newline = 0, size = 0, curr_pos = 0;
-    string NewString;
+void
+StringOut(const string& InputString)
+{
+    const char* pInput = InputString.c_str();
+    char* OutputString = new char[InputString.size() + 1];
+    char* pOutput = OutputString;
 
     /* Unify the line endings (the piped output of the tests may use CRLF) */
-    for(i = 0; i < String.size(); i++)
+    while (*pInput)
     {
         /* If this is a CRLF line-ending, only copy a \n to the new string and 
skip the next character */
-        if(String[i] == '\r' && String[i + 1] == '\n')
-        {
-            NewString += '\n';
-            ++i;
+        if (*pInput == '\r' && *(pInput + 1) == '\n')
+        {
+            *pOutput = '\n';
+            ++pInput;
         }
         else
         {
-            /* Otherwise copy the string */
-            NewString += String[i];
-        }
-
-        curr_pos = NewString.size();
-
-        /* Try to print whole lines but obey the 512 bytes chunk size limit*/
-        if(NewString[curr_pos - 1] == '\n' || (curr_pos - start) == 
DBGPRINT_BUFSIZE)
-        {
-            if((curr_pos - start) >= DBGPRINT_BUFSIZE)
-            {
-                /* No newlines so far, or the string just fits */
-                if(last_newline <= start || ((curr_pos - start == 
DBGPRINT_BUFSIZE) && NewString[curr_pos - 1] == '\n'))
-                {
-                    size = curr_pos - start;
-                    memcpy(DbgString, NewString.c_str() + start, size);
-                    start = curr_pos;
-                }
-                else
-                {
-                    size = last_newline - start;
-                    memcpy(DbgString, NewString.c_str() + start, size);
-                    start = last_newline;
-                }
-
-                DbgString[size] = 0;
-                OutputDebugStringA(DbgString);
-            }
-
-            last_newline = curr_pos;
-        }
-    }
-
-    size = curr_pos - start;
-
-    /* Only print if forced to or if the rest is a whole line */
-    if(forcePrint == true || NewString[curr_pos - 1] == '\n')
-    {
-        /* Output the whole string */
-        if(Configuration.DoPrint())
-            cout << NewString;
-
-        memcpy(DbgString, NewString.c_str() + start, size);
-        DbgString[size] = 0;
-        OutputDebugStringA(DbgString);
-
-        NewString.clear();
-        return NewString;
-    }
-
-    /* Output full lines only */
-    if(Configuration.DoPrint())
-        cout << NewString.substr(0, start);
-
-    /* Return the remaining chunk */
-    return NewString.substr(start, size);
+            *pOutput = *pInput;
+        }
+
+        ++pInput;
+        ++pOutput;
+    }
+
+    *pOutput = 0;
+    OutputDebugStringA(OutputString);
+
+    if (Configuration.DoPrint())
+        cout << OutputString << flush;
+
+    delete[] OutputString;
 }
 
 /**


Reply via email to