]> git.basschouten.com Git - openhab-addons.git/blob
bac87348121911f1d6ffcd3d9987e515a601b9bd
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.modbus.e3dc.util;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.nio.ByteBuffer;
18 import java.util.BitSet;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.modbus.e3dc.internal.dto.DataConverter;
23
24 /**
25  * The {@link DataConverterTest} Test data conversions
26  *
27  * @author Bernd Weymann - Initial contribution
28  */
29 @NonNullByDefault
30 public class DataConverterTest {
31
32     @Test
33     public void testE3DCSwapValueNegative() {
34         // Reg 69 value 65098 bytes [-2, 74]
35         // Reg 70 value 65535 bytes [-1, -1]
36         byte[] b = new byte[] { -2, -74, -1, -1 };
37         assertEquals(-330, DataConverter.getInt32Swap(ByteBuffer.wrap(b)), "Negative Value");
38     }
39
40     @Test
41     public void testBitset() {
42         byte[] b = new byte[] { 3, 16 };
43         BitSet s = BitSet.valueOf(b);
44         assertEquals(true, s.get(0), "Bit0");
45         assertEquals(true, s.get(1), "Bit1");
46         assertEquals(false, s.get(2), "Bit2");
47         assertEquals(false, s.get(3), "Bit3");
48         assertEquals(false, s.get(4), "Bit4");
49         assertEquals(false, s.get(5), "Bit5");
50         assertEquals(false, s.get(6), "Bit6");
51         assertEquals(false, s.get(7), "Bit7");
52         assertEquals(false, s.get(8), "Bit8");
53         assertEquals(false, s.get(9), "Bit9");
54         assertEquals(false, s.get(10), "Bit10");
55         assertEquals(false, s.get(11), "Bit11");
56         assertEquals(true, s.get(12), "Bit12");
57         assertEquals(false, s.get(13), "Bit13");
58         assertEquals(false, s.get(14), "Bit14");
59         assertEquals(false, s.get(15), "Bit15");
60     }
61 }