File indexing completed on 2025-01-05 04:59:55

0001 /*
0002  * SPDX-FileCopyrightText: 2014 Kevin Ottens <ervin@kde.org>
0003  SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 
0007 #include <testlib/qtest_zanshin.h>
0008 
0009 #include <memory>
0010 
0011 #include "akonadi/akonaditimestampattribute.h"
0012 
0013 class AkonadiTimestampAttributeTest : public QObject
0014 {
0015     Q_OBJECT
0016 private slots:
0017     void shouldHaveDefaultState()
0018     {
0019         // GIVEN
0020         const auto timestamp = QDateTime::currentMSecsSinceEpoch();
0021         Akonadi::TimestampAttribute attr;
0022 
0023         // THEN
0024         QVERIFY(attr.timestamp() >= timestamp);
0025         QCOMPARE(attr.type(), QByteArray("ZanshinTimestamp"));
0026     }
0027 
0028     void shouldRefreshTimestamp()
0029     {
0030         // GIVEN
0031         Akonadi::TimestampAttribute attr;
0032         QTest::qWait(50);
0033         auto timestamp = QDateTime::currentMSecsSinceEpoch();
0034         QVERIFY(attr.timestamp() < timestamp);
0035 
0036         // WHEN
0037         QTest::qWait(50);
0038         attr.refreshTimestamp();
0039 
0040         // THEN
0041         QVERIFY(attr.timestamp() > timestamp);
0042     }
0043 
0044     void shouldBeCloneable()
0045     {
0046         // GIVEN
0047         Akonadi::TimestampAttribute attr;
0048 
0049         // WHEN
0050         auto clone = std::unique_ptr<Akonadi::TimestampAttribute>(attr.clone());
0051 
0052         // THEN
0053         QCOMPARE(clone->timestamp(), attr.timestamp());
0054         QCOMPARE(clone->type(), attr.type());
0055     }
0056 
0057     void shouldDeserialize()
0058     {
0059         // GIVEN
0060         Akonadi::TimestampAttribute attr;
0061 
0062         // WHEN
0063         attr.deserialize("42");
0064 
0065         // THEN
0066         QCOMPARE(attr.timestamp(), qint64(42));
0067     }
0068 
0069     void shouldSerialize()
0070     {
0071         // GIVEN
0072         Akonadi::TimestampAttribute attr;
0073 
0074         // WHEN
0075         const auto data = attr.serialized();
0076 
0077         // THEN
0078         QCOMPARE(data, QByteArray::number(attr.timestamp()));
0079     }
0080 };
0081 
0082 ZANSHIN_TEST_MAIN(AkonadiTimestampAttributeTest)
0083 
0084 #include "akonaditimestampattributetest.moc"