File indexing completed on 2024-05-12 05:52:02

0001 /*
0002     SPDX-FileCopyrightText: 2022 Waqar Ahmed <waqar.17a@gmail.com>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #include "bytearraysplitter_tests.h"
0007 #include "bytearraysplitter.h"
0008 
0009 #include <QTest>
0010 
0011 QTEST_MAIN(ByteArraySplitterTests)
0012 
0013 void ByteArraySplitterTests::test_data()
0014 {
0015     const QByteArray b("hello\0world\0waqar", sizeof("hello\0world\0waqar") - 1);
0016 
0017     QTest::addColumn<QByteArray>("data");
0018     QTest::addColumn<char>("splitOn");
0019 
0020     QTest::addRow("1") << QByteArray("hello\0world\0foo", sizeof("hello\0world\0foo") - 1) << char('\0');
0021     QTest::addRow("2") << QByteArray("hello\nworld\nfoo") << char('\n');
0022     QTest::addRow("3") << QByteArray("abc\ndef\nhij") << char('z');
0023 }
0024 
0025 void ByteArraySplitterTests::test()
0026 {
0027     QFETCH(QByteArray, data);
0028     QFETCH(char, splitOn);
0029 
0030     QByteArrayList actual;
0031     for (auto sv : ByteArraySplitter(data, splitOn)) {
0032         actual.append(QByteArray(sv.data(), sv.size()));
0033     }
0034     QCOMPARE(data.split(splitOn), actual);
0035 }
0036 
0037 #include "moc_bytearraysplitter_tests.cpp"