Subversion Repository Public Repository

WOX2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
package wox.serial.tests;

import java.io.*;
import java.lang.reflect.*;
import java.math.*;
import org.litesoft.core.typeutils.Objects;
import java.util.*;

import junit.framework.*;

import ClaimPortal.Requests.*;
import ClaimPortal.*;
import wox.serial.*;

/**
 * Version: 1.0
 * Author: Carlos R. Jaimez Gonzalez
 * Author: Simon M. Lucas
 * Site: http://woxserializer.sourceforge.net/
 *
 * Version: 1.5
 * Author: Steven M Lewis
 *
 * Version: 2.0
 * Author: George Smith
 * SVN: http://svn.xp-dev.com/svn/WOX2/
 * Note: XML form for vs 2 is more compact and therefor incompatible with vs 1
 */

@SuppressWarnings({"unchecked", "FieldCanBeLocal"})
public class SerializationTests extends TestCase
{
    private Easy mEasy;

    public static class TestData
    {
        private static final String TEST_DATA_SUB_DIR = "TestData";

        private static volatile String sDeterminedPath;

        public static String getPath()
                throws IOException
        {
            if ( sDeterminedPath == null )
            {
                sDeterminedPath = findTestDataDir();
            }
            return sDeterminedPath;
        }

        private static String findTestDataDir()
                throws IOException
        {
            File zDir = new File( "." );
            if ( !zDir.isDirectory() )
            {
                throw new ApplicationException( "No Current Directory" );
            }
            zDir = zDir.getCanonicalFile();
            String zOrigPath = zDir.getCanonicalPath();
            File zTestDataDir;
            while ( !(zTestDataDir = new File( zDir, TEST_DATA_SUB_DIR )).isDirectory() )
            {
                if ( null == (zDir = zDir.getParentFile()) )
                {
                    throw new ApplicationException( TEST_DATA_SUB_DIR + " Not Found off any of the following path: " + zOrigPath );
                }
            }
            return zTestDataDir.getCanonicalPath();
        }

        public static void writeOutLines( String pFileName, String pData )
                throws IOException
        {
            Utils.writeFile( getPath() + "/" + pFileName + ".out.txt", pData.replace( "\r\n", "\n" ) );
        }

        public static String readInLines( String pFileName )
                throws IOException
        {
            String zData = Utils.readFile( getPath() + "/" + pFileName + ".in.txt" );
            return zData.replace( "\r\n", "\n" );
        }
    }

    private static class XyzzyMapper implements WoxTypeMapper
    {
        private static final String NATIVE_PREFIX = "wox.serial.tests.SerializationTests$";
        private static final String WOX_PREFIX = "Xyzzy_";

        public String getNativeTypeFor( String pWoxType )
        {
            return pWoxType.startsWith( WOX_PREFIX ) ? NATIVE_PREFIX + pWoxType.substring( WOX_PREFIX.length() ) : pWoxType;
        }

        public String getWoxTypeFor( String pNativeType )
        {
            return pNativeType.startsWith( NATIVE_PREFIX ) ? WOX_PREFIX + pNativeType.substring( NATIVE_PREFIX.length() ) : pNativeType;
        }
    }

    @Override
    protected void setUp()
    {
        mEasy = new Easy();
        mEasy.add( new PatientIdentifierStringifier() );
        mEasy.add( new XyzzyMapper() );
    }

    private static void assertEquivalent( Object pExpected, Object pActual )
    {
        if ( !ComparisonUtilities.equivalent( pExpected, pActual ) )
        {
            Class zExpectedType = pExpected.getClass();
            Class zActualType = pActual.getClass();
            String zExpected = "" + zExpectedType + ":" + pExpected;
            String zActual = "" + zActualType + ":" + pActual;
            assertEquals( zExpected, zActual );
            assertEquals( "E:" + zExpected, "A:" + zActual );
        }
    }

    private void saveType( String pFileNameExpectedText, Object pObjectToSaveType )
            throws IOException
    {
        pFileNameExpectedText += "Type";

        String zPrettySerializedForm = mEasy.formatType( pObjectToSaveType );

        String zExpected;
        try
        {
            zExpected = TestData.readInLines( pFileNameExpectedText ).trim();
        }
        catch ( FileNotFoundException e )
        {
            TestData.writeOutLines( pFileNameExpectedText, zPrettySerializedForm );
            throw e;
        }
        if ( !zExpected.equals( zPrettySerializedForm ) )
        {
            TestData.writeOutLines( pFileNameExpectedText, zPrettySerializedForm );
            assertEquals( zExpected, zPrettySerializedForm );
        }
    }

    public Object fileRoundTripObjectEquivalent( String pFileName, Object pInObject )
            throws IOException
    {
        String zPrettySerializedForm = mEasy.format( pInObject, true ).replace( "\r\n", "\n" ).trim();

        String zExpected;
        try
        {
            zExpected = TestData.readInLines( pFileName ).trim();
        }
        catch ( FileNotFoundException e )
        {
            TestData.writeOutLines( pFileName, zPrettySerializedForm );
            throw e;
        }
        if ( !zExpected.equals( zPrettySerializedForm ) )
        {
            TestData.writeOutLines( pFileName, zPrettySerializedForm );
            assertEquals( zExpected, zPrettySerializedForm );
        }

        Object zDeserializedInstance = mEasy.parse( zPrettySerializedForm );

        assertEquivalent( pInObject, zDeserializedInstance );

        String zCompactSerializedForm = mEasy.format( pInObject );
        zDeserializedInstance = mEasy.parse( zCompactSerializedForm );
        assertEquivalent( pInObject, zDeserializedInstance );

        return zDeserializedInstance;
    }

    public void fileRoundTripSerializedForm( String pFileName )
            throws IOException
    {
        String zInXML = TestData.readInLines( pFileName ).trim();

        Object zDeserializedInstance = mEasy.parse( zInXML );

        String zOutXML = mEasy.format( zDeserializedInstance, true ).replace( "\r\n", "\n" ).trim();

        if ( !zInXML.equals( zOutXML ) )
        {
            TestData.writeOutLines( pFileName, zOutXML );
            assertEquals( zInXML, zOutXML );
        }
    }

    public void fileRoundTripSerializedFormNonPretty( String pFileNameNonPretty, String pFileNamePretty )
            throws IOException
    {
        String zInXML = TestData.readInLines( pFileNameNonPretty ).trim();

        Object zDeserializedInstance = mEasy.parse( zInXML );

        String zOutXML = mEasy.format( zDeserializedInstance, true ).replace( "\r\n", "\n" ).trim();

        zInXML = TestData.readInLines( pFileNamePretty ).trim();

        if ( !zInXML.equals( zOutXML ) )
        {
            TestData.writeOutLines( pFileNamePretty, zOutXML );
            assertEquals( zInXML, zOutXML );
        }
    }

    public static class ObjectWithByteFields
    {
        private byte m_B1;
        private byte m_B2;

        public byte getB1()
        {
            return m_B1;
        }

        public void setB1( int pB1 )
        {
            m_B1 = (byte) pB1;
        }

        public byte getB2()
        {
            return m_B2;
        }

        public void setB2( int pB2 )
        {
            m_B2 = (byte) pB2;
        }
    }

    public static class ObjectWithByteObjectFields
    {
        private Byte m_B1;
        private Byte m_B2;

        public byte getB1()
        {
            return m_B1;
        }

        public void setB1( int pB1 )
        {
            m_B1 = (byte) pB1;
        }

        public byte getB2()
        {
            return m_B2;
        }

        public void setB2( int pB2 )
        {
            m_B2 = (byte) pB2;
        }
    }

    public void testObjectWithByte()
            throws IOException
    {
        ObjectWithByteFields o1 = new ObjectWithByteFields();
        o1.setB1( 12 );
        o1.setB2( 99 );
        fileRoundTripObjectEquivalent( "ObjectWithByteFields", o1 );
        saveType( "ObjectWithByteFields", o1 );

        ObjectWithByteObjectFields o2 = new ObjectWithByteObjectFields();
        o2.setB1( 12 );
        o2.setB2( 99 );
        fileRoundTripObjectEquivalent( "ObjectWithByteObjectFields", o2 );
        saveType( "ObjectWithByteObjectFields", o2 );
    }

    public static class ComplexString
    {
        public String mTest = "\r\n\u000C \"Plus Some Text";
    }

    public void testComplexString()
    {
        ComplexString test = new ComplexString();
        String data = mEasy.format( test );
        assertFalse( data.contains( "\r" ) );
        assertFalse( data.contains( "\n" ) );
        assertFalse( data.contains( "\u000C" ) );
        assertEquals( test.mTest, ((ComplexString) mEasy.parse( data )).mTest );
    }

    public static class Enums
    {
        public PatientIDType mPatientIDType;
        public ServiceProviderIDType mProviderIDType;

        public Enums init()
        {
            mPatientIDType = PatientIDType.Ssn;
            mProviderIDType = ServiceProviderIDType.StateIssued;
            return this;
        }
    }

    public void testEnum()
            throws IOException
    {
        Enums zEnums = new Enums();
        fileRoundTripObjectEquivalent( "Enums", zEnums.init() );
        saveType( "Enums", zEnums );
    }

    public static class ArrayLists
    {
        public ArrayList mArrayList1;
        public ArrayList mArrayList2;
        public ArrayList mArrayList3;

        public ArrayLists init()
        {
            mArrayList1 = new ArrayList();
            mArrayList1.add( "Test" );
            mArrayList1.add( null );
            mArrayList1.add( 1 );

            mArrayList2 = new ArrayList();

            return this;
        }
    }

    public void testArrayLists()
            throws IOException
    {
        ArrayLists zArrayLists = new ArrayLists();
        fileRoundTripObjectEquivalent( "ArrayLists", zArrayLists.init() );
        saveType( "ArrayLists", zArrayLists );
    }

    public static class Hashtables
    {
        public Map mHashtable1;
        public Map mHashtable2;
        public Map mHashtable3;

        public Hashtables init()
        {
            mHashtable1 = new HashMap();
            mHashtable1.put( "A", "Test" );
            mHashtable1.put( "C", null );
            mHashtable1.put( "B", 1 );

            mHashtable2 = new HashMap();

            return this;
        }
    }

    public void testHashtables()
            throws IOException
    {
        Hashtables zHashtables = new Hashtables();
        fileRoundTripObjectEquivalent( "Hashtables", zHashtables.init() );
        saveType( "Hashtables", zHashtables );
    }

    public static class GenericLists
    {
        public List<String> mGenericList1;
        public List<Integer> mGenericList2;
        public List<PatientIdentifier> mGenericList3;
        public List<String> mGenericList4;
        public List<String> mGenericList5;

        public GenericLists init()
        {
            mGenericList1 = new ArrayList<String>();
            mGenericList1.add( "Test" );
            mGenericList1.add( null );

            mGenericList2 = new ArrayList<Integer>();
            mGenericList2.add( 1 );

            mGenericList3 = new ArrayList<PatientIdentifier>();
            mGenericList3.add( new PatientIdentifier( PatientIDType.DriversLicense, "XYZZY1234" ) );

            mGenericList4 = new ArrayList<String>();

            return this;
        }
    }

    public void testGenericLists()
            throws IOException
    {
        GenericLists zGenericLists = new GenericLists();
        fileRoundTripObjectEquivalent( "GenericLists", zGenericLists.init() );
        saveType( "GenericListsJava", zGenericLists );
    }

    public static class GenericDictionarys
    {
        public HashMap<String, String> mGenericDictionary1;
        public HashMap<Integer, String> mGenericDictionary2;
        public HashMap<String, PatientIdentifier> mGenericDictionary3;
        public HashMap<String, String> mGenericDictionary4;
        public HashMap<String, String> mGenericDictionary5;
        public HashMap<String, HashMap<String, String>> mGenGen;

        public GenericDictionarys init()
        {
            mGenericDictionary1 = new HashMap<String, String>();
            mGenericDictionary1.put( "A1", "Test" );
            mGenericDictionary1.put( "B2", null );

            mGenericDictionary2 = new HashMap<Integer, String>();
            mGenericDictionary2.put( 1, "Test2" );

            mGenericDictionary3 = new HashMap<String, PatientIdentifier>();
            mGenericDictionary3.put( "4", new PatientIdentifier( PatientIDType.DriversLicense, "XYZZY1234" ) );

            mGenericDictionary4 = new HashMap<String, String>();

            mGenGen = new HashMap<String, HashMap<String, String>>();

            return this;
        }
    }

    public void testGenericDictionarys()
            throws IOException
    {
        GenericDictionarys zGenericDictionarys = new GenericDictionarys();
        fileRoundTripObjectEquivalent( "GenericDictionarys", zGenericDictionarys.init() );
        saveType( "GenericDictionarysJava", zGenericDictionarys );
    }

    public static class ArraySamples
    {
        public int[] mArray1;
        public String[] mArray2;
        public String[] mArray3;
        public String[] mArray4;
        public PatientIdentifier[] mPIs;
        public int[][] mIntOfInts;

        public ArraySamples init()
        {
            mArray1 = new int[]{1, 2, 3, 4};
            mArray2 = new String[0];
            mArray3 = new String[]{"Test", "of", "the", "american", "broadcasting system"};
            mPIs = new PatientIdentifier[]{new PatientIdentifier( PatientIDType.DriversLicense, "XYZZY1234" ),};
            mIntOfInts = new int[][]{new int[0], new int[]{5, 6, 7}};

            return this;
        }
    }

    public void testArraySamples()
            throws IOException
    {
        ArraySamples zArraySamples = new ArraySamples();
        fileRoundTripObjectEquivalent( "ArraySamples", zArraySamples.init() );
        saveType( "ArraySamples", zArraySamples );
    }

    public static class Decimals
    {
        public BigDecimal mDec1;
        public BigDecimal mDec2;
        public BigDecimal mDec3;

        public Decimals init()
        {
            mDec3 = new BigDecimal( "42.7" );
            mDec2 = new BigDecimal( "0.5" );
            mDec1 = new BigDecimal( "42" );
            return this;
        }
    }

    public void testDecimal()
            throws IOException
    {
        Decimals zDecimals = new Decimals();
        fileRoundTripObjectEquivalent( "Decimals", zDecimals.init() );
        saveType( "DecimalsJava", zDecimals );
    }

    public static class Primatives
    {
        public boolean mBoolean1;
        public Boolean mBoolean2;
        public char mChar1;
        public Character mChar2;
        public byte mByte1;
        public Byte mByte2;
        public short mShort1;
        public Short mShort2;
        public int mInt1;
        public Integer mInt2;
        public long mLong1;
        public Long mLong2;
        public float mSingle1;
        public Float mSingle2;
        public double mDouble1;
        public Double mDouble2;

        public Primatives init()
        {
            mBoolean1 = true;
            mBoolean2 = true;
            mChar1 = 'Z';
            mChar2 = 'Z';
            mByte1 = 42;
            mByte2 = 42;
            mShort1 = 42;
            mShort2 = 42;
            mInt1 = 42;
            mInt2 = 42;
            mLong1 = 42L;
            mLong2 = 42L;
            mSingle1 = -34.56F;
            mSingle2 = -34.56F;
            mDouble1 = 34.56;
            mDouble2 = 34.56;
            return this;
        }
    }

    public void testPrimatives()
            throws IOException
    {
        Primatives zPrimative = new Primatives().init();
        fileRoundTripObjectEquivalent( "Primatives", zPrimative );
        saveType( "Primatives", zPrimative );

        assertNonPrimative( zPrimative.mBoolean1, Boolean.class );
        assertNonPrimative( zPrimative.mBoolean2, Boolean.class );
        assertNonPrimative( zPrimative.mChar1, Character.class );
        assertNonPrimative( zPrimative.mChar2, Character.class );
        assertNonPrimative( zPrimative.mShort1, Short.class );
        assertNonPrimative( zPrimative.mShort2, Short.class );
        assertNonPrimative( zPrimative.mInt1, Integer.class );
        assertNonPrimative( zPrimative.mInt2, Integer.class );
        assertNonPrimative( zPrimative.mLong1, Long.class );
        assertNonPrimative( zPrimative.mLong2, Long.class );
        assertNonPrimative( zPrimative.mSingle1, Float.class );
        assertNonPrimative( zPrimative.mSingle2, Float.class );
        assertNonPrimative( zPrimative.mDouble1, Double.class );
        assertNonPrimative( zPrimative.mDouble2, Double.class );
    }

    private static void assertNonPrimative( Object pWhat, Class pType )
    {
        Class zType = pWhat.getClass();
        assertEquals( pType, zType );
        assertFalse( zType + " == Primitive", zType.isPrimitive() );
    }

    private static void assertReferenceType( Object pWhat, Class pType )
    {
        Class zType = pWhat.getClass();
        assertEquals( pType, zType );
        assertFalse( zType + " == Primitive", zType.isPrimitive() );
    }

    public static class WishWerePrimatives
    {
        public BigDecimal mDecimal1;
        public BigDecimal mDecimal2;

        public String mString1;
        public String mString2;

        public WishWerePrimatives init()
        {
            mDecimal1 = new BigDecimal( "34.56" );
            mDecimal2 = new BigDecimal( "34.56" );
            mString1 = "Fee Fie Foe Fum";
            mString2 = "Fee Fie Foe Fum";
            return this;
        }
    }

    public void testWishWerePrimatives()
            throws IOException
    {
        WishWerePrimatives zWishWerePrimative = new WishWerePrimatives().init();
        fileRoundTripObjectEquivalent( "WishWerePrimatives", zWishWerePrimative );
        saveType( "WishWerePrimativesJava", zWishWerePrimative );

        assertNonPrimative( zWishWerePrimative.mDecimal1, BigDecimal.class );
        assertNonPrimative( zWishWerePrimative.mDecimal2, BigDecimal.class );

        assertReferenceType( zWishWerePrimative.mString1, String.class );
        assertReferenceType( zWishWerePrimative.mString2, String.class );
    }

    public static class WrappedPrimitives
    {
        public Boolean mBoolean1;
        public Character mChar1;
        public Byte mByte1;
        public Short mShort1;
        public Integer mInt1;
        public Long mLong1;
        public Float mSingle1;
        public Double mDouble1;

        public Boolean mBoolean2;
        public Character mChar2;
        public Byte mByte2;
        public Short mShort2;
        public Integer mInt2;
        public Long mLong2;
        public Float mSingle2;
        public Double mDouble2;

        public WrappedPrimitives init()
        {
            mBoolean1 = true;
            mChar1 = 'Z';
            mByte1 = 42;
            mShort1 = 42;
            mInt1 = 42;
            mLong1 = 42L;
            mSingle1 = -34.56F;
            mDouble1 = 34.56;
            return this;
        }
    }

    public void testWrappedPrimitives()
            throws IOException
    {
        WrappedPrimitives zWrappedPrimitive = new WrappedPrimitives().init();
        fileRoundTripObjectEquivalent( "WrappedPrimitives", zWrappedPrimitive );
        saveType( "WrappedPrimitives", zWrappedPrimitive );

        assertNonPrimative( zWrappedPrimitive.mBoolean1, Boolean.class );
        assertNull( zWrappedPrimitive.mBoolean2 );
        assertNonPrimative( zWrappedPrimitive.mChar1, Character.class );
        assertNull( zWrappedPrimitive.mChar2 );
        assertNonPrimative( zWrappedPrimitive.mShort1, Short.class );
        assertNull( zWrappedPrimitive.mShort2 );
        assertNonPrimative( zWrappedPrimitive.mInt1, Integer.class );
        assertNull( zWrappedPrimitive.mInt2 );
        assertNonPrimative( zWrappedPrimitive.mLong1, Long.class );
        assertNull( zWrappedPrimitive.mLong2 );
        assertNonPrimative( zWrappedPrimitive.mSingle1, Float.class );
        assertNull( zWrappedPrimitive.mSingle2 );
        assertNonPrimative( zWrappedPrimitive.mDouble1, Double.class );
        assertNull( zWrappedPrimitive.mDouble2 );
    }

    public static class WrappedWishWerePrimitives
    {
        public BigDecimal mDecimal1;
        public BigDecimal mDecimal2;

        public WrappedWishWerePrimitives init()
        {
            mDecimal1 = new BigDecimal( "34.56" );
            return this;
        }
    }

    public void testWrappedWishWerePrimitives()
            throws IOException
    {
        WrappedWishWerePrimitives zWrappedWishWerePrimitive = new WrappedWishWerePrimitives().init();
        fileRoundTripObjectEquivalent( "WrappedWishWerePrimitives", zWrappedWishWerePrimitive );
        saveType( "WrappedWishWerePrimitives", zWrappedWishWerePrimitive );

        assertNonPrimative( zWrappedWishWerePrimitive.mDecimal1, BigDecimal.class );

        assertNull( zWrappedWishWerePrimitive.mDecimal2 );
    }

    public static class DateTimeCarrier
    {
        private Date mDateTime1;
        public Date mDateTime2;
        public Date mDateTime3;

        public DateTimeCarrier init()
        {
            Date zDateTime = new Date( Date.parse( "1/24/2010 3:23:36 AM" ) );
            mDateTime2 = mDateTime1 = zDateTime;
            return this;
        }

        public Date getDateTime1()
        {
            return mDateTime1;
        }

        public void setDateTime1( Date pDateTime1 )
        {
            mDateTime1 = pDateTime1;
        }
    }

    public void testDate()
            throws IOException
    {
        DateTimeCarrier zCarrier = new DateTimeCarrier().init();
        fileRoundTripObjectEquivalent( "DateTimeCarrier", zCarrier );
        saveType( "DateTimeCarrierJava", zCarrier );

        String zDateAsString = "1957/01/04-13:14:15.016";

        DateTimeConverter zConverter = new DateTimeConverter().attemptParse( zDateAsString );
        Date zDate = zConverter.toDate();
        assertEquals( zDateAsString, new DateTimeConverter( zDate ).toString() );
    }

    public void testBooleanAssumptions()
    {
        assertEquals( "false", Boolean.FALSE.toString() );
        assertEquals( "true", Boolean.TRUE.toString() );
    }

    private boolean mBool1 = true;
    private Boolean mBool2;

    private boolean[] mBoolArray1 = new boolean[]{true};
    private Boolean[] mBoolArray2 = new Boolean[]{true, null};

    public void testWrappedDiff()
    {
        mBool1 = false;
        mBool2 = false;

        Class zType1 = ((Object) mBool1).getClass();
        Class zType2 = mBool2.getClass();

        assertFalse( zType1.isPrimitive() );
        assertFalse( zType2.isPrimitive() );

        assertTrue( zType1 == zType2 );

        zType1 = boolean.class;
        zType2 = Boolean.class;

        assertTrue( zType1.isPrimitive() );
        assertFalse( zType2.isPrimitive() );

        assertFalse( zType1 == zType2 );

        assertTrue( zType1.isAssignableFrom( boolean.class ) );
        assertFalse( zType1.isAssignableFrom( Boolean.class ) );

        assertFalse( zType2.isAssignableFrom( boolean.class ) );
        assertTrue( zType2.isAssignableFrom( Boolean.class ) );

        String zFoundName = null;

        Field[] zFields = getClass().getDeclaredFields();

        for ( Field zInfo : zFields )
        {
            Class t = zInfo.getType();
            if ( !t.isArray() && !t.isPrimitive() && !"mEasy".equals( zInfo.getName() ) )
            {
                assertNull( zFoundName );
                zFoundName = zInfo.getName();
            }
        }

        assertEquals( "mBool2", zFoundName );

        assertEquals( boolean.class, mBoolArray1.getClass().getComponentType() );
        assertEquals( Boolean.class, mBoolArray2.getClass().getComponentType() );
    }

    public void testArrayResolve()
    {
        int[] zInts = new int[0];
        Class zClass = zInts.getClass();

        assertTrue( zClass.isArray() );

        assertEquals( "int", zClass.getComponentType().getName() );

        String zRealName = "int[]";
        String zTypeString = zClass.getName();

        assertTrue( zRealName + " != " + zTypeString, !zRealName.equals( zTypeString ) );

        assertNull( zTypeString, Util.resolveType( zTypeString ) );
        assertNull( zRealName, Util.resolveType( zRealName ) );

        Object zNewArray = Array.newInstance( zClass.getComponentType(), 0 );

        assertEquals( zClass, zNewArray.getClass() );
    }
}

Commits for WOX2/trunk/Java/tests/wox/serial/tests/SerializationTests.java

Diff revisions: vs.
Revision Author Commited Message
17 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 23:44:02 +0000

Extracting commonfoundation

15 Diff Diff GeorgeS picture GeorgeS Fri 19 Feb, 2010 22:29:49 +0000
7 Diff Diff GeorgeS picture GeorgeS Fri 05 Feb, 2010 19:14:48 +0000
5 Diff Diff GeorgeS picture GeorgeS Fri 05 Feb, 2010 18:59:04 +0000
4 Diff Diff GeorgeS picture GeorgeS Fri 05 Feb, 2010 18:15:55 +0000
3 GeorgeS picture GeorgeS Thu 04 Feb, 2010 23:53:47 +0000