Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements. See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership. The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License. You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied. See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
 
20
package org.apache.thrift.test;
21
 
22
// Generated code
23
import java.io.ByteArrayInputStream;
24
import java.io.ByteArrayOutputStream;
25
import java.io.ObjectInputStream;
26
import java.io.ObjectOutputStream;
27
import java.util.ArrayList;
28
import java.util.HashMap;
29
import java.util.HashSet;
30
import java.util.List;
31
 
32
import org.apache.thrift.TDeserializer;
33
import org.apache.thrift.TSerializer;
34
import org.apache.thrift.protocol.TBinaryProtocol;
35
 
36
import thrift.test.Bonk;
37
import thrift.test.HolyMoley;
38
import thrift.test.Nesting;
39
import thrift.test.OneOfEach;
40
 
41
/**
42
 *
43
 */
44
public class IdentityTest {
45
  public static Object deepCopy(Object oldObj) throws Exception {
46
    ObjectOutputStream oos = null;
47
    ObjectInputStream ois = null;
48
    try {
49
      ByteArrayOutputStream bos =
50
        new ByteArrayOutputStream();
51
      oos = new ObjectOutputStream(bos);
52
      oos.writeObject(oldObj);
53
      oos.flush();
54
      ByteArrayInputStream bis =
55
        new ByteArrayInputStream(bos.toByteArray());
56
      ois = new ObjectInputStream(bis);
57
      return ois.readObject();
58
    } finally {
59
      oos.close();
60
      ois.close();
61
    }
62
  }
63
 
64
  public static void main(String[] args) throws Exception {
65
    TSerializer   binarySerializer   = new   TSerializer(new TBinaryProtocol.Factory());
66
    TDeserializer binaryDeserializer = new TDeserializer(new TBinaryProtocol.Factory());
67
 
68
    OneOfEach ooe = Fixtures.oneOfEach;
69
 
70
    Nesting n = new Nesting();
71
    n.my_ooe = (OneOfEach)deepCopy(ooe);
72
    n.my_ooe.integer16 = 16;
73
    n.my_ooe.integer32 = 32;
74
    n.my_ooe.integer64 = 64;
75
    n.my_ooe.double_precision = (Math.sqrt(5)+1)/2;
76
    n.my_ooe.some_characters  = ":R (me going \"rrrr\")";
77
    n.my_ooe.zomg_unicode     = "\u04c0\u216e\u039d\u0020\u041d\u03bf\u217f"+
78
                                "\u043e\u0261\u0433\u0430\u03c1\u210e\u0020"+
79
                                "\u0391\u0074\u0074\u03b1\u217d\u03ba\u01c3"+
80
                                "\u203c";
81
    n.my_bonk = Fixtures.nesting.my_bonk;
82
 
83
    HolyMoley hm = Fixtures.holyMoley;
84
 
85
    OneOfEach ooe2 = new OneOfEach();
86
    binaryDeserializer.deserialize(
87
        ooe2,
88
        binarySerializer.serialize(ooe));
89
 
90
    if (!ooe.equals(ooe2)) {
91
      throw new RuntimeException("Failure: ooe (equals)");
92
    }
93
    if (ooe.hashCode() != ooe2.hashCode()) {
94
      throw new RuntimeException("Failure: ooe (hash)");
95
    }
96
 
97
 
98
    Nesting n2 = new Nesting();
99
    binaryDeserializer.deserialize(
100
        n2,
101
        binarySerializer.serialize(n));
102
 
103
    if (!n.equals(n2)) {
104
      throw new RuntimeException("Failure: n (equals)");
105
    }
106
    if (n.hashCode() != n2.hashCode()) {
107
      throw new RuntimeException("Failure: n (hash)");
108
    }
109
 
110
    HolyMoley hm2 = new HolyMoley();
111
    binaryDeserializer.deserialize(
112
        hm2,
113
        binarySerializer.serialize(hm));
114
 
115
    if (!hm.equals(hm2)) {
116
      throw new RuntimeException("Failure: hm (equals)");
117
    }
118
    if (hm.hashCode() != hm2.hashCode()) {
119
      throw new RuntimeException("Failure: hm (hash)");
120
    }
121
 
122
  }
123
}