summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/test/test-rockboxinfo.cpp
blob: 9d2b53b3ab67fb27419b10a195a20cb380554e15 (plain)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 *
 * Copyright (C) 2012 Dominik Riebeling
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include <QtTest/QtTest>
#include <QObject>
#include "rockboxinfo.h"


class TestRockboxInfo : public QObject
{
    Q_OBJECT
        private slots:
        void testVersion();
        void testVersion_data();
        void testMemory();
        void testMemory_data();
        void testTarget();
        void testTarget_data();
        void testFeatures();
        void testFeatures_data();
};


void TestRockboxInfo::testVersion_data()
{
    struct {
        const char* input;
        const char* revision;
        const char* version;
        const char* release;
    } const testdata[] =
    {
        /* Input string               revision    full version       release version */
        { "Version: r29629-110321",   "29629",    "r29629-110321",   "" },
        { "Version: r29629M-110321",  "29629M",   "r29629M-110321",  "" },
        { "Version: 3.10",            "",         "3.10",            "3.10" },
        { "Version:\t3.10",           "",         "3.10",            "3.10" },
        { "#Version: r29629-110321",  "",         "",                "" },
        { "Version: e5b1b0f-120218",  "e5b1b0f",  "e5b1b0f-120218",  "" },
        { "Version: e5b1b0fM-120218", "e5b1b0fM", "e5b1b0fM-120218", "" },
        { "#Version: e5b1b0f-120218", "",         "",                "" },
        { "Version: 3448f5b-120310",  "3448f5b",  "3448f5b-120310",  "" },
    };


    QTest::addColumn<QString>("input");
    QTest::addColumn<QString>("revision");
    QTest::addColumn<QString>("version");
    QTest::addColumn<QString>("release");
    unsigned int i;
    for(i = 0; i < sizeof(testdata) / sizeof(testdata[0]); i++) {
        for (size_t i = 0; i < sizeof(testdata) / sizeof(testdata[0]); i++) {
            QTest::newRow(testdata[i].input)
                << testdata[i].input << testdata[i].revision
                << testdata[i].version << testdata[i].release;
        }
    }
}


void TestRockboxInfo::testVersion()
{
    QFETCH(QString, input);
    QFETCH(QString, revision);
    QFETCH(QString, version);
    QFETCH(QString, release);
    QTemporaryFile tf(this);
    tf.open();
    QString filename = tf.fileName();
    tf.write(input.toLatin1());
    tf.write("\n");
    tf.close();

    RockboxInfo info("", filename);
    QCOMPARE(info.version(), QString(version));
    QCOMPARE(info.revision(), QString(revision));
    QCOMPARE(info.release(), QString(release));
}

void TestRockboxInfo::testTarget_data()
{
    QTest::addColumn<QString>("target");
    QTest::newRow("sansae200") << "sansae200";
    QTest::newRow("gigabeats") << "gigabeats";
    QTest::newRow("iriverh100") << "iriverh100";
    QTest::newRow("unknown") << "unknown";
}

void TestRockboxInfo::testTarget()
{
    int j;
    QStringList prefix;
    prefix << "Target: "; // << "Target:\t" << "Target:   ";
    for(j = 0; j < prefix.size(); ++j) {
        QFETCH(QString, target);
        QTemporaryFile tf(this);
        tf.open();
        QString filename = tf.fileName();
        tf.write(prefix.at(j).toLatin1());
        tf.write(target.toLatin1());
        tf.write("\n");
        tf.close();

        RockboxInfo info("", filename);
        QCOMPARE(info.target(), target);
    }
}

void TestRockboxInfo::testMemory_data()
{
    QTest::addColumn<QString>("memory");
    QTest::newRow("8") << "8";
    QTest::newRow("16") << "16";
    QTest::newRow("32") << "32";
    QTest::newRow("64") << "64";
}

void TestRockboxInfo::testMemory()
{
    int j;
    QStringList prefix;
    prefix << "Memory: " << "Memory:\t" << "Memory:   ";
    for(j = 0; j < prefix.size(); ++j) {
        QFETCH(QString, memory);
        QTemporaryFile tf(this);
        tf.open();
        QString filename = tf.fileName();
        tf.write(prefix.at(j).toLatin1());
        tf.write(memory.toLatin1());
        tf.write("\n");
        tf.close();

        RockboxInfo info("", filename);
        QCOMPARE(info.ram(), memory.toInt());
    }
}

void TestRockboxInfo::testFeatures_data()
{
    QTest::addColumn<QString>("features");
    QTest::newRow("1") << "backlight_brightness:button_light:dircache:flash_storage";
    QTest::newRow("2") << "pitchscreen:multivolume:multidrive_usb:quickscreen";
}

void TestRockboxInfo::testFeatures()
{
    int j;
    QStringList prefix;
    prefix << "Features: " << "Features:\t" << "Features:   ";
    for(j = 0; j < prefix.size(); ++j) {
        QFETCH(QString, features);
        QTemporaryFile tf(this);
        tf.open();
        QString filename = tf.fileName();
        tf.write(prefix.at(j).toLatin1());
        tf.write(features.toLatin1());
        tf.write("\n");
        tf.close();

        RockboxInfo info("", filename);
        QCOMPARE(info.features(), features);
    }
}

QTEST_MAIN(TestRockboxInfo)

// this include is needed because we don't use a separate header file for the
// test class. It also needs to be at the end.
#include "test-rockboxinfo.moc"