File: main.cpp

package info (click to toggle)
libqxt 0.6.1-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 19,004 kB
  • sloc: cpp: 57,512; xml: 296; sh: 251; makefile: 56; php: 14
file content (68 lines) | stat: -rw-r--r-- 2,768 bytes parent folder | download | duplicates (3)
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
#include <QxtJSON>
#include <QTest>
#include <QDebug>

class QxtJSONTest: public QObject{
    Q_OBJECT;
private slots:
    void initTestCase(){
    }

	void stringifyBasic(){
        QCOMPARE(QxtJSON::stringify((int)4),QString("4"));
        QCOMPARE(QxtJSON::stringify(false),QString("false"));
        QCOMPARE(QxtJSON::stringify(true),QString("true"));
        QCOMPARE(QxtJSON::stringify(QVariant()),QString("null"));
        QCOMPARE(QxtJSON::stringify("hi"),QString("\"hi\""));
        QCOMPARE(QxtJSON::stringify("hi"),QString("\"hi\""));
        QCOMPARE(QxtJSON::stringify(0.4),QString("0.4"));
        QCOMPARE(QxtJSON::stringify(QVariantList()<<4),QString("[4]"));
        QCOMPARE(QxtJSON::stringify(QVariantList()),QString("[]"));
	}
    void stringifyList(){
        QVariantList e;
        e<<"fish";
        e<<5;
        e<<false;
        QCOMPARE(QxtJSON::stringify(e),QString("[\"fish\",5,false]"));
    }
    void stringifyMap(){
        QVariantMap e;
        e["bla"]="fish";
        e["foo"]=5;
        e["boo"]=false;
        QCOMPARE(QxtJSON::stringify(e),QString("{\"bla\":\"fish\",\"boo\":false,\"foo\":5}"));
    }
	void parseLiteral(){
        QCOMPARE(QxtJSON::parse("5123").toInt(),5123);
        QCOMPARE(QxtJSON::parse("1.5").toDouble(),1.5);
    }

	void parseWhitespace(){
        QCOMPARE(QxtJSON::parse("\r\n 51235656          \r\n").toInt(),51235656);
        QCOMPARE(QxtJSON::parse("\r\n [         51235656 ] ").toList(),QVariantList()<<51235656);

        QVariantMap e;
        e["bla"]="fish";
        e["foo"]=5;
        e["boo"]=false;
        QCOMPARE(QxtJSON::parse(" { \"bla\": \"fish\"    ,    \"boo\":false ,\n\"foo\": 5  }\n" ),QVariant(e));
    }

	void same(){
        QVariantList e;
        e<<"fish"<<true<<QVariant()<<"bla"<<false<<6.5;
        QCOMPARE(QxtJSON::parse(QxtJSON::stringify(e)),QVariant(e));
	}


	void regressXenakios(){
        QVariant e=QxtJSON::parse("{\"apina\":\"ripulia!\",\"doctype\":\"QtCDP WorkSpace\",\"processinghistory\":[{\"infilename\":\"H:/Samples from net/Berklee44v8/Berklee44v8/aluminum2.wav\",\"itemname\":\"aluminum2.wav\",\"itemtag\":\"inputfile\",\"tse\":5.62246,\"tss\":5.08163},{\"infilename\":\"H:/Samples from net/Berklee44v8/Berklee44v8/aluminum3.wav\",\"itemname\":\"aluminum3.wav\",\"itemtag\":\"inputfile\"},{\"infilename\":\"H:/Samples from net/Berklee44v8/Berklee44v8/asprin_crinkle_1.wav\",\"itemname\":\"asprin_crinkle_1.wav\",\"itemtag\":\"inputfile\",\"tse\":0.593006,\"tss\":0.255667},{\"infilename\":\"H:/Samples from net/Berklee44v8/Berklee44v8/asprin_crinkle_2.wav\",\"itemname\":\"asprin_crinkle_2.wav\",\"itemtag\":\"inputfile\",\"tse\":1.66739,\"tss\":1.53128}]}");
        QVERIFY(!e.isNull());
    }


};

QTEST_MAIN(QxtJSONTest)
#include "main.moc"