File indexing completed on 2024-04-28 05:52:32

0001 /*
0002     This file is part of the Okteta Core library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2006 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "fixedsizebytearraymodeltest.hpp"
0010 
0011 // test object
0012 #include <fixedsizebytearraymodel.hpp>
0013 // Qt
0014 #include <QTest>
0015 
0016 namespace Okteta {
0017 
0018 // test the compare function
0019 // uses a comparison buffer of the same size
0020 // changes the first, a middle, and the last char to a greater or smaller char and compares
0021 void FixedSizeByteArrayModelTest::testCompare()
0022 {
0023     const Size BaseSize = 60;
0024     // create a working buffer
0025     FixedSizeByteArrayModel Buffer(BaseSize, 'b');
0026     FixedSizeByteArrayModel OtherBuffer(BaseSize);
0027     OtherBuffer.fill('b');
0028 
0029     const Address Last = BaseSize - 1;
0030     AddressRange FullRange(0, Last);
0031     // same size and equal
0032     QCOMPARE(Buffer.compare(OtherBuffer), 0);
0033     // same size and last smaller
0034     Buffer.rawData()[Last] = 'c';
0035     QVERIFY(Buffer.compare(OtherBuffer) > 0);
0036     // same size and last greater
0037     Buffer.rawData()[Last] = 'a';
0038     QVERIFY(Buffer.compare(OtherBuffer) < 0);
0039     // same size and middle smaller
0040     Buffer.rawData()[BaseSize / 2] = 'c';
0041     QVERIFY(Buffer.compare(OtherBuffer) > 0);
0042     // same size and middle greater
0043     Buffer.rawData()[BaseSize / 2] = 'a';
0044     QVERIFY(Buffer.compare(OtherBuffer) < 0);
0045     // same size and first smaller
0046     Buffer.rawData()[0] = 'c';
0047     QVERIFY(Buffer.compare(OtherBuffer) > 0);
0048     // same size and first greater
0049     Buffer.rawData()[0] = 'a';
0050     QVERIFY(Buffer.compare(OtherBuffer) < 0);
0051 }
0052 
0053 /*
0054 void KDataBufferIfTest::testCopy()
0055 {
0056    // test copyTo TODO: for this we would need a compareTo
0057    //  char[] TestArray = new char[OtherBuffer->size()];
0058    //  OtherBuffer->set( 't' );
0059    //  DataBuffwer
0060    //  QVERIFY( "copy() from begin",  OtherBuffer->compare(Buffer,AddressRange( 0, CopySize, true ),0) == 0 );
0061    //  delete [] TestArray;
0062 
0063    int BaseSize = 60;
0064    int CopySize = 20;
0065    // create a working buffer
0066    FixedSizeByteArrayModel Buffer( BaseSize, 'b' );
0067    FixedSizeByteArrayModel OtherBuffer( BaseSize );
0068    OtherBuffer.fill( 'a' );
0069 
0070    int Last = BaseSize-1;
0071    AddressRange FullRange(0,Last);
0072 
0073    // copy from
0074    Buffer.copy( OtherBuffer, 0, CopySize );
0075    QVERIFY( "copy() from begin",  OtherBuffer->compare(Buffer,0,CopySize,0) == 0 );
0076 
0077    Buffer.fill( '\b' );
0078    Buffer.copy( *OtherBuffer, TestSection );
0079    QVERIFY( "copy() from middle",  OtherBuffer->compare(Buffer,0,CopySize,TestSection.start()) == 0 );
0080 
0081    Buffer.fill( '\b' );
0082    Buffer.copy( *OtherBuffer, E, CopySize );
0083    QVERIFY( "copy() from before end",  OtherBuffer->compare(Buffer,0,CopySize,E) == 0 );
0084 
0085    // copy to
0086    Buffer.fill( '\b' );
0087    OtherBuffer->set( 't' );
0088    OtherBuffer->copy( Buffer, 0, CopySize );
0089    QVERIFY( "copy() to begin",  OtherBuffer->compare(Buffer,0,CopySize,0) == 0 );
0090 
0091    Buffer.fill( '\b' );
0092    OtherBuffer->set( 't' );
0093    OtherBuffer->copy( Buffer, 0, CopySize, TestSection.start() );
0094    QVERIFY( "copy() to middle",  OtherBuffer->compare(Buffer,0,CopySize,TestSection.start()) == 0 );
0095 
0096    Buffer.fill( '\b' );
0097    OtherBuffer->set( 't' );
0098    E = OtherBuffer->size() - CopySize;
0099    OtherBuffer->copy( Buffer, 0,CopySize, E );
0100    QVERIFY( "copy() to before end",  OtherBuffer->compare(Buffer,0,CopySize,E) == 0 );
0101 }
0102 */
0103 }
0104 
0105 QTEST_GUILESS_MAIN(Okteta::FixedSizeByteArrayModelTest)
0106 
0107 #include "moc_fixedsizebytearraymodeltest.cpp"