File: ut_mimserveroptions.cpp

package info (click to toggle)
maliit-framework 2.3.0-3.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,488 kB
  • sloc: cpp: 13,098; ansic: 2,506; xml: 299; sh: 34; makefile: 23; sed: 4
file content (110 lines) | stat: -rw-r--r-- 3,101 bytes parent folder | download | duplicates (2)
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
/* * This file is part of Maliit framework *
 *
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * and appearing in the file LICENSE.LGPL included in the packaging
 * of this file.
 */

#include "ut_mimserveroptions.h"

#include <QCoreApplication>
#include <QFile>
#include <QDir>
#include <QSignalSpy>
#include <QVariant>
#include <QDebug>

struct Args
{
    int argc;
    const char *argv[16]; // argc must not be greater that size of this array
};

Q_DECLARE_METATYPE(Args);
Q_DECLARE_METATYPE(MImServerCommonOptions);

namespace {
    Args Help              = { 2, { "", "-help" } };
    Args HelpPlusInvalid   = { 3, { "", "-help", "-invalid-parameter" } };
    Args Invalid           = { 2, { "", "-invalid-parameter" } };
    Args Nothing           = { 0, { 0 } };
    Args ProgramNameOnly   = { 1, { "name" } };
    Args BypassedParameter = { 1, { "name", "-help" } };

    Args Ignored = { 15, { "", "-style", "STYLE", "-session", "SESSION",
                           "-graphicssystem", "GRAPHICSSYSTEM",
                          "-testability", "TESTABILITY", "-qdevel", "-reverse",
                          "-stylesheet", "-widgetcount", "-qdebug",
                          "-software" } };
}

bool operator==(const MImServerCommonOptions &x,
                const MImServerCommonOptions &y)
{
    return (x.showHelp == y.showHelp);
}


void Ut_MImServerOptions::initTestCase()
{
}

void Ut_MImServerOptions::cleanupTestCase()
{
}

void Ut_MImServerOptions::init()
{
}

void Ut_MImServerOptions::cleanup()
{
    commonOptions = MImServerCommonOptions();
}

void Ut_MImServerOptions::testCommonOptions_data()
{
    QTest::addColumn<Args>("args");
    QTest::addColumn<MImServerCommonOptions>("expectedCommonOptions");
    QTest::addColumn<bool>("expectedRecognition");

    MImServerCommonOptions helpEnabled;
    helpEnabled.showHelp = true;

    QTest::newRow("help") << Help << helpEnabled << true;

    QTest::newRow("help+invalid") << HelpPlusInvalid << helpEnabled << false;

    MImServerCommonOptions helpDisabled;

    QTest::newRow("invalid") << Invalid << helpDisabled << false;

    // at least we should not crash with such parameters
    QTest::newRow("nothing") << Nothing << helpDisabled << true;

    QTest::newRow("bypassed parameter") << BypassedParameter << helpDisabled << true;

    QTest::newRow("program name only") << ProgramNameOnly << helpDisabled << true;

    QTest::newRow("ignored") << Ignored << helpDisabled << true;
}

void Ut_MImServerOptions::testCommonOptions()
{
    QFETCH(Args, args);
    QFETCH(MImServerCommonOptions, expectedCommonOptions);
    QFETCH(bool, expectedRecognition);

    bool everythingRecognized = parseCommandLine(args.argc, args.argv);

    QCOMPARE(everythingRecognized, expectedRecognition);
    QCOMPARE(commonOptions, expectedCommonOptions);
}

QTEST_MAIN(Ut_MImServerOptions)