File: TestStandardScheme.java

package info (click to toggle)
libthrift-java 0.9.1-2.1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,192 kB
  • sloc: java: 12,634; xml: 299; makefile: 13
file content (40 lines) | stat: -rw-r--r-- 1,454 bytes parent folder | download | duplicates (5)
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
package org.apache.thrift.scheme;

import junit.framework.TestCase;

import org.apache.thrift.Fixtures;
import org.apache.thrift.TBase;
import org.apache.thrift.TDeserializer;
import org.apache.thrift.TException;
import org.apache.thrift.TSerializer;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TMemoryBuffer;
import org.apache.thrift.transport.TTransport;

import thrift.test.HolyMoley;
import thrift.test.Nesting;
import thrift.test.OneOfEach;

public class TestStandardScheme extends TestCase {
  TSerializer serializer = new TSerializer();
  TDeserializer deserializer = new TDeserializer();

  /**
   * This tests whether the Standard Scheme properly reads structs serialized
   * using an older version of thrift.
   */
  public void testPersistentStructs() throws TException {
    readAndCompare(new OneOfEach(), Fixtures.oneOfEach, Fixtures.persistentBytesOneOfEach);
    readAndCompare(new HolyMoley(), Fixtures.holyMoley, Fixtures.persistentBytesHolyMoley);
    readAndCompare(new Nesting(), Fixtures.nesting, Fixtures.persistentBytesNesting);
  }

  public void readAndCompare(TBase struct, TBase fixture, byte[] inputBytes) throws TException {
    TTransport trans = new TMemoryBuffer(0);
    trans.write(inputBytes, 0, inputBytes.length);
    TProtocol iprot = new TBinaryProtocol(trans);
    struct.read(iprot);
    assertEquals(fixture, struct);
  }
}