| 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 java.util.*;
|
|
|
24 |
import thrift.test.*;
|
|
|
25 |
|
|
|
26 |
public class Fixtures {
|
|
|
27 |
public static final OneOfEach oneOfEach;
|
|
|
28 |
public static final Nesting nesting;
|
|
|
29 |
public static final HolyMoley holyMoley;
|
|
|
30 |
public static final CompactProtoTestStruct compactProtoTestStruct;
|
|
|
31 |
|
|
|
32 |
private static final byte[] kUnicodeBytes = {
|
|
|
33 |
(byte)0xd3, (byte)0x80, (byte)0xe2, (byte)0x85, (byte)0xae, (byte)0xce,
|
|
|
34 |
(byte)0x9d, (byte)0x20, (byte)0xd0, (byte)0x9d, (byte)0xce, (byte)0xbf,
|
|
|
35 |
(byte)0xe2, (byte)0x85, (byte)0xbf, (byte)0xd0, (byte)0xbe, (byte)0xc9,
|
|
|
36 |
(byte)0xa1, (byte)0xd0, (byte)0xb3, (byte)0xd0, (byte)0xb0, (byte)0xcf,
|
|
|
37 |
(byte)0x81, (byte)0xe2, (byte)0x84, (byte)0x8e, (byte)0x20, (byte)0xce,
|
|
|
38 |
(byte)0x91, (byte)0x74, (byte)0x74, (byte)0xce, (byte)0xb1, (byte)0xe2,
|
|
|
39 |
(byte)0x85, (byte)0xbd, (byte)0xce, (byte)0xba, (byte)0x83, (byte)0xe2,
|
|
|
40 |
(byte)0x80, (byte)0xbc
|
|
|
41 |
};
|
|
|
42 |
|
|
|
43 |
static {
|
|
|
44 |
try {
|
|
|
45 |
oneOfEach = new OneOfEach();
|
|
|
46 |
oneOfEach.im_true = true;
|
|
|
47 |
oneOfEach.im_false = false;
|
|
|
48 |
oneOfEach.a_bite = (byte) 0xd6;
|
|
|
49 |
oneOfEach.integer16 = 27000;
|
|
|
50 |
oneOfEach.integer32 = 1 << 24;
|
|
|
51 |
oneOfEach.integer64 = (long) 6000 * 1000 * 1000;
|
|
|
52 |
oneOfEach.double_precision = Math.PI;
|
|
|
53 |
oneOfEach.some_characters = "JSON THIS! \"\1";
|
|
|
54 |
oneOfEach.zomg_unicode = new String(kUnicodeBytes, "UTF-8");
|
|
|
55 |
oneOfEach.base64 = "base64".getBytes();
|
|
|
56 |
// byte, i16, and i64 lists are populated by default constructor
|
|
|
57 |
|
|
|
58 |
Bonk bonk = new Bonk();
|
|
|
59 |
bonk.type = 31337;
|
|
|
60 |
bonk.message = "I am a bonk... xor!";
|
|
|
61 |
nesting = new Nesting(bonk, oneOfEach);
|
|
|
62 |
|
|
|
63 |
holyMoley = new HolyMoley();
|
|
|
64 |
holyMoley.big = new ArrayList<OneOfEach>();
|
|
|
65 |
holyMoley.big.add(new OneOfEach(oneOfEach));
|
|
|
66 |
holyMoley.big.add(nesting.my_ooe);
|
|
|
67 |
holyMoley.big.get(0).a_bite = (byte) 0x22;
|
|
|
68 |
holyMoley.big.get(1).a_bite = (byte) 0x23;
|
|
|
69 |
|
|
|
70 |
holyMoley.contain = new HashSet<List<String>>();
|
|
|
71 |
ArrayList<String> stage1 = new ArrayList<String>(2);
|
|
|
72 |
stage1.add("and a one");
|
|
|
73 |
stage1.add("and a two");
|
|
|
74 |
holyMoley.contain.add(stage1);
|
|
|
75 |
stage1 = new ArrayList<String>(3);
|
|
|
76 |
stage1.add("then a one, two");
|
|
|
77 |
stage1.add("three!");
|
|
|
78 |
stage1.add("FOUR!!");
|
|
|
79 |
holyMoley.contain.add(stage1);
|
|
|
80 |
stage1 = new ArrayList<String>(0);
|
|
|
81 |
holyMoley.contain.add(stage1);
|
|
|
82 |
|
|
|
83 |
ArrayList<Bonk> stage2 = new ArrayList<Bonk>();
|
|
|
84 |
holyMoley.bonks = new HashMap<String, List<Bonk>>();
|
|
|
85 |
// one empty
|
|
|
86 |
holyMoley.bonks.put("zero", stage2);
|
|
|
87 |
|
|
|
88 |
// one with two
|
|
|
89 |
stage2 = new ArrayList<Bonk>();
|
|
|
90 |
Bonk b = new Bonk();
|
|
|
91 |
b.type = 1;
|
|
|
92 |
b.message = "Wait.";
|
|
|
93 |
stage2.add(b);
|
|
|
94 |
b = new Bonk();
|
|
|
95 |
b.type = 2;
|
|
|
96 |
b.message = "What?";
|
|
|
97 |
stage2.add(b);
|
|
|
98 |
holyMoley.bonks.put("two", stage2);
|
|
|
99 |
|
|
|
100 |
// one with three
|
|
|
101 |
stage2 = new ArrayList<Bonk>();
|
|
|
102 |
b = new Bonk();
|
|
|
103 |
b.type = 3;
|
|
|
104 |
b.message = "quoth";
|
|
|
105 |
b = new Bonk();
|
|
|
106 |
b.type = 4;
|
|
|
107 |
b.message = "the raven";
|
|
|
108 |
b = new Bonk();
|
|
|
109 |
b.type = 5;
|
|
|
110 |
b.message = "nevermore";
|
|
|
111 |
holyMoley.bonks.put("three", stage2);
|
|
|
112 |
|
|
|
113 |
// superhuge compact proto test struct
|
|
|
114 |
compactProtoTestStruct = new CompactProtoTestStruct(thrift.test.Constants.COMPACT_TEST);
|
|
|
115 |
compactProtoTestStruct.a_binary = new byte[]{0,1,2,3,4,5,6,7,8};
|
|
|
116 |
} catch (Exception e) {
|
|
|
117 |
throw new RuntimeException(e);
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
}
|