File: UtilsTest.cpp

package info (click to toggle)
kdb 3.2.0-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,276 kB
  • sloc: cpp: 38,360; yacc: 940; python: 779; sh: 711; ansic: 440; lex: 367; xml: 182; sql: 51; makefile: 10
file content (163 lines) | stat: -rw-r--r-- 6,558 bytes parent folder | download | duplicates (4)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* This file is part of the KDE project
   Copyright (C) 2019 Jarosław Staniek <staniek@kde.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include <KDb>

#include <QObject>
#include <QTest>

//! Autotests for KDbUtils.cpp
class UtilsTest : public QObject
{
    Q_OBJECT
private Q_SLOTS:
    void initTestCase();

//TODO:
//    namespace KDbUtils
//    {
//    KDB_EXPORT bool hasParent(QObject* par, QObject* o);
//    template<class type>
//    inline type findParent(QObject* o, const char* className = nullptr)

    //! QString toISODateStringWithMs(const QTime& time);
    //! QString toISODateStringWithMs(const QDateTime& dateTime);
    void testTimeToISODateStringAndFromStringWithMs_data();
    void testTimeToISODateStringAndFromStringWithMs();

    //! QTime timeFromISODateStringWithMs(const QString& string);
    //! QDateTime dateTimeFromISODateStringWithMs(const QString& string);
    void testDateTimeToISODateStringAndFromStringWithMs_data();
    void testDateTimeToISODateStringAndFromStringWithMs();

//    KDB_EXPORT QDateTime stringToHackedQTime(const QString& s);
//    KDB_EXPORT void serializeMap(const QMap<QString, QString>& map, QByteArray *array);
//    KDB_EXPORT void serializeMap(const QMap<QString, QString>& map, QString *string);
//    KDB_EXPORT QMap<QString, QString> deserializeMap(const QByteArray& array);
//    KDB_EXPORT QMap<QString, QString> deserializeMap(const QString& string);
//    KDB_EXPORT QString stringToFileName(const QString& string);
//    KDB_EXPORT void simpleCrypt(QString *string);
//    KDB_EXPORT bool simpleDecrypt(QString *string);
//    KDB_EXPORT QString pointerToStringInternal(void* pointer, int size);
//    KDB_EXPORT void* stringToPointerInternal(const QString& string, int size);
//    template<class type>
//    QString pointerToString(type *pointer);
//    template<class type>
//    type* stringToPointer(const QString& string);
//    KDB_EXPORT QVariant squeezedValue(const QVariant &value);
//    template <class Key, class T>
//    class AutodeletedHash : public QHash<Key, T>;
//    template <typename T>
//    class AutodeletedList : public QList<T>;
//    template <typename Key, typename T>
//    class CaseInsensitiveHash : public QHash<Key, T>;
//    template <typename T>
//    QString debugString(const T& object)
//    QString findExe(const QString& appname,
//                    const QString& path = QString(),
//                    FindExeOptions options = FindExeOption::None);
//    class KDB_EXPORT Property {
//    public:
//        Property();
//        Property(const QVariant &aValue, const QString &aCaption);
//        Property(const Property &other);
//        bool operator==(const Property &other) const;
//        bool operator!=(const Property &other) const { return !operator==(other); }
//        bool isNull() const;
//        QVariant value() const;
//        void setValue(const QVariant &value);
//        QString caption() const;
//        void setCaption(const QString &caption);
//    };
//    class KDB_EXPORT PropertySet
//    {
//    public:
//        PropertySet();
//        PropertySet(const PropertySet &other);
//        PropertySet& operator=(const PropertySet &other);
//        bool operator==(const PropertySet &other) const;
//        bool operator!=(const PropertySet &other) const { return !operator==(other); }
//        void insert(const QByteArray &name, const QVariant &value, const QString &caption = QString());
//        void setCaption(const QByteArray &name, const QString &caption);
//        void setValue(const QByteArray &name, const QVariant &value);
//        void remove(const QByteArray &name);
//        Property property(const QByteArray &name) const;
//        QList<QByteArray> names() const;
//    };

    void cleanupTestCase();
};

QTEST_GUILESS_MAIN(UtilsTest)

void UtilsTest::initTestCase()
{
}

void UtilsTest::testTimeToISODateStringAndFromStringWithMs_data()
{
    QTest::addColumn<QTime>("time");
    QTest::addColumn<QString>("string");

    QTest::newRow("null") << QTime() << "";
    QTest::newRow("invalid") << QTime(27, 1, 1) << "";
    QTest::newRow("valid1") << QTime(21, 12, 13, 1) << "21:12:13.001";
    QTest::newRow("valid2") << QTime(0, 0, 1, 81) << "00:00:01.081";
    QTest::newRow("valid3") << QTime(21, 12, 13, 981) << "21:12:13.981";
    QTest::newRow("valid4") << QTime(21, 12, 13) << "21:12:13.000";
}

void UtilsTest::testTimeToISODateStringAndFromStringWithMs()
{
    QFETCH(QTime, time);
    QFETCH(QString, string);

    qDebug() << string << time;
    QCOMPARE(KDbUtils::toISODateStringWithMs(time), string);
    QCOMPARE(KDbUtils::timeFromISODateStringWithMs(string), time);
}

void UtilsTest::testDateTimeToISODateStringAndFromStringWithMs_data()
{
    QTest::addColumn<QDateTime>("dateTime");
    QTest::addColumn<QString>("string");

    QTest::newRow("null") << QDateTime() << "";
    QTest::newRow("invalid") << QDateTime(QDate(0, 1, 1), QTime(27, 1, 1)) << "";
    QTest::newRow("valid1") << QDateTime(QDate(1999, 12, 4), QTime(21, 12, 13, 1)) << "1999-12-04T21:12:13.001";
    QTest::newRow("valid2") << QDateTime(QDate(1999, 12, 4), QTime(0, 0, 1, 81)) << "1999-12-04T00:00:01.081";
    QTest::newRow("valid3") << QDateTime(QDate(1999, 12, 4), QTime(21, 12, 13, 981)) << "1999-12-04T21:12:13.981";
    QTest::newRow("valid4") << QDateTime(QDate(1999, 12, 4), QTime(21, 12, 13)) << "1999-12-04T21:12:13.000";
}

void UtilsTest::testDateTimeToISODateStringAndFromStringWithMs()
{
    QFETCH(QDateTime, dateTime);
    QFETCH(QString, string);

    qDebug() << string << dateTime << KDbUtils::dateTimeFromISODateStringWithMs(string);
    QCOMPARE(KDbUtils::toISODateStringWithMs(dateTime), string);
    QCOMPARE(KDbUtils::dateTimeFromISODateStringWithMs(string), dateTime);
}

void UtilsTest::cleanupTestCase()
{
}

#include "UtilsTest.moc"