diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests.cc | |
parent | Initial commit. (diff) | |
download | ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/jaegertracing/thrift/compiler/cpp/tests/netcore/t_netcore_generator_functional_tests.cc | 339 |
1 files changed, 339 insertions, 0 deletions
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 <thrift/parse/t_program.h> +#include <thrift/generate/t_netcore_generator.h> +#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<string, string> 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<string, t_enum*> 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<char>(ifs)), (std::istreambuf_iterator<char>())); + 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<string, string> 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<string, t_const*> pair = TestDataGenerator::get_test_void_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector<t_const*> 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<char>(ifs)), (std::istreambuf_iterator<char>())); + 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<string, string> 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<string, t_const*> pair = TestDataGenerator::get_test_string_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector<t_const*> 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<char>(ifs)), (std::istreambuf_iterator<char>())); + 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<string, string> 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<string, t_const*> pair = TestDataGenerator::get_test_bool_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector<t_const*> 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<char>(ifs)), (std::istreambuf_iterator<char>())); + 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<string, string> 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<string, t_const*> pair = TestDataGenerator::get_test_i8_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector<t_const*> 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<char>(ifs)), (std::istreambuf_iterator<char>())); + 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<string, string> 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<string, t_const*> pair = TestDataGenerator::get_test_i16_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector<t_const*> 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<char>(ifs)), (std::istreambuf_iterator<char>())); + 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<string, string> 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<string, t_const*> pair = TestDataGenerator::get_test_i32_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector<t_const*> 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<char>(ifs)), (std::istreambuf_iterator<char>())); + 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<string, string> 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<string, t_const*> pair = TestDataGenerator::get_test_i64_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector<t_const*> 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<char>(ifs)), (std::istreambuf_iterator<char>())); + 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<string, string> 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<string, t_const*> pair = TestDataGenerator::get_test_double_const_data(gen); + string expected_result = pair.first; + t_const* const_ = pair.second; + vector<t_const*> 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<char>(ifs)), (std::istreambuf_iterator<char>())); + std::remove(file_path.c_str()); + + REQUIRE(expected_result == actual_result); + + delete const_; + delete gen; + delete program; +} |