~unity-api-team/unity-scopes-shell/scope-settings

« back to all changes in this revision

Viewing changes to tests/settingstest.cpp

  • Committer: Pete Woods
  • Date: 2014-06-26 10:57:34 UTC
  • Revision ID: pete.woods@canonical.com-20140626105734-608l4w4x5dlmeu4z
TheĀ firstĀ assertion

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
namespace
31
31
{
32
32
 
33
 
const static QByteArray BOOLEAN_DEFINITION = R"(
34
 
[
35
 
    {
36
 
        "id": "enabledSetting",
37
 
        "displayName": "Enabled",
38
 
        "type": "boolean",
39
 
        "parameters": {
40
 
            "defaultValue": true
41
 
        }
42
 
    }
43
 
]
44
 
)";
45
 
 
46
 
const static QByteArray LIST_DEFINITION = R"(
47
 
[
48
 
    {
49
 
        "id": "unitTempSetting",
50
 
        "displayName": "Temperature Units",
51
 
        "type": "list",
52
 
        "parameters": {
53
 
            "defaultValue": 1,
54
 
            "values": ["Celcius", "Fahrenheit"]
55
 
        }
56
 
    }
57
 
]
58
 
)";
59
 
 
60
 
const static QByteArray NUMBER_DEFINITION = R"(
61
 
[
62
 
    {
63
 
        "id": "ageSetting",
64
 
        "displayName": "Age",
65
 
        "type": "number",
66
 
        "parameters": {
67
 
            "defaultValue": 23
68
 
        }
69
 
    }
70
 
]
71
 
)";
72
 
 
73
 
const static QByteArray STRING_DEFINITION = R"(
74
 
[
75
 
    {
76
 
        "id": "locationSetting",
77
 
        "displayName": "Location",
78
 
        "type": "string",
79
 
        "parameters": {
80
 
            "defaultValue": "London"
 
33
const static QByteArray BOOLEAN_DEFINITION =
 
34
        R"(
 
35
[
 
36
    {
 
37
        "id": "enabledSetting",
 
38
        "displayName": "Enabled",
 
39
        "type": "boolean",
 
40
        "parameters": {
 
41
            "defaultValue": true
 
42
        }
 
43
    }
 
44
]
 
45
)";
 
46
 
 
47
const static QByteArray LIST_DEFINITION =
 
48
        R"(
 
49
[
 
50
    {
 
51
        "id": "unitTempSetting",
 
52
        "displayName": "Temperature Units",
 
53
        "type": "list",
 
54
        "parameters": {
 
55
            "defaultValue": 1,
 
56
            "values": ["Celcius", "Fahrenheit"]
 
57
        }
 
58
    }
 
59
]
 
60
)";
 
61
 
 
62
const static QByteArray NUMBER_DEFINITION =
 
63
        R"(
 
64
[
 
65
    {
 
66
        "id": "ageSetting",
 
67
        "displayName": "Age",
 
68
        "type": "number",
 
69
        "parameters": {
 
70
            "defaultValue": 23
 
71
        }
 
72
    }
 
73
]
 
74
)";
 
75
 
 
76
const static QByteArray STRING_DEFINITION =
 
77
        R"(
 
78
[
 
79
    {
 
80
        "id": "locationSetting",
 
81
        "displayName": "Location",
 
82
        "type": "string",
 
83
        "parameters": {
 
84
            "defaultValue": "London"
 
85
        }
 
86
    }
 
87
]
 
88
)";
 
89
 
 
90
const static QByteArray MIXED_DEFINITION =
 
91
        R"(
 
92
[
 
93
    {
 
94
        "id": "locationSetting",
 
95
        "displayName": "Location",
 
96
        "type": "string",
 
97
        "parameters": {
 
98
            "defaultValue": "London"
 
99
        }
 
100
    },
 
101
    {
 
102
        "id": "unitTempSetting",
 
103
        "displayName": "Temperature Units",
 
104
        "type": "list",
 
105
        "parameters": {
 
106
            "defaultValue": 1,
 
107
            "values": ["Celcius", "Fahrenheit"]
 
108
        }
 
109
    },
 
110
    {
 
111
        "id": "ageSetting",
 
112
        "displayName": "Age",
 
113
        "type": "number",
 
114
        "parameters": {
 
115
            "defaultValue": 23
 
116
        }
 
117
    },
 
118
    {
 
119
        "id": "enabledSetting",
 
120
        "displayName": "Enabled",
 
121
        "type": "boolean",
 
122
        "parameters": {
 
123
            "defaultValue": true
81
124
        }
82
125
    }
83
126
]
89
132
private:
90
133
    QScopedPointer<QTemporaryDir> tempDir;
91
134
 
92
 
    QSharedPointer<SettingsModelInterface> newSettingsModel(const QString& id, const QByteArray& json)
 
135
    QSharedPointer<SettingsModelInterface> settings;
 
136
 
 
137
    void newSettingsModel(const QString& id, const QByteArray& json)
93
138
    {
94
139
        QJsonDocument doc = QJsonDocument::fromJson(json);
95
140
        QVariant definitions = doc.toVariant();
96
 
        return QSharedPointer<SettingsModelInterface>(
97
 
                        new SettingsModel(tempDir->path(), id, definitions));
 
141
        settings.reset(new SettingsModel(tempDir->path(), id, definitions));
98
142
    }
99
143
 
100
144
private Q_SLOTS:
110
154
    void testBooleanDefinition()
111
155
    {
112
156
        newSettingsModel("boolean", BOOLEAN_DEFINITION);
 
157
        QVERIFY(settings->rowCount() == 1);
113
158
    }
114
159
 
115
160
    void testListDefinition()
116
161
    {
117
162
        newSettingsModel("list", LIST_DEFINITION);
 
163
        QVERIFY(settings->rowCount() == 1);
118
164
    }
119
165
 
120
166
    void testNumberDefinition()
121
167
    {
122
168
        newSettingsModel("number", NUMBER_DEFINITION);
 
169
        QVERIFY(settings->rowCount() == 1);
123
170
    }
124
171
 
125
172
    void testStringDefinition()
126
173
    {
127
174
        newSettingsModel("string", STRING_DEFINITION);
 
175
        QVERIFY(settings->rowCount() == 1);
 
176
    }
 
177
 
 
178
    void testMixedDefinition()
 
179
    {
 
180
        newSettingsModel("mixed", MIXED_DEFINITION);
 
181
        QVERIFY(settings->rowCount() == 4);
128
182
    }
129
183
};
130
184