|
| 1 | +// Copyright 2024 Contributors to the Eclipse Foundation. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | +// |
| 5 | +// SPDX-License-Identifier: BSD-3-Clause |
| 6 | + |
| 7 | +import "package:dart_wot/binding_coap.dart"; |
| 8 | +import "package:dart_wot/core.dart"; |
| 9 | +import "package:test/test.dart"; |
| 10 | + |
| 11 | +void main() { |
| 12 | + group("CoapClientFactory should", () { |
| 13 | + test("indicate correctly whether an operation is supported", () { |
| 14 | + final coapClientFactory = CoapClientFactory(); |
| 15 | + |
| 16 | + const observeOperations = [ |
| 17 | + OperationType.observeproperty, |
| 18 | + OperationType.unobserveproperty, |
| 19 | + OperationType.subscribeevent, |
| 20 | + OperationType.unsubscribeevent, |
| 21 | + ]; |
| 22 | + final otherOperations = OperationType.values |
| 23 | + .where((operationType) => !observeOperations.contains(operationType)); |
| 24 | + |
| 25 | + final testVector = [ |
| 26 | + ( |
| 27 | + expectedResult: true, |
| 28 | + operationTypes: observeOperations, |
| 29 | + subprotocol: "cov:observe", |
| 30 | + ), |
| 31 | + ( |
| 32 | + expectedResult: false, |
| 33 | + operationTypes: observeOperations, |
| 34 | + subprotocol: null, |
| 35 | + ), |
| 36 | + ( |
| 37 | + expectedResult: true, |
| 38 | + operationTypes: otherOperations, |
| 39 | + subprotocol: null, |
| 40 | + ), |
| 41 | + ( |
| 42 | + expectedResult: false, |
| 43 | + operationTypes: otherOperations, |
| 44 | + subprotocol: "cov:observe", |
| 45 | + ), |
| 46 | + ( |
| 47 | + expectedResult: false, |
| 48 | + operationTypes: OperationType.values, |
| 49 | + subprotocol: "foobar", |
| 50 | + ), |
| 51 | + ]; |
| 52 | + |
| 53 | + for (final testCase in testVector) { |
| 54 | + for (final operationType in testCase.operationTypes) { |
| 55 | + expect( |
| 56 | + coapClientFactory.supportsOperation( |
| 57 | + operationType, |
| 58 | + testCase.subprotocol, |
| 59 | + ), |
| 60 | + testCase.expectedResult, |
| 61 | + ); |
| 62 | + } |
| 63 | + } |
| 64 | + }); |
| 65 | + }); |
| 66 | +} |
0 commit comments