From 94f2da7d2090c83f56fcc0b08239b54d032c1297 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 22 Jul 2025 13:29:17 +0100 Subject: [PATCH 1/8] Work in progress --- include/etl/basic_string.h | 168 +- include/etl/const_string.h | 106 + test/test_const_string_char.cpp | 5479 +++++++++++++++++++++++++++++++ test/vs2022/etl.vcxproj | 1 + 4 files changed, 5670 insertions(+), 84 deletions(-) create mode 100644 include/etl/const_string.h create mode 100644 test/test_const_string_char.cpp diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 934af455..9dd41c16 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -190,7 +190,7 @@ namespace etl /// Gets the current size of the string. ///\return The current size of the string. //************************************************************************* - size_type size() const + ETL_CONSTEXPR14 size_type size() const { return current_size; } @@ -199,7 +199,7 @@ namespace etl /// Gets the current size of the string. ///\return The current size of the string. //************************************************************************* - size_type length() const + ETL_CONSTEXPR14 size_type length() const { return current_size; } @@ -208,7 +208,7 @@ namespace etl /// Checks the 'empty' state of the string. ///\return true if empty. //************************************************************************* - bool empty() const + ETL_CONSTEXPR14 bool empty() const { return (current_size == 0); } @@ -217,7 +217,7 @@ namespace etl /// Checks the 'full' state of the string. ///\return true if full. //************************************************************************* - bool full() const + ETL_CONSTEXPR14 bool full() const { return current_size == CAPACITY; } @@ -226,7 +226,7 @@ namespace etl /// Returns the capacity of the string. ///\return The capacity of the string. //************************************************************************* - size_type capacity() const + ETL_CONSTEXPR14 size_type capacity() const { return CAPACITY; } @@ -235,7 +235,7 @@ namespace etl /// Returns the maximum possible size of the string. ///\return The maximum size of the string. //************************************************************************* - size_type max_size() const + ETL_CONSTEXPR14 size_type max_size() const { return CAPACITY; } @@ -244,7 +244,7 @@ namespace etl /// Returns the remaining capacity. ///\return The remaining capacity. //************************************************************************* - size_type available() const + ETL_CONSTEXPR14 size_type available() const { return max_size() - size(); } @@ -253,7 +253,7 @@ namespace etl /// Returns whether the string was truncated by the last operation. ///\return Whether the string was truncated by the last operation. //************************************************************************* - bool is_truncated() const + ETL_CONSTEXPR14 bool is_truncated() const { #if ETL_HAS_STRING_TRUNCATION_CHECKS return flags.test(); @@ -268,7 +268,7 @@ namespace etl ///\return Whether the string was truncated by the last operation. //************************************************************************* ETL_DEPRECATED - bool truncated() const + ETL_CONSTEXPR14 bool truncated() const { return is_truncated(); } @@ -296,7 +296,7 @@ namespace etl //************************************************************************* /// Gets the 'secure' state flag. //************************************************************************* - bool is_secure() const + ETL_CONSTEXPR14 bool is_secure() const { #if ETL_HAS_STRING_CLEAR_AFTER_USE return flags.test(); @@ -310,7 +310,7 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - string_base(size_type max_size_) + ETL_CONSTEXPR14 string_base(size_type max_size_) : current_size(0) , CAPACITY(max_size_) { @@ -329,7 +329,7 @@ namespace etl //************************************************************************* /// Destructor. //************************************************************************* - ~string_base() + ETL_CONSTEXPR14 ~string_base() { } @@ -378,7 +378,7 @@ namespace etl /// Returns a const_iterator to the beginning of the string. ///\return A const iterator to the beginning of the string. //********************************************************************* - const_iterator begin() const + ETL_CONSTEXPR14 const_iterator begin() const { return &p_buffer[0]; } @@ -396,7 +396,7 @@ namespace etl /// Returns a const_iterator to the end of the string. ///\return A const iterator to the end of the string. //********************************************************************* - const_iterator end() const + ETL_CONSTEXPR14 const_iterator end() const { return &p_buffer[current_size]; } @@ -405,7 +405,7 @@ namespace etl /// Returns a const_iterator to the beginning of the string. ///\return A const iterator to the beginning of the string. //********************************************************************* - const_iterator cbegin() const + ETL_CONSTEXPR14 const_iterator cbegin() const { return &p_buffer[0]; } @@ -414,7 +414,7 @@ namespace etl /// Returns a const_iterator to the end of the string. ///\return A const iterator to the end of the string. //********************************************************************* - const_iterator cend() const + ETL_CONSTEXPR14 const_iterator cend() const { return &p_buffer[current_size]; } @@ -432,7 +432,7 @@ namespace etl /// Returns a const reverse iterator to the reverse beginning of the string. ///\return Const iterator to the reverse beginning of the string. //********************************************************************* - const_reverse_iterator rbegin() const + ETL_CONSTEXPR14 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } @@ -441,7 +441,7 @@ namespace etl /// Returns a reverse iterator to the end + 1 of the string. ///\return Reverse iterator to the end + 1 of the string. //********************************************************************* - reverse_iterator rend() + ETL_CONSTEXPR14 reverse_iterator rend() { return reverse_iterator(begin()); } @@ -450,7 +450,7 @@ namespace etl /// Returns a const reverse iterator to the end + 1 of the string. ///\return Const reverse iterator to the end + 1 of the string. //********************************************************************* - const_reverse_iterator rend() const + ETL_CONSTEXPR14 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } @@ -459,7 +459,7 @@ namespace etl /// Returns a const reverse iterator to the reverse beginning of the string. ///\return Const reverse iterator to the reverse beginning of the string. //********************************************************************* - const_reverse_iterator crbegin() const + ETL_CONSTEXPR14 const_reverse_iterator crbegin() const { return const_reverse_iterator(cend()); } @@ -468,7 +468,7 @@ namespace etl /// Returns a const reverse iterator to the end + 1 of the string. ///\return Const reverse iterator to the end + 1 of the string. //********************************************************************* - const_reverse_iterator crend() const + ETL_CONSTEXPR14 const_reverse_iterator crend() const { return const_reverse_iterator(cbegin()); } @@ -568,7 +568,7 @@ namespace etl ///\param i The index. ///\return A const reference to the value at index 'i' //********************************************************************* - const_reference operator [](size_type i) const + ETL_CONSTEXPR14 const_reference operator [](size_type i) const { return p_buffer[i]; } @@ -591,7 +591,7 @@ namespace etl ///\param i The index. ///\return A const reference to the value at index 'i' //********************************************************************* - const_reference at(size_type i) const + ETL_CONSTEXPR14 const_reference at(size_type i) const { ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds)); return p_buffer[i]; @@ -610,7 +610,7 @@ namespace etl /// Returns a const reference to the first element. ///\return A const reference to the first element. //********************************************************************* - const_reference front() const + ETL_CONSTEXPR14 const_reference front() const { return p_buffer[0]; } @@ -628,7 +628,7 @@ namespace etl /// Returns a const reference to the last element. ///\return A const reference to the last element. //********************************************************************* - const_reference back() const + ETL_CONSTEXPR14 const_reference back() const { return p_buffer[current_size - 1]; } @@ -664,7 +664,7 @@ namespace etl /// Returns a const pointer to the beginning of the string data. ///\return A const pointer to the beginning of the string data. //********************************************************************* - const_pointer data_end() const + ETL_CONSTEXPR14 const_pointer data_end() const { return p_buffer + current_size; } @@ -1371,7 +1371,7 @@ namespace etl //********************************************************************* /// Return a pointer to a C string. //********************************************************************* - const_pointer c_str() const + ETL_CONSTEXPR14 const_pointer c_str() const { return p_buffer; } @@ -1382,7 +1382,7 @@ namespace etl ///\param count The number of characters to copy. ///\param pos The position to start copying from. //********************************************************************* - size_type copy(pointer dest, size_type count, size_type pos = 0) const + ETL_CONSTEXPR14 size_type copy(pointer dest, size_type count, size_type pos = 0) const { if (pos < size()) { @@ -1421,7 +1421,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find(const etl::basic_string_view& view, size_type pos = 0) const + ETL_CONSTEXPR14 size_type find(const etl::basic_string_view& view, size_type pos = 0) const { return find_impl(view.begin(), view.end(), view.size(), pos); } @@ -1431,7 +1431,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find(const_pointer s, size_type pos = 0) const + ETL_CONSTEXPR14 size_type find(const_pointer s, size_type pos = 0) const { size_t sz = etl::strlen(s); @@ -1444,7 +1444,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_type find(const_pointer s, size_type pos, size_type n) const + ETL_CONSTEXPR14 size_type find(const_pointer s, size_type pos, size_type n) const { size_t sz = etl::strlen(s); @@ -1475,7 +1475,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type rfind(const ibasic_string& str, size_type position = npos) const + ETL_CONSTEXPR14 size_type rfind(const ibasic_string& str, size_type position = npos) const { return rfind_impl(str.rbegin(), str.rend(), str.size(), position); } @@ -1496,7 +1496,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type rfind(const_pointer s, size_type position = npos) const + ETL_CONSTEXPR14 size_type rfind(const_pointer s, size_type position = npos) const { size_type len = etl::strlen(s); @@ -1511,7 +1511,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type rfind(const_pointer s, size_type position, size_type length_) const + ETL_CONSTEXPR14 size_type rfind(const_pointer s, size_type position, size_type length_) const { const_reverse_iterator srbegin(s + length_); const_reverse_iterator srend(s); @@ -1524,7 +1524,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - size_type rfind(T c, size_type position = npos) const + ETL_CONSTEXPR14 size_type rfind(T c, size_type position = npos) const { if (position >= size()) { @@ -1548,7 +1548,7 @@ namespace etl //********************************************************************* /// Checks that the string is within this string //********************************************************************* - bool contains(const etl::ibasic_string& str) const + ETL_CONSTEXPR14 bool contains(const etl::ibasic_string& str) const { return find(str) != npos; } @@ -1557,7 +1557,7 @@ namespace etl /// Checks that the view is within this string //********************************************************************* template - bool contains(const etl::basic_string_view& view) const + ETL_CONSTEXPR14 bool contains(const etl::basic_string_view& view) const { return find(view) != npos; } @@ -1565,7 +1565,7 @@ namespace etl //********************************************************************* /// Checks that text is within this string //********************************************************************* - bool contains(const_pointer s) const + ETL_CONSTEXPR14 bool contains(const_pointer s) const { return find(s) != npos; } @@ -1573,7 +1573,7 @@ namespace etl //********************************************************************* /// Checks that character is within this string //********************************************************************* - bool contains(value_type c) const + ETL_CONSTEXPR14 bool contains(value_type c) const { return find(c) != npos; } @@ -1581,7 +1581,7 @@ namespace etl //********************************************************************* /// Checks that the string is the start of this string //********************************************************************* - bool starts_with(const etl::ibasic_string& str) const + ETL_CONSTEXPR14 bool starts_with(const etl::ibasic_string& str) const { return compare(0, str.size(), str) == 0; } @@ -1590,7 +1590,7 @@ namespace etl /// Checks that the view is the start of this string //********************************************************************* template - bool starts_with(const etl::basic_string_view& view) const + ETL_CONSTEXPR14 bool starts_with(const etl::basic_string_view& view) const { return compare(0, view.size(), view) == 0; } @@ -1598,7 +1598,7 @@ namespace etl //********************************************************************* /// Checks that the string is the start of this string //********************************************************************* - bool starts_with(const_pointer s) const + ETL_CONSTEXPR14 bool starts_with(const_pointer s) const { size_t len = etl::strlen(s); @@ -1608,7 +1608,7 @@ namespace etl //********************************************************************* /// Checks that the character is the start of this string //********************************************************************* - bool starts_with(value_type c) const + ETL_CONSTEXPR14 bool starts_with(value_type c) const { return !empty() && (front() == c); } @@ -1616,7 +1616,7 @@ namespace etl //********************************************************************* /// Checks that the string is the end of this string //********************************************************************* - bool ends_with(const etl::ibasic_string& str) const + ETL_CONSTEXPR14 bool ends_with(const etl::ibasic_string& str) const { if (str.size() > size()) { @@ -1630,7 +1630,7 @@ namespace etl /// Checks that the view is the end of this string //********************************************************************* template - bool ends_with(const etl::basic_string_view& view) const + ETL_CONSTEXPR14 bool ends_with(const etl::basic_string_view& view) const { if (view.size() > size()) { @@ -1643,7 +1643,7 @@ namespace etl //********************************************************************* /// Checks that the string is the end of this string //********************************************************************* - bool ends_with(const_pointer s) const + ETL_CONSTEXPR14 bool ends_with(const_pointer s) const { size_t len = etl::strlen(s); @@ -1658,7 +1658,7 @@ namespace etl //********************************************************************* /// Checks that the character is the end of this string //********************************************************************* - bool ends_with(value_type c) const + ETL_CONSTEXPR14 bool ends_with(value_type c) const { return !empty() && (back() == c); } @@ -1949,7 +1949,7 @@ namespace etl //************************************************************************* /// Compare with string. //************************************************************************* - int compare(const ibasic_string& str) const + ETL_CONSTEXPR14 int compare(const ibasic_string& str) const { return compare(p_buffer, p_buffer + size(), @@ -1961,7 +1961,7 @@ namespace etl /// Compare with etl::basic_string_view. //************************************************************************* template - int compare(const etl::basic_string_view& view) const + ETL_CONSTEXPR14 int compare(const etl::basic_string_view& view) const { return compare(p_buffer, p_buffer + size(), @@ -1972,7 +1972,7 @@ namespace etl //************************************************************************* /// Compare position / length with string. //************************************************************************* - int compare(size_type position, size_type length_, const ibasic_string& str) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const ibasic_string& str) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1989,7 +1989,7 @@ namespace etl /// Compare position / length with etl::basic_string_view. //************************************************************************* template - int compare(size_type position, size_type length_, const etl::basic_string_view& view) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const etl::basic_string_view& view) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2000,7 +2000,7 @@ namespace etl //************************************************************************* /// Compare position / length with string / subposition / sublength. //************************************************************************* - int compare(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); @@ -2019,7 +2019,7 @@ namespace etl /// Compare position / length with etl::basic_string_view. / subposition / sublength. //************************************************************************* template - int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); @@ -2037,7 +2037,7 @@ namespace etl //************************************************************************* /// Compare with C string //************************************************************************* - int compare(const value_type* s) const + ETL_CONSTEXPR14 int compare(const value_type* s) const { return compare(p_buffer, p_buffer + size(), @@ -2048,7 +2048,7 @@ namespace etl //************************************************************************* /// Compare position / length with C string. //************************************************************************* - int compare(size_type position, size_type length_, const_pointer s) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const_pointer s) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2059,7 +2059,7 @@ namespace etl //************************************************************************* /// Compare position / length with C string / n. //************************************************************************* - int compare(size_type position, size_type length_, const_pointer s, size_type n) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const_pointer s, size_type n) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2072,7 +2072,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_of(const ibasic_string& str, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_of(const ibasic_string& str, size_type position = 0) const { return find_first_of(str.c_str(), position, str.size()); } @@ -2082,7 +2082,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_of(const_pointer s, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_of(const_pointer s, size_type position = 0) const { return find_first_of(s, position, etl::strlen(s)); } @@ -2093,7 +2093,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_of(view.data(), position, view.size()); } @@ -2104,7 +2104,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_type find_first_of(const_pointer s, size_type position, size_type n) const + ETL_CONSTEXPR14 size_type find_first_of(const_pointer s, size_type position, size_type n) const { if (position < size()) { @@ -2128,7 +2128,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_of(value_type c, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_of(value_type c, size_type position = 0) const { if (position < size()) { @@ -2149,7 +2149,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_last_of(const ibasic_string& str, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_of(const ibasic_string& str, size_type position = npos) const { return find_last_of(str.c_str(), position, str.size()); } @@ -2159,7 +2159,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_last_of(const_pointer s, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_of(const_pointer s, size_type position = npos) const { return find_last_of(s, position, etl::strlen(s)); } @@ -2170,7 +2170,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_of(view.data(), position, view.size()); } @@ -2181,7 +2181,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_type find_last_of(const_pointer s, size_type position, size_type n) const + ETL_CONSTEXPR14 size_type find_last_of(const_pointer s, size_type position, size_type n) const { if (empty()) { @@ -2214,7 +2214,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_last_of(value_type c, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_of(value_type c, size_type position = npos) const { if (empty()) { @@ -2244,7 +2244,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_not_of(const ibasic_string& str, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_not_of(const ibasic_string& str, size_type position = 0) const { return find_first_not_of(str.c_str(), position, str.size()); } @@ -2254,7 +2254,7 @@ namespace etl ///\param s Pointer to the content to not find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_not_of(const_pointer s, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_not_of(const_pointer s, size_type position = 0) const { return find_first_not_of(s, position, etl::strlen(s)); } @@ -2265,7 +2265,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_not_of(view.data(), position, view.size()); } @@ -2276,7 +2276,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_type find_first_not_of(const_pointer s, size_type position, size_type n) const + ETL_CONSTEXPR14 size_type find_first_not_of(const_pointer s, size_type position, size_type n) const { if (position < size()) { @@ -2307,7 +2307,7 @@ namespace etl ///\param c The character to not find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_not_of(value_type c, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_not_of(value_type c, size_type position = 0) const { if (position < size()) { @@ -2328,7 +2328,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_last_not_of(const ibasic_string& str, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_not_of(const ibasic_string& str, size_type position = npos) const { return find_last_not_of(str.c_str(), position, str.size()); } @@ -2338,7 +2338,7 @@ namespace etl ///\param s The pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_last_not_of(const_pointer s, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_not_of(const_pointer s, size_type position = npos) const { return find_last_not_of(s, position, etl::strlen(s)); } @@ -2349,7 +2349,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_not_of(view.data(), position, view.size()); } @@ -2360,7 +2360,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to use. //********************************************************************* - size_type find_last_not_of(const_pointer s, size_type position, size_type n) const + ETL_CONSTEXPR14 size_type find_last_not_of(const_pointer s, size_type position, size_type n) const { if (empty()) { @@ -2398,7 +2398,7 @@ namespace etl //********************************************************************* // //********************************************************************* - size_type find_last_not_of(value_type c, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_not_of(value_type c, size_type position = npos) const { if (empty()) { @@ -2536,7 +2536,7 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - ibasic_string(T* p_buffer_, size_type MAX_SIZE_) + ETL_CONSTEXPR14 ibasic_string(T* p_buffer_, size_type MAX_SIZE_) : string_base(MAX_SIZE_), p_buffer(p_buffer_) { @@ -2545,7 +2545,7 @@ namespace etl //********************************************************************* /// Initialise the string. //********************************************************************* - void initialise() + ETL_CONSTEXPR14 void initialise() { current_size = 0U; p_buffer[0] = 0; @@ -2567,8 +2567,8 @@ namespace etl //************************************************************************* /// Compare helper function //************************************************************************* - static int compare(const_pointer first1, const_pointer last1, - const_pointer first2, const_pointer last2) + ETL_CONSTEXPR14 static int compare(const_pointer first1, const_pointer last1, + const_pointer first2, const_pointer last2) { typedef typename etl::make_unsigned::type type; @@ -2644,7 +2644,7 @@ namespace etl #else protected: #endif - ~ibasic_string() + ETL_CONSTEXPR14 ~ibasic_string() { #if ETL_HAS_STRING_CLEAR_AFTER_USE if (is_secure()) @@ -2659,7 +2659,7 @@ namespace etl //************************************************************************* /// Convert from const_iterator to iterator //************************************************************************* - iterator to_iterator(const_iterator itr) const + ETL_CONSTEXPR14 iterator to_iterator(const_iterator itr) const { return const_cast(itr); } @@ -2782,7 +2782,7 @@ namespace etl /// Common implementation for 'find'. //************************************************************************* template - size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const + ETL_CONSTEXPR14 size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const { if ((pos + sz) > size()) { @@ -2805,7 +2805,7 @@ namespace etl /// Common implementation for 'rfind'. //************************************************************************* template - size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const + ETL_CONSTEXPR14 size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const { if (sz > size()) { diff --git a/include/etl/const_string.h b/include/etl/const_string.h new file mode 100644 index 00000000..ab698d4e --- /dev/null +++ b/include/etl/const_string.h @@ -0,0 +1,106 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +#ifndef ETL_STRING_INCLUDED +#define ETL_STRING_INCLUDED + +#include "platform.h" +#include "basic_string.h" +#include "string_view.h" +#include "hash.h" +#include "initializer_list.h" + +#include + +#include "private/minmax_push.h" + +namespace etl +{ +#if ETL_USING_CPP11 + inline namespace literals + { + inline namespace string_literals + { + inline constexpr etl::string_view operator ""_sv(const char* str, size_t length) noexcept + { + return etl::string_view{ str, length }; + } + } + } +#endif + + typedef etl::ibasic_string istring; + + //*************************************************************************** + /// A string implementation that uses a fixed size external buffer. + ///\ingroup string + //*************************************************************************** + class const_string : public istring + { + public: + + typedef istring base_type; + typedef istring interface_type; + + typedef istring::value_type value_type; + typedef istring::size_type size_type; + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_string(const value_type* buffer) + : istring(const_cast(buffer), etl::strlen(buffer)) + { + this->current_size = etl::strlen(buffer); + } + + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* +#if ETL_HAS_ISTRING_REPAIR + constexpr virtual void repair() ETL_OVERRIDE +#else + constexpr void repair() +#endif + { + } + + private: + + //************************************************************************* + /// Deleted. + //************************************************************************* + const_string(const const_string& other) ETL_DELETE; + }; +} + +#include "private/minmax_pop.h" + +#endif diff --git a/test/test_const_string_char.cpp b/test/test_const_string_char.cpp new file mode 100644 index 00000000..f46c90f3 --- /dev/null +++ b/test/test_const_string_char.cpp @@ -0,0 +1,5479 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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 "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/const_string.h" +#include "etl/string_view.h" +#include "etl/fnv_1.h" + +#undef STR +#define STR(x) x + +namespace +{ + bool compares_agree(int result1, int result2) + { + return ((result1 < 0) && (result2 < 0)) || + ((result1 == 0) && (result2 == 0)) || + ((result1 > 0) && (result2 > 0)); + } + + SUITE(test_string_char) + { + static const size_t SIZE = 11UL; + + using Text = etl::const_string; + using IText = const etl::istring; + using TextSTD = std::string; + using value_t = Text::value_type; + //using TextL = etl::string<52>; + //using TextS = etl::string<4>; + //using View = etl::string_view; + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; + + const value_t* pinitial_text = STR("Hello World"); + + //************************************************************************* + template + bool Equal(const T1& compare_text, const T2& text) + { + return (compare_text.size() == text.size()) && std::equal(text.begin(), text.end(), compare_text.begin()); + } + + //************************************************************************* + struct SetupFixture + { + SetupFixture() + { + initial_text = STR("Hello World"); + insert_text = STR("Insert"); + less_text = STR("Hello Vorld"); + greater_text = STR("Hello Xorld"); + shorter_text = STR("Hello Worl"); + different_text = STR("Byee Planet"); + longer_text = STR("Hello World There"); + short_text = STR("Hello"); + } + }; + +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_default_constructor) +// { +// +// Text text; +// +// CHECK_EQUAL(text.size(), size_t(0)); +// CHECK(text.empty()); +// CHECK_EQUAL(text.capacity(), SIZE); +// CHECK_EQUAL(text.max_size(), SIZE); +// CHECK(text.begin() == text.end()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST(test_iterator_comparison_empty) +// { +// Text text; +// +// CHECK(text.begin() == text.end()); +// CHECK(text.cbegin() == text.cend()); +// CHECK(text.rbegin() == text.rend()); +// CHECK(text.crbegin() == text.crend()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_size_value) +// { +// const size_t INITIAL_SIZE = 5UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); +// Text text(INITIAL_SIZE, INITIAL_VALUE); +// +// CHECK(text.size() == INITIAL_SIZE); +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_size_excess) +// { +// Text text(SIZE + 1, STR('A')); +// +// CHECK_EQUAL(SIZE, text.size()); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) + { + TextSTD compare_text(initial_text.c_str()); + + static constexpr const char* initial = "Hello World"; + static constexpr Text text(initial); + static constexpr size_t length = etl::strlen(initial); + + static constexpr auto text_empty = text.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text.full(); + CHECK_TRUE(text_full); + + text.capacity(); + text.max_size(); + text.size(); + text.length(); + text.available(); + text.is_truncated(); + text.is_secure(); + + static constexpr const char* text_data = text.data(); + CHECK_EQUAL(&initial[0], text_data); + + static constexpr const char* text_data_end = text.data_end(); + CHECK_EQUAL(&initial[length], text_data_end); + + static constexpr auto text_begin = text.begin(); + CHECK_EQUAL(&initial[0], text_begin); + + static constexpr auto text_cbegin = text.cbegin(); + CHECK_EQUAL(&initial[0], text_cbegin); + + static constexpr auto text_rbegin = text.rbegin(); + CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text.crbegin(); + CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text.end(); + CHECK_EQUAL(&initial[length], text_end); + + static constexpr auto text_cend = text.cend(); + CHECK_EQUAL(&initial[length], text_cend); + + static constexpr auto text_rend = text.rend(); + CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text.crend(); + CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_crend)); + + static constexpr auto text_contains_world = text.contains("World"); + CHECK_TRUE(text_contains_world); + + static constexpr auto text_contains_worls = text.contains("Worls"); + CHECK_FALSE(text_contains_worls); + + static constexpr auto text_starts_with_hello = text.starts_with("Hello"); + CHECK_TRUE(text_starts_with_hello); + + static constexpr auto text_starts_with_world = text.starts_with("World"); + CHECK_FALSE(text_starts_with_world); + + static constexpr auto text_ends_with_hello = text.ends_with("Hello"); + CHECK_FALSE(text_ends_with_hello); + + static constexpr auto text_ends_with_world = text.ends_with("World"); + CHECK_TRUE(text_ends_with_world); + + static constexpr auto text_find_world = text.find("World"); + CHECK_EQUAL(6, text_find_world); + + static constexpr auto text_find_worls = text.find("Worls"); + CHECK_EQUAL(Text::npos, text_find_worls); + + static constexpr auto text_index_operator = text[3]; + CHECK_EQUAL(initial[3], text_index_operator); + + static constexpr auto text_at = text.at(3); + CHECK_EQUAL(initial[3], text_at); + + static constexpr auto text_front = text.front(); + CHECK_EQUAL(initial[0], text_front); + + static constexpr auto text_back = text.back(); + CHECK_EQUAL(initial[length - 1], text_back); + + static constexpr const char* text_c_str = text.c_str(); + CHECK_EQUAL(&initial[0], text_c_str); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + } + +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_shorter_string) +// { +// TextSTD compare_text(shorter_text.c_str()); +// +// Text text(shorter_text.c_str()); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text(longer_text.c_str()); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) +// { +// TextSTD compare_text(SIZE, STR('A')); +// +// Text text(SIZE, STR('A')); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) +// { +// TextSTD compare_text(SIZE, STR('A')); +// +// Text text(SIZE + 1, STR('A')); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_size_char) +// { +// TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); +// +// Text text(initial_text.c_str(), initial_text.size() / 2); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) +// { +// TextSTD compare_text(initial_text.c_str(), initial_text.size()); +// +// Text text(longer_text.c_str(), longer_text.size()); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_range) +// { +// TextSTD compare_text(initial_text.begin(), initial_text.end()); +// +// Text text(compare_text.begin(), compare_text.end()); +// +// CHECK(text.size() == SIZE); +// CHECK(!text.empty()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_range_excess) +// { +// Text text(longer_text.begin(), longer_text.end()); +// +// bool is_equal = Equal(initial_text, text); +// CHECK(is_equal); +// CHECK(text.size() == SIZE); +// CHECK(!text.empty()); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_from_literal) +// { +// Text text(STR("Hello World")); +// +// bool is_equal = Equal(initial_text, text); +// CHECK(is_equal); +// CHECK(text.size() == SIZE); +// CHECK(!text.empty()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) +// { +// View view(initial_text.data(), initial_text.size()); +// Text text(view); +// +// bool is_equal = Equal(initial_text, text); +// CHECK(is_equal); +// CHECK(text.size() == SIZE); +// CHECK(!text.empty()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_constructor) +// { +// Text text(initial_text.c_str()); +// Text text2(text); +// CHECK(text2 == text); +// CHECK_FALSE(text2.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_constructor_i) +// { +// Text text(initial_text.c_str()); +// IText& itext = text; +// Text text2(itext); +// CHECK(text2 == text); +// CHECK_FALSE(text2.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_constructor_excess) +// { +// Text text(initial_text.c_str()); +// TextL textl(longer_text.c_str()); +// Text text2(textl); +// CHECK(text2 == text); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text2.is_truncated()); +//#else +// CHECK_FALSE(text2.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_constructor_from_truncated) +// { +// Text text(longer_text.c_str()); +// Text text2(text); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text2.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_construct_position_length) +// { +// TextSTD compare_text(initial_text.c_str()); +// TextSTD compare_text2(compare_text, 2, 4); +// +// Text text(initial_text.c_str()); +// Text text2(text, 2, 4); +// +// bool is_equal = Equal(compare_text2, text2); +// CHECK(is_equal); +// CHECK_FALSE(text2.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) +// { +// TextSTD compare_text(longer_text.c_str()); +// TextSTD compare_text2(compare_text, 2, 11); +// +// TextL textl(longer_text.c_str()); +// Text text2(textl, 2, 12); +// +// bool is_equal = Equal(compare_text2, text2); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text2.is_truncated()); +//#endif +// } +// +//#if ETL_HAS_INITIALIZER_LIST +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_construct_initializer_list) +// { +// TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; +// Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) +// { +// TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), +// STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; +// Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), +// STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), +// STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +//#endif +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment) +// { +// Text text(initial_text.begin(), initial_text.end()); +// Text other_text; +// +// other_text = text; +// +// bool is_equal = Equal(text, other_text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// CHECK_FALSE(other_text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_excess) +// { +// Text text(longer_text.begin(), longer_text.end()); +// Text other_text; +// +// other_text = text; +// +// bool is_equal = Equal(text, other_text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +// CHECK_TRUE(other_text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +// CHECK_FALSE(other_text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_iterface) +// { +// Text text1(initial_text.begin(), initial_text.end()); +// Text text2; +// +// IText& itext1 = text1; +// IText& itext2 = text2; +// +// itext2 = itext1; +// +// bool is_equal = Equal(text1, text2); +// +// CHECK(is_equal); +// CHECK_FALSE(text1.is_truncated()); +// CHECK_FALSE(text2.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_iterface_excess) +// { +// Text text1(longer_text.begin(), longer_text.end()); +// Text text2; +// +// IText& itext1 = text1; +// IText& itext2 = text2; +// +// itext2 = itext1; +// +// bool is_equal = Equal(text1, text2); +// +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text1.is_truncated()); +// CHECK_TRUE(text2.is_truncated()); +//#else +// CHECK_FALSE(text1.is_truncated()); +// CHECK_FALSE(text2.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_self_assignment) +// { +// Text text(initial_text.begin(), initial_text.end()); +// Text other_text(text); +// +//#include "etl/private/diagnostic_self_assign_overloaded_push.h" +// other_text = other_text; +//#include "etl/private/diagnostic_pop.h" +// +// bool is_equal = Equal(text, other_text); +// +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// CHECK_FALSE(other_text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_self_assignment_excess) +// { +// Text text(longer_text.begin(), longer_text.end()); +// Text other_text(text); +// +//#include "etl/private/diagnostic_self_assign_overloaded_push.h" +// other_text = other_text; +//#include "etl/private/diagnostic_pop.h" +// +// bool is_equal = Equal(text, other_text); +// +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +// CHECK_TRUE(other_text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +// CHECK_FALSE(other_text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_from_literal) +// { +// Text text; +// +// text = STR("Hello World"); +// +// bool is_equal = Equal(TextSTD(STR("Hello World")), text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_excess) +// { +// Text text; +// +// text = STR("Hello World There"); +// +// bool is_equal = Equal(TextSTD(STR("Hello World")), text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface) +// { +// Text text; +// IText& itext = text; +// +// itext = STR("Hello World"); +// +// bool is_equal = Equal(TextSTD(STR("Hello World")), itext); +// CHECK(is_equal); +// CHECK(!itext.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface_excess) +// { +// Text text; +// IText& itext = text; +// +// itext = STR("Hello World There"); +// +// bool is_equal = Equal(TextSTD(STR("Hello World")), itext); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK(itext.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_from_view) +// { +// Text text; +// +// text = View(STR("Hello World")); +// +// bool is_equal = Equal(TextSTD(STR("Hello World")), text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_begin) +// { +// Text text(initial_text.c_str()); +// const Text constText(initial_text.c_str()); +// +// CHECK_EQUAL(&text[0], text.begin()); +// CHECK_EQUAL(&constText[0], constText.begin()); +// } +// +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_end) +// { +// Text text(initial_text.c_str()); +// const Text constText(initial_text.c_str()); +// +// CHECK_EQUAL(&text[initial_text.size()], text.end()); +// CHECK_EQUAL(&constText[initial_text.size()], constText.end()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_up) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 8UL; +// +// Text text(initial_text.c_str(), INITIAL_SIZE); +// text.resize(NEW_SIZE); +// +// CHECK_EQUAL(text.size(), NEW_SIZE); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_up_value) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 8UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// Text text(INITIAL_SIZE, INITIAL_VALUE); +// text.resize(NEW_SIZE, INITIAL_VALUE); +// +// std::array compare_text; +// compare_text.fill(INITIAL_VALUE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_excess) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = SIZE + 1UL; +// +// Text text(INITIAL_SIZE, STR('A')); +// text.resize(NEW_SIZE, STR('A')); +// CHECK_EQUAL(SIZE, text.size()); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_down) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 2UL; +// +// Text text(INITIAL_SIZE, STR('A')); +// text.resize(NEW_SIZE); +// +// CHECK_EQUAL(text.size(), NEW_SIZE); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_down_value) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 2UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// Text text(INITIAL_SIZE, INITIAL_VALUE); +// text.resize(NEW_SIZE, INITIAL_VALUE); +// +// CHECK_EQUAL(text.size(), NEW_SIZE); +// +// std::array compare_text; +// compare_text.fill(INITIAL_VALUE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 8UL; +// const value_t INITIAL_VALUE = STR('A'); +// const value_t FILL_VALUE = STR('B'); +// +// Text text(INITIAL_SIZE, INITIAL_VALUE); +// +// Text::pointer pbegin = &text.front(); +// Text::pointer pend = &text.back() + 1; +// Text::pointer pmax = pbegin + text.max_size(); +// +// // Fill free space with a pattern. +// std::fill(pend, pmax, FILL_VALUE); +// +// text.uninitialized_resize(NEW_SIZE); +// +// std::array compare_text; +// compare_text.fill(FILL_VALUE); +// std::fill(compare_text.begin(), compare_text.begin() + INITIAL_SIZE, INITIAL_VALUE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// CHECK_EQUAL(NEW_SIZE, text.size()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = SIZE + 1UL; +// +// Text text(INITIAL_SIZE, STR('A')); +// +// text.uninitialized_resize(NEW_SIZE); +// +// CHECK_EQUAL(SIZE, text.size()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 2UL; +// const value_t INITIAL_VALUE = STR('A'); +// const value_t FILL_VALUE = STR('B'); +// +// Text text(INITIAL_SIZE, INITIAL_VALUE); +// +// Text::pointer pbegin = &text.front(); +// Text::pointer pend = &text.back() + 1; +// Text::pointer pmax = pbegin + text.max_size(); +// +// // Fill free space with a pattern. +// std::fill(pend, pmax, FILL_VALUE); +// +// text.uninitialized_resize(NEW_SIZE); +// +// std::array compare_text; +// compare_text.fill(INITIAL_VALUE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// CHECK_EQUAL(NEW_SIZE, text.size()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 8UL; +// +// Text text(initial_text.c_str(), INITIAL_SIZE); +// +// // Overwrite from index 1 to one less than the new size and set to that size. +// text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept +// { +// size_t i = 1; +// while (i < (n - 1)) +// { +// p[i] = '1' + Text::value_type(i); +// ++i; +// } +// +// return i; +// }); +// +// CHECK_EQUAL(NEW_SIZE - 1, text.size()); +// CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 3UL; +// +// Text text(initial_text.c_str(), INITIAL_SIZE); +// +// // Overwrite from index 1 to one less than the new size and set to that size. +// text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) +// { +// size_t i = 1; +// while (i < (n - 1)) +// { +// p[i] = '1' + Text::value_type(i); +// ++i; +// } +// +// return i; +// }); +// +// CHECK_EQUAL(NEW_SIZE - 1, text.size()); +// CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) +// { +// Text text(initial_text.c_str(), initial_text.size()); +// +// CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_fill) +// { +// Text text(SIZE, STR('A')); +// Text expected(SIZE, STR('B')); +// +// text.fill(STR('B')); +// +// bool is_equal = Equal(expected, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_empty_full) +// { +// Text text; +// text.resize(text.max_size(), STR('A')); +// +// CHECK(!text.empty()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_empty_half) +// { +// Text text; +// text.resize(text.max_size() / 2, STR('A')); +// +// CHECK(!text.empty()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_empty_empty) +// { +// Text text; +// +// CHECK(text.empty()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_full_full) +// { +// Text text; +// text.resize(text.max_size(), STR('A')); +// +// CHECK(text.full()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_full_half) +// { +// Text text; +// text.resize(text.max_size() / 2, STR('A')); +// +// CHECK(!text.full()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_full_empty) +// { +// Text text; +// +// CHECK(!text.full()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_index) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// for (size_t i = 0UL; i < text.size(); ++i) +// { +// CHECK_EQUAL(text[i], compare_text[i]); +// } +// +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_index_const) +// { +// const TextSTD compare_text(initial_text.c_str()); +// const Text text(initial_text.c_str()); +// +// for (size_t i = 0UL; i < text.size(); ++i) +// { +// CHECK_EQUAL(text[i], compare_text[i]); +// } +// +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_at) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// for (size_t i = 0UL; i < text.size(); ++i) +// { +// CHECK_EQUAL(text.at(i), compare_text.at(i)); +// } +// +// CHECK_FALSE(text.is_truncated()); +// CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_at_const) +// { +// const TextSTD compare_text(initial_text.c_str()); +// const Text text(initial_text.c_str()); +// +// for (size_t i = 0UL; i < text.size(); ++i) +// { +// CHECK_EQUAL(text.at(i), compare_text.at(i)); +// } +// +// CHECK_FALSE(text.is_truncated()); +// CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_front) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// CHECK(text.front() == compare_text.front()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_front_const) +// { +// const TextSTD compare_text(initial_text.c_str()); +// const Text text(initial_text.c_str()); +// +// CHECK(text.front() == compare_text.front()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_back) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// CHECK(text.back() == compare_text.back()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_back_const) +// { +// const TextSTD compare_text(initial_text.c_str()); +// const Text text(initial_text.c_str()); +// +// CHECK(text.back() == compare_text.back()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_data) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text(compare_text.begin(), compare_text.end()); +// +// bool is_equal = std::equal(text.data(), +// text.data_end(), +// compare_text.begin()); +// +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_data_const) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// const Text text(compare_text.begin(), compare_text.end()); +// +// bool is_equal = std::equal(text.data(), +// text.data_end(), +// compare_text.begin()); +// +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_string) +// { +// TextSTD compare_input(initial_text.c_str()); +// Text input(initial_text.c_str()); +// +// TextSTD compare_text; +// Text text; +// +// compare_text.assign(compare_input); +// text.assign(input); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_self_assign_string) +// { +// Text text(initial_text.c_str()); +// +// text.assign(text); +// +// bool is_equal = Equal(initial_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_view) +// { +// TextSTD compare_input(initial_text.c_str()); +// Text input(initial_text.c_str()); +// View view(input); +// +// TextSTD compare_text; +// Text text; +// +// compare_text.assign(compare_input); +// text.assign(view); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_string_excess) +// { +// TextSTD compare_input(initial_text.c_str()); +// TextL input(longer_text.c_str()); +// +// TextSTD compare_text; +// Text text; +// +// compare_text.assign(compare_input); +// text.assign(input); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_pointer) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text; +// text.assign(initial_text.c_str()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text; +// text.assign(longer_text.c_str()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_pointer_length) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text; +// text.assign(initial_text.c_str(), initial_text.size()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) +// { +// TextSTD compare_text(longer_text.c_str()); +// +// Text text; +// text.assign(longer_text.c_str(), longer_text.size()); +// +// compare_text.resize(text.max_size()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_range) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text; +// +// text.assign(compare_text.begin(), compare_text.end()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_range_excess) +// { +// Text text; +// +// text.assign(longer_text.begin(), longer_text.end()); +// +// CHECK_EQUAL(initial_text.size(), text.size()); +// +// bool is_equal = Equal(initial_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_size_value) +// { +// const size_t INITIAL_SIZE = 5UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// std::array compare_text; +// compare_text.fill(INITIAL_VALUE); +// +// Text text; +// text.assign(INITIAL_SIZE, INITIAL_VALUE); +// +// CHECK(text.size() == INITIAL_SIZE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_size_value_excess) +// { +// const size_t INITIAL_SIZE = SIZE; +// const size_t EXCESS_SIZE = SIZE + 1UL; +// const value_t INITIAL_VALUE = STR('A'); +// std::array compare_text; +// compare_text.fill(INITIAL_VALUE); +// +// Text text; +// text.assign(EXCESS_SIZE, INITIAL_VALUE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_push_back) +// { +// TextSTD compare_text; +// Text text; +// +// for (size_t i = 0UL; i < SIZE; ++i) +// { +// compare_text.push_back(STR('A') + value_t(i)); +// } +// +// for (size_t i = 0UL; i < SIZE; ++i) +// { +// text.push_back(STR('A') + value_t(i)); +// } +// +// CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); +// CHECK_EQUAL(compare_text.size(), text.size()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_push_back_excess) +// { +// TextSTD compare_text; +// Text text; +// +// for (size_t i = 0UL; i < SIZE; ++i) +// { +// compare_text.push_back(STR('A') + value_t(i)); +// } +// +// for (size_t i = 0UL; i < SIZE; ++i) +// { +// text.push_back(STR('A') + value_t(i)); +// CHECK_FALSE(text.is_truncated()); +// } +// +// text.push_back(STR('A') + value_t(SIZE)); +// +// CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); +// CHECK_EQUAL(compare_text.size(), text.size()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_pop_back) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// compare_text.pop_back(); +// compare_text.pop_back(); +// +// text.pop_back(); +// text.pop_back(); +// +// CHECK_EQUAL(compare_text.size(), text.size()); +// +// bool is_equal = Equal(compare_text, text); +// +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_value) +// { +// const size_t INITIAL_SIZE = 5UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) +// { +// TextSTD compare_text; +// Text text; +// +// text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); +// compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); +// +// text.insert(text.begin() + offset, INITIAL_VALUE); +// compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); +// +// CHECK_EQUAL(compare_text.size(), text.size()); +// +// bool is_equal = Equal(compare_text, text); +// +// CHECK(is_equal); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) +// { +// TextSTD compare_text(initial_text.begin(), initial_text.end()); +// Text text(initial_text.begin(), initial_text.end()); +// +// const value_t INITIAL_VALUE = STR('A'); +// +// size_t offset = 2UL; +// text.insert(text.cbegin() + offset, INITIAL_VALUE); +// compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); +// compare_text.erase(compare_text.cend() - 1); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = 0; +// text.insert(text.cbegin() + offset, STR('A')); +// compare_text.insert(compare_text.cbegin() + offset, STR('A')); +// compare_text.erase(compare_text.cend() - 1); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = text.size(); +// text.insert(text.cbegin() + offset, STR('A')); +// compare_text.insert(compare_text.cbegin() + offset, STR('A')); +// compare_text.erase(compare_text.cend() - 1); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_n_value) +// { +// TextSTD compare_text; +// Text text; +// +// const size_t INITIAL_SIZE = 5UL; +// const size_t INSERT_SIZE = 3UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) +// { +// text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); +// compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); +// text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); +// compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); +// +// CHECK_FALSE(text.is_truncated()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) +// { +// TextSTD compare_text; +// Text text; +// +// const size_t INSERT_SIZE = 4UL; +// const value_t INSERT_VALUE = STR('A'); +// +// size_t offset = 0UL; +// compare_text.assign(initial_text.cbegin(), initial_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); +// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = 2; +// compare_text.assign(initial_text.cbegin(), initial_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = 4; +// compare_text.assign(initial_text.cbegin(), initial_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = text.size(); +// compare_text.assign(initial_text.cbegin(), initial_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_range) +// { +// const size_t INITIAL_SIZE = 5UL; +// +// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) +// { +// TextSTD compare_text; +// Text text; +// +// text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); +// compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); +// text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); +// compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); +// +// CHECK_FALSE(text.is_truncated()); +//# +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) +// { +// const size_t INITIAL_SIZE = 5UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// TextSTD compare_text; +// Text text; +// +// size_t offset = 0UL; +// +// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); +// text.assign(INITIAL_SIZE, INITIAL_VALUE); +// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// compare_text.resize(initial_text.size()); +// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = 2; +// +// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); +// text.assign(INITIAL_SIZE, INITIAL_VALUE); +// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// compare_text.resize(initial_text.size()); +// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// +// offset = 4; +// +// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); +// text.assign(INITIAL_SIZE, INITIAL_VALUE); +// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// compare_text.resize(initial_text.size()); +// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// CHECK_EQUAL(compare_text.size(), text.size()); +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_range_self) +// { +// size_t length = TextL::MAX_SIZE / 2UL; +// +// for (size_t offset = 10UL; offset < length; ++offset) +// { +// TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); +// TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); +// +// text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); +// compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) +// { +// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) +// { +// TextSTD compare_text(short_text.cbegin(), short_text.cend()); +// Text text(short_text.cbegin(), short_text.cend()); +// Text insert(insert_text.cbegin(), insert_text.cend()); +// +// text.insert(offset, insert); +// compare_text.insert(offset, insert_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) +// { +// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) +// { +// TextSTD compare_text(short_text.cbegin(), short_text.cend()); +// Text text(short_text.cbegin(), short_text.cend()); +// View view(insert_text.data(), insert_text.size()); +// +// text.insert(offset, view); +// compare_text.insert(offset, insert_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) +// { +// for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) +// { +// TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); +// Text text(initial_text.cbegin(), initial_text.cend()); +// Text insert(insert_text.cbegin(), insert_text.cend()); +// +// text.insert(offset, insert); +// compare_text.insert(offset, insert_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) +// { +// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) +// { +// TextSTD compare_text(short_text.cbegin(), short_text.cend()); +// Text text(short_text.cbegin(), short_text.cend()); +// Text insert(longer_text.cbegin(), longer_text.cend()); +// insert.erase(insert.cbegin(), insert.cend()); +// insert.append(insert_text.cbegin(), insert_text.cend()); +// +// text.insert(offset, insert); +// compare_text.insert(offset, insert_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) +// { +// TextSTD compare_text(short_text.cbegin(), short_text.cend()); +// Text text(short_text.cbegin(), short_text.cend()); +// Text insert(insert_text.cbegin(), insert_text.cend()); +// +// text.insert(0, insert, 0, insert.size()); +// compare_text.insert(0, insert_text, 0, insert_text.size()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// +// compare_text.assign(short_text.cbegin(), short_text.cend()); +// text.assign(short_text.cbegin(), short_text.cend()); +// +// text.insert(2, insert, 2, insert.size() - 2); +// compare_text.insert(2, insert_text, 2, insert_text.size() - 2); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// CHECK_EQUAL(compare_text.size(), text.size()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// +// compare_text.assign(short_text.cbegin(), short_text.cend()); +// text.assign(short_text.cbegin(), short_text.cend()); +// +// text.insert(short_text.size(), insert, 0, insert.size()); +// compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_string) +// { +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// Text append(insert_text.c_str()); +// +// // Non-overflow. +// compare_text.append(insert_text); +// text.append(append); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// append.assign(initial_text.c_str()); +// +// compare_text.append(initial_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(append); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_view) +// { +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// View view(insert_text.data(), insert_text.size()); +// +// // Non-overflow. +// compare_text.append(insert_text); +// text.append(view); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// view.assign(initial_text.data(), initial_text.size()); +// +// compare_text.append(initial_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(view); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_truncated_string) +// { +////#include "etl/private/diagnostic_array_bounds_push.h" +// Text text(short_text.c_str()); +// TextS append(short_text.c_str()); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK(append.is_truncated()); +//#endif +// +// text.append(append); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +////#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_string_to_self) +// { +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// // Non-overflow. +// compare_text.append(compare_text); +// text.append(text); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(shorter_text.c_str()); +// text.assign(shorter_text.c_str()); +// +// compare_text.append(compare_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(text); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) +// { +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// Text append(insert_text.c_str()); +// +// // Whole string. +// compare_text.append(insert_text, 0, TextSTD::npos); +// text.append(append, 0, Text::npos); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Partial string. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// append.assign(initial_text.c_str()); +// +// compare_text.append(short_text, 1, 3); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(append, 1, 3); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// append.assign(initial_text.c_str()); +// +// compare_text.append(initial_text, 1, initial_text.size() - 1); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(append, 1, append.size() - 1); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_truncated_string_subpos_sublen) +// { +// Text text(short_text.c_str()); +// TextS append(short_text.c_str()); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK(append.is_truncated()); +//#endif +// +// text.append(append, 1, 2); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_c_string) +// { +// // Non-overflow. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// // Whole string. +// compare_text.append(insert_text.c_str()); +// text.append(insert_text.c_str()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.append(initial_text.c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(initial_text.c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_n_c) +// { +// // Non-overflow. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// // Non-overflow. +// compare_text.append(5, STR('A')); +// text.append(5, STR('A')); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.append(SIZE, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(SIZE, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_range) +// { +// // Non-overflow. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// Text append(insert_text.c_str()); +// +// compare_text.append(insert_text.begin(), insert_text.end()); +// text.append(append.begin(), append.end()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// append.assign(initial_text.c_str()); +// +// compare_text.append(initial_text.begin(), initial_text.end()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(append.begin(), append.end()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_string) +// { +// // Non-overflow short text, npos. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace"))); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, TextL(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, TextL(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_view) +// { +// // Non-overflow short text, npos. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace"))); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, View(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, View(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_string) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_view) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace")), 1, 5); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, TextL(STR("Replace")), 1, 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, View(STR("Replace")), 1, 5); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, View(STR("Replace with some text")), 1, 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, View(STR("Replace")), 1, 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, View(STR("Replace with some text")), 1, 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace")).c_str()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, TextL(STR("Replace")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +//#include "etl/private/diagnostic_array_bounds_push.h" +//#include "etl/private/diagnostic_stringop_overread_push.h" +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +//#include "etl/private/diagnostic_pop.h" +//#include "etl/private/diagnostic_pop.h" +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +//#include "etl/private/diagnostic_array_bounds_push.h" +//#include "etl/private/diagnostic_stringop_overread_push.h" +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +//#include "etl/private/diagnostic_pop.h" +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, 4, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, 7, STR('A')); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, 7, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 4, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, 7, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, 7, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 4, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// TextSTD replace(STR("Replace")); +// TextSTD replace_long(STR("Replace with some text")); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, replace.begin() + 1, replace.begin() + 5); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 7, replace.begin() + 1, replace.begin() + 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 7, replace_long.begin() + 1, replace_long.begin() + 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_erase_single_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); +// Text::iterator ditr = text.erase(text.begin() + 2); +// CHECK(*citr == *ditr); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); +// Text::iterator ditr = text.erase(text.cbegin() + 2); +// CHECK(*citr == *ditr); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_erase_range) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); +// Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); +// CHECK(*citr == *ditr); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_clear) +// { +// Text text(initial_text.c_str()); +// text.clear(); +// +// CHECK_EQUAL(text.size(), size_t(0)); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_const_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_reverse_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_equal) +// { +// const Text initial1(initial_text.c_str()); +// const Text initial2(initial_text.c_str()); +// +// CHECK(initial1 == initial2); +// +// const Text different(different_text.c_str()); +// +// CHECK(!(initial1 == different)); +// +// const Text shorter(shorter_text.c_str()); +// +// CHECK(!(shorter == initial1)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_not_equal) +// { +// const Text initial1(initial_text.c_str()); +// const Text initial2(initial_text.c_str()); +// +// CHECK(!(initial1 != initial2)); +// +// const Text different(different_text.begin(), different_text.end()); +// +// CHECK(initial1 != different); +// +// const Text shorter(shorter_text.begin(), shorter_text.end()); +// +// CHECK(shorter != initial1); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_less_than) +// { +// const Text less(less_text.c_str()); +// const Text initial(initial_text.c_str()); +// +// // String-String +// CHECK((less < initial) == (less_text < initial_text)); +// CHECK((initial < less) == (initial_text < less_text)); +// +// const Text greater(greater_text.c_str()); +// CHECK((greater < initial) == (greater_text < initial_text)); +// CHECK((initial < greater) == (initial_text < greater_text)); +// +// const Text shorter(shorter_text.c_str()); +// CHECK((shorter < initial) == (shorter_text < initial_text)); +// CHECK((initial < shorter) == (initial_text < shorter_text)); +// +// CHECK((initial < initial) == (initial_text < initial_text)); +// CHECK((initial < initial) == (initial_text < initial_text)); +// +// // String-Pointer Pointer-String +// CHECK((less < pinitial_text) == (less_text < pinitial_text)); +// CHECK((pinitial_text < less) == (pinitial_text < less_text)); +// +// CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); +// CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); +// +// CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); +// CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); +// +// CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); +// CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_less_than_or_equal) +// { +// const Text less(less_text.c_str()); +// const Text initial(initial_text.c_str()); +// +// // String-String +// CHECK((less <= initial) == (less_text <= initial_text)); +// CHECK((initial <= less) == (initial_text <= less_text)); +// +// const Text greater(greater_text.c_str()); +// CHECK((greater <= initial) == (greater_text <= initial_text)); +// CHECK((initial <= greater) == (initial_text <= greater_text)); +// +// const Text shorter(shorter_text.c_str()); +// CHECK((shorter <= initial) == (shorter_text <= initial_text)); +// CHECK((initial <= shorter) == (initial_text <= shorter_text)); +// +// CHECK((initial <= initial) == (initial_text <= initial_text)); +// CHECK((initial <= initial) == (initial_text <= initial_text)); +// +// // String-Pointer Pointer-String +// CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); +// CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); +// +// CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); +// CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); +// +// CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); +// CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); +// +// CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); +// CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_greater_than) +// { +// const Text less(less_text.c_str()); +// const Text initial(initial_text.c_str()); +// +// // String-String +// CHECK((less > initial) == (less_text > initial_text)); +// CHECK((initial > less) == (initial_text > less_text)); +// +// const Text greater(greater_text.c_str()); +// CHECK((greater > initial) == (greater_text > initial_text)); +// CHECK((initial > greater) == (initial_text > greater_text)); +// +// const Text shorter(shorter_text.c_str()); +// CHECK((shorter > initial) == (shorter_text > initial_text)); +// CHECK((initial > shorter) == (initial_text > shorter_text)); +// +// CHECK((initial > initial) == (initial_text > initial_text)); +// CHECK((initial > initial) == (initial_text > initial_text)); +// +// // String-Pointer Pointer-String +// CHECK((less > pinitial_text) == (less_text > pinitial_text)); +// CHECK((pinitial_text > less) == (pinitial_text > less_text)); +// +// CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); +// CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); +// +// CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); +// CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); +// +// CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); +// CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_greater_than_or_equal) +// { +// const Text less(less_text.begin(), less_text.end()); +// const Text initial(initial_text.begin(), initial_text.end()); +// +// // String-String +// CHECK((less >= initial) == (less_text >= initial_text)); +// CHECK((initial >= less) == (initial_text >= less_text)); +// +// const Text greater(greater_text.begin(), greater_text.end()); +// CHECK((greater >= initial) == (greater_text >= initial_text)); +// CHECK((initial >= greater) == (initial_text >= greater_text)); +// +// const Text shorter(shorter_text.begin(), shorter_text.end()); +// CHECK((shorter >= initial) == (shorter_text >= initial_text)); +// CHECK((initial >= shorter) == (initial_text > shorter_text)); +// +// CHECK((initial >= initial) == (initial_text >= initial_text)); +// CHECK((initial >= initial) == (initial_text >= initial_text)); +// +// // String-Pointer Pointer-String +// CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); +// CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); +// +// CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); +// CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); +// +// CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); +// CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); +// +// CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); +// CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// value_t buffer1[SIZE]; +// value_t buffer2[SIZE]; +// +// size_t length1 = compare_text.copy(buffer1, 5, 2); +// buffer1[length1] = STR('\0'); +// +// size_t length2 = text.copy(buffer2, 5, 2); +// buffer2[length2] = STR('\0'); +// +// CHECK_EQUAL(length1, length2); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = std::equal(buffer1, +// buffer1 + length1, +// buffer2); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_start_pos_too_large) +// { +// Text text(initial_text.c_str()); +// +// value_t buffer1[SIZE]; +// +// size_t length1 = text.copy(buffer1, 5, SIZE); +// +// CHECK_EQUAL(0U, length1); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// value_t buffer1[SIZE]; +// value_t buffer2[SIZE]; +// +// size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); +// buffer1[length1] = STR('\0'); +// +// size_t length2 = text.copy(buffer2, Text::npos, 2); +// buffer2[length2] = STR('\0'); +// +// CHECK_EQUAL(length1, length2); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = std::equal(buffer1, +// buffer1 + length1, +// buffer2); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_count_too_large) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// value_t buffer1[SIZE]; +// value_t buffer2[SIZE]; +// +// size_t length1 = compare_text.copy(buffer1, SIZE, 2); +// buffer1[length1] = STR('\0'); +// +// size_t length2 = text.copy(buffer2, SIZE, 2); +// buffer2[length2] = STR('\0'); +// +// CHECK_EQUAL(length1, length2); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = std::equal(buffer1, +// buffer1 + length1, +// buffer2); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_string) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_needle(STR("needle")); +// Text needle(STR("needle")); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = 0UL; +// size_t position2 = 0UL; +// +// position1 = compare_haystack.find(compare_needle, position1); +// position2 = haystack.find(needle, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.find(compare_needle, position1 + 1); +// position2 = haystack.find(needle, position2 + 1); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.find(needle, position2 + 1); +// CHECK_EQUAL(Text::npos, position2); +// +// Text pin(STR("pin")); +// position2 = haystack.find(pin); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_view) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_needle(STR("needle")); +// Text needle(STR("needle")); +// View needle_view(needle); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = 0UL; +// size_t position2 = 0UL; +// +// position1 = compare_haystack.find(compare_needle, position1); +// position2 = haystack.find(needle_view, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.find(compare_needle, position1 + 1); +// position2 = haystack.find(needle_view, position2 + 1); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.find(needle_view, position2 + 1); +// CHECK_EQUAL(Text::npos, position2); +// +// View pin_view(STR("pin")); +// position2 = haystack.find(pin_view); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_pointer) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// const value_t* needle = STR("needle"); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = 0UL; +// size_t position2 = 0UL; +// +// position1 = compare_haystack.find(needle, position1); +// position2 = haystack.find(needle, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.find(needle, position1 + 1); +// position2 = haystack.find(needle, position2 + 1); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.find(needle, position2 + 1); +// CHECK_EQUAL(TextL::npos, position2); +// +// const value_t *pin = STR("pin"); +// position2 = haystack.find(pin); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// const value_t* needle = STR("needle"); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = 0UL; +// size_t position2 = 0UL; +// +// position1 = compare_haystack.find(needle, position1, 3); +// position2 = haystack.find(needle, position2, 3); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.find(needle, position1 + 1, 3); +// position2 = haystack.find(needle, position2 + 1, 3); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.find(needle, position2 + 1, 3); +// CHECK_EQUAL(TextL::npos, position2); +// +// const value_t *pin = STR("pin"); +// position2 = haystack.find(pin, 0, 3); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_contains_string) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// Text needle(STR("needle")); +// Text pin(STR("pin")); +// Text excess(STR("A really gigantic pin or needle that's really really big")); +// +// CHECK_TRUE(haystack.contains(needle)); +// CHECK_FALSE(haystack.contains(pin)); +// CHECK_FALSE(haystack.contains(excess)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_contains_view) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.contains(View(STR("needle")))); +// CHECK_FALSE(haystack.contains(View(STR("pin")))); +// CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_contains_pointer) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.contains(STR("needle"))); +// CHECK_FALSE(haystack.contains(STR("pin"))); +// CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_contains_char) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.contains(STR('l'))); +// CHECK_FALSE(haystack.contains(STR('p'))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_starts_with_string) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// Text start(STR("A haystack")); +// Text not_start(STR("a needle")); +// Text excess(STR("Really gigantic text that's really really big")); +// +// CHECK_TRUE(haystack.starts_with(start)); +// CHECK_FALSE(haystack.starts_with(not_start)); +// CHECK_FALSE(haystack.starts_with(excess)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_starts_with_view) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); +// CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); +// CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_starts_with_pointer) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.starts_with(STR("A haystack"))); +// CHECK_FALSE(haystack.starts_with(STR("a needle"))); +// CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_starts_with_char) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.starts_with(haystack[0])); +// CHECK_FALSE(haystack.starts_with(haystack[1])); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_ends_with_string) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// Text end(STR("else")); +// Text not_end(STR("needle")); +// Text excess(STR("Really gigantic text that's really really big")); +// +// CHECK_TRUE(haystack.ends_with(end)); +// CHECK_FALSE(haystack.ends_with(not_end)); +// CHECK_FALSE(haystack.ends_with(excess)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_ends_with_view) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.ends_with(View(STR("else")))); +// CHECK_FALSE(haystack.ends_with(View(STR("needle")))); +// CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_ends_with_pointer) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.ends_with(STR("else"))); +// CHECK_FALSE(haystack.ends_with(STR("needle"))); +// CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_ends_with_char) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); +// CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_rfind_string) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_needle(STR("needle")); +// Text needle(STR("needle")); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = TextSTD::npos; +// size_t position2 = Text::npos; +// +// position1 = compare_haystack.rfind(compare_needle, position1); +// position2 = haystack.rfind(needle, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); +// position2 = haystack.rfind(needle, haystack.size() - 10); +// CHECK_EQUAL(position1, position2); +// +// Text pin(STR("pin")); +// position2 = haystack.rfind(pin); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_rfind_view) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_needle(STR("needle")); +// Text needle(STR("needle")); +// View needle_view(needle); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = TextSTD::npos; +// size_t position2 = Text::npos; +// +// position1 = compare_haystack.rfind(compare_needle, position1); +// position2 = haystack.rfind(needle_view, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); +// position2 = haystack.rfind(needle_view, haystack.size() - 10); +// CHECK_EQUAL(position1, position2); +// +// View pin_view(STR("pin")); +// position2 = haystack.rfind(pin_view); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_rfind_pointer) +// { +// const value_t*the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// const value_t* needle = STR("needle"); +// +// size_t position1 = TextSTD::npos; +// size_t position2 = Text::npos; +// +// position1 = compare_haystack.rfind(needle, position1); +// position2 = haystack.rfind(needle, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10); +// position2 = haystack.rfind(needle, haystack.size() - 10); +// CHECK_EQUAL(position1, position2); +// +// Text pin(STR("pin")); +// position2 = haystack.rfind(pin); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) +// { +// const value_t*the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// const value_t* needle = STR("needle"); +// +// size_t position1 = TextSTD::npos; +// size_t position2 = Text::npos; +// +// position1 = compare_haystack.rfind(needle, position1, 3); +// position2 = haystack.rfind(needle, position2, 3); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10, 3); +// position2 = haystack.rfind(needle, haystack.size() - 10, 3); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.rfind(STR("pin"), 3); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_rfind_c_position) +// { +// const value_t*the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// etl::istring::size_type position1 = TextL::npos; +// size_t position2 = Text::npos; +// +// position1 = compare_haystack.rfind(STR('e'), position1); +// position2 = haystack.rfind(STR('e'), position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); +// position2 = haystack.rfind(STR('e'), haystack.size() - 10); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.rfind(STR('z')); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_substr) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// TextSTD compare_result; +// Text result; +// +// // Equal. +// compare_result = compare_text.substr(compare_text.size()); +// result = text.substr(text.size()); +// CHECK(Equal(compare_result, result)); +// +// // Whole string. +// compare_result = compare_text.substr(); +// result = text.substr(); +// CHECK(Equal(compare_result, result)); +// +// // Starting from position 2. +// compare_result = compare_text.substr(2); +// result = text.substr(2); +// CHECK(Equal(compare_result, result)); +// +// // Starting from position 2 for 3 characters. +// compare_result = compare_text.substr(2, 3); +// result = text.substr(2, 3); +// CHECK(Equal(compare_result, result)); +// +// // Starting from position 2 for too many characters. +// compare_result = compare_text.substr(2, compare_text.size()); +// result = text.substr(2, text.size()); +// CHECK(Equal(compare_result, result)); +// +// // Starting from beyond the end of the string. +// CHECK_THROW(text.substr(text.size() + 1), etl::string_out_of_bounds); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_string) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); +// result = text.compare(Text(STR("ABCDEF"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); +// result = text.compare(Text(STR("ABCDEE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); +// result = text.compare(Text(STR("ABCDEG"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); +// result = text.compare(Text(STR("ABCDE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); +// result = text.compare(Text(STR("ABCDEFG"))); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_view) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); +// result = text.compare(View(STR("ABCDEF"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); +// result = text.compare(View(STR("ABCDEE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); +// result = text.compare(View(STR("ABCDEG"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); +// result = text.compare(View(STR("ABCDE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); +// result = text.compare(View(STR("ABCDEFG"))); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_string) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); +// result = text.compare(3, 6, Text(STR("ABCDEF"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); +// result = text.compare(3, 6, Text(STR("ABCDEE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); +// result = text.compare(3, 6, Text(STR("ABCDEG"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); +// result = text.compare(3, 6, Text(STR("ABCDE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); +// result = text.compare(3, 6, Text(STR("ABCDEFG"))); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_view) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); +// result = text.compare(3, 6, View(STR("ABCDEF"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); +// result = text.compare(3, 6, View(STR("ABCDEE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); +// result = text.compare(3, 6, View(STR("ABCDEG"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); +// result = text.compare(3, 6, View(STR("ABCDE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); +// result = text.compare(3, 6, View(STR("ABCDEFG"))); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); +// result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); +// result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); +// result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); +// result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); +// result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); +// result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); +// result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); +// result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); +// result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); +// result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_c_string) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(STR("ABCDEF")); +// result = text.compare(STR("ABCDEF")); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(STR("ABCDEE")); +// result = text.compare(STR("ABCDEE")); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(STR("ABCDEG")); +// result = text.compare(STR("ABCDEG")); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(STR("ABCDE")); +// result = text.compare(STR("ABCDE")); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(STR("ABCDEFG")); +// result = text.compare(STR("ABCDEFG")); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, STR("ABCDEF")); +// result = text.compare(3, 6, STR("ABCDEF")); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, STR("ABCDEE")); +// result = text.compare(3, 6, STR("ABCDEE")); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, STR("ABCDEG")); +// result = text.compare(3, 6, STR("ABCDEG")); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, STR("ABCDE")); +// result = text.compare(3, 6, STR("ABCDE")); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, STR("ABCDEFG")); +// result = text.compare(3, 6, STR("ABCDEFG")); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, STR("ABCDEFbb"), 6); +// result = text.compare(3, 6, STR("ABCDEFbb"), 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, STR("ABCDEEbb"), 6); +// result = text.compare(3, 6, STR("ABCDEEbb"), 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, STR("ABCDEGbb"), 6); +// result = text.compare(3, 6, STR("ABCDEGbb"), 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, STR("ABCDEbb"), 5); +// result = text.compare(3, 6, STR("ABCDEbb"), 5); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, STR("ABCDEFGbb"), 7); +// result = text.compare(3, 6, STR("ABCDEFGbb"), 7); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); +// size_t position2 = text.find_first_of(Text(STR("ZCXF"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); +// position2 = text.find_first_of(Text(STR("WXYZ"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); +// position2 = text.find_first_of(Text(STR("ZCXF")), 3); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); +// position2 = text.find_first_of(Text(STR("ZCXF")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); +// size_t position2 = text.find_first_of(View(STR("ZCXF"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); +// position2 = text.find_first_of(View(STR("WXYZ"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); +// position2 = text.find_first_of(View(STR("ZCXF")), 3); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); +// position2 = text.find_first_of(View(STR("ZCXF")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_of(STR("ZCXF")); +// size_t position2 = text.find_first_of(STR("ZCXF")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR("WXYZ")); +// position2 = text.find_first_of(STR("WXYZ")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR("ZCXF"), 3); +// position2 = text.find_first_of(STR("ZCXF"), 3); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_of(STR("ZCXF"), 100); +// position2 = text.find_first_of(STR("ZCXF"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); +// size_t position2 = text.find_first_of(STR("ZCXF"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR("WXYZ"), 0, 4); +// position2 = text.find_first_of(STR("WXYZ"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR("ZCXF"), 1, 3); +// position2 = text.find_first_of(STR("ZCXF"), 1, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR("ZCXF"), 3, 3); +// position2 = text.find_first_of(STR("ZCXF"), 3, 3); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_of(STR("ZCXF"), 100); +// position2 = text.find_first_of(STR("ZCXF"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_of(STR('C')); +// size_t position2 = text.find_first_of(STR('C')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR('Z')); +// position2 = text.find_first_of(STR('Z')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR('F'), 3); +// position2 = text.find_first_of(STR('F'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR('C'), 3); +// position2 = text.find_first_of(STR('C'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR('C'), compare_text.size()); +// position2 = text.find_first_of(STR('C'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_of(STR('C'), 100); +// position2 = text.find_first_of(STR('C'), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); +// size_t position2 = text.find_last_of(Text(STR("ZCXE"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); +// position2 = text.find_last_of(Text(STR("WXYZ")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); +// position2 = text.find_last_of(Text(STR("ZCXE")), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); +// position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); +// position2 = text.find_last_of(Text(STR("ZCXE")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); +// size_t position2 = text.find_last_of(View(STR("ZCXE"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); +// position2 = text.find_last_of(View(STR("WXYZ")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); +// position2 = text.find_last_of(View(STR("ZCXE")), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); +// position2 = text.find_last_of(View(STR("ZCXE")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); +// position2 = text.find_last_of(View(STR("ZCXE")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_of(STR("ZCXE")); +// size_t position2 = text.find_last_of(STR("ZCXE")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("WXYZ"), 3); +// position2 = text.find_last_of(STR("WXYZ"), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), 5); +// position2 = text.find_last_of(STR("ZCXE"), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), 6); +// position2 = text.find_last_of(STR("ZCXE"), 6); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size()); +// position2 = text.find_last_of(STR("ZCXE"), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_of(STR("ZCXE"), 100); +// position2 = text.find_last_of(STR("ZCXE"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); +// size_t position2 = text.find_last_of(STR("AZCXE"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("WXYZ"), 4, 3); +// position2 = text.find_last_of(STR("WXYZ"), 4, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), 5, 3); +// position2 = text.find_last_of(STR("ZCXE"), 5, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), 1, 3); +// position2 = text.find_last_of(STR("ZCXE"), 1, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size(), 4); +// position2 = text.find_last_of(STR("ZCXE"), text.size(), 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); +// position2 = text.find_last_of(STR("ZCXE"), 100, 4); +// +// CHECK_EQUAL(position1, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_last_of(STR('C')); +// size_t position2 = text.find_last_of(STR('C')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR('Z')); +// position2 = text.find_last_of(STR('Z')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR('F'), compare_text.size()); +// position2 = text.find_last_of(STR('F'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR('C'), 3); +// position2 = text.find_last_of(STR('C'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR('C'), compare_text.size()); +// position2 = text.find_last_of(STR('C'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_of(STR('C'), 100); +// position2 = text.find_last_of(STR('C'), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); +// size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); +// position2 = text.find_first_not_of(Text(STR("ZAXB"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); +// position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); +// position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); +// position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); +// size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); +// position2 = text.find_first_not_of(View(STR("ZAXB"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); +// position2 = text.find_first_not_of(View(STR("ZAXB")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); +// position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); +// position2 = text.find_first_not_of(View(STR("ZAXB")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); +// size_t position2 = text.find_first_not_of(STR("ZAXB")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB")); +// position2 = text.find_first_not_of(STR("ZAXB")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 3); +// position2 = text.find_first_not_of(STR("ZAXB"), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), compare_text.size()); +// position2 = text.find_first_not_of(STR("ZAXB"), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 100); +// position2 = text.find_first_not_of(STR("ZAXB"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); +// size_t position2 = text.find_first_not_of(STR("ZAXB"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); +// position2 = text.find_first_not_of(STR("ZAXB"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 1, 3); +// position2 = text.find_first_not_of(STR("ZAXB"), 1, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 3, 3); +// position2 = text.find_first_not_of(STR("ZAXB"), 3, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), compare_text.size(), 3); +// position2 = text.find_first_not_of(STR("ZAXB"), text.size(), 3); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 100); +// position2 = text.find_first_not_of(STR("ZAXB"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_not_of(STR('A')); +// size_t position2 = text.find_first_not_of(STR('A')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR('B')); +// position2 = text.find_first_not_of(STR('B')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR('C'), 3); +// position2 = text.find_first_not_of(STR('C'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR('D'), 3); +// position2 = text.find_first_not_of(STR('D'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR('C'), compare_text.size()); +// position2 = text.find_first_not_of(STR('C'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_not_of(STR('C'), 100); +// position2 = text.find_first_not_of(STR('C'), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); +// size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); +// size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); +// position2 = text.find_last_not_of(View(STR("ZEXD")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); +// position2 = text.find_last_not_of(View(STR("ZEXD")), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); +// position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); +// position2 = text.find_last_not_of(View(STR("ZEXD")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); +// size_t position2 = text.find_last_not_of(STR("ZEXD")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 3); +// position2 = text.find_last_not_of(STR("ZEXD"), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5); +// position2 = text.find_last_not_of(STR("ZEXD"), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size()); +// position2 = text.find_last_not_of(STR("ZEXD"), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100); +// position2 = text.find_last_not_of(STR("ZEXD"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); +// size_t position2 = text.find_last_not_of(STR("ZEXD"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5, 3); +// position2 = text.find_last_not_of(STR("ZEXD"), 5, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 1, 3); +// position2 = text.find_last_not_of(STR("ZEXD"), 1, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size(), 4); +// position2 = text.find_last_not_of(STR("ZEXD"), text.size(), 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100, 4); +// position2 = text.find_last_not_of(STR("ZEXD"), 100, 4); +// +// CHECK_EQUAL(position1, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_last_not_of(STR('F')); +// size_t position2 = text.find_last_not_of(STR('F')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('Z')); +// position2 = text.find_last_not_of(STR('Z')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('A'), compare_text.size()); +// position2 = text.find_last_not_of(STR('A'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('C'), 3); +// position2 = text.find_last_not_of(STR('C'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('C'), compare_text.size()); +// position2 = text.find_last_not_of(STR('C'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(STR('C'), 100); +// position2 = text.find_last_not_of(STR('C'), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_hash) +// { +// // Test with actual string type. +// Text text(STR("ABCDEFHIJKL")); +// size_t hash = etl::hash()(text); +// size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); +// CHECK_EQUAL(compare_hash, hash); +// +// // Test with interface string type. +// IText& itext = text; +// hash = etl::hash()(itext); +// CHECK_EQUAL(compare_hash, hash); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_memcpy_repair) +// { +// Text text; +// +// text.assign(STR("ABCDEF")); +// +// char buffer[sizeof(Text)]; +// +// memcpy(&buffer, (const void*)&text, sizeof(text)); +// +// Text& rtext(*reinterpret_cast(buffer)); +// rtext.repair(); +// +// CHECK(!rtext.empty()); +// CHECK(!rtext.full()); +// +// bool is_equal = Equal(text, rtext); +// CHECK(is_equal); +// +// text = STR("GHIJKL"); +// is_equal = Equal(text, rtext); +// CHECK(!is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_memcpy_repair_virtual) +// { +// Text text; +// +// text.assign(STR("ABCDEF")); +// +// char buffer[sizeof(Text)]; +// +// memcpy(&buffer, (const void*)&text, sizeof(text)); +// +// IText& itext(*reinterpret_cast(buffer)); +// itext.repair(); +// +// CHECK(!itext.empty()); +// CHECK(!itext.full()); +// +// bool is_equal = Equal(text, itext); +// CHECK(is_equal); +// +// text = STR("GHIJKL"); +// is_equal = Equal(text, itext); +// CHECK(!is_equal); +// } +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) +// { +// Text text(short_text.c_str()); +// CHECK_FALSE(text.is_truncated()); +// +// text.insert(3, initial_text.c_str()); +// CHECK_TRUE(text.is_truncated()); +// +// while (text.size() != 0) +// { +// text.pop_back(); +// CHECK_TRUE(text.is_truncated()); +// } +// +// text.clear(); +// CHECK_FALSE(text.is_truncated()); +// +// text.assign(longer_text.c_str()); +// CHECK_TRUE(text.is_truncated()); +// +// text.assign(short_text.c_str()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_add_from_truncated) +// { +// Text text1(short_text.c_str()); +// TextS text2(short_text.c_str()); +// +// CHECK_FALSE(text1.is_truncated()); +// CHECK_TRUE(text2.is_truncated()); +// +// // text2 has the truncate flag set. +// text1 += text2; +// +// CHECK(text1.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_add_to_truncated) +// { +// Text text1(longer_text.c_str()); +// Text text2(short_text.c_str()); +// +// CHECK(text1.is_truncated()); +// CHECK_FALSE(text2.is_truncated()); +// +// // Clear text but not the truncate flag. +// text1.erase(text1.begin(), text1.end()); +// +// // text1 still has the truncate flag set. +// text1 += text2; +// +// CHECK(text1.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_clear_truncated) +// { +// Text text(longer_text.c_str()); +// CHECK_TRUE(text.is_truncated()); +// +// text.clear_truncated(); +// CHECK_FALSE(text.is_truncated()); +// } +//#endif +// +//#if ETL_HAS_STRING_CLEAR_AFTER_USE +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_destructor) +// { +// char buffer[sizeof(Text)]; +// std::fill_n(buffer, sizeof(Text), 0); +// ::new (buffer) Text(STR("ABCDEF")); +// +// Text& text = *reinterpret_cast(buffer); +// text.set_secure(); +// +// CHECK(Text(STR("ABCDEF")) == text); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// // Destroy the text object. +// std::atomic_signal_fence(std::memory_order_seq_cst); +// text.~Text(); +// std::atomic_signal_fence(std::memory_order_seq_cst); +// +// // Check there no non-zero values in the string. +// CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_assign) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pe = text.end(); +// +// text.assign(STR("ABC")); +// +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_resize_down) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pe = text.end(); +// +// text.resize(text.size() - 3U); +// +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_erase) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// text.erase(pb + 2, pb + 5); +// +// // Check there no non-zero values in the remainder of the string. +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_replace) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// text.replace(pb + 1, pb + 4, STR("G")); +// +// // Check there no non-zero values in the remainder of the string. +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_clear) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// text.clear(); +// +// // 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 +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) +// { +// Text empty; +// Text text; +// +// text.initialize_free_space(); +// +// CHECK(text.empty()); +// CHECK(text == empty); +// +// for (size_t i = text.size(); i < text.max_size(); ++i) +// { +// CHECK_EQUAL(0, text[i]); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) +// { +// Text empty; +// Text initial = STR("ABC"); +// Text text(initial); +// +// text.initialize_free_space(); +// +// CHECK(text == initial); +// CHECK(text != empty); +// +// for (size_t i = text.size(); i < text.max_size(); ++i) +// { +// CHECK_EQUAL(0, text[i]); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) +// { +// Text text; +// +// text.initialize_free_space(); +// std::fill(text.data(), text.data() + text.max_size(), STR('A')); +// text.trim_to_terminator(); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// CHECK_EQUAL(text.max_size(), text.size()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_update_after_c_string_shorter_size) +// { +// Text text; +// +// text.initialize_free_space(); +// std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); +// text.trim_to_terminator(); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// CHECK_EQUAL(text.max_size() - 1, text.size()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_update_after_c_string_greater_size) +// { +// Text text; +// +// text.initialize_free_space(); +// std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. +// text.trim_to_terminator(); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// CHECK_EQUAL(text.max_size(), text.size()); +// } +// +// //************************************************************************* +//#if ETL_USING_STL +// TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) +// { +// Text text1 = STR("Hello World"); +// +// std::stringstream sstream; +// +// sstream << text1; +// +// TextSTD sstream_string = sstream.str(); +// +// View sstream_view(sstream_string.data(), sstream_string.size()); +// +// CHECK(text1 == sstream_view); +// } +//#endif + }; +} diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 1a524c1b..52c94e11 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -9331,6 +9331,7 @@ + From ea468ed0e1d068496a6059be03cc479748579b78 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 24 Jul 2025 09:57:14 +0100 Subject: [PATCH 2/8] Work in progress --- test/test_const_string_char.cpp | 5514 +------------------------------ test/vs2022/etl.vcxproj.filters | 3 + 2 files changed, 163 insertions(+), 5354 deletions(-) diff --git a/test/test_const_string_char.cpp b/test/test_const_string_char.cpp index f46c90f3..a72d5d15 100644 --- a/test/test_const_string_char.cpp +++ b/test/test_const_string_char.cpp @@ -95,5385 +95,191 @@ namespace } }; -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_default_constructor) -// { -// -// Text text; -// -// CHECK_EQUAL(text.size(), size_t(0)); -// CHECK(text.empty()); -// CHECK_EQUAL(text.capacity(), SIZE); -// CHECK_EQUAL(text.max_size(), SIZE); -// CHECK(text.begin() == text.end()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST(test_iterator_comparison_empty) -// { -// Text text; -// -// CHECK(text.begin() == text.end()); -// CHECK(text.cbegin() == text.cend()); -// CHECK(text.rbegin() == text.rend()); -// CHECK(text.crbegin() == text.crend()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_size_value) -// { -// const size_t INITIAL_SIZE = 5UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); -// Text text(INITIAL_SIZE, INITIAL_VALUE); -// -// CHECK(text.size() == INITIAL_SIZE); -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_size_excess) -// { -// Text text(SIZE + 1, STR('A')); -// -// CHECK_EQUAL(SIZE, text.size()); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); - static constexpr const char* initial = "Hello World"; - static constexpr Text text(initial); - static constexpr size_t length = etl::strlen(initial); + static constexpr const char* initial = "Hello World"; + static constexpr Text text(initial); + static constexpr size_t length = etl::strlen(initial); - static constexpr auto text_empty = text.empty(); - CHECK_FALSE(text_empty); + static constexpr auto text_empty = text.empty(); + CHECK_FALSE(text_empty); - static constexpr auto text_full = text.full(); - CHECK_TRUE(text_full); + static constexpr auto text_full = text.full(); + CHECK_TRUE(text_full); - text.capacity(); - text.max_size(); - text.size(); - text.length(); - text.available(); - text.is_truncated(); - text.is_secure(); + static constexpr auto text_capacity = text.capacity(); + CHECK_EQUAL(length, text_capacity); - static constexpr const char* text_data = text.data(); - CHECK_EQUAL(&initial[0], text_data); - - static constexpr const char* text_data_end = text.data_end(); - CHECK_EQUAL(&initial[length], text_data_end); + static constexpr auto text_max_size = text.max_size(); + CHECK_EQUAL(length, text_max_size); - static constexpr auto text_begin = text.begin(); - CHECK_EQUAL(&initial[0], text_begin); + static constexpr auto text_size = text.size(); + CHECK_EQUAL(length, text_size); - static constexpr auto text_cbegin = text.cbegin(); - CHECK_EQUAL(&initial[0], text_cbegin); + static constexpr auto text_length = text.length(); + CHECK_EQUAL(length, text_length); - static constexpr auto text_rbegin = text.rbegin(); - CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_rbegin)); - - static constexpr auto text_crbegin = text.crbegin(); - CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_crbegin)); + static constexpr auto text_available = text.available(); + CHECK_EQUAL(0, text_available); - static constexpr auto text_end = text.end(); - CHECK_EQUAL(&initial[length], text_end); + static constexpr auto text_is_truncated = text.is_truncated(); + CHECK_FALSE(text_is_truncated); - static constexpr auto text_cend = text.cend(); - CHECK_EQUAL(&initial[length], text_cend); + static constexpr auto text_is_secure = text.is_secure(); + CHECK_FALSE(text_is_secure); - static constexpr auto text_rend = text.rend(); - CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_rend)); + static constexpr const char* text_data = text.data(); + CHECK_EQUAL(&initial[0], text_data); - static constexpr auto text_crend = text.crend(); - CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_crend)); + static constexpr const char* text_data_end = text.data_end(); + CHECK_EQUAL(&initial[length], text_data_end); - static constexpr auto text_contains_world = text.contains("World"); - CHECK_TRUE(text_contains_world); + static constexpr auto text_begin = text.begin(); + CHECK_EQUAL(&initial[0], text_begin); - static constexpr auto text_contains_worls = text.contains("Worls"); - CHECK_FALSE(text_contains_worls); + static constexpr auto text_cbegin = text.cbegin(); + CHECK_EQUAL(&initial[0], text_cbegin); - static constexpr auto text_starts_with_hello = text.starts_with("Hello"); - CHECK_TRUE(text_starts_with_hello); + static constexpr auto text_rbegin = text.rbegin(); + CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_rbegin)); - static constexpr auto text_starts_with_world = text.starts_with("World"); - CHECK_FALSE(text_starts_with_world); + static constexpr auto text_crbegin = text.crbegin(); + CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_crbegin)); - static constexpr auto text_ends_with_hello = text.ends_with("Hello"); - CHECK_FALSE(text_ends_with_hello); + static constexpr auto text_end = text.end(); + CHECK_EQUAL(&initial[length], text_end); - static constexpr auto text_ends_with_world = text.ends_with("World"); - CHECK_TRUE(text_ends_with_world); + static constexpr auto text_cend = text.cend(); + CHECK_EQUAL(&initial[length], text_cend); - static constexpr auto text_find_world = text.find("World"); - CHECK_EQUAL(6, text_find_world); + static constexpr auto text_rend = text.rend(); + CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_rend)); - static constexpr auto text_find_worls = text.find("Worls"); - CHECK_EQUAL(Text::npos, text_find_worls); + static constexpr auto text_crend = text.crend(); + CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_crend)); - static constexpr auto text_index_operator = text[3]; - CHECK_EQUAL(initial[3], text_index_operator); - - static constexpr auto text_at = text.at(3); - CHECK_EQUAL(initial[3], text_at); - - static constexpr auto text_front = text.front(); - CHECK_EQUAL(initial[0], text_front); - - static constexpr auto text_back = text.back(); - CHECK_EQUAL(initial[length - 1], text_back); - - static constexpr const char* text_c_str = text.c_str(); - CHECK_EQUAL(&initial[0], text_c_str); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); - CHECK_FALSE(text.is_truncated()); + bool is_equal = Equal(std::string(initial), text); + CHECK(is_equal); } -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_shorter_string) -// { -// TextSTD compare_text(shorter_text.c_str()); -// -// Text text(shorter_text.c_str()); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text(longer_text.c_str()); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) -// { -// TextSTD compare_text(SIZE, STR('A')); -// -// Text text(SIZE, STR('A')); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) -// { -// TextSTD compare_text(SIZE, STR('A')); -// -// Text text(SIZE + 1, STR('A')); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_size_char) -// { -// TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); -// -// Text text(initial_text.c_str(), initial_text.size() / 2); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) -// { -// TextSTD compare_text(initial_text.c_str(), initial_text.size()); -// -// Text text(longer_text.c_str(), longer_text.size()); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_range) -// { -// TextSTD compare_text(initial_text.begin(), initial_text.end()); -// -// Text text(compare_text.begin(), compare_text.end()); -// -// CHECK(text.size() == SIZE); -// CHECK(!text.empty()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_range_excess) -// { -// Text text(longer_text.begin(), longer_text.end()); -// -// bool is_equal = Equal(initial_text, text); -// CHECK(is_equal); -// CHECK(text.size() == SIZE); -// CHECK(!text.empty()); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_from_literal) -// { -// Text text(STR("Hello World")); -// -// bool is_equal = Equal(initial_text, text); -// CHECK(is_equal); -// CHECK(text.size() == SIZE); -// CHECK(!text.empty()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) -// { -// View view(initial_text.data(), initial_text.size()); -// Text text(view); -// -// bool is_equal = Equal(initial_text, text); -// CHECK(is_equal); -// CHECK(text.size() == SIZE); -// CHECK(!text.empty()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_constructor) -// { -// Text text(initial_text.c_str()); -// Text text2(text); -// CHECK(text2 == text); -// CHECK_FALSE(text2.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_constructor_i) -// { -// Text text(initial_text.c_str()); -// IText& itext = text; -// Text text2(itext); -// CHECK(text2 == text); -// CHECK_FALSE(text2.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_constructor_excess) -// { -// Text text(initial_text.c_str()); -// TextL textl(longer_text.c_str()); -// Text text2(textl); -// CHECK(text2 == text); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text2.is_truncated()); -//#else -// CHECK_FALSE(text2.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_constructor_from_truncated) -// { -// Text text(longer_text.c_str()); -// Text text2(text); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text2.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_construct_position_length) -// { -// TextSTD compare_text(initial_text.c_str()); -// TextSTD compare_text2(compare_text, 2, 4); -// -// Text text(initial_text.c_str()); -// Text text2(text, 2, 4); -// -// bool is_equal = Equal(compare_text2, text2); -// CHECK(is_equal); -// CHECK_FALSE(text2.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) -// { -// TextSTD compare_text(longer_text.c_str()); -// TextSTD compare_text2(compare_text, 2, 11); -// -// TextL textl(longer_text.c_str()); -// Text text2(textl, 2, 12); -// -// bool is_equal = Equal(compare_text2, text2); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text2.is_truncated()); -//#endif -// } -// -//#if ETL_HAS_INITIALIZER_LIST -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_construct_initializer_list) -// { -// TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; -// Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) -// { -// TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), -// STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; -// Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), -// STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), -// STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -//#endif -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment) -// { -// Text text(initial_text.begin(), initial_text.end()); -// Text other_text; -// -// other_text = text; -// -// bool is_equal = Equal(text, other_text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// CHECK_FALSE(other_text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_excess) -// { -// Text text(longer_text.begin(), longer_text.end()); -// Text other_text; -// -// other_text = text; -// -// bool is_equal = Equal(text, other_text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -// CHECK_TRUE(other_text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -// CHECK_FALSE(other_text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_iterface) -// { -// Text text1(initial_text.begin(), initial_text.end()); -// Text text2; -// -// IText& itext1 = text1; -// IText& itext2 = text2; -// -// itext2 = itext1; -// -// bool is_equal = Equal(text1, text2); -// -// CHECK(is_equal); -// CHECK_FALSE(text1.is_truncated()); -// CHECK_FALSE(text2.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_iterface_excess) -// { -// Text text1(longer_text.begin(), longer_text.end()); -// Text text2; -// -// IText& itext1 = text1; -// IText& itext2 = text2; -// -// itext2 = itext1; -// -// bool is_equal = Equal(text1, text2); -// -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text1.is_truncated()); -// CHECK_TRUE(text2.is_truncated()); -//#else -// CHECK_FALSE(text1.is_truncated()); -// CHECK_FALSE(text2.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_self_assignment) -// { -// Text text(initial_text.begin(), initial_text.end()); -// Text other_text(text); -// -//#include "etl/private/diagnostic_self_assign_overloaded_push.h" -// other_text = other_text; -//#include "etl/private/diagnostic_pop.h" -// -// bool is_equal = Equal(text, other_text); -// -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// CHECK_FALSE(other_text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_self_assignment_excess) -// { -// Text text(longer_text.begin(), longer_text.end()); -// Text other_text(text); -// -//#include "etl/private/diagnostic_self_assign_overloaded_push.h" -// other_text = other_text; -//#include "etl/private/diagnostic_pop.h" -// -// bool is_equal = Equal(text, other_text); -// -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -// CHECK_TRUE(other_text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -// CHECK_FALSE(other_text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_from_literal) -// { -// Text text; -// -// text = STR("Hello World"); -// -// bool is_equal = Equal(TextSTD(STR("Hello World")), text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_excess) -// { -// Text text; -// -// text = STR("Hello World There"); -// -// bool is_equal = Equal(TextSTD(STR("Hello World")), text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface) -// { -// Text text; -// IText& itext = text; -// -// itext = STR("Hello World"); -// -// bool is_equal = Equal(TextSTD(STR("Hello World")), itext); -// CHECK(is_equal); -// CHECK(!itext.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface_excess) -// { -// Text text; -// IText& itext = text; -// -// itext = STR("Hello World There"); -// -// bool is_equal = Equal(TextSTD(STR("Hello World")), itext); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK(itext.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_from_view) -// { -// Text text; -// -// text = View(STR("Hello World")); -// -// bool is_equal = Equal(TextSTD(STR("Hello World")), text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_begin) -// { -// Text text(initial_text.c_str()); -// const Text constText(initial_text.c_str()); -// -// CHECK_EQUAL(&text[0], text.begin()); -// CHECK_EQUAL(&constText[0], constText.begin()); -// } -// -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_end) -// { -// Text text(initial_text.c_str()); -// const Text constText(initial_text.c_str()); -// -// CHECK_EQUAL(&text[initial_text.size()], text.end()); -// CHECK_EQUAL(&constText[initial_text.size()], constText.end()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_up) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 8UL; -// -// Text text(initial_text.c_str(), INITIAL_SIZE); -// text.resize(NEW_SIZE); -// -// CHECK_EQUAL(text.size(), NEW_SIZE); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_up_value) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 8UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// Text text(INITIAL_SIZE, INITIAL_VALUE); -// text.resize(NEW_SIZE, INITIAL_VALUE); -// -// std::array compare_text; -// compare_text.fill(INITIAL_VALUE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_excess) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = SIZE + 1UL; -// -// Text text(INITIAL_SIZE, STR('A')); -// text.resize(NEW_SIZE, STR('A')); -// CHECK_EQUAL(SIZE, text.size()); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_down) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 2UL; -// -// Text text(INITIAL_SIZE, STR('A')); -// text.resize(NEW_SIZE); -// -// CHECK_EQUAL(text.size(), NEW_SIZE); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_down_value) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 2UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// Text text(INITIAL_SIZE, INITIAL_VALUE); -// text.resize(NEW_SIZE, INITIAL_VALUE); -// -// CHECK_EQUAL(text.size(), NEW_SIZE); -// -// std::array compare_text; -// compare_text.fill(INITIAL_VALUE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 8UL; -// const value_t INITIAL_VALUE = STR('A'); -// const value_t FILL_VALUE = STR('B'); -// -// Text text(INITIAL_SIZE, INITIAL_VALUE); -// -// Text::pointer pbegin = &text.front(); -// Text::pointer pend = &text.back() + 1; -// Text::pointer pmax = pbegin + text.max_size(); -// -// // Fill free space with a pattern. -// std::fill(pend, pmax, FILL_VALUE); -// -// text.uninitialized_resize(NEW_SIZE); -// -// std::array compare_text; -// compare_text.fill(FILL_VALUE); -// std::fill(compare_text.begin(), compare_text.begin() + INITIAL_SIZE, INITIAL_VALUE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// CHECK_EQUAL(NEW_SIZE, text.size()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = SIZE + 1UL; -// -// Text text(INITIAL_SIZE, STR('A')); -// -// text.uninitialized_resize(NEW_SIZE); -// -// CHECK_EQUAL(SIZE, text.size()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 2UL; -// const value_t INITIAL_VALUE = STR('A'); -// const value_t FILL_VALUE = STR('B'); -// -// Text text(INITIAL_SIZE, INITIAL_VALUE); -// -// Text::pointer pbegin = &text.front(); -// Text::pointer pend = &text.back() + 1; -// Text::pointer pmax = pbegin + text.max_size(); -// -// // Fill free space with a pattern. -// std::fill(pend, pmax, FILL_VALUE); -// -// text.uninitialized_resize(NEW_SIZE); -// -// std::array compare_text; -// compare_text.fill(INITIAL_VALUE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// CHECK_EQUAL(NEW_SIZE, text.size()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 8UL; -// -// Text text(initial_text.c_str(), INITIAL_SIZE); -// -// // Overwrite from index 1 to one less than the new size and set to that size. -// text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept -// { -// size_t i = 1; -// while (i < (n - 1)) -// { -// p[i] = '1' + Text::value_type(i); -// ++i; -// } -// -// return i; -// }); -// -// CHECK_EQUAL(NEW_SIZE - 1, text.size()); -// CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 3UL; -// -// Text text(initial_text.c_str(), INITIAL_SIZE); -// -// // Overwrite from index 1 to one less than the new size and set to that size. -// text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) -// { -// size_t i = 1; -// while (i < (n - 1)) -// { -// p[i] = '1' + Text::value_type(i); -// ++i; -// } -// -// return i; -// }); -// -// CHECK_EQUAL(NEW_SIZE - 1, text.size()); -// CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) -// { -// Text text(initial_text.c_str(), initial_text.size()); -// -// CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_fill) -// { -// Text text(SIZE, STR('A')); -// Text expected(SIZE, STR('B')); -// -// text.fill(STR('B')); -// -// bool is_equal = Equal(expected, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_empty_full) -// { -// Text text; -// text.resize(text.max_size(), STR('A')); -// -// CHECK(!text.empty()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_empty_half) -// { -// Text text; -// text.resize(text.max_size() / 2, STR('A')); -// -// CHECK(!text.empty()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_empty_empty) -// { -// Text text; -// -// CHECK(text.empty()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_full_full) -// { -// Text text; -// text.resize(text.max_size(), STR('A')); -// -// CHECK(text.full()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_full_half) -// { -// Text text; -// text.resize(text.max_size() / 2, STR('A')); -// -// CHECK(!text.full()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_full_empty) -// { -// Text text; -// -// CHECK(!text.full()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_index) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// for (size_t i = 0UL; i < text.size(); ++i) -// { -// CHECK_EQUAL(text[i], compare_text[i]); -// } -// -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_index_const) -// { -// const TextSTD compare_text(initial_text.c_str()); -// const Text text(initial_text.c_str()); -// -// for (size_t i = 0UL; i < text.size(); ++i) -// { -// CHECK_EQUAL(text[i], compare_text[i]); -// } -// -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_at) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// for (size_t i = 0UL; i < text.size(); ++i) -// { -// CHECK_EQUAL(text.at(i), compare_text.at(i)); -// } -// -// CHECK_FALSE(text.is_truncated()); -// CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_at_const) -// { -// const TextSTD compare_text(initial_text.c_str()); -// const Text text(initial_text.c_str()); -// -// for (size_t i = 0UL; i < text.size(); ++i) -// { -// CHECK_EQUAL(text.at(i), compare_text.at(i)); -// } -// -// CHECK_FALSE(text.is_truncated()); -// CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_front) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// CHECK(text.front() == compare_text.front()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_front_const) -// { -// const TextSTD compare_text(initial_text.c_str()); -// const Text text(initial_text.c_str()); -// -// CHECK(text.front() == compare_text.front()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_back) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// CHECK(text.back() == compare_text.back()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_back_const) -// { -// const TextSTD compare_text(initial_text.c_str()); -// const Text text(initial_text.c_str()); -// -// CHECK(text.back() == compare_text.back()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_data) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text(compare_text.begin(), compare_text.end()); -// -// bool is_equal = std::equal(text.data(), -// text.data_end(), -// compare_text.begin()); -// -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_data_const) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// const Text text(compare_text.begin(), compare_text.end()); -// -// bool is_equal = std::equal(text.data(), -// text.data_end(), -// compare_text.begin()); -// -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_string) -// { -// TextSTD compare_input(initial_text.c_str()); -// Text input(initial_text.c_str()); -// -// TextSTD compare_text; -// Text text; -// -// compare_text.assign(compare_input); -// text.assign(input); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_self_assign_string) -// { -// Text text(initial_text.c_str()); -// -// text.assign(text); -// -// bool is_equal = Equal(initial_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_view) -// { -// TextSTD compare_input(initial_text.c_str()); -// Text input(initial_text.c_str()); -// View view(input); -// -// TextSTD compare_text; -// Text text; -// -// compare_text.assign(compare_input); -// text.assign(view); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_string_excess) -// { -// TextSTD compare_input(initial_text.c_str()); -// TextL input(longer_text.c_str()); -// -// TextSTD compare_text; -// Text text; -// -// compare_text.assign(compare_input); -// text.assign(input); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_pointer) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text; -// text.assign(initial_text.c_str()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text; -// text.assign(longer_text.c_str()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_pointer_length) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text; -// text.assign(initial_text.c_str(), initial_text.size()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) -// { -// TextSTD compare_text(longer_text.c_str()); -// -// Text text; -// text.assign(longer_text.c_str(), longer_text.size()); -// -// compare_text.resize(text.max_size()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_range) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text; -// -// text.assign(compare_text.begin(), compare_text.end()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_range_excess) -// { -// Text text; -// -// text.assign(longer_text.begin(), longer_text.end()); -// -// CHECK_EQUAL(initial_text.size(), text.size()); -// -// bool is_equal = Equal(initial_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_size_value) -// { -// const size_t INITIAL_SIZE = 5UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// std::array compare_text; -// compare_text.fill(INITIAL_VALUE); -// -// Text text; -// text.assign(INITIAL_SIZE, INITIAL_VALUE); -// -// CHECK(text.size() == INITIAL_SIZE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_size_value_excess) -// { -// const size_t INITIAL_SIZE = SIZE; -// const size_t EXCESS_SIZE = SIZE + 1UL; -// const value_t INITIAL_VALUE = STR('A'); -// std::array compare_text; -// compare_text.fill(INITIAL_VALUE); -// -// Text text; -// text.assign(EXCESS_SIZE, INITIAL_VALUE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_push_back) -// { -// TextSTD compare_text; -// Text text; -// -// for (size_t i = 0UL; i < SIZE; ++i) -// { -// compare_text.push_back(STR('A') + value_t(i)); -// } -// -// for (size_t i = 0UL; i < SIZE; ++i) -// { -// text.push_back(STR('A') + value_t(i)); -// } -// -// CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); -// CHECK_EQUAL(compare_text.size(), text.size()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_push_back_excess) -// { -// TextSTD compare_text; -// Text text; -// -// for (size_t i = 0UL; i < SIZE; ++i) -// { -// compare_text.push_back(STR('A') + value_t(i)); -// } -// -// for (size_t i = 0UL; i < SIZE; ++i) -// { -// text.push_back(STR('A') + value_t(i)); -// CHECK_FALSE(text.is_truncated()); -// } -// -// text.push_back(STR('A') + value_t(SIZE)); -// -// CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); -// CHECK_EQUAL(compare_text.size(), text.size()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_pop_back) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// compare_text.pop_back(); -// compare_text.pop_back(); -// -// text.pop_back(); -// text.pop_back(); -// -// CHECK_EQUAL(compare_text.size(), text.size()); -// -// bool is_equal = Equal(compare_text, text); -// -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_value) -// { -// const size_t INITIAL_SIZE = 5UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) -// { -// TextSTD compare_text; -// Text text; -// -// text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); -// compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); -// -// text.insert(text.begin() + offset, INITIAL_VALUE); -// compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); -// -// CHECK_EQUAL(compare_text.size(), text.size()); -// -// bool is_equal = Equal(compare_text, text); -// -// CHECK(is_equal); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) -// { -// TextSTD compare_text(initial_text.begin(), initial_text.end()); -// Text text(initial_text.begin(), initial_text.end()); -// -// const value_t INITIAL_VALUE = STR('A'); -// -// size_t offset = 2UL; -// text.insert(text.cbegin() + offset, INITIAL_VALUE); -// compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); -// compare_text.erase(compare_text.cend() - 1); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = 0; -// text.insert(text.cbegin() + offset, STR('A')); -// compare_text.insert(compare_text.cbegin() + offset, STR('A')); -// compare_text.erase(compare_text.cend() - 1); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = text.size(); -// text.insert(text.cbegin() + offset, STR('A')); -// compare_text.insert(compare_text.cbegin() + offset, STR('A')); -// compare_text.erase(compare_text.cend() - 1); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_n_value) -// { -// TextSTD compare_text; -// Text text; -// -// const size_t INITIAL_SIZE = 5UL; -// const size_t INSERT_SIZE = 3UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) -// { -// text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); -// compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); -// text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -// compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -// -// CHECK_FALSE(text.is_truncated()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) -// { -// TextSTD compare_text; -// Text text; -// -// const size_t INSERT_SIZE = 4UL; -// const value_t INSERT_VALUE = STR('A'); -// -// size_t offset = 0UL; -// compare_text.assign(initial_text.cbegin(), initial_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); -// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = 2; -// compare_text.assign(initial_text.cbegin(), initial_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = 4; -// compare_text.assign(initial_text.cbegin(), initial_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = text.size(); -// compare_text.assign(initial_text.cbegin(), initial_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_range) -// { -// const size_t INITIAL_SIZE = 5UL; -// -// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) -// { -// TextSTD compare_text; -// Text text; -// -// text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); -// compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); -// text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -// compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -// -// CHECK_FALSE(text.is_truncated()); -//# -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) -// { -// const size_t INITIAL_SIZE = 5UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// TextSTD compare_text; -// Text text; -// -// size_t offset = 0UL; -// -// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); -// text.assign(INITIAL_SIZE, INITIAL_VALUE); -// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// compare_text.resize(initial_text.size()); -// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = 2; -// -// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); -// text.assign(INITIAL_SIZE, INITIAL_VALUE); -// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// compare_text.resize(initial_text.size()); -// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// -// offset = 4; -// -// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); -// text.assign(INITIAL_SIZE, INITIAL_VALUE); -// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// compare_text.resize(initial_text.size()); -// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// CHECK_EQUAL(compare_text.size(), text.size()); -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_range_self) -// { -// size_t length = TextL::MAX_SIZE / 2UL; -// -// for (size_t offset = 10UL; offset < length; ++offset) -// { -// TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); -// TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); -// -// text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); -// compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) -// { -// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) -// { -// TextSTD compare_text(short_text.cbegin(), short_text.cend()); -// Text text(short_text.cbegin(), short_text.cend()); -// Text insert(insert_text.cbegin(), insert_text.cend()); -// -// text.insert(offset, insert); -// compare_text.insert(offset, insert_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) -// { -// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) -// { -// TextSTD compare_text(short_text.cbegin(), short_text.cend()); -// Text text(short_text.cbegin(), short_text.cend()); -// View view(insert_text.data(), insert_text.size()); -// -// text.insert(offset, view); -// compare_text.insert(offset, insert_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) -// { -// for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) -// { -// TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); -// Text text(initial_text.cbegin(), initial_text.cend()); -// Text insert(insert_text.cbegin(), insert_text.cend()); -// -// text.insert(offset, insert); -// compare_text.insert(offset, insert_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) -// { -// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) -// { -// TextSTD compare_text(short_text.cbegin(), short_text.cend()); -// Text text(short_text.cbegin(), short_text.cend()); -// Text insert(longer_text.cbegin(), longer_text.cend()); -// insert.erase(insert.cbegin(), insert.cend()); -// insert.append(insert_text.cbegin(), insert_text.cend()); -// -// text.insert(offset, insert); -// compare_text.insert(offset, insert_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) -// { -// TextSTD compare_text(short_text.cbegin(), short_text.cend()); -// Text text(short_text.cbegin(), short_text.cend()); -// Text insert(insert_text.cbegin(), insert_text.cend()); -// -// text.insert(0, insert, 0, insert.size()); -// compare_text.insert(0, insert_text, 0, insert_text.size()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// -// compare_text.assign(short_text.cbegin(), short_text.cend()); -// text.assign(short_text.cbegin(), short_text.cend()); -// -// text.insert(2, insert, 2, insert.size() - 2); -// compare_text.insert(2, insert_text, 2, insert_text.size() - 2); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// CHECK_EQUAL(compare_text.size(), text.size()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// -// compare_text.assign(short_text.cbegin(), short_text.cend()); -// text.assign(short_text.cbegin(), short_text.cend()); -// -// text.insert(short_text.size(), insert, 0, insert.size()); -// compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_string) -// { -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// Text append(insert_text.c_str()); -// -// // Non-overflow. -// compare_text.append(insert_text); -// text.append(append); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// append.assign(initial_text.c_str()); -// -// compare_text.append(initial_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(append); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_view) -// { -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// View view(insert_text.data(), insert_text.size()); -// -// // Non-overflow. -// compare_text.append(insert_text); -// text.append(view); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// view.assign(initial_text.data(), initial_text.size()); -// -// compare_text.append(initial_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(view); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_truncated_string) -// { -////#include "etl/private/diagnostic_array_bounds_push.h" -// Text text(short_text.c_str()); -// TextS append(short_text.c_str()); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK(append.is_truncated()); -//#endif -// -// text.append(append); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -////#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_string_to_self) -// { -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// // Non-overflow. -// compare_text.append(compare_text); -// text.append(text); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(shorter_text.c_str()); -// text.assign(shorter_text.c_str()); -// -// compare_text.append(compare_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(text); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) -// { -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// Text append(insert_text.c_str()); -// -// // Whole string. -// compare_text.append(insert_text, 0, TextSTD::npos); -// text.append(append, 0, Text::npos); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Partial string. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// append.assign(initial_text.c_str()); -// -// compare_text.append(short_text, 1, 3); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(append, 1, 3); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// append.assign(initial_text.c_str()); -// -// compare_text.append(initial_text, 1, initial_text.size() - 1); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(append, 1, append.size() - 1); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_truncated_string_subpos_sublen) -// { -// Text text(short_text.c_str()); -// TextS append(short_text.c_str()); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK(append.is_truncated()); -//#endif -// -// text.append(append, 1, 2); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_c_string) -// { -// // Non-overflow. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// // Whole string. -// compare_text.append(insert_text.c_str()); -// text.append(insert_text.c_str()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.append(initial_text.c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(initial_text.c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_n_c) -// { -// // Non-overflow. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// // Non-overflow. -// compare_text.append(5, STR('A')); -// text.append(5, STR('A')); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.append(SIZE, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(SIZE, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_range) -// { -// // Non-overflow. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// Text append(insert_text.c_str()); -// -// compare_text.append(insert_text.begin(), insert_text.end()); -// text.append(append.begin(), append.end()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// append.assign(initial_text.c_str()); -// -// compare_text.append(initial_text.begin(), initial_text.end()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(append.begin(), append.end()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_string) -// { -// // Non-overflow short text, npos. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace"))); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, TextL(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, TextL(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_view) -// { -// // Non-overflow short text, npos. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace"))); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, View(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, View(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_string) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_view) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace")), 1, 5); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, TextL(STR("Replace")), 1, 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, View(STR("Replace")), 1, 5); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, View(STR("Replace with some text")), 1, 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, View(STR("Replace")), 1, 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, View(STR("Replace with some text")), 1, 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace")).c_str()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, TextL(STR("Replace")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -//#include "etl/private/diagnostic_array_bounds_push.h" -//#include "etl/private/diagnostic_stringop_overread_push.h" -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -//#include "etl/private/diagnostic_pop.h" -//#include "etl/private/diagnostic_pop.h" -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -//#include "etl/private/diagnostic_array_bounds_push.h" -//#include "etl/private/diagnostic_stringop_overread_push.h" -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -//#include "etl/private/diagnostic_pop.h" -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, 4, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, 7, STR('A')); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, 7, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 4, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, 7, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, 7, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 4, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// TextSTD replace(STR("Replace")); -// TextSTD replace_long(STR("Replace with some text")); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, replace.begin() + 1, replace.begin() + 5); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 7, replace.begin() + 1, replace.begin() + 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 7, replace_long.begin() + 1, replace_long.begin() + 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_erase_single_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); -// Text::iterator ditr = text.erase(text.begin() + 2); -// CHECK(*citr == *ditr); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); -// Text::iterator ditr = text.erase(text.cbegin() + 2); -// CHECK(*citr == *ditr); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_erase_range) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); -// Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); -// CHECK(*citr == *ditr); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_clear) -// { -// Text text(initial_text.c_str()); -// text.clear(); -// -// CHECK_EQUAL(text.size(), size_t(0)); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_const_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_reverse_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_equal) -// { -// const Text initial1(initial_text.c_str()); -// const Text initial2(initial_text.c_str()); -// -// CHECK(initial1 == initial2); -// -// const Text different(different_text.c_str()); -// -// CHECK(!(initial1 == different)); -// -// const Text shorter(shorter_text.c_str()); -// -// CHECK(!(shorter == initial1)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_not_equal) -// { -// const Text initial1(initial_text.c_str()); -// const Text initial2(initial_text.c_str()); -// -// CHECK(!(initial1 != initial2)); -// -// const Text different(different_text.begin(), different_text.end()); -// -// CHECK(initial1 != different); -// -// const Text shorter(shorter_text.begin(), shorter_text.end()); -// -// CHECK(shorter != initial1); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_less_than) -// { -// const Text less(less_text.c_str()); -// const Text initial(initial_text.c_str()); -// -// // String-String -// CHECK((less < initial) == (less_text < initial_text)); -// CHECK((initial < less) == (initial_text < less_text)); -// -// const Text greater(greater_text.c_str()); -// CHECK((greater < initial) == (greater_text < initial_text)); -// CHECK((initial < greater) == (initial_text < greater_text)); -// -// const Text shorter(shorter_text.c_str()); -// CHECK((shorter < initial) == (shorter_text < initial_text)); -// CHECK((initial < shorter) == (initial_text < shorter_text)); -// -// CHECK((initial < initial) == (initial_text < initial_text)); -// CHECK((initial < initial) == (initial_text < initial_text)); -// -// // String-Pointer Pointer-String -// CHECK((less < pinitial_text) == (less_text < pinitial_text)); -// CHECK((pinitial_text < less) == (pinitial_text < less_text)); -// -// CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); -// CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); -// -// CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); -// CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); -// -// CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); -// CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_less_than_or_equal) -// { -// const Text less(less_text.c_str()); -// const Text initial(initial_text.c_str()); -// -// // String-String -// CHECK((less <= initial) == (less_text <= initial_text)); -// CHECK((initial <= less) == (initial_text <= less_text)); -// -// const Text greater(greater_text.c_str()); -// CHECK((greater <= initial) == (greater_text <= initial_text)); -// CHECK((initial <= greater) == (initial_text <= greater_text)); -// -// const Text shorter(shorter_text.c_str()); -// CHECK((shorter <= initial) == (shorter_text <= initial_text)); -// CHECK((initial <= shorter) == (initial_text <= shorter_text)); -// -// CHECK((initial <= initial) == (initial_text <= initial_text)); -// CHECK((initial <= initial) == (initial_text <= initial_text)); -// -// // String-Pointer Pointer-String -// CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); -// CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); -// -// CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); -// CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); -// -// CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); -// CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); -// -// CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); -// CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_greater_than) -// { -// const Text less(less_text.c_str()); -// const Text initial(initial_text.c_str()); -// -// // String-String -// CHECK((less > initial) == (less_text > initial_text)); -// CHECK((initial > less) == (initial_text > less_text)); -// -// const Text greater(greater_text.c_str()); -// CHECK((greater > initial) == (greater_text > initial_text)); -// CHECK((initial > greater) == (initial_text > greater_text)); -// -// const Text shorter(shorter_text.c_str()); -// CHECK((shorter > initial) == (shorter_text > initial_text)); -// CHECK((initial > shorter) == (initial_text > shorter_text)); -// -// CHECK((initial > initial) == (initial_text > initial_text)); -// CHECK((initial > initial) == (initial_text > initial_text)); -// -// // String-Pointer Pointer-String -// CHECK((less > pinitial_text) == (less_text > pinitial_text)); -// CHECK((pinitial_text > less) == (pinitial_text > less_text)); -// -// CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); -// CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); -// -// CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); -// CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); -// -// CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); -// CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_greater_than_or_equal) -// { -// const Text less(less_text.begin(), less_text.end()); -// const Text initial(initial_text.begin(), initial_text.end()); -// -// // String-String -// CHECK((less >= initial) == (less_text >= initial_text)); -// CHECK((initial >= less) == (initial_text >= less_text)); -// -// const Text greater(greater_text.begin(), greater_text.end()); -// CHECK((greater >= initial) == (greater_text >= initial_text)); -// CHECK((initial >= greater) == (initial_text >= greater_text)); -// -// const Text shorter(shorter_text.begin(), shorter_text.end()); -// CHECK((shorter >= initial) == (shorter_text >= initial_text)); -// CHECK((initial >= shorter) == (initial_text > shorter_text)); -// -// CHECK((initial >= initial) == (initial_text >= initial_text)); -// CHECK((initial >= initial) == (initial_text >= initial_text)); -// -// // String-Pointer Pointer-String -// CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); -// CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); -// -// CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); -// CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); -// -// CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); -// CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); -// -// CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); -// CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// value_t buffer1[SIZE]; -// value_t buffer2[SIZE]; -// -// size_t length1 = compare_text.copy(buffer1, 5, 2); -// buffer1[length1] = STR('\0'); -// -// size_t length2 = text.copy(buffer2, 5, 2); -// buffer2[length2] = STR('\0'); -// -// CHECK_EQUAL(length1, length2); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = std::equal(buffer1, -// buffer1 + length1, -// buffer2); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_start_pos_too_large) -// { -// Text text(initial_text.c_str()); -// -// value_t buffer1[SIZE]; -// -// size_t length1 = text.copy(buffer1, 5, SIZE); -// -// CHECK_EQUAL(0U, length1); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// value_t buffer1[SIZE]; -// value_t buffer2[SIZE]; -// -// size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); -// buffer1[length1] = STR('\0'); -// -// size_t length2 = text.copy(buffer2, Text::npos, 2); -// buffer2[length2] = STR('\0'); -// -// CHECK_EQUAL(length1, length2); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = std::equal(buffer1, -// buffer1 + length1, -// buffer2); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_count_too_large) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// value_t buffer1[SIZE]; -// value_t buffer2[SIZE]; -// -// size_t length1 = compare_text.copy(buffer1, SIZE, 2); -// buffer1[length1] = STR('\0'); -// -// size_t length2 = text.copy(buffer2, SIZE, 2); -// buffer2[length2] = STR('\0'); -// -// CHECK_EQUAL(length1, length2); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = std::equal(buffer1, -// buffer1 + length1, -// buffer2); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_string) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_needle(STR("needle")); -// Text needle(STR("needle")); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = 0UL; -// size_t position2 = 0UL; -// -// position1 = compare_haystack.find(compare_needle, position1); -// position2 = haystack.find(needle, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.find(compare_needle, position1 + 1); -// position2 = haystack.find(needle, position2 + 1); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.find(needle, position2 + 1); -// CHECK_EQUAL(Text::npos, position2); -// -// Text pin(STR("pin")); -// position2 = haystack.find(pin); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_view) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_needle(STR("needle")); -// Text needle(STR("needle")); -// View needle_view(needle); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = 0UL; -// size_t position2 = 0UL; -// -// position1 = compare_haystack.find(compare_needle, position1); -// position2 = haystack.find(needle_view, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.find(compare_needle, position1 + 1); -// position2 = haystack.find(needle_view, position2 + 1); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.find(needle_view, position2 + 1); -// CHECK_EQUAL(Text::npos, position2); -// -// View pin_view(STR("pin")); -// position2 = haystack.find(pin_view); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_pointer) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// const value_t* needle = STR("needle"); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = 0UL; -// size_t position2 = 0UL; -// -// position1 = compare_haystack.find(needle, position1); -// position2 = haystack.find(needle, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.find(needle, position1 + 1); -// position2 = haystack.find(needle, position2 + 1); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.find(needle, position2 + 1); -// CHECK_EQUAL(TextL::npos, position2); -// -// const value_t *pin = STR("pin"); -// position2 = haystack.find(pin); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// const value_t* needle = STR("needle"); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = 0UL; -// size_t position2 = 0UL; -// -// position1 = compare_haystack.find(needle, position1, 3); -// position2 = haystack.find(needle, position2, 3); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.find(needle, position1 + 1, 3); -// position2 = haystack.find(needle, position2 + 1, 3); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.find(needle, position2 + 1, 3); -// CHECK_EQUAL(TextL::npos, position2); -// -// const value_t *pin = STR("pin"); -// position2 = haystack.find(pin, 0, 3); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_contains_string) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// Text needle(STR("needle")); -// Text pin(STR("pin")); -// Text excess(STR("A really gigantic pin or needle that's really really big")); -// -// CHECK_TRUE(haystack.contains(needle)); -// CHECK_FALSE(haystack.contains(pin)); -// CHECK_FALSE(haystack.contains(excess)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_contains_view) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.contains(View(STR("needle")))); -// CHECK_FALSE(haystack.contains(View(STR("pin")))); -// CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_contains_pointer) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.contains(STR("needle"))); -// CHECK_FALSE(haystack.contains(STR("pin"))); -// CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_contains_char) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.contains(STR('l'))); -// CHECK_FALSE(haystack.contains(STR('p'))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_starts_with_string) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// Text start(STR("A haystack")); -// Text not_start(STR("a needle")); -// Text excess(STR("Really gigantic text that's really really big")); -// -// CHECK_TRUE(haystack.starts_with(start)); -// CHECK_FALSE(haystack.starts_with(not_start)); -// CHECK_FALSE(haystack.starts_with(excess)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_starts_with_view) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); -// CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); -// CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_starts_with_pointer) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.starts_with(STR("A haystack"))); -// CHECK_FALSE(haystack.starts_with(STR("a needle"))); -// CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_starts_with_char) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.starts_with(haystack[0])); -// CHECK_FALSE(haystack.starts_with(haystack[1])); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_ends_with_string) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// Text end(STR("else")); -// Text not_end(STR("needle")); -// Text excess(STR("Really gigantic text that's really really big")); -// -// CHECK_TRUE(haystack.ends_with(end)); -// CHECK_FALSE(haystack.ends_with(not_end)); -// CHECK_FALSE(haystack.ends_with(excess)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_ends_with_view) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.ends_with(View(STR("else")))); -// CHECK_FALSE(haystack.ends_with(View(STR("needle")))); -// CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_ends_with_pointer) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.ends_with(STR("else"))); -// CHECK_FALSE(haystack.ends_with(STR("needle"))); -// CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_ends_with_char) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); -// CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_rfind_string) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_needle(STR("needle")); -// Text needle(STR("needle")); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = TextSTD::npos; -// size_t position2 = Text::npos; -// -// position1 = compare_haystack.rfind(compare_needle, position1); -// position2 = haystack.rfind(needle, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); -// position2 = haystack.rfind(needle, haystack.size() - 10); -// CHECK_EQUAL(position1, position2); -// -// Text pin(STR("pin")); -// position2 = haystack.rfind(pin); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_rfind_view) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_needle(STR("needle")); -// Text needle(STR("needle")); -// View needle_view(needle); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = TextSTD::npos; -// size_t position2 = Text::npos; -// -// position1 = compare_haystack.rfind(compare_needle, position1); -// position2 = haystack.rfind(needle_view, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); -// position2 = haystack.rfind(needle_view, haystack.size() - 10); -// CHECK_EQUAL(position1, position2); -// -// View pin_view(STR("pin")); -// position2 = haystack.rfind(pin_view); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_rfind_pointer) -// { -// const value_t*the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// const value_t* needle = STR("needle"); -// -// size_t position1 = TextSTD::npos; -// size_t position2 = Text::npos; -// -// position1 = compare_haystack.rfind(needle, position1); -// position2 = haystack.rfind(needle, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10); -// position2 = haystack.rfind(needle, haystack.size() - 10); -// CHECK_EQUAL(position1, position2); -// -// Text pin(STR("pin")); -// position2 = haystack.rfind(pin); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) -// { -// const value_t*the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// const value_t* needle = STR("needle"); -// -// size_t position1 = TextSTD::npos; -// size_t position2 = Text::npos; -// -// position1 = compare_haystack.rfind(needle, position1, 3); -// position2 = haystack.rfind(needle, position2, 3); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10, 3); -// position2 = haystack.rfind(needle, haystack.size() - 10, 3); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.rfind(STR("pin"), 3); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_rfind_c_position) -// { -// const value_t*the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// etl::istring::size_type position1 = TextL::npos; -// size_t position2 = Text::npos; -// -// position1 = compare_haystack.rfind(STR('e'), position1); -// position2 = haystack.rfind(STR('e'), position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); -// position2 = haystack.rfind(STR('e'), haystack.size() - 10); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.rfind(STR('z')); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_substr) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// TextSTD compare_result; -// Text result; -// -// // Equal. -// compare_result = compare_text.substr(compare_text.size()); -// result = text.substr(text.size()); -// CHECK(Equal(compare_result, result)); -// -// // Whole string. -// compare_result = compare_text.substr(); -// result = text.substr(); -// CHECK(Equal(compare_result, result)); -// -// // Starting from position 2. -// compare_result = compare_text.substr(2); -// result = text.substr(2); -// CHECK(Equal(compare_result, result)); -// -// // Starting from position 2 for 3 characters. -// compare_result = compare_text.substr(2, 3); -// result = text.substr(2, 3); -// CHECK(Equal(compare_result, result)); -// -// // Starting from position 2 for too many characters. -// compare_result = compare_text.substr(2, compare_text.size()); -// result = text.substr(2, text.size()); -// CHECK(Equal(compare_result, result)); -// -// // Starting from beyond the end of the string. -// CHECK_THROW(text.substr(text.size() + 1), etl::string_out_of_bounds); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_string) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); -// result = text.compare(Text(STR("ABCDEF"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); -// result = text.compare(Text(STR("ABCDEE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); -// result = text.compare(Text(STR("ABCDEG"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); -// result = text.compare(Text(STR("ABCDE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); -// result = text.compare(Text(STR("ABCDEFG"))); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_view) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); -// result = text.compare(View(STR("ABCDEF"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); -// result = text.compare(View(STR("ABCDEE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); -// result = text.compare(View(STR("ABCDEG"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); -// result = text.compare(View(STR("ABCDE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); -// result = text.compare(View(STR("ABCDEFG"))); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_string) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); -// result = text.compare(3, 6, Text(STR("ABCDEF"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); -// result = text.compare(3, 6, Text(STR("ABCDEE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); -// result = text.compare(3, 6, Text(STR("ABCDEG"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); -// result = text.compare(3, 6, Text(STR("ABCDE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); -// result = text.compare(3, 6, Text(STR("ABCDEFG"))); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_view) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); -// result = text.compare(3, 6, View(STR("ABCDEF"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); -// result = text.compare(3, 6, View(STR("ABCDEE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); -// result = text.compare(3, 6, View(STR("ABCDEG"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); -// result = text.compare(3, 6, View(STR("ABCDE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); -// result = text.compare(3, 6, View(STR("ABCDEFG"))); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); -// result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); -// result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); -// result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); -// result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); -// result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); -// result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); -// result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); -// result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); -// result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); -// result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_c_string) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(STR("ABCDEF")); -// result = text.compare(STR("ABCDEF")); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(STR("ABCDEE")); -// result = text.compare(STR("ABCDEE")); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(STR("ABCDEG")); -// result = text.compare(STR("ABCDEG")); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(STR("ABCDE")); -// result = text.compare(STR("ABCDE")); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(STR("ABCDEFG")); -// result = text.compare(STR("ABCDEFG")); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, STR("ABCDEF")); -// result = text.compare(3, 6, STR("ABCDEF")); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, STR("ABCDEE")); -// result = text.compare(3, 6, STR("ABCDEE")); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, STR("ABCDEG")); -// result = text.compare(3, 6, STR("ABCDEG")); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, STR("ABCDE")); -// result = text.compare(3, 6, STR("ABCDE")); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, STR("ABCDEFG")); -// result = text.compare(3, 6, STR("ABCDEFG")); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, STR("ABCDEFbb"), 6); -// result = text.compare(3, 6, STR("ABCDEFbb"), 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, STR("ABCDEEbb"), 6); -// result = text.compare(3, 6, STR("ABCDEEbb"), 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, STR("ABCDEGbb"), 6); -// result = text.compare(3, 6, STR("ABCDEGbb"), 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, STR("ABCDEbb"), 5); -// result = text.compare(3, 6, STR("ABCDEbb"), 5); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, STR("ABCDEFGbb"), 7); -// result = text.compare(3, 6, STR("ABCDEFGbb"), 7); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); -// size_t position2 = text.find_first_of(Text(STR("ZCXF"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); -// position2 = text.find_first_of(Text(STR("WXYZ"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); -// position2 = text.find_first_of(Text(STR("ZCXF")), 3); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); -// position2 = text.find_first_of(Text(STR("ZCXF")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); -// size_t position2 = text.find_first_of(View(STR("ZCXF"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); -// position2 = text.find_first_of(View(STR("WXYZ"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); -// position2 = text.find_first_of(View(STR("ZCXF")), 3); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); -// position2 = text.find_first_of(View(STR("ZCXF")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_of(STR("ZCXF")); -// size_t position2 = text.find_first_of(STR("ZCXF")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR("WXYZ")); -// position2 = text.find_first_of(STR("WXYZ")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR("ZCXF"), 3); -// position2 = text.find_first_of(STR("ZCXF"), 3); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_of(STR("ZCXF"), 100); -// position2 = text.find_first_of(STR("ZCXF"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); -// size_t position2 = text.find_first_of(STR("ZCXF"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR("WXYZ"), 0, 4); -// position2 = text.find_first_of(STR("WXYZ"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR("ZCXF"), 1, 3); -// position2 = text.find_first_of(STR("ZCXF"), 1, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR("ZCXF"), 3, 3); -// position2 = text.find_first_of(STR("ZCXF"), 3, 3); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_of(STR("ZCXF"), 100); -// position2 = text.find_first_of(STR("ZCXF"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_of(STR('C')); -// size_t position2 = text.find_first_of(STR('C')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR('Z')); -// position2 = text.find_first_of(STR('Z')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR('F'), 3); -// position2 = text.find_first_of(STR('F'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR('C'), 3); -// position2 = text.find_first_of(STR('C'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR('C'), compare_text.size()); -// position2 = text.find_first_of(STR('C'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_of(STR('C'), 100); -// position2 = text.find_first_of(STR('C'), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); -// size_t position2 = text.find_last_of(Text(STR("ZCXE"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); -// position2 = text.find_last_of(Text(STR("WXYZ")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); -// position2 = text.find_last_of(Text(STR("ZCXE")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); -// position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); -// position2 = text.find_last_of(Text(STR("ZCXE")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); -// size_t position2 = text.find_last_of(View(STR("ZCXE"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); -// position2 = text.find_last_of(View(STR("WXYZ")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); -// position2 = text.find_last_of(View(STR("ZCXE")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); -// position2 = text.find_last_of(View(STR("ZCXE")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); -// position2 = text.find_last_of(View(STR("ZCXE")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_of(STR("ZCXE")); -// size_t position2 = text.find_last_of(STR("ZCXE")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("WXYZ"), 3); -// position2 = text.find_last_of(STR("WXYZ"), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), 5); -// position2 = text.find_last_of(STR("ZCXE"), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), 6); -// position2 = text.find_last_of(STR("ZCXE"), 6); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size()); -// position2 = text.find_last_of(STR("ZCXE"), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_of(STR("ZCXE"), 100); -// position2 = text.find_last_of(STR("ZCXE"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); -// size_t position2 = text.find_last_of(STR("AZCXE"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("WXYZ"), 4, 3); -// position2 = text.find_last_of(STR("WXYZ"), 4, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), 5, 3); -// position2 = text.find_last_of(STR("ZCXE"), 5, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), 1, 3); -// position2 = text.find_last_of(STR("ZCXE"), 1, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size(), 4); -// position2 = text.find_last_of(STR("ZCXE"), text.size(), 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); -// position2 = text.find_last_of(STR("ZCXE"), 100, 4); -// -// CHECK_EQUAL(position1, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_last_of(STR('C')); -// size_t position2 = text.find_last_of(STR('C')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR('Z')); -// position2 = text.find_last_of(STR('Z')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR('F'), compare_text.size()); -// position2 = text.find_last_of(STR('F'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR('C'), 3); -// position2 = text.find_last_of(STR('C'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR('C'), compare_text.size()); -// position2 = text.find_last_of(STR('C'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_of(STR('C'), 100); -// position2 = text.find_last_of(STR('C'), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); -// size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); -// position2 = text.find_first_not_of(Text(STR("ZAXB"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); -// position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); -// position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); -// position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); -// size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); -// position2 = text.find_first_not_of(View(STR("ZAXB"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); -// position2 = text.find_first_not_of(View(STR("ZAXB")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); -// position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); -// position2 = text.find_first_not_of(View(STR("ZAXB")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); -// size_t position2 = text.find_first_not_of(STR("ZAXB")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB")); -// position2 = text.find_first_not_of(STR("ZAXB")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 3); -// position2 = text.find_first_not_of(STR("ZAXB"), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), compare_text.size()); -// position2 = text.find_first_not_of(STR("ZAXB"), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 100); -// position2 = text.find_first_not_of(STR("ZAXB"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); -// size_t position2 = text.find_first_not_of(STR("ZAXB"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); -// position2 = text.find_first_not_of(STR("ZAXB"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 1, 3); -// position2 = text.find_first_not_of(STR("ZAXB"), 1, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 3, 3); -// position2 = text.find_first_not_of(STR("ZAXB"), 3, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), compare_text.size(), 3); -// position2 = text.find_first_not_of(STR("ZAXB"), text.size(), 3); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 100); -// position2 = text.find_first_not_of(STR("ZAXB"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_not_of(STR('A')); -// size_t position2 = text.find_first_not_of(STR('A')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR('B')); -// position2 = text.find_first_not_of(STR('B')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR('C'), 3); -// position2 = text.find_first_not_of(STR('C'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR('D'), 3); -// position2 = text.find_first_not_of(STR('D'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR('C'), compare_text.size()); -// position2 = text.find_first_not_of(STR('C'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_not_of(STR('C'), 100); -// position2 = text.find_first_not_of(STR('C'), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); -// size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); -// size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); -// position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); -// size_t position2 = text.find_last_not_of(STR("ZEXD")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5); -// position2 = text.find_last_not_of(STR("ZEXD"), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size()); -// position2 = text.find_last_not_of(STR("ZEXD"), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100); -// position2 = text.find_last_not_of(STR("ZEXD"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); -// size_t position2 = text.find_last_not_of(STR("ZEXD"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5, 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 5, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 1, 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 1, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size(), 4); -// position2 = text.find_last_not_of(STR("ZEXD"), text.size(), 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100, 4); -// position2 = text.find_last_not_of(STR("ZEXD"), 100, 4); -// -// CHECK_EQUAL(position1, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_last_not_of(STR('F')); -// size_t position2 = text.find_last_not_of(STR('F')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('Z')); -// position2 = text.find_last_not_of(STR('Z')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('A'), compare_text.size()); -// position2 = text.find_last_not_of(STR('A'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('C'), 3); -// position2 = text.find_last_not_of(STR('C'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('C'), compare_text.size()); -// position2 = text.find_last_not_of(STR('C'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(STR('C'), 100); -// position2 = text.find_last_not_of(STR('C'), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_hash) -// { -// // Test with actual string type. -// Text text(STR("ABCDEFHIJKL")); -// size_t hash = etl::hash()(text); -// size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); -// CHECK_EQUAL(compare_hash, hash); -// -// // Test with interface string type. -// IText& itext = text; -// hash = etl::hash()(itext); -// CHECK_EQUAL(compare_hash, hash); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_memcpy_repair) -// { -// Text text; -// -// text.assign(STR("ABCDEF")); -// -// char buffer[sizeof(Text)]; -// -// memcpy(&buffer, (const void*)&text, sizeof(text)); -// -// Text& rtext(*reinterpret_cast(buffer)); -// rtext.repair(); -// -// CHECK(!rtext.empty()); -// CHECK(!rtext.full()); -// -// bool is_equal = Equal(text, rtext); -// CHECK(is_equal); -// -// text = STR("GHIJKL"); -// is_equal = Equal(text, rtext); -// CHECK(!is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_memcpy_repair_virtual) -// { -// Text text; -// -// text.assign(STR("ABCDEF")); -// -// char buffer[sizeof(Text)]; -// -// memcpy(&buffer, (const void*)&text, sizeof(text)); -// -// IText& itext(*reinterpret_cast(buffer)); -// itext.repair(); -// -// CHECK(!itext.empty()); -// CHECK(!itext.full()); -// -// bool is_equal = Equal(text, itext); -// CHECK(is_equal); -// -// text = STR("GHIJKL"); -// is_equal = Equal(text, itext); -// CHECK(!is_equal); -// } -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) -// { -// Text text(short_text.c_str()); -// CHECK_FALSE(text.is_truncated()); -// -// text.insert(3, initial_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// while (text.size() != 0) -// { -// text.pop_back(); -// CHECK_TRUE(text.is_truncated()); -// } -// -// text.clear(); -// CHECK_FALSE(text.is_truncated()); -// -// text.assign(longer_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// text.assign(short_text.c_str()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_add_from_truncated) -// { -// Text text1(short_text.c_str()); -// TextS text2(short_text.c_str()); -// -// CHECK_FALSE(text1.is_truncated()); -// CHECK_TRUE(text2.is_truncated()); -// -// // text2 has the truncate flag set. -// text1 += text2; -// -// CHECK(text1.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_add_to_truncated) -// { -// Text text1(longer_text.c_str()); -// Text text2(short_text.c_str()); -// -// CHECK(text1.is_truncated()); -// CHECK_FALSE(text2.is_truncated()); -// -// // Clear text but not the truncate flag. -// text1.erase(text1.begin(), text1.end()); -// -// // text1 still has the truncate flag set. -// text1 += text2; -// -// CHECK(text1.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_clear_truncated) -// { -// Text text(longer_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// text.clear_truncated(); -// CHECK_FALSE(text.is_truncated()); -// } -//#endif -// -//#if ETL_HAS_STRING_CLEAR_AFTER_USE -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_destructor) -// { -// char buffer[sizeof(Text)]; -// std::fill_n(buffer, sizeof(Text), 0); -// ::new (buffer) Text(STR("ABCDEF")); -// -// Text& text = *reinterpret_cast(buffer); -// text.set_secure(); -// -// CHECK(Text(STR("ABCDEF")) == text); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// // Destroy the text object. -// std::atomic_signal_fence(std::memory_order_seq_cst); -// text.~Text(); -// std::atomic_signal_fence(std::memory_order_seq_cst); -// -// // Check there no non-zero values in the string. -// CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_assign) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pe = text.end(); -// -// text.assign(STR("ABC")); -// -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_resize_down) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pe = text.end(); -// -// text.resize(text.size() - 3U); -// -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_erase) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.erase(pb + 2, pb + 5); -// -// // Check there no non-zero values in the remainder of the string. -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_replace) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.replace(pb + 1, pb + 4, STR("G")); -// -// // Check there no non-zero values in the remainder of the string. -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_clear) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.clear(); -// -// // 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 -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) -// { -// Text empty; -// Text text; -// -// text.initialize_free_space(); -// -// CHECK(text.empty()); -// CHECK(text == empty); -// -// for (size_t i = text.size(); i < text.max_size(); ++i) -// { -// CHECK_EQUAL(0, text[i]); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) -// { -// Text empty; -// Text initial = STR("ABC"); -// Text text(initial); -// -// text.initialize_free_space(); -// -// CHECK(text == initial); -// CHECK(text != empty); -// -// for (size_t i = text.size(); i < text.max_size(); ++i) -// { -// CHECK_EQUAL(0, text[i]); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size(), STR('A')); -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size(), text.size()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_update_after_c_string_shorter_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size() - 1, text.size()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_update_after_c_string_greater_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size(), text.size()); -// } -// -// //************************************************************************* -//#if ETL_USING_STL -// TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) -// { -// Text text1 = STR("Hello World"); -// -// std::stringstream sstream; -// -// sstream << text1; -// -// TextSTD sstream_string = sstream.str(); -// -// View sstream_view(sstream_string.data(), sstream_string.size()); -// -// CHECK(text1 == sstream_view); -// } -//#endif + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains) + { + static constexpr Text text("Hello World"); + + static constexpr auto text_contains_world = text.contains("World"); + CHECK_TRUE(text_contains_world); + + static constexpr auto text_contains_worls = text.contains("Worls"); + CHECK_FALSE(text_contains_worls); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_start_with_ends_with) + { + static constexpr Text text("Hello World"); + + static constexpr auto text_starts_with_hello = text.starts_with("Hello"); + CHECK_TRUE(text_starts_with_hello); + + static constexpr auto text_starts_with_world = text.starts_with("World"); + CHECK_FALSE(text_starts_with_world); + + static constexpr auto text_ends_with_hello = text.ends_with("Hello"); + CHECK_FALSE(text_ends_with_hello); + + static constexpr auto text_ends_with_world = text.ends_with("World"); + CHECK_TRUE(text_ends_with_world); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find) + { + static constexpr Text text("Hello World"); + + static constexpr auto text_find_world = text.find("World"); + CHECK_EQUAL(6, text_find_world); + + static constexpr auto text_find_worls = text.find("Worls"); + CHECK_EQUAL(Text::npos, text_find_worls); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of) + { + static constexpr Text text("Hello World"); + static constexpr auto text_find_first_of_o = text.find_first_of(STR('o'), 5); + CHECK_EQUAL(7, text_find_first_of_o); + + static constexpr auto text_find_first_of_s = text.find_first_of(STR('s'), 5); + CHECK_EQUAL(Text::npos, text_find_first_of_s); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of) + { + static constexpr Text text("Hello World"); + static constexpr auto text_find_first_not_of_l = text.find_first_not_of(STR('l'), 2); + CHECK_EQUAL(4, text_find_first_not_of_l); + + static constexpr auto text_find_first_not_of_s = text.find_first_not_of(STR('s'), 2); + CHECK_EQUAL(2, text_find_first_not_of_s); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of) + { + static constexpr Text text("Hello World"); + + static constexpr auto text_find_last_of_o = text.find_last_of(STR('o'), 9); + CHECK_EQUAL(7, text_find_last_of_o); + + static constexpr auto text_find_last_of_s = text.find_last_of(STR('s'), 9); + CHECK_EQUAL(Text::npos, text_find_last_of_s); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of) + { + static constexpr Text text("Hello World"); + + static constexpr auto text_find_last_not_of_l = text.find_last_not_of(STR('l'), 9); + CHECK_EQUAL(8, text_find_last_not_of_l); + + static constexpr auto text_find_last_not_of_s = text.find_last_not_of(STR('s'), 9); + CHECK_EQUAL(9, text_find_last_not_of_s); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_access_functions) + { + static constexpr const char* initial = "Hello World"; + static constexpr Text text(initial); + static constexpr size_t length = etl::strlen(initial); + + static constexpr auto text_index_operator = text[3]; + CHECK_EQUAL(initial[3], text_index_operator); + + static constexpr auto text_at = text.at(3); + CHECK_EQUAL(initial[3], text_at); + + static constexpr auto text_front = text.front(); + CHECK_EQUAL(initial[0], text_front); + + static constexpr auto text_back = text.back(); + CHECK_EQUAL(initial[length - 1], text_back); + + static constexpr const char* text_c_str = text.c_str(); + CHECK_EQUAL(&initial[0], text_c_str); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_functions) + { + static constexpr Text text("Hello World"); + } }; } diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index db94bfea..43705794 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -3689,6 +3689,9 @@ Tests\CRC + + Tests\Strings + From b93166c42450845a3ab679cfbd9063fc1f82181f Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 22 Jul 2025 13:29:17 +0100 Subject: [PATCH 3/8] Work in progress --- include/etl/basic_string.h | 168 +- include/etl/const_string.h | 106 + test/test_const_string_char.cpp | 5479 +++++++++++++++++++++++++++++++ test/vs2022/etl.vcxproj | 1 + 4 files changed, 5670 insertions(+), 84 deletions(-) create mode 100644 include/etl/const_string.h create mode 100644 test/test_const_string_char.cpp diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 934af455..9dd41c16 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -190,7 +190,7 @@ namespace etl /// Gets the current size of the string. ///\return The current size of the string. //************************************************************************* - size_type size() const + ETL_CONSTEXPR14 size_type size() const { return current_size; } @@ -199,7 +199,7 @@ namespace etl /// Gets the current size of the string. ///\return The current size of the string. //************************************************************************* - size_type length() const + ETL_CONSTEXPR14 size_type length() const { return current_size; } @@ -208,7 +208,7 @@ namespace etl /// Checks the 'empty' state of the string. ///\return true if empty. //************************************************************************* - bool empty() const + ETL_CONSTEXPR14 bool empty() const { return (current_size == 0); } @@ -217,7 +217,7 @@ namespace etl /// Checks the 'full' state of the string. ///\return true if full. //************************************************************************* - bool full() const + ETL_CONSTEXPR14 bool full() const { return current_size == CAPACITY; } @@ -226,7 +226,7 @@ namespace etl /// Returns the capacity of the string. ///\return The capacity of the string. //************************************************************************* - size_type capacity() const + ETL_CONSTEXPR14 size_type capacity() const { return CAPACITY; } @@ -235,7 +235,7 @@ namespace etl /// Returns the maximum possible size of the string. ///\return The maximum size of the string. //************************************************************************* - size_type max_size() const + ETL_CONSTEXPR14 size_type max_size() const { return CAPACITY; } @@ -244,7 +244,7 @@ namespace etl /// Returns the remaining capacity. ///\return The remaining capacity. //************************************************************************* - size_type available() const + ETL_CONSTEXPR14 size_type available() const { return max_size() - size(); } @@ -253,7 +253,7 @@ namespace etl /// Returns whether the string was truncated by the last operation. ///\return Whether the string was truncated by the last operation. //************************************************************************* - bool is_truncated() const + ETL_CONSTEXPR14 bool is_truncated() const { #if ETL_HAS_STRING_TRUNCATION_CHECKS return flags.test(); @@ -268,7 +268,7 @@ namespace etl ///\return Whether the string was truncated by the last operation. //************************************************************************* ETL_DEPRECATED - bool truncated() const + ETL_CONSTEXPR14 bool truncated() const { return is_truncated(); } @@ -296,7 +296,7 @@ namespace etl //************************************************************************* /// Gets the 'secure' state flag. //************************************************************************* - bool is_secure() const + ETL_CONSTEXPR14 bool is_secure() const { #if ETL_HAS_STRING_CLEAR_AFTER_USE return flags.test(); @@ -310,7 +310,7 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - string_base(size_type max_size_) + ETL_CONSTEXPR14 string_base(size_type max_size_) : current_size(0) , CAPACITY(max_size_) { @@ -329,7 +329,7 @@ namespace etl //************************************************************************* /// Destructor. //************************************************************************* - ~string_base() + ETL_CONSTEXPR14 ~string_base() { } @@ -378,7 +378,7 @@ namespace etl /// Returns a const_iterator to the beginning of the string. ///\return A const iterator to the beginning of the string. //********************************************************************* - const_iterator begin() const + ETL_CONSTEXPR14 const_iterator begin() const { return &p_buffer[0]; } @@ -396,7 +396,7 @@ namespace etl /// Returns a const_iterator to the end of the string. ///\return A const iterator to the end of the string. //********************************************************************* - const_iterator end() const + ETL_CONSTEXPR14 const_iterator end() const { return &p_buffer[current_size]; } @@ -405,7 +405,7 @@ namespace etl /// Returns a const_iterator to the beginning of the string. ///\return A const iterator to the beginning of the string. //********************************************************************* - const_iterator cbegin() const + ETL_CONSTEXPR14 const_iterator cbegin() const { return &p_buffer[0]; } @@ -414,7 +414,7 @@ namespace etl /// Returns a const_iterator to the end of the string. ///\return A const iterator to the end of the string. //********************************************************************* - const_iterator cend() const + ETL_CONSTEXPR14 const_iterator cend() const { return &p_buffer[current_size]; } @@ -432,7 +432,7 @@ namespace etl /// Returns a const reverse iterator to the reverse beginning of the string. ///\return Const iterator to the reverse beginning of the string. //********************************************************************* - const_reverse_iterator rbegin() const + ETL_CONSTEXPR14 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } @@ -441,7 +441,7 @@ namespace etl /// Returns a reverse iterator to the end + 1 of the string. ///\return Reverse iterator to the end + 1 of the string. //********************************************************************* - reverse_iterator rend() + ETL_CONSTEXPR14 reverse_iterator rend() { return reverse_iterator(begin()); } @@ -450,7 +450,7 @@ namespace etl /// Returns a const reverse iterator to the end + 1 of the string. ///\return Const reverse iterator to the end + 1 of the string. //********************************************************************* - const_reverse_iterator rend() const + ETL_CONSTEXPR14 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } @@ -459,7 +459,7 @@ namespace etl /// Returns a const reverse iterator to the reverse beginning of the string. ///\return Const reverse iterator to the reverse beginning of the string. //********************************************************************* - const_reverse_iterator crbegin() const + ETL_CONSTEXPR14 const_reverse_iterator crbegin() const { return const_reverse_iterator(cend()); } @@ -468,7 +468,7 @@ namespace etl /// Returns a const reverse iterator to the end + 1 of the string. ///\return Const reverse iterator to the end + 1 of the string. //********************************************************************* - const_reverse_iterator crend() const + ETL_CONSTEXPR14 const_reverse_iterator crend() const { return const_reverse_iterator(cbegin()); } @@ -568,7 +568,7 @@ namespace etl ///\param i The index. ///\return A const reference to the value at index 'i' //********************************************************************* - const_reference operator [](size_type i) const + ETL_CONSTEXPR14 const_reference operator [](size_type i) const { return p_buffer[i]; } @@ -591,7 +591,7 @@ namespace etl ///\param i The index. ///\return A const reference to the value at index 'i' //********************************************************************* - const_reference at(size_type i) const + ETL_CONSTEXPR14 const_reference at(size_type i) const { ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds)); return p_buffer[i]; @@ -610,7 +610,7 @@ namespace etl /// Returns a const reference to the first element. ///\return A const reference to the first element. //********************************************************************* - const_reference front() const + ETL_CONSTEXPR14 const_reference front() const { return p_buffer[0]; } @@ -628,7 +628,7 @@ namespace etl /// Returns a const reference to the last element. ///\return A const reference to the last element. //********************************************************************* - const_reference back() const + ETL_CONSTEXPR14 const_reference back() const { return p_buffer[current_size - 1]; } @@ -664,7 +664,7 @@ namespace etl /// Returns a const pointer to the beginning of the string data. ///\return A const pointer to the beginning of the string data. //********************************************************************* - const_pointer data_end() const + ETL_CONSTEXPR14 const_pointer data_end() const { return p_buffer + current_size; } @@ -1371,7 +1371,7 @@ namespace etl //********************************************************************* /// Return a pointer to a C string. //********************************************************************* - const_pointer c_str() const + ETL_CONSTEXPR14 const_pointer c_str() const { return p_buffer; } @@ -1382,7 +1382,7 @@ namespace etl ///\param count The number of characters to copy. ///\param pos The position to start copying from. //********************************************************************* - size_type copy(pointer dest, size_type count, size_type pos = 0) const + ETL_CONSTEXPR14 size_type copy(pointer dest, size_type count, size_type pos = 0) const { if (pos < size()) { @@ -1421,7 +1421,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find(const etl::basic_string_view& view, size_type pos = 0) const + ETL_CONSTEXPR14 size_type find(const etl::basic_string_view& view, size_type pos = 0) const { return find_impl(view.begin(), view.end(), view.size(), pos); } @@ -1431,7 +1431,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find(const_pointer s, size_type pos = 0) const + ETL_CONSTEXPR14 size_type find(const_pointer s, size_type pos = 0) const { size_t sz = etl::strlen(s); @@ -1444,7 +1444,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_type find(const_pointer s, size_type pos, size_type n) const + ETL_CONSTEXPR14 size_type find(const_pointer s, size_type pos, size_type n) const { size_t sz = etl::strlen(s); @@ -1475,7 +1475,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type rfind(const ibasic_string& str, size_type position = npos) const + ETL_CONSTEXPR14 size_type rfind(const ibasic_string& str, size_type position = npos) const { return rfind_impl(str.rbegin(), str.rend(), str.size(), position); } @@ -1496,7 +1496,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type rfind(const_pointer s, size_type position = npos) const + ETL_CONSTEXPR14 size_type rfind(const_pointer s, size_type position = npos) const { size_type len = etl::strlen(s); @@ -1511,7 +1511,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type rfind(const_pointer s, size_type position, size_type length_) const + ETL_CONSTEXPR14 size_type rfind(const_pointer s, size_type position, size_type length_) const { const_reverse_iterator srbegin(s + length_); const_reverse_iterator srend(s); @@ -1524,7 +1524,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - size_type rfind(T c, size_type position = npos) const + ETL_CONSTEXPR14 size_type rfind(T c, size_type position = npos) const { if (position >= size()) { @@ -1548,7 +1548,7 @@ namespace etl //********************************************************************* /// Checks that the string is within this string //********************************************************************* - bool contains(const etl::ibasic_string& str) const + ETL_CONSTEXPR14 bool contains(const etl::ibasic_string& str) const { return find(str) != npos; } @@ -1557,7 +1557,7 @@ namespace etl /// Checks that the view is within this string //********************************************************************* template - bool contains(const etl::basic_string_view& view) const + ETL_CONSTEXPR14 bool contains(const etl::basic_string_view& view) const { return find(view) != npos; } @@ -1565,7 +1565,7 @@ namespace etl //********************************************************************* /// Checks that text is within this string //********************************************************************* - bool contains(const_pointer s) const + ETL_CONSTEXPR14 bool contains(const_pointer s) const { return find(s) != npos; } @@ -1573,7 +1573,7 @@ namespace etl //********************************************************************* /// Checks that character is within this string //********************************************************************* - bool contains(value_type c) const + ETL_CONSTEXPR14 bool contains(value_type c) const { return find(c) != npos; } @@ -1581,7 +1581,7 @@ namespace etl //********************************************************************* /// Checks that the string is the start of this string //********************************************************************* - bool starts_with(const etl::ibasic_string& str) const + ETL_CONSTEXPR14 bool starts_with(const etl::ibasic_string& str) const { return compare(0, str.size(), str) == 0; } @@ -1590,7 +1590,7 @@ namespace etl /// Checks that the view is the start of this string //********************************************************************* template - bool starts_with(const etl::basic_string_view& view) const + ETL_CONSTEXPR14 bool starts_with(const etl::basic_string_view& view) const { return compare(0, view.size(), view) == 0; } @@ -1598,7 +1598,7 @@ namespace etl //********************************************************************* /// Checks that the string is the start of this string //********************************************************************* - bool starts_with(const_pointer s) const + ETL_CONSTEXPR14 bool starts_with(const_pointer s) const { size_t len = etl::strlen(s); @@ -1608,7 +1608,7 @@ namespace etl //********************************************************************* /// Checks that the character is the start of this string //********************************************************************* - bool starts_with(value_type c) const + ETL_CONSTEXPR14 bool starts_with(value_type c) const { return !empty() && (front() == c); } @@ -1616,7 +1616,7 @@ namespace etl //********************************************************************* /// Checks that the string is the end of this string //********************************************************************* - bool ends_with(const etl::ibasic_string& str) const + ETL_CONSTEXPR14 bool ends_with(const etl::ibasic_string& str) const { if (str.size() > size()) { @@ -1630,7 +1630,7 @@ namespace etl /// Checks that the view is the end of this string //********************************************************************* template - bool ends_with(const etl::basic_string_view& view) const + ETL_CONSTEXPR14 bool ends_with(const etl::basic_string_view& view) const { if (view.size() > size()) { @@ -1643,7 +1643,7 @@ namespace etl //********************************************************************* /// Checks that the string is the end of this string //********************************************************************* - bool ends_with(const_pointer s) const + ETL_CONSTEXPR14 bool ends_with(const_pointer s) const { size_t len = etl::strlen(s); @@ -1658,7 +1658,7 @@ namespace etl //********************************************************************* /// Checks that the character is the end of this string //********************************************************************* - bool ends_with(value_type c) const + ETL_CONSTEXPR14 bool ends_with(value_type c) const { return !empty() && (back() == c); } @@ -1949,7 +1949,7 @@ namespace etl //************************************************************************* /// Compare with string. //************************************************************************* - int compare(const ibasic_string& str) const + ETL_CONSTEXPR14 int compare(const ibasic_string& str) const { return compare(p_buffer, p_buffer + size(), @@ -1961,7 +1961,7 @@ namespace etl /// Compare with etl::basic_string_view. //************************************************************************* template - int compare(const etl::basic_string_view& view) const + ETL_CONSTEXPR14 int compare(const etl::basic_string_view& view) const { return compare(p_buffer, p_buffer + size(), @@ -1972,7 +1972,7 @@ namespace etl //************************************************************************* /// Compare position / length with string. //************************************************************************* - int compare(size_type position, size_type length_, const ibasic_string& str) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const ibasic_string& str) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1989,7 +1989,7 @@ namespace etl /// Compare position / length with etl::basic_string_view. //************************************************************************* template - int compare(size_type position, size_type length_, const etl::basic_string_view& view) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const etl::basic_string_view& view) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2000,7 +2000,7 @@ namespace etl //************************************************************************* /// Compare position / length with string / subposition / sublength. //************************************************************************* - int compare(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); @@ -2019,7 +2019,7 @@ namespace etl /// Compare position / length with etl::basic_string_view. / subposition / sublength. //************************************************************************* template - int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); @@ -2037,7 +2037,7 @@ namespace etl //************************************************************************* /// Compare with C string //************************************************************************* - int compare(const value_type* s) const + ETL_CONSTEXPR14 int compare(const value_type* s) const { return compare(p_buffer, p_buffer + size(), @@ -2048,7 +2048,7 @@ namespace etl //************************************************************************* /// Compare position / length with C string. //************************************************************************* - int compare(size_type position, size_type length_, const_pointer s) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const_pointer s) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2059,7 +2059,7 @@ namespace etl //************************************************************************* /// Compare position / length with C string / n. //************************************************************************* - int compare(size_type position, size_type length_, const_pointer s, size_type n) const + ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const_pointer s, size_type n) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2072,7 +2072,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_of(const ibasic_string& str, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_of(const ibasic_string& str, size_type position = 0) const { return find_first_of(str.c_str(), position, str.size()); } @@ -2082,7 +2082,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_of(const_pointer s, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_of(const_pointer s, size_type position = 0) const { return find_first_of(s, position, etl::strlen(s)); } @@ -2093,7 +2093,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_of(view.data(), position, view.size()); } @@ -2104,7 +2104,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_type find_first_of(const_pointer s, size_type position, size_type n) const + ETL_CONSTEXPR14 size_type find_first_of(const_pointer s, size_type position, size_type n) const { if (position < size()) { @@ -2128,7 +2128,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_of(value_type c, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_of(value_type c, size_type position = 0) const { if (position < size()) { @@ -2149,7 +2149,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_last_of(const ibasic_string& str, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_of(const ibasic_string& str, size_type position = npos) const { return find_last_of(str.c_str(), position, str.size()); } @@ -2159,7 +2159,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_last_of(const_pointer s, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_of(const_pointer s, size_type position = npos) const { return find_last_of(s, position, etl::strlen(s)); } @@ -2170,7 +2170,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_of(view.data(), position, view.size()); } @@ -2181,7 +2181,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_type find_last_of(const_pointer s, size_type position, size_type n) const + ETL_CONSTEXPR14 size_type find_last_of(const_pointer s, size_type position, size_type n) const { if (empty()) { @@ -2214,7 +2214,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_last_of(value_type c, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_of(value_type c, size_type position = npos) const { if (empty()) { @@ -2244,7 +2244,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_not_of(const ibasic_string& str, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_not_of(const ibasic_string& str, size_type position = 0) const { return find_first_not_of(str.c_str(), position, str.size()); } @@ -2254,7 +2254,7 @@ namespace etl ///\param s Pointer to the content to not find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_not_of(const_pointer s, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_not_of(const_pointer s, size_type position = 0) const { return find_first_not_of(s, position, etl::strlen(s)); } @@ -2265,7 +2265,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_not_of(view.data(), position, view.size()); } @@ -2276,7 +2276,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_type find_first_not_of(const_pointer s, size_type position, size_type n) const + ETL_CONSTEXPR14 size_type find_first_not_of(const_pointer s, size_type position, size_type n) const { if (position < size()) { @@ -2307,7 +2307,7 @@ namespace etl ///\param c The character to not find ///\param pos The position to start searching from. //********************************************************************* - size_type find_first_not_of(value_type c, size_type position = 0) const + ETL_CONSTEXPR14 size_type find_first_not_of(value_type c, size_type position = 0) const { if (position < size()) { @@ -2328,7 +2328,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_last_not_of(const ibasic_string& str, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_not_of(const ibasic_string& str, size_type position = npos) const { return find_last_not_of(str.c_str(), position, str.size()); } @@ -2338,7 +2338,7 @@ namespace etl ///\param s The pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find_last_not_of(const_pointer s, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_not_of(const_pointer s, size_type position = npos) const { return find_last_not_of(s, position, etl::strlen(s)); } @@ -2349,7 +2349,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_not_of(view.data(), position, view.size()); } @@ -2360,7 +2360,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to use. //********************************************************************* - size_type find_last_not_of(const_pointer s, size_type position, size_type n) const + ETL_CONSTEXPR14 size_type find_last_not_of(const_pointer s, size_type position, size_type n) const { if (empty()) { @@ -2398,7 +2398,7 @@ namespace etl //********************************************************************* // //********************************************************************* - size_type find_last_not_of(value_type c, size_type position = npos) const + ETL_CONSTEXPR14 size_type find_last_not_of(value_type c, size_type position = npos) const { if (empty()) { @@ -2536,7 +2536,7 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - ibasic_string(T* p_buffer_, size_type MAX_SIZE_) + ETL_CONSTEXPR14 ibasic_string(T* p_buffer_, size_type MAX_SIZE_) : string_base(MAX_SIZE_), p_buffer(p_buffer_) { @@ -2545,7 +2545,7 @@ namespace etl //********************************************************************* /// Initialise the string. //********************************************************************* - void initialise() + ETL_CONSTEXPR14 void initialise() { current_size = 0U; p_buffer[0] = 0; @@ -2567,8 +2567,8 @@ namespace etl //************************************************************************* /// Compare helper function //************************************************************************* - static int compare(const_pointer first1, const_pointer last1, - const_pointer first2, const_pointer last2) + ETL_CONSTEXPR14 static int compare(const_pointer first1, const_pointer last1, + const_pointer first2, const_pointer last2) { typedef typename etl::make_unsigned::type type; @@ -2644,7 +2644,7 @@ namespace etl #else protected: #endif - ~ibasic_string() + ETL_CONSTEXPR14 ~ibasic_string() { #if ETL_HAS_STRING_CLEAR_AFTER_USE if (is_secure()) @@ -2659,7 +2659,7 @@ namespace etl //************************************************************************* /// Convert from const_iterator to iterator //************************************************************************* - iterator to_iterator(const_iterator itr) const + ETL_CONSTEXPR14 iterator to_iterator(const_iterator itr) const { return const_cast(itr); } @@ -2782,7 +2782,7 @@ namespace etl /// Common implementation for 'find'. //************************************************************************* template - size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const + ETL_CONSTEXPR14 size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const { if ((pos + sz) > size()) { @@ -2805,7 +2805,7 @@ namespace etl /// Common implementation for 'rfind'. //************************************************************************* template - size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const + ETL_CONSTEXPR14 size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const { if (sz > size()) { diff --git a/include/etl/const_string.h b/include/etl/const_string.h new file mode 100644 index 00000000..ab698d4e --- /dev/null +++ b/include/etl/const_string.h @@ -0,0 +1,106 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +#ifndef ETL_STRING_INCLUDED +#define ETL_STRING_INCLUDED + +#include "platform.h" +#include "basic_string.h" +#include "string_view.h" +#include "hash.h" +#include "initializer_list.h" + +#include + +#include "private/minmax_push.h" + +namespace etl +{ +#if ETL_USING_CPP11 + inline namespace literals + { + inline namespace string_literals + { + inline constexpr etl::string_view operator ""_sv(const char* str, size_t length) noexcept + { + return etl::string_view{ str, length }; + } + } + } +#endif + + typedef etl::ibasic_string istring; + + //*************************************************************************** + /// A string implementation that uses a fixed size external buffer. + ///\ingroup string + //*************************************************************************** + class const_string : public istring + { + public: + + typedef istring base_type; + typedef istring interface_type; + + typedef istring::value_type value_type; + typedef istring::size_type size_type; + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_string(const value_type* buffer) + : istring(const_cast(buffer), etl::strlen(buffer)) + { + this->current_size = etl::strlen(buffer); + } + + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* +#if ETL_HAS_ISTRING_REPAIR + constexpr virtual void repair() ETL_OVERRIDE +#else + constexpr void repair() +#endif + { + } + + private: + + //************************************************************************* + /// Deleted. + //************************************************************************* + const_string(const const_string& other) ETL_DELETE; + }; +} + +#include "private/minmax_pop.h" + +#endif diff --git a/test/test_const_string_char.cpp b/test/test_const_string_char.cpp new file mode 100644 index 00000000..f46c90f3 --- /dev/null +++ b/test/test_const_string_char.cpp @@ -0,0 +1,5479 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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 "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/const_string.h" +#include "etl/string_view.h" +#include "etl/fnv_1.h" + +#undef STR +#define STR(x) x + +namespace +{ + bool compares_agree(int result1, int result2) + { + return ((result1 < 0) && (result2 < 0)) || + ((result1 == 0) && (result2 == 0)) || + ((result1 > 0) && (result2 > 0)); + } + + SUITE(test_string_char) + { + static const size_t SIZE = 11UL; + + using Text = etl::const_string; + using IText = const etl::istring; + using TextSTD = std::string; + using value_t = Text::value_type; + //using TextL = etl::string<52>; + //using TextS = etl::string<4>; + //using View = etl::string_view; + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; + + const value_t* pinitial_text = STR("Hello World"); + + //************************************************************************* + template + bool Equal(const T1& compare_text, const T2& text) + { + return (compare_text.size() == text.size()) && std::equal(text.begin(), text.end(), compare_text.begin()); + } + + //************************************************************************* + struct SetupFixture + { + SetupFixture() + { + initial_text = STR("Hello World"); + insert_text = STR("Insert"); + less_text = STR("Hello Vorld"); + greater_text = STR("Hello Xorld"); + shorter_text = STR("Hello Worl"); + different_text = STR("Byee Planet"); + longer_text = STR("Hello World There"); + short_text = STR("Hello"); + } + }; + +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_default_constructor) +// { +// +// Text text; +// +// CHECK_EQUAL(text.size(), size_t(0)); +// CHECK(text.empty()); +// CHECK_EQUAL(text.capacity(), SIZE); +// CHECK_EQUAL(text.max_size(), SIZE); +// CHECK(text.begin() == text.end()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST(test_iterator_comparison_empty) +// { +// Text text; +// +// CHECK(text.begin() == text.end()); +// CHECK(text.cbegin() == text.cend()); +// CHECK(text.rbegin() == text.rend()); +// CHECK(text.crbegin() == text.crend()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_size_value) +// { +// const size_t INITIAL_SIZE = 5UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); +// Text text(INITIAL_SIZE, INITIAL_VALUE); +// +// CHECK(text.size() == INITIAL_SIZE); +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_size_excess) +// { +// Text text(SIZE + 1, STR('A')); +// +// CHECK_EQUAL(SIZE, text.size()); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) + { + TextSTD compare_text(initial_text.c_str()); + + static constexpr const char* initial = "Hello World"; + static constexpr Text text(initial); + static constexpr size_t length = etl::strlen(initial); + + static constexpr auto text_empty = text.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text.full(); + CHECK_TRUE(text_full); + + text.capacity(); + text.max_size(); + text.size(); + text.length(); + text.available(); + text.is_truncated(); + text.is_secure(); + + static constexpr const char* text_data = text.data(); + CHECK_EQUAL(&initial[0], text_data); + + static constexpr const char* text_data_end = text.data_end(); + CHECK_EQUAL(&initial[length], text_data_end); + + static constexpr auto text_begin = text.begin(); + CHECK_EQUAL(&initial[0], text_begin); + + static constexpr auto text_cbegin = text.cbegin(); + CHECK_EQUAL(&initial[0], text_cbegin); + + static constexpr auto text_rbegin = text.rbegin(); + CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text.crbegin(); + CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text.end(); + CHECK_EQUAL(&initial[length], text_end); + + static constexpr auto text_cend = text.cend(); + CHECK_EQUAL(&initial[length], text_cend); + + static constexpr auto text_rend = text.rend(); + CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text.crend(); + CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_crend)); + + static constexpr auto text_contains_world = text.contains("World"); + CHECK_TRUE(text_contains_world); + + static constexpr auto text_contains_worls = text.contains("Worls"); + CHECK_FALSE(text_contains_worls); + + static constexpr auto text_starts_with_hello = text.starts_with("Hello"); + CHECK_TRUE(text_starts_with_hello); + + static constexpr auto text_starts_with_world = text.starts_with("World"); + CHECK_FALSE(text_starts_with_world); + + static constexpr auto text_ends_with_hello = text.ends_with("Hello"); + CHECK_FALSE(text_ends_with_hello); + + static constexpr auto text_ends_with_world = text.ends_with("World"); + CHECK_TRUE(text_ends_with_world); + + static constexpr auto text_find_world = text.find("World"); + CHECK_EQUAL(6, text_find_world); + + static constexpr auto text_find_worls = text.find("Worls"); + CHECK_EQUAL(Text::npos, text_find_worls); + + static constexpr auto text_index_operator = text[3]; + CHECK_EQUAL(initial[3], text_index_operator); + + static constexpr auto text_at = text.at(3); + CHECK_EQUAL(initial[3], text_at); + + static constexpr auto text_front = text.front(); + CHECK_EQUAL(initial[0], text_front); + + static constexpr auto text_back = text.back(); + CHECK_EQUAL(initial[length - 1], text_back); + + static constexpr const char* text_c_str = text.c_str(); + CHECK_EQUAL(&initial[0], text_c_str); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + } + +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_shorter_string) +// { +// TextSTD compare_text(shorter_text.c_str()); +// +// Text text(shorter_text.c_str()); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text(longer_text.c_str()); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) +// { +// TextSTD compare_text(SIZE, STR('A')); +// +// Text text(SIZE, STR('A')); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) +// { +// TextSTD compare_text(SIZE, STR('A')); +// +// Text text(SIZE + 1, STR('A')); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_size_char) +// { +// TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); +// +// Text text(initial_text.c_str(), initial_text.size() / 2); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) +// { +// TextSTD compare_text(initial_text.c_str(), initial_text.size()); +// +// Text text(longer_text.c_str(), longer_text.size()); +// +// CHECK(!text.empty()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_range) +// { +// TextSTD compare_text(initial_text.begin(), initial_text.end()); +// +// Text text(compare_text.begin(), compare_text.end()); +// +// CHECK(text.size() == SIZE); +// CHECK(!text.empty()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_range_excess) +// { +// Text text(longer_text.begin(), longer_text.end()); +// +// bool is_equal = Equal(initial_text, text); +// CHECK(is_equal); +// CHECK(text.size() == SIZE); +// CHECK(!text.empty()); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_from_literal) +// { +// Text text(STR("Hello World")); +// +// bool is_equal = Equal(initial_text, text); +// CHECK(is_equal); +// CHECK(text.size() == SIZE); +// CHECK(!text.empty()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) +// { +// View view(initial_text.data(), initial_text.size()); +// Text text(view); +// +// bool is_equal = Equal(initial_text, text); +// CHECK(is_equal); +// CHECK(text.size() == SIZE); +// CHECK(!text.empty()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_constructor) +// { +// Text text(initial_text.c_str()); +// Text text2(text); +// CHECK(text2 == text); +// CHECK_FALSE(text2.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_constructor_i) +// { +// Text text(initial_text.c_str()); +// IText& itext = text; +// Text text2(itext); +// CHECK(text2 == text); +// CHECK_FALSE(text2.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_constructor_excess) +// { +// Text text(initial_text.c_str()); +// TextL textl(longer_text.c_str()); +// Text text2(textl); +// CHECK(text2 == text); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text2.is_truncated()); +//#else +// CHECK_FALSE(text2.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_constructor_from_truncated) +// { +// Text text(longer_text.c_str()); +// Text text2(text); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text2.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_construct_position_length) +// { +// TextSTD compare_text(initial_text.c_str()); +// TextSTD compare_text2(compare_text, 2, 4); +// +// Text text(initial_text.c_str()); +// Text text2(text, 2, 4); +// +// bool is_equal = Equal(compare_text2, text2); +// CHECK(is_equal); +// CHECK_FALSE(text2.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) +// { +// TextSTD compare_text(longer_text.c_str()); +// TextSTD compare_text2(compare_text, 2, 11); +// +// TextL textl(longer_text.c_str()); +// Text text2(textl, 2, 12); +// +// bool is_equal = Equal(compare_text2, text2); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text2.is_truncated()); +//#endif +// } +// +//#if ETL_HAS_INITIALIZER_LIST +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_construct_initializer_list) +// { +// TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; +// Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) +// { +// TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), +// STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; +// Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), +// STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), +// STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +//#endif +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment) +// { +// Text text(initial_text.begin(), initial_text.end()); +// Text other_text; +// +// other_text = text; +// +// bool is_equal = Equal(text, other_text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// CHECK_FALSE(other_text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_excess) +// { +// Text text(longer_text.begin(), longer_text.end()); +// Text other_text; +// +// other_text = text; +// +// bool is_equal = Equal(text, other_text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +// CHECK_TRUE(other_text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +// CHECK_FALSE(other_text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_iterface) +// { +// Text text1(initial_text.begin(), initial_text.end()); +// Text text2; +// +// IText& itext1 = text1; +// IText& itext2 = text2; +// +// itext2 = itext1; +// +// bool is_equal = Equal(text1, text2); +// +// CHECK(is_equal); +// CHECK_FALSE(text1.is_truncated()); +// CHECK_FALSE(text2.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_iterface_excess) +// { +// Text text1(longer_text.begin(), longer_text.end()); +// Text text2; +// +// IText& itext1 = text1; +// IText& itext2 = text2; +// +// itext2 = itext1; +// +// bool is_equal = Equal(text1, text2); +// +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text1.is_truncated()); +// CHECK_TRUE(text2.is_truncated()); +//#else +// CHECK_FALSE(text1.is_truncated()); +// CHECK_FALSE(text2.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_self_assignment) +// { +// Text text(initial_text.begin(), initial_text.end()); +// Text other_text(text); +// +//#include "etl/private/diagnostic_self_assign_overloaded_push.h" +// other_text = other_text; +//#include "etl/private/diagnostic_pop.h" +// +// bool is_equal = Equal(text, other_text); +// +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// CHECK_FALSE(other_text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_self_assignment_excess) +// { +// Text text(longer_text.begin(), longer_text.end()); +// Text other_text(text); +// +//#include "etl/private/diagnostic_self_assign_overloaded_push.h" +// other_text = other_text; +//#include "etl/private/diagnostic_pop.h" +// +// bool is_equal = Equal(text, other_text); +// +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +// CHECK_TRUE(other_text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +// CHECK_FALSE(other_text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_from_literal) +// { +// Text text; +// +// text = STR("Hello World"); +// +// bool is_equal = Equal(TextSTD(STR("Hello World")), text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_excess) +// { +// Text text; +// +// text = STR("Hello World There"); +// +// bool is_equal = Equal(TextSTD(STR("Hello World")), text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface) +// { +// Text text; +// IText& itext = text; +// +// itext = STR("Hello World"); +// +// bool is_equal = Equal(TextSTD(STR("Hello World")), itext); +// CHECK(is_equal); +// CHECK(!itext.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface_excess) +// { +// Text text; +// IText& itext = text; +// +// itext = STR("Hello World There"); +// +// bool is_equal = Equal(TextSTD(STR("Hello World")), itext); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK(itext.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assignment_from_view) +// { +// Text text; +// +// text = View(STR("Hello World")); +// +// bool is_equal = Equal(TextSTD(STR("Hello World")), text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_begin) +// { +// Text text(initial_text.c_str()); +// const Text constText(initial_text.c_str()); +// +// CHECK_EQUAL(&text[0], text.begin()); +// CHECK_EQUAL(&constText[0], constText.begin()); +// } +// +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_end) +// { +// Text text(initial_text.c_str()); +// const Text constText(initial_text.c_str()); +// +// CHECK_EQUAL(&text[initial_text.size()], text.end()); +// CHECK_EQUAL(&constText[initial_text.size()], constText.end()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_up) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 8UL; +// +// Text text(initial_text.c_str(), INITIAL_SIZE); +// text.resize(NEW_SIZE); +// +// CHECK_EQUAL(text.size(), NEW_SIZE); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_up_value) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 8UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// Text text(INITIAL_SIZE, INITIAL_VALUE); +// text.resize(NEW_SIZE, INITIAL_VALUE); +// +// std::array compare_text; +// compare_text.fill(INITIAL_VALUE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_excess) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = SIZE + 1UL; +// +// Text text(INITIAL_SIZE, STR('A')); +// text.resize(NEW_SIZE, STR('A')); +// CHECK_EQUAL(SIZE, text.size()); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_down) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 2UL; +// +// Text text(INITIAL_SIZE, STR('A')); +// text.resize(NEW_SIZE); +// +// CHECK_EQUAL(text.size(), NEW_SIZE); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_down_value) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 2UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// Text text(INITIAL_SIZE, INITIAL_VALUE); +// text.resize(NEW_SIZE, INITIAL_VALUE); +// +// CHECK_EQUAL(text.size(), NEW_SIZE); +// +// std::array compare_text; +// compare_text.fill(INITIAL_VALUE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 8UL; +// const value_t INITIAL_VALUE = STR('A'); +// const value_t FILL_VALUE = STR('B'); +// +// Text text(INITIAL_SIZE, INITIAL_VALUE); +// +// Text::pointer pbegin = &text.front(); +// Text::pointer pend = &text.back() + 1; +// Text::pointer pmax = pbegin + text.max_size(); +// +// // Fill free space with a pattern. +// std::fill(pend, pmax, FILL_VALUE); +// +// text.uninitialized_resize(NEW_SIZE); +// +// std::array compare_text; +// compare_text.fill(FILL_VALUE); +// std::fill(compare_text.begin(), compare_text.begin() + INITIAL_SIZE, INITIAL_VALUE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// CHECK_EQUAL(NEW_SIZE, text.size()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = SIZE + 1UL; +// +// Text text(INITIAL_SIZE, STR('A')); +// +// text.uninitialized_resize(NEW_SIZE); +// +// CHECK_EQUAL(SIZE, text.size()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 2UL; +// const value_t INITIAL_VALUE = STR('A'); +// const value_t FILL_VALUE = STR('B'); +// +// Text text(INITIAL_SIZE, INITIAL_VALUE); +// +// Text::pointer pbegin = &text.front(); +// Text::pointer pend = &text.back() + 1; +// Text::pointer pmax = pbegin + text.max_size(); +// +// // Fill free space with a pattern. +// std::fill(pend, pmax, FILL_VALUE); +// +// text.uninitialized_resize(NEW_SIZE); +// +// std::array compare_text; +// compare_text.fill(INITIAL_VALUE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// CHECK_EQUAL(NEW_SIZE, text.size()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 8UL; +// +// Text text(initial_text.c_str(), INITIAL_SIZE); +// +// // Overwrite from index 1 to one less than the new size and set to that size. +// text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept +// { +// size_t i = 1; +// while (i < (n - 1)) +// { +// p[i] = '1' + Text::value_type(i); +// ++i; +// } +// +// return i; +// }); +// +// CHECK_EQUAL(NEW_SIZE - 1, text.size()); +// CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) +// { +// const size_t INITIAL_SIZE = 5UL; +// const size_t NEW_SIZE = 3UL; +// +// Text text(initial_text.c_str(), INITIAL_SIZE); +// +// // Overwrite from index 1 to one less than the new size and set to that size. +// text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) +// { +// size_t i = 1; +// while (i < (n - 1)) +// { +// p[i] = '1' + Text::value_type(i); +// ++i; +// } +// +// return i; +// }); +// +// CHECK_EQUAL(NEW_SIZE - 1, text.size()); +// CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) +// { +// Text text(initial_text.c_str(), initial_text.size()); +// +// CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_fill) +// { +// Text text(SIZE, STR('A')); +// Text expected(SIZE, STR('B')); +// +// text.fill(STR('B')); +// +// bool is_equal = Equal(expected, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_empty_full) +// { +// Text text; +// text.resize(text.max_size(), STR('A')); +// +// CHECK(!text.empty()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_empty_half) +// { +// Text text; +// text.resize(text.max_size() / 2, STR('A')); +// +// CHECK(!text.empty()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_empty_empty) +// { +// Text text; +// +// CHECK(text.empty()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_full_full) +// { +// Text text; +// text.resize(text.max_size(), STR('A')); +// +// CHECK(text.full()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_full_half) +// { +// Text text; +// text.resize(text.max_size() / 2, STR('A')); +// +// CHECK(!text.full()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_full_empty) +// { +// Text text; +// +// CHECK(!text.full()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_index) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// for (size_t i = 0UL; i < text.size(); ++i) +// { +// CHECK_EQUAL(text[i], compare_text[i]); +// } +// +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_index_const) +// { +// const TextSTD compare_text(initial_text.c_str()); +// const Text text(initial_text.c_str()); +// +// for (size_t i = 0UL; i < text.size(); ++i) +// { +// CHECK_EQUAL(text[i], compare_text[i]); +// } +// +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_at) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// for (size_t i = 0UL; i < text.size(); ++i) +// { +// CHECK_EQUAL(text.at(i), compare_text.at(i)); +// } +// +// CHECK_FALSE(text.is_truncated()); +// CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_at_const) +// { +// const TextSTD compare_text(initial_text.c_str()); +// const Text text(initial_text.c_str()); +// +// for (size_t i = 0UL; i < text.size(); ++i) +// { +// CHECK_EQUAL(text.at(i), compare_text.at(i)); +// } +// +// CHECK_FALSE(text.is_truncated()); +// CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_front) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// CHECK(text.front() == compare_text.front()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_front_const) +// { +// const TextSTD compare_text(initial_text.c_str()); +// const Text text(initial_text.c_str()); +// +// CHECK(text.front() == compare_text.front()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_back) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// CHECK(text.back() == compare_text.back()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_back_const) +// { +// const TextSTD compare_text(initial_text.c_str()); +// const Text text(initial_text.c_str()); +// +// CHECK(text.back() == compare_text.back()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_data) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text(compare_text.begin(), compare_text.end()); +// +// bool is_equal = std::equal(text.data(), +// text.data_end(), +// compare_text.begin()); +// +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_data_const) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// const Text text(compare_text.begin(), compare_text.end()); +// +// bool is_equal = std::equal(text.data(), +// text.data_end(), +// compare_text.begin()); +// +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_string) +// { +// TextSTD compare_input(initial_text.c_str()); +// Text input(initial_text.c_str()); +// +// TextSTD compare_text; +// Text text; +// +// compare_text.assign(compare_input); +// text.assign(input); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_self_assign_string) +// { +// Text text(initial_text.c_str()); +// +// text.assign(text); +// +// bool is_equal = Equal(initial_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_view) +// { +// TextSTD compare_input(initial_text.c_str()); +// Text input(initial_text.c_str()); +// View view(input); +// +// TextSTD compare_text; +// Text text; +// +// compare_text.assign(compare_input); +// text.assign(view); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_string_excess) +// { +// TextSTD compare_input(initial_text.c_str()); +// TextL input(longer_text.c_str()); +// +// TextSTD compare_text; +// Text text; +// +// compare_text.assign(compare_input); +// text.assign(input); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_pointer) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text; +// text.assign(initial_text.c_str()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text; +// text.assign(longer_text.c_str()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_pointer_length) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text; +// text.assign(initial_text.c_str(), initial_text.size()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) +// { +// TextSTD compare_text(longer_text.c_str()); +// +// Text text; +// text.assign(longer_text.c_str(), longer_text.size()); +// +// compare_text.resize(text.max_size()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_range) +// { +// TextSTD compare_text(initial_text.c_str()); +// +// Text text; +// +// text.assign(compare_text.begin(), compare_text.end()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_range_excess) +// { +// Text text; +// +// text.assign(longer_text.begin(), longer_text.end()); +// +// CHECK_EQUAL(initial_text.size(), text.size()); +// +// bool is_equal = Equal(initial_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_size_value) +// { +// const size_t INITIAL_SIZE = 5UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// std::array compare_text; +// compare_text.fill(INITIAL_VALUE); +// +// Text text; +// text.assign(INITIAL_SIZE, INITIAL_VALUE); +// +// CHECK(text.size() == INITIAL_SIZE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_assign_size_value_excess) +// { +// const size_t INITIAL_SIZE = SIZE; +// const size_t EXCESS_SIZE = SIZE + 1UL; +// const value_t INITIAL_VALUE = STR('A'); +// std::array compare_text; +// compare_text.fill(INITIAL_VALUE); +// +// Text text; +// text.assign(EXCESS_SIZE, INITIAL_VALUE); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_push_back) +// { +// TextSTD compare_text; +// Text text; +// +// for (size_t i = 0UL; i < SIZE; ++i) +// { +// compare_text.push_back(STR('A') + value_t(i)); +// } +// +// for (size_t i = 0UL; i < SIZE; ++i) +// { +// text.push_back(STR('A') + value_t(i)); +// } +// +// CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); +// CHECK_EQUAL(compare_text.size(), text.size()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_push_back_excess) +// { +// TextSTD compare_text; +// Text text; +// +// for (size_t i = 0UL; i < SIZE; ++i) +// { +// compare_text.push_back(STR('A') + value_t(i)); +// } +// +// for (size_t i = 0UL; i < SIZE; ++i) +// { +// text.push_back(STR('A') + value_t(i)); +// CHECK_FALSE(text.is_truncated()); +// } +// +// text.push_back(STR('A') + value_t(SIZE)); +// +// CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); +// CHECK_EQUAL(compare_text.size(), text.size()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_pop_back) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// compare_text.pop_back(); +// compare_text.pop_back(); +// +// text.pop_back(); +// text.pop_back(); +// +// CHECK_EQUAL(compare_text.size(), text.size()); +// +// bool is_equal = Equal(compare_text, text); +// +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_value) +// { +// const size_t INITIAL_SIZE = 5UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) +// { +// TextSTD compare_text; +// Text text; +// +// text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); +// compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); +// +// text.insert(text.begin() + offset, INITIAL_VALUE); +// compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); +// +// CHECK_EQUAL(compare_text.size(), text.size()); +// +// bool is_equal = Equal(compare_text, text); +// +// CHECK(is_equal); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) +// { +// TextSTD compare_text(initial_text.begin(), initial_text.end()); +// Text text(initial_text.begin(), initial_text.end()); +// +// const value_t INITIAL_VALUE = STR('A'); +// +// size_t offset = 2UL; +// text.insert(text.cbegin() + offset, INITIAL_VALUE); +// compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); +// compare_text.erase(compare_text.cend() - 1); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = 0; +// text.insert(text.cbegin() + offset, STR('A')); +// compare_text.insert(compare_text.cbegin() + offset, STR('A')); +// compare_text.erase(compare_text.cend() - 1); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = text.size(); +// text.insert(text.cbegin() + offset, STR('A')); +// compare_text.insert(compare_text.cbegin() + offset, STR('A')); +// compare_text.erase(compare_text.cend() - 1); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_n_value) +// { +// TextSTD compare_text; +// Text text; +// +// const size_t INITIAL_SIZE = 5UL; +// const size_t INSERT_SIZE = 3UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) +// { +// text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); +// compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); +// text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); +// compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); +// +// CHECK_FALSE(text.is_truncated()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) +// { +// TextSTD compare_text; +// Text text; +// +// const size_t INSERT_SIZE = 4UL; +// const value_t INSERT_VALUE = STR('A'); +// +// size_t offset = 0UL; +// compare_text.assign(initial_text.cbegin(), initial_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); +// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = 2; +// compare_text.assign(initial_text.cbegin(), initial_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = 4; +// compare_text.assign(initial_text.cbegin(), initial_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = text.size(); +// compare_text.assign(initial_text.cbegin(), initial_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); +// text.assign(initial_text.cbegin(), initial_text.cend()); +// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_range) +// { +// const size_t INITIAL_SIZE = 5UL; +// +// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) +// { +// TextSTD compare_text; +// Text text; +// +// text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); +// compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); +// text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); +// compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); +// +// CHECK_FALSE(text.is_truncated()); +//# +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) +// { +// const size_t INITIAL_SIZE = 5UL; +// const value_t INITIAL_VALUE = STR('A'); +// +// TextSTD compare_text; +// Text text; +// +// size_t offset = 0UL; +// +// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); +// text.assign(INITIAL_SIZE, INITIAL_VALUE); +// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// compare_text.resize(initial_text.size()); +// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// offset = 2; +// +// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); +// text.assign(INITIAL_SIZE, INITIAL_VALUE); +// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// compare_text.resize(initial_text.size()); +// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// +// +// offset = 4; +// +// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); +// text.assign(INITIAL_SIZE, INITIAL_VALUE); +// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// compare_text.resize(initial_text.size()); +// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// CHECK_EQUAL(compare_text.size(), text.size()); +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_position_range_self) +// { +// size_t length = TextL::MAX_SIZE / 2UL; +// +// for (size_t offset = 10UL; offset < length; ++offset) +// { +// TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); +// TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); +// +// text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); +// compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) +// { +// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) +// { +// TextSTD compare_text(short_text.cbegin(), short_text.cend()); +// Text text(short_text.cbegin(), short_text.cend()); +// Text insert(insert_text.cbegin(), insert_text.cend()); +// +// text.insert(offset, insert); +// compare_text.insert(offset, insert_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) +// { +// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) +// { +// TextSTD compare_text(short_text.cbegin(), short_text.cend()); +// Text text(short_text.cbegin(), short_text.cend()); +// View view(insert_text.data(), insert_text.size()); +// +// text.insert(offset, view); +// compare_text.insert(offset, insert_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) +// { +// for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) +// { +// TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); +// Text text(initial_text.cbegin(), initial_text.cend()); +// Text insert(insert_text.cbegin(), insert_text.cend()); +// +// text.insert(offset, insert); +// compare_text.insert(offset, insert_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) +// { +// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) +// { +// TextSTD compare_text(short_text.cbegin(), short_text.cend()); +// Text text(short_text.cbegin(), short_text.cend()); +// Text insert(longer_text.cbegin(), longer_text.cend()); +// insert.erase(insert.cbegin(), insert.cend()); +// insert.append(insert_text.cbegin(), insert_text.cend()); +// +// text.insert(offset, insert); +// compare_text.insert(offset, insert_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) +// { +// TextSTD compare_text(short_text.cbegin(), short_text.cend()); +// Text text(short_text.cbegin(), short_text.cend()); +// Text insert(insert_text.cbegin(), insert_text.cend()); +// +// text.insert(0, insert, 0, insert.size()); +// compare_text.insert(0, insert_text, 0, insert_text.size()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// +// compare_text.assign(short_text.cbegin(), short_text.cend()); +// text.assign(short_text.cbegin(), short_text.cend()); +// +// text.insert(2, insert, 2, insert.size() - 2); +// compare_text.insert(2, insert_text, 2, insert_text.size() - 2); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// CHECK_EQUAL(compare_text.size(), text.size()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// +// compare_text.assign(short_text.cbegin(), short_text.cend()); +// text.assign(short_text.cbegin(), short_text.cend()); +// +// text.insert(short_text.size(), insert, 0, insert.size()); +// compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_string) +// { +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// Text append(insert_text.c_str()); +// +// // Non-overflow. +// compare_text.append(insert_text); +// text.append(append); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// append.assign(initial_text.c_str()); +// +// compare_text.append(initial_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(append); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_view) +// { +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// View view(insert_text.data(), insert_text.size()); +// +// // Non-overflow. +// compare_text.append(insert_text); +// text.append(view); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +// CHECK_FALSE(text.is_truncated()); +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// view.assign(initial_text.data(), initial_text.size()); +// +// compare_text.append(initial_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(view); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_truncated_string) +// { +////#include "etl/private/diagnostic_array_bounds_push.h" +// Text text(short_text.c_str()); +// TextS append(short_text.c_str()); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK(append.is_truncated()); +//#endif +// +// text.append(append); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +////#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_string_to_self) +// { +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// // Non-overflow. +// compare_text.append(compare_text); +// text.append(text); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(shorter_text.c_str()); +// text.assign(shorter_text.c_str()); +// +// compare_text.append(compare_text); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(text); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) +// { +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// Text append(insert_text.c_str()); +// +// // Whole string. +// compare_text.append(insert_text, 0, TextSTD::npos); +// text.append(append, 0, Text::npos); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Partial string. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// append.assign(initial_text.c_str()); +// +// compare_text.append(short_text, 1, 3); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(append, 1, 3); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// append.assign(initial_text.c_str()); +// +// compare_text.append(initial_text, 1, initial_text.size() - 1); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(append, 1, append.size() - 1); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_truncated_string_subpos_sublen) +// { +// Text text(short_text.c_str()); +// TextS append(short_text.c_str()); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK(append.is_truncated()); +//#endif +// +// text.append(append, 1, 2); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_c_string) +// { +// // Non-overflow. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// // Whole string. +// compare_text.append(insert_text.c_str()); +// text.append(insert_text.c_str()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.append(initial_text.c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(initial_text.c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_n_c) +// { +// // Non-overflow. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// // Non-overflow. +// compare_text.append(5, STR('A')); +// text.append(5, STR('A')); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.append(SIZE, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(SIZE, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_append_range) +// { +// // Non-overflow. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// Text append(insert_text.c_str()); +// +// compare_text.append(insert_text.begin(), insert_text.end()); +// text.append(append.begin(), append.end()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// append.assign(initial_text.c_str()); +// +// compare_text.append(initial_text.begin(), initial_text.end()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.append(append.begin(), append.end()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_string) +// { +// // Non-overflow short text, npos. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace"))); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, TextL(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, TextL(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_view) +// { +// // Non-overflow short text, npos. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace"))); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, View(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, View(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 2, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_string) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_view) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace")), 1, 5); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, TextL(STR("Replace")), 1, 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, View(STR("Replace")), 1, 5); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, View(STR("Replace with some text")), 1, 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, View(STR("Replace")), 1, 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, View(STR("Replace with some text")), 1, 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace")).c_str()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, TextL(STR("Replace")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +//#include "etl/private/diagnostic_array_bounds_push.h" +//#include "etl/private/diagnostic_stringop_overread_push.h" +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +//#include "etl/private/diagnostic_pop.h" +//#include "etl/private/diagnostic_pop.h" +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +//#include "etl/private/diagnostic_array_bounds_push.h" +//#include "etl/private/diagnostic_stringop_overread_push.h" +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +//#include "etl/private/diagnostic_pop.h" +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(2, 4, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, 7, STR('A')); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, 7, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, 4, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text, npos. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 7, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 7, 7, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, 7, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, 4, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, 4, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow, npos. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(2, TextSTD::npos, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(2, Text::npos, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) +// { +// // Non-overflow short text. +// TextSTD compare_text(short_text.c_str()); +// Text text(short_text.c_str()); +// +// TextSTD replace(STR("Replace")); +// TextSTD replace_long(STR("Replace with some text")); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, replace.begin() + 1, replace.begin() + 5); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow short text. +// compare_text.assign(short_text.c_str()); +// text.assign(short_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Non-overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 7, replace.begin() + 1, replace.begin() + 5); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 7, replace_long.begin() + 1, replace_long.begin() + 5); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// // Overflow. +// compare_text.assign(initial_text.c_str()); +// text.assign(initial_text.c_str()); +// +// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); +// compare_text.resize(std::min(compare_text.size(), SIZE)); +// text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); +// +// is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_erase_single_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); +// Text::iterator ditr = text.erase(text.begin() + 2); +// CHECK(*citr == *ditr); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); +// Text::iterator ditr = text.erase(text.cbegin() + 2); +// CHECK(*citr == *ditr); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_erase_range) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); +// Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); +// CHECK(*citr == *ditr); +// +// bool is_equal = Equal(compare_text, text); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_clear) +// { +// Text text(initial_text.c_str()); +// text.clear(); +// +// CHECK_EQUAL(text.size(), size_t(0)); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_const_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_reverse_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); +// CHECK(is_equal); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_equal) +// { +// const Text initial1(initial_text.c_str()); +// const Text initial2(initial_text.c_str()); +// +// CHECK(initial1 == initial2); +// +// const Text different(different_text.c_str()); +// +// CHECK(!(initial1 == different)); +// +// const Text shorter(shorter_text.c_str()); +// +// CHECK(!(shorter == initial1)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_not_equal) +// { +// const Text initial1(initial_text.c_str()); +// const Text initial2(initial_text.c_str()); +// +// CHECK(!(initial1 != initial2)); +// +// const Text different(different_text.begin(), different_text.end()); +// +// CHECK(initial1 != different); +// +// const Text shorter(shorter_text.begin(), shorter_text.end()); +// +// CHECK(shorter != initial1); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_less_than) +// { +// const Text less(less_text.c_str()); +// const Text initial(initial_text.c_str()); +// +// // String-String +// CHECK((less < initial) == (less_text < initial_text)); +// CHECK((initial < less) == (initial_text < less_text)); +// +// const Text greater(greater_text.c_str()); +// CHECK((greater < initial) == (greater_text < initial_text)); +// CHECK((initial < greater) == (initial_text < greater_text)); +// +// const Text shorter(shorter_text.c_str()); +// CHECK((shorter < initial) == (shorter_text < initial_text)); +// CHECK((initial < shorter) == (initial_text < shorter_text)); +// +// CHECK((initial < initial) == (initial_text < initial_text)); +// CHECK((initial < initial) == (initial_text < initial_text)); +// +// // String-Pointer Pointer-String +// CHECK((less < pinitial_text) == (less_text < pinitial_text)); +// CHECK((pinitial_text < less) == (pinitial_text < less_text)); +// +// CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); +// CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); +// +// CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); +// CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); +// +// CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); +// CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_less_than_or_equal) +// { +// const Text less(less_text.c_str()); +// const Text initial(initial_text.c_str()); +// +// // String-String +// CHECK((less <= initial) == (less_text <= initial_text)); +// CHECK((initial <= less) == (initial_text <= less_text)); +// +// const Text greater(greater_text.c_str()); +// CHECK((greater <= initial) == (greater_text <= initial_text)); +// CHECK((initial <= greater) == (initial_text <= greater_text)); +// +// const Text shorter(shorter_text.c_str()); +// CHECK((shorter <= initial) == (shorter_text <= initial_text)); +// CHECK((initial <= shorter) == (initial_text <= shorter_text)); +// +// CHECK((initial <= initial) == (initial_text <= initial_text)); +// CHECK((initial <= initial) == (initial_text <= initial_text)); +// +// // String-Pointer Pointer-String +// CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); +// CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); +// +// CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); +// CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); +// +// CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); +// CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); +// +// CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); +// CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_greater_than) +// { +// const Text less(less_text.c_str()); +// const Text initial(initial_text.c_str()); +// +// // String-String +// CHECK((less > initial) == (less_text > initial_text)); +// CHECK((initial > less) == (initial_text > less_text)); +// +// const Text greater(greater_text.c_str()); +// CHECK((greater > initial) == (greater_text > initial_text)); +// CHECK((initial > greater) == (initial_text > greater_text)); +// +// const Text shorter(shorter_text.c_str()); +// CHECK((shorter > initial) == (shorter_text > initial_text)); +// CHECK((initial > shorter) == (initial_text > shorter_text)); +// +// CHECK((initial > initial) == (initial_text > initial_text)); +// CHECK((initial > initial) == (initial_text > initial_text)); +// +// // String-Pointer Pointer-String +// CHECK((less > pinitial_text) == (less_text > pinitial_text)); +// CHECK((pinitial_text > less) == (pinitial_text > less_text)); +// +// CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); +// CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); +// +// CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); +// CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); +// +// CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); +// CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_greater_than_or_equal) +// { +// const Text less(less_text.begin(), less_text.end()); +// const Text initial(initial_text.begin(), initial_text.end()); +// +// // String-String +// CHECK((less >= initial) == (less_text >= initial_text)); +// CHECK((initial >= less) == (initial_text >= less_text)); +// +// const Text greater(greater_text.begin(), greater_text.end()); +// CHECK((greater >= initial) == (greater_text >= initial_text)); +// CHECK((initial >= greater) == (initial_text >= greater_text)); +// +// const Text shorter(shorter_text.begin(), shorter_text.end()); +// CHECK((shorter >= initial) == (shorter_text >= initial_text)); +// CHECK((initial >= shorter) == (initial_text > shorter_text)); +// +// CHECK((initial >= initial) == (initial_text >= initial_text)); +// CHECK((initial >= initial) == (initial_text >= initial_text)); +// +// // String-Pointer Pointer-String +// CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); +// CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); +// +// CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); +// CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); +// +// CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); +// CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); +// +// CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); +// CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// value_t buffer1[SIZE]; +// value_t buffer2[SIZE]; +// +// size_t length1 = compare_text.copy(buffer1, 5, 2); +// buffer1[length1] = STR('\0'); +// +// size_t length2 = text.copy(buffer2, 5, 2); +// buffer2[length2] = STR('\0'); +// +// CHECK_EQUAL(length1, length2); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = std::equal(buffer1, +// buffer1 + length1, +// buffer2); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_start_pos_too_large) +// { +// Text text(initial_text.c_str()); +// +// value_t buffer1[SIZE]; +// +// size_t length1 = text.copy(buffer1, 5, SIZE); +// +// CHECK_EQUAL(0U, length1); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// value_t buffer1[SIZE]; +// value_t buffer2[SIZE]; +// +// size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); +// buffer1[length1] = STR('\0'); +// +// size_t length2 = text.copy(buffer2, Text::npos, 2); +// buffer2[length2] = STR('\0'); +// +// CHECK_EQUAL(length1, length2); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = std::equal(buffer1, +// buffer1 + length1, +// buffer2); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_copy_count_too_large) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// value_t buffer1[SIZE]; +// value_t buffer2[SIZE]; +// +// size_t length1 = compare_text.copy(buffer1, SIZE, 2); +// buffer1[length1] = STR('\0'); +// +// size_t length2 = text.copy(buffer2, SIZE, 2); +// buffer2[length2] = STR('\0'); +// +// CHECK_EQUAL(length1, length2); +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// +// bool is_equal = std::equal(buffer1, +// buffer1 + length1, +// buffer2); +// CHECK(is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_string) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_needle(STR("needle")); +// Text needle(STR("needle")); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = 0UL; +// size_t position2 = 0UL; +// +// position1 = compare_haystack.find(compare_needle, position1); +// position2 = haystack.find(needle, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.find(compare_needle, position1 + 1); +// position2 = haystack.find(needle, position2 + 1); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.find(needle, position2 + 1); +// CHECK_EQUAL(Text::npos, position2); +// +// Text pin(STR("pin")); +// position2 = haystack.find(pin); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_view) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_needle(STR("needle")); +// Text needle(STR("needle")); +// View needle_view(needle); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = 0UL; +// size_t position2 = 0UL; +// +// position1 = compare_haystack.find(compare_needle, position1); +// position2 = haystack.find(needle_view, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.find(compare_needle, position1 + 1); +// position2 = haystack.find(needle_view, position2 + 1); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.find(needle_view, position2 + 1); +// CHECK_EQUAL(Text::npos, position2); +// +// View pin_view(STR("pin")); +// position2 = haystack.find(pin_view); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_pointer) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// const value_t* needle = STR("needle"); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = 0UL; +// size_t position2 = 0UL; +// +// position1 = compare_haystack.find(needle, position1); +// position2 = haystack.find(needle, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.find(needle, position1 + 1); +// position2 = haystack.find(needle, position2 + 1); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.find(needle, position2 + 1); +// CHECK_EQUAL(TextL::npos, position2); +// +// const value_t *pin = STR("pin"); +// position2 = haystack.find(pin); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// const value_t* needle = STR("needle"); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = 0UL; +// size_t position2 = 0UL; +// +// position1 = compare_haystack.find(needle, position1, 3); +// position2 = haystack.find(needle, position2, 3); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.find(needle, position1 + 1, 3); +// position2 = haystack.find(needle, position2 + 1, 3); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.find(needle, position2 + 1, 3); +// CHECK_EQUAL(TextL::npos, position2); +// +// const value_t *pin = STR("pin"); +// position2 = haystack.find(pin, 0, 3); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_contains_string) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// Text needle(STR("needle")); +// Text pin(STR("pin")); +// Text excess(STR("A really gigantic pin or needle that's really really big")); +// +// CHECK_TRUE(haystack.contains(needle)); +// CHECK_FALSE(haystack.contains(pin)); +// CHECK_FALSE(haystack.contains(excess)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_contains_view) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.contains(View(STR("needle")))); +// CHECK_FALSE(haystack.contains(View(STR("pin")))); +// CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_contains_pointer) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.contains(STR("needle"))); +// CHECK_FALSE(haystack.contains(STR("pin"))); +// CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_contains_char) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.contains(STR('l'))); +// CHECK_FALSE(haystack.contains(STR('p'))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_starts_with_string) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// Text start(STR("A haystack")); +// Text not_start(STR("a needle")); +// Text excess(STR("Really gigantic text that's really really big")); +// +// CHECK_TRUE(haystack.starts_with(start)); +// CHECK_FALSE(haystack.starts_with(not_start)); +// CHECK_FALSE(haystack.starts_with(excess)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_starts_with_view) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); +// CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); +// CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_starts_with_pointer) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.starts_with(STR("A haystack"))); +// CHECK_FALSE(haystack.starts_with(STR("a needle"))); +// CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_starts_with_char) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.starts_with(haystack[0])); +// CHECK_FALSE(haystack.starts_with(haystack[1])); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_ends_with_string) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// Text end(STR("else")); +// Text not_end(STR("needle")); +// Text excess(STR("Really gigantic text that's really really big")); +// +// CHECK_TRUE(haystack.ends_with(end)); +// CHECK_FALSE(haystack.ends_with(not_end)); +// CHECK_FALSE(haystack.ends_with(excess)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_ends_with_view) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.ends_with(View(STR("else")))); +// CHECK_FALSE(haystack.ends_with(View(STR("needle")))); +// CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_ends_with_pointer) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.ends_with(STR("else"))); +// CHECK_FALSE(haystack.ends_with(STR("needle"))); +// CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_ends_with_char) +// { +// TextL haystack(STR("A haystack with a needle and nothing else")); +// +// CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); +// CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_rfind_string) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_needle(STR("needle")); +// Text needle(STR("needle")); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = TextSTD::npos; +// size_t position2 = Text::npos; +// +// position1 = compare_haystack.rfind(compare_needle, position1); +// position2 = haystack.rfind(needle, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); +// position2 = haystack.rfind(needle, haystack.size() - 10); +// CHECK_EQUAL(position1, position2); +// +// Text pin(STR("pin")); +// position2 = haystack.rfind(pin); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_rfind_view) +// { +// const value_t* the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_needle(STR("needle")); +// Text needle(STR("needle")); +// View needle_view(needle); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// size_t position1 = TextSTD::npos; +// size_t position2 = Text::npos; +// +// position1 = compare_haystack.rfind(compare_needle, position1); +// position2 = haystack.rfind(needle_view, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); +// position2 = haystack.rfind(needle_view, haystack.size() - 10); +// CHECK_EQUAL(position1, position2); +// +// View pin_view(STR("pin")); +// position2 = haystack.rfind(pin_view); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_rfind_pointer) +// { +// const value_t*the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// const value_t* needle = STR("needle"); +// +// size_t position1 = TextSTD::npos; +// size_t position2 = Text::npos; +// +// position1 = compare_haystack.rfind(needle, position1); +// position2 = haystack.rfind(needle, position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10); +// position2 = haystack.rfind(needle, haystack.size() - 10); +// CHECK_EQUAL(position1, position2); +// +// Text pin(STR("pin")); +// position2 = haystack.rfind(pin); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) +// { +// const value_t*the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// const value_t* needle = STR("needle"); +// +// size_t position1 = TextSTD::npos; +// size_t position2 = Text::npos; +// +// position1 = compare_haystack.rfind(needle, position1, 3); +// position2 = haystack.rfind(needle, position2, 3); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10, 3); +// position2 = haystack.rfind(needle, haystack.size() - 10, 3); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.rfind(STR("pin"), 3); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_rfind_c_position) +// { +// const value_t*the_haystack = STR("A haystack with a needle and another needle"); +// +// TextSTD compare_haystack(the_haystack); +// TextL haystack(the_haystack); +// +// etl::istring::size_type position1 = TextL::npos; +// size_t position2 = Text::npos; +// +// position1 = compare_haystack.rfind(STR('e'), position1); +// position2 = haystack.rfind(STR('e'), position2); +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); +// position2 = haystack.rfind(STR('e'), haystack.size() - 10); +// CHECK_EQUAL(position1, position2); +// +// position2 = haystack.rfind(STR('z')); +// CHECK_EQUAL(TextL::npos, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_substr) +// { +// TextSTD compare_text(initial_text.c_str()); +// Text text(initial_text.c_str()); +// +// TextSTD compare_result; +// Text result; +// +// // Equal. +// compare_result = compare_text.substr(compare_text.size()); +// result = text.substr(text.size()); +// CHECK(Equal(compare_result, result)); +// +// // Whole string. +// compare_result = compare_text.substr(); +// result = text.substr(); +// CHECK(Equal(compare_result, result)); +// +// // Starting from position 2. +// compare_result = compare_text.substr(2); +// result = text.substr(2); +// CHECK(Equal(compare_result, result)); +// +// // Starting from position 2 for 3 characters. +// compare_result = compare_text.substr(2, 3); +// result = text.substr(2, 3); +// CHECK(Equal(compare_result, result)); +// +// // Starting from position 2 for too many characters. +// compare_result = compare_text.substr(2, compare_text.size()); +// result = text.substr(2, text.size()); +// CHECK(Equal(compare_result, result)); +// +// // Starting from beyond the end of the string. +// CHECK_THROW(text.substr(text.size() + 1), etl::string_out_of_bounds); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_string) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); +// result = text.compare(Text(STR("ABCDEF"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); +// result = text.compare(Text(STR("ABCDEE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); +// result = text.compare(Text(STR("ABCDEG"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); +// result = text.compare(Text(STR("ABCDE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); +// result = text.compare(Text(STR("ABCDEFG"))); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_view) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); +// result = text.compare(View(STR("ABCDEF"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); +// result = text.compare(View(STR("ABCDEE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); +// result = text.compare(View(STR("ABCDEG"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); +// result = text.compare(View(STR("ABCDE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); +// result = text.compare(View(STR("ABCDEFG"))); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_string) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); +// result = text.compare(3, 6, Text(STR("ABCDEF"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); +// result = text.compare(3, 6, Text(STR("ABCDEE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); +// result = text.compare(3, 6, Text(STR("ABCDEG"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); +// result = text.compare(3, 6, Text(STR("ABCDE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); +// result = text.compare(3, 6, Text(STR("ABCDEFG"))); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_view) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); +// result = text.compare(3, 6, View(STR("ABCDEF"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); +// result = text.compare(3, 6, View(STR("ABCDEE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); +// result = text.compare(3, 6, View(STR("ABCDEG"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); +// result = text.compare(3, 6, View(STR("ABCDE"))); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); +// result = text.compare(3, 6, View(STR("ABCDEFG"))); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); +// result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); +// result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); +// result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); +// result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); +// result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); +// result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); +// result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); +// result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); +// result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); +// result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_c_string) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(STR("ABCDEF")); +// result = text.compare(STR("ABCDEF")); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(STR("ABCDEE")); +// result = text.compare(STR("ABCDEE")); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(STR("ABCDEG")); +// result = text.compare(STR("ABCDEG")); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(STR("ABCDE")); +// result = text.compare(STR("ABCDE")); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(STR("ABCDEFG")); +// result = text.compare(STR("ABCDEFG")); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, STR("ABCDEF")); +// result = text.compare(3, 6, STR("ABCDEF")); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, STR("ABCDEE")); +// result = text.compare(3, 6, STR("ABCDEE")); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, STR("ABCDEG")); +// result = text.compare(3, 6, STR("ABCDEG")); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, STR("ABCDE")); +// result = text.compare(3, 6, STR("ABCDE")); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, STR("ABCDEFG")); +// result = text.compare(3, 6, STR("ABCDEFG")); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) +// { +// TextSTD compare_text(STR("xxxABCDEFyyy")); +// Text text(STR("xxxABCDEFyyy")); +// +// int compare_result; +// int result; +// +// // Equal. +// compare_result = compare_text.compare(3, 6, STR("ABCDEFbb"), 6); +// result = text.compare(3, 6, STR("ABCDEFbb"), 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Less. +// compare_result = compare_text.compare(3, 6, STR("ABCDEEbb"), 6); +// result = text.compare(3, 6, STR("ABCDEEbb"), 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Greater. +// compare_result = compare_text.compare(3, 6, STR("ABCDEGbb"), 6); +// result = text.compare(3, 6, STR("ABCDEGbb"), 6); +// CHECK(compares_agree(compare_result, result)); +// +// // Shorter. +// compare_result = compare_text.compare(3, 6, STR("ABCDEbb"), 5); +// result = text.compare(3, 6, STR("ABCDEbb"), 5); +// CHECK(compares_agree(compare_result, result)); +// +// // Longer. +// compare_result = compare_text.compare(3, 6, STR("ABCDEFGbb"), 7); +// result = text.compare(3, 6, STR("ABCDEFGbb"), 7); +// CHECK(compares_agree(compare_result, result)); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); +// size_t position2 = text.find_first_of(Text(STR("ZCXF"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); +// position2 = text.find_first_of(Text(STR("WXYZ"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); +// position2 = text.find_first_of(Text(STR("ZCXF")), 3); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); +// position2 = text.find_first_of(Text(STR("ZCXF")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); +// size_t position2 = text.find_first_of(View(STR("ZCXF"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); +// position2 = text.find_first_of(View(STR("WXYZ"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); +// position2 = text.find_first_of(View(STR("ZCXF")), 3); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); +// position2 = text.find_first_of(View(STR("ZCXF")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_of(STR("ZCXF")); +// size_t position2 = text.find_first_of(STR("ZCXF")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR("WXYZ")); +// position2 = text.find_first_of(STR("WXYZ")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR("ZCXF"), 3); +// position2 = text.find_first_of(STR("ZCXF"), 3); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_of(STR("ZCXF"), 100); +// position2 = text.find_first_of(STR("ZCXF"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); +// size_t position2 = text.find_first_of(STR("ZCXF"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR("WXYZ"), 0, 4); +// position2 = text.find_first_of(STR("WXYZ"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR("ZCXF"), 1, 3); +// position2 = text.find_first_of(STR("ZCXF"), 1, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR("ZCXF"), 3, 3); +// position2 = text.find_first_of(STR("ZCXF"), 3, 3); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_of(STR("ZCXF"), 100); +// position2 = text.find_first_of(STR("ZCXF"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_of(STR('C')); +// size_t position2 = text.find_first_of(STR('C')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR('Z')); +// position2 = text.find_first_of(STR('Z')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR('F'), 3); +// position2 = text.find_first_of(STR('F'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR('C'), 3); +// position2 = text.find_first_of(STR('C'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_of(STR('C'), compare_text.size()); +// position2 = text.find_first_of(STR('C'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_of(STR('C'), 100); +// position2 = text.find_first_of(STR('C'), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); +// size_t position2 = text.find_last_of(Text(STR("ZCXE"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); +// position2 = text.find_last_of(Text(STR("WXYZ")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); +// position2 = text.find_last_of(Text(STR("ZCXE")), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); +// position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); +// position2 = text.find_last_of(Text(STR("ZCXE")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); +// size_t position2 = text.find_last_of(View(STR("ZCXE"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); +// position2 = text.find_last_of(View(STR("WXYZ")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); +// position2 = text.find_last_of(View(STR("ZCXE")), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); +// position2 = text.find_last_of(View(STR("ZCXE")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); +// position2 = text.find_last_of(View(STR("ZCXE")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_of(STR("ZCXE")); +// size_t position2 = text.find_last_of(STR("ZCXE")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("WXYZ"), 3); +// position2 = text.find_last_of(STR("WXYZ"), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), 5); +// position2 = text.find_last_of(STR("ZCXE"), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), 6); +// position2 = text.find_last_of(STR("ZCXE"), 6); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size()); +// position2 = text.find_last_of(STR("ZCXE"), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_of(STR("ZCXE"), 100); +// position2 = text.find_last_of(STR("ZCXE"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); +// size_t position2 = text.find_last_of(STR("AZCXE"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("WXYZ"), 4, 3); +// position2 = text.find_last_of(STR("WXYZ"), 4, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), 5, 3); +// position2 = text.find_last_of(STR("ZCXE"), 5, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), 1, 3); +// position2 = text.find_last_of(STR("ZCXE"), 1, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size(), 4); +// position2 = text.find_last_of(STR("ZCXE"), text.size(), 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); +// position2 = text.find_last_of(STR("ZCXE"), 100, 4); +// +// CHECK_EQUAL(position1, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_last_of(STR('C')); +// size_t position2 = text.find_last_of(STR('C')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR('Z')); +// position2 = text.find_last_of(STR('Z')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR('F'), compare_text.size()); +// position2 = text.find_last_of(STR('F'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR('C'), 3); +// position2 = text.find_last_of(STR('C'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_of(STR('C'), compare_text.size()); +// position2 = text.find_last_of(STR('C'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_of(STR('C'), 100); +// position2 = text.find_last_of(STR('C'), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); +// size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); +// position2 = text.find_first_not_of(Text(STR("ZAXB"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); +// position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); +// position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); +// position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); +// size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); +// position2 = text.find_first_not_of(View(STR("ZAXB"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); +// position2 = text.find_first_not_of(View(STR("ZAXB")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); +// position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); +// position2 = text.find_first_not_of(View(STR("ZAXB")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); +// size_t position2 = text.find_first_not_of(STR("ZAXB")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB")); +// position2 = text.find_first_not_of(STR("ZAXB")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 3); +// position2 = text.find_first_not_of(STR("ZAXB"), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), compare_text.size()); +// position2 = text.find_first_not_of(STR("ZAXB"), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 100); +// position2 = text.find_first_not_of(STR("ZAXB"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); +// size_t position2 = text.find_first_not_of(STR("ZAXB"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); +// position2 = text.find_first_not_of(STR("ZAXB"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 1, 3); +// position2 = text.find_first_not_of(STR("ZAXB"), 1, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 3, 3); +// position2 = text.find_first_not_of(STR("ZAXB"), 3, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR("ZAXB"), compare_text.size(), 3); +// position2 = text.find_first_not_of(STR("ZAXB"), text.size(), 3); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_not_of(STR("ZAXB"), 100); +// position2 = text.find_first_not_of(STR("ZAXB"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_first_not_of(STR('A')); +// size_t position2 = text.find_first_not_of(STR('A')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR('B')); +// position2 = text.find_first_not_of(STR('B')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR('C'), 3); +// position2 = text.find_first_not_of(STR('C'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR('D'), 3); +// position2 = text.find_first_not_of(STR('D'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_first_not_of(STR('C'), compare_text.size()); +// position2 = text.find_first_not_of(STR('C'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_first_not_of(STR('C'), 100); +// position2 = text.find_first_not_of(STR('C'), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); +// size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); +// size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); +// position2 = text.find_last_not_of(View(STR("ZEXD")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); +// position2 = text.find_last_not_of(View(STR("ZEXD")), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); +// position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); +// position2 = text.find_last_not_of(View(STR("ZEXD")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); +// size_t position2 = text.find_last_not_of(STR("ZEXD")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 3); +// position2 = text.find_last_not_of(STR("ZEXD"), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5); +// position2 = text.find_last_not_of(STR("ZEXD"), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size()); +// position2 = text.find_last_not_of(STR("ZEXD"), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100); +// position2 = text.find_last_not_of(STR("ZEXD"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); +// size_t position2 = text.find_last_not_of(STR("ZEXD"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5, 3); +// position2 = text.find_last_not_of(STR("ZEXD"), 5, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 1, 3); +// position2 = text.find_last_not_of(STR("ZEXD"), 1, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size(), 4); +// position2 = text.find_last_not_of(STR("ZEXD"), text.size(), 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100, 4); +// position2 = text.find_last_not_of(STR("ZEXD"), 100, 4); +// +// CHECK_EQUAL(position1, position2); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_last_not_of(STR('F')); +// size_t position2 = text.find_last_not_of(STR('F')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('Z')); +// position2 = text.find_last_not_of(STR('Z')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('A'), compare_text.size()); +// position2 = text.find_last_not_of(STR('A'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('C'), 3); +// position2 = text.find_last_not_of(STR('C'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('C'), compare_text.size()); +// position2 = text.find_last_not_of(STR('C'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(STR('C'), 100); +// position2 = text.find_last_not_of(STR('C'), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_hash) +// { +// // Test with actual string type. +// Text text(STR("ABCDEFHIJKL")); +// size_t hash = etl::hash()(text); +// size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); +// CHECK_EQUAL(compare_hash, hash); +// +// // Test with interface string type. +// IText& itext = text; +// hash = etl::hash()(itext); +// CHECK_EQUAL(compare_hash, hash); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_memcpy_repair) +// { +// Text text; +// +// text.assign(STR("ABCDEF")); +// +// char buffer[sizeof(Text)]; +// +// memcpy(&buffer, (const void*)&text, sizeof(text)); +// +// Text& rtext(*reinterpret_cast(buffer)); +// rtext.repair(); +// +// CHECK(!rtext.empty()); +// CHECK(!rtext.full()); +// +// bool is_equal = Equal(text, rtext); +// CHECK(is_equal); +// +// text = STR("GHIJKL"); +// is_equal = Equal(text, rtext); +// CHECK(!is_equal); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_memcpy_repair_virtual) +// { +// Text text; +// +// text.assign(STR("ABCDEF")); +// +// char buffer[sizeof(Text)]; +// +// memcpy(&buffer, (const void*)&text, sizeof(text)); +// +// IText& itext(*reinterpret_cast(buffer)); +// itext.repair(); +// +// CHECK(!itext.empty()); +// CHECK(!itext.full()); +// +// bool is_equal = Equal(text, itext); +// CHECK(is_equal); +// +// text = STR("GHIJKL"); +// is_equal = Equal(text, itext); +// CHECK(!is_equal); +// } +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) +// { +// Text text(short_text.c_str()); +// CHECK_FALSE(text.is_truncated()); +// +// text.insert(3, initial_text.c_str()); +// CHECK_TRUE(text.is_truncated()); +// +// while (text.size() != 0) +// { +// text.pop_back(); +// CHECK_TRUE(text.is_truncated()); +// } +// +// text.clear(); +// CHECK_FALSE(text.is_truncated()); +// +// text.assign(longer_text.c_str()); +// CHECK_TRUE(text.is_truncated()); +// +// text.assign(short_text.c_str()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_add_from_truncated) +// { +// Text text1(short_text.c_str()); +// TextS text2(short_text.c_str()); +// +// CHECK_FALSE(text1.is_truncated()); +// CHECK_TRUE(text2.is_truncated()); +// +// // text2 has the truncate flag set. +// text1 += text2; +// +// CHECK(text1.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_add_to_truncated) +// { +// Text text1(longer_text.c_str()); +// Text text2(short_text.c_str()); +// +// CHECK(text1.is_truncated()); +// CHECK_FALSE(text2.is_truncated()); +// +// // Clear text but not the truncate flag. +// text1.erase(text1.begin(), text1.end()); +// +// // text1 still has the truncate flag set. +// text1 += text2; +// +// CHECK(text1.is_truncated()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_clear_truncated) +// { +// Text text(longer_text.c_str()); +// CHECK_TRUE(text.is_truncated()); +// +// text.clear_truncated(); +// CHECK_FALSE(text.is_truncated()); +// } +//#endif +// +//#if ETL_HAS_STRING_CLEAR_AFTER_USE +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_destructor) +// { +// char buffer[sizeof(Text)]; +// std::fill_n(buffer, sizeof(Text), 0); +// ::new (buffer) Text(STR("ABCDEF")); +// +// Text& text = *reinterpret_cast(buffer); +// text.set_secure(); +// +// CHECK(Text(STR("ABCDEF")) == text); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// // Destroy the text object. +// std::atomic_signal_fence(std::memory_order_seq_cst); +// text.~Text(); +// std::atomic_signal_fence(std::memory_order_seq_cst); +// +// // Check there no non-zero values in the string. +// CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_assign) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pe = text.end(); +// +// text.assign(STR("ABC")); +// +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_resize_down) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pe = text.end(); +// +// text.resize(text.size() - 3U); +// +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_erase) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// text.erase(pb + 2, pb + 5); +// +// // Check there no non-zero values in the remainder of the string. +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_replace) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// text.replace(pb + 1, pb + 4, STR("G")); +// +// // Check there no non-zero values in the remainder of the string. +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_secure_after_clear) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// text.clear(); +// +// // 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 +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) +// { +// Text empty; +// Text text; +// +// text.initialize_free_space(); +// +// CHECK(text.empty()); +// CHECK(text == empty); +// +// for (size_t i = text.size(); i < text.max_size(); ++i) +// { +// CHECK_EQUAL(0, text[i]); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) +// { +// Text empty; +// Text initial = STR("ABC"); +// Text text(initial); +// +// text.initialize_free_space(); +// +// CHECK(text == initial); +// CHECK(text != empty); +// +// for (size_t i = text.size(); i < text.max_size(); ++i) +// { +// CHECK_EQUAL(0, text[i]); +// } +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) +// { +// Text text; +// +// text.initialize_free_space(); +// std::fill(text.data(), text.data() + text.max_size(), STR('A')); +// text.trim_to_terminator(); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// CHECK_EQUAL(text.max_size(), text.size()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_update_after_c_string_shorter_size) +// { +// Text text; +// +// text.initialize_free_space(); +// std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); +// text.trim_to_terminator(); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// CHECK_EQUAL(text.max_size() - 1, text.size()); +// } +// +// //************************************************************************* +// TEST_FIXTURE(SetupFixture, test_update_after_c_string_greater_size) +// { +// Text text; +// +// text.initialize_free_space(); +// std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. +// text.trim_to_terminator(); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// CHECK_EQUAL(text.max_size(), text.size()); +// } +// +// //************************************************************************* +//#if ETL_USING_STL +// TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) +// { +// Text text1 = STR("Hello World"); +// +// std::stringstream sstream; +// +// sstream << text1; +// +// TextSTD sstream_string = sstream.str(); +// +// View sstream_view(sstream_string.data(), sstream_string.size()); +// +// CHECK(text1 == sstream_view); +// } +//#endif + }; +} diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 721f9bcc..e0fa728a 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -9331,6 +9331,7 @@ + From 0851740cb4d328358464f7a1ad060d9c872c0f85 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 24 Jul 2025 09:57:14 +0100 Subject: [PATCH 4/8] Work in progress --- test/test_const_string_char.cpp | 5514 +------------------------------ test/vs2022/etl.vcxproj.filters | 3 + 2 files changed, 163 insertions(+), 5354 deletions(-) diff --git a/test/test_const_string_char.cpp b/test/test_const_string_char.cpp index f46c90f3..a72d5d15 100644 --- a/test/test_const_string_char.cpp +++ b/test/test_const_string_char.cpp @@ -95,5385 +95,191 @@ namespace } }; -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_default_constructor) -// { -// -// Text text; -// -// CHECK_EQUAL(text.size(), size_t(0)); -// CHECK(text.empty()); -// CHECK_EQUAL(text.capacity(), SIZE); -// CHECK_EQUAL(text.max_size(), SIZE); -// CHECK(text.begin() == text.end()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST(test_iterator_comparison_empty) -// { -// Text text; -// -// CHECK(text.begin() == text.end()); -// CHECK(text.cbegin() == text.cend()); -// CHECK(text.rbegin() == text.rend()); -// CHECK(text.crbegin() == text.crend()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_size_value) -// { -// const size_t INITIAL_SIZE = 5UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); -// Text text(INITIAL_SIZE, INITIAL_VALUE); -// -// CHECK(text.size() == INITIAL_SIZE); -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_size_excess) -// { -// Text text(SIZE + 1, STR('A')); -// -// CHECK_EQUAL(SIZE, text.size()); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); - static constexpr const char* initial = "Hello World"; - static constexpr Text text(initial); - static constexpr size_t length = etl::strlen(initial); + static constexpr const char* initial = "Hello World"; + static constexpr Text text(initial); + static constexpr size_t length = etl::strlen(initial); - static constexpr auto text_empty = text.empty(); - CHECK_FALSE(text_empty); + static constexpr auto text_empty = text.empty(); + CHECK_FALSE(text_empty); - static constexpr auto text_full = text.full(); - CHECK_TRUE(text_full); + static constexpr auto text_full = text.full(); + CHECK_TRUE(text_full); - text.capacity(); - text.max_size(); - text.size(); - text.length(); - text.available(); - text.is_truncated(); - text.is_secure(); + static constexpr auto text_capacity = text.capacity(); + CHECK_EQUAL(length, text_capacity); - static constexpr const char* text_data = text.data(); - CHECK_EQUAL(&initial[0], text_data); - - static constexpr const char* text_data_end = text.data_end(); - CHECK_EQUAL(&initial[length], text_data_end); + static constexpr auto text_max_size = text.max_size(); + CHECK_EQUAL(length, text_max_size); - static constexpr auto text_begin = text.begin(); - CHECK_EQUAL(&initial[0], text_begin); + static constexpr auto text_size = text.size(); + CHECK_EQUAL(length, text_size); - static constexpr auto text_cbegin = text.cbegin(); - CHECK_EQUAL(&initial[0], text_cbegin); + static constexpr auto text_length = text.length(); + CHECK_EQUAL(length, text_length); - static constexpr auto text_rbegin = text.rbegin(); - CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_rbegin)); - - static constexpr auto text_crbegin = text.crbegin(); - CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_crbegin)); + static constexpr auto text_available = text.available(); + CHECK_EQUAL(0, text_available); - static constexpr auto text_end = text.end(); - CHECK_EQUAL(&initial[length], text_end); + static constexpr auto text_is_truncated = text.is_truncated(); + CHECK_FALSE(text_is_truncated); - static constexpr auto text_cend = text.cend(); - CHECK_EQUAL(&initial[length], text_cend); + static constexpr auto text_is_secure = text.is_secure(); + CHECK_FALSE(text_is_secure); - static constexpr auto text_rend = text.rend(); - CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_rend)); + static constexpr const char* text_data = text.data(); + CHECK_EQUAL(&initial[0], text_data); - static constexpr auto text_crend = text.crend(); - CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_crend)); + static constexpr const char* text_data_end = text.data_end(); + CHECK_EQUAL(&initial[length], text_data_end); - static constexpr auto text_contains_world = text.contains("World"); - CHECK_TRUE(text_contains_world); + static constexpr auto text_begin = text.begin(); + CHECK_EQUAL(&initial[0], text_begin); - static constexpr auto text_contains_worls = text.contains("Worls"); - CHECK_FALSE(text_contains_worls); + static constexpr auto text_cbegin = text.cbegin(); + CHECK_EQUAL(&initial[0], text_cbegin); - static constexpr auto text_starts_with_hello = text.starts_with("Hello"); - CHECK_TRUE(text_starts_with_hello); + static constexpr auto text_rbegin = text.rbegin(); + CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_rbegin)); - static constexpr auto text_starts_with_world = text.starts_with("World"); - CHECK_FALSE(text_starts_with_world); + static constexpr auto text_crbegin = text.crbegin(); + CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_crbegin)); - static constexpr auto text_ends_with_hello = text.ends_with("Hello"); - CHECK_FALSE(text_ends_with_hello); + static constexpr auto text_end = text.end(); + CHECK_EQUAL(&initial[length], text_end); - static constexpr auto text_ends_with_world = text.ends_with("World"); - CHECK_TRUE(text_ends_with_world); + static constexpr auto text_cend = text.cend(); + CHECK_EQUAL(&initial[length], text_cend); - static constexpr auto text_find_world = text.find("World"); - CHECK_EQUAL(6, text_find_world); + static constexpr auto text_rend = text.rend(); + CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_rend)); - static constexpr auto text_find_worls = text.find("Worls"); - CHECK_EQUAL(Text::npos, text_find_worls); + static constexpr auto text_crend = text.crend(); + CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_crend)); - static constexpr auto text_index_operator = text[3]; - CHECK_EQUAL(initial[3], text_index_operator); - - static constexpr auto text_at = text.at(3); - CHECK_EQUAL(initial[3], text_at); - - static constexpr auto text_front = text.front(); - CHECK_EQUAL(initial[0], text_front); - - static constexpr auto text_back = text.back(); - CHECK_EQUAL(initial[length - 1], text_back); - - static constexpr const char* text_c_str = text.c_str(); - CHECK_EQUAL(&initial[0], text_c_str); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); - CHECK_FALSE(text.is_truncated()); + bool is_equal = Equal(std::string(initial), text); + CHECK(is_equal); } -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_shorter_string) -// { -// TextSTD compare_text(shorter_text.c_str()); -// -// Text text(shorter_text.c_str()); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text(longer_text.c_str()); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) -// { -// TextSTD compare_text(SIZE, STR('A')); -// -// Text text(SIZE, STR('A')); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) -// { -// TextSTD compare_text(SIZE, STR('A')); -// -// Text text(SIZE + 1, STR('A')); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_size_char) -// { -// TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); -// -// Text text(initial_text.c_str(), initial_text.size() / 2); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) -// { -// TextSTD compare_text(initial_text.c_str(), initial_text.size()); -// -// Text text(longer_text.c_str(), longer_text.size()); -// -// CHECK(!text.empty()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_range) -// { -// TextSTD compare_text(initial_text.begin(), initial_text.end()); -// -// Text text(compare_text.begin(), compare_text.end()); -// -// CHECK(text.size() == SIZE); -// CHECK(!text.empty()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_range_excess) -// { -// Text text(longer_text.begin(), longer_text.end()); -// -// bool is_equal = Equal(initial_text, text); -// CHECK(is_equal); -// CHECK(text.size() == SIZE); -// CHECK(!text.empty()); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_from_literal) -// { -// Text text(STR("Hello World")); -// -// bool is_equal = Equal(initial_text, text); -// CHECK(is_equal); -// CHECK(text.size() == SIZE); -// CHECK(!text.empty()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) -// { -// View view(initial_text.data(), initial_text.size()); -// Text text(view); -// -// bool is_equal = Equal(initial_text, text); -// CHECK(is_equal); -// CHECK(text.size() == SIZE); -// CHECK(!text.empty()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_constructor) -// { -// Text text(initial_text.c_str()); -// Text text2(text); -// CHECK(text2 == text); -// CHECK_FALSE(text2.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_constructor_i) -// { -// Text text(initial_text.c_str()); -// IText& itext = text; -// Text text2(itext); -// CHECK(text2 == text); -// CHECK_FALSE(text2.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_constructor_excess) -// { -// Text text(initial_text.c_str()); -// TextL textl(longer_text.c_str()); -// Text text2(textl); -// CHECK(text2 == text); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text2.is_truncated()); -//#else -// CHECK_FALSE(text2.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_constructor_from_truncated) -// { -// Text text(longer_text.c_str()); -// Text text2(text); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text2.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_construct_position_length) -// { -// TextSTD compare_text(initial_text.c_str()); -// TextSTD compare_text2(compare_text, 2, 4); -// -// Text text(initial_text.c_str()); -// Text text2(text, 2, 4); -// -// bool is_equal = Equal(compare_text2, text2); -// CHECK(is_equal); -// CHECK_FALSE(text2.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) -// { -// TextSTD compare_text(longer_text.c_str()); -// TextSTD compare_text2(compare_text, 2, 11); -// -// TextL textl(longer_text.c_str()); -// Text text2(textl, 2, 12); -// -// bool is_equal = Equal(compare_text2, text2); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text2.is_truncated()); -//#endif -// } -// -//#if ETL_HAS_INITIALIZER_LIST -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_construct_initializer_list) -// { -// TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; -// Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) -// { -// TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), -// STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; -// Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), -// STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), -// STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -//#endif -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment) -// { -// Text text(initial_text.begin(), initial_text.end()); -// Text other_text; -// -// other_text = text; -// -// bool is_equal = Equal(text, other_text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// CHECK_FALSE(other_text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_excess) -// { -// Text text(longer_text.begin(), longer_text.end()); -// Text other_text; -// -// other_text = text; -// -// bool is_equal = Equal(text, other_text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -// CHECK_TRUE(other_text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -// CHECK_FALSE(other_text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_iterface) -// { -// Text text1(initial_text.begin(), initial_text.end()); -// Text text2; -// -// IText& itext1 = text1; -// IText& itext2 = text2; -// -// itext2 = itext1; -// -// bool is_equal = Equal(text1, text2); -// -// CHECK(is_equal); -// CHECK_FALSE(text1.is_truncated()); -// CHECK_FALSE(text2.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_iterface_excess) -// { -// Text text1(longer_text.begin(), longer_text.end()); -// Text text2; -// -// IText& itext1 = text1; -// IText& itext2 = text2; -// -// itext2 = itext1; -// -// bool is_equal = Equal(text1, text2); -// -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text1.is_truncated()); -// CHECK_TRUE(text2.is_truncated()); -//#else -// CHECK_FALSE(text1.is_truncated()); -// CHECK_FALSE(text2.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_self_assignment) -// { -// Text text(initial_text.begin(), initial_text.end()); -// Text other_text(text); -// -//#include "etl/private/diagnostic_self_assign_overloaded_push.h" -// other_text = other_text; -//#include "etl/private/diagnostic_pop.h" -// -// bool is_equal = Equal(text, other_text); -// -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// CHECK_FALSE(other_text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_self_assignment_excess) -// { -// Text text(longer_text.begin(), longer_text.end()); -// Text other_text(text); -// -//#include "etl/private/diagnostic_self_assign_overloaded_push.h" -// other_text = other_text; -//#include "etl/private/diagnostic_pop.h" -// -// bool is_equal = Equal(text, other_text); -// -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -// CHECK_TRUE(other_text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -// CHECK_FALSE(other_text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_from_literal) -// { -// Text text; -// -// text = STR("Hello World"); -// -// bool is_equal = Equal(TextSTD(STR("Hello World")), text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_excess) -// { -// Text text; -// -// text = STR("Hello World There"); -// -// bool is_equal = Equal(TextSTD(STR("Hello World")), text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface) -// { -// Text text; -// IText& itext = text; -// -// itext = STR("Hello World"); -// -// bool is_equal = Equal(TextSTD(STR("Hello World")), itext); -// CHECK(is_equal); -// CHECK(!itext.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface_excess) -// { -// Text text; -// IText& itext = text; -// -// itext = STR("Hello World There"); -// -// bool is_equal = Equal(TextSTD(STR("Hello World")), itext); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK(itext.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assignment_from_view) -// { -// Text text; -// -// text = View(STR("Hello World")); -// -// bool is_equal = Equal(TextSTD(STR("Hello World")), text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_begin) -// { -// Text text(initial_text.c_str()); -// const Text constText(initial_text.c_str()); -// -// CHECK_EQUAL(&text[0], text.begin()); -// CHECK_EQUAL(&constText[0], constText.begin()); -// } -// -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_end) -// { -// Text text(initial_text.c_str()); -// const Text constText(initial_text.c_str()); -// -// CHECK_EQUAL(&text[initial_text.size()], text.end()); -// CHECK_EQUAL(&constText[initial_text.size()], constText.end()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_up) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 8UL; -// -// Text text(initial_text.c_str(), INITIAL_SIZE); -// text.resize(NEW_SIZE); -// -// CHECK_EQUAL(text.size(), NEW_SIZE); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_up_value) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 8UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// Text text(INITIAL_SIZE, INITIAL_VALUE); -// text.resize(NEW_SIZE, INITIAL_VALUE); -// -// std::array compare_text; -// compare_text.fill(INITIAL_VALUE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_excess) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = SIZE + 1UL; -// -// Text text(INITIAL_SIZE, STR('A')); -// text.resize(NEW_SIZE, STR('A')); -// CHECK_EQUAL(SIZE, text.size()); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_down) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 2UL; -// -// Text text(INITIAL_SIZE, STR('A')); -// text.resize(NEW_SIZE); -// -// CHECK_EQUAL(text.size(), NEW_SIZE); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_down_value) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 2UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// Text text(INITIAL_SIZE, INITIAL_VALUE); -// text.resize(NEW_SIZE, INITIAL_VALUE); -// -// CHECK_EQUAL(text.size(), NEW_SIZE); -// -// std::array compare_text; -// compare_text.fill(INITIAL_VALUE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 8UL; -// const value_t INITIAL_VALUE = STR('A'); -// const value_t FILL_VALUE = STR('B'); -// -// Text text(INITIAL_SIZE, INITIAL_VALUE); -// -// Text::pointer pbegin = &text.front(); -// Text::pointer pend = &text.back() + 1; -// Text::pointer pmax = pbegin + text.max_size(); -// -// // Fill free space with a pattern. -// std::fill(pend, pmax, FILL_VALUE); -// -// text.uninitialized_resize(NEW_SIZE); -// -// std::array compare_text; -// compare_text.fill(FILL_VALUE); -// std::fill(compare_text.begin(), compare_text.begin() + INITIAL_SIZE, INITIAL_VALUE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// CHECK_EQUAL(NEW_SIZE, text.size()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = SIZE + 1UL; -// -// Text text(INITIAL_SIZE, STR('A')); -// -// text.uninitialized_resize(NEW_SIZE); -// -// CHECK_EQUAL(SIZE, text.size()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 2UL; -// const value_t INITIAL_VALUE = STR('A'); -// const value_t FILL_VALUE = STR('B'); -// -// Text text(INITIAL_SIZE, INITIAL_VALUE); -// -// Text::pointer pbegin = &text.front(); -// Text::pointer pend = &text.back() + 1; -// Text::pointer pmax = pbegin + text.max_size(); -// -// // Fill free space with a pattern. -// std::fill(pend, pmax, FILL_VALUE); -// -// text.uninitialized_resize(NEW_SIZE); -// -// std::array compare_text; -// compare_text.fill(INITIAL_VALUE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// CHECK_EQUAL(NEW_SIZE, text.size()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 8UL; -// -// Text text(initial_text.c_str(), INITIAL_SIZE); -// -// // Overwrite from index 1 to one less than the new size and set to that size. -// text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept -// { -// size_t i = 1; -// while (i < (n - 1)) -// { -// p[i] = '1' + Text::value_type(i); -// ++i; -// } -// -// return i; -// }); -// -// CHECK_EQUAL(NEW_SIZE - 1, text.size()); -// CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) -// { -// const size_t INITIAL_SIZE = 5UL; -// const size_t NEW_SIZE = 3UL; -// -// Text text(initial_text.c_str(), INITIAL_SIZE); -// -// // Overwrite from index 1 to one less than the new size and set to that size. -// text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) -// { -// size_t i = 1; -// while (i < (n - 1)) -// { -// p[i] = '1' + Text::value_type(i); -// ++i; -// } -// -// return i; -// }); -// -// CHECK_EQUAL(NEW_SIZE - 1, text.size()); -// CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) -// { -// Text text(initial_text.c_str(), initial_text.size()); -// -// CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_fill) -// { -// Text text(SIZE, STR('A')); -// Text expected(SIZE, STR('B')); -// -// text.fill(STR('B')); -// -// bool is_equal = Equal(expected, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_empty_full) -// { -// Text text; -// text.resize(text.max_size(), STR('A')); -// -// CHECK(!text.empty()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_empty_half) -// { -// Text text; -// text.resize(text.max_size() / 2, STR('A')); -// -// CHECK(!text.empty()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_empty_empty) -// { -// Text text; -// -// CHECK(text.empty()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_full_full) -// { -// Text text; -// text.resize(text.max_size(), STR('A')); -// -// CHECK(text.full()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_full_half) -// { -// Text text; -// text.resize(text.max_size() / 2, STR('A')); -// -// CHECK(!text.full()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_full_empty) -// { -// Text text; -// -// CHECK(!text.full()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_index) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// for (size_t i = 0UL; i < text.size(); ++i) -// { -// CHECK_EQUAL(text[i], compare_text[i]); -// } -// -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_index_const) -// { -// const TextSTD compare_text(initial_text.c_str()); -// const Text text(initial_text.c_str()); -// -// for (size_t i = 0UL; i < text.size(); ++i) -// { -// CHECK_EQUAL(text[i], compare_text[i]); -// } -// -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_at) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// for (size_t i = 0UL; i < text.size(); ++i) -// { -// CHECK_EQUAL(text.at(i), compare_text.at(i)); -// } -// -// CHECK_FALSE(text.is_truncated()); -// CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_at_const) -// { -// const TextSTD compare_text(initial_text.c_str()); -// const Text text(initial_text.c_str()); -// -// for (size_t i = 0UL; i < text.size(); ++i) -// { -// CHECK_EQUAL(text.at(i), compare_text.at(i)); -// } -// -// CHECK_FALSE(text.is_truncated()); -// CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_front) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// CHECK(text.front() == compare_text.front()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_front_const) -// { -// const TextSTD compare_text(initial_text.c_str()); -// const Text text(initial_text.c_str()); -// -// CHECK(text.front() == compare_text.front()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_back) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// CHECK(text.back() == compare_text.back()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_back_const) -// { -// const TextSTD compare_text(initial_text.c_str()); -// const Text text(initial_text.c_str()); -// -// CHECK(text.back() == compare_text.back()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_data) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text(compare_text.begin(), compare_text.end()); -// -// bool is_equal = std::equal(text.data(), -// text.data_end(), -// compare_text.begin()); -// -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_data_const) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// const Text text(compare_text.begin(), compare_text.end()); -// -// bool is_equal = std::equal(text.data(), -// text.data_end(), -// compare_text.begin()); -// -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_string) -// { -// TextSTD compare_input(initial_text.c_str()); -// Text input(initial_text.c_str()); -// -// TextSTD compare_text; -// Text text; -// -// compare_text.assign(compare_input); -// text.assign(input); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_self_assign_string) -// { -// Text text(initial_text.c_str()); -// -// text.assign(text); -// -// bool is_equal = Equal(initial_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_view) -// { -// TextSTD compare_input(initial_text.c_str()); -// Text input(initial_text.c_str()); -// View view(input); -// -// TextSTD compare_text; -// Text text; -// -// compare_text.assign(compare_input); -// text.assign(view); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_string_excess) -// { -// TextSTD compare_input(initial_text.c_str()); -// TextL input(longer_text.c_str()); -// -// TextSTD compare_text; -// Text text; -// -// compare_text.assign(compare_input); -// text.assign(input); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_pointer) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text; -// text.assign(initial_text.c_str()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text; -// text.assign(longer_text.c_str()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_pointer_length) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text; -// text.assign(initial_text.c_str(), initial_text.size()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) -// { -// TextSTD compare_text(longer_text.c_str()); -// -// Text text; -// text.assign(longer_text.c_str(), longer_text.size()); -// -// compare_text.resize(text.max_size()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_range) -// { -// TextSTD compare_text(initial_text.c_str()); -// -// Text text; -// -// text.assign(compare_text.begin(), compare_text.end()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_range_excess) -// { -// Text text; -// -// text.assign(longer_text.begin(), longer_text.end()); -// -// CHECK_EQUAL(initial_text.size(), text.size()); -// -// bool is_equal = Equal(initial_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_size_value) -// { -// const size_t INITIAL_SIZE = 5UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// std::array compare_text; -// compare_text.fill(INITIAL_VALUE); -// -// Text text; -// text.assign(INITIAL_SIZE, INITIAL_VALUE); -// -// CHECK(text.size() == INITIAL_SIZE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_assign_size_value_excess) -// { -// const size_t INITIAL_SIZE = SIZE; -// const size_t EXCESS_SIZE = SIZE + 1UL; -// const value_t INITIAL_VALUE = STR('A'); -// std::array compare_text; -// compare_text.fill(INITIAL_VALUE); -// -// Text text; -// text.assign(EXCESS_SIZE, INITIAL_VALUE); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_push_back) -// { -// TextSTD compare_text; -// Text text; -// -// for (size_t i = 0UL; i < SIZE; ++i) -// { -// compare_text.push_back(STR('A') + value_t(i)); -// } -// -// for (size_t i = 0UL; i < SIZE; ++i) -// { -// text.push_back(STR('A') + value_t(i)); -// } -// -// CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); -// CHECK_EQUAL(compare_text.size(), text.size()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_push_back_excess) -// { -// TextSTD compare_text; -// Text text; -// -// for (size_t i = 0UL; i < SIZE; ++i) -// { -// compare_text.push_back(STR('A') + value_t(i)); -// } -// -// for (size_t i = 0UL; i < SIZE; ++i) -// { -// text.push_back(STR('A') + value_t(i)); -// CHECK_FALSE(text.is_truncated()); -// } -// -// text.push_back(STR('A') + value_t(SIZE)); -// -// CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); -// CHECK_EQUAL(compare_text.size(), text.size()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_pop_back) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// compare_text.pop_back(); -// compare_text.pop_back(); -// -// text.pop_back(); -// text.pop_back(); -// -// CHECK_EQUAL(compare_text.size(), text.size()); -// -// bool is_equal = Equal(compare_text, text); -// -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_value) -// { -// const size_t INITIAL_SIZE = 5UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) -// { -// TextSTD compare_text; -// Text text; -// -// text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); -// compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); -// -// text.insert(text.begin() + offset, INITIAL_VALUE); -// compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); -// -// CHECK_EQUAL(compare_text.size(), text.size()); -// -// bool is_equal = Equal(compare_text, text); -// -// CHECK(is_equal); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) -// { -// TextSTD compare_text(initial_text.begin(), initial_text.end()); -// Text text(initial_text.begin(), initial_text.end()); -// -// const value_t INITIAL_VALUE = STR('A'); -// -// size_t offset = 2UL; -// text.insert(text.cbegin() + offset, INITIAL_VALUE); -// compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); -// compare_text.erase(compare_text.cend() - 1); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = 0; -// text.insert(text.cbegin() + offset, STR('A')); -// compare_text.insert(compare_text.cbegin() + offset, STR('A')); -// compare_text.erase(compare_text.cend() - 1); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = text.size(); -// text.insert(text.cbegin() + offset, STR('A')); -// compare_text.insert(compare_text.cbegin() + offset, STR('A')); -// compare_text.erase(compare_text.cend() - 1); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_n_value) -// { -// TextSTD compare_text; -// Text text; -// -// const size_t INITIAL_SIZE = 5UL; -// const size_t INSERT_SIZE = 3UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) -// { -// text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); -// compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); -// text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -// compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -// -// CHECK_FALSE(text.is_truncated()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) -// { -// TextSTD compare_text; -// Text text; -// -// const size_t INSERT_SIZE = 4UL; -// const value_t INSERT_VALUE = STR('A'); -// -// size_t offset = 0UL; -// compare_text.assign(initial_text.cbegin(), initial_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); -// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = 2; -// compare_text.assign(initial_text.cbegin(), initial_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = 4; -// compare_text.assign(initial_text.cbegin(), initial_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = text.size(); -// compare_text.assign(initial_text.cbegin(), initial_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); -// text.assign(initial_text.cbegin(), initial_text.cend()); -// text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_range) -// { -// const size_t INITIAL_SIZE = 5UL; -// -// for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) -// { -// TextSTD compare_text; -// Text text; -// -// text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); -// compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); -// text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -// compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -// -// CHECK_FALSE(text.is_truncated()); -//# -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) -// { -// const size_t INITIAL_SIZE = 5UL; -// const value_t INITIAL_VALUE = STR('A'); -// -// TextSTD compare_text; -// Text text; -// -// size_t offset = 0UL; -// -// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); -// text.assign(INITIAL_SIZE, INITIAL_VALUE); -// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// compare_text.resize(initial_text.size()); -// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// offset = 2; -// -// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); -// text.assign(INITIAL_SIZE, INITIAL_VALUE); -// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// compare_text.resize(initial_text.size()); -// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// -// -// offset = 4; -// -// compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); -// text.assign(INITIAL_SIZE, INITIAL_VALUE); -// compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// compare_text.resize(initial_text.size()); -// text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// CHECK_EQUAL(compare_text.size(), text.size()); -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_position_range_self) -// { -// size_t length = TextL::MAX_SIZE / 2UL; -// -// for (size_t offset = 10UL; offset < length; ++offset) -// { -// TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); -// TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); -// -// text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); -// compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) -// { -// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) -// { -// TextSTD compare_text(short_text.cbegin(), short_text.cend()); -// Text text(short_text.cbegin(), short_text.cend()); -// Text insert(insert_text.cbegin(), insert_text.cend()); -// -// text.insert(offset, insert); -// compare_text.insert(offset, insert_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) -// { -// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) -// { -// TextSTD compare_text(short_text.cbegin(), short_text.cend()); -// Text text(short_text.cbegin(), short_text.cend()); -// View view(insert_text.data(), insert_text.size()); -// -// text.insert(offset, view); -// compare_text.insert(offset, insert_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) -// { -// for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) -// { -// TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); -// Text text(initial_text.cbegin(), initial_text.cend()); -// Text insert(insert_text.cbegin(), insert_text.cend()); -// -// text.insert(offset, insert); -// compare_text.insert(offset, insert_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) -// { -// for (size_t offset = 0UL; offset <= short_text.size(); ++offset) -// { -// TextSTD compare_text(short_text.cbegin(), short_text.cend()); -// Text text(short_text.cbegin(), short_text.cend()); -// Text insert(longer_text.cbegin(), longer_text.cend()); -// insert.erase(insert.cbegin(), insert.cend()); -// insert.append(insert_text.cbegin(), insert_text.cend()); -// -// text.insert(offset, insert); -// compare_text.insert(offset, insert_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) -// { -// TextSTD compare_text(short_text.cbegin(), short_text.cend()); -// Text text(short_text.cbegin(), short_text.cend()); -// Text insert(insert_text.cbegin(), insert_text.cend()); -// -// text.insert(0, insert, 0, insert.size()); -// compare_text.insert(0, insert_text, 0, insert_text.size()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// -// compare_text.assign(short_text.cbegin(), short_text.cend()); -// text.assign(short_text.cbegin(), short_text.cend()); -// -// text.insert(2, insert, 2, insert.size() - 2); -// compare_text.insert(2, insert_text, 2, insert_text.size() - 2); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// CHECK_EQUAL(compare_text.size(), text.size()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// -// compare_text.assign(short_text.cbegin(), short_text.cend()); -// text.assign(short_text.cbegin(), short_text.cend()); -// -// text.insert(short_text.size(), insert, 0, insert.size()); -// compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_string) -// { -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// Text append(insert_text.c_str()); -// -// // Non-overflow. -// compare_text.append(insert_text); -// text.append(append); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// append.assign(initial_text.c_str()); -// -// compare_text.append(initial_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(append); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_view) -// { -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// View view(insert_text.data(), insert_text.size()); -// -// // Non-overflow. -// compare_text.append(insert_text); -// text.append(view); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -// CHECK_FALSE(text.is_truncated()); -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// view.assign(initial_text.data(), initial_text.size()); -// -// compare_text.append(initial_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(view); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_truncated_string) -// { -////#include "etl/private/diagnostic_array_bounds_push.h" -// Text text(short_text.c_str()); -// TextS append(short_text.c_str()); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK(append.is_truncated()); -//#endif -// -// text.append(append); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -////#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_string_to_self) -// { -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// // Non-overflow. -// compare_text.append(compare_text); -// text.append(text); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(shorter_text.c_str()); -// text.assign(shorter_text.c_str()); -// -// compare_text.append(compare_text); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(text); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) -// { -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// Text append(insert_text.c_str()); -// -// // Whole string. -// compare_text.append(insert_text, 0, TextSTD::npos); -// text.append(append, 0, Text::npos); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Partial string. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// append.assign(initial_text.c_str()); -// -// compare_text.append(short_text, 1, 3); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(append, 1, 3); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// append.assign(initial_text.c_str()); -// -// compare_text.append(initial_text, 1, initial_text.size() - 1); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(append, 1, append.size() - 1); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_truncated_string_subpos_sublen) -// { -// Text text(short_text.c_str()); -// TextS append(short_text.c_str()); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK(append.is_truncated()); -//#endif -// -// text.append(append, 1, 2); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_c_string) -// { -// // Non-overflow. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// // Whole string. -// compare_text.append(insert_text.c_str()); -// text.append(insert_text.c_str()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.append(initial_text.c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(initial_text.c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_n_c) -// { -// // Non-overflow. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// // Non-overflow. -// compare_text.append(5, STR('A')); -// text.append(5, STR('A')); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.append(SIZE, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(SIZE, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_append_range) -// { -// // Non-overflow. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// Text append(insert_text.c_str()); -// -// compare_text.append(insert_text.begin(), insert_text.end()); -// text.append(append.begin(), append.end()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// append.assign(initial_text.c_str()); -// -// compare_text.append(initial_text.begin(), initial_text.end()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.append(append.begin(), append.end()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_string) -// { -// // Non-overflow short text, npos. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace"))); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, TextL(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, TextL(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_view) -// { -// // Non-overflow short text, npos. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace"))); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, View(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, View(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 2, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_string) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_view) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace")), 1, 5); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, TextL(STR("Replace")), 1, 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, View(STR("Replace")), 1, 5); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, View(STR("Replace with some text")), 1, 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, View(STR("Replace")), 1, 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, View(STR("Replace with some text")), 1, 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace")).c_str()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, TextL(STR("Replace")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -//#include "etl/private/diagnostic_array_bounds_push.h" -//#include "etl/private/diagnostic_stringop_overread_push.h" -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -//#include "etl/private/diagnostic_pop.h" -//#include "etl/private/diagnostic_pop.h" -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -//#include "etl/private/diagnostic_array_bounds_push.h" -//#include "etl/private/diagnostic_stringop_overread_push.h" -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -//#include "etl/private/diagnostic_pop.h" -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(2, 4, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, 7, STR('A')); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, 7, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, 4, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text, npos. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 7, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 7, 7, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, 7, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, 4, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, 4, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow, npos. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(2, TextSTD::npos, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(2, Text::npos, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) -// { -// // Non-overflow short text. -// TextSTD compare_text(short_text.c_str()); -// Text text(short_text.c_str()); -// -// TextSTD replace(STR("Replace")); -// TextSTD replace_long(STR("Replace with some text")); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, replace.begin() + 1, replace.begin() + 5); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow short text. -// compare_text.assign(short_text.c_str()); -// text.assign(short_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Non-overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 7, replace.begin() + 1, replace.begin() + 5); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 7, replace_long.begin() + 1, replace_long.begin() + 5); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// // Overflow. -// compare_text.assign(initial_text.c_str()); -// text.assign(initial_text.c_str()); -// -// compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); -// compare_text.resize(std::min(compare_text.size(), SIZE)); -// text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15); -// -// is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_erase_single_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); -// Text::iterator ditr = text.erase(text.begin() + 2); -// CHECK(*citr == *ditr); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); -// Text::iterator ditr = text.erase(text.cbegin() + 2); -// CHECK(*citr == *ditr); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_erase_range) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); -// Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); -// CHECK(*citr == *ditr); -// -// bool is_equal = Equal(compare_text, text); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_clear) -// { -// Text text(initial_text.c_str()); -// text.clear(); -// -// CHECK_EQUAL(text.size(), size_t(0)); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_const_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_reverse_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); -// CHECK(is_equal); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_equal) -// { -// const Text initial1(initial_text.c_str()); -// const Text initial2(initial_text.c_str()); -// -// CHECK(initial1 == initial2); -// -// const Text different(different_text.c_str()); -// -// CHECK(!(initial1 == different)); -// -// const Text shorter(shorter_text.c_str()); -// -// CHECK(!(shorter == initial1)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_not_equal) -// { -// const Text initial1(initial_text.c_str()); -// const Text initial2(initial_text.c_str()); -// -// CHECK(!(initial1 != initial2)); -// -// const Text different(different_text.begin(), different_text.end()); -// -// CHECK(initial1 != different); -// -// const Text shorter(shorter_text.begin(), shorter_text.end()); -// -// CHECK(shorter != initial1); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_less_than) -// { -// const Text less(less_text.c_str()); -// const Text initial(initial_text.c_str()); -// -// // String-String -// CHECK((less < initial) == (less_text < initial_text)); -// CHECK((initial < less) == (initial_text < less_text)); -// -// const Text greater(greater_text.c_str()); -// CHECK((greater < initial) == (greater_text < initial_text)); -// CHECK((initial < greater) == (initial_text < greater_text)); -// -// const Text shorter(shorter_text.c_str()); -// CHECK((shorter < initial) == (shorter_text < initial_text)); -// CHECK((initial < shorter) == (initial_text < shorter_text)); -// -// CHECK((initial < initial) == (initial_text < initial_text)); -// CHECK((initial < initial) == (initial_text < initial_text)); -// -// // String-Pointer Pointer-String -// CHECK((less < pinitial_text) == (less_text < pinitial_text)); -// CHECK((pinitial_text < less) == (pinitial_text < less_text)); -// -// CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); -// CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); -// -// CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); -// CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); -// -// CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); -// CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_less_than_or_equal) -// { -// const Text less(less_text.c_str()); -// const Text initial(initial_text.c_str()); -// -// // String-String -// CHECK((less <= initial) == (less_text <= initial_text)); -// CHECK((initial <= less) == (initial_text <= less_text)); -// -// const Text greater(greater_text.c_str()); -// CHECK((greater <= initial) == (greater_text <= initial_text)); -// CHECK((initial <= greater) == (initial_text <= greater_text)); -// -// const Text shorter(shorter_text.c_str()); -// CHECK((shorter <= initial) == (shorter_text <= initial_text)); -// CHECK((initial <= shorter) == (initial_text <= shorter_text)); -// -// CHECK((initial <= initial) == (initial_text <= initial_text)); -// CHECK((initial <= initial) == (initial_text <= initial_text)); -// -// // String-Pointer Pointer-String -// CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); -// CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); -// -// CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); -// CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); -// -// CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); -// CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); -// -// CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); -// CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_greater_than) -// { -// const Text less(less_text.c_str()); -// const Text initial(initial_text.c_str()); -// -// // String-String -// CHECK((less > initial) == (less_text > initial_text)); -// CHECK((initial > less) == (initial_text > less_text)); -// -// const Text greater(greater_text.c_str()); -// CHECK((greater > initial) == (greater_text > initial_text)); -// CHECK((initial > greater) == (initial_text > greater_text)); -// -// const Text shorter(shorter_text.c_str()); -// CHECK((shorter > initial) == (shorter_text > initial_text)); -// CHECK((initial > shorter) == (initial_text > shorter_text)); -// -// CHECK((initial > initial) == (initial_text > initial_text)); -// CHECK((initial > initial) == (initial_text > initial_text)); -// -// // String-Pointer Pointer-String -// CHECK((less > pinitial_text) == (less_text > pinitial_text)); -// CHECK((pinitial_text > less) == (pinitial_text > less_text)); -// -// CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); -// CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); -// -// CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); -// CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); -// -// CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); -// CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_greater_than_or_equal) -// { -// const Text less(less_text.begin(), less_text.end()); -// const Text initial(initial_text.begin(), initial_text.end()); -// -// // String-String -// CHECK((less >= initial) == (less_text >= initial_text)); -// CHECK((initial >= less) == (initial_text >= less_text)); -// -// const Text greater(greater_text.begin(), greater_text.end()); -// CHECK((greater >= initial) == (greater_text >= initial_text)); -// CHECK((initial >= greater) == (initial_text >= greater_text)); -// -// const Text shorter(shorter_text.begin(), shorter_text.end()); -// CHECK((shorter >= initial) == (shorter_text >= initial_text)); -// CHECK((initial >= shorter) == (initial_text > shorter_text)); -// -// CHECK((initial >= initial) == (initial_text >= initial_text)); -// CHECK((initial >= initial) == (initial_text >= initial_text)); -// -// // String-Pointer Pointer-String -// CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); -// CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); -// -// CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); -// CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); -// -// CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); -// CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); -// -// CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); -// CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// value_t buffer1[SIZE]; -// value_t buffer2[SIZE]; -// -// size_t length1 = compare_text.copy(buffer1, 5, 2); -// buffer1[length1] = STR('\0'); -// -// size_t length2 = text.copy(buffer2, 5, 2); -// buffer2[length2] = STR('\0'); -// -// CHECK_EQUAL(length1, length2); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = std::equal(buffer1, -// buffer1 + length1, -// buffer2); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_start_pos_too_large) -// { -// Text text(initial_text.c_str()); -// -// value_t buffer1[SIZE]; -// -// size_t length1 = text.copy(buffer1, 5, SIZE); -// -// CHECK_EQUAL(0U, length1); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// value_t buffer1[SIZE]; -// value_t buffer2[SIZE]; -// -// size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); -// buffer1[length1] = STR('\0'); -// -// size_t length2 = text.copy(buffer2, Text::npos, 2); -// buffer2[length2] = STR('\0'); -// -// CHECK_EQUAL(length1, length2); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = std::equal(buffer1, -// buffer1 + length1, -// buffer2); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_copy_count_too_large) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// value_t buffer1[SIZE]; -// value_t buffer2[SIZE]; -// -// size_t length1 = compare_text.copy(buffer1, SIZE, 2); -// buffer1[length1] = STR('\0'); -// -// size_t length2 = text.copy(buffer2, SIZE, 2); -// buffer2[length2] = STR('\0'); -// -// CHECK_EQUAL(length1, length2); -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// -// bool is_equal = std::equal(buffer1, -// buffer1 + length1, -// buffer2); -// CHECK(is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_string) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_needle(STR("needle")); -// Text needle(STR("needle")); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = 0UL; -// size_t position2 = 0UL; -// -// position1 = compare_haystack.find(compare_needle, position1); -// position2 = haystack.find(needle, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.find(compare_needle, position1 + 1); -// position2 = haystack.find(needle, position2 + 1); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.find(needle, position2 + 1); -// CHECK_EQUAL(Text::npos, position2); -// -// Text pin(STR("pin")); -// position2 = haystack.find(pin); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_view) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_needle(STR("needle")); -// Text needle(STR("needle")); -// View needle_view(needle); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = 0UL; -// size_t position2 = 0UL; -// -// position1 = compare_haystack.find(compare_needle, position1); -// position2 = haystack.find(needle_view, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.find(compare_needle, position1 + 1); -// position2 = haystack.find(needle_view, position2 + 1); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.find(needle_view, position2 + 1); -// CHECK_EQUAL(Text::npos, position2); -// -// View pin_view(STR("pin")); -// position2 = haystack.find(pin_view); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_pointer) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// const value_t* needle = STR("needle"); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = 0UL; -// size_t position2 = 0UL; -// -// position1 = compare_haystack.find(needle, position1); -// position2 = haystack.find(needle, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.find(needle, position1 + 1); -// position2 = haystack.find(needle, position2 + 1); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.find(needle, position2 + 1); -// CHECK_EQUAL(TextL::npos, position2); -// -// const value_t *pin = STR("pin"); -// position2 = haystack.find(pin); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// const value_t* needle = STR("needle"); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = 0UL; -// size_t position2 = 0UL; -// -// position1 = compare_haystack.find(needle, position1, 3); -// position2 = haystack.find(needle, position2, 3); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.find(needle, position1 + 1, 3); -// position2 = haystack.find(needle, position2 + 1, 3); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.find(needle, position2 + 1, 3); -// CHECK_EQUAL(TextL::npos, position2); -// -// const value_t *pin = STR("pin"); -// position2 = haystack.find(pin, 0, 3); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_contains_string) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// Text needle(STR("needle")); -// Text pin(STR("pin")); -// Text excess(STR("A really gigantic pin or needle that's really really big")); -// -// CHECK_TRUE(haystack.contains(needle)); -// CHECK_FALSE(haystack.contains(pin)); -// CHECK_FALSE(haystack.contains(excess)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_contains_view) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.contains(View(STR("needle")))); -// CHECK_FALSE(haystack.contains(View(STR("pin")))); -// CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_contains_pointer) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.contains(STR("needle"))); -// CHECK_FALSE(haystack.contains(STR("pin"))); -// CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_contains_char) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.contains(STR('l'))); -// CHECK_FALSE(haystack.contains(STR('p'))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_starts_with_string) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// Text start(STR("A haystack")); -// Text not_start(STR("a needle")); -// Text excess(STR("Really gigantic text that's really really big")); -// -// CHECK_TRUE(haystack.starts_with(start)); -// CHECK_FALSE(haystack.starts_with(not_start)); -// CHECK_FALSE(haystack.starts_with(excess)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_starts_with_view) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); -// CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); -// CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_starts_with_pointer) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.starts_with(STR("A haystack"))); -// CHECK_FALSE(haystack.starts_with(STR("a needle"))); -// CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_starts_with_char) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.starts_with(haystack[0])); -// CHECK_FALSE(haystack.starts_with(haystack[1])); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_ends_with_string) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// Text end(STR("else")); -// Text not_end(STR("needle")); -// Text excess(STR("Really gigantic text that's really really big")); -// -// CHECK_TRUE(haystack.ends_with(end)); -// CHECK_FALSE(haystack.ends_with(not_end)); -// CHECK_FALSE(haystack.ends_with(excess)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_ends_with_view) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.ends_with(View(STR("else")))); -// CHECK_FALSE(haystack.ends_with(View(STR("needle")))); -// CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_ends_with_pointer) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.ends_with(STR("else"))); -// CHECK_FALSE(haystack.ends_with(STR("needle"))); -// CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_ends_with_char) -// { -// TextL haystack(STR("A haystack with a needle and nothing else")); -// -// CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); -// CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_rfind_string) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_needle(STR("needle")); -// Text needle(STR("needle")); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = TextSTD::npos; -// size_t position2 = Text::npos; -// -// position1 = compare_haystack.rfind(compare_needle, position1); -// position2 = haystack.rfind(needle, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); -// position2 = haystack.rfind(needle, haystack.size() - 10); -// CHECK_EQUAL(position1, position2); -// -// Text pin(STR("pin")); -// position2 = haystack.rfind(pin); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_rfind_view) -// { -// const value_t* the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_needle(STR("needle")); -// Text needle(STR("needle")); -// View needle_view(needle); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// size_t position1 = TextSTD::npos; -// size_t position2 = Text::npos; -// -// position1 = compare_haystack.rfind(compare_needle, position1); -// position2 = haystack.rfind(needle_view, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); -// position2 = haystack.rfind(needle_view, haystack.size() - 10); -// CHECK_EQUAL(position1, position2); -// -// View pin_view(STR("pin")); -// position2 = haystack.rfind(pin_view); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_rfind_pointer) -// { -// const value_t*the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// const value_t* needle = STR("needle"); -// -// size_t position1 = TextSTD::npos; -// size_t position2 = Text::npos; -// -// position1 = compare_haystack.rfind(needle, position1); -// position2 = haystack.rfind(needle, position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10); -// position2 = haystack.rfind(needle, haystack.size() - 10); -// CHECK_EQUAL(position1, position2); -// -// Text pin(STR("pin")); -// position2 = haystack.rfind(pin); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) -// { -// const value_t*the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// const value_t* needle = STR("needle"); -// -// size_t position1 = TextSTD::npos; -// size_t position2 = Text::npos; -// -// position1 = compare_haystack.rfind(needle, position1, 3); -// position2 = haystack.rfind(needle, position2, 3); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10, 3); -// position2 = haystack.rfind(needle, haystack.size() - 10, 3); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.rfind(STR("pin"), 3); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_rfind_c_position) -// { -// const value_t*the_haystack = STR("A haystack with a needle and another needle"); -// -// TextSTD compare_haystack(the_haystack); -// TextL haystack(the_haystack); -// -// etl::istring::size_type position1 = TextL::npos; -// size_t position2 = Text::npos; -// -// position1 = compare_haystack.rfind(STR('e'), position1); -// position2 = haystack.rfind(STR('e'), position2); -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); -// position2 = haystack.rfind(STR('e'), haystack.size() - 10); -// CHECK_EQUAL(position1, position2); -// -// position2 = haystack.rfind(STR('z')); -// CHECK_EQUAL(TextL::npos, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_substr) -// { -// TextSTD compare_text(initial_text.c_str()); -// Text text(initial_text.c_str()); -// -// TextSTD compare_result; -// Text result; -// -// // Equal. -// compare_result = compare_text.substr(compare_text.size()); -// result = text.substr(text.size()); -// CHECK(Equal(compare_result, result)); -// -// // Whole string. -// compare_result = compare_text.substr(); -// result = text.substr(); -// CHECK(Equal(compare_result, result)); -// -// // Starting from position 2. -// compare_result = compare_text.substr(2); -// result = text.substr(2); -// CHECK(Equal(compare_result, result)); -// -// // Starting from position 2 for 3 characters. -// compare_result = compare_text.substr(2, 3); -// result = text.substr(2, 3); -// CHECK(Equal(compare_result, result)); -// -// // Starting from position 2 for too many characters. -// compare_result = compare_text.substr(2, compare_text.size()); -// result = text.substr(2, text.size()); -// CHECK(Equal(compare_result, result)); -// -// // Starting from beyond the end of the string. -// CHECK_THROW(text.substr(text.size() + 1), etl::string_out_of_bounds); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_string) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); -// result = text.compare(Text(STR("ABCDEF"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); -// result = text.compare(Text(STR("ABCDEE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); -// result = text.compare(Text(STR("ABCDEG"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); -// result = text.compare(Text(STR("ABCDE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); -// result = text.compare(Text(STR("ABCDEFG"))); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_view) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); -// result = text.compare(View(STR("ABCDEF"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); -// result = text.compare(View(STR("ABCDEE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); -// result = text.compare(View(STR("ABCDEG"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); -// result = text.compare(View(STR("ABCDE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); -// result = text.compare(View(STR("ABCDEFG"))); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_string) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); -// result = text.compare(3, 6, Text(STR("ABCDEF"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); -// result = text.compare(3, 6, Text(STR("ABCDEE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); -// result = text.compare(3, 6, Text(STR("ABCDEG"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); -// result = text.compare(3, 6, Text(STR("ABCDE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); -// result = text.compare(3, 6, Text(STR("ABCDEFG"))); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_view) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); -// result = text.compare(3, 6, View(STR("ABCDEF"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); -// result = text.compare(3, 6, View(STR("ABCDEE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); -// result = text.compare(3, 6, View(STR("ABCDEG"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); -// result = text.compare(3, 6, View(STR("ABCDE"))); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); -// result = text.compare(3, 6, View(STR("ABCDEFG"))); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); -// result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); -// result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); -// result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); -// result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); -// result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); -// result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); -// result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); -// result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); -// result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); -// result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_c_string) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(STR("ABCDEF")); -// result = text.compare(STR("ABCDEF")); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(STR("ABCDEE")); -// result = text.compare(STR("ABCDEE")); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(STR("ABCDEG")); -// result = text.compare(STR("ABCDEG")); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(STR("ABCDE")); -// result = text.compare(STR("ABCDE")); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(STR("ABCDEFG")); -// result = text.compare(STR("ABCDEFG")); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, STR("ABCDEF")); -// result = text.compare(3, 6, STR("ABCDEF")); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, STR("ABCDEE")); -// result = text.compare(3, 6, STR("ABCDEE")); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, STR("ABCDEG")); -// result = text.compare(3, 6, STR("ABCDEG")); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, STR("ABCDE")); -// result = text.compare(3, 6, STR("ABCDE")); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, STR("ABCDEFG")); -// result = text.compare(3, 6, STR("ABCDEFG")); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) -// { -// TextSTD compare_text(STR("xxxABCDEFyyy")); -// Text text(STR("xxxABCDEFyyy")); -// -// int compare_result; -// int result; -// -// // Equal. -// compare_result = compare_text.compare(3, 6, STR("ABCDEFbb"), 6); -// result = text.compare(3, 6, STR("ABCDEFbb"), 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Less. -// compare_result = compare_text.compare(3, 6, STR("ABCDEEbb"), 6); -// result = text.compare(3, 6, STR("ABCDEEbb"), 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Greater. -// compare_result = compare_text.compare(3, 6, STR("ABCDEGbb"), 6); -// result = text.compare(3, 6, STR("ABCDEGbb"), 6); -// CHECK(compares_agree(compare_result, result)); -// -// // Shorter. -// compare_result = compare_text.compare(3, 6, STR("ABCDEbb"), 5); -// result = text.compare(3, 6, STR("ABCDEbb"), 5); -// CHECK(compares_agree(compare_result, result)); -// -// // Longer. -// compare_result = compare_text.compare(3, 6, STR("ABCDEFGbb"), 7); -// result = text.compare(3, 6, STR("ABCDEFGbb"), 7); -// CHECK(compares_agree(compare_result, result)); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); -// size_t position2 = text.find_first_of(Text(STR("ZCXF"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); -// position2 = text.find_first_of(Text(STR("WXYZ"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); -// position2 = text.find_first_of(Text(STR("ZCXF")), 3); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); -// position2 = text.find_first_of(Text(STR("ZCXF")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); -// size_t position2 = text.find_first_of(View(STR("ZCXF"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); -// position2 = text.find_first_of(View(STR("WXYZ"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); -// position2 = text.find_first_of(View(STR("ZCXF")), 3); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); -// position2 = text.find_first_of(View(STR("ZCXF")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_of(STR("ZCXF")); -// size_t position2 = text.find_first_of(STR("ZCXF")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR("WXYZ")); -// position2 = text.find_first_of(STR("WXYZ")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR("ZCXF"), 3); -// position2 = text.find_first_of(STR("ZCXF"), 3); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_of(STR("ZCXF"), 100); -// position2 = text.find_first_of(STR("ZCXF"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); -// size_t position2 = text.find_first_of(STR("ZCXF"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR("WXYZ"), 0, 4); -// position2 = text.find_first_of(STR("WXYZ"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR("ZCXF"), 1, 3); -// position2 = text.find_first_of(STR("ZCXF"), 1, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR("ZCXF"), 3, 3); -// position2 = text.find_first_of(STR("ZCXF"), 3, 3); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_of(STR("ZCXF"), 100); -// position2 = text.find_first_of(STR("ZCXF"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_of(STR('C')); -// size_t position2 = text.find_first_of(STR('C')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR('Z')); -// position2 = text.find_first_of(STR('Z')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR('F'), 3); -// position2 = text.find_first_of(STR('F'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR('C'), 3); -// position2 = text.find_first_of(STR('C'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_of(STR('C'), compare_text.size()); -// position2 = text.find_first_of(STR('C'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_of(STR('C'), 100); -// position2 = text.find_first_of(STR('C'), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); -// size_t position2 = text.find_last_of(Text(STR("ZCXE"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); -// position2 = text.find_last_of(Text(STR("WXYZ")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); -// position2 = text.find_last_of(Text(STR("ZCXE")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); -// position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); -// position2 = text.find_last_of(Text(STR("ZCXE")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); -// size_t position2 = text.find_last_of(View(STR("ZCXE"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); -// position2 = text.find_last_of(View(STR("WXYZ")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); -// position2 = text.find_last_of(View(STR("ZCXE")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); -// position2 = text.find_last_of(View(STR("ZCXE")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); -// position2 = text.find_last_of(View(STR("ZCXE")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_of(STR("ZCXE")); -// size_t position2 = text.find_last_of(STR("ZCXE")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("WXYZ"), 3); -// position2 = text.find_last_of(STR("WXYZ"), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), 5); -// position2 = text.find_last_of(STR("ZCXE"), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), 6); -// position2 = text.find_last_of(STR("ZCXE"), 6); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size()); -// position2 = text.find_last_of(STR("ZCXE"), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_of(STR("ZCXE"), 100); -// position2 = text.find_last_of(STR("ZCXE"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); -// size_t position2 = text.find_last_of(STR("AZCXE"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("WXYZ"), 4, 3); -// position2 = text.find_last_of(STR("WXYZ"), 4, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), 5, 3); -// position2 = text.find_last_of(STR("ZCXE"), 5, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), 1, 3); -// position2 = text.find_last_of(STR("ZCXE"), 1, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size(), 4); -// position2 = text.find_last_of(STR("ZCXE"), text.size(), 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); -// position2 = text.find_last_of(STR("ZCXE"), 100, 4); -// -// CHECK_EQUAL(position1, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_last_of(STR('C')); -// size_t position2 = text.find_last_of(STR('C')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR('Z')); -// position2 = text.find_last_of(STR('Z')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR('F'), compare_text.size()); -// position2 = text.find_last_of(STR('F'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR('C'), 3); -// position2 = text.find_last_of(STR('C'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_of(STR('C'), compare_text.size()); -// position2 = text.find_last_of(STR('C'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_of(STR('C'), 100); -// position2 = text.find_last_of(STR('C'), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); -// size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); -// position2 = text.find_first_not_of(Text(STR("ZAXB"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); -// position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); -// position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); -// position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); -// size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); -// position2 = text.find_first_not_of(View(STR("ZAXB"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); -// position2 = text.find_first_not_of(View(STR("ZAXB")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); -// position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); -// position2 = text.find_first_not_of(View(STR("ZAXB")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); -// size_t position2 = text.find_first_not_of(STR("ZAXB")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB")); -// position2 = text.find_first_not_of(STR("ZAXB")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 3); -// position2 = text.find_first_not_of(STR("ZAXB"), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), compare_text.size()); -// position2 = text.find_first_not_of(STR("ZAXB"), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 100); -// position2 = text.find_first_not_of(STR("ZAXB"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); -// size_t position2 = text.find_first_not_of(STR("ZAXB"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); -// position2 = text.find_first_not_of(STR("ZAXB"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 1, 3); -// position2 = text.find_first_not_of(STR("ZAXB"), 1, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 3, 3); -// position2 = text.find_first_not_of(STR("ZAXB"), 3, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR("ZAXB"), compare_text.size(), 3); -// position2 = text.find_first_not_of(STR("ZAXB"), text.size(), 3); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_not_of(STR("ZAXB"), 100); -// position2 = text.find_first_not_of(STR("ZAXB"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_first_not_of(STR('A')); -// size_t position2 = text.find_first_not_of(STR('A')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR('B')); -// position2 = text.find_first_not_of(STR('B')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR('C'), 3); -// position2 = text.find_first_not_of(STR('C'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR('D'), 3); -// position2 = text.find_first_not_of(STR('D'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_first_not_of(STR('C'), compare_text.size()); -// position2 = text.find_first_not_of(STR('C'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_first_not_of(STR('C'), 100); -// position2 = text.find_first_not_of(STR('C'), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); -// size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); -// size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); -// position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); -// size_t position2 = text.find_last_not_of(STR("ZEXD")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5); -// position2 = text.find_last_not_of(STR("ZEXD"), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size()); -// position2 = text.find_last_not_of(STR("ZEXD"), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100); -// position2 = text.find_last_not_of(STR("ZEXD"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); -// size_t position2 = text.find_last_not_of(STR("ZEXD"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5, 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 5, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 1, 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 1, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size(), 4); -// position2 = text.find_last_not_of(STR("ZEXD"), text.size(), 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100, 4); -// position2 = text.find_last_not_of(STR("ZEXD"), 100, 4); -// -// CHECK_EQUAL(position1, position2); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_last_not_of(STR('F')); -// size_t position2 = text.find_last_not_of(STR('F')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('Z')); -// position2 = text.find_last_not_of(STR('Z')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('A'), compare_text.size()); -// position2 = text.find_last_not_of(STR('A'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('C'), 3); -// position2 = text.find_last_not_of(STR('C'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('C'), compare_text.size()); -// position2 = text.find_last_not_of(STR('C'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(STR('C'), 100); -// position2 = text.find_last_not_of(STR('C'), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_hash) -// { -// // Test with actual string type. -// Text text(STR("ABCDEFHIJKL")); -// size_t hash = etl::hash()(text); -// size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); -// CHECK_EQUAL(compare_hash, hash); -// -// // Test with interface string type. -// IText& itext = text; -// hash = etl::hash()(itext); -// CHECK_EQUAL(compare_hash, hash); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_memcpy_repair) -// { -// Text text; -// -// text.assign(STR("ABCDEF")); -// -// char buffer[sizeof(Text)]; -// -// memcpy(&buffer, (const void*)&text, sizeof(text)); -// -// Text& rtext(*reinterpret_cast(buffer)); -// rtext.repair(); -// -// CHECK(!rtext.empty()); -// CHECK(!rtext.full()); -// -// bool is_equal = Equal(text, rtext); -// CHECK(is_equal); -// -// text = STR("GHIJKL"); -// is_equal = Equal(text, rtext); -// CHECK(!is_equal); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_memcpy_repair_virtual) -// { -// Text text; -// -// text.assign(STR("ABCDEF")); -// -// char buffer[sizeof(Text)]; -// -// memcpy(&buffer, (const void*)&text, sizeof(text)); -// -// IText& itext(*reinterpret_cast(buffer)); -// itext.repair(); -// -// CHECK(!itext.empty()); -// CHECK(!itext.full()); -// -// bool is_equal = Equal(text, itext); -// CHECK(is_equal); -// -// text = STR("GHIJKL"); -// is_equal = Equal(text, itext); -// CHECK(!is_equal); -// } -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) -// { -// Text text(short_text.c_str()); -// CHECK_FALSE(text.is_truncated()); -// -// text.insert(3, initial_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// while (text.size() != 0) -// { -// text.pop_back(); -// CHECK_TRUE(text.is_truncated()); -// } -// -// text.clear(); -// CHECK_FALSE(text.is_truncated()); -// -// text.assign(longer_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// text.assign(short_text.c_str()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_add_from_truncated) -// { -// Text text1(short_text.c_str()); -// TextS text2(short_text.c_str()); -// -// CHECK_FALSE(text1.is_truncated()); -// CHECK_TRUE(text2.is_truncated()); -// -// // text2 has the truncate flag set. -// text1 += text2; -// -// CHECK(text1.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_add_to_truncated) -// { -// Text text1(longer_text.c_str()); -// Text text2(short_text.c_str()); -// -// CHECK(text1.is_truncated()); -// CHECK_FALSE(text2.is_truncated()); -// -// // Clear text but not the truncate flag. -// text1.erase(text1.begin(), text1.end()); -// -// // text1 still has the truncate flag set. -// text1 += text2; -// -// CHECK(text1.is_truncated()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_clear_truncated) -// { -// Text text(longer_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// text.clear_truncated(); -// CHECK_FALSE(text.is_truncated()); -// } -//#endif -// -//#if ETL_HAS_STRING_CLEAR_AFTER_USE -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_destructor) -// { -// char buffer[sizeof(Text)]; -// std::fill_n(buffer, sizeof(Text), 0); -// ::new (buffer) Text(STR("ABCDEF")); -// -// Text& text = *reinterpret_cast(buffer); -// text.set_secure(); -// -// CHECK(Text(STR("ABCDEF")) == text); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// // Destroy the text object. -// std::atomic_signal_fence(std::memory_order_seq_cst); -// text.~Text(); -// std::atomic_signal_fence(std::memory_order_seq_cst); -// -// // Check there no non-zero values in the string. -// CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_assign) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pe = text.end(); -// -// text.assign(STR("ABC")); -// -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_resize_down) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pe = text.end(); -// -// text.resize(text.size() - 3U); -// -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_erase) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.erase(pb + 2, pb + 5); -// -// // Check there no non-zero values in the remainder of the string. -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_replace) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.replace(pb + 1, pb + 4, STR("G")); -// -// // Check there no non-zero values in the remainder of the string. -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_secure_after_clear) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.clear(); -// -// // 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 -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_initialize_free_space_empty_string) -// { -// Text empty; -// Text text; -// -// text.initialize_free_space(); -// -// CHECK(text.empty()); -// CHECK(text == empty); -// -// for (size_t i = text.size(); i < text.max_size(); ++i) -// { -// CHECK_EQUAL(0, text[i]); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_initialize_free_space_part_filled_string) -// { -// Text empty; -// Text initial = STR("ABC"); -// Text text(initial); -// -// text.initialize_free_space(); -// -// CHECK(text == initial); -// CHECK(text != empty); -// -// for (size_t i = text.size(); i < text.max_size(); ++i) -// { -// CHECK_EQUAL(0, text[i]); -// } -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_update_after_c_string_max_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size(), STR('A')); -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size(), text.size()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_update_after_c_string_shorter_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size() - 1, text.size()); -// } -// -// //************************************************************************* -// TEST_FIXTURE(SetupFixture, test_update_after_c_string_greater_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size(), text.size()); -// } -// -// //************************************************************************* -//#if ETL_USING_STL -// TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) -// { -// Text text1 = STR("Hello World"); -// -// std::stringstream sstream; -// -// sstream << text1; -// -// TextSTD sstream_string = sstream.str(); -// -// View sstream_view(sstream_string.data(), sstream_string.size()); -// -// CHECK(text1 == sstream_view); -// } -//#endif + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains) + { + static constexpr Text text("Hello World"); + + static constexpr auto text_contains_world = text.contains("World"); + CHECK_TRUE(text_contains_world); + + static constexpr auto text_contains_worls = text.contains("Worls"); + CHECK_FALSE(text_contains_worls); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_start_with_ends_with) + { + static constexpr Text text("Hello World"); + + static constexpr auto text_starts_with_hello = text.starts_with("Hello"); + CHECK_TRUE(text_starts_with_hello); + + static constexpr auto text_starts_with_world = text.starts_with("World"); + CHECK_FALSE(text_starts_with_world); + + static constexpr auto text_ends_with_hello = text.ends_with("Hello"); + CHECK_FALSE(text_ends_with_hello); + + static constexpr auto text_ends_with_world = text.ends_with("World"); + CHECK_TRUE(text_ends_with_world); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find) + { + static constexpr Text text("Hello World"); + + static constexpr auto text_find_world = text.find("World"); + CHECK_EQUAL(6, text_find_world); + + static constexpr auto text_find_worls = text.find("Worls"); + CHECK_EQUAL(Text::npos, text_find_worls); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of) + { + static constexpr Text text("Hello World"); + static constexpr auto text_find_first_of_o = text.find_first_of(STR('o'), 5); + CHECK_EQUAL(7, text_find_first_of_o); + + static constexpr auto text_find_first_of_s = text.find_first_of(STR('s'), 5); + CHECK_EQUAL(Text::npos, text_find_first_of_s); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of) + { + static constexpr Text text("Hello World"); + static constexpr auto text_find_first_not_of_l = text.find_first_not_of(STR('l'), 2); + CHECK_EQUAL(4, text_find_first_not_of_l); + + static constexpr auto text_find_first_not_of_s = text.find_first_not_of(STR('s'), 2); + CHECK_EQUAL(2, text_find_first_not_of_s); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of) + { + static constexpr Text text("Hello World"); + + static constexpr auto text_find_last_of_o = text.find_last_of(STR('o'), 9); + CHECK_EQUAL(7, text_find_last_of_o); + + static constexpr auto text_find_last_of_s = text.find_last_of(STR('s'), 9); + CHECK_EQUAL(Text::npos, text_find_last_of_s); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of) + { + static constexpr Text text("Hello World"); + + static constexpr auto text_find_last_not_of_l = text.find_last_not_of(STR('l'), 9); + CHECK_EQUAL(8, text_find_last_not_of_l); + + static constexpr auto text_find_last_not_of_s = text.find_last_not_of(STR('s'), 9); + CHECK_EQUAL(9, text_find_last_not_of_s); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_access_functions) + { + static constexpr const char* initial = "Hello World"; + static constexpr Text text(initial); + static constexpr size_t length = etl::strlen(initial); + + static constexpr auto text_index_operator = text[3]; + CHECK_EQUAL(initial[3], text_index_operator); + + static constexpr auto text_at = text.at(3); + CHECK_EQUAL(initial[3], text_at); + + static constexpr auto text_front = text.front(); + CHECK_EQUAL(initial[0], text_front); + + static constexpr auto text_back = text.back(); + CHECK_EQUAL(initial[length - 1], text_back); + + static constexpr const char* text_c_str = text.c_str(); + CHECK_EQUAL(&initial[0], text_c_str); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_functions) + { + static constexpr Text text("Hello World"); + } }; } diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index db94bfea..43705794 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -3689,6 +3689,9 @@ Tests\CRC + + Tests\Strings + From 6936551c9a47a3d3c519f88a092ea09a2fb733a6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 25 Jul 2025 18:13:35 +0100 Subject: [PATCH 5/8] Work in progress --- include/etl/const_string.h | 23 +++-------------- test/test_const_string_char.cpp | 46 +++++++++++++++++++++++++++++++++ test/vs2022/etl.vcxproj | 1 + test/vs2022/etl.vcxproj.filters | 3 +++ 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/include/etl/const_string.h b/include/etl/const_string.h index ab698d4e..4dbf576f 100644 --- a/include/etl/const_string.h +++ b/include/etl/const_string.h @@ -28,14 +28,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_STRING_INCLUDED -#define ETL_STRING_INCLUDED +#ifndef ETL_CONST_STRING_INCLUDED +#define ETL_CONST_STRING_INCLUDED #include "platform.h" -#include "basic_string.h" -#include "string_view.h" +#include "string.h" #include "hash.h" -#include "initializer_list.h" #include @@ -43,21 +41,6 @@ SOFTWARE. namespace etl { -#if ETL_USING_CPP11 - inline namespace literals - { - inline namespace string_literals - { - inline constexpr etl::string_view operator ""_sv(const char* str, size_t length) noexcept - { - return etl::string_view{ str, length }; - } - } - } -#endif - - typedef etl::ibasic_string istring; - //*************************************************************************** /// A string implementation that uses a fixed size external buffer. ///\ingroup string diff --git a/test/test_const_string_char.cpp b/test/test_const_string_char.cpp index a72d5d15..ceb7414f 100644 --- a/test/test_const_string_char.cpp +++ b/test/test_const_string_char.cpp @@ -280,6 +280,52 @@ namespace TEST_FIXTURE(SetupFixture, test_compare_functions) { static constexpr Text text("Hello World"); + static constexpr Text text_same("Hello World"); + static constexpr Text text_less("Hello Wnrld"); + static constexpr Text text_greater("Hello Wprld"); + static constexpr Text text_less_length("Hello Worl"); + static constexpr Text text_greater_length("Hello World!"); + + static constexpr auto text_compare_with_same = text.compare(text_same); + CHECK_EQUAL(0, text_compare_with_same); + + static constexpr auto text_compare_with_less = text.compare(text_less); + CHECK_EQUAL(1, text_compare_with_less); + + static constexpr auto text_compare_with_greater = text.compare(text_greater); + CHECK_EQUAL(-1, text_compare_with_greater); + + static constexpr auto text_compare_with_less_length = text.compare(text_less_length); + CHECK_EQUAL(1, text_compare_with_less_length); + + static constexpr auto text_compare_with_greater_length = text.compare(text_greater_length); + CHECK_EQUAL(-1, text_compare_with_greater_length); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_operators) + { + static constexpr Text text("Hello World"); + static constexpr Text text_same("Hello World"); + static constexpr Text text_less("Hello Wnrld"); + static constexpr Text text_greater("Hello Wprld"); + static constexpr Text text_less_length("Hello Worl"); + static constexpr Text text_greater_length("Hello World!"); + + //static constexpr bool text_compare_with_same = (text == text_same); + //CHECK_TRUE(text_compare_with_same); + + //static constexpr auto text_compare_with_less = text.compare(text_less); + //CHECK_EQUAL(1, text_compare_with_less); + + //static constexpr auto text_compare_with_greater = text.compare(text_greater); + //CHECK_EQUAL(-1, text_compare_with_greater); + + //static constexpr auto text_compare_with_less_length = text.compare(text_less_length); + //CHECK_EQUAL(1, text_compare_with_less_length); + + //static constexpr auto text_compare_with_greater_length = text.compare(text_greater_length); + //CHECK_EQUAL(-1, text_compare_with_greater_length); } }; } diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index e0fa728a..0e5888bb 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3297,6 +3297,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 43705794..a6ec09da 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1530,6 +1530,9 @@ UnitTest++\Header Files + + ETL\Strings + From 6874a347f752e1cb32a12080c37034c50cff74da Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 28 Jul 2025 14:48:09 +0100 Subject: [PATCH 6/8] Work in progress --- include/etl/basic_string.h | 38 +++--- test/test_const_string_char.cpp | 220 ++++++++++++++++++-------------- 2 files changed, 144 insertions(+), 114 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 9dd41c16..178a191e 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -2891,7 +2891,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator ==(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator ==(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) { return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin()); } @@ -2904,7 +2904,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator ==(const etl::ibasic_string& lhs, const T* rhs) + ETL_CONSTEXPR bool operator ==(const etl::ibasic_string& lhs, const T* rhs) { return (lhs.size() == etl::strlen(rhs)) && etl::equal(lhs.begin(), lhs.end(), rhs); } @@ -2917,7 +2917,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator ==(const T* lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator ==(const T* lhs, const etl::ibasic_string& rhs) { return (rhs.size() == etl::strlen(lhs)) && etl::equal(rhs.begin(), rhs.end(), lhs); } @@ -2930,7 +2930,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator !=(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator !=(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) { return !(lhs == rhs); } @@ -2943,7 +2943,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator !=(const etl::ibasic_string& lhs, const T* rhs) + ETL_CONSTEXPR bool operator !=(const etl::ibasic_string& lhs, const T* rhs) { return !(lhs == rhs); } @@ -2956,7 +2956,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator !=(const T* lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator !=(const T* lhs, const etl::ibasic_string& rhs) { return !(lhs == rhs); } @@ -2969,7 +2969,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator <(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator <(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) { return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } @@ -2982,7 +2982,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator <(const etl::ibasic_string& lhs, const T* rhs) + ETL_CONSTEXPR bool operator <(const etl::ibasic_string& lhs, const T* rhs) { return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs, rhs + etl::strlen(rhs)); } @@ -2995,7 +2995,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator <(const T* lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator <(const T* lhs, const etl::ibasic_string& rhs) { return etl::lexicographical_compare(lhs, lhs + etl::strlen(lhs), rhs.begin(), rhs.end()); } @@ -3009,7 +3009,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator >(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator >(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) { return (rhs < lhs); } @@ -3022,7 +3022,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator >(const etl::ibasic_string& lhs, const T* rhs) + ETL_CONSTEXPR bool operator >(const etl::ibasic_string& lhs, const T* rhs) { return (rhs < lhs); } @@ -3035,7 +3035,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator >(const T* lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator >(const T* lhs, const etl::ibasic_string& rhs) { return (rhs < lhs); } @@ -3049,7 +3049,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator <=(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator <=(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) { return !(lhs > rhs); } @@ -3062,7 +3062,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator <=(const etl::ibasic_string& lhs, const T* rhs) + ETL_CONSTEXPR bool operator <=(const etl::ibasic_string& lhs, const T* rhs) { return !(lhs > rhs); } @@ -3075,7 +3075,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator <=(const T* lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator <=(const T* lhs, const etl::ibasic_string& rhs) { return !(lhs > rhs); } @@ -3089,7 +3089,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator >=(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator >=(const etl::ibasic_string& lhs, const etl::ibasic_string& rhs) { return !(lhs < rhs); } @@ -3102,7 +3102,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator >=(const etl::ibasic_string& lhs, const T* rhs) + ETL_CONSTEXPR bool operator >=(const etl::ibasic_string& lhs, const T* rhs) { return !(lhs < rhs); } @@ -3115,7 +3115,7 @@ namespace etl ///\ingroup string //*************************************************************************** template - bool operator >=(const T* lhs, const etl::ibasic_string& rhs) + ETL_CONSTEXPR bool operator >=(const T* lhs, const etl::ibasic_string& rhs) { return !(lhs < rhs); } @@ -3138,8 +3138,6 @@ namespace etl #endif } -#undef ETL_USING_WCHAR_T_H - #include "private/minmax_pop.h" #endif diff --git a/test/test_const_string_char.cpp b/test/test_const_string_char.cpp index ceb7414f..4a6b209e 100644 --- a/test/test_const_string_char.cpp +++ b/test/test_const_string_char.cpp @@ -35,7 +35,6 @@ SOFTWARE. #include "etl/const_string.h" #include "etl/string_view.h" -#include "etl/fnv_1.h" #undef STR #define STR(x) x @@ -55,22 +54,27 @@ namespace using Text = etl::const_string; using IText = const etl::istring; - using TextSTD = std::string; using value_t = Text::value_type; - //using TextL = etl::string<52>; - //using TextS = etl::string<4>; - //using View = etl::string_view; - TextSTD initial_text; - TextSTD less_text; - TextSTD greater_text; - TextSTD shorter_text; - TextSTD different_text; - TextSTD insert_text; - TextSTD longer_text; - TextSTD short_text; + static constexpr const char* initial = STR("Hello World"); - const value_t* pinitial_text = STR("Hello World"); + static constexpr const char* ccp_hello = STR("Hello"); + static constexpr const char* ccp_world = STR("World"); + static constexpr const char* ccp_worls = STR("Worls"); + + static constexpr Text text_hello(STR("Hello")); + static constexpr Text text_world(STR("World")); + + static constexpr Text text(STR("Hello World")); + static constexpr Text text_same(STR("Hello World")); + static constexpr Text text_less(STR("Hello Wnrld")); + static constexpr Text text_greater(STR("Hello Wprld")); + static constexpr Text text_less_length(STR("Hello Worl")); + static constexpr Text text_greater_length(STR("Hello World!")); + + static constexpr size_t length = etl::strlen(STR("Hello World")); + + static constexpr IText& itext = text; //************************************************************************* template @@ -80,30 +84,8 @@ namespace } //************************************************************************* - struct SetupFixture + TEST(test_constructor_char_pointer) { - SetupFixture() - { - initial_text = STR("Hello World"); - insert_text = STR("Insert"); - less_text = STR("Hello Vorld"); - greater_text = STR("Hello Xorld"); - shorter_text = STR("Hello Worl"); - different_text = STR("Byee Planet"); - longer_text = STR("Hello World There"); - short_text = STR("Hello"); - } - }; - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) - { - TextSTD compare_text(initial_text.c_str()); - - static constexpr const char* initial = "Hello World"; - static constexpr Text text(initial); - static constexpr size_t length = etl::strlen(initial); - static constexpr auto text_empty = text.empty(); CHECK_FALSE(text_empty); @@ -166,51 +148,48 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_contains) + TEST(test_contains_const_char_pointer) { - static constexpr Text text("Hello World"); - - static constexpr auto text_contains_world = text.contains("World"); + static constexpr auto text_contains_world = text.contains(ccp_world); CHECK_TRUE(text_contains_world); - static constexpr auto text_contains_worls = text.contains("Worls"); + static constexpr auto text_contains_worls = text.contains(ccp_worls); CHECK_FALSE(text_contains_worls); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_start_with_ends_with) + TEST(test_start_with) { - static constexpr Text text("Hello World"); - - static constexpr auto text_starts_with_hello = text.starts_with("Hello"); + static constexpr auto text_starts_with_hello = text.starts_with(ccp_hello); CHECK_TRUE(text_starts_with_hello); - static constexpr auto text_starts_with_world = text.starts_with("World"); + static constexpr auto text_starts_with_world = text.starts_with(ccp_world); CHECK_FALSE(text_starts_with_world); + } - static constexpr auto text_ends_with_hello = text.ends_with("Hello"); + //************************************************************************* + TEST(test_ends_with) + { + static constexpr auto text_ends_with_hello = text.ends_with(ccp_hello); CHECK_FALSE(text_ends_with_hello); - static constexpr auto text_ends_with_world = text.ends_with("World"); + static constexpr auto text_ends_with_world = text.ends_with(ccp_world); CHECK_TRUE(text_ends_with_world); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find) + TEST(test_find) { - static constexpr Text text("Hello World"); - - static constexpr auto text_find_world = text.find("World"); + static constexpr auto text_find_world = text.find(ccp_world); CHECK_EQUAL(6, text_find_world); - static constexpr auto text_find_worls = text.find("Worls"); + static constexpr auto text_find_worls = text.find(ccp_worls); CHECK_EQUAL(Text::npos, text_find_worls); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of) + TEST(test_find_first_of) { - static constexpr Text text("Hello World"); static constexpr auto text_find_first_of_o = text.find_first_of(STR('o'), 5); CHECK_EQUAL(7, text_find_first_of_o); @@ -219,9 +198,8 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of) + TEST(test_find_first_not_of) { - static constexpr Text text("Hello World"); static constexpr auto text_find_first_not_of_l = text.find_first_not_of(STR('l'), 2); CHECK_EQUAL(4, text_find_first_not_of_l); @@ -230,10 +208,8 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of) + TEST(test_find_last_of) { - static constexpr Text text("Hello World"); - static constexpr auto text_find_last_of_o = text.find_last_of(STR('o'), 9); CHECK_EQUAL(7, text_find_last_of_o); @@ -242,10 +218,8 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of) + TEST(test_find_last_not_of) { - static constexpr Text text("Hello World"); - static constexpr auto text_find_last_not_of_l = text.find_last_not_of(STR('l'), 9); CHECK_EQUAL(8, text_find_last_not_of_l); @@ -254,12 +228,8 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_access_functions) + TEST(test_access_functions) { - static constexpr const char* initial = "Hello World"; - static constexpr Text text(initial); - static constexpr size_t length = etl::strlen(initial); - static constexpr auto text_index_operator = text[3]; CHECK_EQUAL(initial[3], text_index_operator); @@ -277,15 +247,8 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_functions) + TEST(test_compare_functions) { - static constexpr Text text("Hello World"); - static constexpr Text text_same("Hello World"); - static constexpr Text text_less("Hello Wnrld"); - static constexpr Text text_greater("Hello Wprld"); - static constexpr Text text_less_length("Hello Worl"); - static constexpr Text text_greater_length("Hello World!"); - static constexpr auto text_compare_with_same = text.compare(text_same); CHECK_EQUAL(0, text_compare_with_same); @@ -303,29 +266,98 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_operators) + TEST(test_compare_equal_operator) { - static constexpr Text text("Hello World"); - static constexpr Text text_same("Hello World"); - static constexpr Text text_less("Hello Wnrld"); - static constexpr Text text_greater("Hello Wprld"); - static constexpr Text text_less_length("Hello Worl"); - static constexpr Text text_greater_length("Hello World!"); + static constexpr bool text_compare_with_same = (text == text_same); + CHECK_TRUE(text_compare_with_same); - //static constexpr bool text_compare_with_same = (text == text_same); - //CHECK_TRUE(text_compare_with_same); + static constexpr bool text_compare_with_less = (text == text_less); + CHECK_FALSE(text_compare_with_less); - //static constexpr auto text_compare_with_less = text.compare(text_less); - //CHECK_EQUAL(1, text_compare_with_less); + static constexpr bool text_compare_with_greater = (text == text_greater); + CHECK_FALSE(text_compare_with_greater); - //static constexpr auto text_compare_with_greater = text.compare(text_greater); - //CHECK_EQUAL(-1, text_compare_with_greater); + static constexpr bool text_compare_with_less_length = (text == text_less_length); + CHECK_FALSE(text_compare_with_less_length); - //static constexpr auto text_compare_with_less_length = text.compare(text_less_length); - //CHECK_EQUAL(1, text_compare_with_less_length); + static constexpr bool text_compare_with_greater_length = (text == text_greater_length); + CHECK_FALSE(text_compare_with_greater_length); + } - //static constexpr auto text_compare_with_greater_length = text.compare(text_greater_length); - //CHECK_EQUAL(-1, text_compare_with_greater_length); + //************************************************************************* + TEST(test_compare_not_equal_operator) + { + static constexpr bool text_compare_with_same = (text != text_same); + CHECK_FALSE(text_compare_with_same); + + static constexpr bool text_compare_with_less = (text != text_less); + CHECK_TRUE(text_compare_with_less); + + static constexpr bool text_compare_with_greater = (text != text_greater); + CHECK_TRUE(text_compare_with_greater); + + static constexpr bool text_compare_with_less_length = (text != text_less_length); + CHECK_TRUE(text_compare_with_less_length); + + static constexpr bool text_compare_with_greater_length = (text != text_greater_length); + CHECK_TRUE(text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_compare_less_than_operator) + { + static constexpr bool text_compare_with_same = (text < text_same); + CHECK_FALSE(text_compare_with_same); + + static constexpr bool text_compare_with_less = (text < text_less); + CHECK_FALSE(text_compare_with_less); + + static constexpr bool text_compare_with_greater = (text < text_greater); + CHECK_TRUE(text_compare_with_greater); + + static constexpr bool text_compare_with_less_length = (text < text_less_length); + CHECK_FALSE(text_compare_with_less_length); + + static constexpr bool text_compare_with_greater_length = (text < text_greater_length); + CHECK_TRUE(text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_compare_less_than_equal_operator) + { + static constexpr bool text_compare_with_same = (text <= text_same); + CHECK_TRUE(text_compare_with_same); + + static constexpr bool text_compare_with_less = (text <= text_less); + CHECK_FALSE(text_compare_with_less); + + static constexpr bool text_compare_with_greater = (text <= text_greater); + CHECK_TRUE(text_compare_with_greater); + + static constexpr bool text_compare_with_less_length = (text <= text_less_length); + CHECK_FALSE(text_compare_with_less_length); + + static constexpr bool text_compare_with_greater_length = (text <= text_greater_length); + CHECK_TRUE(text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_compare_greater_than_operator) + { + static constexpr bool text_compare_with_same = (text > text_same); + CHECK_FALSE(text_compare_with_same); + + static constexpr bool text_compare_with_less = (text > text_less); + CHECK_TRUE(text_compare_with_less); + + static constexpr bool text_compare_with_greater = (text > text_greater); + CHECK_FALSE(text_compare_with_greater); + + static constexpr bool text_compare_with_less_length = (text > text_less_length); + CHECK_TRUE(text_compare_with_less_length); + + static constexpr bool text_compare_with_greater_length = (text > text_greater_length); + CHECK_FALSE(text_compare_with_greater_length); } }; } From 56fe3dd1ffd93ee56031f0dccaa8858e467efc20 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Jul 2025 12:41:44 +0100 Subject: [PATCH 7/8] Work in progress --- include/etl/basic_string.h | 6 +- include/etl/const_string.h | 55 +- test/test_const_string_char.cpp | 1888 +++++++++++++++++++++++++++++-- 3 files changed, 1825 insertions(+), 124 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 178a191e..c35869c7 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -1410,7 +1410,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_type find(const ibasic_string& str, size_type pos = 0) const + ETL_CONSTEXPR14 size_type find(const ibasic_string& str, size_type pos = 0) const { return find_impl(str.begin(), str.end(), str.size(), pos); } @@ -1456,7 +1456,7 @@ namespace etl ///\param c The character to find. ///\param position The position to start searching from. //********************************************************************* - size_type find(T c, size_type position = 0) const + ETL_CONSTEXPR14 size_type find(T c, size_type position = 0) const { const_iterator i = etl::find(begin() + position, end(), c); @@ -1486,7 +1486,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type rfind(const etl::basic_string_view& view, size_type pos = 0) const + ETL_CONSTEXPR14 size_type rfind(const etl::basic_string_view& view, size_type pos = npos) const { return rfind_impl(view.rbegin(), view.rend(), view.size(), pos); } diff --git a/include/etl/const_string.h b/include/etl/const_string.h index 4dbf576f..9ce057fe 100644 --- a/include/etl/const_string.h +++ b/include/etl/const_string.h @@ -64,6 +64,59 @@ namespace etl this->current_size = etl::strlen(buffer); } + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_string(const value_type* buffer, size_t length) + : istring(const_cast(buffer), length) + { + this->current_size = length; + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_string(const value_type* buffer, const value_type* buffer_end) + : istring(const_cast(buffer), buffer_end - buffer) + { + this->current_size = buffer_end - buffer; + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_string(const etl::string_view& view) + : istring(const_cast(view.data()), view.size()) + { + this->current_size = view.size(); + } + + //************************************************************************* + /// Copy constructor. + //************************************************************************* + constexpr const_string(const etl::const_string& other) + : istring(const_cast(other.data()), other.size()) + { + this->current_size = other.size(); + } + + //************************************************************************* + /// Returns a sub-string. + ///\param position The position of the first character. Default = 0. + ///\param length The number of characters. Default = npos. + //************************************************************************* + constexpr etl::const_string substr(size_type position = 0, size_type length_ = npos) const + { + if (position < this->size()) + { + length_ = etl::min(length_, this->size() - position); + + return etl::const_string(data() + position, length_); + } + + return etl::const_string(""); + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -80,7 +133,7 @@ namespace etl //************************************************************************* /// Deleted. //************************************************************************* - const_string(const const_string& other) ETL_DELETE; + //const_string(const const_string& other) ETL_DELETE; }; } diff --git a/test/test_const_string_char.cpp b/test/test_const_string_char.cpp index 4a6b209e..6cdecc68 100644 --- a/test/test_const_string_char.cpp +++ b/test/test_const_string_char.cpp @@ -44,26 +44,28 @@ namespace bool compares_agree(int result1, int result2) { return ((result1 < 0) && (result2 < 0)) || - ((result1 == 0) && (result2 == 0)) || - ((result1 > 0) && (result2 > 0)); + ((result1 == 0) && (result2 == 0)) || + ((result1 > 0) && (result2 > 0)); } SUITE(test_string_char) { - static const size_t SIZE = 11UL; - using Text = etl::const_string; - using IText = const etl::istring; - using value_t = Text::value_type; + using IText = etl::istring; + using TextSTD = std::string; + using View = etl::string_view; - static constexpr const char* initial = STR("Hello World"); + constexpr const char* text_pointer = STR("Hello World"); static constexpr const char* ccp_hello = STR("Hello"); static constexpr const char* ccp_world = STR("World"); static constexpr const char* ccp_worls = STR("Worls"); + static constexpr Text text_he(STR("He")); + static constexpr Text text_llo_world(STR("llo World")); static constexpr Text text_hello(STR("Hello")); - static constexpr Text text_world(STR("World")); + static constexpr Text text_word(STR("Word")); + static constexpr Text text_rd(STR("rd")); static constexpr Text text(STR("Hello World")); static constexpr Text text_same(STR("Hello World")); @@ -74,7 +76,14 @@ namespace static constexpr size_t length = etl::strlen(STR("Hello World")); - static constexpr IText& itext = text; + static constexpr Text text_xxx(STR("xxxHello Worldxxx")); + static constexpr Text text_same_xxx(STR("xxxHello World")); + static constexpr Text text_less_xxx(STR("xxxHello Wnrldxxx")); + static constexpr Text text_greater_xxx(STR("xxxHello Wprldxxx")); + static constexpr Text text_less_length_xxx(STR("xxxHello Worlxxx")); + static constexpr Text text_greater_length_xxx(STR("xxxHello World!xxx")); + + static constexpr const IText& itext = text; //************************************************************************* template @@ -84,189 +93,374 @@ namespace } //************************************************************************* - TEST(test_constructor_char_pointer) + template + bool Equal(const T1* compare_text, const T2& text) { - static constexpr auto text_empty = text.empty(); - CHECK_FALSE(text_empty); + return (etl::strlen(compare_text) == text.size()) && std::equal(text.begin(), text.end(), compare_text); + } - static constexpr auto text_full = text.full(); + //************************************************************************* + TEST(test_constructor_null_string) + { + static constexpr Text text_from_literal_empty(STR("")); + + static constexpr auto text_empty = text_from_literal_empty.empty(); + CHECK_TRUE(text_empty); + + static constexpr auto text_full = text_from_literal_empty.full(); CHECK_TRUE(text_full); - static constexpr auto text_capacity = text.capacity(); - CHECK_EQUAL(length, text_capacity); + static constexpr auto text_capacity = text_from_literal_empty.capacity(); + CHECK_EQUAL(0, text_capacity); - static constexpr auto text_max_size = text.max_size(); - CHECK_EQUAL(length, text_max_size); + static constexpr auto text_max_size = text_from_literal_empty.max_size(); + CHECK_EQUAL(0, text_max_size); - static constexpr auto text_size = text.size(); - CHECK_EQUAL(length, text_size); + static constexpr auto text_size = text_from_literal_empty.size(); + CHECK_EQUAL(0, text_size); - static constexpr auto text_length = text.length(); - CHECK_EQUAL(length, text_length); + static constexpr auto text_length = text_from_literal_empty.length(); + CHECK_EQUAL(0, text_length); - static constexpr auto text_available = text.available(); + static constexpr auto text_available = text_from_literal_empty.available(); CHECK_EQUAL(0, text_available); - static constexpr auto text_is_truncated = text.is_truncated(); + static constexpr auto text_is_truncated = text_from_literal_empty.is_truncated(); CHECK_FALSE(text_is_truncated); - static constexpr auto text_is_secure = text.is_secure(); + static constexpr auto text_is_secure = text_from_literal_empty.is_secure(); + CHECK_FALSE(text_is_secure); + } + + //************************************************************************* + TEST(test_constructor_char_pointer) + { + static constexpr Text text_from_pointer(text_pointer); + + static constexpr auto text_empty = text_from_pointer.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_pointer.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_pointer.capacity(); + CHECK_EQUAL(length, text_capacity); + + static constexpr auto text_max_size = text_from_pointer.max_size(); + CHECK_EQUAL(length, text_max_size); + + static constexpr auto text_size = text_from_pointer.size(); + CHECK_EQUAL(length, text_size); + + static constexpr auto text_length = text_from_pointer.length(); + CHECK_EQUAL(length, text_length); + + static constexpr auto text_available = text_from_pointer.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_pointer.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_pointer.is_secure(); CHECK_FALSE(text_is_secure); - static constexpr const char* text_data = text.data(); - CHECK_EQUAL(&initial[0], text_data); + static constexpr const char* text_data = text_from_pointer.data(); + CHECK_EQUAL(&text_pointer[0], text_data); - static constexpr const char* text_data_end = text.data_end(); - CHECK_EQUAL(&initial[length], text_data_end); + static constexpr const char* text_data_end = text_from_pointer.data_end(); + CHECK_EQUAL(&text_pointer[length], text_data_end); - static constexpr auto text_begin = text.begin(); - CHECK_EQUAL(&initial[0], text_begin); + static constexpr auto text_begin = text_from_pointer.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); - static constexpr auto text_cbegin = text.cbegin(); - CHECK_EQUAL(&initial[0], text_cbegin); + static constexpr auto text_cbegin = text_from_pointer.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); - static constexpr auto text_rbegin = text.rbegin(); - CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_rbegin)); + static constexpr auto text_rbegin = text_from_pointer.rbegin(); + CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_rbegin)); - static constexpr auto text_crbegin = text.crbegin(); - CHECK_EQUAL(&initial[length - 1], etl::addressof(*text_crbegin)); + static constexpr auto text_crbegin = text_from_pointer.crbegin(); + CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_crbegin)); - static constexpr auto text_end = text.end(); - CHECK_EQUAL(&initial[length], text_end); + static constexpr auto text_end = text_from_pointer.end(); + CHECK_EQUAL(&text_pointer[length], text_end); - static constexpr auto text_cend = text.cend(); - CHECK_EQUAL(&initial[length], text_cend); + static constexpr auto text_cend = text_from_pointer.cend(); + CHECK_EQUAL(&text_pointer[length], text_cend); - static constexpr auto text_rend = text.rend(); - CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_rend)); + static constexpr auto text_rend = text_from_pointer.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); - static constexpr auto text_crend = text.crend(); - CHECK_EQUAL(&initial[0] - 1, etl::addressof(*text_crend)); + static constexpr auto text_crend = text_from_pointer.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); - bool is_equal = Equal(std::string(initial), text); + bool is_equal = Equal(std::string(text_pointer), text); CHECK(is_equal); } //************************************************************************* - TEST(test_contains_const_char_pointer) + TEST(test_constructor_from_literal) { - static constexpr auto text_contains_world = text.contains(ccp_world); - CHECK_TRUE(text_contains_world); + static constexpr Text text_from_literal(STR("Hello World")); - static constexpr auto text_contains_worls = text.contains(ccp_worls); - CHECK_FALSE(text_contains_worls); + static constexpr auto text_empty = text_from_literal.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_literal.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal.capacity(); + CHECK_EQUAL(length, text_capacity); + + static constexpr auto text_max_size = text_from_literal.max_size(); + CHECK_EQUAL(length, text_max_size); + + static constexpr auto text_size = text_from_literal.size(); + CHECK_EQUAL(length, text_size); + + static constexpr auto text_length = text_from_literal.length(); + CHECK_EQUAL(length, text_length); + + static constexpr auto text_available = text_from_literal.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr const char* text_data = text_from_literal.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr const char* text_data_end = text_from_literal.data_end(); + CHECK_EQUAL(&text_pointer[length], text_data_end); + + static constexpr auto text_begin = text_from_literal.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_literal.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_literal.rbegin(); + CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_literal.crbegin(); + CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_literal.end(); + CHECK_EQUAL(&text_pointer[length], text_end); + + static constexpr auto text_cend = text_from_literal.cend(); + CHECK_EQUAL(&text_pointer[length], text_cend); + + static constexpr auto text_rend = text_from_literal.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_literal.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::string(text_pointer), text); + CHECK(is_equal); } //************************************************************************* - TEST(test_start_with) + TEST(test_constructor_from_etl_string_view) { - static constexpr auto text_starts_with_hello = text.starts_with(ccp_hello); - CHECK_TRUE(text_starts_with_hello); + static constexpr Text text_from_view(View(STR("Hello World"))); - static constexpr auto text_starts_with_world = text.starts_with(ccp_world); - CHECK_FALSE(text_starts_with_world); + static constexpr auto text_empty = text_from_view.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_view.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_view.capacity(); + CHECK_EQUAL(length, text_capacity); + + static constexpr auto text_max_size = text_from_view.max_size(); + CHECK_EQUAL(length, text_max_size); + + static constexpr auto text_size = text_from_view.size(); + CHECK_EQUAL(length, text_size); + + static constexpr auto text_length = text_from_view.length(); + CHECK_EQUAL(length, text_length); + + static constexpr auto text_available = text_from_view.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_view.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_view.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr const char* text_data = text_from_view.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr const char* text_data_end = text_from_view.data_end(); + CHECK_EQUAL(&text_pointer[length], text_data_end); + + static constexpr auto text_begin = text_from_view.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_view.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_view.rbegin(); + CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_view.crbegin(); + CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_view.end(); + CHECK_EQUAL(&text_pointer[length], text_end); + + static constexpr auto text_cend = text_from_view.cend(); + CHECK_EQUAL(&text_pointer[length], text_cend); + + static constexpr auto text_rend = text_from_view.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_view.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::string(text_pointer), text); + CHECK(is_equal); } //************************************************************************* - TEST(test_ends_with) + TEST(test_begin) { - static constexpr auto text_ends_with_hello = text.ends_with(ccp_hello); - CHECK_FALSE(text_ends_with_hello); + static constexpr Text::const_iterator p_begin = text.begin(); + static constexpr Text::const_iterator p_cbegin = text.cbegin(); - static constexpr auto text_ends_with_world = text.ends_with(ccp_world); - CHECK_TRUE(text_ends_with_world); + CHECK_EQUAL(&text[0], p_begin); + CHECK_EQUAL(&text[0], p_cbegin); } //************************************************************************* - TEST(test_find) + TEST(test_end) { - static constexpr auto text_find_world = text.find(ccp_world); - CHECK_EQUAL(6, text_find_world); + static constexpr Text::const_iterator p_end = text.end(); + static constexpr Text::const_iterator p_cend = text.cend(); - static constexpr auto text_find_worls = text.find(ccp_worls); - CHECK_EQUAL(Text::npos, text_find_worls); + CHECK_EQUAL(&text[length], p_end); + CHECK_EQUAL(&text[length], p_cend); } //************************************************************************* - TEST(test_find_first_of) + TEST(test_empty_full) { - static constexpr auto text_find_first_of_o = text.find_first_of(STR('o'), 5); - CHECK_EQUAL(7, text_find_first_of_o); + static constexpr bool text_empty = text.empty(); + static constexpr bool text_full = text.full(); - static constexpr auto text_find_first_of_s = text.find_first_of(STR('s'), 5); - CHECK_EQUAL(Text::npos, text_find_first_of_s); + CHECK_FALSE(text_empty); + CHECK_TRUE(text_full); } //************************************************************************* - TEST(test_find_first_not_of) + TEST(test_index) { - static constexpr auto text_find_first_not_of_l = text.find_first_not_of(STR('l'), 2); - CHECK_EQUAL(4, text_find_first_not_of_l); + static constexpr Text::value_type c0 = text[0]; + static constexpr Text::value_type c1 = text[1]; + static constexpr Text::value_type c2 = text[2]; + static constexpr Text::value_type c3 = text[3]; + static constexpr Text::value_type c4 = text[4]; + static constexpr Text::value_type c5 = text[5]; + static constexpr Text::value_type c6 = text[6]; + static constexpr Text::value_type c7 = text[7]; + static constexpr Text::value_type c8 = text[8]; + static constexpr Text::value_type c9 = text[9]; + static constexpr Text::value_type c10 = text[10]; + static constexpr Text::value_type c11 = text[11]; - static constexpr auto text_find_first_not_of_s = text.find_first_not_of(STR('s'), 2); - CHECK_EQUAL(2, text_find_first_not_of_s); + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + CHECK_EQUAL(text_pointer[11], c11); } //************************************************************************* - TEST(test_find_last_of) + TEST(test_at) { - static constexpr auto text_find_last_of_o = text.find_last_of(STR('o'), 9); - CHECK_EQUAL(7, text_find_last_of_o); + static constexpr Text::value_type c0 = text.at(0); + static constexpr Text::value_type c1 = text.at(1); + static constexpr Text::value_type c2 = text.at(2); + static constexpr Text::value_type c3 = text.at(3); + static constexpr Text::value_type c4 = text.at(4); + static constexpr Text::value_type c5 = text.at(5); + static constexpr Text::value_type c6 = text.at(6); + static constexpr Text::value_type c7 = text.at(7); + static constexpr Text::value_type c8 = text.at(8); + static constexpr Text::value_type c9 = text.at(9); + static constexpr Text::value_type c10 = text.at(10); - static constexpr auto text_find_last_of_s = text.find_last_of(STR('s'), 9); - CHECK_EQUAL(Text::npos, text_find_last_of_s); + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); } //************************************************************************* - TEST(test_find_last_not_of) + TEST(test_front) { - static constexpr auto text_find_last_not_of_l = text.find_last_not_of(STR('l'), 9); - CHECK_EQUAL(8, text_find_last_not_of_l); - - static constexpr auto text_find_last_not_of_s = text.find_last_not_of(STR('s'), 9); - CHECK_EQUAL(9, text_find_last_not_of_s); + CHECK_TRUE(text_pointer[0] == text.front()); } //************************************************************************* - TEST(test_access_functions) + TEST(test_back) { - static constexpr auto text_index_operator = text[3]; - CHECK_EQUAL(initial[3], text_index_operator); - - static constexpr auto text_at = text.at(3); - CHECK_EQUAL(initial[3], text_at); - - static constexpr auto text_front = text.front(); - CHECK_EQUAL(initial[0], text_front); - - static constexpr auto text_back = text.back(); - CHECK_EQUAL(initial[length - 1], text_back); - - static constexpr const char* text_c_str = text.c_str(); - CHECK_EQUAL(&initial[0], text_c_str); + CHECK_TRUE(text_pointer[length - 1] == text.back()); } //************************************************************************* - TEST(test_compare_functions) + TEST(test_data) { - static constexpr auto text_compare_with_same = text.compare(text_same); - CHECK_EQUAL(0, text_compare_with_same); + static constexpr Text::const_pointer p_data = text.data(); - static constexpr auto text_compare_with_less = text.compare(text_less); - CHECK_EQUAL(1, text_compare_with_less); - - static constexpr auto text_compare_with_greater = text.compare(text_greater); - CHECK_EQUAL(-1, text_compare_with_greater); - - static constexpr auto text_compare_with_less_length = text.compare(text_less_length); - CHECK_EQUAL(1, text_compare_with_less_length); - - static constexpr auto text_compare_with_greater_length = text.compare(text_greater_length); - CHECK_EQUAL(-1, text_compare_with_greater_length); + CHECK_EQUAL(&text[0], p_data); } //************************************************************************* - TEST(test_compare_equal_operator) + TEST(test_const_iterator) + { + static constexpr Text::const_iterator itr = text.begin(); + + bool is_equal = std::equal(text_pointer, text_pointer + length, itr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_const_reverse_iterator) + { + static constexpr Text::const_reverse_iterator ritr = text.rbegin(); + + etl::reverse_iterator rbegin(text_pointer + length); + etl::reverse_iterator rend(text_pointer); + + bool is_equal = std::equal(rbegin, rend, ritr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_equal) { static constexpr bool text_compare_with_same = (text == text_same); CHECK_TRUE(text_compare_with_same); @@ -285,7 +479,7 @@ namespace } //************************************************************************* - TEST(test_compare_not_equal_operator) + TEST(test_not_equal) { static constexpr bool text_compare_with_same = (text != text_same); CHECK_FALSE(text_compare_with_same); @@ -304,7 +498,7 @@ namespace } //************************************************************************* - TEST(test_compare_less_than_operator) + TEST(test_less_than) { static constexpr bool text_compare_with_same = (text < text_same); CHECK_FALSE(text_compare_with_same); @@ -323,7 +517,7 @@ namespace } //************************************************************************* - TEST(test_compare_less_than_equal_operator) + TEST(test_less_than_or_equal) { static constexpr bool text_compare_with_same = (text <= text_same); CHECK_TRUE(text_compare_with_same); @@ -342,7 +536,7 @@ namespace } //************************************************************************* - TEST(test_compare_greater_than_operator) + TEST(test_greater_than) { static constexpr bool text_compare_with_same = (text > text_same); CHECK_FALSE(text_compare_with_same); @@ -359,5 +553,1459 @@ namespace static constexpr bool text_compare_with_greater_length = (text > text_greater_length); CHECK_FALSE(text_compare_with_greater_length); } + + //************************************************************************* + TEST(test_greater_than_or_equal) + { + static constexpr bool text_compare_with_same = (text >= text_same); + CHECK_TRUE(text_compare_with_same); + + static constexpr bool text_compare_with_less = (text >= text_less); + CHECK_TRUE(text_compare_with_less); + + static constexpr bool text_compare_with_greater = (text >= text_greater); + CHECK_FALSE(text_compare_with_greater); + + static constexpr bool text_compare_with_less_length = (text >= text_less_length); + CHECK_TRUE(text_compare_with_less_length); + + static constexpr bool text_compare_with_greater_length = (text >= text_greater_length); + CHECK_FALSE(text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_find_string) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text needle(STR("needle")); + static constexpr Text pin(STR("pin")); + + static constexpr size_t position_needle = haystack.find(needle); + CHECK_EQUAL(18, position_needle); + + static constexpr size_t position_pin = haystack.find(pin); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_find_string_position) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text needle(STR("needle")); + static constexpr Text pin(STR("pin")); + + static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); + CHECK_EQUAL(18, position_needle1); + + static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); + CHECK_EQUAL(37, position_needle2); + + static constexpr size_t position_pin = haystack.find(pin, 0ULL); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_find_view) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr View needle(STR("needle")); + static constexpr View pin(STR("pin")); + + static constexpr size_t position_needle = haystack.find(needle); + CHECK_EQUAL(18, position_needle); + + static constexpr size_t position_pin = haystack.find(pin); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_find_view_position) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr View needle(STR("needle")); + static constexpr View pin(STR("pin")); + + static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); + CHECK_EQUAL(18, position_needle1); + + static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); + CHECK_EQUAL(37, position_needle2); + + static constexpr size_t position_pin = haystack.find(pin, 0ULL); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_find_pointer) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text::const_pointer needle(STR("needle")); + static constexpr Text::const_pointer pin(STR("pin")); + + static constexpr size_t position_needle = haystack.find(needle); + CHECK_EQUAL(18, position_needle); + + static constexpr size_t position_pin = haystack.find(pin); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_find_pointer_position) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text::const_pointer needle(STR("needle")); + static constexpr Text::const_pointer pin(STR("pin")); + + static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); + CHECK_EQUAL(18, position_needle1); + + static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); + CHECK_EQUAL(37, position_needle2); + + static constexpr size_t position_pin = haystack.find(pin, 0ULL); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_find_pointer_position_n) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text::const_pointer needle(STR("needle")); + static constexpr Text::const_pointer pin(STR("pin")); + + static constexpr size_t position_needle1 = haystack.find(needle, 0ULL, 4); + CHECK_EQUAL(18, position_needle1); + + static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1, 4); + CHECK_EQUAL(37, position_needle2); + + static constexpr size_t position_pin = haystack.find(pin, 0ULL); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_find_character) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text::value_type needle(STR('n')); + static constexpr Text::value_type pin(STR('p')); + + static constexpr size_t position_needle = haystack.find(needle); + CHECK_EQUAL(18, position_needle); + + static constexpr size_t position_pin = haystack.find(pin); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_find_character_position) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text::value_type needle(STR('n')); + static constexpr Text::value_type pin(STR('p')); + + static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); + CHECK_EQUAL(18, position_needle1); + + static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); + CHECK_EQUAL(26, position_needle2); + + static constexpr size_t position_pin = haystack.find(pin, 0ULL); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_contains_string) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr Text needle(STR("needle")); + static constexpr Text pin(STR("pin" )); + static constexpr Text excess(STR("A really gigantic pin or needle that's really really big")); + + static constexpr bool contains_needle = haystack.contains(needle); + static constexpr bool constains_pin = haystack.contains(pin); + static constexpr bool contains_excess = haystack.contains(excess); + + CHECK_TRUE(contains_needle); + CHECK_FALSE(constains_pin); + CHECK_FALSE(contains_excess); + } + + //************************************************************************* + TEST(test_contains_view) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr View needle(STR("needle")); + static constexpr View pin(STR("pin" )); + static constexpr View excess(STR("A really gigantic pin or needle that's really really big")); + + static constexpr bool contains_needle = haystack.contains(needle); + static constexpr bool constains_pin = haystack.contains(pin); + static constexpr bool contains_excess = haystack.contains(excess); + + CHECK_TRUE(contains_needle); + CHECK_FALSE(constains_pin); + CHECK_FALSE(contains_excess); + } + + //************************************************************************* + TEST(test_contains_pointer) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr Text::const_pointer needle(STR("needle")); + static constexpr Text::const_pointer pin(STR("pin" )); + static constexpr Text::const_pointer excess(STR("A really gigantic pin or needle that's really really big")); + + static constexpr bool contains_needle = haystack.contains(needle); + static constexpr bool constains_pin = haystack.contains(pin); + static constexpr bool contains_excess = haystack.contains(excess); + + CHECK_TRUE(contains_needle); + CHECK_FALSE(constains_pin); + CHECK_FALSE(contains_excess); + } + + //************************************************************************* + TEST(test_contains_char) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr Text::value_type needle(STR('n')); + static constexpr Text::value_type pin(STR('p' )); + + static constexpr bool contains_needle = haystack.contains(needle); + static constexpr bool constains_pin = haystack.contains(pin); + + CHECK_TRUE(contains_needle); + CHECK_FALSE(constains_pin); + } + + //************************************************************************* + TEST(test_starts_with_string) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr Text start_text(STR("A haystack")); + static constexpr Text not_start_text(STR("nothing else")); + static constexpr Text excess(STR("A really gigantic pin or needle that's really really big")); + + static constexpr bool contains_start_text = haystack.starts_with(start_text); + static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); + static constexpr bool contains_excess = haystack.starts_with(excess); + + CHECK_TRUE(contains_start_text); + CHECK_FALSE(constains_not_start_text); + CHECK_FALSE(contains_excess); + } + + //************************************************************************* + TEST(test_starts_with_view) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr View start_text(STR("A haystack")); + static constexpr View not_start_text(STR("nothing else")); + static constexpr View excess(STR("A really gigantic pin or needle that's really really big")); + + static constexpr bool contains_start_text = haystack.starts_with(start_text); + static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); + + CHECK_TRUE(contains_start_text); + CHECK_FALSE(constains_not_start_text); + } + + //************************************************************************* + TEST(test_starts_with_pointer) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr Text::const_pointer start_text(STR("A haystack")); + static constexpr Text::const_pointer not_start_text(STR("nothing else")); + static constexpr Text::const_pointer excess(STR("A really gigantic pin or needle that's really really big")); + + static constexpr bool contains_start_text = haystack.starts_with(start_text); + static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); + + CHECK_TRUE(contains_start_text); + CHECK_FALSE(constains_not_start_text); + } + + //************************************************************************* + TEST(test_starts_with_char) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr Text::value_type start_text(STR('A')); + static constexpr Text::value_type not_start_text(STR('e')); + + static constexpr bool contains_start_text = haystack.starts_with(start_text); + static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); + + CHECK_TRUE(contains_start_text); + CHECK_FALSE(constains_not_start_text); + } + + //************************************************************************* + TEST(test_ends_with_string) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr Text not_end_text(STR("A haystack")); + static constexpr Text end_text(STR("nothing else")); + static constexpr Text excess(STR("A really gigantic pin or needle that's really really big")); + + static constexpr bool contains_end_text = haystack.ends_with(end_text); + static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); + static constexpr bool contains_excess = haystack.ends_with(excess); + + CHECK_TRUE(contains_end_text); + CHECK_FALSE(constains_not_end_text); + CHECK_FALSE(contains_excess); + } + + //************************************************************************* + TEST(test_ends_with_view) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr View not_end_text(STR("A haystack")); + static constexpr View end_text(STR("nothing else")); + static constexpr View excess(STR("A really gigantic pin or needle that's really really big")); + + static constexpr bool contains_end_text = haystack.ends_with(end_text); + static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); + static constexpr bool contains_excess = haystack.ends_with(excess); + + CHECK_TRUE(contains_end_text); + CHECK_FALSE(constains_not_end_text); + CHECK_FALSE(contains_excess); + } + + //************************************************************************* + TEST(test_ends_with_pointer) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr Text::const_pointer not_end_text(STR("A haystack")); + static constexpr Text::const_pointer end_text(STR("nothing else")); + static constexpr Text::const_pointer excess(STR("A really gigantic pin or needle that's really really big")); + + static constexpr bool contains_end_text = haystack.ends_with(end_text); + static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); + static constexpr bool contains_excess = haystack.ends_with(excess); + + CHECK_TRUE(contains_end_text); + CHECK_FALSE(constains_not_end_text); + CHECK_FALSE(contains_excess); + } + + //************************************************************************* + TEST(test_ends_with_char) + { + static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); + static constexpr Text haystack(the_haystack); + + static constexpr Text::value_type not_end_text(STR('A')); + static constexpr Text::value_type end_text(STR('e')); + + static constexpr bool contains_end_text = haystack.ends_with(end_text); + static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); + + CHECK_TRUE(contains_end_text); + CHECK_FALSE(constains_not_end_text); + } + + //************************************************************************* + TEST(test_rfind_string) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text needle(STR("needle")); + static constexpr Text pin(STR("pin")); + + static constexpr size_t position_needle = haystack.rfind(needle); + CHECK_EQUAL(37, position_needle); + + static constexpr size_t position_pin = haystack.rfind(pin); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_rfind_string_position) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text needle(STR("needle")); + static constexpr Text pin(STR("pin")); + + static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); + CHECK_EQUAL(37, position_needle1); + + static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); + CHECK_EQUAL(18, position_needle2); + + static constexpr size_t position_pin = haystack.rfind(pin, 0ULL); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_rfind_view) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr View needle(STR("needle")); + static constexpr View pin(STR("pin")); + + static constexpr size_t position_needle = haystack.rfind(needle); + CHECK_EQUAL(37, position_needle); + + static constexpr size_t position_pin = haystack.rfind(pin); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_rfind_view_position) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr View needle(STR("needle")); + static constexpr View pin(STR("pin")); + + static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); + CHECK_EQUAL(37, position_needle1); + + static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); + CHECK_EQUAL(18, position_needle2); + + static constexpr size_t position_pin = haystack.rfind(pin, Text::npos); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_rfind_pointer) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text::const_pointer needle(STR("needle")); + static constexpr Text::const_pointer pin(STR("pin")); + + static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); + CHECK_EQUAL(37, position_needle1); + + static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); + CHECK_EQUAL(18, position_needle2); + + static constexpr size_t position_pin = haystack.rfind(pin, Text::npos); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_rfind_pointer_n) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text::const_pointer needle(STR("needle")); + static constexpr Text::const_pointer pin(STR("pin")); + + static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos, 4); + CHECK_EQUAL(37, position_needle1); + + static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1 + 1, 4); + CHECK_EQUAL(18, position_needle2); + + static constexpr size_t position_pin = haystack.rfind(pin, Text::npos, 4); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_rfind_character) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text::value_type needle(STR('n')); + static constexpr Text::value_type pin(STR('p')); + + static constexpr size_t position_needle = haystack.rfind(needle); + CHECK_EQUAL(37, position_needle); + + static constexpr size_t position_pin = haystack.rfind(pin); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_rfind_character_position) + { + static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); + static constexpr Text haystack(the_haystack); + + static constexpr Text::value_type needle(STR('n')); + static constexpr Text::value_type pin(STR('p')); + + static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); + CHECK_EQUAL(37, position_needle1); + + static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); + CHECK_EQUAL(30, position_needle2); + + static constexpr size_t position_pin = haystack.rfind(pin, Text::npos); + CHECK_EQUAL(Text::npos, position_pin); + } + + //************************************************************************* + TEST(test_substr) + { + // Equal. + static constexpr Text sub1(text.substr(text.size())); + CHECK_EQUAL(0, sub1.size()); + + // Whole string. + static constexpr Text sub2(text.substr()); + CHECK_TRUE(Equal(text, sub2)); + + // Starting from position 2. + static constexpr Text sub3(text.substr(2)); + CHECK_TRUE(Equal(View(text.begin() + 2, text.end()), sub3)); + + // Starting from position 2 for 3 characters. + static constexpr Text sub4(text.substr(2, 3)); + CHECK_TRUE(Equal(View(text.begin() + 2, text.begin() + 2 + 3), sub4)); + + // Starting from position 2 for too many characters. + static constexpr Text sub5(text.substr(2, text.size())); + CHECK_TRUE(Equal(View(text.begin() + 2, text.end()), sub3)); + } + + //************************************************************************* + TEST(test_compare_string) + { + // Equal. + static constexpr auto text_compare_with_same = text.compare(text_same); + CHECK_EQUAL(0, text_compare_with_same); + + // Less. + static constexpr auto text_compare_with_less = text.compare(text_less); + CHECK_EQUAL(1, text_compare_with_less); + + // Greater. + static constexpr auto text_compare_with_greater = text.compare(text_greater); + CHECK_EQUAL(-1, text_compare_with_greater); + + // Shorter + static constexpr auto text_compare_with_less_length = text.compare(text_less_length); + CHECK_EQUAL(1, text_compare_with_less_length); + + // Longer. + static constexpr auto text_compare_with_greater_length = text.compare(text_greater_length); + CHECK_EQUAL(-1, text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_compare_position_length_string) + { + // Equal. + static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same); + CHECK_EQUAL(0, text_compare_with_same); + + // Less. + static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less); + CHECK_EQUAL(1, text_compare_with_less); + + // Greater. + static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater); + CHECK_EQUAL(-1, text_compare_with_greater); + + // Shorter + static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length); + CHECK_EQUAL(1, text_compare_with_less_length); + + // Longer. + static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length); + CHECK_EQUAL(-1, text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_compare_position_length_string_subposition_sublength) + { + // Equal. + static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same_xxx, 3, text_same.size()); + CHECK_EQUAL(0, text_compare_with_same); + + // Less. + static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less_xxx, 3, text_less.size()); + CHECK_EQUAL(1, text_compare_with_less); + + // Greater. + static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater_xxx, 3, text_greater.size()); + CHECK_EQUAL(-1, text_compare_with_greater); + + // Shorter + static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length_xxx, 3, text_less_length.size()); + CHECK_EQUAL(1, text_compare_with_less_length); + + // Longer. + static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length_xxx, 3, text_greater_length.size()); + CHECK_EQUAL(-1, text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_compare_view) + { + // Equal. + static constexpr auto text_compare_with_same = text.compare(View(text_same)); + CHECK_EQUAL(0, text_compare_with_same); + + // Less. + static constexpr auto text_compare_with_less = text.compare(View(text_less)); + CHECK_EQUAL(1, text_compare_with_less); + + // Greater. + static constexpr auto text_compare_with_greater = text.compare(View(text_greater)); + CHECK_EQUAL(-1, text_compare_with_greater); + + // Shorter + static constexpr auto text_compare_with_less_length = text.compare(View(text_less_length)); + CHECK_EQUAL(1, text_compare_with_less_length); + + // Longer. + static constexpr auto text_compare_with_greater_length = text.compare(View(text_greater_length)); + CHECK_EQUAL(-1, text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_compare_position_length_view) + { + // Equal. + static constexpr auto text_compare_with_same = text_xxx.compare(3, length, View(text_same)); + CHECK_EQUAL(0, text_compare_with_same); + + // Less. + static constexpr auto text_compare_with_less = text_xxx.compare(3, length, View(text_less)); + CHECK_EQUAL(1, text_compare_with_less); + + // Greater. + static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, View(text_greater)); + CHECK_EQUAL(-1, text_compare_with_greater); + + // Shorter + static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, View(text_less_length)); + CHECK_EQUAL(1, text_compare_with_less_length); + + // Longer. + static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, View(text_greater_length)); + CHECK_EQUAL(-1, text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_compare_position_length_view_subposition_sublength) + { + // Equal. + static constexpr auto text_compare_with_same = text_xxx.compare(3, length, View(text_same_xxx), 3, text_same.size()); + CHECK_EQUAL(0, text_compare_with_same); + + // Less. + static constexpr auto text_compare_with_less = text_xxx.compare(3, length, View(text_less_xxx), 3, text_less.size()); + CHECK_EQUAL(1, text_compare_with_less); + + // Greater. + static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, View(text_greater_xxx), 3, text_greater.size()); + CHECK_EQUAL(-1, text_compare_with_greater); + + // Shorter + static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, View(text_less_length_xxx), 3, text_less_length.size()); + CHECK_EQUAL(1, text_compare_with_less_length); + + // Longer. + static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, View(text_greater_length_xxx), 3, text_greater_length.size()); + CHECK_EQUAL(-1, text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_compare_c_string) + { + // Equal. + static constexpr auto text_compare_with_same = text.compare(text_same.data()); + CHECK_EQUAL(0, text_compare_with_same); + + // Less. + static constexpr auto text_compare_with_less = text.compare(text_less.data()); + CHECK_EQUAL(1, text_compare_with_less); + + // Greater. + static constexpr auto text_compare_with_greater = text.compare(text_greater.data()); + CHECK_EQUAL(-1, text_compare_with_greater); + + // Shorter + static constexpr auto text_compare_with_less_length = text.compare(text_less_length.data()); + CHECK_EQUAL(1, text_compare_with_less_length); + + // Longer. + static constexpr auto text_compare_with_greater_length = text.compare(text_greater_length.data()); + CHECK_EQUAL(-1, text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_compare_position_length_c_string) + { + // Equal. + static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same.data()); + CHECK_EQUAL(0, text_compare_with_same); + + // Less. + static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less.data()); + CHECK_EQUAL(1, text_compare_with_less); + + // Greater. + static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater.data()); + CHECK_EQUAL(-1, text_compare_with_greater); + + // Shorter + static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length.data()); + CHECK_EQUAL(1, text_compare_with_less_length); + + // Longer. + static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length.data()); + CHECK_EQUAL(-1, text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_compare_position_length_c_string_n) + { + // Equal. + static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same.data(), text_same.size()); + CHECK_EQUAL(0, text_compare_with_same); + + // Less. + static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less.data(), text_less.size()); + CHECK_EQUAL(1, text_compare_with_less); + + // Greater. + static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater.data(), text_greater.size()); + CHECK_EQUAL(-1, text_compare_with_greater); + + // Shorter + static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length.data(), text_less_length.size()); + CHECK_EQUAL(1, text_compare_with_less_length); + + // Longer. + static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length.data(), text_greater_length.size()); + CHECK_EQUAL(-1, text_compare_with_greater_length); + } + + //************************************************************************* + TEST(test_find_first_of_string_position) + { + static constexpr auto text_find_first_of_word = text.find_first_of(text_word, 2); + CHECK_EQUAL(4, text_find_first_of_word); + + static constexpr auto text_find_first_of_he = text.find_first_of(text_he, 2); + CHECK_EQUAL(Text::npos, text_find_first_of_he); + } + + //************************************************************************* + TEST(test_find_first_of_view_position) + { + static constexpr auto text_find_first_of_word = text.find_first_of(View(text_word), 2); + CHECK_EQUAL(4, text_find_first_of_word); + + static constexpr auto text_find_first_of_he = text.find_first_of(View(text_he), 2); + CHECK_EQUAL(Text::npos, text_find_first_of_he); + } + + //************************************************************************* + TEST(test_find_first_of_pointer_position) + { + static constexpr auto text_find_first_of_word = text.find_first_of(text_word.data(), 2); + CHECK_EQUAL(4, text_find_first_of_word); + + static constexpr auto text_find_first_of_he = text.find_first_of(text_he.data(), 2); + CHECK_EQUAL(Text::npos, text_find_first_of_he); + } + + //************************************************************************* + TEST(test_find_first_of_pointer_position_n) + { + static constexpr auto text_find_first_of_word = text.find_first_of(text_word.data(), 2, text_word.size()); + CHECK_EQUAL(4, text_find_first_of_word); + + static constexpr auto text_find_first_of_he = text.find_first_of(text_he.data(), 2, text_he.size()); + CHECK_EQUAL(Text::npos, text_find_first_of_he); + } + + //************************************************************************* + TEST(test_find_first_of_character_position) + { + static constexpr auto text_find_first_of_o = text.find_first_of(STR('o'), 2); + CHECK_EQUAL(4, text_find_first_of_o); + + static constexpr auto text_find_first_of_h = text.find_first_of(STR('h'), 2); + CHECK_EQUAL(Text::npos, text_find_first_of_h); + } + + //************************************************************************* + TEST(test_find_last_of_string_position) + { + static constexpr auto text_find_last_of_word = text.find_last_of(text_word, 9); + CHECK_EQUAL(8, text_find_last_of_word); + + static constexpr auto text_find_last_of_rd = text.find_last_of(text_rd, 7); + CHECK_EQUAL(Text::npos, text_find_last_of_rd); + } + + //************************************************************************* + TEST(test_find_last_of_view_position) + { + static constexpr auto text_find_last_of_word = text.find_last_of(View(text_word), 9); + CHECK_EQUAL(8, text_find_last_of_word); + + static constexpr auto text_find_last_of_rd = text.find_last_of(View(text_rd), 7); + CHECK_EQUAL(Text::npos, text_find_last_of_rd); + } + + //************************************************************************* + TEST(test_find_last_of_pointer_position) + { + static constexpr auto text_find_last_of_word = text.find_last_of(text_word.data(), 9); + CHECK_EQUAL(8, text_find_last_of_word); + + static constexpr auto text_find_last_of_rd = text.find_last_of(text_rd.data(), 7); + CHECK_EQUAL(Text::npos, text_find_last_of_rd); + } + + //************************************************************************* + TEST(test_find_last_of_pointer_position_n) + { + static constexpr auto text_find_last_of_word = text.find_last_of(text_word.data(), 9, text_word.size()); + CHECK_EQUAL(8, text_find_last_of_word); + + static constexpr auto text_find_last_of_rd = text.find_last_of(text_rd.data(), 7, text_rd.size()); + CHECK_EQUAL(Text::npos, text_find_last_of_rd); + } + + //************************************************************************* + TEST(test_find_last_of_character_position) + { + static constexpr auto text_find_last_of_o = text.find_last_of(STR('o'), 9); + CHECK_EQUAL(7, text_find_last_of_o); + + static constexpr auto text_find_last_of_h = text.find_last_of(STR('h'), 7); + CHECK_EQUAL(Text::npos, text_find_last_of_h); + } + + //************************************************************************* + TEST(test_find_first_not_of_string_position) + { + static constexpr auto text_find_first_not_of_word = text.find_first_not_of(text_hello, 2); + CHECK_EQUAL(5, text_find_first_not_of_word); + + static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(text_llo_world, 2); + CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); + } + + //************************************************************************* + TEST(test_find_first_not_of_view_position) + { + static constexpr auto text_find_first_not_of_word = text.find_first_not_of(View(text_hello), 2); + CHECK_EQUAL(5, text_find_first_not_of_word); + + static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(View(text_llo_world), 2); + CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); + } + + //************************************************************************* + TEST(test_find_first_not_of_pointer_position) + { + static constexpr auto text_find_first_not_of_word = text.find_first_not_of(text_hello.data(), 2); + CHECK_EQUAL(5, text_find_first_not_of_word); + + static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(text_llo_world.data(), 2); + CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); + } + + //************************************************************************* + TEST(test_find_first_not_of_pointer_position_n) + { + static constexpr auto text_find_first_not_of_word = text.find_first_not_of(text_hello.data(), 2, text_hello.size()); + CHECK_EQUAL(5, text_find_first_not_of_word); + + static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(text_llo_world.data(), 2, text_llo_world.size()); + CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); + } + + //************************************************************************* + TEST(test_find_first_not_of_character_position) + { + static constexpr auto text_find_first_not_of_o = text.find_first_not_of(STR('l'), 2); + CHECK_EQUAL(4, text_find_first_not_of_o); + + static constexpr auto text_find_first_not_of_h = text.find_first_not_of(STR('h'), 2); + CHECK_EQUAL(2, text_find_first_not_of_h); + } + +// //************************************************************************* +// TEST(test_find_last_not_of_string_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); +// size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); +// position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST(test_find_last_not_of_view_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); +// size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); +// position2 = text.find_last_not_of(View(STR("ZEXD")), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); +// position2 = text.find_last_not_of(View(STR("ZEXD")), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); +// position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); +// position2 = text.find_last_not_of(View(STR("ZEXD")), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST(test_find_last_not_of_pointer_position) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); +// size_t position2 = text.find_last_not_of(STR("ZEXD")); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 3); +// position2 = text.find_last_not_of(STR("ZEXD"), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5); +// position2 = text.find_last_not_of(STR("ZEXD"), 5); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size()); +// position2 = text.find_last_not_of(STR("ZEXD"), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100); +// position2 = text.find_last_not_of(STR("ZEXD"), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST(test_find_last_not_of_pointer_position_n) +// { +// TextSTD compare_text(STR("ABCDEFABCDE")); +// Text text(STR("ABCDEFABCDE")); +// +// size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); +// size_t position2 = text.find_last_not_of(STR("ZEXD"), 0, 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5, 3); +// position2 = text.find_last_not_of(STR("ZEXD"), 5, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 1, 3); +// position2 = text.find_last_not_of(STR("ZEXD"), 1, 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size(), 4); +// position2 = text.find_last_not_of(STR("ZEXD"), text.size(), 4); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100, 4); +// position2 = text.find_last_not_of(STR("ZEXD"), 100, 4); +// +// CHECK_EQUAL(position1, position2); +// } +// +// //************************************************************************* +// TEST(test_find_last_not_of_character_position) +// { +// TextSTD compare_text(STR("ABCDEF")); +// Text text(STR("ABCDEF")); +// +// size_t position1 = compare_text.find_last_not_of(STR('F')); +// size_t position2 = text.find_last_not_of(STR('F')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('Z')); +// position2 = text.find_last_not_of(STR('Z')); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('A'), compare_text.size()); +// position2 = text.find_last_not_of(STR('A'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('C'), 3); +// position2 = text.find_last_not_of(STR('C'), 3); +// +// CHECK_EQUAL(position1, position2); +// +// position1 = compare_text.find_last_not_of(STR('C'), compare_text.size()); +// position2 = text.find_last_not_of(STR('C'), text.size()); +// +// CHECK_EQUAL(position1, position2); +// +//#include "etl/private/diagnostic_array_bounds_push.h" +// position1 = compare_text.find_last_not_of(STR('C'), 100); +// position2 = text.find_last_not_of(STR('C'), 100); +// +// CHECK_EQUAL(position1, position2); +//#include "etl/private/diagnostic_pop.h" +// } +// +// //************************************************************************* +// TEST(test_hash) +// { +// // Test with actual string type. +// Text text(STR("ABCDEFHIJKL")); +// size_t hash = etl::hash()(text); +// size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); +// CHECK_EQUAL(compare_hash, hash); +// +// // Test with interface string type. +// IText& itext = text; +// hash = etl::hash()(itext); +// CHECK_EQUAL(compare_hash, hash); +// } +// +// //************************************************************************* +// TEST(test_memcpy_repair) +// { +// Text text; +// +// text.assign(STR("ABCDEF")); +// +// char buffer[Sizeof(Text)]; +// +// memcpy(&buffer, (const void*)&text, Sizeof(text)); +// +// Text& rtext(*reinterpret_cast(buffer)); +// rtext.repair(); +// +// CHECK(!rtext.empty()); +// CHECK(!rtext.full()); +// +// bool is_equal = Equal(text, rtext); +// CHECK(is_equal); +// +// text = STR("GHIJKL"); +// is_equal = Equal(text, rtext); +// CHECK(!is_equal); +// } +// +// //************************************************************************* +// TEST(test_memcpy_repair_virtual) +// { +// Text text; +// +// text.assign(STR("ABCDEF")); +// +// char buffer[Sizeof(Text)]; +// +// memcpy(&buffer, (const void*)&text, Sizeof(text)); +// +// IText& itext(*reinterpret_cast(buffer)); +// itext.repair(); +// +// CHECK(!itext.empty()); +// CHECK(!itext.full()); +// +// bool is_equal = Equal(text, itext); +// CHECK(is_equal); +// +// text = STR("GHIJKL"); +// is_equal = Equal(text, itext); +// CHECK(!is_equal); +// } +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// //************************************************************************* +// TEST(test_truncate_over_many_operations) +// { +// Text text(short_text.c_str()); +// CHECK_FALSE(text.is_truncated()); +// +// text.insert(3, initial_text.c_str()); +// CHECK_TRUE(text.is_truncated()); +// +// while (text.size() != 0) +// { +// text.pop_back(); +// CHECK_TRUE(text.is_truncated()); +// } +// +// text.clear(); +// CHECK_FALSE(text.is_truncated()); +// +// text.assign(longer_text.c_str()); +// CHECK_TRUE(text.is_truncated()); +// +// text.assign(short_text.c_str()); +// CHECK_FALSE(text.is_truncated()); +// } +// +// //************************************************************************* +// TEST(test_add_from_truncated) +// { +// Text text1(short_text.c_str()); +// TextS text2(short_text.c_str()); +// +// CHECK_FALSE(text1.is_truncated()); +// CHECK_TRUE(text2.is_truncated()); +// +// // text2 has the truncate flag set. +// text1 += text2; +// +// CHECK(text1.is_truncated()); +// } +// +// //************************************************************************* +// TEST(test_add_to_truncated) +// { +// Text text1(longer_text.c_str()); +// Text text2(short_text.c_str()); +// +// CHECK(text1.is_truncated()); +// CHECK_FALSE(text2.is_truncated()); +// +// // Clear text but not the truncate flag. +// text1.erase(text1.begin(), text1.end()); +// +// // text1 still has the truncate flag set. +// text1 += text2; +// +// CHECK(text1.is_truncated()); +// } +// +// //************************************************************************* +// TEST(test_clear_truncated) +// { +// Text text(longer_text.c_str()); +// CHECK_TRUE(text.is_truncated()); +// +// text.clear_truncated(); +// CHECK_FALSE(text.is_truncated()); +// } +//#endif +// +//#if ETL_HAS_STRING_CLEAR_AFTER_USE +// //************************************************************************* +// TEST(test_secure_after_destructor) +// { +// char buffer[Sizeof(Text)]; +// std::fill_n(buffer, Sizeof(Text), 0); +// ::new (buffer) Text(STR("ABCDEF")); +// +// Text& text = *reinterpret_cast(buffer); +// text.set_secure(); +// +// CHECK(Text(STR("ABCDEF")) == text); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// // Destroy the text object. +// std::atomic_signal_fence(std::memory_order_seq_cst); +// text.~Text(); +// std::atomic_signal_fence(std::memory_order_seq_cst); +// +// // Check there no non-zero values in the string. +// CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST(test_secure_after_assign) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pe = text.end(); +// +// text.assign(STR("ABC")); +// +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST(test_secure_after_reSize_down) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pe = text.end(); +// +// text.reSize(text.size() - 3U); +// +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST(test_secure_after_erase) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// text.erase(pb + 2, pb + 5); +// +// // Check there no non-zero values in the remainder of the string. +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST(test_secure_after_replace) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// text.replace(pb + 1, pb + 4, STR("G")); +// +// // Check there no non-zero values in the remainder of the string. +// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); +// } +// +// //************************************************************************* +// TEST(test_secure_after_clear) +// { +// Text text; +// text.set_secure(); +// text.assign(STR("ABCDEF")); +// +// Text::pointer pb = text.begin(); +// Text::pointer pe = text.end(); +// +// text.clear(); +// +// // 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(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 +// +// //************************************************************************* +// TEST(test_initialize_free_space_empty_string) +// { +// Text empty; +// Text text; +// +// text.initialize_free_space(); +// +// CHECK(text.empty()); +// CHECK(text == empty); +// +// for (size_t i = text.size(); i < text.max_size(); ++i) +// { +// CHECK_EQUAL(0, text[i]); +// } +// } +// +// //************************************************************************* +// TEST(test_initialize_free_space_part_filled_string) +// { +// Text empty; +// Text initial = STR("ABC"); +// Text text(initial); +// +// text.initialize_free_space(); +// +// CHECK(text == initial); +// CHECK(text != empty); +// +// for (size_t i = text.size(); i < text.max_size(); ++i) +// { +// CHECK_EQUAL(0, text[i]); +// } +// } +// +// //************************************************************************* +// TEST(test_update_after_c_string_max_size) +// { +// Text text; +// +// text.initialize_free_space(); +// std::fill(text.data(), text.data() + text.max_size(), STR('A')); +// text.trim_to_terminator(); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// CHECK_EQUAL(text.max_size(), text.size()); +// } +// +// //************************************************************************* +// TEST(test_update_after_c_string_shorter_size) +// { +// Text text; +// +// text.initialize_free_space(); +// std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); +// text.trim_to_terminator(); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_FALSE(text.is_truncated()); +//#endif +// CHECK_EQUAL(text.max_size() - 1, text.size()); +// } +// +// //************************************************************************* +// TEST(test_update_after_c_string_greater_size) +// { +// Text text; +// +// text.initialize_free_space(); +// std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. +// text.trim_to_terminator(); +// +//#if ETL_HAS_STRING_TRUNCATION_CHECKS +// CHECK_TRUE(text.is_truncated()); +//#else +// CHECK_FALSE(text.is_truncated()); +//#endif +// CHECK_EQUAL(text.max_size(), text.size()); +// } +// +// //************************************************************************* +//#if ETL_USING_STL +// TEST(test_write_string_to_std_basic_ostream) +// { +// Text text1 = STR("Hello World"); +// +// std::stringstream sstream; +// +// sstream << text1; +// +// TextSTD sstream_string = sstream.str(); +// +// View sstream_view(sstream_string.data(), sstream_string.size()); +// +// CHECK(text1 == sstream_view); +// } +//#endif }; } From 76e4a33bef0cfac93ed3b2137efa18284f6ab114 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 31 Jul 2025 19:43:06 +0100 Subject: [PATCH 8/8] Create const_basic_string as a base to all const strings Removed constexpr from basic_string --- include/etl/basic_string.h | 172 +-- include/etl/const_basic_string.h | 313 +++++ include/etl/const_string.h | 90 +- include/etl/const_u16string.h | 92 ++ include/etl/const_u32string.h | 92 ++ include/etl/const_u8string.h | 94 ++ include/etl/const_wstring.h | 92 ++ include/etl/string_view.h | 22 +- test/CMakeLists.txt | 5 + test/test_const_string_char.cpp | 1846 +++------------------------- test/test_const_string_u16.cpp | 525 ++++++++ test/test_const_string_u32.cpp | 525 ++++++++ test/test_const_string_u8.cpp | 528 ++++++++ test/test_const_string_wchar_t.cpp | 543 ++++++++ test/vs2022/etl.vcxproj | 39 +- test/vs2022/etl.vcxproj.filters | 34 + 16 files changed, 3180 insertions(+), 1832 deletions(-) create mode 100644 include/etl/const_basic_string.h create mode 100644 include/etl/const_u16string.h create mode 100644 include/etl/const_u32string.h create mode 100644 include/etl/const_u8string.h create mode 100644 include/etl/const_wstring.h create mode 100644 test/test_const_string_u16.cpp create mode 100644 test/test_const_string_u32.cpp create mode 100644 test/test_const_string_u8.cpp create mode 100644 test/test_const_string_wchar_t.cpp diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index c35869c7..4bd24993 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -190,7 +190,7 @@ namespace etl /// Gets the current size of the string. ///\return The current size of the string. //************************************************************************* - ETL_CONSTEXPR14 size_type size() const + size_type size() const { return current_size; } @@ -199,7 +199,7 @@ namespace etl /// Gets the current size of the string. ///\return The current size of the string. //************************************************************************* - ETL_CONSTEXPR14 size_type length() const + size_type length() const { return current_size; } @@ -208,7 +208,7 @@ namespace etl /// Checks the 'empty' state of the string. ///\return true if empty. //************************************************************************* - ETL_CONSTEXPR14 bool empty() const + bool empty() const { return (current_size == 0); } @@ -217,7 +217,7 @@ namespace etl /// Checks the 'full' state of the string. ///\return true if full. //************************************************************************* - ETL_CONSTEXPR14 bool full() const + bool full() const { return current_size == CAPACITY; } @@ -226,7 +226,7 @@ namespace etl /// Returns the capacity of the string. ///\return The capacity of the string. //************************************************************************* - ETL_CONSTEXPR14 size_type capacity() const + size_type capacity() const { return CAPACITY; } @@ -235,7 +235,7 @@ namespace etl /// Returns the maximum possible size of the string. ///\return The maximum size of the string. //************************************************************************* - ETL_CONSTEXPR14 size_type max_size() const + size_type max_size() const { return CAPACITY; } @@ -244,7 +244,7 @@ namespace etl /// Returns the remaining capacity. ///\return The remaining capacity. //************************************************************************* - ETL_CONSTEXPR14 size_type available() const + size_type available() const { return max_size() - size(); } @@ -253,7 +253,7 @@ namespace etl /// Returns whether the string was truncated by the last operation. ///\return Whether the string was truncated by the last operation. //************************************************************************* - ETL_CONSTEXPR14 bool is_truncated() const + bool is_truncated() const { #if ETL_HAS_STRING_TRUNCATION_CHECKS return flags.test(); @@ -268,7 +268,7 @@ namespace etl ///\return Whether the string was truncated by the last operation. //************************************************************************* ETL_DEPRECATED - ETL_CONSTEXPR14 bool truncated() const + bool truncated() const { return is_truncated(); } @@ -296,7 +296,7 @@ namespace etl //************************************************************************* /// Gets the 'secure' state flag. //************************************************************************* - ETL_CONSTEXPR14 bool is_secure() const + bool is_secure() const { #if ETL_HAS_STRING_CLEAR_AFTER_USE return flags.test(); @@ -310,7 +310,7 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - ETL_CONSTEXPR14 string_base(size_type max_size_) + string_base(size_type max_size_) : current_size(0) , CAPACITY(max_size_) { @@ -329,7 +329,7 @@ namespace etl //************************************************************************* /// Destructor. //************************************************************************* - ETL_CONSTEXPR14 ~string_base() + ETL_CONSTEXPR20 ~string_base() { } @@ -378,7 +378,7 @@ namespace etl /// Returns a const_iterator to the beginning of the string. ///\return A const iterator to the beginning of the string. //********************************************************************* - ETL_CONSTEXPR14 const_iterator begin() const + const_iterator begin() const { return &p_buffer[0]; } @@ -396,7 +396,7 @@ namespace etl /// Returns a const_iterator to the end of the string. ///\return A const iterator to the end of the string. //********************************************************************* - ETL_CONSTEXPR14 const_iterator end() const + const_iterator end() const { return &p_buffer[current_size]; } @@ -405,7 +405,7 @@ namespace etl /// Returns a const_iterator to the beginning of the string. ///\return A const iterator to the beginning of the string. //********************************************************************* - ETL_CONSTEXPR14 const_iterator cbegin() const + const_iterator cbegin() const { return &p_buffer[0]; } @@ -414,7 +414,7 @@ namespace etl /// Returns a const_iterator to the end of the string. ///\return A const iterator to the end of the string. //********************************************************************* - ETL_CONSTEXPR14 const_iterator cend() const + const_iterator cend() const { return &p_buffer[current_size]; } @@ -432,7 +432,7 @@ namespace etl /// Returns a const reverse iterator to the reverse beginning of the string. ///\return Const iterator to the reverse beginning of the string. //********************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator rbegin() const + const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } @@ -441,7 +441,7 @@ namespace etl /// Returns a reverse iterator to the end + 1 of the string. ///\return Reverse iterator to the end + 1 of the string. //********************************************************************* - ETL_CONSTEXPR14 reverse_iterator rend() + reverse_iterator rend() { return reverse_iterator(begin()); } @@ -450,7 +450,7 @@ namespace etl /// Returns a const reverse iterator to the end + 1 of the string. ///\return Const reverse iterator to the end + 1 of the string. //********************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator rend() const + const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } @@ -459,7 +459,7 @@ namespace etl /// Returns a const reverse iterator to the reverse beginning of the string. ///\return Const reverse iterator to the reverse beginning of the string. //********************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator crbegin() const + const_reverse_iterator crbegin() const { return const_reverse_iterator(cend()); } @@ -468,7 +468,7 @@ namespace etl /// Returns a const reverse iterator to the end + 1 of the string. ///\return Const reverse iterator to the end + 1 of the string. //********************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator crend() const + const_reverse_iterator crend() const { return const_reverse_iterator(cbegin()); } @@ -568,7 +568,7 @@ namespace etl ///\param i The index. ///\return A const reference to the value at index 'i' //********************************************************************* - ETL_CONSTEXPR14 const_reference operator [](size_type i) const + const_reference operator [](size_type i) const { return p_buffer[i]; } @@ -591,7 +591,7 @@ namespace etl ///\param i The index. ///\return A const reference to the value at index 'i' //********************************************************************* - ETL_CONSTEXPR14 const_reference at(size_type i) const + const_reference at(size_type i) const { ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds)); return p_buffer[i]; @@ -610,7 +610,7 @@ namespace etl /// Returns a const reference to the first element. ///\return A const reference to the first element. //********************************************************************* - ETL_CONSTEXPR14 const_reference front() const + const_reference front() const { return p_buffer[0]; } @@ -628,7 +628,7 @@ namespace etl /// Returns a const reference to the last element. ///\return A const reference to the last element. //********************************************************************* - ETL_CONSTEXPR14 const_reference back() const + const_reference back() const { return p_buffer[current_size - 1]; } @@ -664,7 +664,7 @@ namespace etl /// Returns a const pointer to the beginning of the string data. ///\return A const pointer to the beginning of the string data. //********************************************************************* - ETL_CONSTEXPR14 const_pointer data_end() const + const_pointer data_end() const { return p_buffer + current_size; } @@ -1371,7 +1371,7 @@ namespace etl //********************************************************************* /// Return a pointer to a C string. //********************************************************************* - ETL_CONSTEXPR14 const_pointer c_str() const + const_pointer c_str() const { return p_buffer; } @@ -1382,7 +1382,7 @@ namespace etl ///\param count The number of characters to copy. ///\param pos The position to start copying from. //********************************************************************* - ETL_CONSTEXPR14 size_type copy(pointer dest, size_type count, size_type pos = 0) const + size_type copy(pointer dest, size_type count, size_type pos = 0) const { if (pos < size()) { @@ -1410,7 +1410,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find(const ibasic_string& str, size_type pos = 0) const + size_type find(const ibasic_string& str, size_type pos = 0) const { return find_impl(str.begin(), str.end(), str.size(), pos); } @@ -1421,7 +1421,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type find(const etl::basic_string_view& view, size_type pos = 0) const + size_type find(const etl::basic_string_view& view, size_type pos = 0) const { return find_impl(view.begin(), view.end(), view.size(), pos); } @@ -1431,7 +1431,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find(const_pointer s, size_type pos = 0) const + size_type find(const_pointer s, size_type pos = 0) const { size_t sz = etl::strlen(s); @@ -1444,7 +1444,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - ETL_CONSTEXPR14 size_type find(const_pointer s, size_type pos, size_type n) const + size_type find(const_pointer s, size_type pos, size_type n) const { size_t sz = etl::strlen(s); @@ -1456,7 +1456,7 @@ namespace etl ///\param c The character to find. ///\param position The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find(T c, size_type position = 0) const + size_type find(T c, size_type position = 0) const { const_iterator i = etl::find(begin() + position, end(), c); @@ -1475,7 +1475,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type rfind(const ibasic_string& str, size_type position = npos) const + size_type rfind(const ibasic_string& str, size_type position = npos) const { return rfind_impl(str.rbegin(), str.rend(), str.size(), position); } @@ -1486,7 +1486,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type rfind(const etl::basic_string_view& view, size_type pos = npos) const + size_type rfind(const etl::basic_string_view& view, size_type pos = npos) const { return rfind_impl(view.rbegin(), view.rend(), view.size(), pos); } @@ -1496,7 +1496,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type rfind(const_pointer s, size_type position = npos) const + size_type rfind(const_pointer s, size_type position = npos) const { size_type len = etl::strlen(s); @@ -1511,7 +1511,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type rfind(const_pointer s, size_type position, size_type length_) const + size_type rfind(const_pointer s, size_type position, size_type length_) const { const_reverse_iterator srbegin(s + length_); const_reverse_iterator srend(s); @@ -1524,7 +1524,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type rfind(T c, size_type position = npos) const + size_type rfind(T c, size_type position = npos) const { if (position >= size()) { @@ -1548,7 +1548,7 @@ namespace etl //********************************************************************* /// Checks that the string is within this string //********************************************************************* - ETL_CONSTEXPR14 bool contains(const etl::ibasic_string& str) const + bool contains(const etl::ibasic_string& str) const { return find(str) != npos; } @@ -1557,7 +1557,7 @@ namespace etl /// Checks that the view is within this string //********************************************************************* template - ETL_CONSTEXPR14 bool contains(const etl::basic_string_view& view) const + bool contains(const etl::basic_string_view& view) const { return find(view) != npos; } @@ -1565,7 +1565,7 @@ namespace etl //********************************************************************* /// Checks that text is within this string //********************************************************************* - ETL_CONSTEXPR14 bool contains(const_pointer s) const + bool contains(const_pointer s) const { return find(s) != npos; } @@ -1573,7 +1573,7 @@ namespace etl //********************************************************************* /// Checks that character is within this string //********************************************************************* - ETL_CONSTEXPR14 bool contains(value_type c) const + bool contains(value_type c) const { return find(c) != npos; } @@ -1581,7 +1581,7 @@ namespace etl //********************************************************************* /// Checks that the string is the start of this string //********************************************************************* - ETL_CONSTEXPR14 bool starts_with(const etl::ibasic_string& str) const + bool starts_with(const etl::ibasic_string& str) const { return compare(0, str.size(), str) == 0; } @@ -1590,7 +1590,7 @@ namespace etl /// Checks that the view is the start of this string //********************************************************************* template - ETL_CONSTEXPR14 bool starts_with(const etl::basic_string_view& view) const + bool starts_with(const etl::basic_string_view& view) const { return compare(0, view.size(), view) == 0; } @@ -1598,7 +1598,7 @@ namespace etl //********************************************************************* /// Checks that the string is the start of this string //********************************************************************* - ETL_CONSTEXPR14 bool starts_with(const_pointer s) const + bool starts_with(const_pointer s) const { size_t len = etl::strlen(s); @@ -1608,7 +1608,7 @@ namespace etl //********************************************************************* /// Checks that the character is the start of this string //********************************************************************* - ETL_CONSTEXPR14 bool starts_with(value_type c) const + bool starts_with(value_type c) const { return !empty() && (front() == c); } @@ -1616,7 +1616,7 @@ namespace etl //********************************************************************* /// Checks that the string is the end of this string //********************************************************************* - ETL_CONSTEXPR14 bool ends_with(const etl::ibasic_string& str) const + bool ends_with(const etl::ibasic_string& str) const { if (str.size() > size()) { @@ -1630,7 +1630,7 @@ namespace etl /// Checks that the view is the end of this string //********************************************************************* template - ETL_CONSTEXPR14 bool ends_with(const etl::basic_string_view& view) const + bool ends_with(const etl::basic_string_view& view) const { if (view.size() > size()) { @@ -1643,7 +1643,7 @@ namespace etl //********************************************************************* /// Checks that the string is the end of this string //********************************************************************* - ETL_CONSTEXPR14 bool ends_with(const_pointer s) const + bool ends_with(const_pointer s) const { size_t len = etl::strlen(s); @@ -1658,7 +1658,7 @@ namespace etl //********************************************************************* /// Checks that the character is the end of this string //********************************************************************* - ETL_CONSTEXPR14 bool ends_with(value_type c) const + bool ends_with(value_type c) const { return !empty() && (back() == c); } @@ -1949,7 +1949,7 @@ namespace etl //************************************************************************* /// Compare with string. //************************************************************************* - ETL_CONSTEXPR14 int compare(const ibasic_string& str) const + int compare(const ibasic_string& str) const { return compare(p_buffer, p_buffer + size(), @@ -1961,7 +1961,7 @@ namespace etl /// Compare with etl::basic_string_view. //************************************************************************* template - ETL_CONSTEXPR14 int compare(const etl::basic_string_view& view) const + int compare(const etl::basic_string_view& view) const { return compare(p_buffer, p_buffer + size(), @@ -1972,7 +1972,7 @@ namespace etl //************************************************************************* /// Compare position / length with string. //************************************************************************* - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const ibasic_string& str) const + int compare(size_type position, size_type length_, const ibasic_string& str) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1989,7 +1989,7 @@ namespace etl /// Compare position / length with etl::basic_string_view. //************************************************************************* template - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const etl::basic_string_view& view) const + int compare(size_type position, size_type length_, const etl::basic_string_view& view) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2000,7 +2000,7 @@ namespace etl //************************************************************************* /// Compare position / length with string / subposition / sublength. //************************************************************************* - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength) const + int compare(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); @@ -2019,7 +2019,7 @@ namespace etl /// Compare position / length with etl::basic_string_view. / subposition / sublength. //************************************************************************* template - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const + int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); @@ -2037,7 +2037,7 @@ namespace etl //************************************************************************* /// Compare with C string //************************************************************************* - ETL_CONSTEXPR14 int compare(const value_type* s) const + int compare(const value_type* s) const { return compare(p_buffer, p_buffer + size(), @@ -2048,7 +2048,7 @@ namespace etl //************************************************************************* /// Compare position / length with C string. //************************************************************************* - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const_pointer s) const + int compare(size_type position, size_type length_, const_pointer s) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2059,7 +2059,7 @@ namespace etl //************************************************************************* /// Compare position / length with C string / n. //************************************************************************* - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const_pointer s, size_type n) const + int compare(size_type position, size_type length_, const_pointer s, size_type n) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2072,7 +2072,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_of(const ibasic_string& str, size_type position = 0) const + size_type find_first_of(const ibasic_string& str, size_type position = 0) const { return find_first_of(str.c_str(), position, str.size()); } @@ -2082,7 +2082,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_of(const_pointer s, size_type position = 0) const + size_type find_first_of(const_pointer s, size_type position = 0) const { return find_first_of(s, position, etl::strlen(s)); } @@ -2093,7 +2093,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const + size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_of(view.data(), position, view.size()); } @@ -2104,7 +2104,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_of(const_pointer s, size_type position, size_type n) const + size_type find_first_of(const_pointer s, size_type position, size_type n) const { if (position < size()) { @@ -2128,7 +2128,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_of(value_type c, size_type position = 0) const + size_type find_first_of(value_type c, size_type position = 0) const { if (position < size()) { @@ -2149,7 +2149,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_of(const ibasic_string& str, size_type position = npos) const + size_type find_last_of(const ibasic_string& str, size_type position = npos) const { return find_last_of(str.c_str(), position, str.size()); } @@ -2159,7 +2159,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_of(const_pointer s, size_type position = npos) const + size_type find_last_of(const_pointer s, size_type position = npos) const { return find_last_of(s, position, etl::strlen(s)); } @@ -2170,7 +2170,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const + size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_of(view.data(), position, view.size()); } @@ -2181,7 +2181,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_of(const_pointer s, size_type position, size_type n) const + size_type find_last_of(const_pointer s, size_type position, size_type n) const { if (empty()) { @@ -2214,7 +2214,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_of(value_type c, size_type position = npos) const + size_type find_last_of(value_type c, size_type position = npos) const { if (empty()) { @@ -2244,7 +2244,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_not_of(const ibasic_string& str, size_type position = 0) const + size_type find_first_not_of(const ibasic_string& str, size_type position = 0) const { return find_first_not_of(str.c_str(), position, str.size()); } @@ -2254,7 +2254,7 @@ namespace etl ///\param s Pointer to the content to not find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_not_of(const_pointer s, size_type position = 0) const + size_type find_first_not_of(const_pointer s, size_type position = 0) const { return find_first_not_of(s, position, etl::strlen(s)); } @@ -2265,7 +2265,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const + size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_not_of(view.data(), position, view.size()); } @@ -2276,7 +2276,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_not_of(const_pointer s, size_type position, size_type n) const + size_type find_first_not_of(const_pointer s, size_type position, size_type n) const { if (position < size()) { @@ -2307,7 +2307,7 @@ namespace etl ///\param c The character to not find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_not_of(value_type c, size_type position = 0) const + size_type find_first_not_of(value_type c, size_type position = 0) const { if (position < size()) { @@ -2328,7 +2328,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_not_of(const ibasic_string& str, size_type position = npos) const + size_type find_last_not_of(const ibasic_string& str, size_type position = npos) const { return find_last_not_of(str.c_str(), position, str.size()); } @@ -2338,7 +2338,7 @@ namespace etl ///\param s The pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_not_of(const_pointer s, size_type position = npos) const + size_type find_last_not_of(const_pointer s, size_type position = npos) const { return find_last_not_of(s, position, etl::strlen(s)); } @@ -2349,7 +2349,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const + size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_not_of(view.data(), position, view.size()); } @@ -2360,7 +2360,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to use. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_not_of(const_pointer s, size_type position, size_type n) const + size_type find_last_not_of(const_pointer s, size_type position, size_type n) const { if (empty()) { @@ -2398,7 +2398,7 @@ namespace etl //********************************************************************* // //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_not_of(value_type c, size_type position = npos) const + size_type find_last_not_of(value_type c, size_type position = npos) const { if (empty()) { @@ -2536,7 +2536,7 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - ETL_CONSTEXPR14 ibasic_string(T* p_buffer_, size_type MAX_SIZE_) + ibasic_string(T* p_buffer_, size_type MAX_SIZE_) : string_base(MAX_SIZE_), p_buffer(p_buffer_) { @@ -2545,7 +2545,7 @@ namespace etl //********************************************************************* /// Initialise the string. //********************************************************************* - ETL_CONSTEXPR14 void initialise() + void initialise() { current_size = 0U; p_buffer[0] = 0; @@ -2567,7 +2567,7 @@ namespace etl //************************************************************************* /// Compare helper function //************************************************************************* - ETL_CONSTEXPR14 static int compare(const_pointer first1, const_pointer last1, + static int compare(const_pointer first1, const_pointer last1, const_pointer first2, const_pointer last2) { typedef typename etl::make_unsigned::type type; @@ -2644,7 +2644,7 @@ namespace etl #else protected: #endif - ETL_CONSTEXPR14 ~ibasic_string() + ETL_CONSTEXPR20 ~ibasic_string() { #if ETL_HAS_STRING_CLEAR_AFTER_USE if (is_secure()) @@ -2659,7 +2659,7 @@ namespace etl //************************************************************************* /// Convert from const_iterator to iterator //************************************************************************* - ETL_CONSTEXPR14 iterator to_iterator(const_iterator itr) const + iterator to_iterator(const_iterator itr) const { return const_cast(itr); } @@ -2782,7 +2782,7 @@ namespace etl /// Common implementation for 'find'. //************************************************************************* template - ETL_CONSTEXPR14 size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const + size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const { if ((pos + sz) > size()) { @@ -2805,7 +2805,7 @@ namespace etl /// Common implementation for 'rfind'. //************************************************************************* template - ETL_CONSTEXPR14 size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const + size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const { if (sz > size()) { diff --git a/include/etl/const_basic_string.h b/include/etl/const_basic_string.h new file mode 100644 index 00000000..142933c0 --- /dev/null +++ b/include/etl/const_basic_string.h @@ -0,0 +1,313 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +#ifndef ETL_CONST_BASIC_STRING_INCLUDED +#define ETL_CONST_BASIC_STRING_INCLUDED + +#include "platform.h" +#include "iterator.h" +#include "char_traits.h" + +#if ETL_USING_CPP14 + +namespace etl +{ + //*************************************************************************** + /// A string implementation that uses a fixed size external const buffer. + ///\ingroup string + //*************************************************************************** + template + class const_basic_string + { + public: + + using value_type = T; + using size_type = size_t; + using const_pointer = const value_type*; + using const_reference = const value_type&; + using const_iterator = const value_type*; + + using const_reverse_iterator = etl::reverse_iterator; + + //************************************************************************* + /// Gets the size of the string. + //************************************************************************* + ETL_NODISCARD + constexpr size_t size() const noexcept + { + return buffer_size; + } + + //************************************************************************* + /// Gets the size of the string. + //************************************************************************* + ETL_NODISCARD + constexpr size_t length() const noexcept + { + return buffer_size; + } + + //************************************************************************* + /// Gets the capacity of the string. + //************************************************************************* + ETL_NODISCARD + constexpr size_t capacity() const noexcept + { + return buffer_size; + } + + //************************************************************************* + /// Gets the maximum size of the string. + //************************************************************************* + ETL_NODISCARD + constexpr size_t max_size() const noexcept + { + return buffer_size; + } + + //************************************************************************* + /// Gets the amount of free space in the string. + //************************************************************************* + ETL_NODISCARD + constexpr size_t available() const noexcept + { + return 0U; + } + + //************************************************************************* + /// Gets the start of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_iterator begin() const noexcept + { + return p_buffer; + } + + //************************************************************************* + /// Gets the start of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_iterator cbegin() const noexcept + { + return p_buffer; + } + + //************************************************************************* + /// Gets the reverse start of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reverse_iterator rbegin() const noexcept + { + return const_reverse_iterator(end()); + } + + //************************************************************************* + /// Gets the reverse start of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reverse_iterator crbegin() const noexcept + { + return const_reverse_iterator(end()); + } + + //************************************************************************* + /// Gets the end of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_iterator end() const noexcept + { + return p_buffer + buffer_size; + } + + //************************************************************************* + /// Gets the end of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_iterator cend() const noexcept + { + return p_buffer + buffer_size; + } + + //************************************************************************* + /// Gets the reverse end of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reverse_iterator rend() const noexcept + { + return const_reverse_iterator(begin()); + } + + //************************************************************************* + /// Gets the reverse end of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reverse_iterator crend() const noexcept + { + return const_reverse_iterator(begin()); + } + + //************************************************************************* + /// Gets the start of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_pointer data() const noexcept + { + return p_buffer; + } + + //************************************************************************* + /// Gets the end of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_pointer data_end() const noexcept + { + return p_buffer + buffer_size; + } + + //********************************************************************* + /// Return a pointer to a C string. + //********************************************************************* + ETL_NODISCARD + constexpr const_pointer c_str() const + { + return p_buffer; + } + + //************************************************************************* + /// Is the string empty? + //************************************************************************* + ETL_NODISCARD + constexpr bool empty() const noexcept + { + return buffer_size == 0U; + } + + //************************************************************************* + /// Is the string full? + //************************************************************************* + ETL_NODISCARD + constexpr bool full() const noexcept + { + return true; + } + + //************************************************************************* + /// Is the string truncated? + //************************************************************************* + ETL_NODISCARD + constexpr bool is_truncated() const noexcept + { + return truncated_state; + } + + //************************************************************************* + /// Is the string secure? + //************************************************************************* + ETL_NODISCARD + constexpr bool is_secure() const noexcept + { + return false; + } + + //************************************************************************* + /// Returns a const reference to the value at the index. + //************************************************************************* + ETL_NODISCARD + constexpr const_reference operator [](int i) const noexcept + { + return p_buffer[i]; + } + + //************************************************************************* + /// Returns a const reference to the value at the index. + //************************************************************************* + ETL_NODISCARD + constexpr const_reference at(int i) const noexcept + { + return p_buffer[i]; + } + + //************************************************************************* + /// Returns a const reference to the value at the front of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reference front() const noexcept + { + return p_buffer[0]; + } + + //************************************************************************* + /// Returns a const reference to the value at the front of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reference back() const noexcept + { + return p_buffer[buffer_size - 1U]; + } + + protected: + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_basic_string(const value_type* buffer, size_t buff_size, bool is_truncated) + : p_buffer(buffer) + , buffer_size(buff_size) + , truncated_state(is_truncated) + { + } + + private: + + const value_type* p_buffer; + const size_t buffer_size; + const bool truncated_state; + }; + + //*************************************************************************** + /// Operator overload to write to std basic_ostream + ///\param os Reference to the output stream. + ///\param str Reference to the string to write. + ///\return Reference to the output stream, for chaining write operations. + ///\ingroup string + //*************************************************************************** +#if ETL_USING_STL + template + std::basic_ostream > &operator<<(std::basic_ostream > &os, + const etl::const_basic_string& str) + { + os.write(str.data(), str.size()); + return os; + } +#endif +} + +#endif +#endif diff --git a/include/etl/const_string.h b/include/etl/const_string.h index 9ce057fe..123164b6 100644 --- a/include/etl/const_string.h +++ b/include/etl/const_string.h @@ -32,111 +32,63 @@ SOFTWARE. #define ETL_CONST_STRING_INCLUDED #include "platform.h" -#include "string.h" -#include "hash.h" +#include "iterator.h" +#include "char_traits.h" +#include "const_basic_string.h" -#include - -#include "private/minmax_push.h" +#if ETL_USING_CPP14 namespace etl { //*************************************************************************** - /// A string implementation that uses a fixed size external buffer. + /// A string implementation that uses a fixed size external const buffer. ///\ingroup string //*************************************************************************** - class const_string : public istring + class const_string : public etl::const_basic_string { public: - typedef istring base_type; - typedef istring interface_type; + using value_type = const_basic_string::value_type; + using size_type = const_basic_string::size_type; + using const_pointer = const_basic_string::const_pointer; + using const_reference = const_basic_string::const_reference; + using const_iterator = const_basic_string::const_iterator; - typedef istring::value_type value_type; - typedef istring::size_type size_type; + using const_reverse_iterator = const_basic_string::const_reverse_iterator; //************************************************************************* /// Constructor. //************************************************************************* - constexpr const_string(const value_type* buffer) - : istring(const_cast(buffer), etl::strlen(buffer)) - { - this->current_size = etl::strlen(buffer); + constexpr const_string(const value_type* buffer, bool is_truncated = false) + : const_basic_string(buffer, etl::strlen(buffer), is_truncated) + { } //************************************************************************* /// Constructor. //************************************************************************* - constexpr const_string(const value_type* buffer, size_t length) - : istring(const_cast(buffer), length) + constexpr const_string(const value_type* buffer, size_t length, bool is_truncated = false) + : const_basic_string(buffer, length, is_truncated) { - this->current_size = length; } //************************************************************************* /// Constructor. //************************************************************************* - constexpr const_string(const value_type* buffer, const value_type* buffer_end) - : istring(const_cast(buffer), buffer_end - buffer) + constexpr const_string(const value_type* buffer, const value_type* buffer_end, bool is_truncated = false) + : const_basic_string(buffer, buffer_end - buffer, is_truncated) { - this->current_size = buffer_end - buffer; - } - - //************************************************************************* - /// Constructor. - //************************************************************************* - constexpr const_string(const etl::string_view& view) - : istring(const_cast(view.data()), view.size()) - { - this->current_size = view.size(); } //************************************************************************* /// Copy constructor. //************************************************************************* constexpr const_string(const etl::const_string& other) - : istring(const_cast(other.data()), other.size()) - { - this->current_size = other.size(); - } - - //************************************************************************* - /// Returns a sub-string. - ///\param position The position of the first character. Default = 0. - ///\param length The number of characters. Default = npos. - //************************************************************************* - constexpr etl::const_string substr(size_type position = 0, size_type length_ = npos) const - { - if (position < this->size()) - { - length_ = etl::min(length_, this->size() - position); - - return etl::const_string(data() + position, length_); - } - - return etl::const_string(""); - } - - //************************************************************************* - /// Fix the internal pointers after a low level memory copy. - //************************************************************************* -#if ETL_HAS_ISTRING_REPAIR - constexpr virtual void repair() ETL_OVERRIDE -#else - constexpr void repair() -#endif + : const_basic_string(other.data(), other.size(), other.is_truncated()) { } - - private: - - //************************************************************************* - /// Deleted. - //************************************************************************* - //const_string(const const_string& other) ETL_DELETE; }; } -#include "private/minmax_pop.h" - +#endif #endif diff --git a/include/etl/const_u16string.h b/include/etl/const_u16string.h new file mode 100644 index 00000000..ce98322a --- /dev/null +++ b/include/etl/const_u16string.h @@ -0,0 +1,92 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +#ifndef ETL_CONST_U16STRING_INCLUDED +#define ETL_CONST_U16STRING_INCLUDED + +#include "platform.h" +#include "const_basic_string.h" + +#if ETL_USING_CPP14 + +namespace etl +{ + //*************************************************************************** + /// A string implementation that uses a fixed size external const buffer. + ///\ingroup string + //*************************************************************************** + class const_u16string : public etl::const_basic_string + { + public: + + using value_type = const_basic_string::value_type; + using size_type = const_basic_string::size_type; + using const_pointer = const_basic_string::const_pointer; + using const_reference = const_basic_string::const_reference; + using const_iterator = const_basic_string::const_iterator; + + using const_reverse_iterator = const_basic_string::const_reverse_iterator; + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u16string(const value_type* buffer, bool is_truncated = false) + : const_basic_string(buffer, etl::strlen(buffer), is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u16string(const value_type* buffer, size_t length, bool is_truncated = false) + : const_basic_string(buffer, length, is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u16string(const value_type* buffer, const value_type* buffer_end, bool is_truncated = false) + : const_basic_string(buffer, buffer_end - buffer, is_truncated) + { + } + + //************************************************************************* + /// Copy constructor. + //************************************************************************* + constexpr const_u16string(const etl::const_u16string& other) + : const_basic_string(other.data(), other.size(), other.is_truncated()) + { + } + }; +} + +#endif +#endif diff --git a/include/etl/const_u32string.h b/include/etl/const_u32string.h new file mode 100644 index 00000000..53b32dc0 --- /dev/null +++ b/include/etl/const_u32string.h @@ -0,0 +1,92 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +#ifndef ETL_CONST_U32STRING_INCLUDED +#define ETL_CONST_U32STRING_INCLUDED + +#include "platform.h" +#include "const_basic_string.h" + +#if ETL_USING_CPP14 + +namespace etl +{ + //*************************************************************************** + /// A string implementation that uses a fixed size external const buffer. + ///\ingroup string + //*************************************************************************** + class const_u32string : public etl::const_basic_string + { + public: + + using value_type = const_basic_string::value_type; + using size_type = const_basic_string::size_type; + using const_pointer = const_basic_string::const_pointer; + using const_reference = const_basic_string::const_reference; + using const_iterator = const_basic_string::const_iterator; + + using const_reverse_iterator = const_basic_string::const_reverse_iterator; + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u32string(const value_type* buffer, bool is_truncated = false) + : const_basic_string(buffer, etl::strlen(buffer), is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u32string(const value_type* buffer, size_t length, bool is_truncated = false) + : const_basic_string(buffer, length, is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u32string(const value_type* buffer, const value_type* buffer_end, bool is_truncated = false) + : const_basic_string(buffer, buffer_end - buffer, is_truncated) + { + } + + //************************************************************************* + /// Copy constructor. + //************************************************************************* + constexpr const_u32string(const etl::const_u32string& other) + : const_basic_string(other.data(), other.size(), other.is_truncated()) + { + } + }; +} + +#endif +#endif diff --git a/include/etl/const_u8string.h b/include/etl/const_u8string.h new file mode 100644 index 00000000..08d01581 --- /dev/null +++ b/include/etl/const_u8string.h @@ -0,0 +1,94 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +#ifndef ETL_CONST_U8STRING_INCLUDED +#define ETL_CONST_U8STRING_INCLUDED + +#include "platform.h" +#include "const_basic_string.h" + +#if ETL_USING_CPP14 + +#if ETL_HAS_CHAR8_T +namespace etl +{ + //*************************************************************************** + /// A string implementation that uses a fixed size external const buffer. + ///\ingroup string + //*************************************************************************** + class const_u8string : public etl::const_basic_string + { + public: + + using value_type = const_basic_string::value_type; + using size_type = const_basic_string::size_type; + using const_pointer = const_basic_string::const_pointer; + using const_reference = const_basic_string::const_reference; + using const_iterator = const_basic_string::const_iterator; + + using const_reverse_iterator = const_basic_string::const_reverse_iterator; + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u8string(const value_type* buffer, bool is_truncated = false) + : const_basic_string(buffer, etl::strlen(buffer), is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u8string(const value_type* buffer, size_t length, bool is_truncated = false) + : const_basic_string(buffer, length, is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u8string(const value_type* buffer, const value_type* buffer_end, bool is_truncated = false) + : const_basic_string(buffer, buffer_end - buffer, is_truncated) + { + } + + //************************************************************************* + /// Copy constructor. + //************************************************************************* + constexpr const_u8string(const etl::const_u8string& other) + : const_basic_string(other.data(), other.size(), other.is_truncated()) + { + } + }; +} + +#endif +#endif +#endif diff --git a/include/etl/const_wstring.h b/include/etl/const_wstring.h new file mode 100644 index 00000000..b1d866b3 --- /dev/null +++ b/include/etl/const_wstring.h @@ -0,0 +1,92 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +#ifndef ETL_CONST_WSTRING_INCLUDED +#define ETL_CONST_WSTRING_INCLUDED + +#include "platform.h" +#include "const_basic_string.h" + +#if ETL_USING_CPP14 + +namespace etl +{ + //*************************************************************************** + /// A string implementation that uses a fixed size external const buffer. + ///\ingroup string + //*************************************************************************** + class const_wstring : public etl::const_basic_string + { + public: + + using value_type = const_basic_string::value_type; + using size_type = const_basic_string::size_type; + using const_pointer = const_basic_string::const_pointer; + using const_reference = const_basic_string::const_reference; + using const_iterator = const_basic_string::const_iterator; + + using const_reverse_iterator = const_basic_string::const_reverse_iterator; + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_wstring(const value_type* buffer, bool is_truncated = false) + : const_basic_string(buffer, etl::strlen(buffer), is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_wstring(const value_type* buffer, size_t length, bool is_truncated = false) + : const_basic_string(buffer, length, is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_wstring(const value_type* buffer, const value_type* buffer_end, bool is_truncated = false) + : const_basic_string(buffer, buffer_end - buffer, is_truncated) + { + } + + //************************************************************************* + /// Copy constructor. + //************************************************************************* + constexpr const_wstring(const etl::const_wstring& other) + : const_basic_string(other.data(), other.size(), other.is_truncated()) + { + } + }; +} + +#endif +#endif diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 62f42772..f35bbac4 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -40,6 +40,7 @@ SOFTWARE. #include "integral_limits.h" #include "hash.h" #include "basic_string.h" +#include "const_basic_string.h" #include "algorithm.h" #include "private/minmax_push.h" @@ -69,7 +70,7 @@ namespace etl }; //*************************************************************************** - ///\ingroup stack + ///\ingroup string /// The exception thrown when the index is out of bounds. //*************************************************************************** class string_view_bounds : public string_view_exception @@ -83,7 +84,7 @@ namespace etl }; //*************************************************************************** - ///\ingroup stack + ///\ingroup string /// The exception thrown when the view is uninitialised. //*************************************************************************** class string_view_uninitialised : public string_view_exception @@ -138,6 +139,17 @@ namespace etl { } +#if ETL_USING_CPP14 + //************************************************************************* + /// Construct from const_string. + //************************************************************************* + ETL_CONSTEXPR basic_string_view(const etl::const_basic_string& str) + : mbegin(str.begin()) + , mend(str.end()) + { + } +#endif + //************************************************************************* /// Construct from T*. //************************************************************************* @@ -563,9 +575,9 @@ namespace etl position = etl::min(position, size()); const_iterator iposition = etl::find_end(begin(), - begin() + position, - view.begin(), - view.end()); + begin() + position, + view.begin(), + view.end()); if (iposition == end()) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 64d11735..bf84d730 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,6 +61,11 @@ add_executable(etl_tests test_const_map_constexpr.cpp test_const_multimap.cpp test_const_multimap_constexpr.cpp + test_const_string_char.cpp + test_const_string_u16.cpp + test_const_string_u32.cpp + test_const_string_u8.cpp + test_const_string_wchar_t.cpp test_char_traits.cpp test_checksum.cpp test_chrono_clocks.cpp diff --git a/test/test_const_string_char.cpp b/test/test_const_string_char.cpp index 6cdecc68..84417677 100644 --- a/test/test_const_string_char.cpp +++ b/test/test_const_string_char.cpp @@ -36,67 +36,36 @@ SOFTWARE. #include "etl/const_string.h" #include "etl/string_view.h" +#if ETL_USING_CPP14 + #undef STR #define STR(x) x namespace { - bool compares_agree(int result1, int result2) + SUITE(test_const_string_char) { - return ((result1 < 0) && (result2 < 0)) || - ((result1 == 0) && (result2 == 0)) || - ((result1 > 0) && (result2 > 0)); - } + using Text = etl::const_string; + using View = etl::string_view; - SUITE(test_string_char) - { - using Text = etl::const_string; - using IText = etl::istring; using TextSTD = std::string; - using View = etl::string_view; - constexpr const char* text_pointer = STR("Hello World"); - - static constexpr const char* ccp_hello = STR("Hello"); - static constexpr const char* ccp_world = STR("World"); - static constexpr const char* ccp_worls = STR("Worls"); - - static constexpr Text text_he(STR("He")); - static constexpr Text text_llo_world(STR("llo World")); - static constexpr Text text_hello(STR("Hello")); - static constexpr Text text_word(STR("Word")); - static constexpr Text text_rd(STR("rd")); - - static constexpr Text text(STR("Hello World")); - static constexpr Text text_same(STR("Hello World")); - static constexpr Text text_less(STR("Hello Wnrld")); - static constexpr Text text_greater(STR("Hello Wprld")); - static constexpr Text text_less_length(STR("Hello Worl")); - static constexpr Text text_greater_length(STR("Hello World!")); - - static constexpr size_t length = etl::strlen(STR("Hello World")); - - static constexpr Text text_xxx(STR("xxxHello Worldxxx")); - static constexpr Text text_same_xxx(STR("xxxHello World")); - static constexpr Text text_less_xxx(STR("xxxHello Wnrldxxx")); - static constexpr Text text_greater_xxx(STR("xxxHello Wprldxxx")); - static constexpr Text text_less_length_xxx(STR("xxxHello Worlxxx")); - static constexpr Text text_greater_length_xxx(STR("xxxHello World!xxx")); - - static constexpr const IText& itext = text; + static constexpr Text::const_pointer text_pointer = STR("Hello World"); + static constexpr Text text(STR("Hello World")); + static constexpr size_t Length = etl::strlen(STR("Hello World")); //************************************************************************* template - bool Equal(const T1& compare_text, const T2& text) + bool Equal(const T1& compare_text, const T2& test_text) { - return (compare_text.size() == text.size()) && std::equal(text.begin(), text.end(), compare_text.begin()); + return (compare_text.size() == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text.begin()); } //************************************************************************* template - bool Equal(const T1* compare_text, const T2& text) + bool Equal(const T1* compare_text, const T2& test_text) { - return (etl::strlen(compare_text) == text.size()) && std::equal(text.begin(), text.end(), compare_text); + return (etl::strlen(compare_text) == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text); } //************************************************************************* @@ -144,16 +113,16 @@ namespace CHECK_TRUE(text_full); static constexpr auto text_capacity = text_from_pointer.capacity(); - CHECK_EQUAL(length, text_capacity); + CHECK_EQUAL(Length, text_capacity); static constexpr auto text_max_size = text_from_pointer.max_size(); - CHECK_EQUAL(length, text_max_size); + CHECK_EQUAL(Length, text_max_size); static constexpr auto text_size = text_from_pointer.size(); - CHECK_EQUAL(length, text_size); + CHECK_EQUAL(Length, text_size); static constexpr auto text_length = text_from_pointer.length(); - CHECK_EQUAL(length, text_length); + CHECK_EQUAL(Length, text_length); static constexpr auto text_available = text_from_pointer.available(); CHECK_EQUAL(0, text_available); @@ -164,11 +133,11 @@ namespace static constexpr auto text_is_secure = text_from_pointer.is_secure(); CHECK_FALSE(text_is_secure); - static constexpr const char* text_data = text_from_pointer.data(); + static constexpr Text::const_pointer text_data = text_from_pointer.data(); CHECK_EQUAL(&text_pointer[0], text_data); - static constexpr const char* text_data_end = text_from_pointer.data_end(); - CHECK_EQUAL(&text_pointer[length], text_data_end); + static constexpr Text::const_pointer text_data_end = text_from_pointer.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); static constexpr auto text_begin = text_from_pointer.begin(); CHECK_EQUAL(&text_pointer[0], text_begin); @@ -177,16 +146,16 @@ namespace CHECK_EQUAL(&text_pointer[0], text_cbegin); static constexpr auto text_rbegin = text_from_pointer.rbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_rbegin)); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); static constexpr auto text_crbegin = text_from_pointer.crbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_crbegin)); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); static constexpr auto text_end = text_from_pointer.end(); - CHECK_EQUAL(&text_pointer[length], text_end); + CHECK_EQUAL(&text_pointer[Length], text_end); static constexpr auto text_cend = text_from_pointer.cend(); - CHECK_EQUAL(&text_pointer[length], text_cend); + CHECK_EQUAL(&text_pointer[Length], text_cend); static constexpr auto text_rend = text_from_pointer.rend(); CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); @@ -210,16 +179,16 @@ namespace CHECK_TRUE(text_full); static constexpr auto text_capacity = text_from_literal.capacity(); - CHECK_EQUAL(length, text_capacity); + CHECK_EQUAL(Length, text_capacity); static constexpr auto text_max_size = text_from_literal.max_size(); - CHECK_EQUAL(length, text_max_size); + CHECK_EQUAL(Length, text_max_size); static constexpr auto text_size = text_from_literal.size(); - CHECK_EQUAL(length, text_size); + CHECK_EQUAL(Length, text_size); static constexpr auto text_length = text_from_literal.length(); - CHECK_EQUAL(length, text_length); + CHECK_EQUAL(Length, text_length); static constexpr auto text_available = text_from_literal.available(); CHECK_EQUAL(0, text_available); @@ -230,11 +199,11 @@ namespace static constexpr auto text_is_secure = text_from_literal.is_secure(); CHECK_FALSE(text_is_secure); - static constexpr const char* text_data = text_from_literal.data(); + static constexpr Text::const_pointer text_data = text_from_literal.data(); CHECK_EQUAL(&text_pointer[0], text_data); - static constexpr const char* text_data_end = text_from_literal.data_end(); - CHECK_EQUAL(&text_pointer[length], text_data_end); + static constexpr Text::const_pointer text_data_end = text_from_literal.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); static constexpr auto text_begin = text_from_literal.begin(); CHECK_EQUAL(&text_pointer[0], text_begin); @@ -243,16 +212,16 @@ namespace CHECK_EQUAL(&text_pointer[0], text_cbegin); static constexpr auto text_rbegin = text_from_literal.rbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_rbegin)); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); static constexpr auto text_crbegin = text_from_literal.crbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_crbegin)); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); static constexpr auto text_end = text_from_literal.end(); - CHECK_EQUAL(&text_pointer[length], text_end); + CHECK_EQUAL(&text_pointer[Length], text_end); static constexpr auto text_cend = text_from_literal.cend(); - CHECK_EQUAL(&text_pointer[length], text_cend); + CHECK_EQUAL(&text_pointer[Length], text_cend); static constexpr auto text_rend = text_from_literal.rend(); CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); @@ -265,65 +234,145 @@ namespace } //************************************************************************* - TEST(test_constructor_from_etl_string_view) + TEST(test_constructor_truncated) { - static constexpr Text text_from_view(View(STR("Hello World"))); + static constexpr Text text_from_pointer(text_pointer, true); + static constexpr Text text_from_literal(STR("Hello World"), true); - static constexpr auto text_empty = text_from_view.empty(); + static constexpr auto text_from_pointer_is_truncated = text_from_pointer.is_truncated(); + CHECK_TRUE(text_from_pointer_is_truncated); + + static constexpr auto text_from_literal_is_truncated = text_from_literal.is_truncated(); + CHECK_TRUE(text_from_literal_is_truncated); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + static constexpr Text text_copy(text); + + static constexpr auto text_empty = text_copy.empty(); CHECK_FALSE(text_empty); - static constexpr auto text_full = text_from_view.full(); + static constexpr auto text_full = text_copy.full(); CHECK_TRUE(text_full); - static constexpr auto text_capacity = text_from_view.capacity(); - CHECK_EQUAL(length, text_capacity); + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); - static constexpr auto text_max_size = text_from_view.max_size(); - CHECK_EQUAL(length, text_max_size); + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); - static constexpr auto text_size = text_from_view.size(); - CHECK_EQUAL(length, text_size); + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); - static constexpr auto text_length = text_from_view.length(); - CHECK_EQUAL(length, text_length); + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); - static constexpr auto text_available = text_from_view.available(); + static constexpr auto text_available = text_copy.available(); CHECK_EQUAL(0, text_available); - static constexpr auto text_is_truncated = text_from_view.is_truncated(); + static constexpr auto text_is_truncated = text_copy.is_truncated(); CHECK_FALSE(text_is_truncated); - static constexpr auto text_is_secure = text_from_view.is_secure(); + static constexpr auto text_is_secure = text_copy.is_secure(); CHECK_FALSE(text_is_secure); - static constexpr const char* text_data = text_from_view.data(); + static constexpr Text::const_pointer text_data = text_copy.data(); CHECK_EQUAL(&text_pointer[0], text_data); - static constexpr const char* text_data_end = text_from_view.data_end(); - CHECK_EQUAL(&text_pointer[length], text_data_end); + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); - static constexpr auto text_begin = text_from_view.begin(); + static constexpr auto text_begin = text_copy.begin(); CHECK_EQUAL(&text_pointer[0], text_begin); - static constexpr auto text_cbegin = text_from_view.cbegin(); + static constexpr auto text_cbegin = text_copy.cbegin(); CHECK_EQUAL(&text_pointer[0], text_cbegin); - static constexpr auto text_rbegin = text_from_view.rbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_rbegin)); + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); - static constexpr auto text_crbegin = text_from_view.crbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_crbegin)); + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); - static constexpr auto text_end = text_from_view.end(); - CHECK_EQUAL(&text_pointer[length], text_end); + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); - static constexpr auto text_cend = text_from_view.cend(); - CHECK_EQUAL(&text_pointer[length], text_cend); + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); - static constexpr auto text_rend = text_from_view.rend(); + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_copy_constructor_from_truncated) + { + static constexpr Text text_original(STR("Hello World"), true); + static constexpr Text text_copy(text_original); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_TRUE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); - static constexpr auto text_crend = text_from_view.crend(); + static constexpr auto text_crend = text_copy.crend(); CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); bool is_equal = Equal(std::string(text_pointer), text); @@ -336,30 +385,10 @@ namespace static constexpr Text::const_iterator p_begin = text.begin(); static constexpr Text::const_iterator p_cbegin = text.cbegin(); - CHECK_EQUAL(&text[0], p_begin); - CHECK_EQUAL(&text[0], p_cbegin); + CHECK_EQUAL(&text_pointer[0], p_begin); + CHECK_EQUAL(&text_pointer[0], p_cbegin); } - - //************************************************************************* - TEST(test_end) - { - static constexpr Text::const_iterator p_end = text.end(); - static constexpr Text::const_iterator p_cend = text.cend(); - - CHECK_EQUAL(&text[length], p_end); - CHECK_EQUAL(&text[length], p_cend); - } - - //************************************************************************* - TEST(test_empty_full) - { - static constexpr bool text_empty = text.empty(); - static constexpr bool text_full = text.full(); - - CHECK_FALSE(text_empty); - CHECK_TRUE(text_full); - } - + //************************************************************************* TEST(test_index) { @@ -427,7 +456,7 @@ namespace //************************************************************************* TEST(test_back) { - CHECK_TRUE(text_pointer[length - 1] == text.back()); + CHECK_TRUE(text_pointer[Length - 1] == text.back()); } //************************************************************************* @@ -438,12 +467,32 @@ namespace CHECK_EQUAL(&text[0], p_data); } + //************************************************************************* + TEST(test_data_end) + { + static constexpr Text::const_pointer p_data = text.data_end(); + + CHECK_EQUAL(&text[Length], p_data); + } + + //************************************************************************* + TEST(test_c_str) + { + static constexpr Text::const_pointer p_data = text.c_str(); + + CHECK_EQUAL(&text[0], p_data); + CHECK_EQUAL(Length, etl::strlen(p_data)); + } + //************************************************************************* TEST(test_const_iterator) { static constexpr Text::const_iterator itr = text.begin(); - bool is_equal = std::equal(text_pointer, text_pointer + length, itr); + Text::const_iterator begin = text.begin(); + Text::const_iterator end = text.end(); + + bool is_equal = std::equal(begin, end, itr); CHECK_TRUE(is_equal); } @@ -452,1560 +501,43 @@ namespace { static constexpr Text::const_reverse_iterator ritr = text.rbegin(); - etl::reverse_iterator rbegin(text_pointer + length); - etl::reverse_iterator rend(text_pointer); + etl::reverse_iterator rbegin(text_pointer + Length); + etl::reverse_iterator rend(text_pointer); bool is_equal = std::equal(rbegin, rend, ritr); CHECK_TRUE(is_equal); } //************************************************************************* - TEST(test_equal) + TEST(test_to_view) { - static constexpr bool text_compare_with_same = (text == text_same); - CHECK_TRUE(text_compare_with_same); + static constexpr View view(text); - static constexpr bool text_compare_with_less = (text == text_less); - CHECK_FALSE(text_compare_with_less); + CHECK_TRUE(text.begin() == view.begin()); + CHECK_TRUE(text.end() == view.end()); - static constexpr bool text_compare_with_greater = (text == text_greater); - CHECK_FALSE(text_compare_with_greater); - - static constexpr bool text_compare_with_less_length = (text == text_less_length); - CHECK_FALSE(text_compare_with_less_length); - - static constexpr bool text_compare_with_greater_length = (text == text_greater_length); - CHECK_FALSE(text_compare_with_greater_length); + bool is_equal = std::equal(text.begin(), text.end(), view.begin()); + CHECK_TRUE(is_equal); } //************************************************************************* - TEST(test_not_equal) +#if ETL_USING_STL + TEST(test_write_string_to_std_basic_ostream) { - static constexpr bool text_compare_with_same = (text != text_same); - CHECK_FALSE(text_compare_with_same); + static constexpr Text text1 = STR("Hello World"); - static constexpr bool text_compare_with_less = (text != text_less); - CHECK_TRUE(text_compare_with_less); + std::stringstream sstream; - static constexpr bool text_compare_with_greater = (text != text_greater); - CHECK_TRUE(text_compare_with_greater); + sstream << text1; - static constexpr bool text_compare_with_less_length = (text != text_less_length); - CHECK_TRUE(text_compare_with_less_length); + TextSTD sstream_string = sstream.str(); - static constexpr bool text_compare_with_greater_length = (text != text_greater_length); - CHECK_TRUE(text_compare_with_greater_length); + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); } - - //************************************************************************* - TEST(test_less_than) - { - static constexpr bool text_compare_with_same = (text < text_same); - CHECK_FALSE(text_compare_with_same); - - static constexpr bool text_compare_with_less = (text < text_less); - CHECK_FALSE(text_compare_with_less); - - static constexpr bool text_compare_with_greater = (text < text_greater); - CHECK_TRUE(text_compare_with_greater); - - static constexpr bool text_compare_with_less_length = (text < text_less_length); - CHECK_FALSE(text_compare_with_less_length); - - static constexpr bool text_compare_with_greater_length = (text < text_greater_length); - CHECK_TRUE(text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_less_than_or_equal) - { - static constexpr bool text_compare_with_same = (text <= text_same); - CHECK_TRUE(text_compare_with_same); - - static constexpr bool text_compare_with_less = (text <= text_less); - CHECK_FALSE(text_compare_with_less); - - static constexpr bool text_compare_with_greater = (text <= text_greater); - CHECK_TRUE(text_compare_with_greater); - - static constexpr bool text_compare_with_less_length = (text <= text_less_length); - CHECK_FALSE(text_compare_with_less_length); - - static constexpr bool text_compare_with_greater_length = (text <= text_greater_length); - CHECK_TRUE(text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_greater_than) - { - static constexpr bool text_compare_with_same = (text > text_same); - CHECK_FALSE(text_compare_with_same); - - static constexpr bool text_compare_with_less = (text > text_less); - CHECK_TRUE(text_compare_with_less); - - static constexpr bool text_compare_with_greater = (text > text_greater); - CHECK_FALSE(text_compare_with_greater); - - static constexpr bool text_compare_with_less_length = (text > text_less_length); - CHECK_TRUE(text_compare_with_less_length); - - static constexpr bool text_compare_with_greater_length = (text > text_greater_length); - CHECK_FALSE(text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_greater_than_or_equal) - { - static constexpr bool text_compare_with_same = (text >= text_same); - CHECK_TRUE(text_compare_with_same); - - static constexpr bool text_compare_with_less = (text >= text_less); - CHECK_TRUE(text_compare_with_less); - - static constexpr bool text_compare_with_greater = (text >= text_greater); - CHECK_FALSE(text_compare_with_greater); - - static constexpr bool text_compare_with_less_length = (text >= text_less_length); - CHECK_TRUE(text_compare_with_less_length); - - static constexpr bool text_compare_with_greater_length = (text >= text_greater_length); - CHECK_FALSE(text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_find_string) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text needle(STR("needle")); - static constexpr Text pin(STR("pin")); - - static constexpr size_t position_needle = haystack.find(needle); - CHECK_EQUAL(18, position_needle); - - static constexpr size_t position_pin = haystack.find(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_string_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text needle(STR("needle")); - static constexpr Text pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); - CHECK_EQUAL(18, position_needle1); - - static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); - CHECK_EQUAL(37, position_needle2); - - static constexpr size_t position_pin = haystack.find(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_view) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr View needle(STR("needle")); - static constexpr View pin(STR("pin")); - - static constexpr size_t position_needle = haystack.find(needle); - CHECK_EQUAL(18, position_needle); - - static constexpr size_t position_pin = haystack.find(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_view_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr View needle(STR("needle")); - static constexpr View pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); - CHECK_EQUAL(18, position_needle1); - - static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); - CHECK_EQUAL(37, position_needle2); - - static constexpr size_t position_pin = haystack.find(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_pointer) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin")); - - static constexpr size_t position_needle = haystack.find(needle); - CHECK_EQUAL(18, position_needle); - - static constexpr size_t position_pin = haystack.find(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_pointer_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); - CHECK_EQUAL(18, position_needle1); - - static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); - CHECK_EQUAL(37, position_needle2); - - static constexpr size_t position_pin = haystack.find(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_pointer_position_n) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.find(needle, 0ULL, 4); - CHECK_EQUAL(18, position_needle1); - - static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1, 4); - CHECK_EQUAL(37, position_needle2); - - static constexpr size_t position_pin = haystack.find(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_character) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type needle(STR('n')); - static constexpr Text::value_type pin(STR('p')); - - static constexpr size_t position_needle = haystack.find(needle); - CHECK_EQUAL(18, position_needle); - - static constexpr size_t position_pin = haystack.find(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_character_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type needle(STR('n')); - static constexpr Text::value_type pin(STR('p')); - - static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); - CHECK_EQUAL(18, position_needle1); - - static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); - CHECK_EQUAL(26, position_needle2); - - static constexpr size_t position_pin = haystack.find(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_contains_string) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text needle(STR("needle")); - static constexpr Text pin(STR("pin" )); - static constexpr Text excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_needle = haystack.contains(needle); - static constexpr bool constains_pin = haystack.contains(pin); - static constexpr bool contains_excess = haystack.contains(excess); - - CHECK_TRUE(contains_needle); - CHECK_FALSE(constains_pin); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_contains_view) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr View needle(STR("needle")); - static constexpr View pin(STR("pin" )); - static constexpr View excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_needle = haystack.contains(needle); - static constexpr bool constains_pin = haystack.contains(pin); - static constexpr bool contains_excess = haystack.contains(excess); - - CHECK_TRUE(contains_needle); - CHECK_FALSE(constains_pin); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_contains_pointer) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin" )); - static constexpr Text::const_pointer excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_needle = haystack.contains(needle); - static constexpr bool constains_pin = haystack.contains(pin); - static constexpr bool contains_excess = haystack.contains(excess); - - CHECK_TRUE(contains_needle); - CHECK_FALSE(constains_pin); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_contains_char) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type needle(STR('n')); - static constexpr Text::value_type pin(STR('p' )); - - static constexpr bool contains_needle = haystack.contains(needle); - static constexpr bool constains_pin = haystack.contains(pin); - - CHECK_TRUE(contains_needle); - CHECK_FALSE(constains_pin); - } - - //************************************************************************* - TEST(test_starts_with_string) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text start_text(STR("A haystack")); - static constexpr Text not_start_text(STR("nothing else")); - static constexpr Text excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_start_text = haystack.starts_with(start_text); - static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); - static constexpr bool contains_excess = haystack.starts_with(excess); - - CHECK_TRUE(contains_start_text); - CHECK_FALSE(constains_not_start_text); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_starts_with_view) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr View start_text(STR("A haystack")); - static constexpr View not_start_text(STR("nothing else")); - static constexpr View excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_start_text = haystack.starts_with(start_text); - static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); - - CHECK_TRUE(contains_start_text); - CHECK_FALSE(constains_not_start_text); - } - - //************************************************************************* - TEST(test_starts_with_pointer) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer start_text(STR("A haystack")); - static constexpr Text::const_pointer not_start_text(STR("nothing else")); - static constexpr Text::const_pointer excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_start_text = haystack.starts_with(start_text); - static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); - - CHECK_TRUE(contains_start_text); - CHECK_FALSE(constains_not_start_text); - } - - //************************************************************************* - TEST(test_starts_with_char) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type start_text(STR('A')); - static constexpr Text::value_type not_start_text(STR('e')); - - static constexpr bool contains_start_text = haystack.starts_with(start_text); - static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); - - CHECK_TRUE(contains_start_text); - CHECK_FALSE(constains_not_start_text); - } - - //************************************************************************* - TEST(test_ends_with_string) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text not_end_text(STR("A haystack")); - static constexpr Text end_text(STR("nothing else")); - static constexpr Text excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_end_text = haystack.ends_with(end_text); - static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); - static constexpr bool contains_excess = haystack.ends_with(excess); - - CHECK_TRUE(contains_end_text); - CHECK_FALSE(constains_not_end_text); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_ends_with_view) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr View not_end_text(STR("A haystack")); - static constexpr View end_text(STR("nothing else")); - static constexpr View excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_end_text = haystack.ends_with(end_text); - static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); - static constexpr bool contains_excess = haystack.ends_with(excess); - - CHECK_TRUE(contains_end_text); - CHECK_FALSE(constains_not_end_text); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_ends_with_pointer) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer not_end_text(STR("A haystack")); - static constexpr Text::const_pointer end_text(STR("nothing else")); - static constexpr Text::const_pointer excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_end_text = haystack.ends_with(end_text); - static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); - static constexpr bool contains_excess = haystack.ends_with(excess); - - CHECK_TRUE(contains_end_text); - CHECK_FALSE(constains_not_end_text); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_ends_with_char) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type not_end_text(STR('A')); - static constexpr Text::value_type end_text(STR('e')); - - static constexpr bool contains_end_text = haystack.ends_with(end_text); - static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); - - CHECK_TRUE(contains_end_text); - CHECK_FALSE(constains_not_end_text); - } - - //************************************************************************* - TEST(test_rfind_string) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text needle(STR("needle")); - static constexpr Text pin(STR("pin")); - - static constexpr size_t position_needle = haystack.rfind(needle); - CHECK_EQUAL(37, position_needle); - - static constexpr size_t position_pin = haystack.rfind(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_string_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text needle(STR("needle")); - static constexpr Text pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); - CHECK_EQUAL(37, position_needle1); - - static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); - CHECK_EQUAL(18, position_needle2); - - static constexpr size_t position_pin = haystack.rfind(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_view) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr View needle(STR("needle")); - static constexpr View pin(STR("pin")); - - static constexpr size_t position_needle = haystack.rfind(needle); - CHECK_EQUAL(37, position_needle); - - static constexpr size_t position_pin = haystack.rfind(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_view_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr View needle(STR("needle")); - static constexpr View pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); - CHECK_EQUAL(37, position_needle1); - - static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); - CHECK_EQUAL(18, position_needle2); - - static constexpr size_t position_pin = haystack.rfind(pin, Text::npos); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_pointer) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); - CHECK_EQUAL(37, position_needle1); - - static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); - CHECK_EQUAL(18, position_needle2); - - static constexpr size_t position_pin = haystack.rfind(pin, Text::npos); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_pointer_n) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos, 4); - CHECK_EQUAL(37, position_needle1); - - static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1 + 1, 4); - CHECK_EQUAL(18, position_needle2); - - static constexpr size_t position_pin = haystack.rfind(pin, Text::npos, 4); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_character) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type needle(STR('n')); - static constexpr Text::value_type pin(STR('p')); - - static constexpr size_t position_needle = haystack.rfind(needle); - CHECK_EQUAL(37, position_needle); - - static constexpr size_t position_pin = haystack.rfind(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_character_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type needle(STR('n')); - static constexpr Text::value_type pin(STR('p')); - - static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); - CHECK_EQUAL(37, position_needle1); - - static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); - CHECK_EQUAL(30, position_needle2); - - static constexpr size_t position_pin = haystack.rfind(pin, Text::npos); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_substr) - { - // Equal. - static constexpr Text sub1(text.substr(text.size())); - CHECK_EQUAL(0, sub1.size()); - - // Whole string. - static constexpr Text sub2(text.substr()); - CHECK_TRUE(Equal(text, sub2)); - - // Starting from position 2. - static constexpr Text sub3(text.substr(2)); - CHECK_TRUE(Equal(View(text.begin() + 2, text.end()), sub3)); - - // Starting from position 2 for 3 characters. - static constexpr Text sub4(text.substr(2, 3)); - CHECK_TRUE(Equal(View(text.begin() + 2, text.begin() + 2 + 3), sub4)); - - // Starting from position 2 for too many characters. - static constexpr Text sub5(text.substr(2, text.size())); - CHECK_TRUE(Equal(View(text.begin() + 2, text.end()), sub3)); - } - - //************************************************************************* - TEST(test_compare_string) - { - // Equal. - static constexpr auto text_compare_with_same = text.compare(text_same); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text.compare(text_less); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text.compare(text_greater); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text.compare(text_less_length); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text.compare(text_greater_length); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_string) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_string_subposition_sublength) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same_xxx, 3, text_same.size()); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less_xxx, 3, text_less.size()); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater_xxx, 3, text_greater.size()); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length_xxx, 3, text_less_length.size()); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length_xxx, 3, text_greater_length.size()); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_view) - { - // Equal. - static constexpr auto text_compare_with_same = text.compare(View(text_same)); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text.compare(View(text_less)); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text.compare(View(text_greater)); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text.compare(View(text_less_length)); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text.compare(View(text_greater_length)); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_view) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, View(text_same)); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, View(text_less)); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, View(text_greater)); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, View(text_less_length)); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, View(text_greater_length)); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_view_subposition_sublength) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, View(text_same_xxx), 3, text_same.size()); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, View(text_less_xxx), 3, text_less.size()); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, View(text_greater_xxx), 3, text_greater.size()); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, View(text_less_length_xxx), 3, text_less_length.size()); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, View(text_greater_length_xxx), 3, text_greater_length.size()); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_c_string) - { - // Equal. - static constexpr auto text_compare_with_same = text.compare(text_same.data()); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text.compare(text_less.data()); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text.compare(text_greater.data()); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text.compare(text_less_length.data()); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text.compare(text_greater_length.data()); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_c_string) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same.data()); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less.data()); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater.data()); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length.data()); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length.data()); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_c_string_n) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same.data(), text_same.size()); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less.data(), text_less.size()); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater.data(), text_greater.size()); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length.data(), text_less_length.size()); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length.data(), text_greater_length.size()); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_find_first_of_string_position) - { - static constexpr auto text_find_first_of_word = text.find_first_of(text_word, 2); - CHECK_EQUAL(4, text_find_first_of_word); - - static constexpr auto text_find_first_of_he = text.find_first_of(text_he, 2); - CHECK_EQUAL(Text::npos, text_find_first_of_he); - } - - //************************************************************************* - TEST(test_find_first_of_view_position) - { - static constexpr auto text_find_first_of_word = text.find_first_of(View(text_word), 2); - CHECK_EQUAL(4, text_find_first_of_word); - - static constexpr auto text_find_first_of_he = text.find_first_of(View(text_he), 2); - CHECK_EQUAL(Text::npos, text_find_first_of_he); - } - - //************************************************************************* - TEST(test_find_first_of_pointer_position) - { - static constexpr auto text_find_first_of_word = text.find_first_of(text_word.data(), 2); - CHECK_EQUAL(4, text_find_first_of_word); - - static constexpr auto text_find_first_of_he = text.find_first_of(text_he.data(), 2); - CHECK_EQUAL(Text::npos, text_find_first_of_he); - } - - //************************************************************************* - TEST(test_find_first_of_pointer_position_n) - { - static constexpr auto text_find_first_of_word = text.find_first_of(text_word.data(), 2, text_word.size()); - CHECK_EQUAL(4, text_find_first_of_word); - - static constexpr auto text_find_first_of_he = text.find_first_of(text_he.data(), 2, text_he.size()); - CHECK_EQUAL(Text::npos, text_find_first_of_he); - } - - //************************************************************************* - TEST(test_find_first_of_character_position) - { - static constexpr auto text_find_first_of_o = text.find_first_of(STR('o'), 2); - CHECK_EQUAL(4, text_find_first_of_o); - - static constexpr auto text_find_first_of_h = text.find_first_of(STR('h'), 2); - CHECK_EQUAL(Text::npos, text_find_first_of_h); - } - - //************************************************************************* - TEST(test_find_last_of_string_position) - { - static constexpr auto text_find_last_of_word = text.find_last_of(text_word, 9); - CHECK_EQUAL(8, text_find_last_of_word); - - static constexpr auto text_find_last_of_rd = text.find_last_of(text_rd, 7); - CHECK_EQUAL(Text::npos, text_find_last_of_rd); - } - - //************************************************************************* - TEST(test_find_last_of_view_position) - { - static constexpr auto text_find_last_of_word = text.find_last_of(View(text_word), 9); - CHECK_EQUAL(8, text_find_last_of_word); - - static constexpr auto text_find_last_of_rd = text.find_last_of(View(text_rd), 7); - CHECK_EQUAL(Text::npos, text_find_last_of_rd); - } - - //************************************************************************* - TEST(test_find_last_of_pointer_position) - { - static constexpr auto text_find_last_of_word = text.find_last_of(text_word.data(), 9); - CHECK_EQUAL(8, text_find_last_of_word); - - static constexpr auto text_find_last_of_rd = text.find_last_of(text_rd.data(), 7); - CHECK_EQUAL(Text::npos, text_find_last_of_rd); - } - - //************************************************************************* - TEST(test_find_last_of_pointer_position_n) - { - static constexpr auto text_find_last_of_word = text.find_last_of(text_word.data(), 9, text_word.size()); - CHECK_EQUAL(8, text_find_last_of_word); - - static constexpr auto text_find_last_of_rd = text.find_last_of(text_rd.data(), 7, text_rd.size()); - CHECK_EQUAL(Text::npos, text_find_last_of_rd); - } - - //************************************************************************* - TEST(test_find_last_of_character_position) - { - static constexpr auto text_find_last_of_o = text.find_last_of(STR('o'), 9); - CHECK_EQUAL(7, text_find_last_of_o); - - static constexpr auto text_find_last_of_h = text.find_last_of(STR('h'), 7); - CHECK_EQUAL(Text::npos, text_find_last_of_h); - } - - //************************************************************************* - TEST(test_find_first_not_of_string_position) - { - static constexpr auto text_find_first_not_of_word = text.find_first_not_of(text_hello, 2); - CHECK_EQUAL(5, text_find_first_not_of_word); - - static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(text_llo_world, 2); - CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); - } - - //************************************************************************* - TEST(test_find_first_not_of_view_position) - { - static constexpr auto text_find_first_not_of_word = text.find_first_not_of(View(text_hello), 2); - CHECK_EQUAL(5, text_find_first_not_of_word); - - static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(View(text_llo_world), 2); - CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); - } - - //************************************************************************* - TEST(test_find_first_not_of_pointer_position) - { - static constexpr auto text_find_first_not_of_word = text.find_first_not_of(text_hello.data(), 2); - CHECK_EQUAL(5, text_find_first_not_of_word); - - static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(text_llo_world.data(), 2); - CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); - } - - //************************************************************************* - TEST(test_find_first_not_of_pointer_position_n) - { - static constexpr auto text_find_first_not_of_word = text.find_first_not_of(text_hello.data(), 2, text_hello.size()); - CHECK_EQUAL(5, text_find_first_not_of_word); - - static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(text_llo_world.data(), 2, text_llo_world.size()); - CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); - } - - //************************************************************************* - TEST(test_find_first_not_of_character_position) - { - static constexpr auto text_find_first_not_of_o = text.find_first_not_of(STR('l'), 2); - CHECK_EQUAL(4, text_find_first_not_of_o); - - static constexpr auto text_find_first_not_of_h = text.find_first_not_of(STR('h'), 2); - CHECK_EQUAL(2, text_find_first_not_of_h); - } - -// //************************************************************************* -// TEST(test_find_last_not_of_string_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); -// size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST(test_find_last_not_of_view_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); -// size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); -// position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST(test_find_last_not_of_pointer_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); -// size_t position2 = text.find_last_not_of(STR("ZEXD")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5); -// position2 = text.find_last_not_of(STR("ZEXD"), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size()); -// position2 = text.find_last_not_of(STR("ZEXD"), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100); -// position2 = text.find_last_not_of(STR("ZEXD"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST(test_find_last_not_of_pointer_position_n) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); -// size_t position2 = text.find_last_not_of(STR("ZEXD"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5, 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 5, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 1, 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 1, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size(), 4); -// position2 = text.find_last_not_of(STR("ZEXD"), text.size(), 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100, 4); -// position2 = text.find_last_not_of(STR("ZEXD"), 100, 4); -// -// CHECK_EQUAL(position1, position2); -// } -// -// //************************************************************************* -// TEST(test_find_last_not_of_character_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_last_not_of(STR('F')); -// size_t position2 = text.find_last_not_of(STR('F')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('Z')); -// position2 = text.find_last_not_of(STR('Z')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('A'), compare_text.size()); -// position2 = text.find_last_not_of(STR('A'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('C'), 3); -// position2 = text.find_last_not_of(STR('C'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('C'), compare_text.size()); -// position2 = text.find_last_not_of(STR('C'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(STR('C'), 100); -// position2 = text.find_last_not_of(STR('C'), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST(test_hash) -// { -// // Test with actual string type. -// Text text(STR("ABCDEFHIJKL")); -// size_t hash = etl::hash()(text); -// size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); -// CHECK_EQUAL(compare_hash, hash); -// -// // Test with interface string type. -// IText& itext = text; -// hash = etl::hash()(itext); -// CHECK_EQUAL(compare_hash, hash); -// } -// -// //************************************************************************* -// TEST(test_memcpy_repair) -// { -// Text text; -// -// text.assign(STR("ABCDEF")); -// -// char buffer[Sizeof(Text)]; -// -// memcpy(&buffer, (const void*)&text, Sizeof(text)); -// -// Text& rtext(*reinterpret_cast(buffer)); -// rtext.repair(); -// -// CHECK(!rtext.empty()); -// CHECK(!rtext.full()); -// -// bool is_equal = Equal(text, rtext); -// CHECK(is_equal); -// -// text = STR("GHIJKL"); -// is_equal = Equal(text, rtext); -// CHECK(!is_equal); -// } -// -// //************************************************************************* -// TEST(test_memcpy_repair_virtual) -// { -// Text text; -// -// text.assign(STR("ABCDEF")); -// -// char buffer[Sizeof(Text)]; -// -// memcpy(&buffer, (const void*)&text, Sizeof(text)); -// -// IText& itext(*reinterpret_cast(buffer)); -// itext.repair(); -// -// CHECK(!itext.empty()); -// CHECK(!itext.full()); -// -// bool is_equal = Equal(text, itext); -// CHECK(is_equal); -// -// text = STR("GHIJKL"); -// is_equal = Equal(text, itext); -// CHECK(!is_equal); -// } -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// //************************************************************************* -// TEST(test_truncate_over_many_operations) -// { -// Text text(short_text.c_str()); -// CHECK_FALSE(text.is_truncated()); -// -// text.insert(3, initial_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// while (text.size() != 0) -// { -// text.pop_back(); -// CHECK_TRUE(text.is_truncated()); -// } -// -// text.clear(); -// CHECK_FALSE(text.is_truncated()); -// -// text.assign(longer_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// text.assign(short_text.c_str()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST(test_add_from_truncated) -// { -// Text text1(short_text.c_str()); -// TextS text2(short_text.c_str()); -// -// CHECK_FALSE(text1.is_truncated()); -// CHECK_TRUE(text2.is_truncated()); -// -// // text2 has the truncate flag set. -// text1 += text2; -// -// CHECK(text1.is_truncated()); -// } -// -// //************************************************************************* -// TEST(test_add_to_truncated) -// { -// Text text1(longer_text.c_str()); -// Text text2(short_text.c_str()); -// -// CHECK(text1.is_truncated()); -// CHECK_FALSE(text2.is_truncated()); -// -// // Clear text but not the truncate flag. -// text1.erase(text1.begin(), text1.end()); -// -// // text1 still has the truncate flag set. -// text1 += text2; -// -// CHECK(text1.is_truncated()); -// } -// -// //************************************************************************* -// TEST(test_clear_truncated) -// { -// Text text(longer_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// text.clear_truncated(); -// CHECK_FALSE(text.is_truncated()); -// } -//#endif -// -//#if ETL_HAS_STRING_CLEAR_AFTER_USE -// //************************************************************************* -// TEST(test_secure_after_destructor) -// { -// char buffer[Sizeof(Text)]; -// std::fill_n(buffer, Sizeof(Text), 0); -// ::new (buffer) Text(STR("ABCDEF")); -// -// Text& text = *reinterpret_cast(buffer); -// text.set_secure(); -// -// CHECK(Text(STR("ABCDEF")) == text); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// // Destroy the text object. -// std::atomic_signal_fence(std::memory_order_seq_cst); -// text.~Text(); -// std::atomic_signal_fence(std::memory_order_seq_cst); -// -// // Check there no non-zero values in the string. -// CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST(test_secure_after_assign) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pe = text.end(); -// -// text.assign(STR("ABC")); -// -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST(test_secure_after_reSize_down) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pe = text.end(); -// -// text.reSize(text.size() - 3U); -// -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST(test_secure_after_erase) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.erase(pb + 2, pb + 5); -// -// // Check there no non-zero values in the remainder of the string. -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST(test_secure_after_replace) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.replace(pb + 1, pb + 4, STR("G")); -// -// // Check there no non-zero values in the remainder of the string. -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST(test_secure_after_clear) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.clear(); -// -// // 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(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 -// -// //************************************************************************* -// TEST(test_initialize_free_space_empty_string) -// { -// Text empty; -// Text text; -// -// text.initialize_free_space(); -// -// CHECK(text.empty()); -// CHECK(text == empty); -// -// for (size_t i = text.size(); i < text.max_size(); ++i) -// { -// CHECK_EQUAL(0, text[i]); -// } -// } -// -// //************************************************************************* -// TEST(test_initialize_free_space_part_filled_string) -// { -// Text empty; -// Text initial = STR("ABC"); -// Text text(initial); -// -// text.initialize_free_space(); -// -// CHECK(text == initial); -// CHECK(text != empty); -// -// for (size_t i = text.size(); i < text.max_size(); ++i) -// { -// CHECK_EQUAL(0, text[i]); -// } -// } -// -// //************************************************************************* -// TEST(test_update_after_c_string_max_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size(), STR('A')); -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size(), text.size()); -// } -// -// //************************************************************************* -// TEST(test_update_after_c_string_shorter_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size() - 1, text.size()); -// } -// -// //************************************************************************* -// TEST(test_update_after_c_string_greater_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size(), text.size()); -// } -// -// //************************************************************************* -//#if ETL_USING_STL -// TEST(test_write_string_to_std_basic_ostream) -// { -// Text text1 = STR("Hello World"); -// -// std::stringstream sstream; -// -// sstream << text1; -// -// TextSTD sstream_string = sstream.str(); -// -// View sstream_view(sstream_string.data(), sstream_string.size()); -// -// CHECK(text1 == sstream_view); -// } -//#endif +#endif }; } + +#endif diff --git a/test/test_const_string_u16.cpp b/test/test_const_string_u16.cpp new file mode 100644 index 00000000..729a24db --- /dev/null +++ b/test/test_const_string_u16.cpp @@ -0,0 +1,525 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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 "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/const_u16string.h" +#include "etl/string_view.h" + +#if ETL_USING_CPP14 + +#undef STR +#define STR(x) u##x + +namespace +{ + SUITE(test_const_string_char16_t) + { + using Text = etl::const_u16string; + using View = etl::u16string_view; + + using TextSTD = std::u16string; + + static constexpr Text::const_pointer text_pointer = STR("Hello World"); + static constexpr Text text(STR("Hello World")); + static constexpr size_t Length = etl::strlen(STR("Hello World")); + + //************************************************************************* + template + bool Equal(const T1& compare_text, const T2& test_text) + { + return (compare_text.size() == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text.begin()); + } + + //************************************************************************* + template + bool Equal(const T1* compare_text, const T2& test_text) + { + return (etl::strlen(compare_text) == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text); + } + + //************************************************************************* + TEST(test_constructor_null_string) + { + static constexpr Text text_from_literal_empty(STR("")); + + static constexpr auto text_empty = text_from_literal_empty.empty(); + CHECK_TRUE(text_empty); + + static constexpr auto text_full = text_from_literal_empty.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal_empty.capacity(); + CHECK_EQUAL(0, text_capacity); + + static constexpr auto text_max_size = text_from_literal_empty.max_size(); + CHECK_EQUAL(0, text_max_size); + + static constexpr auto text_size = text_from_literal_empty.size(); + CHECK_EQUAL(0, text_size); + + static constexpr auto text_length = text_from_literal_empty.length(); + CHECK_EQUAL(0, text_length); + + static constexpr auto text_available = text_from_literal_empty.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal_empty.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal_empty.is_secure(); + CHECK_FALSE(text_is_secure); + } + + //************************************************************************* + TEST(test_constructor_char_pointer) + { + static constexpr Text text_from_pointer(text_pointer); + + static constexpr auto text_empty = text_from_pointer.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_pointer.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_pointer.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_pointer.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_pointer.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_pointer.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_pointer.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_pointer.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_pointer.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_pointer.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_pointer.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_pointer.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_pointer.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_pointer.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_pointer.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_pointer.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_pointer.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_pointer.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_pointer.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u16string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_from_literal) + { + static constexpr Text text_from_literal(STR("Hello World")); + + static constexpr auto text_empty = text_from_literal.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_literal.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_literal.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_literal.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_literal.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_literal.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_literal.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_literal.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_literal.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_literal.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_literal.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_literal.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_literal.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_literal.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_literal.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_literal.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u16string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_truncated) + { + static constexpr Text text_from_pointer(text_pointer, true); + static constexpr Text text_from_literal(STR("Hello World"), true); + + static constexpr auto text_from_pointer_is_truncated = text_from_pointer.is_truncated(); + CHECK_TRUE(text_from_pointer_is_truncated); + + static constexpr auto text_from_literal_is_truncated = text_from_literal.is_truncated(); + CHECK_TRUE(text_from_literal_is_truncated); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + static constexpr Text text_copy(text); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u16string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_copy_constructor_from_truncated) + { + static constexpr Text text_original(STR("Hello World"), true); + static constexpr Text text_copy(text_original); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_TRUE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u16string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_begin) + { + static constexpr Text::const_iterator p_begin = text.begin(); + static constexpr Text::const_iterator p_cbegin = text.cbegin(); + + CHECK_EQUAL(&text_pointer[0], p_begin); + CHECK_EQUAL(&text_pointer[0], p_cbegin); + } + + //************************************************************************* + TEST(test_index) + { + static constexpr Text::value_type c0 = text[0]; + static constexpr Text::value_type c1 = text[1]; + static constexpr Text::value_type c2 = text[2]; + static constexpr Text::value_type c3 = text[3]; + static constexpr Text::value_type c4 = text[4]; + static constexpr Text::value_type c5 = text[5]; + static constexpr Text::value_type c6 = text[6]; + static constexpr Text::value_type c7 = text[7]; + static constexpr Text::value_type c8 = text[8]; + static constexpr Text::value_type c9 = text[9]; + static constexpr Text::value_type c10 = text[10]; + static constexpr Text::value_type c11 = text[11]; + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + CHECK_EQUAL(text_pointer[11], c11); + } + + //************************************************************************* + TEST(test_at) + { + static constexpr Text::value_type c0 = text.at(0); + static constexpr Text::value_type c1 = text.at(1); + static constexpr Text::value_type c2 = text.at(2); + static constexpr Text::value_type c3 = text.at(3); + static constexpr Text::value_type c4 = text.at(4); + static constexpr Text::value_type c5 = text.at(5); + static constexpr Text::value_type c6 = text.at(6); + static constexpr Text::value_type c7 = text.at(7); + static constexpr Text::value_type c8 = text.at(8); + static constexpr Text::value_type c9 = text.at(9); + static constexpr Text::value_type c10 = text.at(10); + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + } + + //************************************************************************* + TEST(test_front) + { + CHECK_TRUE(text_pointer[0] == text.front()); + } + + //************************************************************************* + TEST(test_back) + { + CHECK_TRUE(text_pointer[Length - 1] == text.back()); + } + + //************************************************************************* + TEST(test_data) + { + static constexpr Text::const_pointer p_data = text.data(); + + CHECK_EQUAL(&text[0], p_data); + } + + //************************************************************************* + TEST(test_data_end) + { + static constexpr Text::const_pointer p_data = text.data_end(); + + CHECK_EQUAL(&text[Length], p_data); + } + + //************************************************************************* + TEST(test_c_str) + { + static constexpr Text::const_pointer p_data = text.c_str(); + + CHECK_EQUAL(&text[0], p_data); + CHECK_EQUAL(Length, etl::strlen(p_data)); + } + + //************************************************************************* + TEST(test_const_iterator) + { + static constexpr Text::const_iterator itr = text.begin(); + + Text::const_iterator begin = text.begin(); + Text::const_iterator end = text.end(); + + bool is_equal = std::equal(begin, end, itr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_const_reverse_iterator) + { + static constexpr Text::const_reverse_iterator ritr = text.rbegin(); + + etl::reverse_iterator rbegin(text_pointer + Length); + etl::reverse_iterator rend(text_pointer); + + bool is_equal = std::equal(rbegin, rend, ritr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_to_view) + { + static constexpr View view(text); + + CHECK_TRUE(text.begin() == view.begin()); + CHECK_TRUE(text.end() == view.end()); + + bool is_equal = std::equal(text.begin(), text.end(), view.begin()); + CHECK_TRUE(is_equal); + } + }; +} + +#endif diff --git a/test/test_const_string_u32.cpp b/test/test_const_string_u32.cpp new file mode 100644 index 00000000..92e6e017 --- /dev/null +++ b/test/test_const_string_u32.cpp @@ -0,0 +1,525 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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 "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/const_u32string.h" +#include "etl/string_view.h" + +#if ETL_USING_CPP14 + +#undef STR +#define STR(x) U##x + +namespace +{ + SUITE(test_const_string_char32_t) + { + using Text = etl::const_u32string; + using View = etl::u32string_view; + + using TextSTD = std::u32string; + + static constexpr Text::const_pointer text_pointer = STR("Hello World"); + static constexpr Text text(STR("Hello World")); + static constexpr size_t Length = etl::strlen(STR("Hello World")); + + //************************************************************************* + template + bool Equal(const T1& compare_text, const T2& test_text) + { + return (compare_text.size() == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text.begin()); + } + + //************************************************************************* + template + bool Equal(const T1* compare_text, const T2& test_text) + { + return (etl::strlen(compare_text) == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text); + } + + //************************************************************************* + TEST(test_constructor_null_string) + { + static constexpr Text text_from_literal_empty(STR("")); + + static constexpr auto text_empty = text_from_literal_empty.empty(); + CHECK_TRUE(text_empty); + + static constexpr auto text_full = text_from_literal_empty.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal_empty.capacity(); + CHECK_EQUAL(0, text_capacity); + + static constexpr auto text_max_size = text_from_literal_empty.max_size(); + CHECK_EQUAL(0, text_max_size); + + static constexpr auto text_size = text_from_literal_empty.size(); + CHECK_EQUAL(0, text_size); + + static constexpr auto text_length = text_from_literal_empty.length(); + CHECK_EQUAL(0, text_length); + + static constexpr auto text_available = text_from_literal_empty.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal_empty.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal_empty.is_secure(); + CHECK_FALSE(text_is_secure); + } + + //************************************************************************* + TEST(test_constructor_char_pointer) + { + static constexpr Text text_from_pointer(text_pointer); + + static constexpr auto text_empty = text_from_pointer.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_pointer.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_pointer.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_pointer.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_pointer.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_pointer.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_pointer.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_pointer.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_pointer.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_pointer.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_pointer.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_pointer.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_pointer.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_pointer.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_pointer.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_pointer.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_pointer.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_pointer.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_pointer.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u32string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_from_literal) + { + static constexpr Text text_from_literal(STR("Hello World")); + + static constexpr auto text_empty = text_from_literal.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_literal.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_literal.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_literal.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_literal.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_literal.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_literal.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_literal.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_literal.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_literal.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_literal.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_literal.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_literal.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_literal.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_literal.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_literal.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u32string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_truncated) + { + static constexpr Text text_from_pointer(text_pointer, true); + static constexpr Text text_from_literal(STR("Hello World"), true); + + static constexpr auto text_from_pointer_is_truncated = text_from_pointer.is_truncated(); + CHECK_TRUE(text_from_pointer_is_truncated); + + static constexpr auto text_from_literal_is_truncated = text_from_literal.is_truncated(); + CHECK_TRUE(text_from_literal_is_truncated); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + static constexpr Text text_copy(text); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u32string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_copy_constructor_from_truncated) + { + static constexpr Text text_original(STR("Hello World"), true); + static constexpr Text text_copy(text_original); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_TRUE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u32string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_begin) + { + static constexpr Text::const_iterator p_begin = text.begin(); + static constexpr Text::const_iterator p_cbegin = text.cbegin(); + + CHECK_EQUAL(&text_pointer[0], p_begin); + CHECK_EQUAL(&text_pointer[0], p_cbegin); + } + + //************************************************************************* + TEST(test_index) + { + static constexpr Text::value_type c0 = text[0]; + static constexpr Text::value_type c1 = text[1]; + static constexpr Text::value_type c2 = text[2]; + static constexpr Text::value_type c3 = text[3]; + static constexpr Text::value_type c4 = text[4]; + static constexpr Text::value_type c5 = text[5]; + static constexpr Text::value_type c6 = text[6]; + static constexpr Text::value_type c7 = text[7]; + static constexpr Text::value_type c8 = text[8]; + static constexpr Text::value_type c9 = text[9]; + static constexpr Text::value_type c10 = text[10]; + static constexpr Text::value_type c11 = text[11]; + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + CHECK_EQUAL(text_pointer[11], c11); + } + + //************************************************************************* + TEST(test_at) + { + static constexpr Text::value_type c0 = text.at(0); + static constexpr Text::value_type c1 = text.at(1); + static constexpr Text::value_type c2 = text.at(2); + static constexpr Text::value_type c3 = text.at(3); + static constexpr Text::value_type c4 = text.at(4); + static constexpr Text::value_type c5 = text.at(5); + static constexpr Text::value_type c6 = text.at(6); + static constexpr Text::value_type c7 = text.at(7); + static constexpr Text::value_type c8 = text.at(8); + static constexpr Text::value_type c9 = text.at(9); + static constexpr Text::value_type c10 = text.at(10); + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + } + + //************************************************************************* + TEST(test_front) + { + CHECK_TRUE(text_pointer[0] == text.front()); + } + + //************************************************************************* + TEST(test_back) + { + CHECK_TRUE(text_pointer[Length - 1] == text.back()); + } + + //************************************************************************* + TEST(test_data) + { + static constexpr Text::const_pointer p_data = text.data(); + + CHECK_EQUAL(&text[0], p_data); + } + + //************************************************************************* + TEST(test_data_end) + { + static constexpr Text::const_pointer p_data = text.data_end(); + + CHECK_EQUAL(&text[Length], p_data); + } + + //************************************************************************* + TEST(test_c_str) + { + static constexpr Text::const_pointer p_data = text.c_str(); + + CHECK_EQUAL(&text[0], p_data); + CHECK_EQUAL(Length, etl::strlen(p_data)); + } + + //************************************************************************* + TEST(test_const_iterator) + { + static constexpr Text::const_iterator itr = text.begin(); + + Text::const_iterator begin = text.begin(); + Text::const_iterator end = text.end(); + + bool is_equal = std::equal(begin, end, itr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_const_reverse_iterator) + { + static constexpr Text::const_reverse_iterator ritr = text.rbegin(); + + etl::reverse_iterator rbegin(text_pointer + Length); + etl::reverse_iterator rend(text_pointer); + + bool is_equal = std::equal(rbegin, rend, ritr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_to_view) + { + static constexpr View view(text); + + CHECK_TRUE(text.begin() == view.begin()); + CHECK_TRUE(text.end() == view.end()); + + bool is_equal = std::equal(text.begin(), text.end(), view.begin()); + CHECK_TRUE(is_equal); + } + }; +} + +#endif diff --git a/test/test_const_string_u8.cpp b/test/test_const_string_u8.cpp new file mode 100644 index 00000000..eca0cf5f --- /dev/null +++ b/test/test_const_string_u8.cpp @@ -0,0 +1,528 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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 "unit_test_framework.h" + +#include "etl/platform.h" +#if ETL_USING_CPP20 + +#include +#include +#include +#include + +#include "etl/const_u8string.h" +#include "etl/string_view.h" + +#undef STR +#define STR(x) u8##x + +namespace +{ + SUITE(test_const_string_char8_t) + { + using Text = etl::const_u8string; + using View = etl::u8string_view; + +#if ETL_USING_CPP20 + using TextSTD = std::u8string; +#endif + + static constexpr const char8_t* text_pointer = u8"Hello World"; + static constexpr Text text(STR("Hello World")); + static constexpr size_t Length = etl::strlen(STR("Hello World")); + + //************************************************************************* + template + bool Equal(const T1& compare_text, const T2& test_text) + { + return (compare_text.size() == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text.begin()); + } + + //************************************************************************* + template + bool Equal(const T1* compare_text, const T2& test_text) + { + return (etl::strlen(compare_text) == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text); + } + + //************************************************************************* + TEST(test_constructor_null_string) + { + static constexpr Text text_from_literal_empty(STR("")); + + static constexpr auto text_empty = text_from_literal_empty.empty(); + CHECK_TRUE(text_empty); + + static constexpr auto text_full = text_from_literal_empty.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal_empty.capacity(); + CHECK_EQUAL(0, text_capacity); + + static constexpr auto text_max_size = text_from_literal_empty.max_size(); + CHECK_EQUAL(0, text_max_size); + + static constexpr auto text_size = text_from_literal_empty.size(); + CHECK_EQUAL(0, text_size); + + static constexpr auto text_length = text_from_literal_empty.length(); + CHECK_EQUAL(0, text_length); + + static constexpr auto text_available = text_from_literal_empty.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal_empty.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal_empty.is_secure(); + CHECK_FALSE(text_is_secure); + } + + //************************************************************************* + TEST(test_constructor_char_pointer) + { + static constexpr Text text_from_pointer(text_pointer); + + static constexpr auto text_empty = text_from_pointer.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_pointer.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_pointer.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_pointer.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_pointer.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_pointer.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_pointer.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_pointer.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_pointer.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_pointer.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_pointer.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_pointer.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_pointer.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_pointer.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_pointer.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_pointer.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_pointer.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_pointer.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_pointer.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u8string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_from_literal) + { + static constexpr Text text_from_literal(STR("Hello World")); + + static constexpr auto text_empty = text_from_literal.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_literal.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_literal.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_literal.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_literal.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_literal.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_literal.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_literal.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_literal.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_literal.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_literal.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_literal.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_literal.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_literal.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_literal.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_literal.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u8string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_truncated) + { + static constexpr Text text_from_pointer(text_pointer, true); + static constexpr Text text_from_literal(STR("Hello World"), true); + + static constexpr auto text_from_pointer_is_truncated = text_from_pointer.is_truncated(); + CHECK_TRUE(text_from_pointer_is_truncated); + + static constexpr auto text_from_literal_is_truncated = text_from_literal.is_truncated(); + CHECK_TRUE(text_from_literal_is_truncated); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + static constexpr Text text_copy(text); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u8string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_copy_constructor_from_truncated) + { + static constexpr Text text_original(STR("Hello World"), true); + static constexpr Text text_copy(text_original); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_TRUE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u8string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_begin) + { + static constexpr Text::const_iterator p_begin = text.begin(); + static constexpr Text::const_iterator p_cbegin = text.cbegin(); + + CHECK_EQUAL(&text_pointer[0], p_begin); + CHECK_EQUAL(&text_pointer[0], p_cbegin); + } + + //************************************************************************* + TEST(test_index) + { + static constexpr Text::value_type c0 = text[0]; + static constexpr Text::value_type c1 = text[1]; + static constexpr Text::value_type c2 = text[2]; + static constexpr Text::value_type c3 = text[3]; + static constexpr Text::value_type c4 = text[4]; + static constexpr Text::value_type c5 = text[5]; + static constexpr Text::value_type c6 = text[6]; + static constexpr Text::value_type c7 = text[7]; + static constexpr Text::value_type c8 = text[8]; + static constexpr Text::value_type c9 = text[9]; + static constexpr Text::value_type c10 = text[10]; + static constexpr Text::value_type c11 = text[11]; + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + CHECK_EQUAL(text_pointer[11], c11); + } + + //************************************************************************* + TEST(test_at) + { + static constexpr Text::value_type c0 = text.at(0); + static constexpr Text::value_type c1 = text.at(1); + static constexpr Text::value_type c2 = text.at(2); + static constexpr Text::value_type c3 = text.at(3); + static constexpr Text::value_type c4 = text.at(4); + static constexpr Text::value_type c5 = text.at(5); + static constexpr Text::value_type c6 = text.at(6); + static constexpr Text::value_type c7 = text.at(7); + static constexpr Text::value_type c8 = text.at(8); + static constexpr Text::value_type c9 = text.at(9); + static constexpr Text::value_type c10 = text.at(10); + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + } + + //************************************************************************* + TEST(test_front) + { + CHECK_TRUE(text_pointer[0] == text.front()); + } + + //************************************************************************* + TEST(test_back) + { + CHECK_TRUE(text_pointer[Length - 1] == text.back()); + } + + //************************************************************************* + TEST(test_data) + { + static constexpr Text::const_pointer p_data = text.data(); + + CHECK_EQUAL(&text[0], p_data); + } + + //************************************************************************* + TEST(test_data_end) + { + static constexpr Text::const_pointer p_data = text.data_end(); + + CHECK_EQUAL(&text[Length], p_data); + } + + //************************************************************************* + TEST(test_c_str) + { + static constexpr Text::const_pointer p_data = text.c_str(); + + CHECK_EQUAL(&text[0], p_data); + CHECK_EQUAL(Length, etl::strlen(p_data)); + } + + //************************************************************************* + TEST(test_const_iterator) + { + static constexpr Text::const_iterator itr = text.begin(); + + Text::const_iterator begin = text.begin(); + Text::const_iterator end = text.end(); + + bool is_equal = std::equal(begin, end, itr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_const_reverse_iterator) + { + static constexpr Text::const_reverse_iterator ritr = text.rbegin(); + + etl::reverse_iterator rbegin(text_pointer + Length); + etl::reverse_iterator rend(text_pointer); + + bool is_equal = std::equal(rbegin, rend, ritr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_to_view) + { + static constexpr View view(text); + + CHECK_TRUE(text.begin() == view.begin()); + CHECK_TRUE(text.end() == view.end()); + + bool is_equal = std::equal(text.begin(), text.end(), view.begin()); + CHECK_TRUE(is_equal); + } + }; +} + +#endif diff --git a/test/test_const_string_wchar_t.cpp b/test/test_const_string_wchar_t.cpp new file mode 100644 index 00000000..e44f237e --- /dev/null +++ b/test/test_const_string_wchar_t.cpp @@ -0,0 +1,543 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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 "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/const_wstring.h" +#include "etl/string_view.h" + +#if ETL_USING_CPP14 + +#undef STR +#define STR(x) L##x + +namespace +{ + SUITE(test_const_string_wchar_t) + { + using Text = etl::const_wstring; + using View = etl::wstring_view; + + using TextSTD = std::wstring; + + static constexpr Text::const_pointer text_pointer = STR("Hello World"); + static constexpr Text text(STR("Hello World")); + static constexpr size_t Length = etl::strlen(STR("Hello World")); + + //************************************************************************* + template + bool Equal(const T1& compare_text, const T2& test_text) + { + return (compare_text.size() == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text.begin()); + } + + //************************************************************************* + template + bool Equal(const T1* compare_text, const T2& test_text) + { + return (etl::strlen(compare_text) == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text); + } + + //************************************************************************* + TEST(test_constructor_null_string) + { + static constexpr Text text_from_literal_empty(STR("")); + + static constexpr auto text_empty = text_from_literal_empty.empty(); + CHECK_TRUE(text_empty); + + static constexpr auto text_full = text_from_literal_empty.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal_empty.capacity(); + CHECK_EQUAL(0, text_capacity); + + static constexpr auto text_max_size = text_from_literal_empty.max_size(); + CHECK_EQUAL(0, text_max_size); + + static constexpr auto text_size = text_from_literal_empty.size(); + CHECK_EQUAL(0, text_size); + + static constexpr auto text_length = text_from_literal_empty.length(); + CHECK_EQUAL(0, text_length); + + static constexpr auto text_available = text_from_literal_empty.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal_empty.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal_empty.is_secure(); + CHECK_FALSE(text_is_secure); + } + + //************************************************************************* + TEST(test_constructor_char_pointer) + { + static constexpr Text text_from_pointer(text_pointer); + + static constexpr auto text_empty = text_from_pointer.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_pointer.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_pointer.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_pointer.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_pointer.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_pointer.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_pointer.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_pointer.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_pointer.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_pointer.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_pointer.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_pointer.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_pointer.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_pointer.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_pointer.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_pointer.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_pointer.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_pointer.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_pointer.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::wstring(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_from_literal) + { + static constexpr Text text_from_literal(STR("Hello World")); + + static constexpr auto text_empty = text_from_literal.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_literal.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_literal.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_literal.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_literal.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_literal.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_literal.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_literal.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_literal.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_literal.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_literal.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_literal.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_literal.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_literal.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_literal.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_literal.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::wstring(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_truncated) + { + static constexpr Text text_from_pointer(text_pointer, true); + static constexpr Text text_from_literal(STR("Hello World"), true); + + static constexpr auto text_from_pointer_is_truncated = text_from_pointer.is_truncated(); + CHECK_TRUE(text_from_pointer_is_truncated); + + static constexpr auto text_from_literal_is_truncated = text_from_literal.is_truncated(); + CHECK_TRUE(text_from_literal_is_truncated); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + static constexpr Text text_copy(text); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::wstring(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_copy_constructor_from_truncated) + { + static constexpr Text text_original(STR("Hello World"), true); + static constexpr Text text_copy(text_original); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_TRUE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::wstring(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_begin) + { + static constexpr Text::const_iterator p_begin = text.begin(); + static constexpr Text::const_iterator p_cbegin = text.cbegin(); + + CHECK_EQUAL(&text_pointer[0], p_begin); + CHECK_EQUAL(&text_pointer[0], p_cbegin); + } + + //************************************************************************* + TEST(test_index) + { + static constexpr Text::value_type c0 = text[0]; + static constexpr Text::value_type c1 = text[1]; + static constexpr Text::value_type c2 = text[2]; + static constexpr Text::value_type c3 = text[3]; + static constexpr Text::value_type c4 = text[4]; + static constexpr Text::value_type c5 = text[5]; + static constexpr Text::value_type c6 = text[6]; + static constexpr Text::value_type c7 = text[7]; + static constexpr Text::value_type c8 = text[8]; + static constexpr Text::value_type c9 = text[9]; + static constexpr Text::value_type c10 = text[10]; + static constexpr Text::value_type c11 = text[11]; + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + CHECK_EQUAL(text_pointer[11], c11); + } + + //************************************************************************* + TEST(test_at) + { + static constexpr Text::value_type c0 = text.at(0); + static constexpr Text::value_type c1 = text.at(1); + static constexpr Text::value_type c2 = text.at(2); + static constexpr Text::value_type c3 = text.at(3); + static constexpr Text::value_type c4 = text.at(4); + static constexpr Text::value_type c5 = text.at(5); + static constexpr Text::value_type c6 = text.at(6); + static constexpr Text::value_type c7 = text.at(7); + static constexpr Text::value_type c8 = text.at(8); + static constexpr Text::value_type c9 = text.at(9); + static constexpr Text::value_type c10 = text.at(10); + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + } + + //************************************************************************* + TEST(test_front) + { + CHECK_TRUE(text_pointer[0] == text.front()); + } + + //************************************************************************* + TEST(test_back) + { + CHECK_TRUE(text_pointer[Length - 1] == text.back()); + } + + //************************************************************************* + TEST(test_data) + { + static constexpr Text::const_pointer p_data = text.data(); + + CHECK_EQUAL(&text[0], p_data); + } + + //************************************************************************* + TEST(test_data_end) + { + static constexpr Text::const_pointer p_data = text.data_end(); + + CHECK_EQUAL(&text[Length], p_data); + } + + //************************************************************************* + TEST(test_c_str) + { + static constexpr Text::const_pointer p_data = text.c_str(); + + CHECK_EQUAL(&text[0], p_data); + CHECK_EQUAL(Length, etl::strlen(p_data)); + } + + //************************************************************************* + TEST(test_const_iterator) + { + static constexpr Text::const_iterator itr = text.begin(); + + Text::const_iterator begin = text.begin(); + Text::const_iterator end = text.end(); + + bool is_equal = std::equal(begin, end, itr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_const_reverse_iterator) + { + static constexpr Text::const_reverse_iterator ritr = text.rbegin(); + + etl::reverse_iterator rbegin(text_pointer + Length); + etl::reverse_iterator rend(text_pointer); + + bool is_equal = std::equal(rbegin, rend, ritr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_to_view) + { + static constexpr View view(text); + + CHECK_TRUE(text.begin() == view.begin()); + CHECK_TRUE(text.end() == view.end()); + + bool is_equal = std::equal(text.begin(), text.end(), view.begin()); + CHECK_TRUE(is_equal); + } + + //************************************************************************* +#if ETL_USING_STL + TEST(test_write_string_to_std_basic_ostream) + { + Text text1(STR("Hello World")); + + std::wstringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif + }; +} + +#endif diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 0e5888bb..217e7ec1 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -1403,7 +1403,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1429,7 +1429,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS;ETL_NO_STL;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS;ETL_NO_STL;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1455,7 +1455,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_FORCE_TEST_CPP03_IMPLEMENTATION;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_FORCE_TEST_CPP03_IMPLEMENTATION;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1481,7 +1481,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_FORCE_TEST_CPP03_IMPLEMENTATION;ETL_MESSAGES_ARE_NOT_VIRTUAL;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_FORCE_TEST_CPP03_IMPLEMENTATION;ETL_MESSAGES_ARE_NOT_VIRTUAL;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1507,7 +1507,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_MESSAGES_ARE_NOT_VIRTUAL;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_MESSAGES_ARE_NOT_VIRTUAL;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1533,7 +1533,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_IMESSAGE_IS_NON_VIRTUAL;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_IMESSAGE_IS_NON_VIRTUAL;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1559,7 +1559,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1585,7 +1585,7 @@ Level3 MaxSpeed - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1611,7 +1611,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1636,7 +1636,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1661,7 +1661,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_NO_STL;ETL_FORCE_STD_INITIALIZER_LIST;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_NO_STL;ETL_FORCE_STD_INITIALIZER_LIST;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1686,7 +1686,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_NO_STL;ETL_FORCE_STD_INITIALIZER_LIST;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_NO_STL;ETL_FORCE_STD_INITIALIZER_LIST;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1711,7 +1711,7 @@ Level3 MaxSpeed - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_NO_STL;ETL_FORCE_STD_INITIALIZER_LIST;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_NO_STL;ETL_FORCE_STD_INITIALIZER_LIST;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1737,7 +1737,7 @@ Level3 MaxSpeed - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_NO_STL;ETL_FORCE_STD_INITIALIZER_LIST;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_NO_STL;ETL_FORCE_STD_INITIALIZER_LIST;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test @@ -1948,7 +1948,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;ETL_NO_STL;ETL_FORCE_STD_INITIALIZER_LIST;%(PreprocessorDefinitions);N = 123456789;N + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;ETL_NO_STL;ETL_FORCE_STD_INITIALIZER_LIST;%(PreprocessorDefinitions) ./;../../../unittest-cpp/;../../include;../../test @@ -3293,11 +3293,16 @@ + + + + + @@ -9333,6 +9338,10 @@ + + + + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index a6ec09da..e91c2fb9 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1533,6 +1533,21 @@ ETL\Strings + + ETL\Strings + + + ETL\Strings + + + ETL\Strings + + + ETL\Strings + + + ETL\Strings + @@ -3695,6 +3710,18 @@ Tests\Strings + + Tests\Strings + + + Tests\Strings + + + Tests\Strings + + + Tests\Strings + @@ -3853,6 +3880,12 @@ Resource Files + + Tests + + + Tests + @@ -3891,6 +3924,7 @@ Tests\Syntax Checks +