Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.1
    • Component/s: None
    • Labels:
      None

      Description

      // Look for //TODO:FAILS!!!

      import java.util.HashMap;

      import junit.framework.Test;
      import junit.framework.TestCase;
      import junit.framework.TestSuite;

      import com.thoughtworks.xstream.XStream;

      /**

      • <p>Test for XStream with HashMap</p>
        *
      • <p>Fails on
        */
        public class XStreamTest extends TestCase {

      public static Test suite()

      { return new TestSuite(XStreamTest.class); }

      public static void main(String[] args)

      { junit.textui.TestRunner.run(suite()); }

      public void testSaveRestore()
      {
      byte[][] testByteArr = {
      null,
      {},

      {1,2,3,-1,0,(byte)255,127}

      };

      char[] testChars =

      { 'A', '\u2297', '\n', '\r', //TODO:FAILS!!! }

      ;

      double[] testDoubles =

      { 0.0, Math.E, Math.PI, Double.MIN_VALUE, Double.MAX_VALUE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN, }

      ;

      float[] testFloats =

      { (float)0.0, Float.MIN_VALUE, Float.MAX_VALUE, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NaN, }

      ;

      String[] testStrings =

      { "abc", "123=456", "containing\ttabs", "containing\nlinefeeds", "containing\rcarriage-returns", //TODO:FAILS!!! "", null, "\\u2297=\u2297", "\"", "\u0000abc", "abc" + (char)0, }

      ;

      HashMap map1 = new HashMap();

      for (int i = 0; i < testByteArr.length; i++)

      { map1.put("byteArr" + i, testByteArr[i]); }

      for (int i = 0; i < testChars.length; i++)

      { map1.put("char" + i, new Character(testChars[i])); }

      for (int i = 0; i < testDoubles.length; i++)

      { map1.put("double" + i, new Double(testDoubles[i])); }

      for (int i = 0; i < testFloats.length; i++)

      { map1.put("float" + i, new Float(testFloats[i])); }

      for (int i = 0; i < testStrings.length; i++)

      { map1.put("string" + i, testStrings[i]); }

      XStream xstream = new XStream();
      String map1String = xstream.toXML(map1);
      System.out.println(map1String);
      HashMap map2 = (HashMap)xstream.fromXML(map1String);

      for (int i = 0; i < testByteArr.length; i++)

      { assertEquals( "byteArr " + i, testByteArr[i], (byte[])map2.get("byteArr" + i)); }

      for (int i = 0; i < testChars.length; i++)

      { assertEquals( "char " + i, testChars[i], ((Character)map2.get("char" + i)).charValue()); }

      for (int i = 0; i < testDoubles.length; i++)

      { assertEqualsOrBothNaN( "double " + i, testDoubles[i], ((Double)map2.get("double" + i)).doubleValue(), 0.0); }

      for (int i = 0; i < testFloats.length; i++)

      { assertEqualsOrBothNaN( "float" + i, testFloats[i], ((Float)map2.get("float" + i)).floatValue(), 0.0); }

      for (int i = 0; i < testStrings.length; i++)

      { assertEquals( "string " + i, testStrings[i], (String)map2.get("string" + i)); }

      }

      /**

      • Check that two byte arrays are equal
      • @param message the message (will have info appended in parentheses)
      • @param expected the expected byte array
      • @param actual the actual byte array
        */
        public static void assertEquals(String message,
        byte[] expected, byte[] actual)
        {
        if (expected==null) { assertNull(message + " (expected==null)", actual); }

        else

        Unknown macro: { assertEquals(message + " (length)", expected.length, actual.length); for (int i = 0; i < expected.length; i++) { assertEquals( message + " (element " + i + ")", expected[i], actual[i]); } }

        }

      public static void assertEqualsOrBothNaN(
      String message, double expected, double actual, double delta)

      { if (!Double.isNaN(expected) || !Double.isNaN(actual)) assertEquals(message, expected, actual, delta); }

      public static void assertEqualsOrBothNaN(
      String message, float expected, float actual, float delta)

      { if (!Float.isNaN(expected) || !Float.isNaN(actual)) assertEquals(message, expected, actual, delta); }

      }

        Issue Links

          People

          • Assignee:
            Unassigned
            Reporter:
            Zellyn Hunter
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: