-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c7f05d
commit 20103dd
Showing
6 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
# | ||
add_subdirectory(simpletest) | ||
add_subdirectory(stresstest) | ||
add_subdirectory(namelengthtest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file is part of KDSingleApplication. | ||
# | ||
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# Contact KDAB at <[email protected]> for commercial licensing options. | ||
# | ||
add_subdirectory(namelengthtest) | ||
add_subdirectory(test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# This file is part of KDSingleApplication. | ||
# | ||
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# Contact KDAB at <[email protected]> for commercial licensing options. | ||
# | ||
set(namelengthtest_SRCS main.cpp) | ||
add_executable( | ||
namelengthtest | ||
${namelengthtest_SRCS} | ||
) | ||
target_link_libraries( | ||
namelengthtest Qt::Widgets kdsingleapplication | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
This file is part of KDSingleApplication. | ||
SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
SPDX-License-Identifier: MIT | ||
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
#include <QtCore/QCoreApplication> | ||
#include <QtCore/QStringList> | ||
#include <QtCore/QString> | ||
#include <QtCore/QTimer> | ||
|
||
#include <kdsingleapplication.h> | ||
|
||
#include <iostream> | ||
|
||
#if defined(Q_OS_WIN) | ||
#include <io.h> | ||
#include <fcntl.h> | ||
#endif | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
#if defined(Q_OS_WIN) | ||
_setmode(_fileno(stdout), _O_BINARY); | ||
#endif | ||
|
||
QCoreApplication app(argc, argv); | ||
|
||
const QString appName = QLatin1String("namelengthtest-") + app.arguments().value(1); | ||
|
||
KDSingleApplication kdsa(QStringLiteral("a").repeated(9000)); | ||
|
||
if (kdsa.isPrimaryInstance()) { | ||
std::cout << "Primary" << std::endl; | ||
|
||
QObject::connect(&kdsa, &KDSingleApplication::messageReceived, qApp, | ||
[](const QByteArray &message) { | ||
std::cout << "MESSAGE: >" << message.constData() << '<' << std::endl; | ||
qApp->quit(); | ||
}); | ||
|
||
QTimer::singleShot(5000, qApp, []() { qApp->exit(1); }); | ||
|
||
return app.exec(); | ||
} else { | ||
std::cout << "Secondary" << std::endl; | ||
|
||
if (!kdsa.sendMessage(app.arguments().value(2).toUtf8())) { | ||
std::cerr << "Unable to send message to the primary!" << std::endl; | ||
return 1; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This file is part of KDSingleApplication. | ||
# | ||
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# Contact KDAB at <[email protected]> for commercial licensing options. | ||
# | ||
include_directories(${CMAKE_SOURCE_DIR}/src) | ||
include_directories(${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
add_executable( | ||
tst_namelengthtest | ||
../tst_namelengthtest.cpp | ||
) | ||
target_link_libraries( | ||
tst_namelengthtest Qt::Test | ||
) | ||
add_test(NAME tst_namelengthtest COMMAND tst_namelengthtest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
This file is part of KDSingleApplication. | ||
SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
SPDX-License-Identifier: MIT | ||
Contact KDAB at <[email protected]> for commercial licensing options. | ||
*/ | ||
|
||
#include <QtCore/QProcess> | ||
#include <QtCore/QRandomGenerator> | ||
#include <QtTest/QTest> | ||
|
||
|
||
#include <vector> | ||
#include <memory> | ||
|
||
// runs a primary, runs a secondary, checks that a message is received. | ||
|
||
class tst_NameLengthTest : public QObject | ||
{ | ||
Q_OBJECT | ||
private Q_SLOTS: | ||
void testNameLength_data(); | ||
void testNameLength(); | ||
}; | ||
|
||
void tst_NameLengthTest::testNameLength_data() | ||
{ | ||
QTest::addColumn<QString>("message"); | ||
|
||
QTest::addRow("message-1") << QStringLiteral("Hello"); | ||
QTest::addRow("message-2") << QStringLiteral("Hello World"); | ||
QTest::addRow("message-3") << QStringLiteral("Hello World 123456789"); | ||
// QTest::addRow("message empty") << QString(); | ||
|
||
for (int i = 1; i <= 2048; i *= 2) { | ||
QTest::addRow("message-x-%d", i) << QString(i, QLatin1Char('x')); | ||
} | ||
} | ||
|
||
void tst_NameLengthTest::testNameLength() | ||
{ | ||
QFETCH(QString, message); | ||
#ifdef KDSINGLEAPPLICATION_BINARY_DIR | ||
const QString executable = QStringLiteral(KDSINGLEAPPLICATION_BINARY_DIR "namelengthtest"); | ||
#else | ||
const QString executable = QStringLiteral("namelengthtest/namelengthtest"); | ||
#endif | ||
QByteArray output; | ||
bool ok; | ||
|
||
const QString testId = QString::number(QRandomGenerator::global()->generate()); | ||
|
||
QProcess primary; | ||
primary.setProcessChannelMode(QProcess::ForwardedErrorChannel); | ||
primary.start(executable, { testId }); | ||
QVERIFY(primary.waitForStarted()); | ||
QCOMPARE(primary.state(), QProcess::Running); | ||
output.clear(); | ||
ok = QTest::qWaitFor([&]() { | ||
output += primary.readAllStandardOutput(); | ||
return output == "Primary\n"; | ||
}); | ||
QVERIFY(ok); | ||
|
||
QProcess secondary; | ||
secondary.setProcessChannelMode(QProcess::ForwardedErrorChannel); | ||
secondary.start(executable, { testId, message }); | ||
QVERIFY(secondary.waitForStarted()); | ||
QCOMPARE(secondary.state(), QProcess::Running); | ||
|
||
output.clear(); | ||
ok = QTest::qWaitFor([&]() { | ||
output += secondary.readAllStandardOutput(); | ||
return output == "Secondary\n"; | ||
}); | ||
QVERIFY(ok); | ||
|
||
if (secondary.state() != QProcess::NotRunning) | ||
QVERIFY(secondary.waitForFinished()); | ||
QCOMPARE(secondary.exitCode(), 0); | ||
QCOMPARE(secondary.exitStatus(), QProcess::NormalExit); | ||
|
||
output.clear(); | ||
const QByteArray expected = "MESSAGE: >" + message.toUtf8() + "<\n"; | ||
ok = QTest::qWaitFor([&]() { | ||
output += primary.readAllStandardOutput(); | ||
return output == expected; | ||
}); | ||
QVERIFY(ok); | ||
|
||
if (primary.state() != QProcess::NotRunning) | ||
QVERIFY(primary.waitForFinished()); | ||
QCOMPARE(primary.exitCode(), 0); | ||
QCOMPARE(primary.exitStatus(), QProcess::NormalExit); | ||
} | ||
|
||
QTEST_MAIN(tst_NameLengthTest) | ||
|
||
#include "tst_namelengthtest.moc" |