From 48dc52a0da31d6b3105a737073c85ef73230d254 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 6 Nov 2017 16:26:34 +0100 Subject: [PATCH] Add an integration test for unix sockets Signed-off-by: Uli Schlachter --- test/integration/main.cpp | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/integration/main.cpp b/test/integration/main.cpp index f5edf19b..ee65d449 100644 --- a/test/integration/main.cpp +++ b/test/integration/main.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -151,6 +152,7 @@ class IO { // Need to flush QTcpSocket, and QIODevice doesn't have flush at all... static void FlushIfCan(QIODevice*) {} static void FlushIfCan(QTcpSocket* sock) { sock->flush(); } + static void FlushIfCan(QLocalSocket* sock) { sock->flush(); } Device* m_device; bool m_verbose; @@ -901,4 +903,44 @@ TEST_F(ZNCTest, ModuleCrypt) { Z; } +TEST(UnixSocketTest, Connect) { + // Create a config + QTemporaryDir tempDir; + QDir dir(tempDir.path()); + QString socketName = dir.filePath("socket"); + dir.mkdir("configs"); + QFile config(dir.filePath("configs/znc.conf")); + ASSERT_TRUE(config.open(QIODevice::WriteOnly | QIODevice::Text)); + Z; + + QTextStream out(&config); + // FIXME: Hardcoding a version is bad + out << "Version = 1.7.x\n\nPath = "; + out << socketName; + out << "\nSSL = false\n\n"; + out << "\nPass = test\nAdmin = true\n\n"; + config.close(); + Z; + + // Start znc + Process p(ZNC_BIN_DIR "/znc", QStringList() << "--debug" + << "--datadir" << dir.path()); + p.ReadUntil("https://znc.in"); + Z; + + // Connect to it and log in + QLocalSocket socket; + socket.connectToServer(socketName); + ASSERT_TRUE(socket.waitForConnected()) + << socket.errorString().toStdString(); + Z; + + auto wrapper = IO(&socket, true); + wrapper.Write("PASS :test:test"); + wrapper.Write("NICK test"); + wrapper.Write("USER user/test x x :x"); + Z; + wrapper.ReadUntil("Welcome to ZNC"); +} + } // namespace