01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.dna.impl;
05:
06: import com.tc.io.TCByteBufferInputStream;
07: import com.tc.io.TCByteBufferOutputStream;
08:
09: import java.io.IOException;
10:
11: import junit.framework.TestCase;
12:
13: public class ObjectStringSerializerTest extends TestCase {
14:
15: public void test() throws IOException {
16: // write it
17: TCByteBufferOutputStream out = new TCByteBufferOutputStream();
18: ObjectStringSerializer ser = new ObjectStringSerializer();
19:
20: ser.writeFieldName(out, "className.fieldName");
21: ser.writeString(out, "timmy teck");
22: ser.writeFieldName(out, "className.fieldName");
23: ser.writeString(out, "timmy teck");
24:
25: // cook it
26: TCByteBufferOutputStream data = new TCByteBufferOutputStream();
27: ser.serializeTo(data);
28: data.write(out.toArray());
29:
30: // read it
31: TCByteBufferInputStream in = new TCByteBufferInputStream(data
32: .toArray());
33: ObjectStringSerializer ser2 = new ObjectStringSerializer();
34: ser2.deserializeFrom(in);
35:
36: String fn1 = ser2.readFieldName(in);
37: String s1 = ser2.readString(in);
38: String fn2 = ser2.readFieldName(in);
39: String s2 = ser2.readString(in);
40:
41: assertEquals("className.fieldName", fn1);
42: assertEquals("timmy teck", s1);
43: assertEquals("className.fieldName", fn2);
44: assertEquals("timmy teck", s2);
45: }
46:
47: }
|