Example #1
0
 /**
  * Verifies that the default encoding (UTF-16) works for wstrings in giop 1.1, which uses the
  * length indicator to specify the number of characters rather than bytes and require a two-byte
  * null terminator. Wide characters in 1.1 do not take width bytes
  */
 @Test
 public void testDefaultEncodingWCharGiop1_1() throws Exception {
   byte[] codedText = {
     0,
     0,
     0,
     5, // string length in bytes, not chars
     0x30,
     (byte) (0xDF & 0xff), // Mitsubishi, in Katakana
     0x30,
     (byte) (0xC4 & 0xff),
     0x30,
     (byte) (0xFA & 0xff),
     0x30,
     (byte) (0xB7 & 0xff),
     0,
     0, // two-byte null terminator
     0x5,
     (byte) (0xD1 & 0xff), // Hebrew letter beis
   };
   CDRInputStream stream = new CDRInputStream(orb, codedText);
   stream.setGIOPMinor(1);
   assertEquals("wstring value", "\u30DF\u30C4\u30FA\u30B7", stream.read_wstring());
   assertEquals("wchar 1", '\u05D1', stream.read_wchar());
   stream.close();
 }
Example #2
0
  /**
   * Verifies that the UTF-8 works for wchar, wchar arrays, and wstrings. Reading the wstring forces
   * alignment of the 4-byte length. Note that byte-ordering is fixed by the encoding.
   */
  @Test
  public void testUTF8EncodingWChar() throws Exception {
    byte[] codedText = {
      1,
      'x', // Latin-l lowercase x
      2,
      (byte) (0xD7 & 0xff),
      (byte) (0x90 & 0xff), // Hebrew letter aleph
      3,
      (byte) (0xE3 & 0xff),
      (byte) (0x81 & 0xff),
      (byte) (0x91 & 0xff), // Hiragana syllable ha
      3,
      (byte) (0xE3 & 0xff),
      (byte) (0x81 & 0xff),
      (byte) (0xB4 & 0xff), // Hiragana syllable pi
      2,
      (byte) (0xD7 & 0xff),
      (byte) (0x91 & 0xff), // Hebrew letter beis
      2,
      (byte) (0xD7 & 0xff),
      (byte) (0x92 & 0xff), // Hebrew letter gimmel
      2,
      (byte) (0xD7 & 0xff),
      (byte) (0x93 & 0xff), // Hebrew letter dalet
      45,
      73, // bytes ignored by 'long' alignment
      0,
      0,
      0,
      12, // string length in bytes, not chars
      (byte) (0xE3 & 0xff),
      (byte) (0x83 & 0xff),
      (byte) (0x9F & 0xff), // Mitsubishi, in Katakana
      (byte) (0xE3 & 0xff),
      (byte) (0x83 & 0xff),
      (byte) (0x84 & 0xff),
      (byte) (0xE3 & 0xff),
      (byte) (0x83 & 0xff),
      (byte) (0xBA & 0xff),
      (byte) (0xE3 & 0xff),
      (byte) (0x82 & 0xff),
      (byte) (0xB7 & 0xff),
    };
    CDRInputStream stream = new CDRInputStream(orb, codedText);
    selectCodeSets(stream, "ISO8859_1", "UTF8");
    assertEquals("wchar 1", 'x', stream.read_wchar());
    assertEquals("wchar 2", '\u05D0', stream.read_wchar());
    assertEquals("wchar 3", '\u3051', stream.read_wchar());
    assertEquals("wchar 4", '\u3074', stream.read_wchar());

    char[] buffer = new char[4];
    buffer[0] = '\u05D0';
    stream.read_wchar_array(buffer, 1, 3);
    assertEquals("wchar array", "\u05D0\u05D1\u05D2\u05D3", new String(buffer));
    assertEquals("wstring value", "\u30DF\u30C4\u30FA\u30B7", stream.read_wstring());
    stream.close();
  }
Example #3
0
  /**
   * Verifies that the default encoding (UTF-16) works for wchar, wchar arrays, and wstrings with no
   * byte-order-marker. Reading the wstring forces alignment of the 4-byte length.
   */
  @Test
  public void testDefaultEncodingWChar() throws Exception {
    byte[] codedText = {
      2,
      0x5,
      (byte) (0xD0 & 0xff), // Hebrew letter aleph
      2,
      0x30,
      0x51, // Hiragana syllable ha
      2,
      0x30,
      0x74, // Hiragana syllable pi
      2, // Hebrew letter beis: length byte
      (byte) (0xFE & 0xff), //   Big-endian indicator
      (byte) (0xFF & 0xff),
      0x5,
      (byte) (0xD1 & 0xff), //   UTF16 encoding (big-endian)
      2, // Hebrew letter gimmel: length byte
      (byte) (0xFF & 0xff), //   Little-endian indicator
      (byte) (0xFE & 0xff),
      (byte) (0xD2 & 0xff),
      0x5, //   UTF16 encoding (little-endian)
      2,
      0x5,
      (byte) (0xD3 & 0xff), // Hebrew letter dalet
      45,
      23, // bytes ignored by 'long' alignment
      0,
      0,
      0,
      8, // string length in bytes, not chars
      0x30,
      (byte) (0xDF & 0xff), // Mitsubishi, in Katakana
      0x30,
      (byte) (0xC4 & 0xff),
      0x30,
      (byte) (0xFA & 0xff),
      0x30,
      (byte) (0xB7 & 0xff),
    };
    CDRInputStream stream = new CDRInputStream(orb, codedText);
    assertEquals("wchar 1", '\u05D0', stream.read_wchar());
    assertEquals("wchar 2", '\u3051', stream.read_wchar());
    assertEquals("wchar 3", '\u3074', stream.read_wchar());

    char[] buffer = new char[4];
    buffer[0] = '\u05D0';
    stream.read_wchar_array(buffer, 1, 3);
    assertEquals("wchar array", "\u05D0\u05D1\u05D2\u05D3", new String(buffer));
    assertEquals("wstring value", "\u30DF\u30C4\u30FA\u30B7", stream.read_wstring());
    stream.close();
  }