~ubuntu-branches/ubuntu/vivid/kdesdk/vivid

« back to all changes in this revision

Viewing changes to okteta/kasten/controllers/test/osdparsertest.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-06-06 11:49:54 UTC
  • mfrom: (0.4.21)
  • Revision ID: package-import@ubuntu.com-20120606114954-rdls73fzlpzxglbx
Tags: 4:4.8.80-0ubuntu1
* New uptream beta release
* Update dont_export_private_classes.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
*/
20
20
 
21
21
 
22
 
#undef QT_NO_CAST_FROM_ASCII //being lazy
23
 
 
24
22
#include <QtTest>
25
23
#include <QtCore/QString>
26
24
#include <QtCore/QDate>
31
29
class OsdParserTest : public QObject
32
30
{
33
31
    Q_OBJECT
34
 
public:
35
32
private Q_SLOTS:
36
33
    void testPrimitive();
37
34
    void testPrimitive_data();
38
35
};
39
36
 
 
37
namespace {
 
38
        inline QString arg(const QString& str, const char* argument) {
 
39
                return str.arg(QLatin1String(argument));
 
40
        }
 
41
}
40
42
void OsdParserTest::testPrimitive_data()
41
43
{
42
44
    QTest::addColumn<QString>("xml");
43
45
    QTest::addColumn<QString>("secondXml");
44
46
    QTest::addColumn<int>("expectedType");
45
 
    QString base ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><data><primitive name=\"foo\" type=\"%1\" /></data>");
46
 
    QTest::newRow("uint8") << base.arg("uint8") << base.arg("UInt8") << (int)Type_UInt8;
47
 
    QTest::newRow("uint16") << base.arg("uint16") << base.arg("UInt16") << (int)Type_UInt16;
48
 
    QTest::newRow("uint32") << base.arg("uint32") << base.arg("UInt32") << (int)Type_UInt32;
49
 
    QTest::newRow("uint64") << base.arg("uint64") << base.arg("UInt64") << (int)Type_UInt64;
50
 
    QTest::newRow("int8") << base.arg("int8") << base.arg("Int8") << (int)Type_Int8;
51
 
    QTest::newRow("int16") << base.arg("int16") << base.arg("Int16") << (int)Type_Int16;
52
 
    QTest::newRow("int32") << base.arg("int32") << base.arg("Int32") << (int)Type_Int32;
53
 
    QTest::newRow("int64") << base.arg("int64") << base.arg("Int64") << (int)Type_Int64;
54
 
    QTest::newRow("bool8") << base.arg("bool8") << base.arg("Bool8") << (int)Type_Bool8;
55
 
    QTest::newRow("bool16") << base.arg("bool16") << base.arg("Bool16") << (int)Type_Bool16;
56
 
    QTest::newRow("bool32") << base.arg("bool32") << base.arg("Bool32") << (int)Type_Bool32;
57
 
    QTest::newRow("bool64") << base.arg("bool64") << base.arg("Bool64") << (int)Type_Bool64;
58
 
    QTest::newRow("char") << base.arg("char") << base.arg("Char") << (int)Type_Char;
59
 
    QTest::newRow("float") << base.arg("float") << base.arg("Float") << (int)Type_Float;
60
 
    QTest::newRow("double") << base.arg("double") << base.arg("Double") << (int)Type_Double;
 
47
    QString base(QLatin1String("<?xml version=\"1.0\" encoding=\"UTF-8\"?><data><primitive name=\"foo\" type=\"%1\" /></data>"));
 
48
    QTest::newRow("uint8") << arg(base, "uint8") << arg(base, "UInt8") << (int)Type_UInt8;
 
49
    QTest::newRow("uint16") << arg(base, "uint16") << arg(base, "UInt16") << (int)Type_UInt16;
 
50
    QTest::newRow("uint32") << arg(base, "uint32") << arg(base, "UInt32") << (int)Type_UInt32;
 
51
    QTest::newRow("uint64") << arg(base, "uint64") << arg(base, "UInt64") << (int)Type_UInt64;
 
52
    QTest::newRow("int8") << arg(base, "int8") << arg(base, "Int8") << (int)Type_Int8;
 
53
    QTest::newRow("int16") << arg(base, "int16") << arg(base, "Int16") << (int)Type_Int16;
 
54
    QTest::newRow("int32") << arg(base, "int32") << arg(base, "Int32") << (int)Type_Int32;
 
55
    QTest::newRow("int64") << arg(base, "int64") << arg(base, "Int64") << (int)Type_Int64;
 
56
    QTest::newRow("bool8") << arg(base, "bool8") << arg(base, "Bool8") << (int)Type_Bool8;
 
57
    QTest::newRow("bool16") << arg(base, "bool16") << arg(base, "Bool16") << (int)Type_Bool16;
 
58
    QTest::newRow("bool32") << arg(base, "bool32") << arg(base, "Bool32") << (int)Type_Bool32;
 
59
    QTest::newRow("bool64") << arg(base, "bool64") << arg(base, "Bool64") << (int)Type_Bool64;
 
60
    QTest::newRow("char") << arg(base, "char") << arg(base, "Char") << (int)Type_Char;
 
61
    QTest::newRow("float") << arg(base, "float") << arg(base, "Float") << (int)Type_Float;
 
62
    QTest::newRow("double") << arg(base, "double") << arg(base, "Double") << (int)Type_Double;
61
63
}
62
64
 
63
65
void OsdParserTest::testPrimitive()
65
67
    QFETCH(QString, xml);
66
68
    QFETCH(QString, secondXml);
67
69
    QFETCH(int, expectedType);
68
 
    PrimitiveDataType type = (PrimitiveDataType)expectedType;
 
70
    PrimitiveDataType type(static_cast<PrimitiveDataTypeEnum>(expectedType));
69
71
 
70
72
    OsdParser parser(xml);
71
 
    QList<const TopLevelDataInformation*> tds = parser.parseStructures();
 
73
    QVector<TopLevelDataInformation*> tds = parser.parseStructures();
72
74
    QCOMPARE(tds.size(), 1);
73
75
    const TopLevelDataInformation* td = tds.at(0);
74
76
    DataInformation* data = td->actualDataInformation();
75
 
    QCOMPARE(data->name(), QString("foo"));
76
 
    PrimitiveDataInformation* prim = dynamic_cast<PrimitiveDataInformation*>(data);
 
77
    QCOMPARE(data->name(), QLatin1String("foo"));
 
78
    PrimitiveDataInformation* prim = data->asPrimitive();
77
79
    QVERIFY(prim);
78
80
    QCOMPARE(prim->type(), type);
 
81
    qDeleteAll(tds);
79
82
 
80
83
    //just to ensure comparison is case insensitive
81
84
    OsdParser parser2(secondXml);
82
 
    QList<const TopLevelDataInformation*> tds2 = parser2.parseStructures();
 
85
    QVector<TopLevelDataInformation*> tds2 = parser2.parseStructures();
83
86
    QCOMPARE(tds2.size(), 1);
84
87
    const TopLevelDataInformation* td2 = tds2.at(0);
85
88
    DataInformation* data2 = td2->actualDataInformation();
86
 
    QCOMPARE(data2->name(), QString("foo"));
87
 
    PrimitiveDataInformation* prim2 = dynamic_cast<PrimitiveDataInformation*>(data2);
 
89
    QCOMPARE(data2->name(), QString(QLatin1String("foo")));
 
90
    PrimitiveDataInformation* prim2 = data2->asPrimitive();
88
91
    QVERIFY(prim2);
89
92
    QCOMPARE(prim2->type(), type);
 
93
    qDeleteAll(tds2);
90
94
}
91
95
 
92
96