| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "mock_i3ipc.h" | ||
| 2 | #include "data/i3_messages.h" | ||
| 3 | |||
| 4 |
3/8✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→8) not taken.
✓ Branch 2 (4→5) taken 1 times.
✗ Branch 3 (4→8) not taken.
✓ Branch 4 (5→6) taken 1 times.
✗ Branch 5 (5→10) not taken.
✗ Branch 6 (10→11) not taken.
✗ Branch 7 (10→12) not taken.
|
1 | Q_LOGGING_CATEGORY(MockI3ServerLogger, "qi3pc.test.i3wm.mock", QtMsgType::QtDebugMsg); |
| 5 | |||
| 6 | 1 | MockI3Server::MockI3Server(const QString& socketPath, QObject* parent) | |
| 7 | 1 | : QLocalServer(parent), m_socketPath(socketPath) | |
| 8 | { | ||
| 9 |
3/6✓ Branch 0 (6→7) taken 1 times.
✗ Branch 1 (6→17) not taken.
✓ Branch 2 (7→8) taken 1 times.
✗ Branch 3 (7→15) not taken.
✓ Branch 4 (8→9) taken 1 times.
✗ Branch 5 (8→15) not taken.
|
1 | qDebug(MockI3ServerLogger) << "Creating mock i3wm server reachable at" << socketPath; |
| 10 |
1/2✓ Branch 0 (10→11) taken 1 times.
✗ Branch 1 (10→19) not taken.
|
1 | connect(this, &QLocalServer::newConnection, this, &MockI3Server::handleNewConnection); |
| 11 |
1/2✓ Branch 0 (12→13) taken 1 times.
✗ Branch 1 (12→21) not taken.
|
1 | QFile::remove(m_socketPath); |
| 12 |
1/2✓ Branch 0 (13→14) taken 1 times.
✗ Branch 1 (13→21) not taken.
|
1 | listen(m_socketPath); |
| 13 | 1 | } | |
| 14 | |||
| 15 | void | ||
| 16 | 20 | MockI3Server::handleNewConnection() | |
| 17 | { | ||
| 18 |
1/2✓ Branch 0 (2→3) taken 20 times.
✗ Branch 1 (2→29) not taken.
|
20 | auto socket = nextPendingConnection(); |
| 19 |
1/2✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→9) taken 20 times.
|
20 | if (socket == nullptr) { |
| 20 | ✗ | qWarning(MockI3ServerLogger) << "New connection returned a nullptr client!"; | |
| 21 | ✗ | return; | |
| 22 | } | ||
| 23 | |||
| 24 |
1/2✓ Branch 0 (9→10) taken 20 times.
✗ Branch 1 (9→29) not taken.
|
20 | m_clients.push_back(socket); |
| 25 | |||
| 26 | ✗ | auto connection = connect(socket, &QLocalSocket::readyRead, this, [this, socket]() { | |
| 27 | 10 | handleClientMessage(socket); | |
| 28 |
1/2✓ Branch 0 (10→11) taken 20 times.
✗ Branch 1 (10→22) not taken.
|
20 | }); |
| 29 | |||
| 30 |
2/4✓ Branch 0 (11→12) taken 20 times.
✗ Branch 1 (11→25) not taken.
✓ Branch 2 (12→13) taken 20 times.
✗ Branch 3 (12→23) not taken.
|
20 | connect(socket, &QLocalSocket::disconnected, this, [this, socket, connection]() { |
| 31 | 20 | disconnect(connection); | |
| 32 | 20 | std::erase(m_clients, socket); | |
| 33 | 20 | }); | |
| 34 | 20 | } | |
| 35 | |||
| 36 | void | ||
| 37 | 10 | MockI3Server::handleClientMessage(QLocalSocket* socket) | |
| 38 | { | ||
| 39 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→14) taken 10 times.
|
10 | if (socket == nullptr) { |
| 40 | ✗ | qCWarning(MockI3ServerLogger) << "Can't read message from nullptr socket."; | |
| 41 | ✗ | return; | |
| 42 | } | ||
| 43 | |||
| 44 | char c[qi3pc::IpcMagicLength]; | ||
| 45 |
1/2✓ Branch 0 (14→15) taken 10 times.
✗ Branch 1 (14→155) not taken.
|
10 | socket->read(c, qi3pc::IpcMagicLength); |
| 46 |
2/4✓ Branch 0 (17→18) taken 10 times.
✗ Branch 1 (17→125) not taken.
✗ Branch 2 (20→21) not taken.
✓ Branch 3 (20→36) taken 10 times.
|
20 | if (auto s = std::string(c); s != qi3pc::IpcMagicString) { |
| 47 | ✗ | qCWarning(MockI3ServerLogger) << "Unexpected magic string in message. Expected" | |
| 48 | ✗ | << qi3pc::IpcMagicString << ". - Found" << s << "."; | |
| 49 | ✗ | return; | |
| 50 |
1/2✓ Branch 0 (38→39) taken 10 times.
✗ Branch 1 (38→41) not taken.
|
10 | } |
| 51 | |||
| 52 | quint32 size; | ||
| 53 |
2/4✓ Branch 0 (40→42) taken 10 times.
✗ Branch 1 (40→155) not taken.
✗ Branch 2 (42→43) not taken.
✓ Branch 3 (42→58) taken 10 times.
|
10 | if (auto read_size = socket->read(reinterpret_cast<char*>(&size), sizeof size); |
| 54 | read_size != sizeof size) { | ||
| 55 | ✗ | qCWarning(MockI3ServerLogger) << "Insufficient data read for message size. Seeked" | |
| 56 | ✗ | << sizeof size <<"bytes. - Read" << read_size << "bytes."; | |
| 57 | ✗ | return; | |
| 58 | } | ||
| 59 | |||
| 60 | quint32 type; | ||
| 61 |
2/4✓ Branch 0 (58→59) taken 10 times.
✗ Branch 1 (58→155) not taken.
✗ Branch 2 (59→60) not taken.
✓ Branch 3 (59→75) taken 10 times.
|
10 | if (auto read_size = socket->read(reinterpret_cast<char*>(&type), sizeof type); |
| 62 | read_size != sizeof type) { | ||
| 63 | ✗ | qCWarning(MockI3ServerLogger) << "Insufficient data read for message type. Seeked" | |
| 64 | ✗ | << sizeof type <<"bytes. - Read" << read_size << "bytes."; | |
| 65 | ✗ | return; | |
| 66 | } | ||
| 67 | |||
| 68 |
1/2✓ Branch 0 (75→76) taken 10 times.
✗ Branch 1 (75→155) not taken.
|
10 | QByteArray bytes = socket->read(size); |
| 69 |
1/2✓ Branch 0 (76→77) taken 10 times.
✗ Branch 1 (76→153) not taken.
|
10 | QJsonDocument json = QJsonDocument::fromJson(bytes); |
| 70 | |||
| 71 |
2/4✓ Branch 0 (77→78) taken 10 times.
✗ Branch 1 (77→151) not taken.
✗ Branch 2 (78→79) not taken.
✓ Branch 3 (78→80) taken 10 times.
|
10 | if(socket->bytesAvailable() > 0) { |
| 72 | ✗ | emit socket->readyRead(); | |
| 73 | } | ||
| 74 | |||
| 75 |
9/14✗ Branch 0 (80→81) not taken.
✓ Branch 1 (80→82) taken 1 times.
✗ Branch 2 (80→84) not taken.
✓ Branch 3 (80→85) taken 1 times.
✓ Branch 4 (80→87) taken 1 times.
✓ Branch 5 (80→89) taken 1 times.
✓ Branch 6 (80→91) taken 2 times.
✓ Branch 7 (80→93) taken 1 times.
✓ Branch 8 (80→95) taken 1 times.
✓ Branch 9 (80→97) taken 1 times.
✗ Branch 10 (80→99) not taken.
✗ Branch 11 (80→100) not taken.
✓ Branch 12 (80→101) taken 1 times.
✗ Branch 13 (80→103) not taken.
|
10 | switch(static_cast<qi3pc::IpcType>(type)) { |
| 76 | ✗ | case qi3pc::IpcType::Command: | |
| 77 | ✗ | break; | |
| 78 | 1 | case qi3pc::IpcType::Workspaces: | |
| 79 |
1/2✓ Branch 0 (82→83) taken 1 times.
✗ Branch 1 (82→151) not taken.
|
1 | send(socket, test_qi3pc::data::i3messages::workspaces, qi3pc::IpcType::Workspaces); |
| 80 | 1 | break; | |
| 81 | ✗ | case qi3pc::IpcType::Subscribe: | |
| 82 | ✗ | break; | |
| 83 | 1 | case qi3pc::IpcType::Outputs: | |
| 84 |
1/2✓ Branch 0 (85→86) taken 1 times.
✗ Branch 1 (85→151) not taken.
|
1 | send(socket, test_qi3pc::data::i3messages::outputs, qi3pc::IpcType::Outputs); |
| 85 | 1 | break; | |
| 86 | 1 | case qi3pc::IpcType::Tree: | |
| 87 |
1/2✓ Branch 0 (87→88) taken 1 times.
✗ Branch 1 (87→151) not taken.
|
1 | send(socket, test_qi3pc::data::i3messages::tree, qi3pc::IpcType::Tree); |
| 88 | 1 | break; | |
| 89 | 1 | case qi3pc::IpcType::Marks: | |
| 90 |
1/2✓ Branch 0 (89→90) taken 1 times.
✗ Branch 1 (89→151) not taken.
|
1 | send(socket, test_qi3pc::data::i3messages::marks, qi3pc::IpcType::Marks); |
| 91 | 1 | break; | |
| 92 | 2 | case qi3pc::IpcType::BarConfig: | |
| 93 |
1/2✓ Branch 0 (91→92) taken 2 times.
✗ Branch 1 (91→151) not taken.
|
2 | sendBarConfigReply(socket, bytes); |
| 94 | 2 | break; | |
| 95 | 1 | case qi3pc::IpcType::Version: | |
| 96 |
1/2✓ Branch 0 (93→94) taken 1 times.
✗ Branch 1 (93→151) not taken.
|
1 | send(socket, test_qi3pc::data::i3messages::version, qi3pc::IpcType::Version); |
| 97 | 1 | break; | |
| 98 | 1 | case qi3pc::IpcType::BindingModes: | |
| 99 |
1/2✓ Branch 0 (95→96) taken 1 times.
✗ Branch 1 (95→151) not taken.
|
1 | send(socket, test_qi3pc::data::i3messages::bindingModes, qi3pc::IpcType::BindingModes); |
| 100 | 1 | break; | |
| 101 | 1 | case qi3pc::IpcType::Config: | |
| 102 |
1/2✓ Branch 0 (97→98) taken 1 times.
✗ Branch 1 (97→151) not taken.
|
1 | send(socket, test_qi3pc::data::i3messages::config, qi3pc::IpcType::Config); |
| 103 | 1 | break; | |
| 104 | ✗ | case qi3pc::IpcType::Tick: | |
| 105 | ✗ | break; | |
| 106 | ✗ | case qi3pc::IpcType::Sync: | |
| 107 | ✗ | break; | |
| 108 | 1 | case qi3pc::IpcType::BindingState: | |
| 109 |
1/2✓ Branch 0 (101→102) taken 1 times.
✗ Branch 1 (101→151) not taken.
|
1 | send(socket, test_qi3pc::data::i3messages::bindingState, qi3pc::IpcType::BindingState); |
| 110 | 1 | break; | |
| 111 | ✗ | default: | |
| 112 | ✗ | qCWarning(MockI3ServerLogger) << "Received message of unknown type:" << type; | |
| 113 | ✗ | break; | |
| 114 | } | ||
| 115 | 10 | } | |
| 116 | |||
| 117 | qsizetype | ||
| 118 | 50 | MockI3Server::clientCount() | |
| 119 | { | ||
| 120 | 50 | return m_clients.size(); | |
| 121 | } | ||
| 122 | |||
| 123 | void | ||
| 124 | 10 | MockI3Server::send(QLocalSocket* socket, const QByteArray& payload, qi3pc::IpcType type) | |
| 125 | { | ||
| 126 | 10 | QByteArray message; | |
| 127 |
1/2✓ Branch 0 (3→4) taken 10 times.
✗ Branch 1 (3→16) not taken.
|
10 | QDataStream stream(&message, QIODevice::WriteOnly); |
| 128 |
1/2✓ Branch 0 (5→6) taken 10 times.
✗ Branch 1 (5→17) not taken.
|
10 | stream.writeRawData(qi3pc::IpcMagicString.data(), qi3pc::IpcMagicLength); |
| 129 | |||
| 130 | 10 | qint32 size = payload.size(); | |
| 131 |
1/2✓ Branch 0 (7→8) taken 10 times.
✗ Branch 1 (7→17) not taken.
|
10 | stream.writeRawData(reinterpret_cast<const char*>(&size), sizeof size); |
| 132 |
1/2✓ Branch 0 (8→9) taken 10 times.
✗ Branch 1 (8→17) not taken.
|
10 | stream.writeRawData(reinterpret_cast<const char*>(&type), sizeof type); |
| 133 | |||
| 134 |
1/2✓ Branch 0 (9→10) taken 10 times.
✗ Branch 1 (9→12) not taken.
|
10 | if (size > 0) { |
| 135 |
1/2✓ Branch 0 (11→12) taken 10 times.
✗ Branch 1 (11→17) not taken.
|
10 | stream.writeRawData(payload.constData(), size); |
| 136 | } | ||
| 137 | |||
| 138 |
1/2✓ Branch 0 (12→13) taken 10 times.
✗ Branch 1 (12→17) not taken.
|
10 | socket->write(message); |
| 139 | 10 | } | |
| 140 | |||
| 141 | void | ||
| 142 | 2 | MockI3Server::sendBarConfigReply(QLocalSocket* socket, const QByteArray& message) | |
| 143 | { | ||
| 144 |
2/2✓ Branch 0 (3→4) taken 1 times.
✓ Branch 1 (3→8) taken 1 times.
|
2 | if (message.isEmpty()) { |
| 145 |
2/4✓ Branch 0 (4→5) taken 1 times.
✗ Branch 1 (4→20) not taken.
✓ Branch 2 (5→6) taken 1 times.
✗ Branch 3 (5→18) not taken.
|
1 | send(socket, test_qi3pc::data::i3messages::barIds(), qi3pc::IpcType::BarConfig); |
| 146 | } else { | ||
| 147 | 1 | auto configs = test_qi3pc::data::i3messages::barConfigs; | |
| 148 |
3/6✓ Branch 0 (9→10) taken 1 times.
✗ Branch 1 (9→23) not taken.
✓ Branch 2 (10→11) taken 1 times.
✗ Branch 3 (10→21) not taken.
✓ Branch 4 (11→12) taken 1 times.
✗ Branch 5 (11→14) not taken.
|
1 | if(auto id = QString::fromUtf8(message); configs.contains(id)) { |
| 149 |
2/4✓ Branch 0 (12→13) taken 1 times.
✗ Branch 1 (12→21) not taken.
✓ Branch 2 (13→14) taken 1 times.
✗ Branch 3 (13→21) not taken.
|
1 | send(socket, configs[id], qi3pc::IpcType::BarConfig); |
| 150 | 1 | } | |
| 151 | 1 | } | |
| 152 | 2 | } | |
| 153 |