1 /***************************************************************************
2 * Copyright (C) 2005-2020 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
24 #include <QDataStream>
27 #include "testglobal.h"
30 using namespace ::testing;
37 enum class Enum16 : uint16_t {};
38 enum class Enum32 : uint32_t {};
40 enum class EnumQt16 : uint16_t {};
42 enum class EnumQt32 : uint32_t {};
46 // Verify that enums are (de)serialized as their underlying type
47 TEST(TypesTest, enumSerialization)
50 QDataStream out(&data, QIODevice::WriteOnly);
53 out << EnumHolder::Enum16(0xabcd);
54 ASSERT_THAT(data.size(), Eq(2));
55 out << EnumHolder::Enum32(0x123456);
56 ASSERT_THAT(data.size(), Eq(6));
57 out << EnumHolder::EnumQt16(0x4321);
58 ASSERT_THAT(data.size(), Eq(8));
59 out << EnumHolder::Enum32(0xfedcba);
60 ASSERT_THAT(data.size(), Eq(12));
61 ASSERT_THAT(out.status(), Eq(QDataStream::Status::Ok));
65 EnumHolder::Enum16 enum16;
66 EnumHolder::Enum32 enum32;
67 EnumHolder::EnumQt16 enumQt16;
68 EnumHolder::EnumQt32 enumQt32;
69 in >> enum16 >> enum32 >> enumQt16 >> enumQt32;
70 ASSERT_THAT(in.status(), Eq(QDataStream::Status::Ok));
71 EXPECT_TRUE(in.atEnd());
73 EXPECT_THAT((int)enum16, Eq(0xabcd));
74 EXPECT_THAT((int)enum32, Eq(0x123456));
75 EXPECT_THAT((int)enumQt16, Eq(0x4321));
76 EXPECT_THAT((int)enumQt32, Eq(0xfedcba));
79 #include "typestest.moc"