]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // Licensed to the Apache Software Foundation(ASF) under one |
2 | // or more contributor license agreements.See the NOTICE file | |
3 | // distributed with this work for additional information | |
4 | // regarding copyright ownership.The ASF licenses this file | |
5 | // to you under the Apache License, Version 2.0 (the | |
6 | // "License"); you may not use this file except in compliance | |
7 | // with the License. You may obtain a copy of the License at | |
8 | // | |
9 | // http://www.apache.org/licenses/LICENSE-2.0 | |
10 | // | |
11 | // Unless required by applicable law or agreed to in writing, | |
12 | // software distributed under the License is distributed on an | |
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | // KIND, either express or implied. See the License for the | |
15 | // specific language governing permissions and limitations | |
16 | // under the License. | |
17 | ||
18 | #include <thrift/parse/t_program.h> | |
19 | #include "thrift/common.h" | |
20 | #include <thrift/generate/t_netcore_generator.h> | |
21 | #include "t_netcore_generator_functional_tests_helpers.h" | |
22 | ||
23 | const string TestDataGenerator::DEFAULT_FILE_HEADER = "/**" "\n" | |
24 | " * Autogenerated by Thrift Compiler ()" "\n" | |
25 | " *" "\n" | |
26 | " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING" "\n" | |
27 | " * @generated" "\n" | |
28 | " */"; | |
29 | ||
30 | std::pair<string, t_enum*> TestDataGenerator::get_test_enum_data(t_program* program) | |
31 | { | |
32 | string expected_result = DEFAULT_FILE_HEADER + | |
33 | "\n" | |
34 | "\n" | |
35 | "/// <summary>\n" | |
36 | "/// TestDoc\n" | |
37 | "/// </summary>\n" | |
38 | "public enum TestName\n" | |
39 | "{\n" | |
40 | " None = 0,\n" | |
41 | " First = 1,\n" | |
42 | " Second = 2,\n" | |
43 | "}\n"; | |
44 | ||
45 | t_enum* enum_ = new t_enum(program); | |
46 | enum_->set_name("TestName"); | |
47 | enum_->set_doc("TestDoc"); | |
48 | enum_->append(new t_enum_value("None", 0)); | |
49 | enum_->append(new t_enum_value("First", 1)); | |
50 | enum_->append(new t_enum_value("Second", 2)); | |
51 | ||
52 | return std::pair<string, t_enum*>(expected_result, enum_); | |
53 | } | |
54 | ||
55 | std::pair<string, t_const*> TestDataGenerator::get_test_void_const_data(t_netcore_generator* gen) | |
56 | { | |
57 | string expected_result = DEFAULT_FILE_HEADER; | |
58 | ||
59 | t_type* type_ = new t_base_type("void", t_base_type::TYPE_VOID); | |
60 | type_->set_doc("TestDoc"); | |
61 | ||
62 | t_const_value* const_value_ = new t_const_value(); | |
63 | const_value_->set_string("VoidValue"); | |
64 | ||
65 | t_const* const_ = new t_const(type_, "void", const_value_); | |
66 | const_->set_doc("TestDoc"); | |
67 | ||
68 | return std::pair<string, t_const*>(expected_result, const_); | |
69 | } | |
70 | ||
71 | std::pair<string, t_const*> TestDataGenerator::get_test_string_const_data(t_netcore_generator* gen) | |
72 | { | |
73 | string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + | |
74 | "\n" | |
75 | "public static class netcoreConstants\n" | |
76 | "{\n" | |
77 | " /// <summary>\n" | |
78 | " /// TestDoc\n" | |
79 | " /// </summary>\n" | |
80 | " public const string @string = \"StringValue\";\n" | |
81 | "}\n"; | |
82 | ||
83 | t_type* type_ = new t_base_type("string", t_base_type::TYPE_STRING); | |
84 | type_->set_doc("TestDoc"); | |
85 | ||
86 | t_const_value* const_value_ = new t_const_value(); | |
87 | const_value_->set_string("StringValue"); | |
88 | ||
89 | t_const* const_ = new t_const(type_, "string", const_value_); | |
90 | const_->set_doc("TestDoc"); | |
91 | ||
92 | return std::pair<string, t_const*>(expected_result, const_); | |
93 | } | |
94 | ||
95 | std::pair<string, t_const*> TestDataGenerator::get_test_bool_const_data(t_netcore_generator* gen) | |
96 | { | |
97 | string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + | |
98 | "\n" | |
99 | "public static class netcoreConstants\n" | |
100 | "{\n" | |
101 | " /// <summary>\n" | |
102 | " /// TestDoc\n" | |
103 | " /// </summary>\n" | |
104 | " public const bool @bool = true;\n" | |
105 | "}\n"; | |
106 | ||
107 | t_type* type_ = new t_base_type("bool", t_base_type::TYPE_BOOL); | |
108 | type_->set_doc("TestDoc"); | |
109 | ||
110 | t_const_value* const_value_ = new t_const_value(); | |
111 | const_value_->set_integer(1); | |
112 | ||
113 | t_const* const_ = new t_const(type_, "bool", const_value_); | |
114 | const_->set_doc("TestDoc"); | |
115 | ||
116 | return std::pair<string, t_const*>(expected_result, const_); | |
117 | } | |
118 | ||
119 | std::pair<string, t_const*> TestDataGenerator::get_test_i8_const_data(t_netcore_generator* gen) | |
120 | { | |
121 | string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + | |
122 | "\n" | |
123 | "public static class netcoreConstants\n" | |
124 | "{\n" | |
125 | " /// <summary>\n" | |
126 | " /// TestDoc\n" | |
127 | " /// </summary>\n" | |
128 | " public const sbyte @sbyte = 127;\n" | |
129 | "}\n"; | |
130 | ||
131 | t_type* type_ = new t_base_type("I8", t_base_type::TYPE_I8); | |
132 | type_->set_doc("TestDoc"); | |
133 | ||
134 | t_const_value* const_value_ = new t_const_value(); | |
135 | const_value_->set_integer(127); | |
136 | ||
137 | t_const* const_ = new t_const(type_, "sbyte", const_value_); | |
138 | const_->set_doc("TestDoc"); | |
139 | ||
140 | return std::pair<string, t_const*>(expected_result, const_); | |
141 | } | |
142 | ||
143 | std::pair<string, t_const*> TestDataGenerator::get_test_i16_const_data(t_netcore_generator* gen) | |
144 | { | |
145 | string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + | |
146 | "\n" | |
147 | "public static class netcoreConstants\n" | |
148 | "{\n" | |
149 | " /// <summary>\n" | |
150 | " /// TestDoc\n" | |
151 | " /// </summary>\n" | |
152 | " public const short @short = 32767;\n" | |
153 | "}\n"; | |
154 | ||
155 | t_type* type_ = new t_base_type("i16", t_base_type::TYPE_I16); | |
156 | type_->set_doc("TestDoc"); | |
157 | ||
158 | t_const_value* const_value_ = new t_const_value(); | |
159 | const_value_->set_integer(32767); | |
160 | ||
161 | t_const* const_ = new t_const(type_, "short", const_value_); | |
162 | const_->set_doc("TestDoc"); | |
163 | ||
164 | return std::pair<string, t_const*>(expected_result, const_); | |
165 | } | |
166 | ||
167 | std::pair<string, t_const*> TestDataGenerator::get_test_i32_const_data(t_netcore_generator* gen) | |
168 | { | |
169 | string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + | |
170 | "\n" | |
171 | "public static class netcoreConstants\n" | |
172 | "{\n" | |
173 | " /// <summary>\n" | |
174 | " /// TestDoc\n" | |
175 | " /// </summary>\n" | |
176 | " public const int @int = 2147483647;\n" | |
177 | "}\n"; | |
178 | ||
179 | t_type* type_ = new t_base_type("i32", t_base_type::TYPE_I32); | |
180 | type_->set_doc("TestDoc"); | |
181 | ||
182 | t_const_value* const_value_ = new t_const_value(); | |
183 | const_value_->set_integer(2147483647); | |
184 | ||
185 | t_const* const_ = new t_const(type_, "int", const_value_); | |
186 | const_->set_doc("TestDoc"); | |
187 | ||
188 | return std::pair<string, t_const*>(expected_result, const_); | |
189 | } | |
190 | ||
191 | std::pair<string, t_const*> TestDataGenerator::get_test_i64_const_data(t_netcore_generator* gen) | |
192 | { | |
193 | string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + | |
194 | "\n" | |
195 | "public static class netcoreConstants\n" | |
196 | "{\n" | |
197 | " /// <summary>\n" | |
198 | " /// TestDoc\n" | |
199 | " /// </summary>\n" | |
200 | " public const long @long = 9223372036854775807;\n" | |
201 | "}\n"; | |
202 | ||
203 | t_type* type_ = new t_base_type("i64", t_base_type::TYPE_I64); | |
204 | type_->set_doc("TestDoc"); | |
205 | ||
206 | t_const_value* const_value_ = new t_const_value(); | |
207 | const_value_->set_integer(9223372036854775807); | |
208 | ||
209 | t_const* const_ = new t_const(type_, "long", const_value_); | |
210 | const_->set_doc("TestDoc"); | |
211 | ||
212 | return std::pair<string, t_const*>(expected_result, const_); | |
213 | } | |
214 | ||
215 | std::pair<string, t_const*> TestDataGenerator::get_test_double_const_data(t_netcore_generator* gen) | |
216 | { | |
217 | string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + | |
218 | "\n" | |
219 | "public static class netcoreConstants\n" | |
220 | "{\n" | |
221 | " /// <summary>\n" | |
222 | " /// TestDoc\n" | |
223 | " /// </summary>\n" | |
224 | " public const double @double = 9.22337e+18;\n" | |
225 | "}\n"; | |
226 | ||
227 | t_type* type_ = new t_base_type("double", t_base_type::TYPE_DOUBLE); | |
228 | type_->set_doc("TestDoc"); | |
229 | ||
230 | t_const_value* const_value_ = new t_const_value(); | |
231 | const_value_->set_double(9223372036854775807.1); | |
232 | ||
233 | t_const* const_ = new t_const(type_, "double", const_value_); | |
234 | const_->set_doc("TestDoc"); | |
235 | ||
236 | return std::pair<string, t_const*>(expected_result, const_); | |
237 | } |