| 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 |
|
| 9 |
TestCase { |
| 10 |
id: root |
| 11 |
name: "qtgrpcCallOptionsTest" |
| 12 |
|
| 13 |
GrpcCallOptions { |
| 14 |
id: options |
| 15 |
metadata: grpcData |
| 16 |
deadlineTimeout: { 1000 } |
| 17 |
} |
| 18 |
|
| 19 |
GrpcCallOptions { |
| 20 |
id: options_dup |
| 21 |
metadata: options.metadata |
| 22 |
deadlineTimeout: options.deadlineTimeout |
| 23 |
} |
| 24 |
|
| 25 |
GrpcMetadata { |
| 26 |
id: grpcData |
| 27 |
data: ({ "user-name": "localhost", |
| 28 |
"user-password": "qwerty"}) |
| 29 |
} |
| 30 |
|
| 31 |
GrpcCallOptions { |
| 32 |
id: optionsWithChangedProperties |
| 33 |
metadata: grpcData |
| 34 |
deadlineTimeout: { 2000 } |
| 35 |
} |
| 36 |
|
| 37 |
GrpcCallOptions { |
| 38 |
id: optionsWithDefaultProperty |
| 39 |
} |
| 40 |
|
| 41 |
Component.onCompleted: { |
| 42 |
optionsWithChangedProperties.metadata = null |
| 43 |
optionsWithChangedProperties.deadlineTimeout = 3000 |
| 44 |
} |
| 45 |
|
| 46 |
function test_OptionTypes_data() { |
| 47 |
return [ |
| 48 |
{ tag: "options is an object", |
| 49 |
field: typeof options, answer: "object" }, |
| 50 |
{ tag: "options.metadata is an object", |
| 51 |
field: typeof options.metadata, answer: "object" }, |
| 52 |
{ tag: "options.metadata.data is an object", |
| 53 |
field: typeof options.metadata.data, answer: "object" }, |
| 54 |
{ tag: "grpcData is an object", |
| 55 |
field: typeof grpcData, answer: "object" } |
| 56 |
] |
| 57 |
} |
| 58 |
|
| 59 |
function test_OptionTypes(data) { |
| 60 |
compare(data.field, data.answer) |
| 61 |
} |
| 62 |
|
| 63 |
function test_ChannelOptions_data() { |
| 64 |
return [ |
| 65 |
{ tag: "options.metadata == grpcData", |
| 66 |
field: options.metadata, answer: grpcData }, |
| 67 |
{ tag: "options.metadata.data == grpcData.data", |
| 68 |
field: options.metadata.data, answer: grpcData.data }, |
| 69 |
{ tag: "options.metadata.data[user-name] == localhost", |
| 70 |
field: options.metadata.data["user-name"], answer: "localhost" }, |
| 71 |
{ tag: "options.metadata.data[user-password] == qwerty", |
| 72 |
field: options.metadata.data["user-password"], answer: "qwerty" }, |
| 73 |
{ tag: "metadata deadlineTimeout == 1000", |
| 74 |
field: options.deadlineTimeout, answer: 1000 }, |
| 75 |
{ tag: "options == options_dup", |
| 76 |
field: options.metadata, answer: options_dup.metadata }, |
| 77 |
{ tag: "optionsWithChangedProperties.metadata == null", |
| 78 |
field: optionsWithChangedProperties.metadata, answer: null }, |
| 79 |
{ tag: "optionsWithChangedProperties.deadlineTimeout == 3000", |
| 80 |
field: optionsWithChangedProperties.deadlineTimeout, answer: 3000 }, |
| 81 |
{ tag: "optionsWithDefaultProperty.metadata == null", |
| 82 |
field: optionsWithDefaultProperty.metadata, answer: null } |
| 83 |
] |
| 84 |
} |
| 85 |
|
| 86 |
function test_ChannelOptions(data) { |
| 87 |
compare(data.field, data.answer) |
| 88 |
} |
| 89 |
} |