summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/test/test-rockboxinfo.cpp
blob: 310a0770b3b134ddfc7380f29979deb135235ea6 (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
/***************************************************************************
 *             __________               __   ___.
 *   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 testMemory();
        void testTarget();
        void testFeatures();
};


void TestRockboxInfo::testVersion()
{
    struct testvector {
        const char* versionline;
        const char* revisionstring;
        const char* versionstring;
        const char* releasestring;
    };

    const struct testvector 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", "",         "",                "" },
    };


    unsigned int i;
    for(i = 0; i < sizeof(testdata) / sizeof(struct testvector); i++) {
        QTemporaryFile tf(this);
        tf.open();
        QString filename = tf.fileName();
        tf.write(testdata[i].versionline);
        tf.write("\n");
        tf.close();

        RockboxInfo info("", filename);
        QCOMPARE(info.version(), QString(testdata[i].versionstring));
        QCOMPARE(info.revision(), QString(testdata[i].revisionstring));
        QCOMPARE(info.release(), QString(testdata[i].releasestring));
    }
}


void TestRockboxInfo::testTarget()
{
    int i, j;
    QStringList targets;
    targets << "sansae200" << "gigabeats" << "iriverh100" << "unknown";
    QStringList prefix;
    prefix << "Target: "; // << "Target:\t" << "Target:   ";
    for(j = 0; j < prefix.size(); ++j) {
        for(i = 0; i < targets.size(); i++) {
            QTemporaryFile tf(this);
            tf.open();
            QString filename = tf.fileName();
            tf.write(prefix.at(j).toLocal8Bit());
            tf.write(targets.at(i).toLocal8Bit());
            tf.write("\n");
            tf.close();

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


void TestRockboxInfo::testMemory()
{
    int i, j;
    QStringList memsizes;
    memsizes << "8" << "16" << "32" << "64";
    QStringList prefix;
    prefix << "Memory: " << "Memory:\t" << "Memory:   ";
    for(j = 0; j < prefix.size(); ++j) {
        for(i = 0; i < memsizes.size(); i++) {
            QTemporaryFile tf(this);
            tf.open();
            QString filename = tf.fileName();
            tf.write(prefix.at(j).toLocal8Bit());
            tf.write(memsizes.at(i).toLocal8Bit());
            tf.write("\n");
            tf.close();

            RockboxInfo info("", filename);
            QCOMPARE(info.ram(), memsizes.at(i).toInt());
        }
    }
}


void TestRockboxInfo::testFeatures()
{
    int i, j;
    QStringList features;
    features << "backlight_brightness:button_light:dircache:flash_storage"
             << "pitchscreen:multivolume:multidrive_usb:quickscreen";
    QStringList prefix;
    prefix << "Features: " << "Features:\t" << "Features:   ";
    for(j = 0; j < prefix.size(); ++j) {
        for(i = 0; i < features.size(); i++) {
            QTemporaryFile tf(this);
            tf.open();
            QString filename = tf.fileName();
            tf.write(prefix.at(j).toLocal8Bit());
            tf.write(features.at(i).toLocal8Bit());
            tf.write("\n");
            tf.close();

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

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"