[Libreoffice-commits] core.git: comphelper/qa comphelper/source

Vasily Melenchuk (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 30 18:30:19 UTC 2019


 comphelper/qa/complex/comphelper/SequenceOutputStreamUnitTest.java |   60 ++--------
 comphelper/source/streaming/seqoutputstreamserv.cxx                |    1 
 2 files changed, 17 insertions(+), 44 deletions(-)

New commits:
commit 468a048942cad81db81a4999a1840a488988f253
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Mon Sep 30 13:15:34 2019 +0300
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Sep 30 20:28:55 2019 +0200

    fix: SequenceOutputStream does append content correctly
    
    Previous implementation was just rewriting content on each
    call to writeBytes() making this stream unusable.
    
    Improved and refactored corresponding Java unittest, now
    it check given above behavior and reacts on failures instead
    just writing mesages to stdout.
    
    Change-Id: Ib56baf07d8767b246a9d75cd5d639a2c2c0e7a5d
    Reviewed-on: https://gerrit.libreoffice.org/79840
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/comphelper/qa/complex/comphelper/SequenceOutputStreamUnitTest.java b/comphelper/qa/complex/comphelper/SequenceOutputStreamUnitTest.java
index 6a14a359bd2c..03906134b9f7 100644
--- a/comphelper/qa/complex/comphelper/SequenceOutputStreamUnitTest.java
+++ b/comphelper/qa/complex/comphelper/SequenceOutputStreamUnitTest.java
@@ -35,35 +35,13 @@ import static org.junit.Assert.*;
 /* Document.
  */
 
-class TestHelper
-{
-    private String m_sTestPrefix;
-
-    /** Creates a new instance of TestHelper
-     */
-    public TestHelper ( String sTestPrefix ) {
-        m_sTestPrefix = sTestPrefix;
-    }
-
-    public void Error ( String sError ) {
-        System.out.println ( m_sTestPrefix + "Error: " + sError );
-    }
-
-    public void Message ( String sMessage ) {
-        System.out.println ( m_sTestPrefix + sMessage );
-    }
-}
-
 public class SequenceOutputStreamUnitTest
 {
     private XMultiServiceFactory m_xMSF = null;
 
-    TestHelper m_aTestHelper = null;
-
     @Before public void before() {
         try {
             m_xMSF = getMSF();
-            m_aTestHelper = new TestHelper ( "Test01: ");
         } catch (Exception e) {
             fail ("Cannot create service factory!");
         }
@@ -86,15 +64,19 @@ public class SequenceOutputStreamUnitTest
             XSequenceOutputStream xSeqOutStream =
                     UnoRuntime.queryInterface (
                     XSequenceOutputStream.class, oSequenceOutputStream );
-            m_aTestHelper.Message ( "SequenceOutputStream created." );
 
             //write something to the stream
             byte pBytesOriginal[] = new byte [nBytesCnt];
             Random oRandom = new Random();
             oRandom.nextBytes (pBytesOriginal);
             xSeqOutStream.writeBytes (pBytesOriginal);
+
+            // Append the same content once again
+            xSeqOutStream.writeBytes (pBytesOriginal);
+
             byte pBytesWritten[] = xSeqOutStream.getWrittenBytes ();
-            m_aTestHelper.Message ( "SequenceOutputStream filled." );
+            assertTrue( "SequenceOutputStream::getWrittenBytes() - wrong amount of bytes returned",
+                    pBytesWritten.length == nBytesCnt * 2 );
 
             //create SequenceInputstream
             Object pArgs[] = new Object[1];
@@ -104,36 +86,28 @@ public class SequenceOutputStreamUnitTest
             XSeekableInputStream xSeekableInStream =
                     UnoRuntime.queryInterface (
                     XSeekableInputStream.class, oSequenceInputStream );
-            m_aTestHelper.Message ( "SequenceInputStream created." );
 
             //read from the stream
-            byte pBytesRead[][] = new byte [1][nBytesCnt];
-            xSeekableInStream.readBytes ( pBytesRead, pBytesRead[0].length + 1 );
-            m_aTestHelper.Message ( "Read from SequenceInputStream." );
+            byte pBytesRead[][] = new byte [1][nBytesCnt*2];
+            int nBytesCountRead = xSeekableInStream.readBytes ( pBytesRead, pBytesRead[0].length + 1 );
+
+            assertTrue( "SequenceInputStream::readBytes() - wrong amount of bytes returned " + pBytesRead[0].length + " vs " + (nBytesCountRead),
+                    pBytesRead[0].length == nBytesCountRead);
 
             //close the streams
             xSeqOutStream.closeOutput ();
             xSeekableInStream.closeInput ();
-            m_aTestHelper.Message ( "Both streams closed." );
 
             //compare the original, written and read arrays
-            for ( int i = 0; i < nBytesCnt; ++i ) {
-                if ( pBytesOriginal[i] != pBytesWritten[i] ) {
-                    m_aTestHelper.Error ( "Written array not identical to " +
-                            "original array. Position: " + i );
-                    return /* false */;
-                } else if ( pBytesOriginal[i] != pBytesRead[0][i] ) {
-                    m_aTestHelper.Error ( "Read array not identical to original " +
-                            "array. Position: " + i );
-                    return /* false */;
-                }
+            for ( int i = 0; i < nBytesCnt * 2; ++i ) {
+                assertTrue( "Written array not identical to original array. Position: " + i,
+                    pBytesOriginal[i % nBytesCnt] == pBytesWritten[i] );
+                assertTrue( "Read array not identical to original array. Position: " + i,
+                    pBytesOriginal[i % nBytesCnt] == pBytesRead[0][i] );
             }
-            m_aTestHelper.Message ( "All data correct." );
         } catch ( Exception e ) {
-            m_aTestHelper.Error ( "Exception: " + e );
-            return /* false */;
+            fail ( "Exception: " + e );
         }
-        // return /* true */;
     }
 
     private static XMultiServiceFactory getMSF()
diff --git a/comphelper/source/streaming/seqoutputstreamserv.cxx b/comphelper/source/streaming/seqoutputstreamserv.cxx
index 5f679a914abf..cadc691c8f03 100644
--- a/comphelper/source/streaming/seqoutputstreamserv.cxx
+++ b/comphelper/source/streaming/seqoutputstreamserv.cxx
@@ -95,7 +95,6 @@ void SAL_CALL SequenceOutputStreamService::writeBytes( const uno::Sequence< ::sa
         throw io::NotConnectedException();
 
     m_xOutputStream->writeBytes( aData );
-    m_aSequence = aData;
 }
 
 void SAL_CALL SequenceOutputStreamService::flush()


More information about the Libreoffice-commits mailing list