diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index f48008c2d..4afdc6614 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -111,3 +111,12 @@ foreach( subdir modulesystem utils viewpages widgets ) file( GLOB subdir_headers "${subdir}/*.h" ) install( FILES ${subdir_headers} DESTINATION include/libcalamares/${subdir} ) endforeach() + +calamares_add_test( + test_libcalamaresuipaste + SOURCES + utils/TestPaste.cpp + utils/Paste.cpp + LIBRARIES + calamaresui +) diff --git a/src/libcalamaresui/utils/Paste.cpp b/src/libcalamaresui/utils/Paste.cpp index ee54d265a..2d2f5404e 100644 --- a/src/libcalamaresui/utils/Paste.cpp +++ b/src/libcalamaresui/utils/Paste.cpp @@ -36,7 +36,7 @@ logFileContents() STATICTEST QString -ficheLogUpload( const QByteArray& pasteData, QUrl& serverUrl, QObject* parent ) +ficheLogUpload( const QByteArray& pasteData, const QUrl& serverUrl, QObject* parent ) { QTcpSocket* socket = new QTcpSocket( parent ); socket->connectToHost( serverUrl.host(), serverUrl.port() ); diff --git a/src/libcalamaresui/utils/TestPaste.cpp b/src/libcalamaresui/utils/TestPaste.cpp new file mode 100644 index 000000000..ff75be02d --- /dev/null +++ b/src/libcalamaresui/utils/TestPaste.cpp @@ -0,0 +1,67 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2021 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later + * + * + * Calamares is Free Software: see the License-Identifier above. + * + * + */ + +#include "Paste.h" + +#include "utils/Logger.h" + +#include +#include + +extern QByteArray logFileContents(); +extern QString ficheLogUpload( const QByteArray& pasteData, const QUrl& serverUrl, QObject* parent ); + +class TestPaste : public QObject +{ + Q_OBJECT + +public: + TestPaste() {} + ~TestPaste() override {} + +private Q_SLOTS: + void testGetLogFile(); + void testFichePaste(); +}; + +void +TestPaste::testGetLogFile() +{ + // This test assumes nothing **else** has set up logging yet + QByteArray b = logFileContents(); + QVERIFY( b.isEmpty() ); + + Logger::setupLogLevel( Logger::LOGDEBUG ); + Logger::setupLogfile(); + + b = logFileContents(); + QVERIFY( !b.isEmpty() ); +} + +void +TestPaste::testFichePaste() +{ + QString blabla( "the quick brown fox tested Calamares and found it rubbery" ); + QDateTime now = QDateTime::currentDateTime(); + + QByteArray d = ( blabla + now.toString() ).toUtf8(); + QString s = ficheLogUpload( d, QUrl( "http://termbin.com:9999" ), nullptr ); + + cDebug() << "Paste data to" << s; + QVERIFY( !s.isEmpty() ); +} + + +QTEST_GUILESS_MAIN( TestPaste ) + +#include "utils/moc-warnings.h" + +#include "TestPaste.moc"