]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | package org.apache.thrift.scheme; |
2 | ||
3 | import junit.framework.TestCase; | |
4 | ||
5 | import org.apache.thrift.Fixtures; | |
6 | import org.apache.thrift.TBase; | |
7 | import org.apache.thrift.TDeserializer; | |
8 | import org.apache.thrift.TException; | |
9 | import org.apache.thrift.TSerializer; | |
10 | import org.apache.thrift.protocol.TBinaryProtocol; | |
11 | import org.apache.thrift.protocol.TProtocol; | |
12 | import org.apache.thrift.transport.TMemoryBuffer; | |
13 | import org.apache.thrift.transport.TTransport; | |
14 | ||
15 | import thrift.test.HolyMoley; | |
16 | import thrift.test.Nesting; | |
17 | import thrift.test.OneOfEach; | |
18 | ||
19 | public class TestStandardScheme extends TestCase { | |
20 | TSerializer serializer = new TSerializer(); | |
21 | TDeserializer deserializer = new TDeserializer(); | |
22 | ||
23 | /** | |
24 | * This tests whether the Standard Scheme properly reads structs serialized | |
25 | * using an older version of thrift. | |
26 | */ | |
27 | public void testPersistentStructs() throws TException { | |
28 | readAndCompare(new OneOfEach(), Fixtures.oneOfEach, Fixtures.persistentBytesOneOfEach); | |
29 | readAndCompare(new HolyMoley(), Fixtures.holyMoley, Fixtures.persistentBytesHolyMoley); | |
30 | readAndCompare(new Nesting(), Fixtures.nesting, Fixtures.persistentBytesNesting); | |
31 | } | |
32 | ||
33 | public void readAndCompare(TBase struct, TBase fixture, byte[] inputBytes) throws TException { | |
34 | TTransport trans = new TMemoryBuffer(0); | |
35 | trans.write(inputBytes, 0, inputBytes.length); | |
36 | TProtocol iprot = new TBinaryProtocol(trans); | |
37 | struct.read(iprot); | |
38 | assertEquals(fixture, struct); | |
39 | } | |
40 | } |