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 "../catch/catch.hpp"
19 #include <thrift/parse/t_program.h>
20 #include <thrift/generate/t_netcore_generator.h>
24 TEST_CASE("t_netcore_generator::netcore_type_usings() without option wcf should return valid namespaces", "[helpers]")
26 string path
= "CassandraTest.thrift";
27 string name
= "netcore";
28 map
<string
, string
> parsed_options
= { { "union", "union" } };
29 string option_string
= "";
31 string expected_namespaces
= "using System;\n"
32 "using System.Collections;\n"
33 "using System.Collections.Generic;\n"
34 "using System.Text;\n"
36 "using System.Threading;\n"
37 "using System.Threading.Tasks;\n"
39 "using Thrift.Collections;\n" + endl
;
41 t_program
* program
= new t_program(path
, name
);
42 t_netcore_generator
* gen
= new t_netcore_generator(program
, parsed_options
, option_string
);
44 REQUIRE_FALSE(gen
->is_wcf_enabled());
45 REQUIRE(gen
->netcore_type_usings() == expected_namespaces
);
51 TEST_CASE("t_netcore_generator::netcore_type_usings() with option wcf should return valid namespaces", "[helpers]")
53 string path
= "CassandraTest.thrift";
54 string name
= "netcore";
55 map
<string
, string
> parsed_options
= { { "wcf", "wcf" } };
56 string option_string
= "";
58 string expected_namespaces_wcf
= "using System;\n"
59 "using System.Collections;\n"
60 "using System.Collections.Generic;\n"
61 "using System.Text;\n"
63 "using System.Threading;\n"
64 "using System.Threading.Tasks;\n"
66 "using Thrift.Collections;\n"
67 "using System.ServiceModel;\n"
68 "using System.Runtime.Serialization;\n" + endl
;
70 t_program
* program
= new t_program(path
, name
);
71 t_netcore_generator
* gen
= new t_netcore_generator(program
, parsed_options
, option_string
);
73 REQUIRE(gen
->is_wcf_enabled());
74 REQUIRE(gen
->netcore_type_usings() == expected_namespaces_wcf
);
80 TEST_CASE("t_netcore_generator should contains latest C# keywords to normalize with @", "[helpers]")
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
= {
163 // Contextual Keywords
190 string missed_keywords
= "";
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();
197 for (vector
<string
>::iterator it
= current_keywords
.begin(); it
!= current_keywords
.end(); ++it
)
199 if (generators_keywords
.find(*it
) == generators_keywords
.end())
201 missed_keywords
= missed_keywords
+ *it
+ ",";
205 REQUIRE(missed_keywords
== "");