Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / vcl / qt5 / tst_exclude_socket_notifiers.hxx
blob7f4d2e3d62447c17403a166d3bd2b969df68b9c5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 * This code is based on the SocketEventsTester from the Qt4 test suite.
22 #pragma once
24 #include <QtCore/QCoreApplication>
25 #include <QtCore/QEventLoop>
26 #include <QtCore/QSocketNotifier>
27 #include <unistd.h>
29 class TestExcludeSocketNotifiers : public QObject
31 Q_OBJECT
32 public:
33 TestExcludeSocketNotifiers(const int* pipes);
34 virtual ~TestExcludeSocketNotifiers() override;
35 bool received;
36 public slots:
37 void slotReceived();
39 private:
40 const int* pipes;
43 TestExcludeSocketNotifiers::TestExcludeSocketNotifiers(const int* thePipes)
44 : received(false)
45 , pipes(thePipes)
49 TestExcludeSocketNotifiers::~TestExcludeSocketNotifiers()
51 close(pipes[0]);
52 close(pipes[1]);
55 void TestExcludeSocketNotifiers::slotReceived() { received = true; }
57 #define QVERIFY(a) \
58 if (!a) \
59 return 1;
61 static int tst_processEventsExcludeSocket()
63 int pipes[2];
64 if (pipe(pipes) < 0)
65 return 1;
66 TestExcludeSocketNotifiers test(pipes);
67 QSocketNotifier notifier(pipes[0], QSocketNotifier::Read);
68 QObject::connect(&notifier, SIGNAL(activated(int)), &test, SLOT(slotReceived()));
69 char dummy = 'a';
70 if (1 != write(pipes[1], &dummy, 1))
71 return 1;
72 QEventLoop loop;
73 loop.processEvents(QEventLoop::ExcludeSocketNotifiers);
74 QVERIFY(!test.received);
75 loop.processEvents();
76 QVERIFY(test.received);
77 return 0;