1
#include "leinputstream.h"
2
#include "leoutputstream.h"
3
#include "introspection.h"
4
#include "utils.h"
5
#include <QBuffer>
6
#include <QCoreApplication>
7
#include <QXmlStreamWriter>
8
#include <QDebug>
9
#include <QFile>
10
#include <QVariant>
11
#include <cstdio>
12
#include <QSharedPointer>
13
14
/** 
15
 * This program reads mso ole files, converts the streams to runtime structures,
16
 * translates these runtime structures to xml, parses the xml back to runtime
17
 * structures, serializes those runtime structures to binary streams and checks
18
 * whether the resulting collestion of streams is the same as the original.
19
 **/
20
21
const Introspectable* parse(const QString& key, LEInputStream& in);
22
void serialize(const Introspectable* i, const QString& key, LEOutputStream& out);
23
const QMap<QString,QSharedPointer<const Introspectable> > parse(QXmlStreamReader& in);
24
25
using namespace std;
26
27
void
28
testfile(const QString& file) {
29
    const QMap<QString, QByteArray> streams = readStreams(file);
30
    const QMap<QString, QSharedPointer<const Introspectable> > introspectables
31
            = parseStreams(streams);
32
    QMap<QString, QByteArray> streams2 = serialize(introspectables);
33
    if (streams != streams2) {
34
        qDebug() << "Serialized streams are different from the original.";
35
        return;
36
    }
37
    const QByteArray xml = streamsToXml(introspectables);
38
    write("out", xml);
39
    QXmlStreamReader in(xml);
40
    const QMap<QString,QSharedPointer<const Introspectable> > introspectables2
41
            = parse(in);
42
    streams2 = serialize(introspectables2);
43
    if (streams != streams2) {
44
        qDebug() << "Serialized streams from xml are different from the original.";
45
    }
46
}
47
48
int
49
main(int argc, char** argv) {
50
    QCoreApplication app(argc, argv);
51
    if (argc != 2) return -1;
52
53
    testfile(QLatin1String(argv[1]));
54
55
    return 0;
56
}