|
| 1 | +/* |
| 2 | + * Copyright (C) 2020 European Spallation Source ERIC. |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or |
| 5 | + * modify it under the terms of the GNU General Public License |
| 6 | + * as published by the Free Software Foundation; either version 2 |
| 7 | + * of the License, or (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | + * |
| 18 | + */ |
| 19 | + |
| 20 | +package org.epics.pva.data; |
| 21 | + |
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +import java.util.Arrays; |
| 25 | +import java.util.List; |
| 26 | + |
| 27 | +import static org.junit.Assert.*; |
| 28 | + |
| 29 | +public class PVAByteArrayTest { |
| 30 | + |
| 31 | + @Test |
| 32 | + public void fromString() throws Exception{ |
| 33 | + PVAByteArray foo = newPVAByteArray(); |
| 34 | + foo.setValue("bar"); |
| 35 | + |
| 36 | + assertArrayEquals(new byte[]{(byte)98, (byte)97, (byte)114}, foo.get()); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void fromPVAByteArray() throws Exception{ |
| 41 | + PVAByteArray foo = newPVAByteArray(); |
| 42 | + PVAByteArray bar = new PVAByteArray("bar", false, (byte)98, (byte)97, (byte)114); |
| 43 | + foo.setValue(bar); |
| 44 | + |
| 45 | + assertArrayEquals(new byte[]{(byte)98, (byte)97, (byte)114}, foo.get()); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void fromPVADoubleArray() throws Exception{ |
| 50 | + PVAByteArray foo = newPVAByteArray(); |
| 51 | + PVADoubleArray bar = new PVADoubleArray("bar", 98, 97, 114); |
| 52 | + foo.setValue(bar); |
| 53 | + |
| 54 | + assertArrayEquals(new byte[]{(byte)98, (byte)97, (byte)114}, foo.get()); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void fromByteArray() throws Exception{ |
| 59 | + PVAByteArray foo = newPVAByteArray(); |
| 60 | + foo.setValue(new byte[]{(byte)98, (byte)97, (byte)114}); |
| 61 | + |
| 62 | + assertArrayEquals(new byte[]{(byte)98, (byte)97, (byte)114}, foo.get()); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void fromDoubleArray() throws Exception{ |
| 67 | + PVAByteArray foo = newPVAByteArray(); |
| 68 | + foo.setValue(new double[]{98.0, 97.0, 114.0}); |
| 69 | + |
| 70 | + assertArrayEquals(new byte[]{(byte)98, (byte)97, (byte)114}, foo.get()); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void fromList() throws Exception{ |
| 75 | + PVAByteArray foo = newPVAByteArray(); |
| 76 | + List<Integer> list = Arrays.asList(98, 97, 114); |
| 77 | + foo.setValue(list); |
| 78 | + |
| 79 | + assertArrayEquals(new byte[]{(byte)98, (byte)97, (byte)114}, foo.get()); |
| 80 | + } |
| 81 | + |
| 82 | + private PVAByteArray newPVAByteArray(){ |
| 83 | + return new PVAByteArray("foo", false, (byte)102, (byte)111, (byte)111); |
| 84 | + } |
| 85 | +} |
0 commit comments