예제 #1
0
  /**
   * Test method for {@link
   * at.ac.tuwien.auto.calimero.dptxlator.DPTXlatorString#setValue(java.lang.String)}.
   *
   * @throws KNXFormatException
   */
  public final void testSetValue() throws KNXFormatException {
    t.setValue(string1);
    assertEquals(string1, t.getValue());
    final String s = t.getValue();
    t.setValue(s);
    assertEquals(string1, t.getValue());
    assertEquals(s, t.getValue());
    t.setValue(empty);
    assertEquals(empty, t.getValue());
    assertTrue(Arrays.equals(dataEmpty, t.getData()));
    t.setValue(max);
    assertEquals(max, t.getValue());

    try {
      t.setValue("tooooooooo long");
    } catch (final KNXFormatException e) {
    }
    assertEquals(max, t.getValue());

    final DPTXlatorString t2 = new DPTXlatorString(DPTXlatorString.DPT_STRING_ASCII);
    t2.setValue(nonASCII);
    assertEquals("ab?cd?ef", t2.getValue());
    final byte[] nonAsciiData = t2.getData();
    final byte[] expected = {
      (byte) 'a',
      (byte) 'b',
      (byte) '?',
      (byte) 'c',
      (byte) 'd',
      (byte) '?',
      (byte) 'e',
      (byte) 'f',
      0,
      0,
      0,
      0,
      0,
      0
    };
    assertTrue(Arrays.equals(expected, nonAsciiData));

    t.setValue(nonASCII);
    assertEquals(nonASCII, t.getValue());

    t.setValue(nonLatin);
    assertEquals("ab?cd?", t.getValue());

    t2.setValue(nonLatin);
    assertEquals("ab?cd?", t.getValue());
  }
예제 #2
0
  /**
   * Test method for {@link at.ac.tuwien.auto.calimero.dptxlator.DPTXlatorString#getAllValues()}.
   *
   * @throws KNXFormatException
   */
  public final void testGetAllValues() throws KNXFormatException {
    assertEquals(1, t.getItems());
    assertEquals(t.getItems(), t.getItems());
    assertEquals(empty, t.getAllValues()[0]);

    t.setData(data);
    assertArrayEquals(strings, t.getAllValues());
    assertEquals(t.getItems(), t.getItems());

    t.setValue(string1);
    assertEquals(1, t.getItems());
    assertEquals(string1, t.getAllValues()[0]);
  }
예제 #3
0
  /**
   * Test method for {@link at.ac.tuwien.auto.calimero.dptxlator.DPTXlatorString#getData(byte[],
   * int)}.
   *
   * @throws KNXFormatException
   */
  public final void testGetDataByteArrayInt() throws KNXFormatException {
    assertEquals(25, t.getData(new byte[25], 4).length);
    final byte[] buf = new byte[20];
    assertTrue(Arrays.equals(buf, t.getData(new byte[20], 3)));

    t.setData(data);
    byte[] d = new byte[45];
    Arrays.fill(d, (byte) 0xCC);
    t.getData(d, 2);
    for (int i = 0; i < 2; i++) assertEquals((byte) 0xCC, d[i]);
    for (int i = 2; i < 44; i++) assertEquals(data[i - 2], d[i]);
    for (int i = 44; i < 45; i++) assertEquals((byte) 0xCC, d[i]);

    for (int i = 0; i < strings.length; i++) {
      t.setValue(strings[i]);
      d = t.getData(new byte[14 + i], i);
      for (int k = 0; k < 14; ++k) assertEquals(data[14 * i + k], d[i + k]);
    }
  }