From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../t_netcore_generator_functional_tests.cc | 339 +++++++++++++++++++++ ...t_netcore_generator_functional_tests_helpers.cc | 237 ++++++++++++++ .../t_netcore_generator_functional_tests_helpers.h | 34 +++ .../netcore/t_netcore_generator_helpers_tests.cc | 209 +++++++++++++ .../t_netcore_generator_initialization_tests.cc | 74 +++++ 5 files changed, 893 insertions(+) create mode 100644 src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests.cc create mode 100644 src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests_helpers.cc create mode 100644 src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests_helpers.h create mode 100644 src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_helpers_tests.cc create mode 100644 src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_initialization_tests.cc (limited to 'src/jaegertracing/thrift/compiler/cpp/tests/netcore') diff --git a/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests.cc b/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests.cc new file mode 100644 index 000000000..0b8c8378e --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests.cc @@ -0,0 +1,339 @@ +// Licensed to the Apache Software Foundation(ASF) under one +// or more contributor license agreements.See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership.The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "../catch/catch.hpp" +#include +#include +#include "t_netcore_generator_functional_tests_helpers.h" + +TEST_CASE( "t_netcore_generator should generate valid enum", "[functional]" ) +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" } }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + + std::pair pair = TestDataGenerator::get_test_enum_data(program); + string expected_result = pair.first; + t_enum* test_enum = pair.second; + + string file_path = test_enum->get_name() + ".cs"; + ofstream out; + out.open(file_path.c_str()); + + REQUIRE_NOTHROW(gen->generate_enum(out, test_enum)); + + out.close(); + + std::ifstream ifs(file_path); + string actual_result((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + std::remove(file_path.c_str()); + + REQUIRE(expected_result == actual_result); + + delete test_enum; + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator should generate valid void", "[functional]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" } }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + + std::pair pair = TestDataGenerator::get_test_void_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector consts_; + consts_.push_back(const_); + + string file_path = const_->get_name() + ".cs"; + ofstream out; + out.open(file_path.c_str()); + + REQUIRE_THROWS(gen->generate_consts(out, consts_)); + + out.close(); + + std::ifstream ifs(file_path); + string actual_result((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + std::remove(file_path.c_str()); + + delete const_; + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator should generate valid string with escaping keyword", "[functional]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" } }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + gen->init_generator(); + + std::pair pair = TestDataGenerator::get_test_string_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector consts_; + consts_.push_back(const_); + + string file_path = const_->get_name() + ".cs"; + ofstream out; + out.open(file_path.c_str()); + + REQUIRE_NOTHROW(gen->generate_consts(out, consts_)); + + out.close(); + + std::ifstream ifs(file_path); + string actual_result((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + std::remove(file_path.c_str()); + + REQUIRE(expected_result == actual_result); + + delete const_; + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator should generate valid bool with escaping keyword", "[functional]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" } }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + gen->init_generator(); + + std::pair pair = TestDataGenerator::get_test_bool_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector consts_; + consts_.push_back(const_); + + string file_path = const_->get_name() + ".cs"; + ofstream out; + out.open(file_path.c_str()); + + REQUIRE_NOTHROW(gen->generate_consts(out, consts_)); + + out.close(); + + std::ifstream ifs(file_path); + string actual_result((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + std::remove(file_path.c_str()); + + REQUIRE(expected_result == actual_result); + + delete const_; + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator should generate valid sbyte (i8) with escaping keyword", "[functional]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" } }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + gen->init_generator(); + + std::pair pair = TestDataGenerator::get_test_i8_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector consts_; + consts_.push_back(const_); + + string file_path = const_->get_name() + ".cs"; + ofstream out; + out.open(file_path.c_str()); + + REQUIRE_NOTHROW(gen->generate_consts(out, consts_)); + + out.close(); + + std::ifstream ifs(file_path); + string actual_result((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + std::remove(file_path.c_str()); + + REQUIRE(expected_result == actual_result); + + delete const_; + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator should generate valid short (i16) with escaping keyword", "[functional]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" } }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + gen->init_generator(); + + std::pair pair = TestDataGenerator::get_test_i16_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector consts_; + consts_.push_back(const_); + + string file_path = const_->get_name() + ".cs"; + ofstream out; + out.open(file_path.c_str()); + + REQUIRE_NOTHROW(gen->generate_consts(out, consts_)); + + out.close(); + + std::ifstream ifs(file_path); + string actual_result((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + std::remove(file_path.c_str()); + + REQUIRE(expected_result == actual_result); + + delete const_; + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator should generate valid integer (i32) with escaping keyword", "[functional]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" } }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + gen->init_generator(); + + std::pair pair = TestDataGenerator::get_test_i32_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector consts_; + consts_.push_back(const_); + + string file_path = const_->get_name() + ".cs"; + ofstream out; + out.open(file_path.c_str()); + + REQUIRE_NOTHROW(gen->generate_consts(out, consts_)); + + out.close(); + + std::ifstream ifs(file_path); + string actual_result((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + std::remove(file_path.c_str()); + + REQUIRE(expected_result == actual_result); + + delete const_; + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator should generate valid long (i64) with escaping keyword", "[functional]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" } }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + gen->init_generator(); + + std::pair pair = TestDataGenerator::get_test_i64_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector consts_; + consts_.push_back(const_); + + string file_path = const_->get_name() + ".cs"; + ofstream out; + out.open(file_path.c_str()); + + REQUIRE_NOTHROW(gen->generate_consts(out, consts_)); + + out.close(); + + std::ifstream ifs(file_path); + string actual_result((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + std::remove(file_path.c_str()); + + REQUIRE(expected_result == actual_result); + + delete const_; + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator should generate valid double with escaping keyword", "[functional]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" } }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + gen->init_generator(); + + std::pair pair = TestDataGenerator::get_test_double_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector consts_; + consts_.push_back(const_); + + string file_path = const_->get_name() + ".cs"; + ofstream out; + out.open(file_path.c_str()); + + REQUIRE_NOTHROW(gen->generate_consts(out, consts_)); + + out.close(); + + std::ifstream ifs(file_path); + string actual_result((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + std::remove(file_path.c_str()); + + REQUIRE(expected_result == actual_result); + + delete const_; + delete gen; + delete program; +} diff --git a/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests_helpers.cc b/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests_helpers.cc new file mode 100644 index 000000000..92c170bb9 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests_helpers.cc @@ -0,0 +1,237 @@ +// Licensed to the Apache Software Foundation(ASF) under one +// or more contributor license agreements.See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership.The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include +#include "thrift/common.h" +#include +#include "t_netcore_generator_functional_tests_helpers.h" + +const string TestDataGenerator::DEFAULT_FILE_HEADER = "/**" "\n" + " * Autogenerated by Thrift Compiler ()" "\n" + " *" "\n" + " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING" "\n" + " * @generated" "\n" + " */"; + +std::pair TestDataGenerator::get_test_enum_data(t_program* program) +{ + string expected_result = DEFAULT_FILE_HEADER + + "\n" + "\n" + "/// \n" + "/// TestDoc\n" + "/// \n" + "public enum TestName\n" + "{\n" + " None = 0,\n" + " First = 1,\n" + " Second = 2,\n" + "}\n"; + + t_enum* enum_ = new t_enum(program); + enum_->set_name("TestName"); + enum_->set_doc("TestDoc"); + enum_->append(new t_enum_value("None", 0)); + enum_->append(new t_enum_value("First", 1)); + enum_->append(new t_enum_value("Second", 2)); + + return std::pair(expected_result, enum_); +} + +std::pair TestDataGenerator::get_test_void_const_data(t_netcore_generator* gen) +{ + string expected_result = DEFAULT_FILE_HEADER; + + t_type* type_ = new t_base_type("void", t_base_type::TYPE_VOID); + type_->set_doc("TestDoc"); + + t_const_value* const_value_ = new t_const_value(); + const_value_->set_string("VoidValue"); + + t_const* const_ = new t_const(type_, "void", const_value_); + const_->set_doc("TestDoc"); + + return std::pair(expected_result, const_); +} + +std::pair TestDataGenerator::get_test_string_const_data(t_netcore_generator* gen) +{ + string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + + "\n" + "public static class netcoreConstants\n" + "{\n" + " /// \n" + " /// TestDoc\n" + " /// \n" + " public const string @string = \"StringValue\";\n" + "}\n"; + + t_type* type_ = new t_base_type("string", t_base_type::TYPE_STRING); + type_->set_doc("TestDoc"); + + t_const_value* const_value_ = new t_const_value(); + const_value_->set_string("StringValue"); + + t_const* const_ = new t_const(type_, "string", const_value_); + const_->set_doc("TestDoc"); + + return std::pair(expected_result, const_); +} + +std::pair TestDataGenerator::get_test_bool_const_data(t_netcore_generator* gen) +{ + string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + + "\n" + "public static class netcoreConstants\n" + "{\n" + " /// \n" + " /// TestDoc\n" + " /// \n" + " public const bool @bool = true;\n" + "}\n"; + + t_type* type_ = new t_base_type("bool", t_base_type::TYPE_BOOL); + type_->set_doc("TestDoc"); + + t_const_value* const_value_ = new t_const_value(); + const_value_->set_integer(1); + + t_const* const_ = new t_const(type_, "bool", const_value_); + const_->set_doc("TestDoc"); + + return std::pair(expected_result, const_); +} + +std::pair TestDataGenerator::get_test_i8_const_data(t_netcore_generator* gen) +{ + string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + + "\n" + "public static class netcoreConstants\n" + "{\n" + " /// \n" + " /// TestDoc\n" + " /// \n" + " public const sbyte @sbyte = 127;\n" + "}\n"; + + t_type* type_ = new t_base_type("I8", t_base_type::TYPE_I8); + type_->set_doc("TestDoc"); + + t_const_value* const_value_ = new t_const_value(); + const_value_->set_integer(127); + + t_const* const_ = new t_const(type_, "sbyte", const_value_); + const_->set_doc("TestDoc"); + + return std::pair(expected_result, const_); +} + +std::pair TestDataGenerator::get_test_i16_const_data(t_netcore_generator* gen) +{ + string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + + "\n" + "public static class netcoreConstants\n" + "{\n" + " /// \n" + " /// TestDoc\n" + " /// \n" + " public const short @short = 32767;\n" + "}\n"; + + t_type* type_ = new t_base_type("i16", t_base_type::TYPE_I16); + type_->set_doc("TestDoc"); + + t_const_value* const_value_ = new t_const_value(); + const_value_->set_integer(32767); + + t_const* const_ = new t_const(type_, "short", const_value_); + const_->set_doc("TestDoc"); + + return std::pair(expected_result, const_); +} + +std::pair TestDataGenerator::get_test_i32_const_data(t_netcore_generator* gen) +{ + string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + + "\n" + "public static class netcoreConstants\n" + "{\n" + " /// \n" + " /// TestDoc\n" + " /// \n" + " public const int @int = 2147483647;\n" + "}\n"; + + t_type* type_ = new t_base_type("i32", t_base_type::TYPE_I32); + type_->set_doc("TestDoc"); + + t_const_value* const_value_ = new t_const_value(); + const_value_->set_integer(2147483647); + + t_const* const_ = new t_const(type_, "int", const_value_); + const_->set_doc("TestDoc"); + + return std::pair(expected_result, const_); +} + +std::pair TestDataGenerator::get_test_i64_const_data(t_netcore_generator* gen) +{ + string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + + "\n" + "public static class netcoreConstants\n" + "{\n" + " /// \n" + " /// TestDoc\n" + " /// \n" + " public const long @long = 9223372036854775807;\n" + "}\n"; + + t_type* type_ = new t_base_type("i64", t_base_type::TYPE_I64); + type_->set_doc("TestDoc"); + + t_const_value* const_value_ = new t_const_value(); + const_value_->set_integer(9223372036854775807); + + t_const* const_ = new t_const(type_, "long", const_value_); + const_->set_doc("TestDoc"); + + return std::pair(expected_result, const_); +} + +std::pair TestDataGenerator::get_test_double_const_data(t_netcore_generator* gen) +{ + string expected_result = DEFAULT_FILE_HEADER + "\n" +gen->netcore_type_usings() + + "\n" + "public static class netcoreConstants\n" + "{\n" + " /// \n" + " /// TestDoc\n" + " /// \n" + " public const double @double = 9.22337e+18;\n" + "}\n"; + + t_type* type_ = new t_base_type("double", t_base_type::TYPE_DOUBLE); + type_->set_doc("TestDoc"); + + t_const_value* const_value_ = new t_const_value(); + const_value_->set_double(9223372036854775807.1); + + t_const* const_ = new t_const(type_, "double", const_value_); + const_->set_doc("TestDoc"); + + return std::pair(expected_result, const_); +} diff --git a/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests_helpers.h b/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests_helpers.h new file mode 100644 index 000000000..c6eaac22c --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests_helpers.h @@ -0,0 +1,34 @@ +// Licensed to the Apache Software Foundation(ASF) under one +// or more contributor license agreements.See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership.The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include + +class TestDataGenerator +{ +public: + static const string DEFAULT_FILE_HEADER; + + static std::pair get_test_enum_data(t_program* program); + static std::pair get_test_void_const_data(t_netcore_generator* gen); + static std::pair get_test_string_const_data(t_netcore_generator* gen); + static std::pair get_test_bool_const_data(t_netcore_generator* gen); + static std::pair get_test_i8_const_data(t_netcore_generator* gen); + static std::pair get_test_i16_const_data(t_netcore_generator* gen); + static std::pair get_test_i32_const_data(t_netcore_generator* gen); + static std::pair get_test_i64_const_data(t_netcore_generator* gen); + static std::pair get_test_double_const_data(t_netcore_generator* gen); +}; diff --git a/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_helpers_tests.cc b/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_helpers_tests.cc new file mode 100644 index 000000000..0bcbeed19 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_helpers_tests.cc @@ -0,0 +1,209 @@ +// Licensed to the Apache Software Foundation(ASF) under one +// or more contributor license agreements.See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership.The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "../catch/catch.hpp" +#include +#include + +using std::vector; + +TEST_CASE("t_netcore_generator::netcore_type_usings() without option wcf should return valid namespaces", "[helpers]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "union", "union" } }; + string option_string = ""; + + string expected_namespaces = "using System;\n" + "using System.Collections;\n" + "using System.Collections.Generic;\n" + "using System.Text;\n" + "using System.IO;\n" + "using System.Threading;\n" + "using System.Threading.Tasks;\n" + "using Thrift;\n" + "using Thrift.Collections;\n" + endl; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + + REQUIRE_FALSE(gen->is_wcf_enabled()); + REQUIRE(gen->netcore_type_usings() == expected_namespaces); + + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator::netcore_type_usings() with option wcf should return valid namespaces", "[helpers]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" } }; + string option_string = ""; + + string expected_namespaces_wcf = "using System;\n" + "using System.Collections;\n" + "using System.Collections.Generic;\n" + "using System.Text;\n" + "using System.IO;\n" + "using System.Threading;\n" + "using System.Threading.Tasks;\n" + "using Thrift;\n" + "using Thrift.Collections;\n" + "using System.ServiceModel;\n" + "using System.Runtime.Serialization;\n" + endl; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + + REQUIRE(gen->is_wcf_enabled()); + REQUIRE(gen->netcore_type_usings() == expected_namespaces_wcf); + + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator should contains latest C# keywords to normalize with @", "[helpers]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" } }; + string option_string = ""; + vector current_keywords = { + { "abstract" }, + { "as" }, + { "base" }, + { "bool" }, + { "break" }, + { "byte" }, + { "case" }, + { "catch" }, + { "char" }, + { "checked" }, + { "class" }, + { "const" }, + { "continue" }, + { "decimal" }, + { "default" }, + { "delegate" }, + { "do" }, + { "double" }, + { "else" }, + { "enum" }, + { "event" }, + { "explicit" }, + { "extern" }, + { "false" }, + { "finally" }, + { "fixed" }, + { "float" }, + { "for" }, + { "foreach" }, + { "goto" }, + { "if" }, + { "implicit" }, + { "in" }, + { "int" }, + { "interface" }, + { "internal" }, + { "is" }, + { "lock" }, + { "long" }, + { "namespace" }, + { "new" }, + { "null" }, + { "object" }, + { "operator" }, + { "out" }, + { "override" }, + { "params" }, + { "private" }, + { "protected" }, + { "public" }, + { "readonly" }, + { "ref" }, + { "return" }, + { "sbyte" }, + { "sealed" }, + { "short" }, + { "sizeof" }, + { "stackalloc" }, + { "static" }, + { "string" }, + { "struct" }, + { "switch" }, + { "this" }, + { "throw" }, + { "true" }, + { "try" }, + { "typeof" }, + { "uint" }, + { "ulong" }, + { "unchecked" }, + { "unsafe" }, + { "ushort" }, + { "using" }, + { "void" }, + { "volatile" }, + { "while" }, + // Contextual Keywords + { "add" }, + { "alias" }, + { "ascending" }, + { "async" }, + { "await" }, + { "descending" }, + { "dynamic" }, + { "from" }, + { "get" }, + { "global" }, + { "group" }, + { "into" }, + { "join" }, + { "let" }, + { "orderby" }, + { "partial" }, + { "remove" }, + { "select" }, + { "set" }, + { "value" }, + { "var" }, + { "when" }, + { "where" }, + { "yield" } + }; + + string missed_keywords = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + gen->init_generator(); + map generators_keywords = gen->get_keywords_list(); + + for (vector::iterator it = current_keywords.begin(); it != current_keywords.end(); ++it) + { + if (generators_keywords.find(*it) == generators_keywords.end()) + { + missed_keywords = missed_keywords + *it + ","; + } + } + + REQUIRE(missed_keywords == ""); + + delete gen; + delete program; +} diff --git a/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_initialization_tests.cc b/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_initialization_tests.cc new file mode 100644 index 000000000..ec17733bd --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_initialization_tests.cc @@ -0,0 +1,74 @@ +// Licensed to the Apache Software Foundation(ASF) under one +// or more contributor license agreements.See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership.The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "../catch/catch.hpp" +#include +#include + +TEST_CASE( "t_netcore_generator should throw error with unknown options", "[initialization]" ) +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "keys", "keys" } }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = nullptr; + + REQUIRE_THROWS(gen = new t_netcore_generator(program, parsed_options, option_string)); + + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator should create valid instance with valid options", "[initialization]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" }, { "nullable", "nullable"} }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = nullptr; + + REQUIRE_NOTHROW(gen = new t_netcore_generator(program, parsed_options, option_string)); + REQUIRE(gen != nullptr); + REQUIRE(gen->is_wcf_enabled()); + REQUIRE(gen->is_nullable_enabled()); + REQUIRE_FALSE(gen->is_hashcode_enabled()); + REQUIRE_FALSE(gen->is_serialize_enabled()); + REQUIRE_FALSE(gen->is_union_enabled()); + + delete gen; + delete program; +} + +TEST_CASE("t_netcore_generator should pass init succesfully", "[initialization]") +{ + string path = "CassandraTest.thrift"; + string name = "netcore"; + map parsed_options = { { "wcf", "wcf" },{ "nullable", "nullable" } }; + string option_string = ""; + + t_program* program = new t_program(path, name); + t_netcore_generator* gen = new t_netcore_generator(program, parsed_options, option_string); + + REQUIRE_NOTHROW(gen->init_generator()); + + delete gen; + delete program; +} -- cgit v1.2.3