quassel-0.13.1-qt5.14.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. commit c90702bdbc43fc542d7df6d5ec4b321912ca0035
  2. Author: Manuel Nickschas <sputnick@quassel-irc.org>
  3. Date: Tue Jan 7 18:34:54 2020 +0100
  4. common: Disable enum type stream operators for Qt >= 5.14
  5. Starting from version 5.14, Qt provides stream operators for enum
  6. types, which collide with the ones we ship in types.h. Disable
  7. Quassel's stream operators when compiling against Qt 5.14 or later.
  8. Add a unit test that ensures that enum serialization honors the width
  9. of the underlying type.
  10. diff --git a/src/common/types.h b/src/common/types.h
  11. index 467d9fb2..c4b9f364 100644
  12. --- a/src/common/types.h
  13. +++ b/src/common/types.h
  14. @@ -140,6 +140,7 @@ Q_DECLARE_METATYPE(QHostAddress)
  15. typedef QList<MsgId> MsgIdList;
  16. typedef QList<BufferId> BufferIdList;
  17. +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
  18. /**
  19. * Catch-all stream serialization operator for enum types.
  20. *
  21. @@ -169,6 +170,7 @@ QDataStream &operator>>(QDataStream &in, T &value) {
  22. value = static_cast<T>(v);
  23. return in;
  24. }
  25. +#endif
  26. // Exceptions
  27. diff --git a/src/common/typestest.cpp b/src/common/typestest.cpp
  28. new file mode 100644
  29. index 00000000..04031c29
  30. --- /dev/null
  31. +++ b/src/common/typestest.cpp
  32. @@ -0,0 +1,79 @@
  33. +/***************************************************************************
  34. + * Copyright (C) 2005-2020 by the Quassel Project *
  35. + * devel@quassel-irc.org *
  36. + * *
  37. + * This program is free software; you can redistribute it and/or modify *
  38. + * it under the terms of the GNU General Public License as published by *
  39. + * the Free Software Foundation; either version 2 of the License, or *
  40. + * (at your option) version 3. *
  41. + * *
  42. + * This program is distributed in the hope that it will be useful, *
  43. + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  44. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  45. + * GNU General Public License for more details. *
  46. + * *
  47. + * You should have received a copy of the GNU General Public License *
  48. + * along with this program; if not, write to the *
  49. + * Free Software Foundation, Inc., *
  50. + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
  51. + ***************************************************************************/
  52. +
  53. +#include <cstdint>
  54. +
  55. +#include <QByteArray>
  56. +#include <QDataStream>
  57. +#include <QObject>
  58. +
  59. +#include "testglobal.h"
  60. +#include "types.h"
  61. +
  62. +using namespace ::testing;
  63. +
  64. +class EnumHolder
  65. +{
  66. + Q_GADGET
  67. +
  68. +public:
  69. + enum class Enum16 : uint16_t {};
  70. + enum class Enum32 : uint32_t {};
  71. +
  72. + enum class EnumQt16 : uint16_t {};
  73. + Q_ENUM(EnumQt16)
  74. + enum class EnumQt32 : uint32_t {};
  75. + Q_ENUM(EnumQt32)
  76. +};
  77. +
  78. +// Verify that enums are (de)serialized as their underlying type
  79. +TEST(TypesTest, enumSerialization)
  80. +{
  81. + QByteArray data;
  82. + QDataStream out(&data, QIODevice::WriteOnly);
  83. +
  84. + // Serialize
  85. + out << EnumHolder::Enum16(0xabcd);
  86. + ASSERT_THAT(data.size(), Eq(2));
  87. + out << EnumHolder::Enum32(0x123456);
  88. + ASSERT_THAT(data.size(), Eq(6));
  89. + out << EnumHolder::EnumQt16(0x4321);
  90. + ASSERT_THAT(data.size(), Eq(8));
  91. + out << EnumHolder::Enum32(0xfedcba);
  92. + ASSERT_THAT(data.size(), Eq(12));
  93. + ASSERT_THAT(out.status(), Eq(QDataStream::Status::Ok));
  94. +
  95. + // Deserialize
  96. + QDataStream in(data);
  97. + EnumHolder::Enum16 enum16;
  98. + EnumHolder::Enum32 enum32;
  99. + EnumHolder::EnumQt16 enumQt16;
  100. + EnumHolder::EnumQt32 enumQt32;
  101. + in >> enum16 >> enum32 >> enumQt16 >> enumQt32;
  102. + ASSERT_THAT(in.status(), Eq(QDataStream::Status::Ok));
  103. + EXPECT_TRUE(in.atEnd());
  104. +
  105. + EXPECT_THAT((int)enum16, Eq(0xabcd));
  106. + EXPECT_THAT((int)enum32, Eq(0x123456));
  107. + EXPECT_THAT((int)enumQt16, Eq(0x4321));
  108. + EXPECT_THAT((int)enumQt32, Eq(0xfedcba));
  109. +}
  110. +
  111. +#include "typestest.moc"