Debian Codegraph @

tests/auto/grpcquick/channeloptions/qml/tst_channeloptions.qml

raw
1 // Copyright (C) 2023 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 import QtQuick
5 import QtTest
6 import QtGrpc
7 import QmlTestUri
8 import QtNetwork
9
10 Item {
11 id: root
12
13 property bool sslSupport: options.sslConfiguration !== undefined
14
15 property Item sslDynamicItem;
16
17 function createSslConfigurationItem() {
18 return Qt.createQmlObject("import QtQuick; import QtGrpc; import QtNetwork; Item { \
19 property sslConfiguration defaultConfig; }", root)
20 }
21
22 Component.onCompleted: {
23 if (sslSupport) {
24 sslDynamicItem = root.createSslConfigurationItem()
25 options.sslConfiguration = sslDynamicItem.defaultConfig
26 }
27 optionsWithChangedProperties.metadata = null
28 optionsWithChangedProperties.deadlineTimeout = 3000
29 options.serializationFormat = QtGrpc.SerializationFormat.Json
30
31 }
32
33 GrpcChannelOptions {
34 id: options
35 deadlineTimeout: { 1000 }
36 metadata: GrpcMetadata {
37 id: grpcData
38 data: ({ "user-name": "localhost",
39 "user-password": "qwerty"})
40 }
41 serializationFormat: {QtGrpc.SerializationFormat.Protobuf}
42 }
43
44 GrpcChannelOptions {
45 id: optionsWithChangedProperties
46 metadata: GrpcMetadata {
47 data: ({ "user-name": "localhost",
48 "user-password": "qwerty"})
49 }
50 deadlineTimeout: { 1000 }
51 serializationFormat: {QtGrpc.SerializationFormat.Json}
52 }
53
54 TestCase {
55 id: optionsCase
56 name: "qtgrpcSslChannelOptionsTest"
57
58 function initTestCase()
59 {
60 if (!sslSupport) {
61 warn("No SSL support detected!")
62 compare(options.sslConfiguration, undefined)
63 }
64 }
65
66 function test_sslOptionType_data() {
67 if (sslSupport) {
68 return [
69 { tag: "peerVerifyMode == AutoVerifyPeer",
70 field: options.sslConfiguration.peerVerifyMode , answer: SslSocket.AutoVerifyPeer }
71 ]
72 } else {
73 return [
74 { tag: "SSL option is not creatable",
75 field: options.sslConfiguration, answer: undefined }
76 ]
77 }
78 }
79
80 function test_sslOptionType(data) {
81 compare(data.field, data.answer)
82 }
83 }
84
85 TestCase {
86 name: "qtgrpcChannelOptionsTest"
87 function test_OptionTypes_data() {
88 return [
89 { tag: "options is an object",
90 field: typeof options, answer: "object" },
91 { tag: "options.metadata is an object",
92 field: typeof options.metadata, answer: "object" },
93 { tag: "options.metadata.data is an object",
94 field: typeof options.metadata.data, answer: "object" },
95 { tag: "grpcData is an object",
96 field: typeof grpcData, answer: "object" },
97 { tag: "QtGrpc.SerializationFormat.Protobuf == 1",
98 field: QtGrpc.SerializationFormat.Protobuf, answer: 1 },
99 { tag: "QtGrpc.SerializationFormat.Json == 2",
100 field: QtGrpc.SerializationFormat.Json, answer: 2 }
101 ]
102 }
103
104 function test_OptionTypes(data) {
105 compare(data.field, data.answer)
106 }
107
108 function test_ChannelOptions_data() {
109 return [
110 { tag: "options.metadata == grpcData",
111 field: options.metadata, answer: grpcData },
112 { tag: "options.metadata.data == grpcData.data",
113 field: options.metadata.data, answer: grpcData.data },
114 { tag: "options.metadata.data[user-name] == localhost",
115 field: options.metadata.data["user-name"], answer: "localhost" },
116 { tag: "options.metadata.data[user-password] == qwerty",
117 field: options.metadata.data["user-password"], answer: "qwerty" },
118 { tag: "metadata deadlineTimeout = 1000",
119 field: options.deadlineTimeout, answer: 1000 },
120 { tag: "optionsWithChangedProperties.metadata == null",
121 field: optionsWithChangedProperties.metadata, answer: null },
122 { tag: "optionsWithChangedProperties.deadlineTimeout == 3000",
123 field: optionsWithChangedProperties.deadlineTimeout, answer: 3000 }
124 ]
125 }
126
127 function test_ChannelOptions(data) {
128 compare(data.field, data.answer)
129 }
130
131 function test_serializationFormat_data() {
132 return [
133 { tag: "options.serializationFormat == QtGrpc.SerializationFormat.Json",
134 field: options.serializationFormat,
135 answer: QtGrpc.SerializationFormat.Json },
136 { tag: "qtgrpcSslChannelOptionsTest.serializationFormat == QtGrpc.SerializationFormat.Json",
137 field: optionsWithChangedProperties.serializationFormat,
138 answer: QtGrpc.SerializationFormat.Json },
139 { tag: "optionsWithChangedProperties.metadata == null",
140 field: optionsWithChangedProperties.metadata, answer: null },
141 { tag: "optionsWithChangedProperties.deadlineTimeout == 3000",
142 field: optionsWithChangedProperties.deadlineTimeout, answer: 3000 }
143 ]
144 }
145
146 function test_serializationFormat(data) {
147 compare(data.field, data.answer)
148 }
149 }
150 }