You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2018/11/01 20:17:43 UTC
[incubator-plc4x] 13/35: [plc4j-ads] added encoder/decoder round
trip tests (disabled)
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch add-simple-mock-driver
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit cb3f25fce3e14c7c89306431c598e6726d1e5f65
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Oct 29 14:17:31 2018 +0100
[plc4j-ads] added encoder/decoder round trip tests (disabled)
---
.../protocol/util/EncoderDecoderRoundTripTest.java | 58 ++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/protocol/util/EncoderDecoderRoundTripTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/protocol/util/EncoderDecoderRoundTripTest.java
new file mode 100644
index 0000000..a7f693f
--- /dev/null
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/protocol/util/EncoderDecoderRoundTripTest.java
@@ -0,0 +1,58 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+package org.apache.plc4x.java.ads.protocol.util;
+
+import org.apache.plc4x.java.ads.model.AdsDataType;
+import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
+import org.assertj.core.api.WithAssertions;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.Arrays;
+import java.util.stream.Stream;
+
+@Disabled("check if the encoder/decoder can be used like this.")
+public class EncoderDecoderRoundTripTest implements WithAssertions {
+
+ @ParameterizedTest
+ @MethodSource("generateData")
+ public void testMin(AdsDataType adsDataType, Double min, Double max) throws Exception {
+ byte[] bytes = LittleEndianEncoder.encodeData(adsDataType, min);
+ BaseDefaultFieldItem baseDefaultFieldItem = LittleEndianDecoder.decodeData(adsDataType, bytes);
+
+ assertThat(baseDefaultFieldItem.getDouble(0)).isEqualTo(min);
+ }
+
+ @ParameterizedTest
+ @MethodSource("generateData")
+ public void testMax(AdsDataType adsDataType, Double min, Double max) throws Exception {
+ byte[] bytes = LittleEndianEncoder.encodeData(adsDataType, max);
+ BaseDefaultFieldItem baseDefaultFieldItem = LittleEndianDecoder.decodeData(adsDataType, bytes);
+
+ assertThat(baseDefaultFieldItem.getDouble(0)).isEqualTo(max);
+ }
+
+ public static Stream<Arguments> generateData() {
+ return Arrays.stream(AdsDataType.values())
+ .map(adsDataType -> Arguments.of(adsDataType, adsDataType.getLowerBound(), adsDataType.getUpperBound()));
+ }
+}