From ed36d6262ee3d2dac4753a4e5d572681c5c6c1a9 Mon Sep 17 00:00:00 2001 From: Damian Meden Date: Fri, 21 Aug 2020 15:27:37 +0100 Subject: [PATCH] Add member initialization to the Errata class. --- include/tscore/Errata.h | 4 +- src/tscore/Makefile.am | 3 +- src/tscore/unit_tests/test_Errata.cc | 60 ++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 src/tscore/unit_tests/test_Errata.cc diff --git a/include/tscore/Errata.h b/include/tscore/Errata.h index b28a291c837..758d2187adb 100644 --- a/include/tscore/Errata.h +++ b/include/tscore/Errata.h @@ -728,8 +728,8 @@ MakeRv(R const &r, ///< The function result /* ----------------------------------------------------------------------- */ // Inline methods. inline Errata::Message::Message(std::string const &text) : m_text(text) {} -inline Errata::Message::Message(Id id, std::string const &text) : m_text(text) {} -inline Errata::Message::Message(Id id, Code code, std::string const &text) : m_text(text) {} +inline Errata::Message::Message(Id id, std::string const &text) : m_id(id), m_text(text) {} +inline Errata::Message::Message(Id id, Code code, std::string const &text) : m_id(id), m_code(code), m_text(text) {} template Errata::Message::Message(Id id, Code code, Args const &... text) : m_id(id), m_code(code), m_text(stringify(text...)) { diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am index 76cd274cb8c..ed6788ebc0c 100644 --- a/src/tscore/Makefile.am +++ b/src/tscore/Makefile.am @@ -185,7 +185,8 @@ test_tscore_SOURCES = \ unit_tests/test_scoped_resource.cc \ unit_tests/test_Tokenizer.cc \ unit_tests/test_ts_file.cc \ - unit_tests/test_Version.cc + unit_tests/test_Version.cc \ + unit_tests/test_Errata.cc if HAS_HKDF test_tscore_SOURCES += \ diff --git a/src/tscore/unit_tests/test_Errata.cc b/src/tscore/unit_tests/test_Errata.cc new file mode 100644 index 00000000000..a234f778fec --- /dev/null +++ b/src/tscore/unit_tests/test_Errata.cc @@ -0,0 +1,60 @@ +/** + @file Test for Errata + + @section license License + + 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.hpp" + +#include "tscore/Errata.h" + +TEST_CASE("Basic Errata with text only", "[errata]") +{ + ts::Errata err; + std::string text{"Some error text"}; + err.push(text); + REQUIRE(err.isOK()); // as code is 0 by default. + REQUIRE(err.top().text() == text); +} + +TEST_CASE("Basic Errata test with id and text", "[errata]") +{ + ts::Errata err; + int id{1}; + std::string text{"Some error text"}; + + err.push(id, text); + + REQUIRE(err.isOK()); // as code is 0 by default. + REQUIRE(err.top().text() == text); +} + +TEST_CASE("Basic Errata test with id,code and text", "[errata]") +{ + ts::Errata err; + int id{1}; + int code{2}; + std::string text{"Some error text"}; + + err.push(id, code, text); + + REQUIRE(!err.isOK()); // This should not be ok as code now is 2 + REQUIRE(err.top().getCode() == code); + REQUIRE(err.top().text() == text); +}