]>
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 "../catch/catch.hpp" | |
19 | #include <thrift/parse/t_program.h> | |
20 | #include <thrift/generate/t_netcore_generator.h> | |
21 | ||
22 | using std::vector; | |
23 | ||
24 | TEST_CASE("t_netcore_generator::netcore_type_usings() without option wcf should return valid namespaces", "[helpers]") | |
25 | { | |
26 | string path = "CassandraTest.thrift"; | |
27 | string name = "netcore"; | |
28 | map<string, string> parsed_options = { { "union", "union" } }; | |
29 | string option_string = ""; | |
30 | ||
31 | string expected_namespaces = "using System;\n" | |
32 | "using System.Collections;\n" | |
33 | "using System.Collections.Generic;\n" | |
34 | "using System.Text;\n" | |
35 | "using System.IO;\n" | |
36 | "using System.Threading;\n" | |
37 | "using System.Threading.Tasks;\n" | |
38 | "using Thrift;\n" | |
39 | "using Thrift.Collections;\n" + endl; | |
40 | ||
41 | t_program* program = new t_program(path, name); | |
42 | t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); | |
43 | ||
44 | REQUIRE_FALSE(gen->is_wcf_enabled()); | |
45 | REQUIRE(gen->netcore_type_usings() == expected_namespaces); | |
46 | ||
47 | delete gen; | |
48 | delete program; | |
49 | } | |
50 | ||
51 | TEST_CASE("t_netcore_generator::netcore_type_usings() with option wcf should return valid namespaces", "[helpers]") | |
52 | { | |
53 | string path = "CassandraTest.thrift"; | |
54 | string name = "netcore"; | |
55 | map<string, string> parsed_options = { { "wcf", "wcf" } }; | |
56 | string option_string = ""; | |
57 | ||
58 | string expected_namespaces_wcf = "using System;\n" | |
59 | "using System.Collections;\n" | |
60 | "using System.Collections.Generic;\n" | |
61 | "using System.Text;\n" | |
62 | "using System.IO;\n" | |
63 | "using System.Threading;\n" | |
64 | "using System.Threading.Tasks;\n" | |
65 | "using Thrift;\n" | |
66 | "using Thrift.Collections;\n" | |
67 | "using System.ServiceModel;\n" | |
68 | "using System.Runtime.Serialization;\n" + endl; | |
69 | ||
70 | t_program* program = new t_program(path, name); | |
71 | t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); | |
72 | ||
73 | REQUIRE(gen->is_wcf_enabled()); | |
74 | REQUIRE(gen->netcore_type_usings() == expected_namespaces_wcf); | |
75 | ||
76 | delete gen; | |
77 | delete program; | |
78 | } | |
79 | ||
80 | TEST_CASE("t_netcore_generator should contains latest C# keywords to normalize with @", "[helpers]") | |
81 | { | |
82 | string path = "CassandraTest.thrift"; | |
83 | string name = "netcore"; | |
84 | map<string, string> parsed_options = { { "wcf", "wcf" } }; | |
85 | string option_string = ""; | |
86 | vector<string> current_keywords = { | |
87 | { "abstract" }, | |
88 | { "as" }, | |
89 | { "base" }, | |
90 | { "bool" }, | |
91 | { "break" }, | |
92 | { "byte" }, | |
93 | { "case" }, | |
94 | { "catch" }, | |
95 | { "char" }, | |
96 | { "checked" }, | |
97 | { "class" }, | |
98 | { "const" }, | |
99 | { "continue" }, | |
100 | { "decimal" }, | |
101 | { "default" }, | |
102 | { "delegate" }, | |
103 | { "do" }, | |
104 | { "double" }, | |
105 | { "else" }, | |
106 | { "enum" }, | |
107 | { "event" }, | |
108 | { "explicit" }, | |
109 | { "extern" }, | |
110 | { "false" }, | |
111 | { "finally" }, | |
112 | { "fixed" }, | |
113 | { "float" }, | |
114 | { "for" }, | |
115 | { "foreach" }, | |
116 | { "goto" }, | |
117 | { "if" }, | |
118 | { "implicit" }, | |
119 | { "in" }, | |
120 | { "int" }, | |
121 | { "interface" }, | |
122 | { "internal" }, | |
123 | { "is" }, | |
124 | { "lock" }, | |
125 | { "long" }, | |
126 | { "namespace" }, | |
127 | { "new" }, | |
128 | { "null" }, | |
129 | { "object" }, | |
130 | { "operator" }, | |
131 | { "out" }, | |
132 | { "override" }, | |
133 | { "params" }, | |
134 | { "private" }, | |
135 | { "protected" }, | |
136 | { "public" }, | |
137 | { "readonly" }, | |
138 | { "ref" }, | |
139 | { "return" }, | |
140 | { "sbyte" }, | |
141 | { "sealed" }, | |
142 | { "short" }, | |
143 | { "sizeof" }, | |
144 | { "stackalloc" }, | |
145 | { "static" }, | |
146 | { "string" }, | |
147 | { "struct" }, | |
148 | { "switch" }, | |
149 | { "this" }, | |
150 | { "throw" }, | |
151 | { "true" }, | |
152 | { "try" }, | |
153 | { "typeof" }, | |
154 | { "uint" }, | |
155 | { "ulong" }, | |
156 | { "unchecked" }, | |
157 | { "unsafe" }, | |
158 | { "ushort" }, | |
159 | { "using" }, | |
160 | { "void" }, | |
161 | { "volatile" }, | |
162 | { "while" }, | |
163 | // Contextual Keywords | |
164 | { "add" }, | |
165 | { "alias" }, | |
166 | { "ascending" }, | |
167 | { "async" }, | |
168 | { "await" }, | |
169 | { "descending" }, | |
170 | { "dynamic" }, | |
171 | { "from" }, | |
172 | { "get" }, | |
173 | { "global" }, | |
174 | { "group" }, | |
175 | { "into" }, | |
176 | { "join" }, | |
177 | { "let" }, | |
178 | { "orderby" }, | |
179 | { "partial" }, | |
180 | { "remove" }, | |
181 | { "select" }, | |
182 | { "set" }, | |
183 | { "value" }, | |
184 | { "var" }, | |
185 | { "when" }, | |
186 | { "where" }, | |
187 | { "yield" } | |
188 | }; | |
189 | ||
190 | string missed_keywords = ""; | |
191 | ||
192 | t_program* program = new t_program(path, name); | |
193 | t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); | |
194 | gen->init_generator(); | |
195 | map<string, int> generators_keywords = gen->get_keywords_list(); | |
196 | ||
197 | for (vector<string>::iterator it = current_keywords.begin(); it != current_keywords.end(); ++it) | |
198 | { | |
199 | if (generators_keywords.find(*it) == generators_keywords.end()) | |
200 | { | |
201 | missed_keywords = missed_keywords + *it + ","; | |
202 | } | |
203 | } | |
204 | ||
205 | REQUIRE(missed_keywords == ""); | |
206 | ||
207 | delete gen; | |
208 | delete program; | |
209 | } |