Changeset View
Changeset View
Standalone View
Standalone View
autotests/client/test_remote_access.cpp
Show First 20 Lines • Show All 236 Lines • ▼ Show 20 Line(s) | 233 | { | |||
---|---|---|---|---|---|
237 | QVERIFY(!m_remoteAccessInterface->isBound()); | 237 | QVERIFY(!m_remoteAccessInterface->isBound()); | ||
238 | auto *client1 = new MockupClient(this); | 238 | auto *client1 = new MockupClient(this); | ||
239 | auto *client2 = new MockupClient(this); | 239 | auto *client2 = new MockupClient(this); | ||
240 | client1->bindOutput(0); | 240 | client1->bindOutput(0); | ||
241 | client2->bindOutput(0); | 241 | client2->bindOutput(0); | ||
242 | m_display->dispatchEvents(); | 242 | m_display->dispatchEvents(); | ||
243 | QVERIFY(m_remoteAccessInterface->isBound()); // now we have 2 clients | 243 | QVERIFY(m_remoteAccessInterface->isBound()); // now we have 2 clients | ||
244 | 244 | | |||
245 | QSignalSpy bufferReadySpy1(client1->remoteAccess, &RemoteAccessManager::bufferReady); | | |||
246 | QVERIFY(bufferReadySpy1.isValid()); | | |||
247 | QSignalSpy bufferReadySpy2(client2->remoteAccess, &RemoteAccessManager::bufferReady); | | |||
248 | QVERIFY(bufferReadySpy2.isValid()); | | |||
249 | | ||||
250 | BufferHandle *buf = new BufferHandle(); | 245 | BufferHandle *buf = new BufferHandle(); | ||
251 | QTemporaryFile *tmpFile = new QTemporaryFile(this); | 246 | QTemporaryFile *tmpFile = new QTemporaryFile(this); | ||
252 | tmpFile->open(); | 247 | tmpFile->open(); | ||
253 | 248 | | |||
254 | buf->setFd(tmpFile->handle()); | 249 | buf->setFd(tmpFile->handle()); | ||
255 | buf->setSize(50, 50); | 250 | buf->setSize(50, 50); | ||
256 | buf->setFormat(100500); | 251 | buf->setFormat(100500); | ||
257 | buf->setStride(7800); | 252 | buf->setStride(7800); | ||
258 | m_remoteAccessInterface->sendBufferReady(m_outputInterface[0], buf); | | |||
259 | 253 | | |||
260 | // wait for event loop | 254 | bool buffer1ParametersReceived = false; | ||
261 | QVERIFY(bufferReadySpy1.wait()); | 255 | bool buffer2ParametersReceived = false; | ||
262 | // receive buffer at client 1 | | |||
263 | QCOMPARE(bufferReadySpy1.size(), 1); | | |||
264 | auto rbuf1 = bufferReadySpy1.takeFirst()[1].value<const RemoteBuffer *>(); | | |||
265 | QSignalSpy paramsObtainedSpy1(rbuf1, &RemoteBuffer::parametersObtained); | | |||
266 | QVERIFY(paramsObtainedSpy1.isValid()); | | |||
267 | 256 | | |||
268 | if (bufferReadySpy2.size() == 0) { | 257 | const RemoteBuffer *rbuf1 = nullptr; | ||
269 | QVERIFY(bufferReadySpy2.wait()); | 258 | const RemoteBuffer *rbuf2 = nullptr; | ||
259 | | ||||
260 | client1->connection->flush(); | ||||
261 | client2->connection->flush(); | ||||
262 | | ||||
263 | { | ||||
264 | QEventLoop e; | ||||
265 | QTimer::singleShot(1000, &e, &QEventLoop::quit); //safety timer | ||||
266 | connect(client1->remoteAccess, &RemoteAccessManager::bufferReady, [&] (const void*, const RemoteBuffer *buffer) { | ||||
267 | rbuf1 = buffer; | ||||
268 | connect(rbuf1, &RemoteBuffer::parametersObtained, [&]() { | ||||
269 | buffer1ParametersReceived = true; | ||||
270 | if (buffer1ParametersReceived && buffer2ParametersReceived) { | ||||
271 | e.quit(); | ||||
272 | } | ||||
273 | }); | ||||
274 | }); | ||||
275 | | ||||
276 | connect(client2->remoteAccess, &RemoteAccessManager::bufferReady, [&] (const void*, const RemoteBuffer *buffer) { | ||||
277 | rbuf2 = buffer; | ||||
278 | connect(rbuf2, &RemoteBuffer::parametersObtained, [&]() { | ||||
279 | buffer2ParametersReceived = true; | ||||
280 | if (buffer1ParametersReceived && buffer2ParametersReceived) { | ||||
281 | e.quit(); | ||||
270 | } | 282 | } | ||
271 | // receive buffer at client 2 | 283 | }); | ||
272 | QCOMPARE(bufferReadySpy2.size(), 1); | 284 | }); | ||
273 | auto rbuf2 = bufferReadySpy2.takeFirst()[1].value<const RemoteBuffer *>(); | 285 | m_remoteAccessInterface->sendBufferReady(m_outputInterface[0], buf); | ||
274 | QSignalSpy paramsObtainedSpy2(rbuf2, &RemoteBuffer::parametersObtained); | | |||
275 | QVERIFY(paramsObtainedSpy2.isValid()); | | |||
276 | 286 | | |||
277 | // wait for event loop | 287 | e.exec(); | ||
278 | QVERIFY(paramsObtainedSpy1.size() == 1 || paramsObtainedSpy1.wait()); | | |||
279 | QCOMPARE(paramsObtainedSpy1.size(), 1); | | |||
280 | if (paramsObtainedSpy2.size() == 0) { | | |||
281 | QVERIFY(paramsObtainedSpy2.wait()); | | |||
282 | } | 288 | } | ||
283 | QCOMPARE(paramsObtainedSpy2.size(), 1); | 289 | | ||
290 | | ||||
291 | QVERIFY(rbuf1); | ||||
292 | QVERIFY(rbuf2); | ||||
293 | QVERIFY(buffer1ParametersReceived); | ||||
294 | QVERIFY(buffer2ParametersReceived); | ||||
284 | 295 | | |||
285 | // release | 296 | // release | ||
286 | QSignalSpy bufferReleasedSpy(m_remoteAccessInterface, &RemoteAccessManagerInterface::bufferReleased); | 297 | QSignalSpy bufferReleasedSpy(m_remoteAccessInterface, &RemoteAccessManagerInterface::bufferReleased); | ||
287 | QVERIFY(bufferReleasedSpy.isValid()); | | |||
288 | delete rbuf1; | 298 | delete rbuf1; | ||
289 | QVERIFY(!bufferReleasedSpy.wait(1000)); // one client released, second still holds buffer! | 299 | QVERIFY(!bufferReleasedSpy.wait(1000)); // one client released, second still holds buffer! | ||
290 | 300 | | |||
291 | delete rbuf2; | 301 | delete rbuf2; | ||
292 | QVERIFY(bufferReleasedSpy.wait()); // all clients released, buffer should be freed | 302 | QVERIFY(bufferReleasedSpy.wait()); // all clients released, buffer should be freed | ||
293 | 303 | | |||
294 | // cleanup | 304 | // cleanup | ||
295 | delete buf; | 305 | delete buf; | ||
▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines |