summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/FileAPI/ClientStateful-check.py
blob: f3d20d13e40a137fd1d904039589e0cc943be239 (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
from check_index import *

def check_reply(q):
    assert is_dict(q)
    assert sorted(q.keys()) == [
        "client-client-member",
        "client-empty-array",
        "client-empty-object",
        "client-json-bad-root",
        "client-json-empty",
        "client-json-extra",
        "client-not-file",
        "client-request-array-negative-major-version",
        "client-request-array-negative-minor-version",
        "client-request-array-negative-version",
        "client-request-array-no-major-version",
        "client-request-array-no-supported-version",
        "client-request-array-no-supported-version-among",
        "client-request-array-version-1",
        "client-request-array-version-1-1",
        "client-request-array-version-2",
        "client-request-negative-major-version",
        "client-request-negative-minor-version",
        "client-request-negative-version",
        "client-request-no-major-version",
        "client-request-no-version",
        "client-request-version-1",
        "client-request-version-1-1",
        "client-request-version-2",
        "client-requests-bad",
        "client-requests-empty",
        "client-requests-not-kinded",
        "client-requests-not-objects",
        "client-requests-unknown",
    ]
    expected = [
        (check_query_client_member, "client-client-member"),
        (check_query_empty_array, "client-empty-array"),
        (check_query_empty_object, "client-empty-object"),
        (check_query_json_bad_root, "client-json-bad-root"),
        (check_query_json_empty, "client-json-empty"),
        (check_query_json_extra, "client-json-extra"),
        (check_query_not_file, "client-not-file"),
        (check_query_requests_bad, "client-requests-bad"),
        (check_query_requests_empty, "client-requests-empty"),
        (check_query_requests_not_kinded, "client-requests-not-kinded"),
        (check_query_requests_not_objects, "client-requests-not-objects"),
        (check_query_requests_unknown, "client-requests-unknown"),
    ]
    for (f, k) in expected:
        assert is_dict(q[k])
        assert sorted(q[k].keys()) == ["query.json"]
        f(q[k]["query.json"])
    expected = [
        (check_query_response_array_negative_major_version,     "client-request-array-negative-major-version"),
        (check_query_response_array_negative_minor_version,     "client-request-array-negative-minor-version"),
        (check_query_response_array_negative_version,           "client-request-array-negative-version"),
        (check_query_response_array_no_major_version,           "client-request-array-no-major-version"),
        (check_query_response_array_no_supported_version,       "client-request-array-no-supported-version"),
        (check_query_response_array_no_supported_version_among, "client-request-array-no-supported-version-among"),
        (check_query_response_array_version_1,                  "client-request-array-version-1"),
        (check_query_response_array_version_1_1,                "client-request-array-version-1-1"),
        (check_query_response_array_version_2,                  "client-request-array-version-2"),
        (check_query_response_negative_major_version,           "client-request-negative-major-version"),
        (check_query_response_negative_minor_version,           "client-request-negative-minor-version"),
        (check_query_response_negative_version,                 "client-request-negative-version"),
        (check_query_response_no_major_version,                 "client-request-no-major-version"),
        (check_query_response_no_version,                       "client-request-no-version"),
        (check_query_response_version_1,                        "client-request-version-1"),
        (check_query_response_version_1_1,                      "client-request-version-1-1"),
        (check_query_response_version_2,                        "client-request-version-2"),
    ]
    for (f, k) in expected:
        assert is_dict(q[k])
        assert sorted(q[k].keys()) == ["query.json"]
        assert is_dict(q[k]["query.json"])
        assert sorted(q[k]["query.json"].keys()) == ["requests", "responses"]
        r = q[k]["query.json"]["requests"]
        assert is_list(r)
        assert len(r) == 1
        assert is_dict(r[0])
        assert r[0]["kind"] == "__test"
        r = q[k]["query.json"]["responses"]
        assert is_list(r)
        assert len(r) == 1
        assert is_dict(r[0])
        f(r[0])

def check_query_client_member(q):
    assert is_dict(q)
    assert sorted(q.keys()) == ["client", "responses"]
    assert is_dict(q["client"])
    assert sorted(q["client"].keys()) == []
    check_error(q["responses"], "'requests' member missing")

def check_query_empty_array(q):
    check_error(q, "query root is not an object")

def check_query_empty_object(q):
    assert is_dict(q)
    assert sorted(q.keys()) == ["responses"]
    check_error(q["responses"], "'requests' member missing")

def check_query_json_bad_root(q):
    check_error_re(q, "A valid JSON document must be either an array or an object value")

def check_query_json_empty(q):
    check_error_re(q, "value, object or array expected")

def check_query_json_extra(q):
    check_error_re(q, "Extra non-whitespace after JSON value")

def check_query_not_file(q):
    check_error_re(q, "failed to read from file")

def check_query_requests_bad(q):
    assert is_dict(q)
    assert sorted(q.keys()) == ["requests", "responses"]
    r = q["requests"]
    assert is_dict(r)
    assert sorted(r.keys()) == []
    check_error(q["responses"], "'requests' member is not an array")

def check_query_requests_empty(q):
    assert is_dict(q)
    assert sorted(q.keys()) == ["requests", "responses"]
    r = q["requests"]
    assert is_list(r)
    assert len(r) == 0
    r = q["responses"]
    assert is_list(r)
    assert len(r) == 0

def check_query_requests_not_kinded(q):
    assert is_dict(q)
    assert sorted(q.keys()) == ["requests", "responses"]
    r = q["requests"]
    assert is_list(r)
    assert len(r) == 4
    assert is_dict(r[0])
    assert sorted(r[0].keys()) == []
    assert is_dict(r[1])
    assert sorted(r[1].keys()) == ["kind"]
    assert is_dict(r[1]["kind"])
    assert is_dict(r[2])
    assert sorted(r[2].keys()) == ["kind"]
    assert is_list(r[2]["kind"])
    assert is_dict(r[3])
    assert sorted(r[3].keys()) == ["kind"]
    assert is_int(r[3]["kind"])
    r = q["responses"]
    assert is_list(r)
    assert len(r) == 4
    check_error(r[0], "'kind' member missing")
    check_error(r[1], "'kind' member is not a string")
    check_error(r[2], "'kind' member is not a string")
    check_error(r[3], "'kind' member is not a string")

def check_query_requests_not_objects(q):
    assert is_dict(q)
    assert sorted(q.keys()) == ["requests", "responses"]
    r = q["requests"]
    assert is_list(r)
    assert len(r) == 3
    assert is_int(r[0])
    assert is_string(r[1])
    assert is_list(r[2])
    r = q["responses"]
    assert is_list(r)
    assert len(r) == 3
    check_error(r[0], "request is not an object")
    check_error(r[1], "request is not an object")
    check_error(r[2], "request is not an object")

def check_query_requests_unknown(q):
    assert is_dict(q)
    assert sorted(q.keys()) == ["requests", "responses"]
    r = q["requests"]
    assert is_list(r)
    assert len(r) == 3
    assert is_dict(r[0])
    assert sorted(r[0].keys()) == ["kind"]
    assert r[0]["kind"] == "unknownC"
    assert is_dict(r[1])
    assert sorted(r[1].keys()) == ["kind"]
    assert r[1]["kind"] == "unknownB"
    assert is_dict(r[2])
    assert sorted(r[2].keys()) == ["kind"]
    assert r[2]["kind"] == "unknownA"
    r = q["responses"]
    assert is_list(r)
    assert len(r) == 3
    check_error(r[0], "unknown request kind 'unknownC'")
    check_error(r[1], "unknown request kind 'unknownB'")
    check_error(r[2], "unknown request kind 'unknownA'")

def check_query_response_array_negative_major_version(r):
    check_error(r, "'version' object 'major' member is not a non-negative integer")

def check_query_response_array_negative_minor_version(r):
    check_error(r, "'version' object 'minor' member is not a non-negative integer")

def check_query_response_array_negative_version(r):
    check_error(r, "'version' array entry is not a non-negative integer or object")

def check_query_response_array_no_major_version(r):
    check_error(r, "'version' object 'major' member missing")

def check_query_response_array_no_supported_version(r):
    check_error(r, "no supported version specified")

def check_query_response_array_no_supported_version_among(r):
    check_error(r, "no supported version specified among: 4.0 3.0")

def check_query_response_array_version_1(r):
    check_index__test(r, 1, 3)

def check_query_response_array_version_1_1(r):
    check_index__test(r, 1, 3) # always uses latest minor version

def check_query_response_array_version_2(r):
    check_index__test(r, 2, 0)

def check_query_response_negative_major_version(r):
    check_error(r, "'version' object 'major' member is not a non-negative integer")

def check_query_response_negative_minor_version(r):
    check_error(r, "'version' object 'minor' member is not a non-negative integer")

def check_query_response_negative_version(r):
    check_error(r, "'version' member is not a non-negative integer, object, or array")

def check_query_response_no_major_version(r):
    check_error(r, "'version' object 'major' member missing")

def check_query_response_no_version(r):
    check_error(r, "'version' member missing")

def check_query_response_version_1(r):
    check_index__test(r, 1, 3)

def check_query_response_version_1_1(r):
    check_index__test(r, 1, 3) # always uses latest minor version

def check_query_response_version_2(r):
    check_index__test(r, 2, 0)

def check_objects(o):
    assert is_list(o)
    assert len(o) == 2
    check_index__test(o[0], 1, 3)
    check_index__test(o[1], 2, 0)

assert is_dict(index)
assert sorted(index.keys()) == ["cmake", "objects", "reply"]
check_cmake(index["cmake"])
check_reply(index["reply"])
check_objects(index["objects"])