diff --git a/include/etl/basic_format_spec.h b/include/etl/basic_format_spec.h index d5a885ff..80e9870e 100644 --- a/include/etl/basic_format_spec.h +++ b/include/etl/basic_format_spec.h @@ -211,15 +211,22 @@ namespace etl /// Upper case (for hex) = true /// Left Justified = false //*************************************************************************** - basic_format_spec() + ETL_CONSTEXPR basic_format_spec() + : base_(10U) + , width_(0U) + , precision_(0U) + , upper_case_(false) + , left_justified_(false) + , boolalpha_(false) + , show_base_(false) + , fill_(typename TString::value_type(' ')) { - clear(); } //*************************************************************************** /// Clears the format spec back to default. //*************************************************************************** - void clear() + ETL_CONSTEXPR void clear() { base_ = 10U; width_ = 0U; @@ -235,7 +242,7 @@ namespace etl /// Sets the base. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& base(uint32_t b) + ETL_CONSTEXPR basic_format_spec& base(uint32_t b) { base_ = static_cast(b); return *this; @@ -245,7 +252,7 @@ namespace etl /// Sets the base to binary. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& binary() + ETL_CONSTEXPR basic_format_spec& binary() { base(2); return *this; @@ -255,7 +262,7 @@ namespace etl /// Sets the base to octal. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& octal() + ETL_CONSTEXPR basic_format_spec& octal() { base(8); return *this; @@ -265,7 +272,7 @@ namespace etl /// Sets the base to decimal. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& decimal() + ETL_CONSTEXPR basic_format_spec& decimal() { base(10); return *this; @@ -275,7 +282,7 @@ namespace etl /// Sets the base to hex. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& hex() + ETL_CONSTEXPR basic_format_spec& hex() { base(16); return *this; @@ -284,7 +291,7 @@ namespace etl //*************************************************************************** /// Gets the base. //*************************************************************************** - uint32_t get_base() const + ETL_CONSTEXPR uint32_t get_base() const { return base_; } @@ -293,7 +300,7 @@ namespace etl /// Sets the show base flag. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& show_base(bool b) + ETL_CONSTEXPR basic_format_spec& show_base(bool b) { show_base_ = b; return *this; @@ -302,7 +309,7 @@ namespace etl //*************************************************************************** /// Gets the show base flag. //*************************************************************************** - bool is_show_base() const + ETL_CONSTEXPR bool is_show_base() const { return show_base_; } @@ -311,7 +318,7 @@ namespace etl /// Sets the width. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& width(uint32_t w) + ETL_CONSTEXPR basic_format_spec& width(uint32_t w) { width_ = static_cast(w); return *this; @@ -320,7 +327,7 @@ namespace etl //*************************************************************************** /// Gets the width. //*************************************************************************** - uint32_t get_width() const + ETL_CONSTEXPR uint32_t get_width() const { return width_; } @@ -329,7 +336,7 @@ namespace etl /// Sets the precision. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& precision(uint32_t p) + ETL_CONSTEXPR basic_format_spec& precision(uint32_t p) { precision_ = static_cast(p); return *this; @@ -338,7 +345,7 @@ namespace etl //*************************************************************************** /// Gets the precision. //*************************************************************************** - uint32_t get_precision() const + ETL_CONSTEXPR uint32_t get_precision() const { return precision_; } @@ -347,7 +354,7 @@ namespace etl /// Sets the upper case flag. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& upper_case(bool u) + ETL_CONSTEXPR basic_format_spec& upper_case(bool u) { upper_case_ = u; return *this; @@ -356,7 +363,7 @@ namespace etl //*************************************************************************** /// Gets the upper case flag. //*************************************************************************** - bool is_upper_case() const + ETL_CONSTEXPR bool is_upper_case() const { return upper_case_; } @@ -365,7 +372,7 @@ namespace etl /// Sets the fill character. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& fill(typename TString::value_type c) + ETL_CONSTEXPR basic_format_spec& fill(typename TString::value_type c) { fill_ = c; return *this; @@ -374,7 +381,7 @@ namespace etl //*************************************************************************** /// Gets the fill character. //*************************************************************************** - typename TString::value_type get_fill() const + ETL_CONSTEXPR typename TString::value_type get_fill() const { return fill_; } @@ -383,7 +390,7 @@ namespace etl /// Sets the left justify flag. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& left() + ETL_CONSTEXPR basic_format_spec& left() { left_justified_ = true; return *this; @@ -392,7 +399,7 @@ namespace etl //*************************************************************************** /// Gets the left justify flag. //*************************************************************************** - bool is_left() const + ETL_CONSTEXPR bool is_left() const { return left_justified_; } @@ -401,7 +408,7 @@ namespace etl /// Sets the right justify flag. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& right() + ETL_CONSTEXPR basic_format_spec& right() { left_justified_ = false; return *this; @@ -410,7 +417,7 @@ namespace etl //*************************************************************************** /// Gets the right justify flag. //*************************************************************************** - bool is_right() const + ETL_CONSTEXPR bool is_right() const { return !left_justified_; } @@ -419,7 +426,7 @@ namespace etl /// Sets the bool alpha flag. /// \return A reference to the basic_format_spec. //*************************************************************************** - basic_format_spec& boolalpha(bool b) + ETL_CONSTEXPR basic_format_spec& boolalpha(bool b) { boolalpha_ = b; return *this; @@ -428,7 +435,7 @@ namespace etl //*************************************************************************** /// Gets the boolalpha flag. //*************************************************************************** - bool is_boolalpha() const + ETL_CONSTEXPR bool is_boolalpha() const { return boolalpha_; } @@ -436,7 +443,7 @@ namespace etl //*************************************************************************** /// Equality operator. //*************************************************************************** - friend bool operator ==(const basic_format_spec& lhs, const basic_format_spec& rhs) + ETL_CONSTEXPR friend bool operator ==(const basic_format_spec& lhs, const basic_format_spec& rhs) { return (lhs.base_ == rhs.base_) && (lhs.width_ == rhs.width_) && @@ -451,7 +458,7 @@ namespace etl //*************************************************************************** /// Inequality operator. //*************************************************************************** - friend bool operator !=(const basic_format_spec& lhs, const basic_format_spec& rhs) + ETL_CONSTEXPR friend bool operator !=(const basic_format_spec& lhs, const basic_format_spec& rhs) { return !(lhs == rhs); } diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 4f4df6d2..17023675 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -602,6 +602,13 @@ namespace etl } #endif +#if ETL_STRING_CLEAR_AFTER_USE_ENABLED + if (other.is_secure()) + { + set_secure(); + } +#endif + cleanup(); } @@ -622,6 +629,24 @@ namespace etl ETL_ASSERT(subposition <= other.size(), ETL_ERROR(string_out_of_bounds)); assign(other.begin() + subposition, sublength); + +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (other.is_truncated()) + { + this->set_truncated(true); + +#if defined(ETL_STRING_TRUNCATION_IS_ERROR) + ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif + } +#endif + +#if ETL_STRING_CLEAR_AFTER_USE_ENABLED + if (other.is_secure()) + { + set_secure(); + } +#endif } //********************************************************************* diff --git a/include/etl/math_constants.h b/include/etl/math_constants.h index bc76cfcd..29595399 100644 --- a/include/etl/math_constants.h +++ b/include/etl/math_constants.h @@ -35,16 +35,16 @@ namespace etl { namespace math { - const double pi = 3.14159265358979; - const double pi_reciprocal = 0.31830988618379; - const double pi_squared = 9.86960440108936; - const double e = 2.71828182845905; - const double e_reciprocal = 0.36787944117144; - const double e_squared = 7.38905609893065; - const double root2 = 1.41421356237310; - const double root2_reciprocal = 0.70710678118655; - const double euler = 0.57721566490153; - const double golden_ratio = 1.61803398874989; + ETL_CONSTANT double pi = 3.14159265358979; + ETL_CONSTANT double pi_reciprocal = 0.31830988618379; + ETL_CONSTANT double pi_squared = 9.86960440108936; + ETL_CONSTANT double e = 2.71828182845905; + ETL_CONSTANT double e_reciprocal = 0.36787944117144; + ETL_CONSTANT double e_squared = 7.38905609893065; + ETL_CONSTANT double root2 = 1.41421356237310; + ETL_CONSTANT double root2_reciprocal = 0.70710678118655; + ETL_CONSTANT double euler = 0.57721566490153; + ETL_CONSTANT double golden_ratio = 1.61803398874989; } } diff --git a/include/etl/nullptr.h b/include/etl/nullptr.h index a661288f..2e200787 100644 --- a/include/etl/nullptr.h +++ b/include/etl/nullptr.h @@ -33,7 +33,7 @@ SOFTWARE. #include "platform.h" -#if defined(ARDUINO) +#if defined(ARDUINO) || defined(AVR) #include #else #include diff --git a/include/etl/string.h b/include/etl/string.h index e7924371..361c2024 100644 --- a/include/etl/string.h +++ b/include/etl/string.h @@ -100,23 +100,12 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - string(const etl::istring& other, size_t position, size_t length_ = npos) + string(const etl::istring& other, size_t position, size_t length = npos) : istring(reinterpret_cast(&buffer), MAX_SIZE) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->assign(other.begin() + position, other.begin() + position + length_); - -#if ETL_STRING_TRUNCATION_CHECKS_ENABLED - if (other.is_truncated()) - { - this->set_truncated(true); - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); -#endif - } -#endif + this->assign(other, position, length); } //************************************************************************* @@ -309,23 +298,12 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - string_ext(const etl::istring& other, value_type* buffer, size_type buffer_size, size_type position, size_type length_ = npos) + string_ext(const etl::istring& other, value_type* buffer, size_type buffer_size, size_type position, size_type length = npos) : istring(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->assign(other.begin() + position, other.begin() + position + length_); - -#if ETL_STRING_TRUNCATION_CHECKS_ENABLED - if (other.is_truncated()) - { - this->set_truncated(true); - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); -#endif - } -#endif + this->assign(other, position, length); } //************************************************************************* diff --git a/include/etl/u16string.h b/include/etl/u16string.h index d3351a9d..e79d9219 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -98,23 +98,12 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u16string(const etl::iu16string& other, size_type position, size_type length_ = npos) + u16string(const etl::iu16string& other, size_type position, size_type length = npos) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->assign(other.begin() + position, other.begin() + position + length_); - -#if ETL_STRING_TRUNCATION_CHECKS_ENABLED - if (other.is_truncated()) - { - this->set_truncated(true); - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); -#endif - } -#endif + this->assign(other, position, length); } //************************************************************************* @@ -292,23 +281,12 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u16string_ext(const etl::iu16string& other, value_type* buffer, size_type buffer_size, size_type position, size_type length_ = npos) + u16string_ext(const etl::iu16string& other, value_type* buffer, size_type buffer_size, size_type position, size_type length = npos) : iu16string(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->assign(other.begin() + position, other.begin() + position + length_); - -#if ETL_STRING_TRUNCATION_CHECKS_ENABLED - if (other.is_truncated()) - { - this->set_truncated(true); - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(u16string_truncation)); -#endif - } -#endif + this->assign(other, position, length); } //************************************************************************* diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 7a0ad002..40ab1ca1 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -98,23 +98,12 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u32string(const etl::iu32string& other, size_type position, size_type length_ = npos) + u32string(const etl::iu32string& other, size_type position, size_type length = npos) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->assign(other.begin() + position, other.begin() + position + length_); - -#if ETL_STRING_TRUNCATION_CHECKS_ENABLED - if (other.is_truncated()) - { - this->set_truncated(true); - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); -#endif - } -#endif + this->assign(other, position, length); } //************************************************************************* @@ -292,23 +281,12 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u32string_ext(const etl::iu32string& other, value_type* buffer, size_type buffer_size, size_type position, size_type length_ = npos) + u32string_ext(const etl::iu32string& other, value_type* buffer, size_type buffer_size, size_type position, size_type length = npos) : iu32string(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->assign(other.begin() + position, other.begin() + position + length_); - -#if ETL_STRING_TRUNCATION_CHECKS_ENABLED - if (other.is_truncated()) - { - this->set_truncated(true); - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(u32string_truncation)); -#endif - } -#endif + this->assign(other, position, length); } //************************************************************************* diff --git a/include/etl/version.h b/include/etl/version.h index 64d6a44a..bce0a92e 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,7 +38,7 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 19 -#define ETL_VERSION_MINOR 1 +#define ETL_VERSION_MINOR 2 #define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/include/etl/wstring.h b/include/etl/wstring.h index a86b24b5..802e6dfb 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -98,23 +98,12 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - wstring(const etl::iwstring& other, size_type position, size_type length_ = npos) + wstring(const etl::iwstring& other, size_type position, size_type length = npos) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->assign(other.begin() + position, other.begin() + position + length_); - -#if ETL_STRING_TRUNCATION_CHECKS_ENABLED - if (other.is_truncated()) - { - this->set_truncated(true); - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); -#endif - } -#endif + this->assign(other, position, length); } //************************************************************************* @@ -292,23 +281,12 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - wstring_ext(const etl::iwstring& other, value_type* buffer, size_type buffer_size, size_type position, size_type length_ = npos) + wstring_ext(const etl::iwstring& other, value_type* buffer, size_type buffer_size, size_type position, size_type length = npos) : iwstring(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->assign(other.begin() + position, other.begin() + position + length_); - -#if ETL_STRING_TRUNCATION_CHECKS_ENABLED - if (other.is_truncated()) - { - this->set_truncated(true); - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(wstring_truncation)); -#endif - } -#endif + this->assign(other, position, length); } //************************************************************************* diff --git a/library.json b/library.json index 32bead34..28ed610d 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "19.1.0", + "version": "19.2.0", "author s": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index d91061e6..3625eedf 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=19.1.0 +version=19.2.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index c0f99551..7b0bb26e 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,9 @@ +=============================================================================== +19.2.0 +Security flag for a string is copied on assignment or copy constructor. +etl::format_spec may now be a constexpr. +Added AVR check to nullptr.h + =============================================================================== 19.1.0 Refactor of etl::buffer_descriptors interface. diff --git a/test/test_format_spec.cpp b/test/test_format_spec.cpp new file mode 100644 index 00000000..471ab91b --- /dev/null +++ b/test/test_format_spec.cpp @@ -0,0 +1,105 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2019 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "UnitTest++/UnitTest++.h" + +#include +#include +#include + +#include "etl/format_spec.h" +#include "etl/wformat_spec.h" +#include "etl/u16format_spec.h" +#include "etl/u32format_spec.h" + +namespace +{ + SUITE(test_format_spec) + { + //************************************************************************* + TEST(test_default_format) + { + etl::format_spec format; + + CHECK_EQUAL(10, format.get_base()); + CHECK_EQUAL(' ', format.get_fill()); + CHECK_EQUAL(0, format.get_precision()); + CHECK_EQUAL(0, format.get_width()); + CHECK_EQUAL(false, format.is_boolalpha()); + CHECK_EQUAL(false, format.is_left()); + CHECK_EQUAL(true, format.is_right()); + CHECK_EQUAL(false, format.is_show_base()); + CHECK_EQUAL(false, format.is_upper_case()); + } + + //************************************************************************* + TEST(test_format) + { + etl::format_spec format; + + format.base(16).boolalpha(true).fill('?').left().precision(6).show_base(true).upper_case(true).width(10); + + CHECK_EQUAL(16, format.get_base()); + CHECK_EQUAL('?', format.get_fill()); + CHECK_EQUAL(6, format.get_precision()); + CHECK_EQUAL(10, format.get_width()); + CHECK_EQUAL(true, format.is_boolalpha()); + CHECK_EQUAL(true, format.is_left()); + CHECK_EQUAL(false, format.is_right()); + CHECK_EQUAL(true, format.is_show_base()); + CHECK_EQUAL(true, format.is_upper_case()); + } + + //************************************************************************* + TEST(test_format_constexpr) + { + constexpr etl::format_spec format = etl::format_spec().base(16).boolalpha(true).fill('?').left().precision(6).show_base(true).upper_case(true).width(10); + + constexpr int base = format.get_base(); + constexpr char fill = format.get_fill(); + constexpr int precision = format.get_precision(); + constexpr int width = format.get_width(); + constexpr bool boolalpha = format.is_boolalpha(); + constexpr bool left = format.is_left(); + constexpr bool right = format.is_right(); + constexpr bool show_base = format.is_show_base(); + constexpr bool upper_case = format.is_upper_case(); + + CHECK_EQUAL(16, base); + CHECK_EQUAL('?', fill); + CHECK_EQUAL(6, precision); + CHECK_EQUAL(10, width); + CHECK_EQUAL(true, boolalpha); + CHECK_EQUAL(true, left); + CHECK_EQUAL(false, right); + CHECK_EQUAL(true, show_base); + CHECK_EQUAL(true, upper_case); + } + }; +} + diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 786cb44b..01e1a32f 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -4138,6 +4138,25 @@ namespace // Check there no non-zero values in the remainder of the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) + { + Text text1 = STR("Hello World"); + text1.set_secure(); + + Text text2(text1); + + Text text3; + text3 = text1; + + Text text4(text1, 6U, 3U); + + CHECK(text2.is_secure()); + CHECK(text3.is_secure()); + CHECK(text4.is_secure()); + } + #endif }; } diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index 69bd1674..3a3d35d4 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -4496,6 +4496,28 @@ namespace // Check there no non-zero values in the remainder of the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) + { + TextBuffer buffer1; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + text1.set_secure(); + + TextBuffer buffer2; + Text text2(text1, buffer2.data(), buffer2.size()); + + TextBuffer buffer3; + Text text3(buffer3.data(), buffer3.size()); + text3 = text1; + + TextBuffer buffer4; + Text text4(text1, buffer4.data(), buffer4.size(), 6U, 2U); + + CHECK(text2.is_secure()); + CHECK(text3.is_secure()); + CHECK(text4.is_secure()); + } #endif }; } diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index ea4031ff..379d18bf 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -4138,6 +4138,24 @@ namespace // Check there no non-zero values in the remainder of the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) + { + Text text1 = STR("Hello World"); + text1.set_secure(); + + Text text2(text1); + + Text text3; + text3 = text1; + + Text text4(text1, 6U, 3U); + + CHECK(text2.is_secure()); + CHECK(text3.is_secure()); + CHECK(text4.is_secure()); + } #endif }; } diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index d3339e61..4673ab2c 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -4496,6 +4496,28 @@ namespace // Check there no non-zero values in the remainder of the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) + { + TextBuffer buffer1; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + text1.set_secure(); + + TextBuffer buffer2; + Text text2(text1, buffer2.data(), buffer2.size()); + + TextBuffer buffer3; + Text text3(buffer3.data(), buffer3.size()); + text3 = text1; + + TextBuffer buffer4; + Text text4(text1, buffer4.data(), buffer4.size(), 6U, 2U); + + CHECK(text2.is_secure()); + CHECK(text3.is_secure()); + CHECK(text4.is_secure()); + } #endif }; } diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index ab3e7775..4e011676 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -4138,6 +4138,24 @@ namespace // Check there no non-zero values in the remainder of the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) + { + Text text1 = STR("Hello World"); + text1.set_secure(); + + Text text2(text1); + + Text text3; + text3 = text1; + + Text text4(text1, 6U, 3U); + + CHECK(text2.is_secure()); + CHECK(text3.is_secure()); + CHECK(text4.is_secure()); + } #endif }; } diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index e4343826..859dbfcf 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -4481,20 +4481,25 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_secure_after_clear) + TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); - text.set_secure(); - text.assign(STR("ABCDEF")); + TextBuffer buffer1; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + text1.set_secure(); - Text::pointer pb = text.begin(); - Text::pointer pe = text.end(); + TextBuffer buffer2; + Text text2(text1, buffer2.data(), buffer2.size()); - text.clear(); + TextBuffer buffer3; + Text text3(buffer3.data(), buffer3.size()); + text3 = text1; - // Check there no non-zero values in the remainder of the string. - CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); + TextBuffer buffer4; + Text text4(text1, buffer4.data(), buffer4.size(), 6U, 2U); + + CHECK(text2.is_secure()); + CHECK(text3.is_secure()); + CHECK(text4.is_secure()); } #endif }; diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 7b4d096b..26cbde56 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -4138,6 +4138,24 @@ namespace // Check there no non-zero values in the remainder of the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) + { + Text text1 = STR("Hello World"); + text1.set_secure(); + + Text text2(text1); + + Text text3; + text3 = text1; + + Text text4(text1, 6U, 3U); + + CHECK(text2.is_secure()); + CHECK(text3.is_secure()); + CHECK(text4.is_secure()); + } #endif }; } diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index ed1bceb9..009a48bf 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -4481,20 +4481,25 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_secure_after_clear) + TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) { - TextBuffer buffer; - Text text(buffer.data(), buffer.size()); - text.set_secure(); - text.assign(STR("ABCDEF")); + TextBuffer buffer1; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + text1.set_secure(); - Text::pointer pb = text.begin(); - Text::pointer pe = text.end(); + TextBuffer buffer2; + Text text2(text1, buffer2.data(), buffer2.size()); - text.clear(); + TextBuffer buffer3; + Text text3(buffer3.data(), buffer3.size()); + text3 = text1; - // Check there no non-zero values in the remainder of the string. - CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); + TextBuffer buffer4; + Text text4(text1, buffer4.data(), buffer4.size(), 6U, 2U); + + CHECK(text2.is_secure()); + CHECK(text3.is_secure()); + CHECK(text4.is_secure()); } #endif }; diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 4323d358..2c947ac9 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1515,6 +1515,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 198c3ed2..36af486d 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -1424,6 +1424,9 @@ Source Files + + Source Files +