diff --git a/include/etl/cstring.h b/include/etl/cstring.h index a6b424aa..806a5555 100644 --- a/include/etl/cstring.h +++ b/include/etl/cstring.h @@ -274,18 +274,34 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - string(value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + : istring(buffer, buffer_size - 1U) { - this->initialise(); + if (use_buffer_contents) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->initialise(); + } + } + + //************************************************************************* + /// Constructor direct from buffer. + //************************************************************************* + string(value_type* buffer) + : istring(buffer, etl::strlen(buffer)) + { + this->current_size = etl::strlen(buffer); } //************************************************************************* /// Copy constructor. ///\param other The other string. //************************************************************************* - string(const etl::string<0U>& other, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(const etl::string<0U>& other, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(other); } @@ -294,8 +310,8 @@ namespace etl /// From other istring. ///\param other The other istring. //************************************************************************* - string(const etl::istring& other, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(const etl::istring& other, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(other); } @@ -306,8 +322,8 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - string(const etl::istring& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : istring(buffer, max_size - 1) + string(const etl::istring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : istring(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); @@ -327,8 +343,8 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the string. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(text, text + etl::char_traits::length(text)); } @@ -338,8 +354,8 @@ namespace etl ///\param text The initial text of the string. ///\param count The number of characters to copy. //************************************************************************* - string(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(text, text + count); } @@ -349,8 +365,8 @@ namespace etl ///\param initialSize The initial size of the string. ///\param value The value to fill the string with. //************************************************************************* - string(size_t count, value_type c, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->initialise(); this->resize(count, c); @@ -363,8 +379,8 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - string(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(first, last); } @@ -373,8 +389,8 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - string(std::initializer_list init, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(std::initializer_list init, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); } @@ -384,8 +400,8 @@ namespace etl /// From string_view. ///\param view The string_view. //************************************************************************* - explicit string(const etl::string_view& view, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + explicit string(const etl::string_view& view, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); } diff --git a/include/etl/u16string.h b/include/etl/u16string.h index c3911002..f65c9fcf 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -260,18 +260,34 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - u16string(value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + : iu16string(buffer, buffer_size - 1U) { - this->initialise(); + if (use_buffer_contents) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->initialise(); + } + } + + //************************************************************************* + /// Constructor direct from buffer. + //************************************************************************* + u16string(value_type* buffer) + : iu16string(buffer, etl::strlen(buffer)) + { + this->current_size = etl::strlen(buffer); } //************************************************************************* /// Copy constructor. ///\param other The other u16string. //************************************************************************* - u16string(const etl::u16string<0U>& other, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(const etl::u16string<0U>& other, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(other); } @@ -280,8 +296,8 @@ namespace etl /// From other iu16string. ///\param other The other iu16string. //************************************************************************* - u16string(const etl::iu16string& other, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(const etl::iu16string& other, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(other); } @@ -292,8 +308,8 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u16string(const etl::iu16string& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : iu16string(buffer, max_size - 1) + u16string(const etl::iu16string& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : iu16string(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); @@ -313,8 +329,8 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the u16string. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR u16string(const value_type* text, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + ETL_EXPLICIT_STRING_FROM_CHAR u16string(const value_type* text, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(text, text + etl::char_traits::length(text)); } @@ -324,8 +340,8 @@ namespace etl ///\param text The initial text of the u16string. ///\param count The number of characters to copy. //************************************************************************* - u16string(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(text, text + count); } @@ -335,8 +351,8 @@ namespace etl ///\param initialSize The initial size of the u16string. ///\param value The value to fill the u16string with. //************************************************************************* - u16string(size_t count, value_type c, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->initialise(); this->resize(count, c); @@ -349,8 +365,8 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - u16string(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(first, last); } @@ -359,8 +375,8 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - u16string(std::initializer_list init, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(std::initializer_list init, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); } @@ -370,8 +386,8 @@ namespace etl /// From u16string_view. ///\param view The u16string_view. //************************************************************************* - explicit u16string(const etl::u16string_view& view, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + explicit u16string(const etl::u16string_view& view, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); } diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 7de99cb6..38c24b4b 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -260,18 +260,34 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - u32string(value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + : iu32string(buffer, buffer_size - 1U) { - this->initialise(); + if (use_buffer_contents) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->initialise(); + } + } + + //************************************************************************* + /// Constructor direct from buffer. + //************************************************************************* + u32string(value_type* buffer) + : iu32string(buffer, etl::strlen(buffer)) + { + this->current_size = etl::strlen(buffer); } //************************************************************************* /// Copy constructor. ///\param other The other u32string. //************************************************************************* - u32string(const etl::u32string<0U>& other, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(const etl::u32string<0U>& other, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(other); } @@ -280,8 +296,8 @@ namespace etl /// From other iu32string. ///\param other The other iu32string. //************************************************************************* - u32string(const etl::iu32string& other, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(const etl::iu32string& other, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(other); } @@ -292,8 +308,8 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u32string(const etl::iu32string& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : iu32string(buffer, max_size - 1) + u32string(const etl::iu32string& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : iu32string(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); @@ -313,8 +329,8 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the u32string. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(text, text + etl::char_traits::length(text)); } @@ -324,8 +340,8 @@ namespace etl ///\param text The initial text of the u32string. ///\param count The number of characters to copy. //************************************************************************* - u32string(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(text, text + count); } @@ -335,8 +351,8 @@ namespace etl ///\param initialSize The initial size of the u32string. ///\param value The value to fill the u32string with. //************************************************************************* - u32string(size_t count, value_type c, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->initialise(); this->resize(count, c); @@ -349,8 +365,8 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - u32string(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(first, last); } @@ -359,8 +375,8 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - u32string(std::initializer_list init, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(std::initializer_list init, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); } @@ -370,8 +386,8 @@ namespace etl /// From u32string_view. ///\param view The u32string_view. //************************************************************************* - explicit u32string(const etl::u32string_view& view, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + explicit u32string(const etl::u32string_view& view, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); } diff --git a/include/etl/version.h b/include/etl/version.h index d09a042f..eb0b5456 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,8 +38,8 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 18 -#define ETL_VERSION_MINOR 14 -#define ETL_VERSION_PATCH 1 +#define ETL_VERSION_MINOR 15 +#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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 562ac06e..d5c89661 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -261,18 +261,34 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - wstring(value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + : iwstring(buffer, buffer_size - 1U) { - this->initialise(); + if (use_buffer_contents) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->initialise(); + } + } + + //************************************************************************* + /// Constructor direct from buffer. + //************************************************************************* + wstring(value_type* buffer) + : iwstring(buffer, etl::strlen(buffer)) + { + this->current_size = etl::strlen(buffer); } //************************************************************************* /// Copy constructor. ///\param other The other wstring. //************************************************************************* - wstring(const etl::wstring<0U>& other, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(const etl::wstring<0U>& other, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(other); } @@ -281,8 +297,8 @@ namespace etl /// From other iwstring. ///\param other The other iwstring. //************************************************************************* - wstring(const etl::iwstring& other, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(const etl::iwstring& other, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(other); } @@ -293,8 +309,8 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - wstring(const etl::iwstring& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : iwstring(buffer, max_size - 1) + wstring(const etl::iwstring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : iwstring(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); @@ -314,8 +330,8 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the wstring. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR wstring(const value_type* text, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + ETL_EXPLICIT_STRING_FROM_CHAR wstring(const value_type* text, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(text, text + etl::char_traits::length(text)); } @@ -325,8 +341,8 @@ namespace etl ///\param text The initial text of the wstring. ///\param count The number of characters to copy. //************************************************************************* - wstring(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(text, text + count); } @@ -336,8 +352,8 @@ namespace etl ///\param initialSize The initial size of the wstring. ///\param value The value to fill the wstring with. //************************************************************************* - wstring(size_t count, value_type c, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->initialise(); this->resize(count, c); @@ -350,8 +366,8 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - wstring(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(first, last); } @@ -360,8 +376,8 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - wstring(std::initializer_list init, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(std::initializer_list init, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); } @@ -371,8 +387,8 @@ namespace etl /// From wstring_view. ///\param view The wstring_view. //************************************************************************* - explicit wstring(const etl::wstring_view& view, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + explicit wstring(const etl::wstring_view& view, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); } diff --git a/library.json b/library.json index f519d66c..4ea5c97a 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.14.1", + "version": "18.15.0", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index f359f708..7acb642c 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.14.1 +version=18.15.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 84c36e41..8f897939 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.15.0 +Allow strings with external buffers to use a pre-initialised buffer. + =============================================================================== 18.14.1 Fixed conditional compilation macro use for template deduction guides. diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index d4f8d9ff..354ed5ca 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -73,6 +73,9 @@ namespace Compare_Text short_text; const value_t* pinitial_text = STR("Hello World"); + + value_t array_text[12]; + value_t* p_text = array_text; //************************************************************************* template @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,72 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) + { + Text text(p_text); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, etl::strlen(p_text) + 1, true); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, etl::size(array_text), true); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index 08115e6b..2f14651d 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -74,6 +74,9 @@ namespace const value_t* pinitial_text = STR("Hello World"); + value_t array_text[12]; + value_t* p_text = array_text; + //************************************************************************* template bool Equal(const T1& compare_text, const T2& text) @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,72 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) + { + Text text(p_text); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, etl::strlen(p_text) + 1, true); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, etl::size(array_text), true); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index cdc8d4a1..5500699c 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -74,6 +74,9 @@ namespace const value_t* pinitial_text = STR("Hello World"); + value_t array_text[12]; + value_t* p_text = array_text; + //************************************************************************* template bool Equal(const T1& compare_text, const T2& text) @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,72 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) + { + Text text(p_text); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, etl::strlen(p_text) + 1, true); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, etl::size(array_text), true); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index b6c851bc..2814f5eb 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -74,6 +74,9 @@ namespace const value_t* pinitial_text = STR("Hello World"); + value_t array_text[12]; + value_t* p_text = array_text; + //************************************************************************* template bool Equal(const T1& compare_text, const T2& text) @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,72 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) + { + Text text(p_text); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, etl::strlen(p_text) + 1, true); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, etl::size(array_text), true); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) {