File indexing completed on 2024-06-09 05:06:57

0001 /*
0002  * SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@redhat.com>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  *
0006  */
0007 
0008 #pragma once
0009 
0010 #include <QBuffer>
0011 #include <QObject>
0012 
0013 #include "private/datastream_p_p.h"
0014 #include "private/protocol_p.h"
0015 
0016 #include <type_traits>
0017 
0018 class ProtocolTest : public QObject
0019 {
0020     Q_OBJECT
0021 
0022 private Q_SLOTS:
0023     void testFactory_data();
0024     void testFactory();
0025 
0026     void testCommand();
0027     void testResponse_data();
0028     void testResponse();
0029     void testAncestor();
0030     void testFetchScope_data();
0031     void testFetchScope();
0032     void testScopeContext_data();
0033     void testScopeContext();
0034     void testPartMetaData();
0035     void testCachePolicy();
0036 
0037     void testHelloResponse();
0038     void testLoginCommand();
0039     void testLoginResponse();
0040     void testLogoutCommand();
0041     void testLogoutResponse();
0042     void testTransactionCommand();
0043     void testTransactionResponse();
0044     void testCreateItemCommand();
0045     void testCreateItemResponse();
0046     void testCopyItemsCommand();
0047     void testCopyItemsResponse();
0048 
0049 private:
0050     template<typename T>
0051     typename std::enable_if<std::is_base_of<Akonadi::Protocol::Command, T>::value, QSharedPointer<T>>::type serializeAndDeserialize(const QSharedPointer<T> &in)
0052     {
0053         QBuffer buf;
0054         buf.open(QIODevice::ReadWrite);
0055         Akonadi::Protocol::DataStream stream(&buf);
0056 
0057         Akonadi::Protocol::serialize(stream, in);
0058         stream.flush();
0059         buf.seek(0);
0060         return Akonadi::Protocol::deserialize(&buf).staticCast<T>();
0061     }
0062 
0063     template<typename T>
0064     typename std::enable_if<std::is_base_of<Akonadi::Protocol::Command, T>::value == false, T>::type serializeAndDeserialize(const T &in, int * = nullptr)
0065     {
0066         QBuffer buf;
0067         buf.open(QIODevice::ReadWrite);
0068 
0069         Akonadi::Protocol::DataStream stream(&buf);
0070         stream << in;
0071         stream.flush();
0072         buf.seek(0);
0073         T out;
0074         stream >> out;
0075 
0076         return out;
0077     }
0078 };