summary refs log tree commit diff
path: root/gnu/packages/patches/quassel-qt-514-compat.patch
blob: 7a0c42e8aa88f4d4f53f3f4880239bd57af02701 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
https://github.com/quassel/quassel/commit/579e559a6322209df7cd51c34801fecff5fe734b.patch

Based on the above patch, with some changes due to how the code has changed
in the time since 0.13.1 was released.

https://git.archlinux.org/svntogit/community.git/plain/trunk/quassel-0.13.1-qt5.14.patch?h=packages/quassel

From 579e559a6322209df7cd51c34801fecff5fe734b Mon Sep 17 00:00:00 2001
From: Manuel Nickschas <sputnick@quassel-irc.org>
Date: Tue, 7 Jan 2020 18:34:54 +0100
Subject: [PATCH] common: Disable enum type stream operators for Qt >= 5.14

Starting from version 5.14, Qt provides stream operators for enum
types, which collide with the ones we ship in types.h. Disable
Quassel's stream operators when compiling against Qt 5.14 or later.

Add a unit test that ensures that enum serialization honors the width
of the underlying type.
---
 src/common/types.h          |  2 +
 tests/common/CMakeLists.txt |  2 +
 tests/common/typestest.cpp  | 79 +++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+)
 create mode 100644 tests/common/typestest.cpp

diff --git a/src/common/types.h b/src/common/types.h
index d3742b788..e2a9aab5e 100644
--- a/src/common/types.h
+++ b/src/common/types.h
@@ -140,6 +140,7 @@ Q_DECLARE_METATYPE(QHostAddress)
 typedef QList<MsgId> MsgIdList;
 typedef QList<BufferId> BufferIdList;

+#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
 /**
   * Catch-all stream serialization operator for enum types.
   *
@@ -169,6 +170,7 @@ QDataStream &operator>>(QDataStream &in, T &value) {
     value = static_cast<T>(v);
     return in;
 }
+#endif

 // Exceptions

diff --git a/tests/common/typestest.cpp b/tests/common/typestest.cpp
new file mode 100644
index 000000000..04031c299
--- /dev/null
+++ b/tests/common/typestest.cpp
@@ -0,0 +1,79 @@
+/***************************************************************************
+ *   Copyright (C) 2005-2020 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#include <cstdint>
+
+#include <QByteArray>
+#include <QDataStream>
+#include <QObject>
+
+#include "testglobal.h"
+#include "types.h"
+
+using namespace ::testing;
+
+class EnumHolder
+{
+    Q_GADGET
+
+public:
+    enum class Enum16 : uint16_t {};
+    enum class Enum32 : uint32_t {};
+
+    enum class EnumQt16 : uint16_t {};
+    Q_ENUM(EnumQt16)
+    enum class EnumQt32 : uint32_t {};
+    Q_ENUM(EnumQt32)
+};
+
+// Verify that enums are (de)serialized as their underlying type
+TEST(TypesTest, enumSerialization)
+{
+    QByteArray data;
+    QDataStream out(&data, QIODevice::WriteOnly);
+
+    // Serialize
+    out << EnumHolder::Enum16(0xabcd);
+    ASSERT_THAT(data.size(), Eq(2));
+    out << EnumHolder::Enum32(0x123456);
+    ASSERT_THAT(data.size(), Eq(6));
+    out << EnumHolder::EnumQt16(0x4321);
+    ASSERT_THAT(data.size(), Eq(8));
+    out << EnumHolder::Enum32(0xfedcba);
+    ASSERT_THAT(data.size(), Eq(12));
+    ASSERT_THAT(out.status(), Eq(QDataStream::Status::Ok));
+
+    // Deserialize
+    QDataStream in(data);
+    EnumHolder::Enum16 enum16;
+    EnumHolder::Enum32 enum32;
+    EnumHolder::EnumQt16 enumQt16;
+    EnumHolder::EnumQt32 enumQt32;
+    in >> enum16  >> enum32 >> enumQt16 >> enumQt32;
+    ASSERT_THAT(in.status(), Eq(QDataStream::Status::Ok));
+    EXPECT_TRUE(in.atEnd());
+
+    EXPECT_THAT((int)enum16, Eq(0xabcd));
+    EXPECT_THAT((int)enum32, Eq(0x123456));
+    EXPECT_THAT((int)enumQt16, Eq(0x4321));
+    EXPECT_THAT((int)enumQt32, Eq(0xfedcba));
+}
+
+#include "typestest.moc"