Subversion Repositories SmartDukaan

Rev

Rev 30 | Details | Compare with Previous | 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
 
21
package org.apache.thrift.test;
22
 
23
import org.apache.thrift.TDeserializer;
24
import org.apache.thrift.TSerializer;
25
import org.apache.thrift.protocol.TBinaryProtocol;
26
import thrift.test.*;
27
import java.util.ArrayList;
28
import java.util.HashMap;
29
import java.util.HashSet;
30
import java.util.List;
31
 
32
public class DeepCopyTest {
33
  public static void main(String[] args) throws Exception {
34
    TSerializer   binarySerializer   = new   TSerializer(new TBinaryProtocol.Factory());
35
    TDeserializer binaryDeserializer = new TDeserializer(new TBinaryProtocol.Factory());
36
 
37
    HolyMoley hm = Fixtures.holyMoley;
38
 
39
    byte[] binaryCopy = binarySerializer.serialize(hm);
40
    HolyMoley hmCopy = new HolyMoley();
41
    binaryDeserializer.deserialize(hmCopy, binaryCopy);
42
    HolyMoley hmCopy2 = new HolyMoley(hm);
43
 
44
    if (!hm.equals(hmCopy))
45
      throw new RuntimeException("copy constructor modified the original object!");
46
    if (!hmCopy.equals(hmCopy2))
47
      throw new RuntimeException("copy constructor generated incorrect copy");
48
 
49
    hm.big.get(0).base64[0]++; // change binary value in original object
50
    if (hm.equals(hmCopy2)) // make sure the change didn't propagate to the copied object
51
      throw new RuntimeException("Binary field not copied correctly!");
52
    hm.big.get(0).base64[0]--; // undo change
53
 
54
    hmCopy2.bonks.get("two").get(1).message = "What else?";
55
 
56
    if (hm.equals(hmCopy2))
57
      throw new RuntimeException("A deep copy was not done!");
58
 
59
  }
60
}