-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for supportsOperation methods
- Loading branch information
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2024 Contributors to the Eclipse Foundation. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import "package:dart_wot/binding_coap.dart"; | ||
import "package:dart_wot/core.dart"; | ||
import "package:test/test.dart"; | ||
|
||
void main() { | ||
group("CoapClientFactory should", () { | ||
test("indicate correctly whether an operation is supported", () { | ||
final coapClientFactory = CoapClientFactory(); | ||
|
||
const observeOperations = [ | ||
OperationType.observeproperty, | ||
OperationType.unobserveproperty, | ||
OperationType.subscribeevent, | ||
OperationType.unsubscribeevent, | ||
]; | ||
final otherOperations = OperationType.values | ||
.where((operationType) => !observeOperations.contains(operationType)); | ||
|
||
final testVector = [ | ||
( | ||
expectedResult: true, | ||
operationTypes: observeOperations, | ||
subprotocol: "cov:observe", | ||
), | ||
( | ||
expectedResult: false, | ||
operationTypes: observeOperations, | ||
subprotocol: null, | ||
), | ||
( | ||
expectedResult: true, | ||
operationTypes: otherOperations, | ||
subprotocol: null, | ||
), | ||
( | ||
expectedResult: false, | ||
operationTypes: otherOperations, | ||
subprotocol: "cov:observe", | ||
), | ||
( | ||
expectedResult: false, | ||
operationTypes: OperationType.values, | ||
subprotocol: "foobar", | ||
), | ||
]; | ||
|
||
for (final testCase in testVector) { | ||
for (final operationType in testCase.operationTypes) { | ||
expect( | ||
coapClientFactory.supportsOperation( | ||
operationType, | ||
testCase.subprotocol, | ||
), | ||
testCase.expectedResult, | ||
); | ||
} | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2024 Contributors to the Eclipse Foundation. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import "package:dart_wot/binding_http.dart"; | ||
import "package:dart_wot/core.dart"; | ||
import "package:test/test.dart"; | ||
|
||
void main() { | ||
group("HttpClientFactory should", () { | ||
test("indicate correctly whether an operation is supported", () { | ||
final httpClientFactory = HttpClientFactory(); | ||
|
||
const observeOperations = [ | ||
OperationType.observeproperty, | ||
OperationType.unobserveproperty, | ||
OperationType.subscribeevent, | ||
OperationType.unsubscribeevent, | ||
]; | ||
final otherOperations = OperationType.values | ||
.where((operationType) => !observeOperations.contains(operationType)); | ||
|
||
final testVector = [ | ||
( | ||
expectedResult: false, | ||
operationTypes: observeOperations, | ||
subprotocol: null, | ||
), | ||
( | ||
expectedResult: false, | ||
operationTypes: observeOperations, | ||
subprotocol: "foobar", | ||
), | ||
( | ||
expectedResult: true, | ||
operationTypes: otherOperations, | ||
subprotocol: null, | ||
), | ||
( | ||
expectedResult: false, | ||
operationTypes: otherOperations, | ||
subprotocol: "foobar", | ||
), | ||
]; | ||
|
||
for (final testCase in testVector) { | ||
for (final operationType in testCase.operationTypes) { | ||
expect( | ||
httpClientFactory.supportsOperation( | ||
operationType, | ||
testCase.subprotocol, | ||
), | ||
testCase.expectedResult, | ||
); | ||
} | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2024 Contributors to the Eclipse Foundation. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import "package:dart_wot/binding_mqtt.dart"; | ||
import "package:dart_wot/core.dart"; | ||
import "package:test/test.dart"; | ||
|
||
void main() { | ||
group("MqttClientFactory should", () { | ||
test("indicate correctly whether an operation is supported", () { | ||
final coapClientFactory = MqttClientFactory(); | ||
|
||
final testVector = [ | ||
( | ||
expectedResult: false, | ||
operationTypes: OperationType.values, | ||
subprotocol: "foobar", | ||
), | ||
( | ||
expectedResult: true, | ||
operationTypes: OperationType.values, | ||
subprotocol: null, | ||
), | ||
]; | ||
|
||
for (final testCase in testVector) { | ||
for (final operationType in testCase.operationTypes) { | ||
expect( | ||
coapClientFactory.supportsOperation( | ||
operationType, | ||
testCase.subprotocol, | ||
), | ||
testCase.expectedResult, | ||
); | ||
} | ||
} | ||
}); | ||
}); | ||
} |