]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests_helpers.cc
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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
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"
23 const string
TestDataGenerator::DEFAULT_FILE_HEADER
= "/**" "\n"
24 " * Autogenerated by Thrift Compiler ()" "\n"
26 " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING" "\n"
30 std::pair
<string
, t_enum
*> TestDataGenerator::get_test_enum_data(t_program
* program
)
32 string expected_result
= DEFAULT_FILE_HEADER
+
38 "public enum TestName\n"
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));
52 return std::pair
<string
, t_enum
*>(expected_result
, enum_
);
55 std::pair
<string
, t_const
*> TestDataGenerator::get_test_void_const_data(t_netcore_generator
* gen
)
57 string expected_result
= DEFAULT_FILE_HEADER
;
59 t_type
* type_
= new t_base_type("void", t_base_type::TYPE_VOID
);
60 type_
->set_doc("TestDoc");
62 t_const_value
* const_value_
= new t_const_value();
63 const_value_
->set_string("VoidValue");
65 t_const
* const_
= new t_const(type_
, "void", const_value_
);
66 const_
->set_doc("TestDoc");
68 return std::pair
<string
, t_const
*>(expected_result
, const_
);
71 std::pair
<string
, t_const
*> TestDataGenerator::get_test_string_const_data(t_netcore_generator
* gen
)
73 string expected_result
= DEFAULT_FILE_HEADER
+ "\n" +gen
->netcore_type_usings() +
75 "public static class netcoreConstants\n"
80 " public const string @string = \"StringValue\";\n"
83 t_type
* type_
= new t_base_type("string", t_base_type::TYPE_STRING
);
84 type_
->set_doc("TestDoc");
86 t_const_value
* const_value_
= new t_const_value();
87 const_value_
->set_string("StringValue");
89 t_const
* const_
= new t_const(type_
, "string", const_value_
);
90 const_
->set_doc("TestDoc");
92 return std::pair
<string
, t_const
*>(expected_result
, const_
);
95 std::pair
<string
, t_const
*> TestDataGenerator::get_test_bool_const_data(t_netcore_generator
* gen
)
97 string expected_result
= DEFAULT_FILE_HEADER
+ "\n" +gen
->netcore_type_usings() +
99 "public static class netcoreConstants\n"
104 " public const bool @bool = true;\n"
107 t_type
* type_
= new t_base_type("bool", t_base_type::TYPE_BOOL
);
108 type_
->set_doc("TestDoc");
110 t_const_value
* const_value_
= new t_const_value();
111 const_value_
->set_integer(1);
113 t_const
* const_
= new t_const(type_
, "bool", const_value_
);
114 const_
->set_doc("TestDoc");
116 return std::pair
<string
, t_const
*>(expected_result
, const_
);
119 std::pair
<string
, t_const
*> TestDataGenerator::get_test_i8_const_data(t_netcore_generator
* gen
)
121 string expected_result
= DEFAULT_FILE_HEADER
+ "\n" +gen
->netcore_type_usings() +
123 "public static class netcoreConstants\n"
128 " public const sbyte @sbyte = 127;\n"
131 t_type
* type_
= new t_base_type("I8", t_base_type::TYPE_I8
);
132 type_
->set_doc("TestDoc");
134 t_const_value
* const_value_
= new t_const_value();
135 const_value_
->set_integer(127);
137 t_const
* const_
= new t_const(type_
, "sbyte", const_value_
);
138 const_
->set_doc("TestDoc");
140 return std::pair
<string
, t_const
*>(expected_result
, const_
);
143 std::pair
<string
, t_const
*> TestDataGenerator::get_test_i16_const_data(t_netcore_generator
* gen
)
145 string expected_result
= DEFAULT_FILE_HEADER
+ "\n" +gen
->netcore_type_usings() +
147 "public static class netcoreConstants\n"
152 " public const short @short = 32767;\n"
155 t_type
* type_
= new t_base_type("i16", t_base_type::TYPE_I16
);
156 type_
->set_doc("TestDoc");
158 t_const_value
* const_value_
= new t_const_value();
159 const_value_
->set_integer(32767);
161 t_const
* const_
= new t_const(type_
, "short", const_value_
);
162 const_
->set_doc("TestDoc");
164 return std::pair
<string
, t_const
*>(expected_result
, const_
);
167 std::pair
<string
, t_const
*> TestDataGenerator::get_test_i32_const_data(t_netcore_generator
* gen
)
169 string expected_result
= DEFAULT_FILE_HEADER
+ "\n" +gen
->netcore_type_usings() +
171 "public static class netcoreConstants\n"
176 " public const int @int = 2147483647;\n"
179 t_type
* type_
= new t_base_type("i32", t_base_type::TYPE_I32
);
180 type_
->set_doc("TestDoc");
182 t_const_value
* const_value_
= new t_const_value();
183 const_value_
->set_integer(2147483647);
185 t_const
* const_
= new t_const(type_
, "int", const_value_
);
186 const_
->set_doc("TestDoc");
188 return std::pair
<string
, t_const
*>(expected_result
, const_
);
191 std::pair
<string
, t_const
*> TestDataGenerator::get_test_i64_const_data(t_netcore_generator
* gen
)
193 string expected_result
= DEFAULT_FILE_HEADER
+ "\n" +gen
->netcore_type_usings() +
195 "public static class netcoreConstants\n"
200 " public const long @long = 9223372036854775807;\n"
203 t_type
* type_
= new t_base_type("i64", t_base_type::TYPE_I64
);
204 type_
->set_doc("TestDoc");
206 t_const_value
* const_value_
= new t_const_value();
207 const_value_
->set_integer(9223372036854775807);
209 t_const
* const_
= new t_const(type_
, "long", const_value_
);
210 const_
->set_doc("TestDoc");
212 return std::pair
<string
, t_const
*>(expected_result
, const_
);
215 std::pair
<string
, t_const
*> TestDataGenerator::get_test_double_const_data(t_netcore_generator
* gen
)
217 string expected_result
= DEFAULT_FILE_HEADER
+ "\n" +gen
->netcore_type_usings() +
219 "public static class netcoreConstants\n"
224 " public const double @double = 9.22337e+18;\n"
227 t_type
* type_
= new t_base_type("double", t_base_type::TYPE_DOUBLE
);
228 type_
->set_doc("TestDoc");
230 t_const_value
* const_value_
= new t_const_value();
231 const_value_
->set_double(9223372036854775807.1);
233 t_const
* const_
= new t_const(type_
, "double", const_value_
);
234 const_
->set_doc("TestDoc");
236 return std::pair
<string
, t_const
*>(expected_result
, const_
);