diff --git a/.github/workflows/clang-c++11.yml b/.github/workflows/clang-c++11.yml index 0f1d647b..3bfb863c 100644 --- a/.github/workflows/clang-c++11.yml +++ b/.github/workflows/clang-c++11.yml @@ -15,7 +15,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -37,7 +37,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | diff --git a/.github/workflows/clang-c++14.yml b/.github/workflows/clang-c++14.yml index 816dcc54..6ec45fdb 100644 --- a/.github/workflows/clang-c++14.yml +++ b/.github/workflows/clang-c++14.yml @@ -15,7 +15,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -37,7 +37,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | diff --git a/.github/workflows/clang-c++17.yml b/.github/workflows/clang-c++17.yml index 9259f2a6..789ce3be 100644 --- a/.github/workflows/clang-c++17.yml +++ b/.github/workflows/clang-c++17.yml @@ -15,7 +15,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -37,7 +37,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | diff --git a/.github/workflows/clang-c++20.yml b/.github/workflows/clang-c++20.yml index 34e85e54..37d0b75b 100644 --- a/.github/workflows/clang-c++20.yml +++ b/.github/workflows/clang-c++20.yml @@ -15,7 +15,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # Temporary fix. See https://github.com/actions/runner-images/issues/8659 - name: Install newer Clang @@ -44,7 +44,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # Temporary fix. See https://github.com/actions/runner-images/issues/8659 - name: Install newer Clang @@ -73,7 +73,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # Temporary fix. See https://github.com/actions/runner-images/issues/8659 - name: Install newer Clang @@ -99,10 +99,10 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [macos-12] + os: [macos-13] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -121,10 +121,10 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [macos-12] + os: [macos-13] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -143,10 +143,10 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [macos-12] + os: [macos-13] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -165,10 +165,10 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [macos-12] + os: [macos-13] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | diff --git a/.github/workflows/clang-syntax-checks.yml b/.github/workflows/clang-syntax-checks.yml index 67b9eafb..2baf9ef2 100644 --- a/.github/workflows/clang-syntax-checks.yml +++ b/.github/workflows/clang-syntax-checks.yml @@ -14,13 +14,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++03 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -32,13 +32,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++03 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -50,13 +50,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++11 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -68,13 +68,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++11 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -86,13 +86,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++11 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -104,13 +104,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++11 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -122,13 +122,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++14 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -140,13 +140,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++14 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -158,13 +158,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++14 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -176,13 +176,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++14 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -194,13 +194,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++17 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -212,13 +212,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++17 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -230,13 +230,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++17 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -248,13 +248,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++17 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -266,13 +266,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++20 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -284,13 +284,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++20 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -302,13 +302,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++20 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) @@ -320,12 +320,12 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=clang export CXX=clang++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++20 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check clang --version make -j $(getconf _NPROCESSORS_ONLN) diff --git a/.github/workflows/gcc-c++11.yml b/.github/workflows/gcc-c++11.yml index 67010d5e..030d2482 100644 --- a/.github/workflows/gcc-c++11.yml +++ b/.github/workflows/gcc-c++11.yml @@ -15,7 +15,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -38,7 +38,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | diff --git a/.github/workflows/gcc-c++14.yml b/.github/workflows/gcc-c++14.yml index c037f3bb..9220446f 100644 --- a/.github/workflows/gcc-c++14.yml +++ b/.github/workflows/gcc-c++14.yml @@ -15,7 +15,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -37,7 +37,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | diff --git a/.github/workflows/gcc-c++17.yml b/.github/workflows/gcc-c++17.yml index d780311c..34929496 100644 --- a/.github/workflows/gcc-c++17.yml +++ b/.github/workflows/gcc-c++17.yml @@ -15,7 +15,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -37,7 +37,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | diff --git a/.github/workflows/gcc-c++20.yml b/.github/workflows/gcc-c++20.yml index 06b98344..be28e824 100644 --- a/.github/workflows/gcc-c++20.yml +++ b/.github/workflows/gcc-c++20.yml @@ -15,7 +15,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -37,7 +37,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -59,7 +59,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | @@ -81,7 +81,7 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | diff --git a/.github/workflows/gcc-syntax-checks.yml b/.github/workflows/gcc-syntax-checks.yml index 75e17ef8..75bcafa3 100644 --- a/.github/workflows/gcc-syntax-checks.yml +++ b/.github/workflows/gcc-syntax-checks.yml @@ -14,13 +14,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++03 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -32,13 +32,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++03 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -50,13 +50,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++11 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -68,13 +68,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++11 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -86,13 +86,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++11 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -104,13 +104,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++11 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -122,13 +122,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++14 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -140,13 +140,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++14 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -158,13 +158,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++14 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -176,13 +176,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++14 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -194,13 +194,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++17 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -212,13 +212,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++17 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -230,13 +230,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++17 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -248,13 +248,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++17 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -266,13 +266,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++20 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -284,13 +284,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check/c++20 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -302,13 +302,13 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++20 + cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) @@ -320,12 +320,12 @@ jobs: os: [ubuntu-22.04] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build run: | export CC=gcc export CXX=g++ - cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check/c++20 + cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON ./test/syntax_check gcc --version make -j $(getconf _NPROCESSORS_ONLN) \ No newline at end of file diff --git a/.github/workflows/msvc.yml b/.github/workflows/msvc.yml index c63a35c2..8324c507 100644 --- a/.github/workflows/msvc.yml +++ b/.github/workflows/msvc.yml @@ -12,7 +12,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive @@ -33,7 +33,7 @@ jobs: runs-on: [windows-2022] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive @@ -55,7 +55,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive @@ -77,7 +77,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive diff --git a/.gitignore b/.gitignore index 420a66d3..8caedc19 100644 --- a/.gitignore +++ b/.gitignore @@ -388,6 +388,15 @@ support/time remaining test.xlsx test/vs2022/Debug MSVC C++20 - Force C++03 test/vs2022/Release MSVC C++20 - No STL - Optimised -O2 - Sanitiser test/test_file_list.txt +examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/CopilotIndices +examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/FileContentIndex +examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/v17 +test/etl_error_handler/assert_errors/build-make +test/etl_error_handler/assert_function/build-make +test/syntax_check/bgcc +test/syntax_check/bclang +test/vs2022/Debug Clang C++20 +test/vs2022/Debug MSVC C++20 - Forve C++03 - No virtual messages test/reflog.txt test/etl_error_handler/assert_function/build-make test/syntax_check/bgcc diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..3c1aa1c9 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,13 @@ +# How to contribute + +If your are considering creating a pull request, please observe the following: + +- If you are adding or modifying a feature, add *new* unit tests that test that feature. +- If you are fixing a bug, add a unit test that *fails* before the bug fix is implemented. +- Do not initiate a pull request until all of the units tests pass. +- Branches should be based on the branch `master`. + +There is a project file for VS2022 for C++14, 17, 20, and bash scripts that run the tests for C++11, 14, 17, 20 under Linux with GCC and Clang. + +If you are thinking of adding a new feature then raise this on the GitHub Issues page for disccussion as the maintainers and user of the ETL may have questions or suggestions. +It is possible that the maintainer of the ETL or another contributor is already working on the same or related feature. diff --git a/README.md b/README.md index d7c9c02b..50c564c7 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ The library is intended for any compiler that supports C++98/03/11/14/17/20. - Checksums & hash functions - Variants (a type that can store many types in a type-safe interface) - Choice of asserts, exceptions, error handler or no checks on errors -- Unit tested (currently over 6480 tests), using VS2019, GCC 8.1.0, , GCC 9.3.0, Clang 9.0.0 & 10.0.0 +- Unit tested (currently over 9400 tests), using VS2022, GCC 12, Clang 14. - Many utilities for template support. - Easy to read and documented source. - Free support via email, GitHub and Slack diff --git a/appveyor.yml b/appveyor.yml index a3cba3df..0b8eef40 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,11 +16,5 @@ install: build: project: test/vs2022/etl.vcxproj verbosity: minimal -notifications: -- provider: Webhook - url: https://hooks.slack.com/services/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 - method: POST - on_build_success: true - on_build_failure: true - on_build_status_changed: true + \ No newline at end of file diff --git a/arduino/library-arduino.json b/arduino/library-arduino.json index 84249819..f3956d8c 100644 --- a/arduino/library-arduino.json +++ b/arduino/library-arduino.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library ETL", - "version": "20.39.0", + "version": "20.40.0", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/arduino/library-arduino.properties b/arduino/library-arduino.properties index 9689dd75..307259d1 100644 --- a/arduino/library-arduino.properties +++ b/arduino/library-arduino.properties @@ -1,5 +1,5 @@ name=Embedded Template Library ETL -version=20.39.0 +version=20.40.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/cmake/helpers.cmake b/cmake/helpers.cmake index 9249fb4e..4624f3c2 100644 --- a/cmake/helpers.cmake +++ b/cmake/helpers.cmake @@ -13,7 +13,7 @@ function(determine_version_with_git) git_describe(VERSION ${ARGN}) string(FIND ${VERSION} "." VALID_VERSION) if(VALID_VERSION EQUAL -1) - if(PROJECT_IS_TOP_LEVEL) + if(CMAKE_CURRENT_LIST_DIR STREQUAL PROJECT_SOURCE_DIR) # only warn if this is the top-level project, since we may be # building from a tarball as a subproject message(WARNING "Version string ${VERSION} retrieved with git describe is invalid") diff --git a/examples/QueuedMessageRouter/QueuedMessageRouter.cpp b/examples/QueuedMessageRouter/QueuedMessageRouter.cpp index d4f78f77..f4348e5e 100644 --- a/examples/QueuedMessageRouter/QueuedMessageRouter.cpp +++ b/examples/QueuedMessageRouter/QueuedMessageRouter.cpp @@ -52,8 +52,6 @@ public: typedef etl::message_router Base_t; - using Base_t::receive; - //*************************************************************************** Router() : message_router(1) diff --git a/examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.sln b/examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.sln similarity index 100% rename from examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.sln rename to examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.sln diff --git a/examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.vcxproj b/examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.vcxproj similarity index 97% rename from examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.vcxproj rename to examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.vcxproj index 65dad150..eaacbe96 100644 --- a/examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.vcxproj +++ b/examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.vcxproj @@ -29,26 +29,26 @@ Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index 3929a57d..5dc231bb 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -1449,16 +1449,20 @@ namespace etl TCompare compare) { TIterator minimum = begin; - ++begin; - while (begin != end) + if (begin != end) { - if (compare(*begin, *minimum)) - { - minimum = begin; - } - ++begin; + + while (begin != end) + { + if (compare(*begin, *minimum)) + { + minimum = begin; + } + + ++begin; + } } return minimum; @@ -1493,16 +1497,20 @@ namespace etl TCompare compare) { TIterator maximum = begin; - ++begin; - while (begin != end) + if (begin != end) { - if (!compare(*begin, *maximum)) - { - maximum = begin; - } - ++begin; + + while (begin != end) + { + if (!compare(*begin, *maximum)) + { + maximum = begin; + } + + ++begin; + } } return maximum; @@ -1538,21 +1546,25 @@ namespace etl { TIterator minimum = begin; TIterator maximum = begin; - ++begin; - while (begin != end) + if (begin != end) { - if (compare(*begin, *minimum)) - { - minimum = begin; - } - - if (compare(*maximum, *begin)) - { - maximum = begin; - } - ++begin; + + while (begin != end) + { + if (compare(*begin, *minimum)) + { + minimum = begin; + } + + if (compare(*maximum, *begin)) + { + maximum = begin; + } + + ++begin; + } } return ETL_OR_STD::pair(minimum, maximum); diff --git a/include/etl/alignment.h b/include/etl/alignment.h index c6a4de06..627517be 100644 --- a/include/etl/alignment.h +++ b/include/etl/alignment.h @@ -36,6 +36,7 @@ SOFTWARE. #include "static_assert.h" #include "error_handler.h" #include "exception.h" +#include "utility.h" #include @@ -71,6 +72,19 @@ namespace etl } }; + //*************************************************************************** + /// Typed storage exception. + //*************************************************************************** + class typed_storage_error : public alignment_exception + { + public: + + typed_storage_error(string_type file_name_, numeric_type line_number_) + : alignment_exception(ETL_ERROR_TEXT("typed_storage:error", ETL_ALIGNMENT_FILE_ID"B"), file_name_, line_number_) + { + } + }; + //***************************************************************************** /// Check that 'p' has 'required_alignment'. //***************************************************************************** @@ -334,6 +348,167 @@ namespace etl template using aligned_storage_as_t = typename aligned_storage_as::type; #endif + + //*************************************************************************** + /// Wrapper class that provides a memory area and lets the user create an + /// instance of T in this memory at runtime. This class also erases the + /// destructor call of T, i.e. if typed_storage goes out of scope, the + /// destructor if the wrapped type will not be called. This can be done + /// explicitly by calling destroy(). + /// \tparam T Type of element stored in this instance of typed_storage. + //*************************************************************************** + template + class typed_storage + { + public: + + typedef T value_type; + typedef T& reference; + typedef const T& const_reference; + typedef T* pointer; + typedef const T* const_pointer; + + // Constructor + typed_storage() + : valid(false) + { + } + + //*************************************************************************** + /// Default destructor which will NOT call the destructor of the object which + /// was created by calling create(). + //*************************************************************************** + ~typed_storage() = default; + + //*************************************************************************** + /// Calls the destructor of the wrapped object and asserts if has_value() is false. + //*************************************************************************** + void destroy() + { + ETL_ASSERT(has_value(), ETL_ERROR(etl::typed_storage_error)); + data.template get_reference().~T(); + valid = false; + } + + //*************************************************************************** + /// \returns true if object has been constructed using create(). + /// \returns false otherwise. + //*************************************************************************** + bool has_value() const + { + return valid; + } + +#if ETL_USING_CPP11 + //*************************************************************************** + /// Constructs the instance of T forwarding the given \p args to its constructor and + /// asserts if has_value() is false. + /// + /// \returns the instance of T which has been constructed in the internal byte array. + //*************************************************************************** + template + reference create(Args&&... args) + { + ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); + valid = true; + return *::new (data.template get_address()) value_type(etl::forward(args)...); + } +#else + //*************************************************************************** + /// Constructs the instance of T with type T1 + /// asserts if has_value() is false. + /// + /// \returns the instance of T which has been constructed in the internal byte array. + //*************************************************************************** + template + reference create(const T1& t1) + { + ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); + valid = true; + return *::new (data.template get_address()) value_type(t1); + } + + //*************************************************************************** + /// Constructs the instance of T with types T1, T2 + /// asserts if has_value() is false. + /// + /// \returns the instance of T which has been constructed in the internal byte array. + //*************************************************************************** + template + reference create(const T1& t1, const T2& t2) + { + ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); + valid = true; + return *::new (data.template get_address()) value_type(t1, t2); + } + + //*************************************************************************** + /// Constructs the instance of T with types T1, T2, T3 + /// asserts if has_value() is false. + /// + /// \returns the instance of T which has been constructed in the internal byte array. + //*************************************************************************** + template + reference create(const T1& t1, const T2& t2, const T3& t3) + { + ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); + valid = true; + return *::new (data.template get_address()) value_type(t1, t2, t3); + } + + //*************************************************************************** + /// Constructs the instance of T with types T1, T2, T3, T4 + /// asserts if has_value() is false. + /// + /// \returns the instance of T which has been constructed in the internal byte array. + //*************************************************************************** + template + reference create(const T1& t1, const T2& t2, const T3& t3, const T4& t4) + { + ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); + valid = true; + return *::new (data.template get_address()) value_type(t1, t2, t3, t4); + } +#endif + + //*************************************************************************** + /// \returns a pointer of type T and asserts if has_value() is false. + //*************************************************************************** + pointer operator->() + { + ETL_ASSERT(has_value(), ETL_ERROR(etl::typed_storage_error)); + return data.template get_address(); + } + + //*************************************************************************** + /// \returns a const pointer of type T and asserts if has_value() is false. + //*************************************************************************** + const_pointer operator->() const + { + return operator->(); + } + + //*************************************************************************** + /// \returns reference of type T and asserts if has_value() is false. + //*************************************************************************** + reference operator*() + { + return *operator->(); + } + + //*************************************************************************** + /// \returns const reference of type T and asserts if has_value() is false. + //*************************************************************************** + const_reference operator*() const + { + return *operator->(); + } + + private: + + typename aligned_storage_as::type data; + bool valid; + }; } #endif diff --git a/include/etl/array_view.h b/include/etl/array_view.h index f388f287..653bf0b0 100644 --- a/include/etl/array_view.h +++ b/include/etl/array_view.h @@ -239,19 +239,19 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR array_view(const TIterator begin_, const TIterator end_) - : mbegin(etl::addressof(*begin_)), - mend(etl::addressof(*begin_) + etl::distance(begin_, end_)) + : mbegin(etl::to_address(begin_)), + mend(etl::to_address(begin_) + etl::distance(begin_, end_)) { } //************************************************************************* - /// Construct from C array + /// Construct from iterator and size //************************************************************************* template ETL_CONSTEXPR array_view(const TIterator begin_, const TSize size_) - : mbegin(etl::addressof(*begin_)), - mend(etl::addressof(*begin_) + size_) + : mbegin(etl::to_address(begin_)), + mend(etl::to_address(begin_) + size_) { } @@ -458,8 +458,8 @@ namespace etl template void assign(const TIterator begin_, const TIterator end_) { - mbegin = etl::addressof(*begin_); - mend = etl::addressof(*begin_) + etl::distance(begin_, end_); + mbegin = etl::to_address(begin_); + mend = etl::to_address(begin_) + etl::distance(begin_, end_); } //************************************************************************* @@ -469,8 +469,8 @@ namespace etl typename TSize> void assign(const TIterator begin_, const TSize size_) { - mbegin = etl::addressof(*begin_); - mend = etl::addressof(*begin_) + size_; + mbegin = etl::to_address(begin_); + mend = etl::to_address(begin_) + size_; } #if defined(ETL_ARRAY_VIEW_IS_MUTABLE) diff --git a/include/etl/atomic/atomic_gcc_sync.h b/include/etl/atomic/atomic_gcc_sync.h index 9e7399aa..67c7c8bf 100644 --- a/include/etl/atomic/atomic_gcc_sync.h +++ b/include/etl/atomic/atomic_gcc_sync.h @@ -83,7 +83,7 @@ namespace etl // Only integral and pointer types are supported. //*************************************************************************** - enum memory_order + typedef enum memory_order { memory_order_relaxed = __ATOMIC_RELAXED, memory_order_consume = __ATOMIC_CONSUME, @@ -91,13 +91,22 @@ namespace etl memory_order_release = __ATOMIC_RELEASE, memory_order_acq_rel = __ATOMIC_ACQ_REL, memory_order_seq_cst = __ATOMIC_SEQ_CST + } memory_order; + + template + struct atomic_traits + { + static ETL_CONSTANT bool is_always_lock_free = Is_Always_Lock_Free; }; + template + ETL_CONSTANT bool atomic_traits::is_always_lock_free; + //*************************************************************************** /// For all types except bool, pointers and types that are always lock free. //*************************************************************************** template ::value> - class atomic + class atomic : public atomic_traits { public: @@ -389,7 +398,7 @@ namespace etl /// Specialisation for pointers //*************************************************************************** template - class atomic + class atomic : public atomic_traits { public: @@ -631,7 +640,7 @@ namespace etl /// Specialisation for bool //*************************************************************************** template <> - class atomic + class atomic : public atomic_traits { public: @@ -794,7 +803,7 @@ namespace etl /// Uses a mutex to control access. //*************************************************************************** template - class atomic + class atomic : public atomic_traits { public: @@ -1030,11 +1039,20 @@ namespace etl memory_order_seq_cst } memory_order; + template + struct atomic_traits + { + static ETL_CONSTANT bool is_always_lock_free = Is_Always_Lock_Free; + }; + + template + ETL_CONSTANT bool atomic_traits::is_always_lock_free; + //*************************************************************************** /// For all types except bool and pointers //*************************************************************************** template ::value> - class atomic + class atomic : public atomic_traits { public: @@ -1440,7 +1458,7 @@ namespace etl /// Specialisation for pointers //*************************************************************************** template - class atomic + class atomic : public atomic_traits { public: @@ -1750,7 +1768,7 @@ namespace etl /// Specialisation for bool //*************************************************************************** template <> - class atomic + class atomic : public atomic_traits { public: @@ -1973,7 +1991,7 @@ namespace etl /// Uses a mutex to control access. //*************************************************************************** template - class atomic + class atomic : public atomic_traits { public: @@ -2234,3 +2252,4 @@ namespace etl } #endif + diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 1371e80a..0b0404b5 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -38,13 +38,11 @@ SOFTWARE. #include "char_traits.h" #include "alignment.h" #include "array.h" -#include "algorithm.h" #include "type_traits.h" #include "error_handler.h" #include "integral_limits.h" #include "exception.h" #include "memory.h" -#include "exception.h" #include "binary.h" #include "flags.h" @@ -52,6 +50,14 @@ SOFTWARE. #include #include +#if ETL_USING_STL && ETL_USING_CPP17 + #include +#endif + +#if ETL_USING_STL + #include +#endif + #include "private/minmax_push.h" //***************************************************************************** @@ -60,6 +66,13 @@ SOFTWARE. ///\ingroup containers //***************************************************************************** +// Forward declaration of string_view +namespace etl +{ + template + class basic_string_view; +} + namespace etl { //*************************************************************************** @@ -127,7 +140,7 @@ namespace etl public: string_truncation(string_type file_name_, numeric_type line_number_) - : string_exception(ETL_ERROR_TEXT("string:iterator", ETL_BASIC_STRING_FILE_ID"D"), file_name_, line_number_) + : string_exception(ETL_ERROR_TEXT("string:truncation", ETL_BASIC_STRING_FILE_ID"D"), file_name_, line_number_) { } }; @@ -232,7 +245,6 @@ namespace etl return max_size() - size(); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS //************************************************************************* /// Returns whether the string was truncated by the last operation. /// Deprecated. Use is_truncated() @@ -241,7 +253,11 @@ namespace etl ETL_DEPRECATED bool truncated() const { +#if ETL_HAS_STRING_TRUNCATION_CHECKS return flags.test(); +#else + return false; +#endif } //************************************************************************* @@ -250,9 +266,14 @@ namespace etl //************************************************************************* bool is_truncated() const { +#if ETL_HAS_STRING_TRUNCATION_CHECKS return flags.test(); +#else + return false; +#endif } +#if ETL_HAS_STRING_TRUNCATION_CHECKS //************************************************************************* /// Clears the 'truncated' flag. //************************************************************************* @@ -270,15 +291,19 @@ namespace etl { flags.set(); } +#endif //************************************************************************* /// Gets the 'secure' state flag. //************************************************************************* bool is_secure() const { +#if ETL_HAS_STRING_CLEAR_AFTER_USE return flags.test(); - } +#else + return false; #endif + } protected: @@ -489,6 +514,22 @@ namespace etl cleanup(); } + //********************************************************************* + /// Resizes the string and overwrites to data using the operation. + //********************************************************************* + template + void resize_and_overwrite(size_type new_size, TOperation operation) + { + if (new_size > CAPACITY) + { + ETL_ASSERT_FAIL(ETL_ERROR(string_out_of_bounds)); + } + + current_size = operation(p_buffer, new_size); + p_buffer[current_size] = '\0'; + cleanup(); + } + //********************************************************************* /// Resizes the string, but doesn't initialise the free space /// except for a terminator null. @@ -635,27 +676,10 @@ namespace etl //********************************************************************* void assign(const etl::ibasic_string& other) { - assign(other.begin(), other.end()); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - if (other.is_truncated()) + if (&other != this) { - set_truncated(true); - -#if ETL_HAS_ERROR_ON_STRING_TRUNCATION - ETL_ASSERT_FAIL(ETL_ERROR(string_truncation)); -#endif + assign_impl(other.begin(), other.end(), other.is_truncated(), other.is_secure()); } -#endif - -#if ETL_HAS_STRING_CLEAR_AFTER_USE - if (other.is_secure()) - { - set_secure(); - } -#endif - - cleanup(); } //********************************************************************* @@ -667,83 +691,17 @@ namespace etl //********************************************************************* void assign(const etl::ibasic_string& other, size_type subposition, size_type sublength) { - if (sublength == npos) + if (&other != this) { - sublength = other.size() - subposition; + if (sublength == npos) + { + sublength = other.size() - subposition; + } + + ETL_ASSERT(subposition <= other.size(), ETL_ERROR(string_out_of_bounds)); + + assign_impl(other.begin() + subposition, other.begin() + subposition + sublength, other.is_truncated(), other.is_secure()); } - - ETL_ASSERT(subposition <= other.size(), ETL_ERROR(string_out_of_bounds)); - - assign(other.begin() + subposition, sublength); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - if (other.is_truncated()) - { - this->set_truncated(true); - -#if ETL_HAS_ERROR_ON_STRING_TRUNCATION - ETL_ASSERT_FAIL(ETL_ERROR(string_truncation)); -#endif - } -#endif - -#if ETL_HAS_STRING_CLEAR_AFTER_USE - if (other.is_secure()) - { - set_secure(); - } -#endif - } - - //********************************************************************* - /// Assigns values to the string. - /// Truncates if the string does not have enough free space. - ///\param other The other string. - //********************************************************************* - void assign(const_pointer other) - { - initialise(); - - while ((*other != 0) && (current_size < CAPACITY)) - { - p_buffer[current_size++] = *other++; - } - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - set_truncated(*other != 0); - -#if ETL_HAS_ERROR_ON_STRING_TRUNCATION - ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)); -#endif -#endif - - p_buffer[current_size] = 0; - } - - //********************************************************************* - /// Assigns values to the string. - /// Truncates if the string does not have enough free space. - ///\param other The other string. - ///\param length The length to copy. - //********************************************************************* - void assign(const_pointer other, size_type length_) - { - initialise(); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - set_truncated(length_ > CAPACITY); - -#if ETL_HAS_ERROR_ON_STRING_TRUNCATION - ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)); -#endif -#endif - - length_ = etl::min(length_, CAPACITY); - - etl::copy_n(other, length_, begin()); - - current_size = length_; - p_buffer[current_size] = 0; } //********************************************************************* @@ -756,27 +714,37 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if ETL_IS_DEBUG_BUILD - difference_type d = etl::distance(first, last); - ETL_ASSERT(d >= 0, ETL_ERROR(string_iterator)); -#endif + assign_impl(first, last, false, false); + } - initialise(); + //********************************************************************* + /// Assigns values to the string. + /// Truncates if the string does not have enough free space. + ///\param other The other string. + //********************************************************************* + void assign(const_pointer text) + { + assign_impl(text, text + etl::strlen(text), false, false); + } - while ((first != last) && (current_size != CAPACITY)) - { - p_buffer[current_size++] = *first++; - } + //********************************************************************* + /// Assigns values to the string. + /// Truncates if the string does not have enough free space. + ///\param other The other string. + ///\param length The length to copy. + //********************************************************************* + void assign(const_pointer text, size_type length_) + { + assign_impl(text, text + length_, false, false); + } - p_buffer[current_size] = 0; - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - set_truncated(first != last); - -#if ETL_HAS_ERROR_ON_STRING_TRUNCATION - ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)); -#endif -#endif + //********************************************************************* + /// Assigns values to the string from a view. + //********************************************************************* + template + void assign(const etl::basic_string_view& view) + { + assign_impl(view.begin(), view.end(), false, false); } //********************************************************************* @@ -929,6 +897,17 @@ namespace etl return *this; } + //********************************************************************* + /// Appends to the string. + ///\param view An etl::string_view. + //********************************************************************* + template + ibasic_string& append(const etl::basic_string_view& view) + { + insert(end(), view.begin(), view.end()); + return *this; + } + //********************************************************************* /// Inserts a value to the string. ///\param position The position to insert before. @@ -1159,6 +1138,18 @@ namespace etl return position_; } + //********************************************************************* + /// Inserts a view to the string. + /// If asserts or exceptions are enabled, emits string_full if the string does not have enough free space. + ///\param position The position to insert before. + ///\param view The view element to add. + //********************************************************************* + template + iterator insert(const_iterator position, const etl::basic_string_view& view) + { + return insert(position, view.begin(), view.end()); + } + //********************************************************************* /// Inserts a string at the specified position. ///\param position The position to insert before. @@ -1184,6 +1175,21 @@ namespace etl return *this; } + //********************************************************************* + /// Inserts a string at the specified position. + ///\param position The position to insert before. + ///\param view The view to insert. + //********************************************************************* + template + etl::ibasic_string& insert(size_type position, const etl::basic_string_view& view) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + + insert(begin() + position, view.cbegin(), view.cend()); + + return *this; + } + //********************************************************************* /// Inserts a string at the specified position from subposition for sublength. ///\param position The position to insert before. @@ -1193,7 +1199,7 @@ namespace etl //********************************************************************* etl::ibasic_string& insert(size_type position, const etl::ibasic_string& str, size_type subposition, size_type sublength) { - ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); if ((sublength == npos) || (subposition + sublength > str.size())) @@ -1217,6 +1223,29 @@ namespace etl return *this; } + //********************************************************************* + /// Inserts a view at the specified position from subposition for sublength. + ///\param position The position to insert before. + ///\param view The view to insert. + ///\param subposition The subposition to start from. + ///\param sublength The number of characters to insert. + //********************************************************************* + template + etl::ibasic_string& insert(size_type position, const etl::basic_string_view& view, size_type subposition, size_type sublength) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); + + if ((sublength == npos) || (subposition + sublength > view.size())) + { + sublength = view.size() - subposition; + } + + insert(begin() + position, view.cbegin() + subposition, view.cbegin() + subposition + sublength); + + return *this; + } + //********************************************************************* /// Inserts a string at the specified position from pointer. ///\param position The position to insert before. @@ -1374,21 +1403,18 @@ namespace etl //********************************************************************* size_type find(const ibasic_string& str, size_type pos = 0) const { - if ((pos + str.size()) > size()) - { - return npos; - } + return find_impl(str.begin(), str.end(), str.size(), pos); + } - const_iterator iposition = etl::search(begin() + pos, end(), str.begin(), str.end()); - - if (iposition == end()) - { - return npos; - } - else - { - return etl::distance(begin(), iposition); - } + //********************************************************************* + /// Find content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find(const etl::basic_string_view& view, size_type pos = 0) const + { + return find_impl(view.begin(), view.end(), view.size(), pos); } //********************************************************************* @@ -1398,23 +1424,9 @@ namespace etl //********************************************************************* size_type find(const_pointer s, size_type pos = 0) const { -#if ETL_IS_DEBUG_BUILD - if ((pos + etl::strlen(s)) > size()) - { - return npos; - } -#endif + size_t sz = etl::strlen(s); - const_iterator iposition = etl::search(begin() + pos, end(), s, s + etl::strlen(s)); - - if (iposition == end()) - { - return npos; - } - else - { - return etl::distance(begin(), iposition); - } + return find_impl(s, s + sz, sz, pos); } //********************************************************************* @@ -1425,23 +1437,9 @@ namespace etl //********************************************************************* size_type find(const_pointer s, size_type pos, size_type n) const { -#if ETL_IS_DEBUG_BUILD - if ((pos + etl::strlen(s) - n) > size()) - { - return npos; - } -#endif + size_t sz = etl::strlen(s); - const_iterator iposition = etl::search(begin() + pos, end(), s, s + n); - - if (iposition == end()) - { - return npos; - } - else - { - return etl::distance(begin(), iposition); - } + return find_impl(s, s + n, sz, pos); } //********************************************************************* @@ -1470,28 +1468,18 @@ namespace etl //********************************************************************* size_type rfind(const ibasic_string& str, size_type position = npos) const { - if ((str.size()) > size()) - { - return npos; - } + return rfind_impl(str.rbegin(), str.rend(), str.size(), position); + } - if (position >= size()) - { - position = size(); - } - - position = size() - position; - - const_reverse_iterator iposition = etl::search(rbegin() + position, rend(), str.rbegin(), str.rend()); - - if (iposition == rend()) - { - return npos; - } - else - { - return size() - str.size() - etl::distance(rbegin(), iposition); - } + //********************************************************************* + /// Find content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type rfind(const etl::basic_string_view& view, size_type pos = 0) const + { + return rfind_impl(view.rbegin(), view.rend(), view.size(), pos); } //********************************************************************* @@ -1503,31 +1491,10 @@ namespace etl { size_type len = etl::strlen(s); - if (len > size()) - { - return npos; - } - - if (position >= size()) - { - position = size(); - } - - position = size() - position; - const_reverse_iterator srbegin(s + len); const_reverse_iterator srend(s); - const_reverse_iterator iposition = etl::search(rbegin() + position, rend(), srbegin, srend); - - if (iposition == rend()) - { - return npos; - } - else - { - return size() - len - etl::distance(rbegin(), iposition); - } + return rfind_impl(srbegin, srend, len, position); } //********************************************************************* @@ -1537,31 +1504,10 @@ namespace etl //********************************************************************* size_type rfind(const_pointer s, size_type position, size_type length_) const { - if (length_ > size()) - { - return npos; - } - - if (position >= size()) - { - position = size(); - } - - position = size() - position; - const_reverse_iterator srbegin(s + length_); const_reverse_iterator srend(s); - const_reverse_iterator iposition = etl::search(rbegin() + position, rend(), srbegin, srend); - - if (iposition == rend()) - { - return npos; - } - else - { - return size() - length_ - etl::distance(rbegin(), iposition); - } + return rfind_impl(srbegin, srend, length_, position); } //********************************************************************* @@ -1590,6 +1536,124 @@ namespace etl } } + //********************************************************************* + /// Checks that the string is within this string + //********************************************************************* + bool contains(const etl::ibasic_string& str) const + { + return find(str) != npos; + } + + //********************************************************************* + /// Checks that the view is within this string + //********************************************************************* + template + bool contains(const etl::basic_string_view& view) const + { + return find(view) != npos; + } + + //********************************************************************* + /// Checks that text is within this string + //********************************************************************* + bool contains(const_pointer s) const + { + return find(s) != npos; + } + + //********************************************************************* + /// Checks that character is within this string + //********************************************************************* + bool contains(value_type c) const + { + return find(c) != npos; + } + + //********************************************************************* + /// Checks that the string is the start of this string + //********************************************************************* + bool starts_with(const etl::ibasic_string& str) const + { + return compare(0, str.size(), str) == 0; + } + + //********************************************************************* + /// Checks that the view is the start of this string + //********************************************************************* + template + bool starts_with(const etl::basic_string_view& view) const + { + return compare(0, view.size(), view) == 0; + } + + //********************************************************************* + /// Checks that the string is the start of this string + //********************************************************************* + bool starts_with(const_pointer s) const + { + size_t len = etl::strlen(s); + + return compare(0, len, s, len) == 0; + } + + //********************************************************************* + /// Checks that the character is the start of this string + //********************************************************************* + bool starts_with(value_type c) const + { + return !empty() && (front() == c); + } + + //********************************************************************* + /// Checks that the string is the end of this string + //********************************************************************* + bool ends_with(const etl::ibasic_string& str) const + { + if (str.size() > size()) + { + return false; + } + + return compare(size() - str.size(), str.size(), str) == 0; + } + + //********************************************************************* + /// Checks that the view is the end of this string + //********************************************************************* + template + bool ends_with(const etl::basic_string_view& view) const + { + if (view.size() > size()) + { + return false; + } + + return compare(size() - view.size(), view.size(), view) == 0; + } + + //********************************************************************* + /// Checks that the string is the end of this string + //********************************************************************* + bool ends_with(const_pointer s) const + { + size_t len = etl::strlen(s); + + if (len > size()) + { + return false; + } + + return compare(size() - len, len, s, len) == 0; + } + + //********************************************************************* + /// Checks that the character is the end of this string + //********************************************************************* + bool ends_with(value_type c) const + { + return !empty() && (back() == c); + } + //********************************************************************* /// Replace 'length' characters from 'position' with 'str'. ///\param position The position to start from. @@ -1612,6 +1676,29 @@ namespace etl return *this; } + //********************************************************************* + /// Replace 'length' characters from 'position' with 'view'. + ///\param position The position to start from. + ///\param length The number of characters to replace. + ///\param view The string to replace it with. + //********************************************************************* + template + ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + + // Limit the length. + length_ = etl::min(length_, size() - position); + + // Erase the bit we want to replace. + erase(position, length_); + + // Insert the new stuff. + insert(position, view); + + return *this; + } + //********************************************************************* /// Replace characters from 'first' to one before 'last' with 'str'. ///\param first The position to start from. @@ -1622,7 +1709,7 @@ namespace etl { // Quick hack, as iterators are pointers. iterator first_ = to_iterator(first); - iterator last_ = to_iterator(last); + iterator last_ = to_iterator(last); // Erase the bit we want to replace. erase(first_, last_); @@ -1644,6 +1731,28 @@ namespace etl return *this; } + //********************************************************************* + /// Replace characters from 'first' to one before 'last' with 'view'. + ///\param first The position to start from. + ///\param last The one after the position to end at. + ///\param view The string view to replace it with. + //********************************************************************* + template + ibasic_string& replace(const_iterator first, const_iterator last, const etl::basic_string_view& view) + { + // Quick hack, as iterators are pointers. + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); + + // Erase the bit we want to replace. + erase(first_, last_); + + // Insert the new stuff. + insert(first_, view.begin(), view.end()); + + return *this; + } + //********************************************************************* /// Replace characters from 'position' of 'length' with 'str' from 'subposition' of 'sublength'. //********************************************************************* @@ -1653,7 +1762,7 @@ namespace etl ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); // Limit the lengths. - length_ = etl::min(length_, size() - position); + length_ = etl::min(length_, size() - position); sublength = etl::min(sublength, str.size() - subposition); // Erase the bit we want to replace. @@ -1676,6 +1785,28 @@ namespace etl return *this; } + //********************************************************************* + /// Replace characters from 'position' of 'length' with 'view' from 'subposition' of 'sublength'. + //********************************************************************* + template + ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); + + // Limit the lengths. + length_ = etl::min(length_, size() - position); + sublength = etl::min(sublength, view.size() - subposition); + + // Erase the bit we want to replace. + erase(position, length_); + + // Insert the new stuff. + insert(position, view, subposition, sublength); + + return *this; + } + //********************************************************************* /// Replace characters from 'position' of 'length' with pointed to string. //********************************************************************* @@ -1817,6 +1948,18 @@ namespace etl str.p_buffer + str.size()); } + //************************************************************************* + /// Compare with etl::basic_string_view. + //************************************************************************* + template + int compare(const etl::basic_string_view& view) const + { + return compare(p_buffer, + p_buffer + size(), + view.data(), + view.data() + view.size()); + } + //************************************************************************* /// Compare position / length with string. //************************************************************************* @@ -1833,6 +1976,18 @@ namespace etl str.p_buffer + str.size()); } + //************************************************************************* + /// Compare position / length with etl::basic_string_view. + //************************************************************************* + template + int compare(size_type position, size_type length_, const etl::basic_string_view& view) const + { + return compare(p_buffer + position, + p_buffer + position + length_, + view.data(), + view.data() + view.size()); + } + //************************************************************************* /// Compare position / length with string / subposition / sublength. //************************************************************************* @@ -1851,6 +2006,25 @@ namespace etl str.p_buffer + subposition + sublength); } + //************************************************************************* + /// 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_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); + + // Limit the lengths. + length_ = etl::min(length_, size() - position); + sublength = etl::min(sublength, view.size() - subposition); + + return compare(p_buffer + position, + p_buffer + position + length_, + view.data() + subposition, + view.data() + subposition + sublength); + } + //************************************************************************* /// Compare with C string //************************************************************************* @@ -1904,6 +2078,17 @@ namespace etl return find_first_of(s, position, etl::strlen(s)); } + //********************************************************************* + /// Find first of any of content within the string + ///\param view The content to find + ///\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 + { + return find_first_of(view.data(), position, view.size()); + } + //********************************************************************* /// Find first of any of content within the string ///\param s Pointer to the content to find @@ -1970,6 +2155,17 @@ namespace etl return find_last_of(s, position, etl::strlen(s)); } + //********************************************************************* + /// Find last of any of content within the string + ///\param view The content to find + ///\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 + { + return find_last_of(view.data(), position, view.size()); + } + //********************************************************************* /// Find last of any of content within the string ///\param s Pointer to the content to find @@ -2054,6 +2250,17 @@ namespace etl return find_first_not_of(s, position, etl::strlen(s)); } + //********************************************************************* + /// Find first not of any of content within the string + ///\param view The content to find + ///\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 + { + return find_first_not_of(view.data(), position, view.size()); + } + //********************************************************************* /// Find first not of any of content within the string ///\param s Pointer to the content to not find @@ -2127,6 +2334,17 @@ namespace etl return find_last_not_of(s, position, etl::strlen(s)); } + //********************************************************************* + /// Find last not of any of content within the string + ///\param view The content to find + ///\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 + { + return find_last_not_of(view.data(), position, view.size()); + } + //********************************************************************* /// Find last not of any of content within the string ///\param s The pointer to the content to find @@ -2219,6 +2437,17 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + template + ibasic_string& operator = (const etl::basic_string_view& view) + { + assign(view); + + return *this; + } + //************************************************************************* /// += operator. //************************************************************************* @@ -2229,6 +2458,17 @@ namespace etl return *this; } + //************************************************************************* + /// += operator. + //************************************************************************* + template + ibasic_string& operator += (const etl::basic_string_view& rhs) + { + append(rhs); + + return *this; + } + //************************************************************************* /// += operator. //************************************************************************* @@ -2319,7 +2559,7 @@ namespace etl //************************************************************************* /// Compare helper function //************************************************************************* - int compare(const_pointer first1, const_pointer last1, const_pointer first2, const_pointer last2) const + int compare(const_pointer first1, const_pointer last1, const_pointer first2, const_pointer last2) const { while ((first1 != last1) && (first2 != last2)) { @@ -2407,6 +2647,99 @@ namespace etl { return const_cast(itr); } + + private: + + //********************************************************************* + /// Common implementation for 'assign'. + //********************************************************************* + template + void assign_impl(TIterator first, TIterator last, bool truncated, bool secure) + { +#if ETL_IS_DEBUG_BUILD + difference_type d = etl::distance(first, last); + ETL_ASSERT(d >= 0, ETL_ERROR(string_iterator)); +#endif + + initialise(); + + while ((first != last) && (current_size != CAPACITY)) + { + p_buffer[current_size++] = *first++; + } + + p_buffer[current_size] = 0; + +#if ETL_HAS_STRING_TRUNCATION_CHECKS + set_truncated((first != last) || truncated); + +#if ETL_HAS_ERROR_ON_STRING_TRUNCATION + ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)); +#endif +#endif + +#if ETL_HAS_STRING_CLEAR_AFTER_USE + if (secure) + { + set_secure(); + } +#endif + + cleanup(); + } + + //************************************************************************* + /// Common implementation for 'find'. + //************************************************************************* + template + size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const + { + if ((pos + sz) > size()) + { + return npos; + } + + const_iterator iposition = etl::search(begin() + pos, end(), first, last); + + if (iposition == end()) + { + return npos; + } + else + { + return etl::distance(begin(), iposition); + } + } + + //************************************************************************* + /// Common implementation for 'rfind'. + //************************************************************************* + template + size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const + { + if (sz > size()) + { + return npos; + } + + if (pos >= size()) + { + pos = size(); + } + + pos = size() - pos; + + const_reverse_iterator iposition = etl::search(rbegin() + pos, rend(), rfirst, rlast); + + if (iposition == rend()) + { + return npos; + } + else + { + return size() - sz - etl::distance(rbegin(), iposition); + } + } }; //*************************************************************************** @@ -2645,6 +2978,23 @@ namespace etl { return !(lhs < rhs); } + + //*************************************************************************** + /// 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::ibasic_string& str) + { + os.write(str.data(), str.size()); + return os; + } +#endif } #include "private/minmax_pop.h" diff --git a/include/etl/bip_buffer_spsc_atomic.h b/include/etl/bip_buffer_spsc_atomic.h index 5333dc68..f8c0eff1 100644 --- a/include/etl/bip_buffer_spsc_atomic.h +++ b/include/etl/bip_buffer_spsc_atomic.h @@ -86,13 +86,13 @@ namespace etl //*************************************************************************** /// The common base for a bip_buffer_spsc_atomic_base. //*************************************************************************** - template + template class bip_buffer_spsc_atomic_base { public: /// The type used for determining the size of buffer. - typedef typename etl::size_type_lookup::type size_type; + typedef typename etl::size_type_lookup::type size_type; //************************************************************************* /// Returns true if the buffer is empty. @@ -168,7 +168,7 @@ namespace etl //************************************************************************* size_type capacity() const { - return RESERVED; + return Reserved; } //************************************************************************* @@ -176,7 +176,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return RESERVED; + return Reserved; } protected: @@ -188,7 +188,7 @@ namespace etl : read(0) , write(0) , last(0) - , RESERVED(reserved_) + , Reserved(reserved_) { } @@ -341,7 +341,7 @@ namespace etl etl::atomic read; etl::atomic write; etl::atomic last; - const size_type RESERVED; + const size_type Reserved; #if defined(ETL_POLYMORPHIC_SPSC_BIP_BUFFER_ATOMIC) || defined(ETL_POLYMORPHIC_CONTAINERS) public: @@ -361,12 +361,12 @@ namespace etl //*************************************************************************** /// A fixed capacity bipartite buffer. //*************************************************************************** - template - class ibip_buffer_spsc_atomic : public bip_buffer_spsc_atomic_base + template + class ibip_buffer_spsc_atomic : public bip_buffer_spsc_atomic_base { private: - typedef typename etl::bip_buffer_spsc_atomic_base base_t; + typedef typename etl::bip_buffer_spsc_atomic_base base_t; using base_t::reset; using base_t::get_read_reserve; using base_t::apply_read_reserve; @@ -486,15 +486,15 @@ namespace etl /// A fixed capacity bipartite buffer. /// This buffer supports concurrent access by one producer and one consumer. /// \tparam T The type this buffer should support. - /// \tparam SIZE The maximum capacity of the buffer. - /// \tparam MEMORY_MODEL The memory model for the buffer. Determines the type of the internal counter variables. + /// \tparam Size The maximum capacity of the buffer. + /// \tparam Memory_Model The memory model for the buffer. Determines the type of the internal counter variables. //*************************************************************************** - template - class bip_buffer_spsc_atomic : public ibip_buffer_spsc_atomic + template + class bip_buffer_spsc_atomic : public ibip_buffer_spsc_atomic { private: - typedef typename etl::ibip_buffer_spsc_atomic base_t; + typedef typename etl::ibip_buffer_spsc_atomic base_t; public: @@ -502,19 +502,19 @@ namespace etl private: - static ETL_CONSTANT size_type RESERVED_SIZE = size_type(SIZE); + static ETL_CONSTANT size_type Reserved_Size = size_type(Size); public: - ETL_STATIC_ASSERT((SIZE <= (etl::integral_limits::max)), "Size too large for memory model"); + ETL_STATIC_ASSERT((Size <= (etl::integral_limits::max)), "Size too large for memory model"); - static ETL_CONSTANT size_type MAX_SIZE = size_type(SIZE); + static ETL_CONSTANT size_type MAX_SIZE = size_type(Size); //************************************************************************* /// Default constructor. //************************************************************************* bip_buffer_spsc_atomic() - : base_t(reinterpret_cast(buffer.raw), RESERVED_SIZE) + : base_t(reinterpret_cast(buffer.raw), Reserved_Size) { } @@ -529,11 +529,11 @@ namespace etl private: /// The uninitialised buffer of T used in the bip_buffer_spsc. - etl::uninitialized_buffer_of buffer; + etl::uninitialized_buffer_of buffer; }; - template - ETL_CONSTANT typename bip_buffer_spsc_atomic::size_type bip_buffer_spsc_atomic::RESERVED_SIZE; + template + ETL_CONSTANT typename bip_buffer_spsc_atomic::size_type bip_buffer_spsc_atomic::Reserved_Size; } #endif /* ETL_HAS_ATOMIC && ETL_USING_CPP11 */ diff --git a/include/etl/bit_stream.h b/include/etl/bit_stream.h index 7c5b557e..b58c5882 100644 --- a/include/etl/bit_stream.h +++ b/include/etl/bit_stream.h @@ -236,8 +236,8 @@ namespace etl while (nbits != 0) { unsigned char mask_width = static_cast(etl::min(nbits, bits_available_in_char)); - - typedef typename etl::make_unsigned::type chunk_t; + + typedef typename etl::make_unsigned::type chunk_t; chunk_t chunk = get_chunk(mask_width); nbits -= mask_width; @@ -529,7 +529,7 @@ namespace etl typedef char value_type; typedef value_type* iterator; - typedef const value_type* const_iterator; + typedef const value_type* const_iterator; typedef etl::span callback_parameter_type; typedef etl::delegate callback_type; diff --git a/include/etl/circular_buffer.h b/include/etl/circular_buffer.h index 0902f0da..a6967d82 100644 --- a/include/etl/circular_buffer.h +++ b/include/etl/circular_buffer.h @@ -251,7 +251,7 @@ namespace etl //************************************************************************* reference operator [](size_t index) { - return pbuffer[(current + index) % picb->buffer_size]; + return picb->pbuffer[(current + index) % picb->buffer_size]; } //************************************************************************* @@ -259,7 +259,7 @@ namespace etl //************************************************************************* const_reference operator [](size_t index) const { - return pbuffer[(current + index) % picb->buffer_size]; + return picb->pbuffer[(current + index) % picb->buffer_size]; } //************************************************************************* @@ -438,7 +438,7 @@ namespace etl //*************************************************** pointer get_buffer() const { - return pbuffer; + return picb->pbuffer; } protected: @@ -550,7 +550,7 @@ namespace etl //************************************************************************* const_reference operator [](size_t index) const { - return pbuffer[(current + index) % picb->buffer_size]; + return picb->pbuffer[(current + index) % picb->buffer_size]; } //************************************************************************* @@ -717,7 +717,7 @@ namespace etl //*************************************************** pointer get_buffer() const { - return pbuffer; + return picb->pbuffer; } protected: diff --git a/include/etl/crc1.h b/include/etl/crc1.h index 305f894e..47986991 100644 --- a/include/etl/crc1.h +++ b/include/etl/crc1.h @@ -52,19 +52,19 @@ namespace etl }; //********************************* - value_type initial() const + ETL_CONSTEXPR14 value_type initial() const { return even_parity; } //********************************* - uint8_t add(int parity, uint8_t value) const + ETL_CONSTEXPR14 uint8_t add(int parity, uint8_t value) const { return parity ^ etl::parity(value); } //********************************* - uint8_t final(uint8_t parity) const + ETL_CONSTEXPR14 uint8_t final(uint8_t parity) const { return parity; } @@ -83,7 +83,7 @@ namespace etl //************************************************************************* /// Default constructor. //************************************************************************* - crc1() + ETL_CONSTEXPR14 crc1() { this->reset(); } @@ -94,7 +94,7 @@ namespace etl /// \param end End of the range. //************************************************************************* template - crc1(TIterator begin, const TIterator end) + ETL_CONSTEXPR14 crc1(TIterator begin, const TIterator end) { this->reset(); this->add(begin, end); diff --git a/include/etl/debug_count.h b/include/etl/debug_count.h index ebbfb13e..9e15c21a 100644 --- a/include/etl/debug_count.h +++ b/include/etl/debug_count.h @@ -158,23 +158,16 @@ inline void swap(etl::debug_count& lhs, etl::debug_count& rhs) } #else - #define ETL_DECLARE_DEBUG_COUNT etl::debug_count etl_debug_count - #define ETL_SET_DEBUG_COUNT(n) ETL_DO_NOTHING - #define ETL_GET_DEBUG_COUNT ETL_DO_NOTHING - #define ETL_INCREMENT_DEBUG_COUNT ETL_DO_NOTHING - #define ETL_DECREMENT_DEBUG_COUNT ETL_DO_NOTHING - #define ETL_ADD_DEBUG_COUNT(n) ETL_DO_NOTHING - #define ETL_SUBTRACT_DEBUG_COUNT(n) ETL_DO_NOTHING - #define ETL_RESET_DEBUG_COUNT ETL_DO_NOTHING - #define ETL_OBJECT_RESET_DEBUG_COUNT(object) ETL_DO_NOTHING - #define ETL_OBJECT_GET_DEBUG_COUNT(object) ETL_DO_NOTHING - -namespace etl -{ - class debug_count - { - }; -} + #define ETL_DECLARE_DEBUG_COUNT + #define ETL_SET_DEBUG_COUNT(n) + #define ETL_GET_DEBUG_COUNT + #define ETL_INCREMENT_DEBUG_COUNT + #define ETL_DECREMENT_DEBUG_COUNT + #define ETL_ADD_DEBUG_COUNT(n) + #define ETL_SUBTRACT_DEBUG_COUNT(n) + #define ETL_RESET_DEBUG_COUNT + #define ETL_OBJECT_RESET_DEBUG_COUNT(object) + #define ETL_OBJECT_GET_DEBUG_COUNT(object) #endif // ETL_DEBUG_COUNT #endif diff --git a/include/etl/error_handler.h b/include/etl/error_handler.h index b08a0d4b..f0c60be6 100644 --- a/include/etl/error_handler.h +++ b/include/etl/error_handler.h @@ -255,6 +255,38 @@ namespace etl } }; } +#elif defined(ETL_USE_ASSERT_FUNCTION) +namespace etl +{ + namespace private_error_handler + { + typedef void(*assert_function_ptr_t)(const etl::exception&); + + // Stores the assert function pointer and default assert function. + template + struct assert_handler + { + static assert_function_ptr_t assert_function_ptr; + + static void default_assert(const etl::exception&) + { + assert(false); + } + }; + + template + assert_function_ptr_t assert_handler::assert_function_ptr = assert_handler::default_assert; + } + + //*************************************************************************** + /// Sets the assert function. + /// The argument function signature is void(*)(const etl::exception&) + //*************************************************************************** + void set_assert_function(etl::private_error_handler::assert_function_ptr_t afptr) + { + etl::private_error_handler::assert_handler<0>::assert_function_ptr = afptr; + } +} #endif //*************************************************************************** @@ -264,6 +296,7 @@ namespace etl /// If ETL_NO_CHECKS is defined then no runtime checks are executed at all. /// If asserts or exceptions are enabled then the error is thrown if the assert fails. The return value is always 'true'. /// If ETL_LOG_ERRORS is defined then the error is logged if the assert fails. The return value is the value of the boolean test. +/// If ETL_USE_ASSERT_FUNCTION is defined then the error is sent to the assert function. /// Otherwise 'assert' is called. The return value is always 'true'. ///\ingroup error_handler //*************************************************************************** @@ -275,6 +308,14 @@ namespace etl #define ETL_ASSERT_FAIL(e) ETL_DO_NOTHING // Does nothing. #define ETL_ASSERT_FAIL_AND_RETURN(e) ETL_DO_NOTHING // Does nothing. #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) ETL_DO_NOTHING // Does nothing. +#elif defined(ETL_USE_ASSERT_FUNCTION) + #define ETL_ASSERT(b, e) {if(!(b)) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e));}} // If the condition fails, calls the assert function + #define ETL_ASSERT_OR_RETURN(b, e) {if(!(b)) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return;}} // If the condition fails, calls the assert function and return + #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if(!(b)) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return (v);}} // If the condition fails, calls the assert function and return a value + + #define ETL_ASSERT_FAIL(e) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e));} // Calls the assert function + #define ETL_ASSERT_FAIL_AND_RETURN(e) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return;} // Calls the assert function and return + #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return (v);} // Calls the assert function and return a value #elif ETL_USING_EXCEPTIONS #if defined(ETL_LOG_ERRORS) #define ETL_ASSERT(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e));}} // If the condition fails, calls the error handler then throws an exception. @@ -292,7 +333,6 @@ namespace etl #define ETL_ASSERT_FAIL(e) {throw((e));} // Throws an exception. #define ETL_ASSERT_FAIL_AND_RETURN(e) {throw((e));} // Throws an exception. #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {throw((e));} // Throws an exception. - #endif #else #if defined(ETL_LOG_ERRORS) @@ -314,8 +354,8 @@ namespace etl #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {assert(false); return(v);} // Asserts. #else #define ETL_ASSERT(b, e) // Does nothing. - #define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) return;} // Returns. - #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) return(v);} // Returns a value. + #define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) return;} // Returns. + #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) return(v);} // Returns a value. #define ETL_ASSERT_FAIL(e) // Does nothing. #define ETL_ASSERT_FAIL_AND_RETURN(e) {return;} // Returns. diff --git a/include/etl/expected.h b/include/etl/expected.h index 0dc4a584..fd68ac85 100644 --- a/include/etl/expected.h +++ b/include/etl/expected.h @@ -188,7 +188,7 @@ namespace etl //******************************************* /// Get the error. - //******************************************* + //******************************************* ETL_CONSTEXPR14 TError&& error() const&& ETL_NOEXCEPT { return etl::move(error_value); @@ -350,7 +350,7 @@ namespace etl //******************************************* template ETL_CONSTEXPR14 explicit expected(etl::in_place_t, Args&&... args) - : storage(etl::forward(args)...) + : storage(etl::in_place_index_t(), etl::forward(args)...) { } @@ -360,7 +360,7 @@ namespace etl //******************************************* template ETL_CONSTEXPR14 explicit expected(etl::in_place_t, std::initializer_list il, Args&&... args) - : storage(il, etl::forward(args)...) + : storage(etl::in_place_index_t(), il, etl::forward(args)...) { } #endif @@ -500,7 +500,7 @@ namespace etl //******************************************* /// Get the value. //******************************************* - value_type& value() const + const value_type& value() const { return etl::get(storage); } @@ -511,7 +511,7 @@ namespace etl //******************************************* ETL_NODISCARD ETL_CONSTEXPR14 - bool has_value() const + bool has_value() const ETL_NOEXCEPT { return (storage.index() == Value_Type); } @@ -521,7 +521,8 @@ namespace etl //******************************************* ETL_NODISCARD ETL_CONSTEXPR14 - operator bool() const + ETL_EXPLICIT + operator bool() const ETL_NOEXCEPT { return has_value(); } @@ -659,7 +660,7 @@ namespace etl //******************************************* /// //******************************************* - error_type& error() const + const error_type& error() const { return etl::get(storage); } @@ -865,8 +866,8 @@ namespace etl /// Returns true if expected has a value //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - bool has_value() const + ETL_CONSTEXPR14 + bool has_value() const ETL_NOEXCEPT { return (storage.index() != Error_Type); } @@ -875,8 +876,9 @@ namespace etl /// Returns true if expected has a value //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - operator bool() const + ETL_CONSTEXPR14 + ETL_EXPLICIT + operator bool() const ETL_NOEXCEPT { return has_value(); } @@ -887,8 +889,8 @@ namespace etl /// Undefined behaviour if an error has not been set. //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - error_type& error()& ETL_NOEXCEPT + ETL_CONSTEXPR14 + error_type& error()& ETL_NOEXCEPT { return etl::get(storage); } @@ -898,8 +900,8 @@ namespace etl /// Undefined behaviour if an error has not been set. //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - const error_type& error() const& ETL_NOEXCEPT + ETL_CONSTEXPR14 + const error_type& error() const& ETL_NOEXCEPT { return etl::get(storage); } @@ -909,8 +911,8 @@ namespace etl /// Undefined behaviour if an error has not been set. //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - error_type&& error() && ETL_NOEXCEPT + ETL_CONSTEXPR14 + error_type&& error() && ETL_NOEXCEPT { return etl::move(etl::get(storage)); } @@ -920,8 +922,8 @@ namespace etl /// Undefined behaviour if an error has not been set. //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - const error_type&& error() const&& ETL_NOEXCEPT + ETL_CONSTEXPR14 + const error_type&& error() const&& ETL_NOEXCEPT { return etl::move(etl::get(storage)); } @@ -930,7 +932,7 @@ namespace etl /// Returns the error /// Undefined behaviour if an error has not been set. //******************************************* - error_type& error() const + const error_type& error() const { return etl::get(storage); } @@ -1105,4 +1107,3 @@ void swap(etl::unexpected& lhs, etl::unexpected& rhs) } #endif - diff --git a/include/etl/file_error_numbers.h b/include/etl/file_error_numbers.h index a866ce41..2369f68c 100644 --- a/include/etl/file_error_numbers.h +++ b/include/etl/file_error_numbers.h @@ -103,5 +103,8 @@ SOFTWARE. #define ETL_EXPECTED_FILE_ID "70" #define ETL_ALIGNMENT_FILE_ID "71" #define ETL_BASE64_FILE_ID "72" +#define ETL_SINGLETON_BASE_FILE_ID "73" +#define ETL_UNALIGNED_TYPE_FILE_ID "74" +#define ETL_SPAN_FILE_ID "75" #endif diff --git a/include/etl/frame_check_sequence.h b/include/etl/frame_check_sequence.h index ec67e1ba..6a21e93d 100644 --- a/include/etl/frame_check_sequence.h +++ b/include/etl/frame_check_sequence.h @@ -107,7 +107,8 @@ namespace etl //************************************************************************* /// Default constructor. //************************************************************************* - frame_check_sequence() + ETL_CONSTEXPR14 frame_check_sequence() + : frame_check() { reset(); } @@ -118,7 +119,7 @@ namespace etl /// \param end End of the range. //************************************************************************* template - frame_check_sequence(TIterator begin, const TIterator end) + ETL_CONSTEXPR14 frame_check_sequence(TIterator begin, const TIterator end) : frame_check() { ETL_STATIC_ASSERT(sizeof(typename etl::iterator_traits::value_type) == 1, "Type not supported"); @@ -129,7 +130,7 @@ namespace etl //************************************************************************* /// Resets the FCS to the initial state. //************************************************************************* - void reset() + ETL_CONSTEXPR14 void reset() { frame_check = policy.initial(); } @@ -140,7 +141,7 @@ namespace etl /// \param end //************************************************************************* template - void add(TIterator begin, const TIterator end) + ETL_CONSTEXPR14 void add(TIterator begin, const TIterator end) { ETL_STATIC_ASSERT(sizeof(typename etl::iterator_traits::value_type) == 1, "Type not supported"); @@ -154,7 +155,7 @@ namespace etl //************************************************************************* /// \param value The uint8_t to add to the FCS. //************************************************************************* - void add(uint8_t value_) + ETL_CONSTEXPR14 void add(uint8_t value_) { frame_check = policy.add(frame_check, value_); } @@ -162,7 +163,7 @@ namespace etl //************************************************************************* /// Gets the FCS value. //************************************************************************* - value_type value() const + ETL_CONSTEXPR14 value_type value() const { return policy.final(frame_check); } @@ -170,7 +171,7 @@ namespace etl //************************************************************************* /// Conversion operator to value_type. //************************************************************************* - operator value_type () const + ETL_CONSTEXPR14 operator value_type () const { return policy.final(frame_check); } @@ -178,7 +179,7 @@ namespace etl //************************************************************************* /// Gets an add_insert_iterator for input. //************************************************************************* - add_insert_iterator input() + ETL_CONSTEXPR14 add_insert_iterator input() { return add_insert_iterator(*this); } diff --git a/include/etl/function_traits.h b/include/etl/function_traits.h new file mode 100644 index 00000000..5d30d684 --- /dev/null +++ b/include/etl/function_traits.h @@ -0,0 +1,136 @@ +///\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_FUNCTION_TRAITS_INCLUDED +#define ETL_FUNCTION_TRAITS_INCLUDED + +#include "platform.h" +#include "type_list.h" +#include "type_traits.h" + +#if ETL_USING_CPP11 +namespace etl +{ + //*************************************************************************** + /// A template to extract the function type traits. + //*************************************************************************** + template + struct function_traits; + + //*************************************************************************** + /// Specialisation for function pointers + //*************************************************************************** + template + struct function_traits + { + using function_type = TReturn(TArgs...); ///< The signature of the function. + using return_type = TReturn; ///< The return type. + using object_type = void; ///< The object type, if a member function. + using argument_types = etl::type_list; ///< An etl::type_list containing the function argument types. + + static constexpr bool is_function = true; ///< true if the type is a free, static or global function, otherwise false. + static constexpr bool is_member_function = false; ///< true if the type is a member function, otherwise false. + static constexpr bool is_const = false; ///< true if the type is a const member function, otherwise false. + static constexpr size_t argument_count = sizeof...(TArgs); ///< The number of arguments that the function takes. + }; + + template + constexpr bool function_traits::is_function; + + template + constexpr bool function_traits::is_member_function; + + template + constexpr bool function_traits::is_const; + + template + constexpr size_t function_traits::argument_count; + + //*************************************************************************** + /// Specialisation for member function pointers + //*************************************************************************** + template + struct function_traits + { + using function_type = TReturn(TArgs...); ///< The signature of the function. + using return_type = TReturn; ///< The return type. + using object_type = TObject; ///< The object type, if a member function. + using argument_types = etl::type_list; ///< An etl::type_list containing the function argument types. + + static constexpr bool is_function = false; ///< true if the type is a free, static or global function, otherwise false. + static constexpr bool is_member_function = true; ///< true if the type is a member function, otherwise false. + static constexpr bool is_const = false; ///< true if the type is a const member function, otherwise false. + static constexpr size_t argument_count = sizeof...(TArgs); ///< The number of arguments that the function takes. + }; + + template + constexpr bool function_traits::is_function; + + template + constexpr bool function_traits::is_member_function; + + template + constexpr bool function_traits::is_const; + + template + constexpr size_t function_traits::argument_count; + + //*************************************************************************** + /// Specialisation for const member function pointers + //*************************************************************************** + template + struct function_traits + { + using function_type = TReturn(TArgs...); ///< The signature of the function. + using return_type = TReturn; ///< The return type. + using object_type = TObject; ///< The object type, if a member function. + using argument_types = etl::type_list; ///< An etl::type_list containing the function argument types. + + static constexpr bool is_function = false; ///< true if the type is a free, static or global function, otherwise false. + static constexpr bool is_member_function = true; ///< true if the type is a member function, otherwise false. + static constexpr bool is_const = true; ///< true if the type is a const member function, otherwise false. + static constexpr size_t argument_count = sizeof...(TArgs); ///< The number of arguments that the function takes. + }; + + template + constexpr bool function_traits::is_function; + + template + constexpr bool function_traits::is_member_function; + + template + constexpr bool function_traits::is_const; + + template + constexpr size_t function_traits::argument_count; +} +#endif + +#endif diff --git a/include/etl/functional.h b/include/etl/functional.h index d762506c..7fb3e415 100644 --- a/include/etl/functional.h +++ b/include/etl/functional.h @@ -112,6 +112,39 @@ namespace etl return reference_wrapper(t.get()); } + //*************************************************************************** + /// unwrap_reference. + //*************************************************************************** + template + struct unwrap_reference + { + typedef T type; + }; + + template + struct unwrap_reference > + { + typedef T& type; + }; + +#if ETL_USING_CPP11 + template + using unwrap_reference_t = typename unwrap_reference::type; +#endif + + //*************************************************************************** + /// unwrap_ref_decay. + //*************************************************************************** + template + struct unwrap_ref_decay : etl::unwrap_reference::type> {}; + +#if ETL_USING_CPP11 + template + using unwrap_ref_decay_t = typename unwrap_ref_decay::type; +#endif + + //*************************************************************************** + /// unary_function //*************************************************************************** template struct unary_function @@ -120,6 +153,8 @@ namespace etl typedef TResultType result_type; }; + //*************************************************************************** + /// binary_function //*************************************************************************** template struct binary_function diff --git a/include/etl/generators/message_packet_generator.h b/include/etl/generators/message_packet_generator.h index 595fa12f..ae03d718 100644 --- a/include/etl/generators/message_packet_generator.h +++ b/include/etl/generators/message_packet_generator.h @@ -65,8 +65,6 @@ cog.outl("//******************************************************************** #include "platform.h" -#if ETL_HAS_VIRTUAL_MESSAGES - #include "message.h" #include "error_handler.h" #include "static_assert.h" @@ -298,11 +296,39 @@ namespace etl { etl::imessage* pmsg = static_cast(data); +#if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); +#else + delete_message(pmsg); +#endif } } #include "private/diagnostic_pop.h" +#if !ETL_HAS_VIRTUAL_MESSAGES + //******************************************** + void delete_message(etl::imessage* pmsg) + { + (delete_message_type(pmsg) || ...); + } + + //******************************************** + template + bool delete_message_type(etl::imessage* pmsg) + { + if (TType::ID == pmsg->get_message_id()) + { + TType* p = static_cast(pmsg); + p->~TType(); + return true; + } + else + { + return false; + } + } +#endif + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -671,12 +697,28 @@ namespace etl cog.outl(" {") cog.outl(" etl::imessage* pmsg = static_cast(data);") cog.outl("") + cog.outl("#if ETL_HAS_VIRTUAL_MESSAGES") cog.outl(" pmsg->~imessage();") + cog.outl("#else") + cog.outl(" delete_message(pmsg);") + cog.outl("#endif") cog.outl(" }") cog.outl(" }") cog.outl(" #include \"private/diagnostic_pop.h\"") cog.outl("") cog.outl(" //********************************************") + cog.outl(" void delete_message(etl::imessage* pmsg)") + cog.outl(" {") + cog.outl(" switch (pmsg->get_message_id())") + cog.outl(" {") + for n in range(1, int(Handlers) + 1): + cog.out(" case T%d::ID: static_cast(pmsg)->~T%d(); break;" % n) + cog.outl(" default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;") + cog.outl(" }") + cog.outl(" }") + cog.outl("") + cog.outl(" //********************************************") cog.outl(" void add_new_message(const etl::imessage& msg)") cog.outl(" {") cog.outl(" const size_t id = msg.get_message_id();") @@ -686,7 +728,7 @@ namespace etl cog.outl(" {") for n in range(1, int(Handlers) + 1): cog.outl(" case T%d::ID: ::new (p) T%d(static_cast(msg)); break;" %(n, n, n)) - cog.outl(" default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break;") + cog.outl(" default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;") cog.outl(" }") cog.outl(" }") cog.outl("") @@ -701,7 +743,7 @@ namespace etl cog.outl(" {") for n in range(1, int(Handlers) + 1): cog.outl(" case T%d::ID: ::new (p) T%d(static_cast(msg)); break;" %(n, n, n)) - cog.outl(" default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break;") + cog.outl(" default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;") cog.outl(" }") cog.outl(" }") cog.outl("#endif") @@ -959,12 +1001,29 @@ namespace etl cog.outl(" {") cog.outl(" etl::imessage* pmsg = static_cast(data);") cog.outl("") + cog.outl("") + cog.outl("#if ETL_HAS_VIRTUAL_MESSAGES") cog.outl(" pmsg->~imessage();") + cog.outl("#else") + cog.outl(" delete_message(pmsg);") + cog.outl("#endif") cog.outl(" }") cog.outl(" }") cog.outl(" #include \"private/diagnostic_pop.h\"") cog.outl("") cog.outl(" //********************************************") + cog.outl(" void delete_message(etl::imessage* pmsg)") + cog.outl(" {") + cog.outl(" switch (pmsg->get_message_id())") + cog.outl(" {") + for t in range(1, n + 1): + cog.out(" case T%d::ID: static_cast(pmsg)->~T%d(); break;" % t) + cog.outl(" default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;") + cog.outl(" }") + cog.outl(" }") + cog.outl("") + cog.outl(" //********************************************") cog.outl(" void add_new_message(const etl::imessage& msg)") cog.outl(" {") cog.outl(" const size_t id = msg.get_message_id();") @@ -974,7 +1033,7 @@ namespace etl cog.outl(" {") for t in range(1, n + 1): cog.outl(" case T%d::ID: ::new (p) T%d(static_cast(msg)); break;" %(t, t, t)) - cog.outl(" default: break;") + cog.outl(" default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;") cog.outl(" }") cog.outl(" }") cog.outl("") @@ -1001,8 +1060,5 @@ namespace etl /*[[[end]]]*/ #endif } -#else - #error "etl::message_packet is not compatible with non-virtual etl::imessage" -#endif #endif diff --git a/include/etl/generators/message_router_generator.h b/include/etl/generators/message_router_generator.h index 35d47d70..adad5be8 100644 --- a/include/etl/generators/message_router_generator.h +++ b/include/etl/generators/message_router_generator.h @@ -66,9 +66,7 @@ cog.outl("//******************************************************************** #include "platform.h" #include "message.h" #include "shared_message.h" -#if ETL_HAS_VIRTUAL_MESSAGES - #include "message_packet.h" -#endif +#include "message_packet.h" #include "message_types.h" #include "alignment.h" #include "error_handler.h" @@ -424,9 +422,7 @@ namespace etl { public: -#if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; -#endif //********************************************** message_router() @@ -584,12 +580,10 @@ namespace etl cog.outl("{") cog.outl("public:") cog.outl("") - cog.outl("#if ETL_HAS_VIRTUAL_MESSAGES") cog.out(" typedef etl::message_packet<") for n in range(1, int(Handlers)): cog.out("T%s, " % n) cog.outl(" T%s> message_packet;" % int(Handlers)) - cog.outl("#endif") cog.outl("") cog.outl(" //**********************************************") cog.outl(" message_router(etl::message_router_id_t id_)") @@ -754,12 +748,10 @@ namespace etl cog.outl("{") cog.outl("public:") cog.outl("") - cog.outl("#if ETL_HAS_VIRTUAL_MESSAGES") cog.out(" typedef etl::message_packet<") for t in range(1, n): cog.out("T%s, " % t) cog.outl(" T%s> message_packet;" % n) - cog.outl("#endif") cog.outl("") cog.outl(" //**********************************************") cog.outl(" message_router(etl::message_router_id_t id_)") diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index f086b841..ac421eb9 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -640,17 +640,12 @@ namespace etl { private: - template struct dummy {}; - struct internal: TDerived, dummy{}; - static TBase* check(TBase*) { return (TBase*)0; } - - template - static char check(dummy*) { return 0; } + static char check(...) { return 0; } public: - static const bool value = (sizeof(check((internal*)0)) == sizeof(TBase*)); + static const bool value = (sizeof(check((TDerived*)0)) == sizeof(TBase*)); }; // For when TBase or TDerived is a fundamental type. @@ -1339,6 +1334,79 @@ typedef integral_constant true_type; // ETL extended type traits. //*************************************************************************** +#if ETL_USING_CPP11 + //*************************************************************************** + /// conjunction +#if ETL_USING_CPP11 + template + struct conjunction : public etl::true_type + { + }; + + template + struct conjunction : public etl::conditional_t, T1> + { + }; + + template + struct conjunction : public T + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool conjunction_v = conjunction::value; +#endif + + //*************************************************************************** + /// disjunction +#if ETL_USING_CPP11 + template + struct disjunction : public etl::false_type + { + }; + + template + struct disjunction : public etl::conditional_t> + { + }; + + template struct disjunction : public T1 + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool disjunction_v = etl::disjunction::value; +#endif + +#endif + + //*************************************************************************** + /// exclusive_disjunction +#if ETL_USING_CPP11 + template + struct exclusive_disjunction; + + template + struct exclusive_disjunction : public etl::bool_constant + { + }; + + // Recursive case: XOR the first two values and recurse + template + struct exclusive_disjunction : public etl::exclusive_disjunction::value && !etl::conjunction::value>, TRest...> + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool exclusive_disjunction_v = etl::exclusive_disjunction::value; +#endif + //*************************************************************************** /// conditional_integral_constant // /\ingroup type_traits @@ -1361,19 +1429,11 @@ typedef integral_constant true_type; #if ETL_USING_CPP11 //*************************************************************************** - /// Template to determine if a type is one of a specified list. + /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types - template - struct is_one_of + template + struct is_one_of : etl::disjunction...> { - static const bool value = etl::is_same::value || - etl::is_one_of::value; - }; - - template - struct is_one_of - { - static const bool value = etl::is_same::value; }; #else /*[[[cog @@ -1406,21 +1466,46 @@ typedef integral_constant true_type; inline constexpr bool is_one_of_v = etl::is_one_of::value; #endif +#if ETL_USING_CPP11 + namespace private_type_traits + { + //*************************************************************************** + // Helper to count occurrences of a type in a list of types + template + struct count_type; + + // Base case: zero occurrences + template + struct count_type : etl::integral_constant + { + }; + + // Recursive case: increment count if head is the same as T, otherwise continue with tail + template + struct count_type : etl::integral_constant::value ? 1 : 0) + count_type::value> + { + }; + } + + template + struct has_duplicates_of + : etl::integral_constant::value > 1)> + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool has_duplicates_of_v = etl::has_duplicates_of::value; +#endif + #if ETL_USING_CPP11 //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types - template - struct is_base_of_all + template + struct is_base_of_all : etl::conjunction...> { - static const bool value = etl::is_base_of::value && - etl::is_base_of_all::value; - }; - - template - struct is_base_of_all - { - static const bool value = etl::is_base_of::value; }; #endif @@ -1433,18 +1518,11 @@ typedef integral_constant true_type; //*************************************************************************** /// Template to determine if a type is a base of any type in a specified list. ///\ingroup types - template - struct is_base_of_any + template + struct is_base_of_any : etl::disjunction...> { - static const bool value = etl::is_base_of::value || - etl::is_base_of_any::value; }; - template - struct is_base_of_any - { - static const bool value = etl::is_base_of::value; - }; #endif #if ETL_USING_CPP17 @@ -1452,6 +1530,28 @@ typedef integral_constant true_type; inline constexpr bool is_base_of_any_v = etl::is_base_of_any::value; #endif + //*************************************************************************** + /// Get the Nth base of a recursively inherited type. + /// Requires that the class has defined 'base_type'. + //*************************************************************************** + // Recursive definition of the type. + template + struct nth_base + { + typedef typename nth_base::type type; + }; + + template + struct nth_base<0, TType> + { + typedef TType type; + }; + +#if ETL_USING_CPP11 + template + using nth_base_t = typename nth_base::type; +#endif + //*************************************************************************** /// A set of templates to allow related types to be derived. ///\ingroup types @@ -1605,70 +1705,15 @@ typedef integral_constant true_type; #if ETL_USING_CPP11 //*************************************************************************** /// are_all_same - template - struct are_all_same - { - static const bool value = etl::is_same::value && - etl::are_all_same::value; - }; - - template - struct are_all_same - { - static const bool value = etl::is_same::value; - }; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool are_all_same_v = are_all_same::value; -#endif - - //*************************************************************************** - /// conjunction -#if ETL_USING_CPP11 - template - struct conjunction : public etl::true_type - { - }; - - template - struct conjunction : public etl::conditional_t, T1> - { - }; - - template - struct conjunction : public T + template + struct are_all_same : etl::conjunction...> { }; #endif #if ETL_USING_CPP17 - template - inline constexpr bool conjunction_v = conjunction::value; -#endif - - //*************************************************************************** - /// disjunction -#if ETL_USING_CPP11 - template - struct disjunction : public etl::false_type - { - }; - - template - struct disjunction : public etl::conditional_t> - { - }; - - template struct disjunction : public T1 - { - }; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool disjunction_v = etl::disjunction::value; + template + inline constexpr bool are_all_same_v = are_all_same::value; #endif //*************************************************************************** @@ -2318,6 +2363,9 @@ typedef integral_constant true_type; etl::true_type, has_duplicates> {}; + template + struct has_duplicates : etl::false_type {}; + template <> struct has_duplicates<> : etl::false_type {}; #endif @@ -2346,18 +2394,6 @@ typedef integral_constant true_type; template inline constexpr size_t count_of_v = etl::count_of::value; #endif - -#if ETL_USING_CPP11 - //********************************************* - // has_duplicates_of - template - struct has_duplicates_of : etl::bool_constant<(etl::count_of::value > 1U)> {}; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool has_duplicates_of_v = etl::has_duplicates_of::value; -#endif } // Helper macros diff --git a/include/etl/index_of_type.h b/include/etl/index_of_type.h new file mode 100644 index 00000000..5546ad53 --- /dev/null +++ b/include/etl/index_of_type.h @@ -0,0 +1,80 @@ +/****************************************************************************** +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_INDEX_OF_TYPE_INCLUDED +#define ETL_INDEX_OF_TYPE_INCLUDED + +#include "platform.h" +#include "static_assert.h" +#include "integral_limits.h" + +namespace etl +{ +#if ETL_USING_CPP11 + + //*************************************************************************** + /// Defines a no-position constant. + //*************************************************************************** + static ETL_CONSTANT size_t index_of_type_npos = etl::integral_limits::max; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + struct index_of_type; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + struct index_of_type : public etl::integral_constant::value ? 0 : + (etl::index_of_type::value == etl::index_of_type_npos ? etl::index_of_type_npos : + etl::index_of_type::value + 1)> + { + }; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + /// No types left. + //*************************************************************************** + template + struct index_of_type : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + inline constexpr size_t index_of_type_v = etl::index_of_type::value; +#endif +#endif +} + +#endif diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 84d0aa94..7e6d4dba 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -253,6 +253,24 @@ namespace etl return current_size; } + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type& search_link) const + { + return is_link_in_list(&search_link); + } + + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type* search_link) const + { + return is_link_in_list(search_link); + } + protected: link_type start; ///< The link pointer that acts as the intrusive_forward_list start. @@ -304,7 +322,10 @@ namespace etl if (p_next != &this->terminator) { link_type* p_unlinked = etl::unlink_after(link); - p_unlinked->clear(); + if (p_unlinked != ETL_NULLPTR) + { + p_unlinked->clear(); + } --current_size; } } @@ -338,24 +359,20 @@ namespace etl /// Tests if the link is in this list. /// Returns the previous link to it, if found, otherwise ETL_NULLPTR. //************************************************************************* - link_type* is_link_in_list(link_type& search_link) + link_type* is_link_in_list(const link_type* search_link) const { link_type* p_link = start.etl_next; - link_type* p_previous = &start; + link_type* p_previous = const_cast(&start); while (p_link != ETL_NULLPTR) { - if (&search_link == p_link) + if (search_link == p_link) { return p_previous; } p_previous = p_link; - - if (p_link != ETL_NULLPTR) - { - p_link = p_link->link_type::etl_next; - } + p_link = p_link->link_type::etl_next; } return ETL_NULLPTR; @@ -366,7 +383,7 @@ namespace etl /// Returns ETL_NULLPTR if the link was not in this list. /// Returns the next //************************************************************************* - link_type* remove_link(link_type& link) + link_type* remove_link(link_type* link) { link_type* result = ETL_NULLPTR; @@ -374,7 +391,7 @@ namespace etl if (p_previous != ETL_NULLPTR) { - link_type* p_next = link.etl_next; + link_type* p_next = link->etl_next; disconnect_link_after(*p_previous); @@ -629,6 +646,22 @@ namespace etl this->assign(first, last); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Constructor from variadic list of nodes. + //************************************************************************* + template + intrusive_forward_list(link_type& first, TLinks&... links) + { + ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); + + this->current_size = 0; + this->start.etl_next = &first; + link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); + last->etl_next = &this->terminator; + } +#endif + //************************************************************************* /// Gets the beginning of the intrusive_forward_list. //************************************************************************* @@ -787,9 +820,17 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(node_type& node) + node_type* erase(const node_type& node) { - return static_cast(this->remove_link(node)); + return static_cast(this->remove_link(const_cast(&node))); + } + + //************************************************************************* + /// Erases the specified node. + //************************************************************************* + node_type* erase(const node_type* p_node) + { + return static_cast(this->remove_link(const_cast(p_node))); } //************************************************************************* @@ -991,6 +1032,29 @@ namespace etl } } + //************************************************************************* + // Removes the element specified by pointer. + //************************************************************************* + void remove(const_pointer element) + { + iterator i_item = begin(); + iterator i_last_item = before_begin(); + + while (i_item != end()) + { + if (&i_item == element) + { + i_item = erase_after(i_last_item); + return; + } + else + { + ++i_item; + ++i_last_item; + } + } + } + //************************************************************************* /// Removes according to a predicate. //************************************************************************* @@ -1167,8 +1231,64 @@ namespace etl } } + //************************************************************************* + /// Detects existence of specified value in list. + ///\param value The value to find in list + //************************************************************************* + bool contains(const_reference value) const + { + const_iterator i_item = begin(); + + while (i_item != end()) + { + if (*i_item == value) + { + return true; + } + + ++i_item; + } + + return false; + } + private: +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, TLinks&... links) + { + link_type* current = &first; + ++count; + ((current->etl_next = &links, current = &links, ++count), ...); + + return current; + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a counted linked list from a number of forward_link nodes. + //*************************************************************************** + link_type* make_linked_list(size_t& count, link_type& first) + { + ++count; + return &first; + } + + //*************************************************************************** + /// Create a counted linked list from a number of forward_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, link_type& next, TLinks&... links) + { + ++count; + first.etl_next = &next; + return make_linked_list(count, next, static_cast(links)...); + } +#endif + //************************************************************************* /// Get the next value. //************************************************************************* diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 577f5010..9f0e5514 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -375,7 +375,7 @@ namespace etl } //*************************************************************************** - // link_clear + // link_clear range //*************************************************************************** // Reference template @@ -404,6 +404,112 @@ namespace etl } } +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLinks&... links) + { + TLink* current = &first; + ((current->etl_next = &links, current = &links), ...); + + return current; + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, (*links)...); + } + else + { + return nullptr; + } + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first) + { + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLink& next, TLinks&... links) + { + first.etl_next = &next; + return create_linked_list(next, static_cast(links)...); + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first); + } + else + { + return ETL_NULLPTR; + } + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLink* next, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, *next, static_cast(*links)...); + } + else + { + return ETL_NULLPTR; + } + } +#endif + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink& first) + { + link_clear_range(first); + } + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + detach_linked_list(*first); + } + } + //*************************************************************************** /// A bidirectional link. //*************************************************************************** @@ -829,6 +935,93 @@ namespace etl etl::link_clear_range(*start); } +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLinks&... links) + { + TLink* current = &first; + ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links), ...); + + return current; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLinks*... links) + { + TLink* current = first; + ((current->etl_next = links, static_cast(links)->etl_previous = current, current = links), ...); + + return current; + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first) + { + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLink& next, TLinks&... links) + { + first.etl_next = &next; + next.etl_previous = &first; + + return create_linked_list(next, static_cast(links)...); + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLink* next, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, *next, static_cast(*links)...); + } + else + { + return ETL_NULLPTR; + } + } +#endif + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink& first) + { + link_clear_range(first); + } + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + detach_linked_list(*first); + } + } + //*************************************************************************** /// A binary tree link. //*************************************************************************** diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 6bbd906f..563fadfa 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -255,6 +255,24 @@ namespace etl return current_size; } + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type& search_link) const + { + return is_link_in_list(&search_link);; + } + + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type* search_link) const + { + return is_link_in_list(search_link);; + } + protected: /// The link that acts as the intrusive_list start & end. @@ -379,13 +397,13 @@ namespace etl //************************************************************************* /// Tests if the link is in this list. //************************************************************************* - bool is_link_in_list(link_type& search_link) const + bool is_link_in_list(const link_type* search_link) const { link_type* p_link = terminal_link.link_type::etl_next; while (p_link != &terminal_link) { - if (&search_link == p_link) + if (search_link == p_link) { return true; } @@ -400,13 +418,13 @@ namespace etl /// Remove the specified node from the list. /// Returns ETL_NULLPTR if the link was not in this list or was the last in the list. //************************************************************************* - link_type* remove_link(link_type& link) + link_type* remove_link(link_type* link) { link_type* result = ETL_NULLPTR; if (is_link_in_list(link)) { - link_type* p_next = link.etl_next; + link_type* p_next = link->etl_next; disconnect_link(link); @@ -685,6 +703,24 @@ namespace etl this->assign(first, last); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Constructor from variadic list of nodes. + //************************************************************************* + template + intrusive_list(link_type& first, TLinks&... links) + { + ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); + + this->current_size = 0; + this->terminal_link.etl_next = &first; + link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); + first.etl_previous = &this->terminal_link; + last->etl_next = &this->terminal_link; + this->terminal_link.etl_previous = last; + } +#endif + //************************************************************************* /// Gets the beginning of the intrusive_list. //************************************************************************* @@ -843,9 +879,17 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(node_type& node) + node_type* erase(const node_type& node) { - return static_cast(this->remove_link(node)); + return static_cast(this->remove_link(const_cast(&node))); + } + + //************************************************************************* + /// Erases the specified node. + //************************************************************************* + node_type* erase(const node_type* p_node) + { + return static_cast(this->remove_link(const_cast(p_node))); } //************************************************************************* @@ -1192,8 +1236,67 @@ namespace etl } } + //************************************************************************* + /// Detects existence of specified value in list. + ///\param value The value to find in list + //************************************************************************* + bool contains(const_reference value) const + { + const_iterator i_item = begin(); + + while (i_item != end()) + { + if (*i_item == value) + { + return true; + } + + ++i_item; + } + + return false; + } + private: +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, TLinks&... links) + { + TLink* current = &first; + ++count; + ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links, ++count), ...); + + return current; + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + link_type* make_linked_list(size_t& count, link_type& first) + { + ++count; + + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, link_type& next, TLinks&... links) + { + ++count; + first.etl_next = &next; + next.etl_previous = &first; + + return make_linked_list(count, next, static_cast(links)...); + } +#endif + // Disabled. intrusive_list(const intrusive_list& other); intrusive_list& operator = (const intrusive_list& rhs); diff --git a/include/etl/ipool.h b/include/etl/ipool.h index ce4c317e..94292774 100644 --- a/include/etl/ipool.h +++ b/include/etl/ipool.h @@ -271,6 +271,14 @@ namespace etl return Max_Size; } + //************************************************************************* + /// Returns the maximum size of an item in the pool. + //************************************************************************* + size_t max_item_size() const + { + return Item_Size; + } + //************************************************************************* /// Returns the maximum number of items in the pool. //************************************************************************* @@ -377,39 +385,13 @@ namespace etl //************************************************************************* void release_item(char* p_value) { - //// Does it belong to us? - //ETL_ASSERT(is_item_in_pool(p_value), ETL_ERROR(pool_object_not_in_pool)); - - //if (p_next != ETL_NULLPTR) - //{ - // // Point it to the current free item. - // *(uintptr_t*)p_value = reinterpret_cast(p_next); - //} - //else - //{ - // // This is the only free item. - // *((uintptr_t*)p_value) = 0; - //} - - //p_next = p_value; - - //--items_allocated; - // Does it belong to us? ETL_ASSERT(is_item_in_pool(p_value), ETL_ERROR(pool_object_not_in_pool)); if (items_allocated > 0) { - if (p_next != ETL_NULLPTR) - { - // Point it to the current free item. - *(uintptr_t*)p_value = reinterpret_cast(p_next); - } - else - { - // This is the only free item. - *((uintptr_t*)p_value) = 0; - } + // Point it to the current free item. + *(uintptr_t*)p_value = reinterpret_cast(p_next); p_next = p_value; diff --git a/include/etl/mem_cast.h b/include/etl/mem_cast.h index 33b79021..c45b99af 100644 --- a/include/etl/mem_cast.h +++ b/include/etl/mem_cast.h @@ -139,7 +139,7 @@ namespace etl { ETL_STATIC_ASSERT(Size >= sizeof(T), "Type size is too large"); - ::new (static_cast(buffer)) T(value); + ::new (static_cast(buffer.raw)) T(value); } //*********************************** @@ -148,7 +148,7 @@ namespace etl template void assign_at_offset(size_t offset, const T& value) { - char* p = static_cast(buffer) + offset; + char* p = static_cast(buffer.raw) + offset; ETL_ASSERT(sizeof(T) <= (Size - offset), ETL_ERROR(etl::mem_cast_size_exception)); ::new (p) T(value); @@ -160,7 +160,7 @@ namespace etl template void assign_at_offset(const T& value) { - char* p = static_cast(buffer) + Offset; + char* p = static_cast(buffer.raw) + Offset; ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Type size is too large"); ::new (p) T(value); @@ -171,35 +171,41 @@ namespace etl /// Emplace from parameters //*********************************** template - void emplace(TArgs... args) + T& emplace(TArgs... args) { ETL_STATIC_ASSERT(Size >= sizeof(T), "Type size is too large"); - ::new (static_cast(buffer)) T(etl::forward(args)...); + ::new (static_cast(buffer.raw)) T(etl::forward(args)...); + + return ref(); } //*********************************** /// Emplace from parameters at offset //*********************************** template - void emplace_at_offset(size_t offset, TArgs... args) + T& emplace_at_offset(size_t offset, TArgs... args) { - char* p = static_cast(buffer) + offset; + char* p = static_cast(buffer.raw) + offset; ETL_ASSERT(sizeof(T) <= (Size - offset), ETL_ERROR(etl::mem_cast_size_exception)); ::new (p) T(etl::forward(args)...); + + return ref_at_offset(offset); } //*********************************** /// Emplace from parameters at offset //*********************************** template - void emplace_at_offset(TArgs... args) + T& emplace_at_offset(TArgs... args) { - char* p = static_cast(buffer) + Offset; + char* p = static_cast(buffer.raw) + Offset; ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Type size is too large"); ::new (p) T(etl::forward(args)...); + + return ref_at_offset(); } #endif @@ -209,9 +215,9 @@ namespace etl template ETL_NODISCARD T& ref() { - ETL_STATIC_ASSERT(sizeof(T) <= Size, "Size of T is too large"); + ETL_STATIC_ASSERT(sizeof(T) <= Size, "Size of type too large for storage"); - return *static_cast(buffer); + return *reinterpret_cast(buffer.raw); } //*********************************** @@ -220,9 +226,9 @@ namespace etl template ETL_NODISCARD const T& ref() const { - ETL_STATIC_ASSERT(sizeof(T) <= Size, "Size of T is too large"); + ETL_STATIC_ASSERT(sizeof(T) <= Size, "Size of type too large for storage"); - return *static_cast(buffer); + return *reinterpret_cast(buffer.raw); } //*********************************** @@ -233,9 +239,7 @@ namespace etl { ETL_ASSERT(sizeof(T) <= (Size - offset), ETL_ERROR(etl::mem_cast_size_exception)); - char* p = buffer + offset; - - return *static_cast(p); + return *reinterpret_cast(buffer.raw + offset); } //*********************************** @@ -246,9 +250,7 @@ namespace etl { ETL_ASSERT(sizeof(T) <= (Size - offset), ETL_ERROR(etl::mem_cast_size_exception)); - char* p = buffer + offset; - - return *static_cast(p); + return *reinterpret_cast(buffer.raw + offset); } //*********************************** @@ -257,11 +259,9 @@ namespace etl template ETL_NODISCARD T& ref_at_offset() { - ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Size of T is too large"); + ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Size of type too large for storage"); - char* p = buffer + Offset; - - return *static_cast(p); + return *reinterpret_cast(buffer.raw + Offset); } //*********************************** @@ -270,11 +270,9 @@ namespace etl template ETL_NODISCARD const T& ref_at_offset() const { - ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Size of T is too large"); + ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Size of type too large for storage"); - char* p = buffer + Offset; - - return *static_cast(p); + return *reinterpret_cast(buffer.raw + Offset); } //*********************************** @@ -411,38 +409,44 @@ namespace etl /// Emplace from parameters //*********************************** template - void emplace(TArgs... args) + T& emplace(TArgs... args) { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::mem_cast_size_exception)); ::new (pbuffer) T(etl::forward(args)...); + + return ref(); } //*********************************** /// Emplace from parameters at offset //*********************************** template - void emplace_at_offset(size_t offset, TArgs... args) + T& emplace_at_offset(size_t offset, TArgs... args) { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); char* p = pbuffer + offset; ETL_ASSERT(sizeof(T) <= (buffer_size - offset), ETL_ERROR(etl::mem_cast_size_exception)); ::new (p) T(etl::forward(args)...); + + return ref_at_offset(offset); } //*********************************** /// Emplace from parameters at offset //*********************************** template - void emplace_at_offset(TArgs... args) + T& emplace_at_offset(TArgs... args) { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); char* p = pbuffer + Offset; ETL_ASSERT(sizeof(T) <= (buffer_size - Offset), ETL_ERROR(etl::mem_cast_size_exception)); ::new (p) T(etl::forward(args)...); + + return ref_at_offset(); } #endif @@ -455,7 +459,9 @@ namespace etl ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(pbuffer); + T* p = reinterpret_cast(pbuffer); + + return *p; } //*********************************** @@ -467,7 +473,9 @@ namespace etl ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(pbuffer); + const T* p = reinterpret_cast(pbuffer); + + return *p; } //*********************************** @@ -477,10 +485,11 @@ namespace etl ETL_NODISCARD T& ref_at_offset(size_t offset) { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); - char* p = pbuffer + offset; ETL_ASSERT(sizeof(T) <= (buffer_size - offset), ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(p); + T* p = reinterpret_cast(pbuffer + offset); + + return *p; } //*********************************** @@ -490,10 +499,11 @@ namespace etl ETL_NODISCARD const T& ref_at_offset(size_t offset) const { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); - char* p = pbuffer + offset; ETL_ASSERT(sizeof(T) <= (buffer_size - offset), ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(p); + const T* p = reinterpret_cast(pbuffer + offset); + + return *p; } //*********************************** @@ -503,10 +513,11 @@ namespace etl ETL_NODISCARD T& ref_at_offset() { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); - char* p = pbuffer + Offset; ETL_ASSERT(sizeof(T) <= (buffer_size - Offset), ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(p); + T* p = reinterpret_cast(pbuffer + Offset); + + return *p; } //*********************************** @@ -516,10 +527,11 @@ namespace etl ETL_NODISCARD const T& ref_at_offset() const { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); - char* p = pbuffer + Offset; ETL_ASSERT(sizeof(T) <= (buffer_size - Offset), ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(p); + const T* p = reinterpret_cast(pbuffer + Offset); + + return *p; } //*********************************** diff --git a/include/etl/memory.h b/include/etl/memory.h index b285068b..83e9a200 100644 --- a/include/etl/memory.h +++ b/include/etl/memory.h @@ -54,6 +54,27 @@ SOFTWARE. namespace etl { + //***************************************************************************** + /// Obtain the address represented by p without forming a reference to the object pointed to by p. + /// Defined when not using the STL or C++20 + //***************************************************************************** + template + ETL_CONSTEXPR T* to_address(T* p) + { + return p; + } + + //***************************************************************************** + /// Obtain the address represented by itr without forming a reference to the object pointed to by itr. + /// Requires that the iterator defines operator->() + /// Defined when not using the STL or C++20 + //***************************************************************************** + template + ETL_CONSTEXPR typename Iterator::pointer to_address(const Iterator& itr) + { + return etl::to_address(itr.operator->()); + } + #if ETL_USING_STL //***************************************************************************** /// Fills uninitialised memory range with a value. @@ -112,7 +133,7 @@ namespace etl while (o_begin != o_end) { - ::new (static_cast(etl::addressof(*o_begin))) value_type(value); + ::new (static_cast(etl::to_address(o_begin))) value_type(value); ++o_begin; } @@ -259,7 +280,7 @@ namespace etl while (i_begin != i_end) { - ::new (static_cast(etl::addressof(*o_end))) value_type(*i_begin); + ::new (static_cast(etl::to_address(o_end))) value_type(*i_begin); ++i_begin; ++o_end; } @@ -407,7 +428,7 @@ namespace etl while (i_begin != i_end) { - ::new (static_cast(etl::addressof(*o_end))) value_type(etl::move(*i_begin)); + ::new (static_cast(etl::to_address(o_end))) value_type(etl::move(*i_begin)); ++i_begin; ++o_end; } @@ -532,7 +553,7 @@ namespace etl while (n-- != 0) { - ::new (static_cast(etl::addressof(*o_end))) value_type(etl::move(*i_begin)); + ::new (static_cast(etl::to_address(o_end))) value_type(etl::move(*i_begin)); ++i_begin; ++o_end; } @@ -665,7 +686,7 @@ namespace etl while (o_begin != o_end) { - ::new (static_cast(etl::addressof(*o_begin))) value_type; + ::new (static_cast(etl::to_address(o_begin))) value_type; ++o_begin; } } @@ -844,7 +865,7 @@ namespace etl while (o_begin != o_end) { - ::new (static_cast(etl::addressof(*o_begin))) value_type(); + ::new (static_cast(etl::to_address(o_begin))) value_type(); ++o_begin; } } @@ -1095,7 +1116,7 @@ namespace etl { while (i_begin != i_end) { - etl::destroy_at(etl::addressof(*i_begin)); + etl::destroy_at(etl::to_address(i_begin)); ++i_begin; } } @@ -1127,7 +1148,7 @@ namespace etl while (i_begin != i_end) { - etl::destroy_at(etl::addressof(*i_begin)); + etl::destroy_at(etl::to_address(i_begin)); ++i_begin; } } @@ -1182,7 +1203,7 @@ namespace etl { while (n > 0) { - etl::destroy_at(etl::addressof(*i_begin)); + etl::destroy_at(etl::to_address(i_begin)); ++i_begin; --n; } @@ -1218,7 +1239,7 @@ namespace etl while (n > 0) { - etl::destroy_at(etl::addressof(*i_begin)); + etl::destroy_at(etl::to_address(i_begin)); ++i_begin; --n; } @@ -2264,13 +2285,13 @@ namespace etl /// \param destination begin /// \return A pointer to the destination. //*************************************************************************** - template - typename etl::enable_if::value_type>::value, TPointer>::type - mem_copy(const TPointer sb, const TPointer se, TPointer db) ETL_NOEXCEPT + template + typename etl::enable_if::value_type>::value, T*>::type + mem_copy(const T* sb, const T* se, T* db) ETL_NOEXCEPT { - return reinterpret_cast(memcpy(reinterpret_cast(db), - reinterpret_cast(sb), - sizeof(typename etl::iterator_traits::value_type) * static_cast(se - sb))); + return reinterpret_cast(memcpy(reinterpret_cast(db), + reinterpret_cast(sb), + sizeof(typename etl::iterator_traits::value_type) * static_cast(se - sb))); } //*************************************************************************** @@ -2280,13 +2301,13 @@ namespace etl /// \param source length /// \param destination begin //*************************************************************************** - template - typename etl::enable_if::value_type>::value, TPointer>::type - mem_copy(const TPointer sb, size_t n, TPointer db) ETL_NOEXCEPT + template + typename etl::enable_if::value_type>::value, T*>::type + mem_copy(const T* sb, size_t n, T* db) ETL_NOEXCEPT { - return reinterpret_cast(memcpy(reinterpret_cast(db), - reinterpret_cast(sb), - sizeof(typename etl::iterator_traits::value_type) * n)); + return reinterpret_cast(memcpy(reinterpret_cast(db), + reinterpret_cast(sb), + sizeof(typename etl::iterator_traits::value_type) * n)); } //*************************************************************************** @@ -2296,13 +2317,13 @@ namespace etl /// \param source end /// \param destination begin //*************************************************************************** - template - typename etl::enable_if::value_type>::value, TPointer>::type - mem_move(const TPointer sb, const TPointer se, TPointer db) ETL_NOEXCEPT + template + typename etl::enable_if::value_type>::value, T*>::type + mem_move(const T* sb, const T* se, T* db) ETL_NOEXCEPT { - return reinterpret_cast(memmove(reinterpret_cast(db), - reinterpret_cast(sb), - sizeof(typename etl::iterator_traits::value_type) * static_cast(se - sb))); + return reinterpret_cast(memmove(reinterpret_cast(db), + reinterpret_cast(sb), + sizeof(typename etl::iterator_traits::value_type) * static_cast(se - sb))); } //*************************************************************************** @@ -2312,32 +2333,32 @@ namespace etl /// \param source length /// \param destination begin //*************************************************************************** - template - typename etl::enable_if::value_type>::value, TPointer>::type - mem_move(const TPointer sb, size_t n, TPointer db) ETL_NOEXCEPT + template + typename etl::enable_if::value_type>::value, T*>::type + mem_move(const T* sb, size_t n, T* db) ETL_NOEXCEPT { - return reinterpret_cast(memmove(reinterpret_cast(db), - reinterpret_cast(sb), - sizeof(typename etl::iterator_traits::value_type) * n)); + return reinterpret_cast(memmove(reinterpret_cast(db), + reinterpret_cast(sb), + sizeof(typename etl::iterator_traits::value_type) * n)); } //*************************************************************************** /// Template wrapper for memcmp. - /// \param source begin - /// \param source end - /// \param destination begin + /// \param sb Source begin + /// \param se Source end + /// \param db Destination begin /// \return < 0 The first byte that does not match in both memory blocks has a lower value in 'sb' than in 'db' when evaluated as unsigned char values. /// 0 The contents of both memory blocks are equal /// > 0 The first byte that does not match in both memory blocks has a greater value in 'sb' than in 'db' when evaluated as unsigned char values. //*************************************************************************** - template + template ETL_NODISCARD - typename etl::enable_if::value_type>::value, int>::type - mem_compare(const TPointer sb, const TPointer se, TPointer db) ETL_NOEXCEPT + typename etl::enable_if::value_type>::value, int>::type + mem_compare(const T* sb, const T* se, const T* db) ETL_NOEXCEPT { - return memcmp(reinterpret_cast(db), - reinterpret_cast(sb), - sizeof(typename etl::iterator_traits::value_type) * static_cast(se - sb)); + return memcmp(reinterpret_cast(db), + reinterpret_cast(sb), + sizeof(typename etl::iterator_traits::value_type) * static_cast(se - sb)); } //*************************************************************************** @@ -2349,14 +2370,14 @@ namespace etl /// 0 The contents of both memory blocks are equal /// > 0 The first byte that does not match in both memory blocks has a greater value in 'sb' than in 'db' when evaluated as unsigned char values. //*************************************************************************** - template + template ETL_NODISCARD - typename etl::enable_if::value_type>::value, int>::type - mem_compare(const TPointer sb, size_t n, TPointer db) ETL_NOEXCEPT + typename etl::enable_if::value_type>::value, int>::type + mem_compare(const T* sb, size_t n, const T* db) ETL_NOEXCEPT { - return memcmp(reinterpret_cast(db), - reinterpret_cast(sb), - sizeof(typename etl::iterator_traits::value_type) * n); + return memcmp(reinterpret_cast(db), + reinterpret_cast(sb), + sizeof(typename etl::iterator_traits::value_type) * n); } //*************************************************************************** @@ -2384,7 +2405,7 @@ namespace etl //*************************************************************************** template typename etl::enable_if::value_type>::value, TPointer>::type - mem_set(const TPointer db, size_t n, T value) ETL_NOEXCEPT + mem_set(TPointer db, size_t n, T value) ETL_NOEXCEPT { return reinterpret_cast(memset(reinterpret_cast(db), static_cast(value), diff --git a/include/etl/message_packet.h b/include/etl/message_packet.h index 35650a6b..96b785d1 100644 --- a/include/etl/message_packet.h +++ b/include/etl/message_packet.h @@ -53,8 +53,6 @@ SOFTWARE. #include "platform.h" -#if ETL_HAS_VIRTUAL_MESSAGES - #include "message.h" #include "error_handler.h" #include "static_assert.h" @@ -286,11 +284,39 @@ namespace etl { etl::imessage* pmsg = static_cast(data); +#if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); +#else + delete_message(pmsg); +#endif } } #include "private/diagnostic_pop.h" +#if !ETL_HAS_VIRTUAL_MESSAGES + //******************************************** + void delete_message(etl::imessage* pmsg) + { + (delete_message_type(pmsg) || ...); + } + + //******************************************** + template + bool delete_message_type(etl::imessage* pmsg) + { + if (TType::ID == pmsg->get_message_id()) + { + TType* p = static_cast(pmsg); + p->~TType(); + return true; + } + else + { + return false; + } + } +#endif + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -584,11 +610,40 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + case T6::ID: static_cast(pmsg)->~T6(); break; + case T7::ID: static_cast(pmsg)->~T7(); break; + case T8::ID: static_cast(pmsg)->~T8(); break; + case T9::ID: static_cast(pmsg)->~T9(); break; + case T10::ID: static_cast(pmsg)->~T10(); break; + case T11::ID: static_cast(pmsg)->~T11(); break; + case T12::ID: static_cast(pmsg)->~T12(); break; + case T13::ID: static_cast(pmsg)->~T13(); break; + case T14::ID: static_cast(pmsg)->~T14(); break; + case T15::ID: static_cast(pmsg)->~T15(); break; + case T16::ID: static_cast(pmsg)->~T16(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -613,7 +668,7 @@ namespace etl case T14::ID: ::new (p) T14(static_cast(msg)); break; case T15::ID: ::new (p) T15(static_cast(msg)); break; case T16::ID: ::new (p) T16(static_cast(msg)); break; - default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -642,7 +697,7 @@ namespace etl case T14::ID: ::new (p) T14(static_cast(msg)); break; case T15::ID: ::new (p) T15(static_cast(msg)); break; case T16::ID: ::new (p) T16(static_cast(msg)); break; - default: ETL_ASSERT(false, ETL_ERROR(unhandled_message_exception)); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } #endif @@ -879,11 +934,40 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + case T6::ID: static_cast(pmsg)->~T6(); break; + case T7::ID: static_cast(pmsg)->~T7(); break; + case T8::ID: static_cast(pmsg)->~T8(); break; + case T9::ID: static_cast(pmsg)->~T9(); break; + case T10::ID: static_cast(pmsg)->~T10(); break; + case T11::ID: static_cast(pmsg)->~T11(); break; + case T12::ID: static_cast(pmsg)->~T12(); break; + case T13::ID: static_cast(pmsg)->~T13(); break; + case T14::ID: static_cast(pmsg)->~T14(); break; + case T15::ID: static_cast(pmsg)->~T15(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -907,7 +991,7 @@ namespace etl case T13::ID: ::new (p) T13(static_cast(msg)); break; case T14::ID: ::new (p) T14(static_cast(msg)); break; case T15::ID: ::new (p) T15(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -1172,11 +1256,39 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + case T6::ID: static_cast(pmsg)->~T6(); break; + case T7::ID: static_cast(pmsg)->~T7(); break; + case T8::ID: static_cast(pmsg)->~T8(); break; + case T9::ID: static_cast(pmsg)->~T9(); break; + case T10::ID: static_cast(pmsg)->~T10(); break; + case T11::ID: static_cast(pmsg)->~T11(); break; + case T12::ID: static_cast(pmsg)->~T12(); break; + case T13::ID: static_cast(pmsg)->~T13(); break; + case T14::ID: static_cast(pmsg)->~T14(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -1199,7 +1311,7 @@ namespace etl case T12::ID: ::new (p) T12(static_cast(msg)); break; case T13::ID: ::new (p) T13(static_cast(msg)); break; case T14::ID: ::new (p) T14(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -1463,11 +1575,38 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + case T6::ID: static_cast(pmsg)->~T6(); break; + case T7::ID: static_cast(pmsg)->~T7(); break; + case T8::ID: static_cast(pmsg)->~T8(); break; + case T9::ID: static_cast(pmsg)->~T9(); break; + case T10::ID: static_cast(pmsg)->~T10(); break; + case T11::ID: static_cast(pmsg)->~T11(); break; + case T12::ID: static_cast(pmsg)->~T12(); break; + case T13::ID: static_cast(pmsg)->~T13(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -1489,7 +1628,7 @@ namespace etl case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; case T13::ID: ::new (p) T13(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -1748,11 +1887,37 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + case T6::ID: static_cast(pmsg)->~T6(); break; + case T7::ID: static_cast(pmsg)->~T7(); break; + case T8::ID: static_cast(pmsg)->~T8(); break; + case T9::ID: static_cast(pmsg)->~T9(); break; + case T10::ID: static_cast(pmsg)->~T10(); break; + case T11::ID: static_cast(pmsg)->~T11(); break; + case T12::ID: static_cast(pmsg)->~T12(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -1773,7 +1938,7 @@ namespace etl case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; case T12::ID: ::new (p) T12(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -2031,11 +2196,36 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + case T6::ID: static_cast(pmsg)->~T6(); break; + case T7::ID: static_cast(pmsg)->~T7(); break; + case T8::ID: static_cast(pmsg)->~T8(); break; + case T9::ID: static_cast(pmsg)->~T9(); break; + case T10::ID: static_cast(pmsg)->~T10(); break; + case T11::ID: static_cast(pmsg)->~T11(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -2055,7 +2245,7 @@ namespace etl case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; case T11::ID: ::new (p) T11(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -2312,11 +2502,35 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + case T6::ID: static_cast(pmsg)->~T6(); break; + case T7::ID: static_cast(pmsg)->~T7(); break; + case T8::ID: static_cast(pmsg)->~T8(); break; + case T9::ID: static_cast(pmsg)->~T9(); break; + case T10::ID: static_cast(pmsg)->~T10(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -2335,7 +2549,7 @@ namespace etl case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; case T10::ID: ::new (p) T10(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -2591,11 +2805,34 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + case T6::ID: static_cast(pmsg)->~T6(); break; + case T7::ID: static_cast(pmsg)->~T7(); break; + case T8::ID: static_cast(pmsg)->~T8(); break; + case T9::ID: static_cast(pmsg)->~T9(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -2613,7 +2850,7 @@ namespace etl case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; case T9::ID: ::new (p) T9(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -2864,11 +3101,33 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + case T6::ID: static_cast(pmsg)->~T6(); break; + case T7::ID: static_cast(pmsg)->~T7(); break; + case T8::ID: static_cast(pmsg)->~T8(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -2885,7 +3144,7 @@ namespace etl case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; case T8::ID: ::new (p) T8(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -3135,11 +3394,32 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + case T6::ID: static_cast(pmsg)->~T6(); break; + case T7::ID: static_cast(pmsg)->~T7(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -3155,7 +3435,7 @@ namespace etl case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; case T7::ID: ::new (p) T7(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -3404,11 +3684,31 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + case T6::ID: static_cast(pmsg)->~T6(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -3423,7 +3723,7 @@ namespace etl case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; case T6::ID: ::new (p) T6(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -3671,11 +3971,30 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + case T5::ID: static_cast(pmsg)->~T5(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -3689,7 +4008,7 @@ namespace etl case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; case T5::ID: ::new (p) T5(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -3932,11 +4251,29 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + case T4::ID: static_cast(pmsg)->~T4(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -3949,7 +4286,7 @@ namespace etl case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; case T4::ID: ::new (p) T4(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -4191,11 +4528,28 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + case T3::ID: static_cast(pmsg)->~T3(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -4207,7 +4561,7 @@ namespace etl case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; case T3::ID: ::new (p) T3(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -4448,11 +4802,27 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + case T2::ID: static_cast(pmsg)->~T2(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -4463,7 +4833,7 @@ namespace etl { case T1::ID: ::new (p) T1(static_cast(msg)); break; case T2::ID: ::new (p) T2(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -4703,11 +5073,26 @@ namespace etl { etl::imessage* pmsg = static_cast(data); + + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); + #else + delete_message(pmsg); + #endif } } #include "private/diagnostic_pop.h" + //******************************************** + void delete_message(etl::imessage* pmsg) + { + switch (pmsg->get_message_id()) + { + case T1::ID: static_cast(pmsg)->~T1(); break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; + } + } + //******************************************** void add_new_message(const etl::imessage& msg) { @@ -4717,7 +5102,7 @@ namespace etl switch (id) { case T1::ID: ::new (p) T1(static_cast(msg)); break; - default: break; + default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break; } } @@ -4741,8 +5126,5 @@ namespace etl }; #endif } -#else - #error "etl::message_packet is not compatible with non-virtual etl::imessage" -#endif #endif diff --git a/include/etl/message_router.h b/include/etl/message_router.h index 3f846ef9..44d2310a 100644 --- a/include/etl/message_router.h +++ b/include/etl/message_router.h @@ -54,9 +54,7 @@ SOFTWARE. #include "platform.h" #include "message.h" #include "shared_message.h" -#if ETL_HAS_VIRTUAL_MESSAGES - #include "message_packet.h" -#endif +#include "message_packet.h" #include "message_types.h" #include "alignment.h" #include "error_handler.h" @@ -412,9 +410,7 @@ namespace etl { public: -#if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; -#endif //********************************************** message_router() @@ -562,9 +558,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -709,9 +703,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -856,9 +848,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -1002,9 +992,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -1146,9 +1134,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -1289,9 +1275,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -1431,9 +1415,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -1572,9 +1554,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -1711,9 +1691,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -1849,9 +1827,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -1985,9 +1961,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -2120,9 +2094,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -2253,9 +2225,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -2385,9 +2355,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -2516,9 +2484,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -2646,9 +2612,7 @@ namespace etl { public: - #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet< T1> message_packet; - #endif //********************************************** message_router(etl::message_router_id_t id_) diff --git a/include/etl/monostate.h b/include/etl/monostate.h new file mode 100644 index 00000000..eb7877bf --- /dev/null +++ b/include/etl/monostate.h @@ -0,0 +1,46 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_MONOSTATE_INCLUDED +#define ETL_MONOSTATE_INCLUDED + +#include "platform.h" + +namespace etl +{ + //*************************************************************************** + /// A 'no-value' placeholder. + //*************************************************************************** + struct monostate + { + }; +} + +#endif diff --git a/include/etl/multi_span.h b/include/etl/multi_span.h index 8e974ee3..eefd2b13 100644 --- a/include/etl/multi_span.h +++ b/include/etl/multi_span.h @@ -38,7 +38,7 @@ SOFTWARE. #include "span.h" ///\defgroup multi_multi_span multi_span multi_span -/// Scatter/Gather functionality +/// Allows Scatter/Gather functionality ///\ingroup containers namespace etl @@ -62,36 +62,56 @@ namespace etl //************************************************************************* /// Iterator //************************************************************************* - class iterator : public etl::iterator + class iterator : public etl::iterator { public: friend class multi_span; + friend class const_iterator; - iterator() - : p_current(ETL_NULLPTR) - , p_end(ETL_NULLPTR) + //***************************************** + ETL_CONSTEXPR14 iterator() + : p_span_list(ETL_NULLPTR) + , p_current_span(ETL_NULLPTR) , p_value(ETL_NULLPTR) { } //***************************************** - iterator& operator ++() + ETL_CONSTEXPR14 iterator(const iterator& other) + : p_span_list(other.p_span_list) + , p_current_span(other.p_current_span) + , p_value(other.p_value) { - if (p_current != p_end) + } + + //***************************************** + ETL_CONSTEXPR14 iterator& operator =(const iterator& rhs) + { + p_span_list = rhs.p_span_list; + p_current_span = rhs.p_current_span; + p_value = rhs.p_value; + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 iterator& operator ++() + { + if (p_current_span != p_span_list->end()) { ++p_value; - if (p_value == p_current->end()) + if (p_value == p_current_span->end()) { do { - ++p_current; - } while ((p_current != p_end) && p_current->empty()); + ++p_current_span; + } while ((p_current_span != p_span_list->end()) && p_current_span->empty()); - if (p_current != p_end) + if (p_current_span != p_span_list->end()) { - p_value = p_current->begin(); + p_value = p_current_span->begin(); } else { @@ -104,7 +124,7 @@ namespace etl } //***************************************** - iterator operator ++(int) + ETL_CONSTEXPR14 iterator operator ++(int) { iterator temp = *this; @@ -113,10 +133,54 @@ namespace etl return temp; } + //***************************************** + ETL_CONSTEXPR14 iterator& operator --() + { + if (p_current_span == p_span_list->end()) + { + --p_current_span; + p_value = p_current_span->end(); + --p_value; + } + else if ((p_current_span != p_span_list->begin()) || (p_value != p_current_span->begin())) + { + if (p_value == p_current_span->begin()) + { + do + { + --p_current_span; + } while ((p_current_span != p_span_list->begin()) && p_current_span->empty()); + + p_value = p_current_span->end(); + --p_value; + } + else + { + --p_value; + } + } + else + { + p_value = ETL_NULLPTR; + } + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 iterator operator --(int) + { + iterator temp = *this; + + operator --(); + + return temp; + } + //************************************************************************* /// * operator //************************************************************************* - reference operator *() + ETL_CONSTEXPR14 reference operator *() { return *p_value; } @@ -124,7 +188,7 @@ namespace etl //************************************************************************* /// * operator //************************************************************************* - const_reference operator *() const + ETL_CONSTEXPR14 const_reference operator *() const { return *p_value; } @@ -132,55 +196,57 @@ namespace etl //************************************************************************* /// -> operator //************************************************************************* - pointer operator ->() + ETL_CONSTEXPR14 pointer operator ->() { - return &operator*(); + return p_value; } //************************************************************************* /// -> operator //************************************************************************* - const_pointer operator ->() const + ETL_CONSTEXPR14 const_pointer operator ->() const { - return &operator*(); + return p_value; } //************************************************************************* /// == operator //************************************************************************* - friend bool operator ==(const iterator& lhs, const iterator& rhs) + ETL_CONSTEXPR14 friend bool operator ==(const iterator& lhs, const iterator& rhs) { - return (lhs.p_current == rhs.p_current); + return (lhs.p_current_span == rhs.p_current_span) && (lhs.p_value == rhs.p_value); } //************************************************************************* /// != operator //************************************************************************* - friend bool operator !=(const iterator& lhs, const iterator& rhs) + ETL_CONSTEXPR14 friend bool operator !=(const iterator& lhs, const iterator& rhs) { return !(lhs == rhs); } private: + typedef const span_type* span_pointer; + typedef const span_list_type* span_list_pointer; typedef typename span_list_type::iterator span_list_iterator; //***************************************** - iterator(span_list_iterator p_current_, span_list_iterator p_end_) - : p_current(p_current_) - , p_end(p_end_) + ETL_CONSTEXPR14 iterator(const span_list_type& span_list_, span_list_iterator p_current_span_) + : p_span_list(&span_list_) + , p_current_span(p_current_span_) , p_value(ETL_NULLPTR) { - if (p_current != p_end) + if (p_current_span != p_span_list->end()) { - while ((p_current != p_end) && p_current->empty()) + while ((p_current_span != p_span_list->end()) && p_current_span->empty()) { - ++p_current; + ++p_current_span; } - if (p_current != p_end) + if (p_current_span != p_span_list->end()) { - p_value = p_current->begin(); + p_value = p_current_span->begin(); } else { @@ -189,13 +255,216 @@ namespace etl } } - typedef const span_type* span_list_pointer; - - span_list_pointer p_current; - span_list_pointer p_end; + span_list_pointer p_span_list; + span_pointer p_current_span; pointer p_value; }; + //************************************************************************* + /// Const Iterator + //************************************************************************* + class const_iterator : public etl::iterator + { + public: + + friend class multi_span; + + //***************************************** + ETL_CONSTEXPR14 const_iterator() + : p_span_list(ETL_NULLPTR) + , p_current_span(ETL_NULLPTR) + , p_value(ETL_NULLPTR) + { + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator(const const_iterator& other) + : p_span_list(other.p_span_list) + , p_current_span(other.p_current_span) + , p_value(other.p_value) + { + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator& operator =(const const_iterator& rhs) + { + p_span_list = rhs.p_span_list; + p_current_span = rhs.p_current_span; + p_value = rhs.p_value; + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator(const etl::multi_span::iterator& other) + : p_span_list(other.p_span_list) + , p_current_span(other.p_current_span) + , p_value(other.p_value) + { + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator& operator =(const etl::multi_span::iterator& rhs) + { + p_span_list = rhs.p_span_list; + p_current_span = rhs.p_current_span; + p_value = rhs.p_value; + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator& operator ++() + { + if (p_current_span != p_span_list->end()) + { + ++p_value; + + if (p_value == p_current_span->end()) + { + do + { + ++p_current_span; + } while ((p_current_span != p_span_list->end()) && p_current_span->empty()); + + if (p_current_span != p_span_list->end()) + { + p_value = p_current_span->begin(); + } + else + { + p_value = ETL_NULLPTR; + } + } + } + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator operator ++(int) + { + const_iterator temp = *this; + + operator ++(); + + return temp; + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator& operator --() + { + if (p_current_span == p_span_list->end()) + { + --p_current_span; + p_value = p_current_span->end(); + --p_value; + } + else if ((p_current_span != p_span_list->begin()) || (p_value != p_current_span->begin())) + { + if (p_value == p_current_span->begin()) + { + do + { + --p_current_span; + } while ((p_current_span != p_span_list->begin()) && p_current_span->empty()); + + p_value = p_current_span->end(); + --p_value; + } + else + { + --p_value; + } + } + else + { + p_value = ETL_NULLPTR; + } + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator operator --(int) + { + const_iterator temp = *this; + + operator --(); + + return temp; + } + + //************************************************************************* + /// * operator + //************************************************************************* + ETL_CONSTEXPR14 const_reference operator *() const + { + return *p_value; + } + + //************************************************************************* + /// -> operator + //************************************************************************* + ETL_CONSTEXPR14 const_pointer operator ->() const + { + return p_value; + } + + //************************************************************************* + /// == operator + //************************************************************************* + ETL_CONSTEXPR14 friend bool operator ==(const const_iterator& lhs, const const_iterator& rhs) + { + return (lhs.p_current_span == rhs.p_current_span) && (lhs.p_value == rhs.p_value); + } + + //************************************************************************* + /// != operator + //************************************************************************* + ETL_CONSTEXPR14 friend bool operator !=(const const_iterator& lhs, const const_iterator& rhs) + { + return !(lhs == rhs); + } + + private: + + typedef const span_type* span_pointer; + typedef const span_list_type* span_list_pointer; + typedef const typename span_list_type::iterator span_list_iterator; + + //***************************************** + ETL_CONSTEXPR14 const_iterator(const span_list_type& span_list_, span_list_iterator p_current_span_) + : p_span_list(&span_list_) + , p_current_span(p_current_span_) + , p_value(ETL_NULLPTR) + { + if (p_current_span != p_span_list->end()) + { + while ((p_current_span != p_span_list->end()) && p_current_span->empty()) + { + ++p_current_span; + } + + if (p_current_span != p_span_list->end()) + { + p_value = p_current_span->begin(); + } + else + { + p_value = ETL_NULLPTR; + } + } + } + + span_list_pointer p_span_list; + span_pointer p_current_span; + const_pointer p_value; + }; + + typedef ETL_OR_STD::reverse_iterator reverse_iterator; + typedef ETL_OR_STD::reverse_iterator const_reverse_iterator; + //************************************************************************* /// Constructor. //************************************************************************* @@ -229,7 +498,7 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 multi_span(TIterator begin_, TIterator end_) - : span_list(etl::addressof(*begin_), etl::distance(begin_, end_)) + : span_list(etl::to_address(begin_), etl::distance(begin_, end_)) { } @@ -238,7 +507,7 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 multi_span(TIterator begin_, size_t length_) - : span_list(etl::addressof(*begin_), length_) + : span_list(etl::to_address(begin_), length_) { } @@ -253,7 +522,7 @@ namespace etl //************************************************************************* /// Assignment operator //************************************************************************* - ETL_CONSTEXPR14 multi_span& operator = (const multi_span & other) + ETL_CONSTEXPR14 multi_span& operator =(const multi_span & other) { span_list = other.span_list; @@ -265,7 +534,15 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 iterator begin() const { - return iterator(span_list.begin(), span_list.end()); + return iterator(span_list, span_list.begin()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 const_iterator cbegin() const + { + return const_iterator(span_list, span_list.cbegin()); } //************************************************************************* @@ -273,7 +550,66 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 iterator end() const { - return iterator(span_list.end(), span_list.end()); + return iterator(span_list, span_list.end()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 const_iterator cend() const + { + return const_iterator(span_list, span_list.cend()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 reverse_iterator rbegin() const + { + return reverse_iterator(end()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 reverse_iterator crbegin() const + { + return const_reverse_iterator(cend()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 reverse_iterator rend() const + { + return reverse_iterator(begin()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 const_reverse_iterator crend() const + { + return const_reverse_iterator(cbegin()); + } + + //************************************************************************* + /// Returns a reference to the indexed value. + //************************************************************************* + ETL_CONSTEXPR14 reference operator[](size_t i) const + { + // Find the span in the span list. + size_t number_of_spans = span_list.size(); + + size_t index = 0; + + while ((i >= span_list[index].size()) && (index < number_of_spans)) + { + i -= span_list[index].size(); + ++index; + } + + return span_list[index][i]; } //************************************************************************* diff --git a/include/etl/nth_type.h b/include/etl/nth_type.h index f870bb7c..7617dc68 100644 --- a/include/etl/nth_type.h +++ b/include/etl/nth_type.h @@ -30,25 +30,43 @@ SOFTWARE. #define ETL_NTH_TYPE_INCLUDED #include "platform.h" +#include "static_assert.h" +#if ETL_NOT_USING_CPP11 + #if !defined(ETL_IN_UNIT_TEST) + #error NOT SUPPORTED FOR C++03 OR BELOW + #endif +#else namespace etl { -#if ETL_USING_CPP11 - template + namespace private_nth_type + { + //*********************************** + template + struct nth_type_helper + { + using type = typename nth_type_helper::type; + }; + + template + struct nth_type_helper<0U, T1, TRest...> + { + using type = T1; + }; + } + + //*********************************** + template struct nth_type { - using type = typename nth_type::type; - }; - - template - struct nth_type<0U, T1, TRest...> - { - using type = T1; + ETL_STATIC_ASSERT(N < sizeof...(TTypes), "etl::nth_type index 'N' out of bounds"); + + using type = typename private_nth_type::nth_type_helper::type; }; + //*********************************** template using nth_type_t = typename nth_type::type; -#endif } - +#endif #endif diff --git a/include/etl/optional.h b/include/etl/optional.h index 002d010a..f70b2689 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -484,14 +484,16 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR20_STL - void emplace(TArgs&& ... args) + T& emplace(TArgs&& ... args) { storage.construct(etl::forward(args)...); + + return storage.u.value; } #else //************************************************************************* /// Emplaces a value. - /// 1 parameter. + /// 0 parameters. //************************************************************************* T& emplace() { @@ -1048,14 +1050,16 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 - void emplace(TArgs&& ... args) + T& emplace(TArgs&& ... args) { storage.construct(etl::forward(args)...); + + return storage.value; } #else //************************************************************************* /// Emplaces a value. - /// 1 parameter. + /// 0 parameters. //************************************************************************* T& emplace() { diff --git a/include/etl/parameter_pack.h b/include/etl/parameter_pack.h index a5e5ee7f..7948b17c 100644 --- a/include/etl/parameter_pack.h +++ b/include/etl/parameter_pack.h @@ -134,7 +134,7 @@ namespace etl inline constexpr size_t parameter_pack_v = etl::parameter_pack::template index_of_type::value; #endif -#if ETL_USING_CPP17 && (!ETL_USING_GCC_COMPILER || (__GNUC__ > 7)) +#if ETL_USING_CPP17 && !ETL_USING_GCC_COMPILER //*********************************** template template diff --git a/include/etl/platform.h b/include/etl/platform.h index 1eaa1329..3b097387 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -314,7 +314,7 @@ SOFTWARE. //************************************* // The macros below are dependent on the profile. // C++11 -#if ETL_USING_CPP11 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP11 #define ETL_CONSTEXPR constexpr #define ETL_CONSTEXPR11 constexpr // Synonym for ETL_CONSTEXPR #define ETL_CONSTANT constexpr @@ -354,10 +354,16 @@ SOFTWARE. //************************************* // C++14 -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) - #define ETL_CONSTEXPR14 constexpr - #define ETL_DEPRECATED [[deprecated]] - #define ETL_DEPRECATED_REASON(reason) [[deprecated(reason)]] +#if ETL_USING_CPP14 + #define ETL_CONSTEXPR14 constexpr + + #if !defined(ETL_IN_UNIT_TEST) + #define ETL_DEPRECATED [[deprecated]] + #define ETL_DEPRECATED_REASON(reason) [[deprecated(reason)]] + #else + #define ETL_DEPRECATED + #define ETL_DEPRECATED_REASON(reason) + #endif #else #define ETL_CONSTEXPR14 #define ETL_DEPRECATED @@ -366,7 +372,7 @@ SOFTWARE. //************************************* // C++17 -#if ETL_USING_CPP17 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP17 #define ETL_CONSTEXPR17 constexpr #define ETL_IF_CONSTEXPR constexpr #define ETL_NODISCARD [[nodiscard]] @@ -384,7 +390,7 @@ SOFTWARE. //************************************* // C++20 -#if ETL_USING_CPP20 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP20 #define ETL_LIKELY [[likely]] #define ETL_UNLIKELY [[unlikely]] #define ETL_CONSTEXPR20 constexpr @@ -410,7 +416,7 @@ SOFTWARE. //************************************* // C++23 -#if ETL_USING_CPP23 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP23 #define ETL_ASSUME(expression) [[assume(expression)]] #else #define ETL_ASSUME ETL_DO_NOTHING @@ -468,6 +474,15 @@ SOFTWARE. #else #define ETL_HAS_ATOMIC 0 #endif + #if ((ETL_USING_CPP17 && (ETL_USING_STL || defined(ETL_IN_UNIT_TEST))) || \ + defined(ETL_COMPILER_ARM5) || \ + defined(ETL_COMPILER_ARM6) || \ + defined(ETL_COMPILER_GCC) || \ + defined(ETL_COMPILER_CLANG)) + #define ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE 1 + #else + #define ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE 0 + #endif #endif //************************************* @@ -494,6 +509,26 @@ SOFTWARE. #define ETL_HAS_INITIALIZER_LIST 0 #endif +//************************************* +// Determine if the ETL should use __attribute__((packed). +#if defined(ETL_COMPILER_CLANG) || defined(ETL_COMPILER_GCC) || defined(ETL_COMPILER_INTEL) || defined(ETL_COMPILER_ARM6) + #define ETL_PACKED_CLASS(class_type) class __attribute__((packed)) class_type + #define ETL_PACKED_STRUCT(struct_type) struct __attribute__((packed)) struct_type + #define ETL_END_PACKED + #define ETL_HAS_PACKED 1 +#elif defined(ETL_COMPILER_MICROSOFT) + #define ETL_PACKED_CLASS(class_type) __pragma(pack(push, 1)) class class_type + #define ETL_PACKED_STRUCT(struct_type) __pragma(pack(push, 1)) struct struct_type + #define ETL_PACKED + #define ETL_END_PACKED __pragma(pack(pop)) + #define ETL_HAS_PACKED 1 +#else + #define ETL_PACKED_CLASS(class_type) class class_type + #define ETL_PACKED_STRUCT(struct_type) struct struct_type + #define ETL_END_PACKED + #define ETL_HAS_PACKED 0 +#endif + //************************************* // Check for availability of certain builtins #include "profiles/determine_builtin_support.h" @@ -538,6 +573,7 @@ namespace etl static ETL_CONSTANT bool has_8bit_types = (ETL_USING_8BIT_TYPES == 1); static ETL_CONSTANT bool has_64bit_types = (ETL_USING_64BIT_TYPES == 1); static ETL_CONSTANT bool has_atomic = (ETL_HAS_ATOMIC == 1); + static ETL_CONSTANT bool has_atomic_always_lock_free = (ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE == 1); static ETL_CONSTANT bool has_nullptr = (ETL_HAS_NULLPTR == 1); static ETL_CONSTANT bool has_char8_t = (ETL_HAS_CHAR8_T == 1); static ETL_CONSTANT bool has_native_char8_t = (ETL_HAS_NATIVE_CHAR8_T == 1); @@ -552,6 +588,7 @@ namespace etl static ETL_CONSTANT bool has_mutable_array_view = (ETL_HAS_MUTABLE_ARRAY_VIEW == 1); static ETL_CONSTANT bool has_ideque_repair = (ETL_HAS_IDEQUE_REPAIR == 1); static ETL_CONSTANT bool has_virtual_messages = (ETL_HAS_VIRTUAL_MESSAGES == 1); + static ETL_CONSTANT bool has_packed = (ETL_HAS_PACKED == 1); static ETL_CONSTANT bool has_chrono_literals_day = (ETL_HAS_CHRONO_LITERALS_DAY == 1); static ETL_CONSTANT bool has_chrono_literals_weekday = (ETL_HAS_CHRONO_LITERALS_WEEKDAY == 1); static ETL_CONSTANT bool has_chrono_literals_month = (ETL_HAS_CHRONO_LITERALS_MONTH == 1); diff --git a/include/etl/private/bitset_legacy.h b/include/etl/private/bitset_legacy.h index 593f415b..a1f40737 100644 --- a/include/etl/private/bitset_legacy.h +++ b/include/etl/private/bitset_legacy.h @@ -148,6 +148,8 @@ namespace etl public: + typedef size_t size_type; + typedef typename etl::make_unsigned::type element_type; typedef element_type element_t; // Backward compatibility diff --git a/include/etl/private/bitset_new.h b/include/etl/private/bitset_new.h index 323a4e47..2fcbc990 100644 --- a/include/etl/private/bitset_new.h +++ b/include/etl/private/bitset_new.h @@ -171,6 +171,7 @@ namespace etl typedef TElement element_type; typedef TElement* pointer; typedef const TElement* const_pointer; + typedef size_t size_type; static ETL_CONSTANT size_t npos = etl::integral_limits::max; static ETL_CONSTANT size_t Bits_Per_Element = etl::integral_limits::bits; @@ -1937,6 +1938,8 @@ namespace etl typedef typename etl::private_bitset::bitset_common::span_type span_type; typedef typename etl::private_bitset::bitset_common::const_span_type const_span_type; + + using etl::private_bitset::bitset_common::Bits_Per_Element; using etl::private_bitset::bitset_common::All_Set_Element; using etl::private_bitset::bitset_common::All_Clear_Element; @@ -2826,6 +2829,8 @@ namespace etl { public: + typedef size_t size_type; + typedef etl::private_bitset::bitset_common<0U, unsigned char>::element_type element_type; typedef etl::private_bitset::bitset_common<0U, unsigned char>::span_type span_type; typedef etl::private_bitset::bitset_common<0U, unsigned char>::const_span_type const_span_type; @@ -2850,6 +2855,8 @@ namespace etl ETL_STATIC_ASSERT(etl::is_unsigned::value, "The element type must be unsigned"); + typedef size_t size_type; + typedef typename etl::private_bitset::bitset_common::element_type element_type; typedef typename etl::private_bitset::bitset_common::span_type span_type; typedef typename etl::private_bitset::bitset_common::const_span_type const_span_type; diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index 511ae0a9..a3459658 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -181,7 +181,7 @@ namespace etl private: - unsigned char value; + uint_least8_t value; }; //*********************************************************************** diff --git a/include/etl/private/chrono/month.h b/include/etl/private/chrono/month.h index f9693c2c..6c3d05cc 100644 --- a/include/etl/private/chrono/month.h +++ b/include/etl/private/chrono/month.h @@ -181,15 +181,7 @@ namespace etl private: - //*********************************************************************** - /// Normalise to a in-range month - //*********************************************************************** - ETL_CONSTEXPR void normalise() ETL_NOEXCEPT - { - value = ((value % 12U) == 0U) ? 12U : value; - } - - unsigned char value; + uint_least8_t value; }; //*********************************************************************** @@ -302,9 +294,18 @@ namespace etl { if (m1.ok() && m2.ok()) { - etl::chrono::months ms(static_cast(static_cast(m1)) - - static_cast(static_cast(m2)) % 12); + // Calculate the signed difference. + int difference = static_cast(static_cast(m1)) - static_cast(static_cast(m2)); + // Adjust for wrap-around. + if (difference < 0) + { + difference += 12; + } + + etl::chrono::months ms(difference); + + // Check for validity. if (m1 == (m2 + ms)) { return ms; diff --git a/include/etl/private/crc_implementation.h b/include/etl/private/crc_implementation.h index d94f0f18..9e642907 100644 --- a/include/etl/private/crc_implementation.h +++ b/include/etl/private/crc_implementation.h @@ -163,7 +163,7 @@ namespace etl // Accumulator_Bits > Chunk_Bits // Not Reflected template - static + static ETL_CONSTEXPR14 typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && !Reflect, TAccumulator>::type crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) { @@ -181,7 +181,7 @@ namespace etl // Accumulator_Bits > Chunk_Bits // Reflected template - static + static ETL_CONSTEXPR14 typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && Reflect, TAccumulator>::type crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) { @@ -199,7 +199,7 @@ namespace etl // Accumulator_Bits == Chunk_Bits // Not Reflected template - static + static ETL_CONSTEXPR14 typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && !Reflect, TAccumulator>::type crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) { @@ -216,7 +216,7 @@ namespace etl // Accumulator_Bits == Chunk_Bits // Reflected template - static + static ETL_CONSTEXPR14 typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && Reflect, TAccumulator>::type crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) { @@ -241,8 +241,10 @@ namespace etl struct crc_table { //************************************************************************* +#if !ETL_USING_CPP11 TAccumulator add(TAccumulator crc, uint8_t value) const { +#endif static ETL_CONSTANT TAccumulator table[4U] = { crc_table_entry::value, @@ -250,7 +252,10 @@ namespace etl crc_table_entry::value, crc_table_entry::value }; - +#if ETL_USING_CPP11 + ETL_CONSTEXPR14 TAccumulator add(TAccumulator crc, uint8_t value) const + { +#endif if ETL_IF_CONSTEXPR(Reflect) { crc = crc_update_chunk(crc, value, table); @@ -269,6 +274,10 @@ namespace etl return crc; } }; +#if ETL_USING_CPP11 + template + ETL_CONSTANT TAccumulator crc_table::table[4U]; +#endif //********************************* // Table size of 16. @@ -276,8 +285,10 @@ namespace etl struct crc_table { //************************************************************************* +#if !ETL_USING_CPP11 TAccumulator add(TAccumulator crc, uint8_t value) const { +#endif static ETL_CONSTANT TAccumulator table[16U] = { crc_table_entry::value, @@ -297,7 +308,10 @@ namespace etl crc_table_entry::value, crc_table_entry::value }; - +#if ETL_USING_CPP11 + ETL_CONSTEXPR14 TAccumulator add(TAccumulator crc, uint8_t value) const + { +#endif if ETL_IF_CONSTEXPR(Reflect) { crc = crc_update_chunk(crc, value, table); @@ -312,6 +326,10 @@ namespace etl return crc; } }; +#if ETL_USING_CPP11 + template + ETL_CONSTANT TAccumulator crc_table::table[16U]; +#endif //********************************* // Table size of 256. @@ -319,9 +337,11 @@ namespace etl struct crc_table { //************************************************************************* +#if !ETL_USING_CPP11 TAccumulator add(TAccumulator crc, uint8_t value) const { - static ETL_CONSTANT TAccumulator table[256U] = +#endif + static ETL_CONSTANT TAccumulator table[256U]= { crc_table_entry::value, crc_table_entry::value, @@ -580,13 +600,20 @@ namespace etl crc_table_entry::value, crc_table_entry::value }; +#if ETL_USING_CPP11 + ETL_CONSTEXPR14 TAccumulator add(TAccumulator crc, uint8_t value) const + { +#endif crc = crc_update_chunk(crc, value, table); return crc; } }; - +#if ETL_USING_CPP11 + template + ETL_CONSTANT TAccumulator crc_table::table[256U]; +#endif //***************************************************************************** // CRC Policies. //***************************************************************************** @@ -615,7 +642,7 @@ namespace etl } //************************************************************************* - accumulator_type final(accumulator_type crc) const + ETL_CONSTEXPR accumulator_type final(accumulator_type crc) const { return crc ^ TCrcParameters::Xor_Out; } @@ -643,7 +670,7 @@ namespace etl } //************************************************************************* - accumulator_type final(accumulator_type crc) const + ETL_CONSTEXPR accumulator_type final(accumulator_type crc) const { return crc ^ TCrcParameters::Xor_Out; } @@ -671,7 +698,7 @@ namespace etl } //************************************************************************* - accumulator_type final(accumulator_type crc) const + ETL_CONSTEXPR accumulator_type final(accumulator_type crc) const { return crc ^ TCrcParameters::Xor_Out; } @@ -691,7 +718,7 @@ namespace etl //************************************************************************* /// Default constructor. //************************************************************************* - crc_type() + ETL_CONSTEXPR14 crc_type() { this->reset(); } @@ -702,7 +729,7 @@ namespace etl /// \param end End of the range. //************************************************************************* template - crc_type(TIterator begin, const TIterator end) + ETL_CONSTEXPR14 crc_type(TIterator begin, const TIterator end) { this->reset(); this->add(begin, end); diff --git a/include/etl/private/delegate_cpp03.h b/include/etl/private/delegate_cpp03.h index 74da0e49..382e6504 100644 --- a/include/etl/private/delegate_cpp03.h +++ b/include/etl/private/delegate_cpp03.h @@ -66,11 +66,11 @@ namespace etl //*********************************** template struct call_if_impl - { + { etl::optional call_if(TParam param) { - TDelegate& d = static_cast(*this); - + TDelegate& d = static_cast(*this); + etl::optional result; if (d.is_valid()) @@ -88,8 +88,8 @@ namespace etl { bool call_if() { - TDelegate& d = static_cast(*this); - + TDelegate& d = static_cast(*this); + if (d.is_valid()) { d(); @@ -168,6 +168,22 @@ namespace etl } }; + //***************************************************************** + /// The tag to identify an etl::delegate. + ///\ingroup delegate + //***************************************************************** + struct delegate_tag + { + }; + + //*************************************************************************** + /// is_delegate + //*************************************************************************** + template + struct is_delegate : etl::bool_constant::value> + { + }; + //************************************************************************* /// Declaration. //************************************************************************* @@ -175,14 +191,19 @@ namespace etl class delegate; template - class delegate : public private_delegate::call_if_impl, TReturn, TParam> + class delegate : public private_delegate::call_if_impl, TReturn, TParam>, + public delegate_tag { private: - + typedef delegate delegate_type; public: + typedef TReturn (*function_type)(TParam); + typedef TReturn return_type; + typedef TParam argument_type; + using private_delegate::call_if_impl, TReturn, TParam>::call_if; //************************************************************************* @@ -204,7 +225,7 @@ namespace etl // Construct from a functor. //************************************************************************* template - delegate(TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + delegate(TFunctor& instance, typename etl::enable_if::value && !is_delegate::value, int>::type = 0) { assign((void*)(&instance), functor_stub); } @@ -213,7 +234,7 @@ namespace etl // Construct from a const functor. //************************************************************************* template - delegate(const TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + delegate(const TFunctor& instance, typename etl::enable_if::value && !is_delegate::value, int>::type = 0) { assign((void*)(&instance), const_functor_stub); } @@ -232,7 +253,7 @@ namespace etl //************************************************************************* template static - typename etl::enable_if::value &&!etl::is_same::value, delegate>::type + typename etl::enable_if::value &&!is_delegate::value, delegate>::type create(TFunctor& instance) { return delegate((void*)(&instance), functor_stub); @@ -243,7 +264,7 @@ namespace etl //************************************************************************* template static - typename etl::enable_if::value && !etl::is_same::value, delegate>::type + typename etl::enable_if::value && !is_delegate::value, delegate>::type create(const TFunctor& instance) { return delegate((void*)(&instance), const_functor_stub); @@ -330,7 +351,7 @@ namespace etl /// Set from Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, void>::type + typename etl::enable_if::value && !is_delegate::value, void>::type set(TFunctor& instance) { assign((void*)(&instance), functor_stub); @@ -340,7 +361,7 @@ namespace etl /// Set from const Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, void>::type + typename etl::enable_if::value && !is_delegate::value, void>::type set(const TFunctor& instance) { assign((void*)(&instance), const_functor_stub); @@ -467,7 +488,7 @@ namespace etl /// Create from Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + typename etl::enable_if::value && !is_delegate::value, delegate&>::type operator =(TFunctor& instance) { assign((void*)(&instance), functor_stub); @@ -478,7 +499,7 @@ namespace etl /// Create from const Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + typename etl::enable_if::value && !is_delegate::value, delegate&>::type operator =(const TFunctor& instance) { assign((void*)(&instance), const_functor_stub); @@ -684,6 +705,10 @@ namespace etl public: + typedef TReturn (*function_type)(void); + typedef TReturn return_type; + typedef void argument_type; + using private_delegate::call_if_impl< delegate, TReturn, void>::call_if; //************************************************************************* @@ -705,7 +730,7 @@ namespace etl // Construct from functor. //************************************************************************* template - delegate(TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + delegate(TFunctor& instance, typename etl::enable_if::value && !is_delegate::value, int>::type = 0) { assign((void*)(&instance), functor_stub); } @@ -714,7 +739,7 @@ namespace etl // Construct from const functor. //************************************************************************* template - delegate(const TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + delegate(const TFunctor& instance, typename etl::enable_if::value && !is_delegate::value, int>::type = 0) { assign((void*)(&instance), const_functor_stub); } @@ -733,7 +758,7 @@ namespace etl //************************************************************************* template static - typename etl::enable_if::value && !etl::is_same::value, delegate>::type + typename etl::enable_if::value && !is_delegate::value, delegate>::type create(TFunctor& instance) { return delegate((void*)(&instance), functor_stub); @@ -744,7 +769,7 @@ namespace etl //************************************************************************* template static - typename etl::enable_if::value && !etl::is_same::value, delegate>::type + typename etl::enable_if::value && !is_delegate::value, delegate>::type create(const TFunctor& instance) { return delegate((void*)(&instance), const_functor_stub); @@ -831,7 +856,7 @@ namespace etl /// Set from Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, void>::type + typename etl::enable_if::value && !is_delegate::value, void>::type set(TFunctor& instance) { assign((void*)(&instance), functor_stub); @@ -841,7 +866,7 @@ namespace etl /// Set from const Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, void>::type + typename etl::enable_if::value && !is_delegate::value, void>::type set(const TFunctor& instance) { assign((void*)(&instance), const_functor_stub); @@ -968,7 +993,7 @@ namespace etl /// Create from Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + typename etl::enable_if::value && !is_delegate::value, delegate&>::type operator =(TFunctor& instance) { assign((void*)(&instance), functor_stub); @@ -979,7 +1004,7 @@ namespace etl /// Create from const Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + typename etl::enable_if::value && !is_delegate::value, delegate&>::type operator =(const TFunctor& instance) { assign((void*)(&instance), const_functor_stub); diff --git a/include/etl/private/delegate_cpp11.h b/include/etl/private/delegate_cpp11.h index 8f438602..0bb8025e 100644 --- a/include/etl/private/delegate_cpp11.h +++ b/include/etl/private/delegate_cpp11.h @@ -52,6 +52,7 @@ Original publication: https://www.codeproject.com/Articles/1170503/The-Impossibl #include "../error_handler.h" #include "../exception.h" #include "../type_traits.h" +#include "../function_traits.h" #include "../utility.h" #include "../optional.h" @@ -83,16 +84,38 @@ namespace etl } }; + //***************************************************************** + /// The tag to identify an etl::delegate. + ///\ingroup delegate + //***************************************************************** + struct delegate_tag + { + }; + + //*************************************************************************** + /// is_delegate + //*************************************************************************** + template + struct is_delegate : etl::bool_constant::value> + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool is_delegate_v = is_delegate::value; +#endif + //************************************************************************* /// Declaration. //************************************************************************* - template class delegate; + template + class delegate; //************************************************************************* /// Specialisation. //************************************************************************* template - class delegate final + class delegate final : public delegate_tag { public: @@ -111,7 +134,7 @@ namespace etl //************************************************************************* // Construct from lambda or functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 delegate(TLambda& instance) { assign((void*)(&instance), lambda_stub); @@ -120,12 +143,18 @@ namespace etl //************************************************************************* // Construct from const lambda or functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 delegate(const TLambda& instance) { assign((void*)(&instance), const_lambda_stub); } + //************************************************************************* + // Delete construction from rvalue reference lambda or functor. + //************************************************************************* + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 delegate(TLambda&& instance) = delete; + //************************************************************************* /// Create from function (Compile time). //************************************************************************* @@ -139,7 +168,7 @@ namespace etl //************************************************************************* /// Create from Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_NODISCARD static ETL_CONSTEXPR14 delegate create(TLambda& instance) { @@ -149,7 +178,7 @@ namespace etl //************************************************************************* /// Create from const Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_NODISCARD static ETL_CONSTEXPR14 delegate create(const TLambda& instance) { @@ -257,7 +286,7 @@ namespace etl //************************************************************************* /// Set from Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 void set(TLambda& instance) { assign((void*)(&instance), lambda_stub); @@ -266,7 +295,7 @@ namespace etl //************************************************************************* /// Set from const Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 void set(const TLambda& instance) { assign((void*)(&instance), const_lambda_stub); @@ -348,7 +377,7 @@ namespace etl //************************************************************************* /// Execute the delegate if valid. - /// 'void' return. + /// 'void' return delegate. //************************************************************************* template ETL_CONSTEXPR14 @@ -368,7 +397,7 @@ namespace etl //************************************************************************* /// Execute the delegate if valid. - /// Non 'void' return. + /// Non 'void' return delegate. //************************************************************************* template ETL_CONSTEXPR14 @@ -427,7 +456,7 @@ namespace etl //************************************************************************* /// Create from Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 delegate& operator =(TLambda& instance) { assign((void*)(&instance), lambda_stub); @@ -437,7 +466,7 @@ namespace etl //************************************************************************* /// Create from const Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 delegate& operator =(const TLambda& instance) { assign((void*)(&instance), const_lambda_stub); @@ -447,6 +476,7 @@ namespace etl //************************************************************************* /// Checks equality. //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 bool operator == (const delegate& rhs) const { return invocation == rhs.invocation; @@ -472,6 +502,7 @@ namespace etl //************************************************************************* /// Returns true if the delegate is valid. //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 operator bool() const { return is_valid(); @@ -627,6 +658,92 @@ namespace etl //************************************************************************* invocation_element invocation; }; + +#if ETL_USING_CPP17 + //************************************************************************* + /// Make a delegate from a free function. + //************************************************************************* + template + ETL_NODISCARD + constexpr auto make_delegate() ETL_NOEXCEPT + { + using function_type = typename etl::function_traits::function_type; + + return etl::delegate::template create(); + } + + //************************************************************************* + /// Make a delegate from a functor or lambda function. + //************************************************************************* + template ::value, void>> + ETL_NODISCARD + constexpr auto make_delegate(TLambda& instance) ETL_NOEXCEPT + { + using function_type = typename etl::function_traits::function_type; + + return etl::delegate(instance); + } + + //************************************************************************* + /// Make a delegate from a functor, compile time. + //************************************************************************* + template + ETL_NODISCARD + constexpr auto make_delegate() ETL_NOEXCEPT + { + using function_type = typename etl::function_traits::function_type; + + return etl::delegate::template create(); + } + + //************************************************************************* + /// Make a delegate from a member function at compile time. + //************************************************************************* + template ::is_const>> + ETL_NODISCARD + constexpr auto make_delegate() ETL_NOEXCEPT + { + using function_type = typename etl::function_traits::function_type; + + return etl::delegate::template create(); + } + + //************************************************************************* + /// Make a delegate from a const member function at compile time. + //************************************************************************* + template ::is_const>> + ETL_NODISCARD + constexpr auto make_delegate() ETL_NOEXCEPT + { + using function_type = typename etl::function_traits::function_type; + + return etl::delegate::template create(); + } + + //************************************************************************* + /// Make a delegate from a member function at run time. + //************************************************************************* + template + ETL_NODISCARD + constexpr auto make_delegate(T& instance) ETL_NOEXCEPT + { + using function_type = typename etl::function_traits::function_type; + + return etl::delegate::template create(instance); + } + + //************************************************************************* + /// Make a delegate from a member function at run time. + //************************************************************************* + template + ETL_NODISCARD + constexpr auto make_delegate(const T& instance) ETL_NOEXCEPT + { + using function_type = typename etl::function_traits::function_type; + + return etl::delegate::template create(instance); + } +#endif } #endif diff --git a/include/etl/private/tuple_element.h b/include/etl/private/tuple_element.h new file mode 100644 index 00000000..ca6231a3 --- /dev/null +++ b/include/etl/private/tuple_element.h @@ -0,0 +1,54 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 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_TUPLE_ELEMENT_INCLUDED +#define ETL_TUPLE_ELEMENT_INCLUDED + +namespace etl +{ +#if ETL_USING_CPP11 + //*************************************************************************** + template + struct tuple_element; + + //*************************************************************************** + template + struct tuple_element + { + using type = typename etl::add_const_t::type>; + }; + + //*************************************************************************** + template + using tuple_element_t = typename tuple_element::type; +#endif +} + +#endif diff --git a/include/etl/private/tuple_size.h b/include/etl/private/tuple_size.h new file mode 100644 index 00000000..895a61f7 --- /dev/null +++ b/include/etl/private/tuple_size.h @@ -0,0 +1,53 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 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_TUPLE_SIZE_INCLUDED +#define ETL_TUPLE_SIZE_INCLUDED + +namespace etl +{ + //*************************************************************************** + template + struct tuple_size; + + //*************************************************************************** + template + struct tuple_size : etl::integral_constant::value> + { + }; + + //*************************************************************************** +#if ETL_USING_CPP17 + template + inline constexpr size_t tuple_size_v = tuple_size::value; +#endif +} + +#endif diff --git a/include/etl/private/variant_legacy.h b/include/etl/private/variant_legacy.h index dc2dbd70..d6eb539a 100644 --- a/include/etl/private/variant_legacy.h +++ b/include/etl/private/variant_legacy.h @@ -40,6 +40,7 @@ SOFTWARE. #include "../error_handler.h" #include "../null_type.h" #include "../placement_new.h" +#include "../monostate.h" #include @@ -75,9 +76,7 @@ namespace etl /// Monostate for variants. ///\ingroup variant //*************************************************************************** - struct monostate - { - }; + typedef etl::monostate monostate; //*************************************************************************** /// Base exception for the variant class. @@ -480,6 +479,19 @@ namespace etl type_id = Type_Id_Lookup::type_id; } + //*************************************************************************** + /// Constructor that catches any types that are not supported. + /// Forces a ETL_STATIC_ASSERT. + //*************************************************************************** + template + explicit variant(etl::in_place_index_t, T const& value) + : type_id(Index) + { + ETL_STATIC_ASSERT(Type_Id_Lookup::type_id == Index, "Missmatched type"); + ::new (static_cast(data)) T(value); + type_id = Index; + } + //*************************************************************************** /// Copy constructor. ///\param other The other variant object to copy. diff --git a/include/etl/private/variant_select_do_operator.h b/include/etl/private/variant_select_do_operator.h new file mode 100644 index 00000000..c4b125d0 --- /dev/null +++ b/include/etl/private/variant_select_do_operator.h @@ -0,0 +1,1020 @@ +/****************************************************************************** +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. +******************************************************************************/ + +//*************************************************************************** +// This file is included in variant_variadic.h for C++11 and C++14, as they +// do not support template fold expressions. +//*************************************************************************** + +namespace private_variant +{ + //*************************************************************************** + // Selects a do_operator inplementation that is configured for the number of types. + //*************************************************************************** + template + struct select_do_operator; + + //*************************************************************************** + template <> + struct select_do_operator<1> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_operator<2> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_operator<3> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<4> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<5> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<6> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<7> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<8> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) + //*************************************************************************** + template <> + struct select_do_operator<9> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<10> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<11> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<12> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<13> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<14> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<15> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<16> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) + //*************************************************************************** + template <> + struct select_do_operator<17> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<18> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<19> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<20> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<21> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<22> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<23> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<24> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) + //*************************************************************************** + template <> + struct select_do_operator<25> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<26> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<27> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<28> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<29> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<30> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + case 29: { visitor(etl::get<29>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<31> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + case 29: { visitor(etl::get<29>(the_variant)); break; } + case 30: { visitor(etl::get<30>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<32> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + case 29: { visitor(etl::get<29>(the_variant)); break; } + case 30: { visitor(etl::get<30>(the_variant)); break; } + case 31: { visitor(etl::get<31>(the_variant)); break; } + default: break; + } + }; + }; +#endif +#endif +#endif +} diff --git a/include/etl/private/variant_select_do_visitor.h b/include/etl/private/variant_select_do_visitor.h new file mode 100644 index 00000000..b6e5bc50 --- /dev/null +++ b/include/etl/private/variant_select_do_visitor.h @@ -0,0 +1,1020 @@ +/****************************************************************************** +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. +******************************************************************************/ + +//*************************************************************************** +// This file is included in variant_variadic.h for C++11 and C++14, as they +// do not support template fold expressions. +//*************************************************************************** + +namespace private_variant +{ + //*************************************************************************** + // Selects a do_visitor inplementation that is configured for the number of types. + //*************************************************************************** + template + struct select_do_visitor; + + //*************************************************************************** + template <> + struct select_do_visitor<1> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_visitor<2> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_visitor<3> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<4> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<5> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<6> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<7> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<8> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) + //*************************************************************************** + template <> + struct select_do_visitor<9> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<10> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<11> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<12> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<13> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<14> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<15> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<16> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) + //*************************************************************************** + template <> + struct select_do_visitor<17> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<18> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<19> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<20> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<21> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<22> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<23> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<24> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) + //*************************************************************************** + template <> + struct select_do_visitor<25> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<26> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<27> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<28> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<29> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<30> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + case 29: { visitor.visit(etl::get<29>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<31> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + case 29: { visitor.visit(etl::get<29>(the_variant)); break; } + case 30: { visitor.visit(etl::get<30>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<32> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + case 29: { visitor.visit(etl::get<29>(the_variant)); break; } + case 30: { visitor.visit(etl::get<30>(the_variant)); break; } + case 31: { visitor.visit(etl::get<31>(the_variant)); break; } + default: break; + } + }; + }; +#endif +#endif +#endif +} diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index 44334669..37f723a7 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -31,18 +31,20 @@ SOFTWARE. #include "../platform.h" #include "../utility.h" #include "../largest.h" +#include "../nth_type.h" #include "../exception.h" #include "../type_traits.h" #include "../integral_limits.h" #include "../static_assert.h" #include "../alignment.h" #include "../error_handler.h" -#include "../parameter_pack.h" +#include "../type_list.h" #include "../placement_new.h" #include "../visitor.h" #include "../memory.h" #include "../compare.h" #include "../initializer_list.h" +#include "../monostate.h" #include @@ -66,95 +68,19 @@ namespace etl { namespace private_variant { - //*************************************************************************** - // This is a copy of the normal etl::parameter_pack, but without the static_assert - // so that the C++11 versions of do_visitor() & do_operator() do not throw a compile time error. - //*************************************************************************** - template - class parameter_pack - { - public: - - static constexpr size_t size = sizeof...(TTypes); - - //*************************************************************************** - /// index_of_type - //*************************************************************************** - template - class index_of_type - { - private: - - using type = etl::remove_cvref_t; - - //*********************************** - template - struct index_of_type_helper - { - static constexpr size_t value = etl::is_same::value ? 1 : 1 + index_of_type_helper::value; - }; - - //*********************************** - template - struct index_of_type_helper - { - static constexpr size_t value = 1UL; - }; - - public: - - static_assert(etl::is_one_of::value, "T is not in parameter pack"); - - /// The index value. - static constexpr size_t value = index_of_type_helper::value - 1; - }; - - //*************************************************************************** - /// type_from_index - //*************************************************************************** - template - class type_from_index - { - private: - - //*********************************** - template - struct type_from_index_helper - { - using type = typename etl::conditional::type>::type; - }; - - //*********************************** - template - struct type_from_index_helper - { - using type = T1; - }; - - public: - - /// Template alias - using type = typename type_from_index_helper::type; - }; - - //*********************************** - template - using type_from_index_t = typename type_from_index::type; - }; - //******************************************* // The traits an object may have. //******************************************* - static constexpr bool Copyable = true; + static constexpr bool Copyable = true; static constexpr bool Non_Copyable = false; - static constexpr bool Moveable = true; + static constexpr bool Moveable = true; static constexpr bool Non_Moveable = false; //******************************************* // The types of operations we can perform. //******************************************* - static constexpr int Copy = 0; - static constexpr int Move = 1; + static constexpr int Copy = 0; + static constexpr int Move = 1; static constexpr int Destroy = 2; //******************************************* @@ -168,7 +94,7 @@ namespace etl template <> struct operation_type { - static void do_operation(int , char* , const char* ) + static void do_operation(int, char*, const char*) { // This should never occur. #if defined(ETL_IN_UNIT_TEST) @@ -195,9 +121,9 @@ namespace etl default: { // This should never occur. - #if defined(ETL_IN_UNIT_TEST) +#if defined(ETL_IN_UNIT_TEST) assert(false); - #endif +#endif break; } } @@ -228,9 +154,9 @@ namespace etl default: { // This should never occur. - #if defined(ETL_IN_UNIT_TEST) +#if defined(ETL_IN_UNIT_TEST) assert(false); - #endif +#endif break; } } @@ -261,9 +187,9 @@ namespace etl default: { // This should never occur. - #if defined(ETL_IN_UNIT_TEST) +#if defined(ETL_IN_UNIT_TEST) assert(false); - #endif +#endif break; } } @@ -320,14 +246,14 @@ namespace etl //*************************************************************************** /// variant_alternative - //*************************************************************************** + //*************************************************************************** template struct variant_alternative; template struct variant_alternative> { - using type = typename etl::private_variant::parameter_pack::template type_from_index::type; + using type = etl::nth_type_t; }; template @@ -374,13 +300,10 @@ namespace etl template ETL_CONSTEXPR14 const T&& get(const etl::variant&& v); - //*************************************************************************** - /// Monostate for variants. - ///\ingroup variant - //*************************************************************************** - struct monostate - { - }; +#if ETL_NOT_USING_CPP17 + #include "variant_select_do_visitor.h" + #include "variant_select_do_operator.h" +#endif constexpr bool operator >(etl::monostate, etl::monostate) noexcept { return false; } constexpr bool operator <(etl::monostate, etl::monostate) noexcept { return false; } @@ -455,11 +378,6 @@ namespace etl { public: - //*************************************************************************** - /// The type used for ids. - //*************************************************************************** - using type_id_t = uint_least8_t ; - //*************************************************************************** /// get() is a friend function. //*************************************************************************** @@ -529,13 +447,13 @@ namespace etl // Get the index of a type. //******************************************* template - using index_of_type = typename etl::private_variant::parameter_pack::template index_of_type>; + using index_of_type = etl::type_list_index_of_type, etl::remove_cvref_t>; //******************************************* // Get the type from the index. //******************************************* template - using type_from_index = typename etl::private_variant::parameter_pack::template type_from_index::type; + using type_from_index = typename etl::type_list_type_at_index, Index>::type; public: @@ -546,7 +464,7 @@ namespace etl #include "diagnostic_uninitialized_push.h" ETL_CONSTEXPR14 variant() { - using type = typename etl::private_variant::parameter_pack::template type_from_index<0U>::type; + using type = type_from_index<0U>; default_construct_in_place(data); operation = operation_type::value, etl::is_move_constructible::value>::do_operation; @@ -592,7 +510,7 @@ namespace etl ETL_CONSTEXPR14 explicit variant(etl::in_place_index_t, TArgs&&... args) : type_id(Index) { - using type = typename private_variant::parameter_pack:: template type_from_index_t; + using type = type_from_index; static_assert(etl::is_one_of ::value, "Unsupported type"); construct_in_place_args(data, etl::forward(args)...); @@ -625,7 +543,7 @@ namespace etl ETL_CONSTEXPR14 explicit variant(etl::in_place_index_t, std::initializer_list init, TArgs&&... args) : type_id(Index) { - using type = typename private_variant::parameter_pack:: template type_from_index_t; + using type = type_from_index; static_assert(etl::is_one_of ::value, "Unsupported type"); construct_in_place_args(data, init, etl::forward(args)...); @@ -715,7 +633,7 @@ namespace etl operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *static_cast(data); } @@ -737,7 +655,7 @@ namespace etl operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *static_cast(data); } @@ -747,9 +665,9 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(TArgs&&... args) + typename etl::variant_alternative_t>& emplace(TArgs&&... args) { - static_assert(Index < etl::private_variant::parameter_pack::size, "Index out of range"); + static_assert(Index < sizeof...(TTypes), "Index out of range"); using type = type_from_index; @@ -769,9 +687,9 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(std::initializer_list il, TArgs&&... args) + typename etl::variant_alternative_t>& emplace(std::initializer_list il, TArgs&&... args) { - static_assert(Index < etl::private_variant::parameter_pack::size, "Index out of range"); + static_assert(Index < sizeof...(TTypes), "Index out of range"); using type = type_from_index; @@ -803,7 +721,7 @@ namespace etl construct_in_place(data, etl::forward(value)); operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *this; } @@ -896,7 +814,7 @@ namespace etl template (), int> = 0> constexpr bool is_type() const noexcept { - return (type_id == etl::private_variant::parameter_pack::template index_of_type::value); + return (type_id == index_of_type::value); } //*************************************************************************** @@ -937,7 +855,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -951,7 +869,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -965,7 +883,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -979,7 +897,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -996,7 +914,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -1013,7 +931,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -1030,7 +948,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -1047,7 +965,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -1120,103 +1038,21 @@ namespace etl } #else //*************************************************************************** - /// /// Call the relevant visitor. + /// Call the relevant visitor. //*************************************************************************** - template + template void do_visitor(TVisitor& visitor) { - switch (index()) - { - case 0: { visitor.visit(etl::get<0>(*this)); break; } - case 1: { visitor.visit(etl::get<1>(*this)); break; } - case 2: { visitor.visit(etl::get<2>(*this)); break; } - case 3: { visitor.visit(etl::get<3>(*this)); break; } - case 4: { visitor.visit(etl::get<4>(*this)); break; } - case 5: { visitor.visit(etl::get<5>(*this)); break; } - case 6: { visitor.visit(etl::get<6>(*this)); break; } - case 7: { visitor.visit(etl::get<7>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: { visitor.visit(etl::get<8>(*this)); break; } - case 9: { visitor.visit(etl::get<9>(*this)); break; } - case 10: { visitor.visit(etl::get<10>(*this)); break; } - case 11: { visitor.visit(etl::get<11>(*this)); break; } - case 12: { visitor.visit(etl::get<12>(*this)); break; } - case 13: { visitor.visit(etl::get<13>(*this)); break; } - case 14: { visitor.visit(etl::get<14>(*this)); break; } - case 15: { visitor.visit(etl::get<15>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: { visitor.visit(etl::get<16>(*this)); break; } - case 17: { visitor.visit(etl::get<17>(*this)); break; } - case 18: { visitor.visit(etl::get<18>(*this)); break; } - case 19: { visitor.visit(etl::get<19>(*this)); break; } - case 20: { visitor.visit(etl::get<20>(*this)); break; } - case 21: { visitor.visit(etl::get<21>(*this)); break; } - case 22: { visitor.visit(etl::get<22>(*this)); break; } - case 23: { visitor.visit(etl::get<23>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: { visitor.visit(etl::get<24>(*this)); break; } - case 25: { visitor.visit(etl::get<25>(*this)); break; } - case 26: { visitor.visit(etl::get<26>(*this)); break; } - case 27: { visitor.visit(etl::get<27>(*this)); break; } - case 28: { visitor.visit(etl::get<28>(*this)); break; } - case 29: { visitor.visit(etl::get<29>(*this)); break; } - case 30: { visitor.visit(etl::get<30>(*this)); break; } - case 31: { visitor.visit(etl::get<31>(*this)); break; } -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_visitor::do_visitor(*this, visitor); } //*************************************************************************** - /// /// Call the relevant visitor. + /// Call the relevant visitor. //*************************************************************************** - template + template void do_visitor(TVisitor& visitor) const { - switch (index()) - { - case 0: { visitor.visit(etl::get<0>(*this)); break; } - case 1: { visitor.visit(etl::get<1>(*this)); break; } - case 2: { visitor.visit(etl::get<2>(*this)); break; } - case 3: { visitor.visit(etl::get<3>(*this)); break; } - case 4: { visitor.visit(etl::get<4>(*this)); break; } - case 5: { visitor.visit(etl::get<5>(*this)); break; } - case 6: { visitor.visit(etl::get<6>(*this)); break; } - case 7: { visitor.visit(etl::get<7>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: { visitor.visit(etl::get<8>(*this)); break; } - case 9: { visitor.visit(etl::get<9>(*this)); break; } - case 10: { visitor.visit(etl::get<10>(*this)); break; } - case 11: { visitor.visit(etl::get<11>(*this)); break; } - case 12: { visitor.visit(etl::get<12>(*this)); break; } - case 13: { visitor.visit(etl::get<13>(*this)); break; } - case 14: { visitor.visit(etl::get<14>(*this)); break; } - case 15: { visitor.visit(etl::get<15>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: { visitor.visit(etl::get<16>(*this)); break; } - case 17: { visitor.visit(etl::get<17>(*this)); break; } - case 18: { visitor.visit(etl::get<18>(*this)); break; } - case 19: { visitor.visit(etl::get<19>(*this)); break; } - case 20: { visitor.visit(etl::get<20>(*this)); break; } - case 21: { visitor.visit(etl::get<21>(*this)); break; } - case 22: { visitor.visit(etl::get<22>(*this)); break; } - case 23: { visitor.visit(etl::get<23>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: { visitor.visit(etl::get<24>(*this)); break; } - case 25: { visitor.visit(etl::get<25>(*this)); break; } - case 26: { visitor.visit(etl::get<26>(*this)); break; } - case 27: { visitor.visit(etl::get<27>(*this)); break; } - case 28: { visitor.visit(etl::get<28>(*this)); break; } - case 29: { visitor.visit(etl::get<29>(*this)); break; } - case 30: { visitor.visit(etl::get<30>(*this)); break; } - case 31: { visitor.visit(etl::get<31>(*this)); break; } -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_visitor::do_visitor(*this, visitor); } #endif @@ -1282,9 +1118,9 @@ namespace etl } #else //*************************************************************************** - /// Call the relevant visitor. + /// Call the relevant operator. //*************************************************************************** - template + template void do_operator(TVisitor& visitor) { #if defined(ETL_VARIANT_CPP11_MAX_8_TYPES) @@ -1301,54 +1137,13 @@ namespace etl ETL_STATIC_ASSERT(sizeof...(TTypes) <= 32U, "A maximum of 32 types are allowed in this variant"); - switch (index()) - { - case 0: visitor(etl::get<0>(*this)); break; - case 1: visitor(etl::get<1>(*this)); break; - case 2: visitor(etl::get<2>(*this)); break; - case 3: visitor(etl::get<3>(*this)); break; - case 4: visitor(etl::get<4>(*this)); break; - case 5: visitor(etl::get<5>(*this)); break; - case 6: visitor(etl::get<6>(*this)); break; - case 7: visitor(etl::get<7>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: visitor(etl::get<8>(*this)); break; - case 9: visitor(etl::get<9>(*this)); break; - case 10: visitor(etl::get<10>(*this)); break; - case 11: visitor(etl::get<11>(*this)); break; - case 12: visitor(etl::get<12>(*this)); break; - case 13: visitor(etl::get<13>(*this)); break; - case 14: visitor(etl::get<14>(*this)); break; - case 15: visitor(etl::get<15>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: visitor(etl::get<16>(*this)); break; - case 17: visitor(etl::get<17>(*this)); break; - case 18: visitor(etl::get<18>(*this)); break; - case 19: visitor(etl::get<19>(*this)); break; - case 20: visitor(etl::get<20>(*this)); break; - case 21: visitor(etl::get<21>(*this)); break; - case 22: visitor(etl::get<22>(*this)); break; - case 23: visitor(etl::get<23>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: visitor(etl::get<24>(*this)); break; - case 25: visitor(etl::get<25>(*this)); break; - case 26: visitor(etl::get<26>(*this)); break; - case 27: visitor(etl::get<27>(*this)); break; - case 28: visitor(etl::get<28>(*this)); break; - case 29: visitor(etl::get<29>(*this)); break; - case 30: visitor(etl::get<30>(*this)); break; - case 31: visitor(etl::get<31>(*this)); break; -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_operator::do_operator(*this, visitor); } //*************************************************************************** - /// Call the relevant visitor. + /// Call the relevant operator. //*************************************************************************** - template + template void do_operator(TVisitor& visitor) const { #if defined(ETL_VARIANT_CPP11_MAX_8_TYPES) @@ -1365,48 +1160,7 @@ namespace etl ETL_STATIC_ASSERT(sizeof...(TTypes) <= 32U, "A maximum of 32 types are allowed in this variant"); - switch (index()) - { - case 0: visitor(etl::get<0>(*this)); break; - case 1: visitor(etl::get<1>(*this)); break; - case 2: visitor(etl::get<2>(*this)); break; - case 3: visitor(etl::get<3>(*this)); break; - case 4: visitor(etl::get<4>(*this)); break; - case 5: visitor(etl::get<5>(*this)); break; - case 6: visitor(etl::get<6>(*this)); break; - case 7: visitor(etl::get<7>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: visitor(etl::get<8>(*this)); break; - case 9: visitor(etl::get<9>(*this)); break; - case 10: visitor(etl::get<10>(*this)); break; - case 11: visitor(etl::get<11>(*this)); break; - case 12: visitor(etl::get<12>(*this)); break; - case 13: visitor(etl::get<13>(*this)); break; - case 14: visitor(etl::get<14>(*this)); break; - case 15: visitor(etl::get<15>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: visitor(etl::get<16>(*this)); break; - case 17: visitor(etl::get<17>(*this)); break; - case 18: visitor(etl::get<18>(*this)); break; - case 19: visitor(etl::get<19>(*this)); break; - case 20: visitor(etl::get<20>(*this)); break; - case 21: visitor(etl::get<21>(*this)); break; - case 22: visitor(etl::get<22>(*this)); break; - case 23: visitor(etl::get<23>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: visitor(etl::get<24>(*this)); break; - case 25: visitor(etl::get<25>(*this)); break; - case 26: visitor(etl::get<26>(*this)); break; - case 27: visitor(etl::get<27>(*this)); break; - case 28: visitor(etl::get<28>(*this)); break; - case 29: visitor(etl::get<29>(*this)); break; - case 30: visitor(etl::get<30>(*this)); break; - case 31: visitor(etl::get<31>(*this)); break; -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_operator::do_operator(*this, visitor); } #endif @@ -1469,7 +1223,7 @@ namespace etl template ETL_CONSTEXPR14 bool holds_alternative(const etl::variant& v) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return (Index == variant_npos) ? false : (v.index() == Index); } @@ -1560,7 +1314,7 @@ namespace etl template ETL_CONSTEXPR14 T& get(etl::variant& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(v); } @@ -1569,7 +1323,7 @@ namespace etl template ETL_CONSTEXPR14 T&& get(etl::variant&& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(etl::move(v)); } @@ -1578,7 +1332,7 @@ namespace etl template ETL_CONSTEXPR14 const T& get(const etl::variant& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(v); } @@ -1587,7 +1341,7 @@ namespace etl template ETL_CONSTEXPR14 const T&& get(const etl::variant&& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(etl::move(v)); } @@ -1628,7 +1382,7 @@ namespace etl template< class T, typename... TTypes > ETL_CONSTEXPR14 etl::add_pointer_t get_if(etl::variant* pv) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; if ((pv != nullptr) && (pv->index() == Index)) { @@ -1644,7 +1398,7 @@ namespace etl template< typename T, typename... TTypes > ETL_CONSTEXPR14 etl::add_pointer_t get_if(const etl::variant* pv) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; if ((pv != nullptr) && (pv->index() == Index)) { diff --git a/include/etl/queue.h b/include/etl/queue.h index b704d8a1..99e4d50e 100644 --- a/include/etl/queue.h +++ b/include/etl/queue.h @@ -337,90 +337,107 @@ namespace etl //************************************************************************* /// Constructs a value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. + ///\param args The arguments to the constructor for the new item to push to the queue. //************************************************************************* template - void emplace(Args && ... args) + reference emplace(Args && ... args) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(etl::forward(args)...); + reference value = p_buffer[in]; + ::new (&value) T(etl::forward(args)...); add_in(); + return value; } #else //************************************************************************* - /// Constructs a value in the queue 'in place'. + /// Constructs a default constructed value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. //************************************************************************* - void emplace() + reference emplace() { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(); + reference value = p_buffer[in]; + ::new (&value) T(); add_in(); + return value; } //************************************************************************* /// Constructs a value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. + ///\param value1 The argument to use to construct the item to push to the queue. //************************************************************************* template - void emplace(const T1& value1) + reference emplace(const T1& value1) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(value1); + reference value = p_buffer[in]; + ::new (&value) T(value1); add_in(); + return value; } //************************************************************************* /// Constructs a value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. + ///\param value1 The first argument to use to construct the item to push to the queue. + ///\param value2 The second argument to use to construct the item to push to the queue. //************************************************************************* template - void emplace(const T1& value1, const T2& value2) + reference emplace(const T1& value1, const T2& value2) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(value1, value2); + reference value = p_buffer[in]; + ::new (&value) T(value1, value2); add_in(); + return value; } //************************************************************************* /// Constructs a value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. + ///\param value1 The first argument to use to construct the item to push to the queue. + ///\param value2 The second argument to use to construct the item to push to the queue. + ///\param value3 The third argument to use to construct the item to push to the queue. //************************************************************************* template - void emplace(const T1& value1, const T2& value2, const T3& value3) + reference emplace(const T1& value1, const T2& value2, const T3& value3) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(value1, value2, value3); + reference value = p_buffer[in]; + ::new (&value) T(value1, value2, value3); add_in(); + return value; } //************************************************************************* /// Constructs a value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. + ///\param value1 The first argument to use to construct the item to push to the queue. + ///\param value2 The second argument to use to construct the item to push to the queue. + ///\param value3 The third argument to use to construct the item to push to the queue. + ///\param value4 The fourth argument to use to construct the item to push to the queue. //************************************************************************* template - void emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + reference emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(value1, value2, value3, value4); + reference value = p_buffer[in]; + ::new (&value) T(value1, value2, value3, value4); add_in(); + return value; } #endif diff --git a/include/etl/queue_spsc_atomic.h b/include/etl/queue_spsc_atomic.h index d06dce2d..d7929919 100644 --- a/include/etl/queue_spsc_atomic.h +++ b/include/etl/queue_spsc_atomic.h @@ -47,13 +47,13 @@ SOFTWARE. namespace etl { - template + template class queue_spsc_atomic_base { public: /// The type used for determining the size of queue. - typedef typename etl::size_type_lookup::type size_type; + typedef typename etl::size_type_lookup::type size_type; //************************************************************************* /// Is the queue empty? @@ -72,7 +72,7 @@ namespace etl //************************************************************************* bool full() const { - size_type next_index = get_next_index(write.load(etl::memory_order_acquire), RESERVED); + size_type next_index = get_next_index(write.load(etl::memory_order_acquire), Reserved); return (next_index == read.load(etl::memory_order_acquire)); } @@ -94,7 +94,7 @@ namespace etl } else { - n = RESERVED - read_index + write_index; + n = Reserved - read_index + write_index; } return n; @@ -106,7 +106,7 @@ namespace etl //************************************************************************* size_type available() const { - return RESERVED - size() - 1; + return Reserved - size() - 1; } //************************************************************************* @@ -114,7 +114,7 @@ namespace etl //************************************************************************* size_type capacity() const { - return RESERVED - 1; + return Reserved - 1; } //************************************************************************* @@ -122,7 +122,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return RESERVED - 1; + return Reserved - 1; } protected: @@ -130,7 +130,7 @@ namespace etl queue_spsc_atomic_base(size_type reserved_) : write(0), read(0), - RESERVED(reserved_) + Reserved(reserved_) { } @@ -151,7 +151,7 @@ namespace etl etl::atomic write; ///< Where to input new data. etl::atomic read; ///< Where to get the oldest data. - const size_type RESERVED; ///< The maximum number of items in the queue. + const size_type Reserved; ///< The maximum number of items in the queue. private: @@ -182,12 +182,12 @@ namespace etl /// This queue supports concurrent access by one producer and one consumer. /// \tparam T The type of value that the queue_spsc_atomic holds. //*************************************************************************** - template - class iqueue_spsc_atomic : public queue_spsc_atomic_base + template + class iqueue_spsc_atomic : public queue_spsc_atomic_base { private: - typedef typename etl::queue_spsc_atomic_base base_t; + typedef typename etl::queue_spsc_atomic_base base_t; public: @@ -201,7 +201,7 @@ namespace etl using base_t::write; using base_t::read; - using base_t::RESERVED; + using base_t::Reserved; using base_t::get_next_index; //************************************************************************* @@ -210,7 +210,7 @@ namespace etl bool push(const_reference value) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -232,7 +232,7 @@ namespace etl bool push(rvalue_reference value) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -257,7 +257,7 @@ namespace etl bool emplace(Args&&... args) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -279,7 +279,7 @@ namespace etl bool emplace() { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -302,7 +302,7 @@ namespace etl bool emplace(const T1& value1) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -325,7 +325,7 @@ namespace etl bool emplace(const T1& value1, const T2& value2) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -348,7 +348,7 @@ namespace etl bool emplace(const T1& value1, const T2& value2, const T3& value3) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -371,7 +371,7 @@ namespace etl bool emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -418,7 +418,7 @@ namespace etl return false; } - size_type next_index = get_next_index(read_index, RESERVED); + size_type next_index = get_next_index(read_index, Reserved); #if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION) value = etl::move(p_buffer[read_index]); @@ -446,7 +446,7 @@ namespace etl return false; } - size_type next_index = get_next_index(read_index, RESERVED); + size_type next_index = get_next_index(read_index, Reserved); p_buffer[read_index].~T(); @@ -518,15 +518,15 @@ namespace etl /// A fixed capacity spsc queue. /// This queue supports concurrent access by one producer and one consumer. /// \tparam T The type this queue should support. - /// \tparam SIZE The maximum capacity of the queue. - /// \tparam MEMORY_MODEL The memory model for the queue. Determines the type of the internal counter variables. + /// \tparam Size The maximum capacity of the queue. + /// \tparam Memory_Model The memory model for the queue. Determines the type of the internal counter variables. //*************************************************************************** - template - class queue_spsc_atomic : public iqueue_spsc_atomic + template + class queue_spsc_atomic : public iqueue_spsc_atomic { private: - typedef typename etl::iqueue_spsc_atomic base_t; + typedef typename etl::iqueue_spsc_atomic base_t; public: @@ -534,19 +534,19 @@ namespace etl private: - static ETL_CONSTANT size_type RESERVED_SIZE = size_type(SIZE + 1); + static ETL_CONSTANT size_type Reserved_Size = size_type(Size + 1); public: - ETL_STATIC_ASSERT((SIZE <= (etl::integral_limits::max - 1)), "Size too large for memory model"); + ETL_STATIC_ASSERT((Size <= (etl::integral_limits::max - 1)), "Size too large for memory model"); - static ETL_CONSTANT size_type MAX_SIZE = size_type(SIZE); + static ETL_CONSTANT size_type MAX_SIZE = size_type(Size); //************************************************************************* /// Default constructor. //************************************************************************* queue_spsc_atomic() - : base_t(reinterpret_cast(&buffer[0]), RESERVED_SIZE) + : base_t(reinterpret_cast(&buffer[0]), Reserved_Size) { } @@ -561,11 +561,11 @@ namespace etl private: /// The uninitialised buffer of T used in the queue_spsc. - typename etl::aligned_storage::value>::type buffer[RESERVED_SIZE]; + typename etl::aligned_storage::value>::type buffer[Reserved_Size]; }; - template - ETL_CONSTANT typename queue_spsc_atomic::size_type queue_spsc_atomic::MAX_SIZE; + template + ETL_CONSTANT typename queue_spsc_atomic::size_type queue_spsc_atomic::MAX_SIZE; } #endif diff --git a/include/etl/queue_spsc_isr.h b/include/etl/queue_spsc_isr.h index 0e9be3f1..ed1d7542 100644 --- a/include/etl/queue_spsc_isr.h +++ b/include/etl/queue_spsc_isr.h @@ -822,8 +822,8 @@ namespace etl private: - queue_spsc_isr(const queue_spsc_isr&); - queue_spsc_isr& operator = (const queue_spsc_isr&); + queue_spsc_isr(const queue_spsc_isr&) ETL_DELETE; + queue_spsc_isr& operator = (const queue_spsc_isr&) ETL_DELETE; #if ETL_USING_CPP11 queue_spsc_isr(queue_spsc_isr&&) = delete; diff --git a/include/etl/ratio.h b/include/etl/ratio.h index f2bc38e9..4485594d 100644 --- a/include/etl/ratio.h +++ b/include/etl/ratio.h @@ -35,6 +35,8 @@ SOFTWARE. #include "static_assert.h" #include "gcd.h" +#include "type_traits.h" + #include #include @@ -138,6 +140,26 @@ namespace etl { }; +#if ETL_USING_CPP17 + template + inline constexpr bool ratio_equal_v = ratio_equal::value; + + template + inline constexpr bool ratio_not_equal_v = ratio_not_equal::value; + + template + inline constexpr bool ratio_less_v = ratio_less::value; + + template + inline constexpr bool ratio_less_equal_v = ratio_less_equal::value; + + template + inline constexpr bool ratio_greater_v = ratio_greater::value; + + template + inline constexpr bool ratio_greater_equal_v = ratio_greater_equal::value; +#endif + //*********************************************************************** /// Predefined ration types. //*********************************************************************** @@ -182,7 +204,93 @@ namespace etl typedef ratio<169, 239> ratio_1_over_root2; /// An approximation of e. - typedef ratio<106, 39> ratio_e; + typedef ratio<326, 120> ratio_e; + +#if ETL_USING_CPP11 + namespace private_ratio + { + // Primary template for GCD calculation + template + struct ratio_gcd; + + // Specialisation for the case when B is not zero + template + struct ratio_gcd + { + static constexpr T value = ratio_gcd::value; + }; + + // Specialisation for the case when B is zero + template + struct ratio_gcd + { + static constexpr T value = (A < 0) ? -A : A; + }; + + // Primary template for LCM calculation + template + struct ratio_lcm + { + private: + + static constexpr T product = ((A * B) < 0) ? -(A * B) : A * B; + + public: + + static constexpr T value = product / ratio_gcd::value; + }; + + template + struct ratio_reduce + { + private: + + static ETL_CONSTEXPR11 intmax_t gcd = etl::private_ratio::ratio_gcd::value; + + public: + + using type = ratio; + }; + + template + struct ratio_add + { + private: + + static ETL_CONSTEXPR11 intmax_t lcm = etl::private_ratio::ratio_lcm::value; + + public: + + using type = typename ratio_reduce>::type; + }; + + template + struct ratio_subtract + { + public: + using type = typename ratio_add>::type; + }; + + template + struct ratio_multiply + { + private: + static ETL_CONSTEXPR11 intmax_t gcd1 = etl::private_ratio::ratio_gcd::value; + static ETL_CONSTEXPR11 intmax_t gcd2 = etl::private_ratio::ratio_gcd::value; + + public: + using type = ratio<(R1::num / gcd1) * (R2::num / gcd2), (R1::den / gcd2) * (R2::den / gcd1)>; + }; + + template + struct ratio_divide + { + public: + using type = typename ratio_multiply>::type; + }; + } + +#endif } #endif diff --git a/include/etl/scaled_rounding.h b/include/etl/scaled_rounding.h index d8a97da3..595f8ea6 100644 --- a/include/etl/scaled_rounding.h +++ b/include/etl/scaled_rounding.h @@ -46,14 +46,13 @@ namespace etl //***************************************************************************** /// A set of rounding algorithms for scaled integrals. /// \tparam T The integral type. - /// \tparam SCALING The scaling factor. + /// \tparam Scaling The scaling factor. /// /// \example For emulating fixed point of two decimal places we could use a /// scaling factor of '100'. To round the result of scaled int calculations /// using 'Banker's Rounding' we would define this. /// \code - /// typedef etl::scaled_rounding Rounding; - /// int final_result = Rounding::round_half_even_unscaled(accumulated_result); + /// int final_result = round_half_even_unscaled<100>(accumulated_result); /// \endcode /// \link http://www.clivemaxfield.com/diycalculator/sp-round.shtml //***************************************************************************** @@ -63,19 +62,25 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_ceiling_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_ceiling_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; + if (Scaling == 1) + { + return value; + } + if (value >= 0) { - return T((value + scale_t(SCALING)) / scale_t(SCALING)); + return T((value + scale_t(Scaling - 1U)) / scale_t(Scaling)); } else { - return T(value / scale_t(SCALING)); + return T(value / scale_t(Scaling)); } } @@ -84,12 +89,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_ceiling_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_ceiling_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return round_ceiling_unscaled(value) * scale_t(SCALING); + return round_ceiling_unscaled(value) * scale_t(Scaling); } //*************************************************************************** @@ -97,19 +104,24 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_floor_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_floor_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; + if (Scaling == 1) + { + return value; + } if (value >= 0) { - return T(value / scale_t(SCALING)); + return T(value / scale_t(Scaling)); } else { - return T((value - scale_t(SCALING)) / scale_t(SCALING)); + return T((value - scale_t(Scaling - 1)) / scale_t(Scaling)); } } @@ -118,12 +130,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_floor_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_floor_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_floor_unscaled(value) * scale_t(SCALING)); + return T(round_floor_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** @@ -132,20 +146,27 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_half_up_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_up_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); - ETL_STATIC_ASSERT((((SCALING / 2U) * 2U) == SCALING), "Scaling must be divisible by 2"); typedef typename scaled_rounding_t::type scale_t; - if (value >= 0) + if (Scaling == 1) { - return T((value + scale_t(SCALING / 2U)) / scale_t(SCALING)); + return value; } else { - return T((value - scale_t(SCALING / 2U)) / scale_t(SCALING)); + if (value >= 0) + { + return T((value + scale_t(Scaling / 2U)) / scale_t(Scaling)); + } + else + { + return T((value - scale_t(Scaling / 2U)) / scale_t(Scaling)); + } } } @@ -155,12 +176,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_half_up_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_up_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_half_up_unscaled(value) * scale_t(SCALING)); + return T(round_half_up_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** @@ -169,20 +192,25 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_half_down_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_down_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); - ETL_STATIC_ASSERT((((SCALING / 2U) * 2U) == SCALING), "Scaling must be divisible by 2"); typedef typename scaled_rounding_t::type scale_t; + if (Scaling == 1) + { + return value; + } + if (value >= 0) { - return T((value + scale_t((SCALING / 2U) - 1U)) / scale_t(SCALING)); + return T((value + scale_t((Scaling - 1) / 2U)) / scale_t(Scaling)); } else { - return T((value - scale_t((SCALING / 2U) - 1U)) / scale_t(SCALING)); + return T((value - scale_t((Scaling - 1) / 2U)) / scale_t(Scaling)); } } @@ -192,12 +220,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_half_down_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_down_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_half_down_unscaled(value) * scale_t(SCALING)); + return T(round_half_down_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** @@ -205,13 +235,21 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_zero_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_zero_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; - return T(value / scale_t(SCALING)); + if (Scaling == 1) + { + return value; + } + else + { + return T(value / scale_t(Scaling)); + } } //*************************************************************************** @@ -219,46 +257,49 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_zero_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_zero_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_zero_unscaled(value) * scale_t(SCALING)); + return T(round_zero_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** - /// Round toward infinity. + /// Round twords infinity or away from zero. /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_infinity_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_infinity_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); - typedef typename scaled_rounding_t::type scale_t; - if (value >= 0) { - return T((value + scale_t(SCALING)) / scale_t(SCALING)); + return etl::round_ceiling_unscaled(value); } else { - return T((value - scale_t(SCALING)) / scale_t(SCALING)); + return etl::round_floor_unscaled(value); } } //*************************************************************************** - /// Round toward infinity. + /// Round twords infinity or away from zero. /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_infinity_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_infinity_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_infinity_unscaled(value) * scale_t(SCALING)); + return T(round_infinity_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** @@ -267,28 +308,36 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_half_even_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_even_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; - // Half? - if ((etl::absolute(value) % scale_t(SCALING)) == scale_t(SCALING / 2U)) + if (Scaling == 1) { - // Odd? - if ((value / scale_t(SCALING)) & 1U) - { - return T(round_half_up_unscaled(value)); - } - else - { - return T(round_half_down_unscaled(value)); - } + return value; } else { - return T(round_half_up_unscaled(value)); + // Half? + if ((etl::absolute(value) % scale_t(Scaling)) == scale_t(Scaling / 2U)) + { + // Odd? + if ((value / scale_t(Scaling)) & 1U) + { + return T(round_half_up_unscaled(value)); + } + else + { + return T(round_half_down_unscaled(value)); + } + } + else + { + return T(round_half_up_unscaled(value)); + } } } @@ -298,12 +347,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_half_even_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_even_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_half_even_unscaled(value) * scale_t(SCALING)); + return T(round_half_even_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** @@ -312,28 +363,36 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_half_odd_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_odd_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; - // Half? - if ((etl::absolute(value) % scale_t(SCALING)) == scale_t(SCALING / 2U)) + if (Scaling == 1) { - // Odd? - if ((value / scale_t(SCALING)) & 1U) - { - return T(round_half_down_unscaled(value)); - } - else - { - return T(round_half_up_unscaled(value)); - } + return value; } else { - return T(round_half_up_unscaled(value)); + // Half? + if ((etl::absolute(value) % scale_t(Scaling)) == scale_t(Scaling / 2U)) + { + // Odd? + if ((value / scale_t(Scaling)) & 1U) + { + return T(round_half_down_unscaled(value)); + } + else + { + return T(round_half_up_unscaled(value)); + } + } + else + { + return T(round_half_up_unscaled(value)); + } } } @@ -343,12 +402,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_half_odd_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_odd_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_half_odd_unscaled(value) * scale_t(SCALING)); + return T(round_half_odd_unscaled(value) * scale_t(Scaling)); } } diff --git a/include/etl/singleton_base.h b/include/etl/singleton_base.h new file mode 100644 index 00000000..eb9653b4 --- /dev/null +++ b/include/etl/singleton_base.h @@ -0,0 +1,172 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2019 John Wellbelove +Copyright(c) 2024 BMW AG + +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_SINGLETON_BASE_INCLUDED +#define ETL_SINGLETON_BASE_INCLUDED + +///\defgroup singleton_base singleton_base +/// Templated version of the singleton pattern, implemented as base class +/// for singletons. +///\ingroup etl + +#include "platform.h" +#include "error_handler.h" +#include "nullptr.h" +#include "file_error_numbers.h" + +namespace etl +{ + //************************************************************************* + /// Base singleton error exception. + //************************************************************************* + class singleton_base_exception : public etl::exception + { + public: + + singleton_base_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + //************************************************************************* + /// Singleton not created error exception. + //************************************************************************* + class singleton_base_not_created : public etl::singleton_base_exception + { + public: + + singleton_base_not_created(string_type file_name_, numeric_type line_number_) + : singleton_base_exception(ETL_ERROR_TEXT("singleton_base:not created", ETL_SINGLETON_BASE_FILE_ID"A"), file_name_, line_number_) + { + } + }; + + //************************************************************************* + /// Singleton instance already exists. + //************************************************************************* + class singleton_base_already_created : public etl::singleton_base_exception + { + public: + + singleton_base_already_created(string_type file_name_, numeric_type line_number_) + : singleton_base_exception(ETL_ERROR_TEXT("singleton_base:already created", ETL_SINGLETON_BASE_FILE_ID"A"), file_name_, line_number_) + { + } + }; + + //*********************************************************************** + /// Base class for singletons. + /// \tparam T Any type that wants to expose the instance() interface. + /// + /// This class is designed to work as a generic base class for any class that wants to + /// provide a singleton interface. It'll also work for classes that do not have a + /// default constructor. + /// + /// Usage example: + /// + /// class Origin + /// : singleton + /// { + /// public: + /// Origin(int x, int y) + /// : singleton(*this) + /// {} + /// + /// int getX() const; + /// } theOrigin(0, 0); + /// + /// int x = Origin::instance().getX(); + /// + /// + /// Note: + /// + /// It is important that a call to instance() will not create the instance of the class. It needs + /// to be created by the user before calling instance(). This way, the user has better control + /// over the instance lifetime instead of e.g. lazy initialization. + //*********************************************************************** + template + class singleton_base + { + public: + + //*********************************************************************** + // Returns a reference to the instance. + //*********************************************************************** + static T& instance() + { + ETL_ASSERT(m_self != ETL_NULLPTR, ETL_ERROR(etl::singleton_base_not_created)); + + return *m_self; + } + + //*********************************************************************** + /// Returns whether an instance has been attached to singleton or not. + //*********************************************************************** + static bool is_valid() + { + return (m_self != ETL_NULLPTR); + } + + protected: + + //*********************************************************************** + /// Constructs the instance of singleton. + /// theInstance Reference to T, which will be returned when instance() is called. + //*********************************************************************** + explicit singleton_base(T& theInstance) + { + ETL_ASSERT(m_self == ETL_NULLPTR, ETL_ERROR(etl::singleton_base_already_created)); + + m_self = &theInstance; + } + + //*********************************************************************** + /// Removes the internal reference to the instance passed in the constructor. + //*********************************************************************** + ~singleton_base() + { + m_self = ETL_NULLPTR; + } + + private: + + static T* m_self; + }; + + //*********************************************************************** + /// No violation of one definition rule as this is a class template + //*********************************************************************** + template + T* singleton_base::m_self = ETL_NULLPTR; +} + +#endif diff --git a/include/etl/span.h b/include/etl/span.h index f1077ea7..5e364b23 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -32,6 +32,10 @@ SOFTWARE. #define ETL_SPAN_INCLUDED #include "platform.h" + +#include "error_handler.h" +#include "exception.h" +#include "alignment.h" #include "iterator.h" #include "algorithm.h" #include "circular_iterator.h" @@ -46,20 +50,63 @@ SOFTWARE. #include "private/dynamic_extent.h" -#if ETL_USING_CPP20 && ETL_USING_STL - #include -#endif - ///\defgroup span span ///\ingroup containers namespace etl { + //*************************************************************************** + // Tag to indicate a class is a span. + //*************************************************************************** + class span_tag {}; + + //*************************************************************************** + ///\ingroup span + /// Exception base for span + //*************************************************************************** + class span_exception : public exception + { + public: + + span_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + //*************************************************************************** + ///\ingroup span + /// Bad alignment exception. + //*************************************************************************** + class span_alignment_exception : public span_exception + { + public: + + span_alignment_exception(string_type file_name_, numeric_type line_number_) + : span_exception(ETL_ERROR_TEXT("span:alignment", ETL_SPAN_FILE_ID"A"), file_name_, line_number_) + { + } + }; + + //*************************************************************************** + ///\ingroup span + /// span size exception. + //*************************************************************************** + class span_size_mismatch : public span_exception + { + public: + + span_size_mismatch(string_type file_name_, numeric_type line_number_) + : span_exception(ETL_ERROR_TEXT("span:size", ETL_SPAN_FILE_ID"B"), file_name_, line_number_) + { + } + }; + //*************************************************************************** /// Span - Fixed Extent //*************************************************************************** template - class span + class span : public span_tag { public: @@ -71,8 +118,10 @@ namespace etl typedef T* pointer; typedef const T* const_pointer; - typedef T* iterator; - typedef ETL_OR_STD::reverse_iterator reverse_iterator; + typedef T* iterator; + typedef const T* const_iterator; + typedef ETL_OR_STD::reverse_iterator reverse_iterator; + typedef ETL_OR_STD::reverse_iterator const_reverse_iterator; typedef etl::circular_iterator circular_iterator; typedef etl::circular_iterator > reverse_circular_iterator; @@ -84,7 +133,7 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR explicit span(const TIterator begin_, const TSize /*size_*/) ETL_NOEXCEPT - : pbegin(etl::addressof(*begin_)) + : pbegin(etl::to_address(begin_)) { } @@ -93,28 +142,40 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR explicit span(const TIterator begin_, const TIterator /*end_*/) - : pbegin(etl::addressof(*begin_)) + : pbegin(etl::to_address(begin_)) { } //************************************************************************* /// Construct from C array //************************************************************************* - template +#if ETL_USING_CPP11 + template::type> ETL_CONSTEXPR span(element_type(&begin_)[Array_Size]) ETL_NOEXCEPT : pbegin(begin_) { } +#else + //************************************************************************* + /// Construct from C array + //************************************************************************* + template + ETL_CONSTEXPR span(element_type(&begin_)[Array_Size], typename etl::enable_if<(Array_Size == Extent), void>::type* = 0) ETL_NOEXCEPT + : pbegin(begin_) + { + } +#endif #if ETL_USING_CPP11 //************************************************************************* /// Construct from a container or other type that supports /// data() and size() member functions. //************************************************************************* - template >::value && + template >::value && + !etl::is_pointer>::value && !etl::is_array>::value&& etl::is_same, etl::remove_cv_t::value_type>>::value, void>::type> - ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT + ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT : pbegin(a.data()) { } @@ -124,7 +185,8 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - span(TContainer& a, typename etl::enable_if::type>::value && + span(TContainer& a, typename etl::enable_if::type>::value && + !etl::is_pointer::type>::value && !etl::is_array::value && etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) @@ -136,9 +198,10 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - ETL_CONSTEXPR span(const TContainer& a, typename etl::enable_if::type>::value && - !etl::is_array::value&& - etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT + span(const TContainer& a, typename etl::enable_if::type>::value && + !etl::is_pointer::type>::value && + !etl::is_array::value&& + etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) { } @@ -154,13 +217,25 @@ namespace etl //************************************************************************* /// Copy constructor + /// From fixed extent span. //************************************************************************* template - ETL_CONSTEXPR span(const etl::span& other, typename etl::enable_if<(Extent == etl::dynamic_extent) || (N == etl::dynamic_extent) || (N == Extent), void>::type) ETL_NOEXCEPT + ETL_CONSTEXPR span(const etl::span& other, typename etl::enable_if::type* = 0) ETL_NOEXCEPT : pbegin(other.data()) { } + //************************************************************************* + /// Copy constructor + /// From dynamic extent span. + //************************************************************************* + template + ETL_CONSTEXPR14 span(const etl::span& other, typename etl::enable_if::type* = 0) + : pbegin(other.data()) + { + ETL_ASSERT(other.size() == Extent, ETL_ERROR(span_size_mismatch)); + } + //************************************************************************* /// Returns a reference to the first element. //************************************************************************* @@ -185,6 +260,14 @@ namespace etl return pbegin; } + //************************************************************************* + /// Returns a const iterator to the beginning of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT + { + return pbegin; + } + //************************************************************************* /// Returns an iterator to the beginning of the span. //************************************************************************* @@ -201,6 +284,14 @@ namespace etl return circular_iterator(begin(), end()); } + //************************************************************************* + /// Returns a const iterator to the end of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT + { + return (pbegin + Extent); + } + //************************************************************************* /// Returns an iterator to the end of the span. //************************************************************************* @@ -209,6 +300,14 @@ namespace etl return (pbegin + Extent); } + //************************************************************************* + // Returns a const reverse iterator to the reverse beginning of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT + { + return const_reverse_iterator((pbegin + Extent)); + } + //************************************************************************* // Returns an reverse iterator to the reverse beginning of the span. //************************************************************************* @@ -225,6 +324,14 @@ namespace etl return reverse_circular_iterator(rbegin(), rend()); } + //************************************************************************* + /// Returns a const reverse iterator to the end of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT + { + return const_reverse_iterator(pbegin); + } + //************************************************************************* /// Returns a reverse iterator to the end of the span. //************************************************************************* @@ -238,7 +345,7 @@ namespace etl //************************************************************************* ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT { - return false; + return Extent == 0; } //************************************************************************* @@ -272,6 +379,26 @@ namespace etl { pbegin = other.pbegin; return *this; + } + + //************************************************************************* + /// Returns a reference to the value at index 'i'. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t i) + { + ETL_ASSERT(i < size(), ETL_ERROR(array_out_of_range)); + + return pbegin[i]; + } + + //************************************************************************* + /// Returns a const reference to the value at index 'i'. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t i) const + { + ETL_ASSERT(i < size(), ETL_ERROR(array_out_of_range)); + + return pbegin[i]; } //************************************************************************* @@ -328,14 +455,14 @@ namespace etl //************************************************************************* template ETL_NODISCARD ETL_CONSTEXPR - etl::span subspan() const ETL_NOEXCEPT + etl::span subspan() const ETL_NOEXCEPT { // If Extent is static, check that OFFSET is within the original span ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) ? OFFSET <= Extent : true, "OFFSET is not within the original span"); // If count is also static, check that OFFSET + COUNT is within the original span ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (Extent - OFFSET) : true, "OFFSET + COUNT is not within the original span"); - + return (COUNT == etl::dynamic_extent) ? etl::span(pbegin + OFFSET, (pbegin + Extent)) : etl::span(pbegin + OFFSET, pbegin + OFFSET + COUNT); } @@ -351,7 +478,7 @@ namespace etl // If count is also static, check that OFFSET + COUNT is within the original span ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (Extent - OFFSET) : true, "OFFSET + COUNT is not within the original span"); - + if (COUNT == etl::dynamic_extent) { return etl::span(pbegin + OFFSET, (pbegin + Extent)); @@ -372,16 +499,48 @@ namespace etl : etl::span(pbegin + offset, pbegin + offset + count); } + //************************************************************************* + /// Moves the pointer to the first element of the span further by a specified number of elements. + ///\tparam elements Number of elements to move forward + //************************************************************************* + void advance(size_t elements) ETL_NOEXCEPT + { + elements = etl::min(elements, size()); + pbegin += elements; + } + + //************************************************************************* + /// Reinterpret the span as a span with different element type. + //************************************************************************* + template + ETL_NODISCARD ETL_CONSTEXPR14 etl::span reinterpret_as() const + { + ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); + + return etl::span(reinterpret_cast(pbegin), + Extent * sizeof(element_type) / sizeof(TNew)); + } + private: pointer pbegin; }; + //************************************************************************* + /// Pseudo constructor for constructing from C array without explicitly + /// specifying type and size + //************************************************************************* + template + ETL_CONSTEXPR span make_span(T (&data)[Extent]) + { + return span(data); + } + //*************************************************************************** /// Span - Dynamic Extent //*************************************************************************** template - class span + class span : public span_tag { public: @@ -392,9 +551,11 @@ namespace etl typedef const T& const_reference; typedef T* pointer; typedef const T* const_pointer; - - typedef T* iterator; - typedef ETL_OR_STD::reverse_iterator reverse_iterator; + + typedef T* iterator; + typedef const T* const_iterator; + typedef ETL_OR_STD::reverse_iterator reverse_iterator; + typedef ETL_OR_STD::reverse_iterator const_reverse_iterator; typedef etl::circular_iterator circular_iterator; typedef etl::circular_iterator > reverse_circular_iterator; @@ -415,8 +576,8 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR span(const TIterator begin_, const TSize size_) ETL_NOEXCEPT - : pbegin(etl::addressof(*begin_)) - , pend(etl::addressof(*begin_) + size_) + : pbegin(etl::to_address(begin_)) + , pend(etl::to_address(begin_) + size_) { } @@ -425,8 +586,8 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR span(const TIterator begin_, const TIterator end_) - : pbegin(etl::addressof(*begin_)) - , pend(etl::addressof(*begin_) + etl::distance(begin_, end_)) + : pbegin(etl::to_address(begin_)) + , pend(etl::to_address(begin_) + etl::distance(begin_, end_)) { } @@ -445,10 +606,11 @@ namespace etl /// Construct from a container or other type that supports /// data() and size() member functions. //************************************************************************* - template >::value && + template >::value && + !etl::is_pointer>::value && !etl::is_array>::value && etl::is_same, etl::remove_cv_t::value_type>>::value, void>::type> - ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT + ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT : pbegin(a.data()) , pend(a.data() + a.size()) { @@ -459,7 +621,8 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - ETL_CONSTEXPR span(TContainer& a, typename etl::enable_if::type>::value && + ETL_CONSTEXPR span(TContainer& a, typename etl::enable_if::type>::value && + !etl::is_pointer::type>::value && !etl::is_array::value && etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) @@ -472,7 +635,8 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - ETL_CONSTEXPR span(const TContainer& a, typename etl::enable_if::type>::value && + ETL_CONSTEXPR span(const TContainer& a, typename etl::enable_if::type>::value && + !etl::is_pointer::type>::value && !etl::is_array::value && etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) @@ -524,6 +688,14 @@ namespace etl return pbegin; } + //************************************************************************* + /// Returns a const iterator to the beginning of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT + { + return pbegin; + } + //************************************************************************* /// Returns an iterator to the beginning of the span. //************************************************************************* @@ -540,6 +712,14 @@ namespace etl return circular_iterator(begin(), end()); } + //************************************************************************* + /// Returns a const iterator to the end of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT + { + return pend; + } + //************************************************************************* /// Returns an iterator to the end of the span. //************************************************************************* @@ -556,6 +736,14 @@ namespace etl return reverse_iterator(pend); } + //************************************************************************* + // Returns a const reverse iterator to the reverse beginning of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT + { + return const_reverse_iterator(pend); + } + //************************************************************************* /// Returns a reverse circular iterator to the end of the span. //************************************************************************* @@ -564,6 +752,14 @@ namespace etl return reverse_circular_iterator(rbegin(), rend()); } + //************************************************************************* + /// Returns a const reverse iterator to the end of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT + { + return const_reverse_iterator(pbegin); + } + //************************************************************************* /// Returns a reverse iterator to the end of the span. //************************************************************************* @@ -614,6 +810,26 @@ namespace etl return *this; } + //************************************************************************* + /// Returns a reference to the value at index 'i'. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t i) + { + ETL_ASSERT(i < size(), ETL_ERROR(array_out_of_range)); + + return pbegin[i]; + } + + //************************************************************************* + /// Returns a const reference to the value at index 'i'. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t i) const + { + ETL_ASSERT(i < size(), ETL_ERROR(array_out_of_range)); + + return pbegin[i]; + } + //************************************************************************* /// Returns a reference to the indexed value. //************************************************************************* @@ -662,7 +878,7 @@ namespace etl //************************************************************************* template ETL_NODISCARD ETL_CONSTEXPR - etl::span subspan() const ETL_NOEXCEPT + etl::span subspan() const ETL_NOEXCEPT { return (COUNT == etl::dynamic_extent) ? etl::span(pbegin + OFFSET, pend) : etl::span(pbegin + OFFSET, pbegin + OFFSET + COUNT); @@ -694,12 +910,54 @@ namespace etl : etl::span(pbegin + offset, pbegin + offset + count); } + //************************************************************************* + /// Moves the pointer to the first element of the span further by a specified number of elements. + ///\tparam elements Number of elements to move forward + //************************************************************************* + void advance(size_t elements) ETL_NOEXCEPT + { + elements = etl::min(elements, size()); + pbegin += elements; + } + + //************************************************************************* + /// Reinterpret the span as a span with different element type. + //************************************************************************* + template + ETL_NODISCARD ETL_CONSTEXPR14 etl::span reinterpret_as() const + { + ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); + + return etl::span(reinterpret_cast(pbegin), + (pend - pbegin) * sizeof(element_type) / sizeof(TNew)); + } + private: pointer pbegin; pointer pend; }; + //************************************************************************* + /// Pseudo constructor for constructing from container without explicitly + /// specifying type and size + //************************************************************************* + template + ETL_CONSTEXPR span make_span(T& data) + { + return span(data); + } + + //************************************************************************* + /// Pseudo constructor for constructing from const container without + /// explicitly specifying type and size + //************************************************************************* + template + ETL_CONSTEXPR span make_span(const T& data) + { + return span(data); + } + template ETL_CONSTANT size_t span::extent; @@ -746,6 +1004,33 @@ namespace etl etl::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } + //************************************************************************* + /// Copy complete element data from one span to another. If the destination + /// span is bigger than the source span, only the initial part of + /// destination span is overwritten. + ///\param src Source + ///\param dst Destination + ///\return true, if copy was successful (including empty source span, or + /// spans pointing to the same address) + ///\return false, if the destination span is shorter than the source span. + //************************************************************************* + template + typename etl::enable_if::type, typename etl::remove_cv::type>::value && + !etl::is_const::value, bool>::type + copy(const etl::span& src, const etl::span& dst) + { + if (src.empty() || (src.begin() == dst.begin())) + { + return true; + } + if (src.size() > dst.size()) + { + return false; + } + (void) etl::copy(src.begin(), src.end(), dst.begin()); + return true; + } + //************************************************************************* /// Template deduction guides. //************************************************************************* @@ -818,4 +1103,4 @@ namespace etl } } -#endif +#endif \ No newline at end of file diff --git a/include/etl/stack.h b/include/etl/stack.h index a292218a..1c375906 100644 --- a/include/etl/stack.h +++ b/include/etl/stack.h @@ -283,13 +283,15 @@ namespace etl ///\param value The value to push to the stack. //************************************************************************* template - void emplace(Args && ... args) + reference emplace(Args && ... args) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(etl::forward(args)...); + + return p_buffer[top_index]; } #else //************************************************************************* @@ -297,13 +299,15 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::stack_full if the stack is already full. ///\param value The value to push to the stack. //************************************************************************* - void emplace() + reference emplace() { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(); + + return p_buffer[top_index]; } //************************************************************************* @@ -312,13 +316,15 @@ namespace etl ///\param value The value to push to the stack. //************************************************************************* template - void emplace(const T1& value1) + reference emplace(const T1& value1) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(value1); + + return p_buffer[top_index]; } //************************************************************************* @@ -327,13 +333,15 @@ namespace etl ///\param value The value to push to the stack. //************************************************************************* template - void emplace(const T1& value1, const T2& value2) + reference emplace(const T1& value1, const T2& value2) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(value1, value2); + + return p_buffer[top_index]; } //************************************************************************* @@ -342,13 +350,15 @@ namespace etl ///\param value The value to push to the stack. //************************************************************************* template - void emplace(const T1& value1, const T2& value2, const T3& value3) + reference emplace(const T1& value1, const T2& value2, const T3& value3) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(value1, value2, value3); + + return p_buffer[top_index]; } //************************************************************************* @@ -357,13 +367,15 @@ namespace etl ///\param value The value to push to the stack. //************************************************************************* template - void emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + reference emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(value1, value2, value3, value4); + + return p_buffer[top_index]; } #endif diff --git a/include/etl/string.h b/include/etl/string.h index 1fbc19d2..3c74ef46 100644 --- a/include/etl/string.h +++ b/include/etl/string.h @@ -48,7 +48,7 @@ namespace etl { inline namespace string_literals { - constexpr etl::string_view operator ""_sv(const char* str, size_t length) noexcept + inline constexpr etl::string_view operator ""_sv(const char* str, size_t length) noexcept { return etl::string_view{ str, length }; } @@ -72,6 +72,7 @@ namespace etl typedef istring interface_type; typedef istring::value_type value_type; + typedef istring::size_type size_type; static ETL_CONSTANT size_t MAX_SIZE = MAX_SIZE_; @@ -243,6 +244,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const etl::string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -261,7 +272,7 @@ namespace etl }; template - ETL_CONSTANT size_t string::MAX_SIZE; + ETL_CONSTANT typename string::size_type string::MAX_SIZE; //*************************************************************************** /// A string implementation that uses a fixed size external buffer. @@ -361,6 +372,16 @@ namespace etl this->resize(count, c); } + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit string_ext(const etl::string_view& view, value_type* buffer, size_type buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(view.begin(), view.end()); + } + //************************************************************************* /// Constructor, from an iterator range. ///\tparam TIterator The iterator type. @@ -385,16 +406,6 @@ namespace etl } #endif - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit string_ext(const etl::string_view& view, value_type* buffer, size_type buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->assign(view.begin(), view.end()); - } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -408,7 +419,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -432,6 +442,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string_ext& operator = (const etl::string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 7ddce503..8421068e 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -43,6 +43,14 @@ SOFTWARE. #include "algorithm.h" #include "private/minmax_push.h" +#if ETL_USING_STL && ETL_USING_CPP17 + #include +#endif + +#if ETL_USING_STL + #include +#endif + #include namespace etl @@ -96,9 +104,9 @@ namespace etl { public: - typedef T value_type; - typedef TTraits traits_type; - typedef size_t size_type; + typedef T value_type; + typedef TTraits traits_type; + typedef size_t size_type; typedef const T& const_reference; typedef const T* const_pointer; typedef const T* const_iterator; @@ -366,7 +374,7 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 basic_string_view substr(size_type position = 0, size_type count = npos) const { - basic_string_view view; + basic_string_view view = basic_string_view(); if (position < size()) { @@ -408,20 +416,48 @@ namespace etl } ETL_CONSTEXPR14 int compare(size_type position1, size_type count1, - basic_string_view view, - size_type position2, size_type count2) const + basic_string_view view, + size_type position2, size_type count2) const { return substr(position1, count1).compare(view.substr(position2, count2)); } ETL_CONSTEXPR14 int compare(const T* text) const { - return compare(etl::basic_string_view(text)); + const T* view_itr = mbegin; + const T* text_itr = text; + + while (view_itr != mend && *text_itr != T(0)) + { + if (*view_itr < *text_itr) + { + return -1; + } + else if (*view_itr > *text_itr) + { + return 1; + } + ++view_itr; + ++text_itr; + } + + if ((view_itr == mend) && (*text_itr == T(0))) + { + return 0; + } + else if (view_itr == mend) + { + return -1; + } + else + { + return 1; + } } ETL_CONSTEXPR14 int compare(size_type position, size_type count, const T* text) const { - return substr(position, count).compare(etl::basic_string_view(text)); + return substr(position, count).compare(text); } ETL_CONSTEXPR14 int compare(size_type position, size_type count1, const T* text, size_type count2) const @@ -435,7 +471,7 @@ namespace etl ETL_CONSTEXPR14 bool starts_with(etl::basic_string_view view) const { return (size() >= view.size()) && - (compare(0, view.size(), view) == 0); + (compare(0, view.size(), view) == 0); } ETL_CONSTEXPR14 bool starts_with(T c) const @@ -448,7 +484,7 @@ namespace etl size_t lengthtext = TTraits::length(text); return (size() >= lengthtext) && - (compare(0, lengthtext, text) == 0); + (compare(0, lengthtext, text) == 0); } //************************************************************************* @@ -457,7 +493,7 @@ namespace etl ETL_CONSTEXPR14 bool ends_with(etl::basic_string_view view) const { return (size() >= view.size()) && - (compare(size() - view.size(), npos, view) == 0); + (compare(size() - view.size(), npos, view) == 0); } ETL_CONSTEXPR14 bool ends_with(T c) const @@ -471,7 +507,7 @@ namespace etl size_t lengthview = size(); return (lengthview >= lengthtext) && - (compare(lengthview - lengthtext, lengthtext, text) == 0); + (compare(lengthview - lengthtext, lengthtext, text) == 0); } //************************************************************************* @@ -747,6 +783,30 @@ namespace etl return find_last_not_of(etl::basic_string_view(text), position); } + //********************************************************************* + /// Checks that the view is within this string + //********************************************************************* + bool contains(const etl::basic_string_view& view) const + { + return find(view) != npos; + } + + //********************************************************************* + /// Checks that text is within this string + //********************************************************************* + bool contains(const_pointer s) const + { + return find(s) != npos; + } + + //********************************************************************* + /// Checks that character is within this string + //********************************************************************* + bool contains(value_type c) const + { + return find(c) != npos; + } + //************************************************************************* /// Equality for string_view. //************************************************************************* @@ -916,6 +976,19 @@ void swap(etl::basic_string_view >& lhs, etl::basic_strin lhs.swap(rhs); } +//************************************************************************* +/// Operator overload to write to std basic_ostream +//************************************************************************* +#if ETL_USING_STL +template +std::basic_ostream > &operator<<(std::basic_ostream > &os, + etl::basic_string_view > text) +{ + os.write(text.data(), text.size()); + return os; +} +#endif + #include "private/minmax_pop.h" #endif diff --git a/include/etl/tuple.h b/include/etl/tuple.h new file mode 100644 index 00000000..2b15e017 --- /dev/null +++ b/include/etl/tuple.h @@ -0,0 +1,1259 @@ +#pragma once + +#if ETL_USING_STL + #include +#endif + +#include "etl/nth_type.h" +#include "etl/type_traits.h" +#include "etl/utility.h" +#include "etl/functional.h" + +#include "etl/private/tuple_element.h" +#include "etl/private/tuple_size.h" + +namespace etl +{ + //*************************************************************************** + /// A tuple type + /// etl::tuple + //*************************************************************************** + template + class tuple; + + //*************************************************************************** + /// Type trait to check if a type is an etl::tuple + /// Default implementation. + //*************************************************************************** + template + struct is_tuple : etl::false_type + { + }; + + //*************************************************************************** + /// Type trait to check if a type is an etl::tuple + /// Specialisation for etl::tuple + //*************************************************************************** + template + struct is_tuple> : etl::true_type + { + }; + + namespace private_tuple + { + //*************************************************************************** + /// Get the base of a tuple type whose head type is T. + //*************************************************************************** + template + struct tuple_type_base; + + // Specialisation for an empty tuple + template + struct tuple_type_base> + { + using type = void; + }; + + // Recursive definition of the type. + template + struct tuple_type_base> + { + using type = etl::conditional_t::value, + tuple, + typename tuple_type_base>::type>; + }; + + // Get the base of a tuple type whose head type is T. + template + using tuple_type_base_t = typename tuple_type_base::type; + + //*************************************************************************** + /// ignore + /// An object of unspecified type such that any value can be assigned to it with no effect. + /// Intended for use with etl::tie when unpacking a etl::tuple, as a placeholder for the arguments that are not used. + /// https://en.cppreference.com/w/cpp/utility/tuple/ignore + //*************************************************************************** + struct ignore_t + { + template + ETL_CONSTEXPR ignore_t operator =(T&&) const ETL_NOEXCEPT + { + return *this; + } + }; + } + + //*************************************************************************** + /// Empty tuple + //*************************************************************************** + template<> + class tuple<> + { + public: + + using value_type = void; ///< The type contained by this tuple. + using this_type = tuple<>; ///< The type of this tuple. + using base_type = void; ///< The type of the base tuple. + using index_sequence_type = etl::make_index_sequence<0>; ///< The index_sequence type for this tuple. + + //********************************* + // No-op copy_assignment for the base case + //********************************* + ETL_CONSTEXPR14 + void copy_assignment(const this_type& /*other*/) + { + } + + //********************************* + // No-op forward_assignment for the base case + //********************************* + ETL_CONSTEXPR14 + void forward_assignment(this_type&& /*other*/) + { + } + + //********************************* + // No-op swap for the base case + //********************************* + ETL_CONSTEXPR14 + void swap(this_type& /*other*/) + { + } + + //********************************* + // Returns the size of the base case. + // Always zero. + //********************************* + ETL_NODISCARD + ETL_CONSTEXPR + static size_t size() + { + return 0U; + } + }; + + //*************************************************************************** + /// Tuple + //*************************************************************************** + template + class tuple : public tuple + { + private: + + //********************************* + /// Helper function to calculate the number + /// of types from a type list. + //********************************* + template + static constexpr size_t number_of_types() + { + return sizeof...(UTypes); + } + + public: + + //********************************* + /// Friends + //********************************* + template + friend class tuple; + + template + ETL_CONSTEXPR14 + friend etl::tuple_element_t>& get(tuple&); + + template + ETL_CONSTEXPR14 + friend etl::tuple_element_t>&& get(tuple&&); + + template + ETL_CONSTEXPR14 + friend const etl::tuple_element_t>& get(const tuple&); + + template + ETL_CONSTEXPR14 + friend const etl::tuple_element_t>&& get(const tuple&&); + + template + ETL_CONSTEXPR14 + friend T& get(tuple&); + + template + ETL_CONSTEXPR14 + friend T&& get(tuple&&); + + template + ETL_CONSTEXPR14 + friend const T& get(const tuple&); + + template + ETL_CONSTEXPR14 + friend const T&& get(const tuple&&); + + //********************************* + /// Types + //********************************* + using value_type = THead; ///< The type contained by this tuple. + using this_type = tuple; ///< The type of this tuple. + using base_type = tuple; ///< The type of the base tuple. + using index_sequence_type = etl::make_index_sequence()>; ///< The index_sequence type for this tuple. + + //********************************* + /// Default constructor. + //********************************* + ETL_CONSTEXPR14 + tuple() + : value(THead()) + { + } + + //********************************* + /// Copy constructor. + //********************************* + ETL_CONSTEXPR14 + tuple(const tuple& other) = default; + + //********************************* + /// Move constructor. + //********************************* + ETL_CONSTEXPR14 + tuple(tuple&& other) = default; + + //********************************* + /// Copy assignment. + //********************************* + ETL_CONSTEXPR14 + tuple& operator =(const tuple& other) = default; + + //********************************* + /// Move assignment. + //********************************* + ETL_CONSTEXPR14 + tuple& operator =(tuple&& other) = default; + + //********************************* + /// Copy construct from lvalue reference tuple type. + /// Implicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(tuple& other) + : base_type(other.get_base()) + , value(other.get_value()) + { + } + + //********************************* + /// Copy construct from lvalue reference tuple type. + /// Explicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + !etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + explicit tuple(tuple& other) + : base_type(other.get_base()) + , value(other.get_value()) + { + } + + //********************************* + /// Copy construct from const lvalue reference tuple type. + /// Implicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(const tuple& other) + : base_type(other.get_base()) + , value(other.get_value()) + { + } + + //********************************* + /// Copy construct from const lvalue reference tuple type. + /// Explicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + !etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + explicit tuple(const tuple& other) + : base_type(other.get_base()) + , value(other.get_value()) + { + } + + //********************************* + /// Move construct from rvalue reference tuple type. + /// Implicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(tuple&& other) + : base_type(etl::forward>(other.get_base())) + , value(etl::forward(other.get_value())) + { + } + + //********************************* + /// Move construct from rvalue reference tuple type. + /// Explicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + !etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + explicit tuple(tuple&& other) + : base_type(etl::forward>(other.get_base())) + , value(etl::forward(other.get_value())) + { + } + + //********************************* + /// Construct from const rvalue reference tuple type. + /// Implicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(const tuple&& other) + : base_type(etl::forward>(other.get_base())) + , value(etl::forward(other.get_value())) + { + } + + //********************************* + /// Construct from const rvalue reference tuple type. + /// Explicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + !etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + explicit tuple(const tuple&& other) + : base_type(etl::forward>(other.get_base())) + , value(etl::forward(other.get_value())) + { + } + + //********************************* + /// Construct from arguments. + //********************************* + ETL_CONSTEXPR14 + tuple(const THead& head, const TTail&... tail) + : base_type(tail...) + , value(head) + { + } + + //********************************* + /// Construct from arguments. + /// Implicit conversion. + //********************************* + template >::value && + (number_of_types() == number_of_types()) && + (number_of_types() >= 1U) && + etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(UHead&& head, UTail&&... tail) ETL_NOEXCEPT + : base_type(etl::forward(tail)...) + , value(etl::forward(head)) + { + } + + //********************************* + /// Construct from arguments. + /// explicit conversion. + //********************************* + template >::value && + (number_of_types() == number_of_types()) && + (number_of_types() >= 1U) && + !etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + explicit tuple(UHead&& head, UTail&&... tail) ETL_NOEXCEPT + : base_type(etl::forward(tail)...) + , value(etl::forward(head)) + { + } + + //********************************* + /// Construct from lvalue reference pair. + /// Implicit conversion. + //********************************* + template () == 2U && + etl ::is_convertible::value && + etl ::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(ETL_OR_STD::pair& p) ETL_NOEXCEPT + : base_type(p.second) + , value(p.first) + { + } + + //********************************* + /// Construct from lvalue reference pair. + /// Explicit conversion. + //********************************* + template () == 2U && + (!etl ::is_convertible::value || + !etl ::is_convertible::value), int> = 0> + ETL_CONSTEXPR14 + explicit tuple(ETL_OR_STD::pair& p) ETL_NOEXCEPT + : base_type(p.second) + , value(p.first) + { + } + + //********************************* + /// Construct from const lvalue reference pair. + /// Implicit conversion. + //********************************* + template () == 2U && + etl ::is_convertible::value && + etl ::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(const ETL_OR_STD::pair& p) ETL_NOEXCEPT + : base_type(p.second) + , value(p.first) + { + } + + //********************************* + /// Construct from const lvalue reference pair. + /// Explicit conversion. + //********************************* + template () == 2U && + (!etl ::is_convertible::value || + !etl ::is_convertible::value), int> = 0> + ETL_CONSTEXPR14 + explicit tuple(const ETL_OR_STD::pair& p) ETL_NOEXCEPT + : base_type(p.second) + , value(p.first) + { + } + + //********************************* + /// Construct from rvalue reference pair. + /// Implicit conversion. + //********************************* + template () == 2U && + etl ::is_convertible::value && + etl ::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(ETL_OR_STD::pair&& p) ETL_NOEXCEPT + : base_type(etl::forward(p.second)) + , value(etl::forward(p.first)) + { + } + + //********************************* + /// Construct from rvalue reference pair. + /// Explicit conversion. + //********************************* + template () == 2U && + (!etl ::is_convertible::value || + !etl ::is_convertible::value), int> = 0> + ETL_CONSTEXPR14 + explicit tuple(ETL_OR_STD::pair&& p) ETL_NOEXCEPT + : base_type(etl::forward(p.second)) + , value(etl::forward(p.first)) + { + } + + //********************************* + /// Construct from const rvalue reference pair. + /// Implicit conversion. + //********************************* + template () == 2U && + etl ::is_convertible::value && + etl ::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(const ETL_OR_STD::pair&& p) ETL_NOEXCEPT + : base_type(etl::forward(p.second)) + , value(etl::forward(p.first)) + { + } + + //********************************* + /// Construct from const rvalue reference pair. + /// Explicit conversion. + //********************************* + template () == 2U && + (!etl ::is_convertible::value || + !etl ::is_convertible::value), int> = 0> + ETL_CONSTEXPR14 + explicit tuple(const ETL_OR_STD::pair&& p) ETL_NOEXCEPT + : base_type(p.second) + , value(p.first) + { + } + + //********************************* + /// Copy assign from other tuple type. + //********************************* + template () == number_of_types()), int> = 0> + ETL_CONSTEXPR14 + tuple& operator =(const tuple& other) + { + copy_assignment(other); + + return *this; + } + + //********************************* + /// Move assign from other tuple type. + //********************************* + template () == number_of_types()), int> = 0> + ETL_CONSTEXPR14 + tuple& operator =(tuple&& other) + { + forward_assignment(etl::forward>(other)); + + return *this; + } + + //********************************* + /// Assign from lvalue pair tuple type. + //********************************* + template , etl::enable_if_t = 0> + ETL_CONSTEXPR14 + tuple& operator =(pair& p) + { + get_value() = p.first; + get_base().get_value() = p.second; + + return *this; + } + + //********************************* + /// Assign from const lvalue pair tuple type. + //********************************* + template , etl::enable_if_t = 0> + ETL_CONSTEXPR14 + tuple& operator =(const pair& p) + { + get_value() = p.first; + get_base().get_value() = p.second; + + return *this; + } + + //********************************* + /// Assign from rvalue pair tuple type. + //********************************* + template , etl::enable_if_t = 0> + ETL_CONSTEXPR14 + tuple& operator =(pair&& p) + { + get_value() = etl::forward(p.first); + get_base().get_value() = etl::forward(p.second); + + return *this; + } + + //********************************* + /// Assign from const rvalue pair tuple type. + //********************************* + template , etl::enable_if_t = 0> + ETL_CONSTEXPR14 + tuple& operator =(const pair&& p) + { + get_value() = etl::forward(p.first); + get_base().get_value() = etl::forward(p.second); + + return *this; + } + + //********************************* + /// Swaps this tuple with another. + //********************************* + ETL_CONSTEXPR14 + void swap(this_type& other) + { + using ETL_OR_STD::swap; + + // Swap the head + swap(get_value(), other.get_value()); + + auto& this_base = get_base(); + auto& other_base = other.get_base(); + + // Recursively swap the tail by calling the base class's swap implementation. + this_base.swap(other_base); + } + + //********************************* + /// Returns the number of elements in the tuple. + //********************************* + ETL_NODISCARD + constexpr + static size_t size() + { + return number_of_types(); + } + + protected: + + //********************************* + /// Returns a reference to the head value. + //********************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + THead& get_value() + { + return value; + } + + //********************************* + /// Returns a const reference to the head value. + //********************************* + ETL_CONSTEXPR + const THead& get_value() const + { + return value; + } + + //********************************* + /// Get a reference to the base class. + //********************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + base_type& get_base() + { + return static_cast(*this); + } + + //********************************* + /// Get a const reference to the base class. + //********************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + const base_type& get_base() const + { + return static_cast(*this); + } + + //********************************* + /// Handles copy assignment from another tuple. + //********************************* + template + ETL_CONSTEXPR14 + void copy_assignment(const tuple& other) + { + // Assign the head + this->value = other.get_value(); + + // Get the base classes + auto& this_base = get_base(); + const auto& other_base = other.get_base(); + + // Recursively assign the tail by calling the base class's assignment implementation + this_base.copy_assignment(other_base); + } + + //********************************* + /// Handles move assignment from another tuple. + //********************************* + template + ETL_CONSTEXPR14 + void forward_assignment(tuple&& other) + { + // Assign the head + this->value = etl::forward(other.get_value()); + + auto& this_base = get_base(); + auto&& other_base = other.get_base(); + + // Recursively assign the tail by calling the base class's move assignment implementation + this_base.forward_assignment(etl::forward>(other_base)); + } + + private: + + THead value; + }; + +#if ETL_USING_CPP17 + //*************************************************************************** + /// Template deduction guideline from variadic arguments. + //*************************************************************************** + template + tuple(TArgs... args) -> tuple; + + //*************************************************************************** + /// Template deduction guideline from pair. + //*************************************************************************** + template + tuple(ETL_OR_STD::pair) -> tuple; +#endif + + //*************************************************************************** + /// Gets the element type at the index in the tuple. + //*************************************************************************** + template + struct tuple_element> + { + using type = etl::nth_type_t; + }; + + //*************************************************************************** + /// Gets the size of the tuple. + //*************************************************************************** + template + struct tuple_size> + : etl::integral_constant + { + }; + + //*************************************************************************** + /// Gets the common type of a tuple. + //*************************************************************************** + template + struct common_type> + { + using type = etl::common_type_t; + }; + + //*************************************************************************** + /// Extracts the element at Index from the tuple. + /// Index must be an integer value in sizeof...(TTypes)). + /// Returns a reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + etl::tuple_element_t>& get(tuple& t) + { + ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); + + // Get the type at this index. + using tuple_type = etl::nth_base_t>&; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + + //*************************************************************************** + /// Extracts the element at Index from the tuple. + /// Index must be an integer value in [?0?, sizeof...(TTypes)). + /// Returns a const reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + const etl::tuple_element_t>& get(const tuple& t) + { + ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); + + // Get the type at this index. + using tuple_type = const etl::nth_base_t>&; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + + //*************************************************************************** + /// Extracts the element at Index from the tuple. + /// Index must be an integer value in [?0?, sizeof...(TTypes)). + /// Returns an rvalue reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + etl::tuple_element_t>&& get(tuple&& t) + { + ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); + + // Get the type at this index. + using tuple_type = etl::nth_base_t>&&; + + // Cast the tuple to the selected type and get the value. + return etl::move(static_cast(t).get_value()); + } + + //*************************************************************************** + /// Extracts the element at Index from the tuple. + /// Index must be an integer value in [?0?, sizeof...(TTypes)). + /// Returns a const rvalue reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + const etl::tuple_element_t>&& get(const tuple&& t) + { + ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); + + // Get the type at this index. + using tuple_type = const etl::nth_base_t>&&; + + // Cast the tuple to the selected type and get the value. + return etl::move(static_cast(t).get_value()); + } + + //*************************************************************************** + /// Extracts the element with type T from the tuple. + /// Static asserts if the tuple contain more than one T, or does not contain a T element. + /// Returns a reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T& get(tuple& t) + { + ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + + // Get the tuple base type that contains a T + using tuple_type = etl::private_tuple::tuple_type_base_t>&; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + + //*************************************************************************** + /// Extracts the element with type T from the tuple. + /// Static asserts if the tuple contain more than one T, or does not contain a T element. + /// Returns a const reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + const T& get(const tuple& t) + { + ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + + // Get the tuple base type that contains a T + using tuple_type = const etl::private_tuple::tuple_type_base_t>&; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + + //*************************************************************************** + /// Extracts the element with type T from the tuple. + /// Static asserts if the tuple contain more than one T, or does not contain a T element. + /// Returns an rvalue reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T&& get(tuple&& t) + { + ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + + // Get the tuple base type that contains a T + using tuple_type = etl::private_tuple::tuple_type_base_t>&&; + + // Cast the tuple to the selected type and get the value. + return etl::move(static_cast(t).get_value()); + } + + //*************************************************************************** + /// Extracts the element with type T from the tuple. + /// Static asserts if the tuple contain more than one T, or does not contain a T element. + /// Returns a const rvalue reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + const T&& get(const tuple&& t) + { + ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + + // Get the tuple base type that contains a T + using tuple_type = const etl::private_tuple::tuple_type_base_t>&&; + + // Cast the tuple to the selected type and get the value. + return etl::move(static_cast(t).get_value()); + } + +#if ETL_USING_CPP17 + inline constexpr private_tuple::ignore_t ignore; +#else + static constexpr private_tuple::ignore_t ignore; +#endif + + //*************************************************************************** + /// Creates a tuple of references to the provided arguments. + //*************************************************************************** + template + ETL_CONSTEXPR + etl::tuple tie(TTypes&... args) + { + return { args... }; + } + + //*************************************************************************** + // Creates a tuple from the provided arguments. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + etl::tuple...> make_tuple(TTypes&&... args) + { + return etl::tuple...>(etl::forward(args)...); + } + + //*************************************************************************** + /// Creates a new tuple by selecting elements from another, given a run time index sequence. + /// Static asserts if the number of indices does not match the tuple size. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto select_from_tuple(TTuple&& tuple, etl::index_sequence) + -> etl::tuple>...> + { + ETL_STATIC_ASSERT(sizeof...(Indices) <= etl::tuple_size>::value, "Number of indices is greater than the tuple size"); + + return etl::make_tuple(etl::forward>>(etl::get(etl::forward(tuple)))...); + } + + //*************************************************************************** + /// Creates a new tuple by selecting elements from another, given a template parameter index sequence. + /// Static asserts if the number of indices does not match the tuple size. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto select_from_tuple(TTuple&& tuple) + -> etl::tuple>...> + { + return select_from_tuple(etl::forward(tuple), etl::index_sequence{}); + } + + //*************************************************************************** + /// Forwards the arguments as a tuple. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + etl::tuple forward_as_tuple(TTypes&&... args) + { + return tuple(etl::forward(args)...); + } + + namespace private_tuple + { + //********************************** + // Helper to concatenate two tuples + //********************************** + template + ETL_CONSTEXPR14 + auto tuple_cat_impl(Tuple1&& t1, etl::index_sequence, Tuple2&& t2, etl::index_sequence) + -> etl::tuple>..., etl::tuple_element_t>...> + { + return etl::tuple>..., + etl::tuple_element_t>...> + (etl::get(etl::forward(t1))..., etl::get(etl::forward(t2))...); + } + } + + //*************************************************************************** + /// Base case for concatenating one tuple + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto tuple_cat(Tuple&& t) -> Tuple + { + return etl::forward(t); + } + + //*************************************************************************** + /// Recursive case for concatenating multiple tuples + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto tuple_cat(Tuple1&& t1, Tuple2&& t2, Tuples&&... ts) + -> decltype(private_tuple::tuple_cat_impl(etl::forward(t1), + etl::make_index_sequence>::value>{}, + etl::forward(t2), + etl::make_index_sequence>::value>{})) + { + auto concatenated = private_tuple::tuple_cat_impl(etl::forward(t1), + etl::make_index_sequence>::value>{}, + etl::forward(t2), + etl::make_index_sequence>::value>{}); + + return tuple_cat(etl::move(concatenated), etl::forward(ts)...); + } + +#if ETL_USING_STL + //*************************************************************************** + // Tuple conversion functions. + // From ETL to STL + //*************************************************************************** + namespace private_tuple + { + ///********************************* + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_std_impl(const TEtl_Tuple& etl_tuple, etl::index_sequence) + -> std::tuple...> + { + return std::tuple...>(etl::get(etl_tuple)...); + } + + ///********************************* + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_std_impl(TEtl_Tuple&& etl_tuple, etl::index_sequence) + -> std::tuple...> + { + return std::tuple...>(etl::move(etl::get(etl_tuple))...); + } + } + + //*************************************************************************** + /// Converts an etl::tuple to a std::tuple. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_std(const etl::tuple& etl_tuple) + -> std::tuple...> + { + return private_tuple::to_std_impl(etl_tuple, etl::make_index_sequence_for()); + } + + //*************************************************************************** + /// Converts an etl::tuple to a std::tuple. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_std(etl::tuple&& etl_tuple) + -> std::tuple...> + { + return private_tuple::to_std_impl(etl::move(etl_tuple), etl::make_index_sequence_for()); + } + + //*************************************************************************** + /// Tuple conversion functions. + /// From STL to ETL + //*************************************************************************** + namespace private_tuple + { + ///********************************* + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_etl_impl(const TStd_Tuple& std_tuple, etl::index_sequence) + -> etl::tuple::type...> + { + return etl::tuple::type...>(std::get(std_tuple)...); + } + + ///********************************* + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_etl_impl(TStd_Tuple&& std_tuple, etl::index_sequence) + -> etl::tuple::type...> + { + return etl::tuple::type...>(std::move(std::get(std_tuple))...); + } + } + + //*************************************************************************** + /// Converts a std::tuple to an etl::tuple. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_etl(const std::tuple& std_tuple) + -> etl::tuple...> + { + return private_tuple::to_etl_impl(std_tuple, etl::make_index_sequence_for()); + } + + //*************************************************************************** + /// Converts a std::tuple to an etl::tuple. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_etl(std::tuple&& std_tuple) + -> etl::tuple...> + { + return private_tuple::to_etl_impl(etl::move(std_tuple), etl::make_index_sequence_for()); + } +#endif + + namespace private_tuple + { + //*************************************************************************** + /// Equality + //*************************************************************************** + // When there are no indices left to compare. + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool tuple_equality(const TTuple1& /*lhs*/, const TTuple2& /*rhs*/, etl::index_sequence<>) + { + return true; + } + + // Recursive case: compare the current element and recurse. + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool tuple_equality(const TTuple1& lhs, const TTuple2& rhs, etl::index_sequence) + { + return etl::get(lhs) == etl::get(rhs) && tuple_equality(lhs, rhs, etl::index_sequence{}); + } + + //*************************************************************************** + /// Less than + //*************************************************************************** + // When there are no indices left to compare. + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool tuple_less_than(const TTuple1& /*lhs*/, const TTuple2& /*rhs*/, etl::index_sequence<>) + { + return false; + } + + // Recursively compare the current element and the rest. + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool tuple_less_than(const TTuple1& lhs, const TTuple2& rhs, etl::index_sequence) + { + if (get(lhs) < get(rhs)) + { + return true; + } + + if (get(rhs) < get(lhs)) + { + return false; + } + + return tuple_less_than(lhs, rhs, etl::index_sequence{}); + } + } + + //*************************************************************************** + /// Equality operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator ==(const etl::tuple& lhs, + const etl::tuple& rhs) + { + ETL_STATIC_ASSERT(sizeof...(TTypes) == sizeof...(UTypes), "Cannot compare tuples of different sizes"); + + // Compare each element of the tuples. + return private_tuple::tuple_equality(lhs, rhs, etl::make_index_sequence::size()>{}); + } + + //*************************************************************************** + /// Inequality operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator !=(const etl::tuple& lhs, + const etl::tuple& rhs) + { + return !(lhs == rhs); + } + + //*************************************************************************** + /// Less than operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator <(const etl::tuple& lhs, + const etl::tuple& rhs) + { + ETL_STATIC_ASSERT(sizeof...(TTypes) == sizeof...(UTypes), "Cannot compare tuples of different sizes"); + + // Compare the elements. + return private_tuple::tuple_less_than(lhs, rhs, etl::make_index_sequence::size()>{}); + } + + //*************************************************************************** + /// Less than or equals operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator <=(const etl::tuple& lhs, + const etl::tuple& rhs) + { + return !(rhs < lhs); + } + + //*************************************************************************** + /// Greater than operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator >(const etl::tuple& lhs, + const etl::tuple& rhs) + { + return (rhs < lhs); + } + + //*************************************************************************** + /// Greater than or equals operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator >=(const etl::tuple& lhs, + const etl::tuple& rhs) + { + return !(lhs < rhs); + } + + //*************************************************************************** + /// Swap two tuples. + //*************************************************************************** + template + ETL_CONSTEXPR14 + void swap(etl::tuple& lhs, etl::tuple& rhs) + { + lhs.swap(rhs); + } +} + +namespace std +{ + //*************************************************************************** + /// Specialisation of tuple_size to allow the use of C++ structured bindings. + //*************************************************************************** + template + struct tuple_size> : etl::integral_constant + { + }; + + //*************************************************************************** + /// Specialisation of tuple_element to allow the use of C++ structured bindings. + //*************************************************************************** + template + struct tuple_element> + { + using type = typename etl::nth_type_t; + }; +} diff --git a/include/etl/type_def.h b/include/etl/type_def.h index c124aa7e..cdd916e7 100644 --- a/include/etl/type_def.h +++ b/include/etl/type_def.h @@ -58,10 +58,9 @@ namespace etl typedef TIdType id_type; //********************************************************************* - ETL_CONSTEXPR type_def() - : value(TValue()) - { - } +#if ETL_USING_CPP11 + ETL_CONSTEXPR type_def() = default; +#endif //********************************************************************* ETL_CONSTEXPR type_def(TValue value_) @@ -70,10 +69,9 @@ namespace etl } //********************************************************************* - ETL_CONSTEXPR type_def(const type_def& other) - : value(other.value) - { - } +#if ETL_USING_CPP11 + ETL_CONSTEXPR type_def(const type_def& other) = default; +#endif //********************************************************************* ETL_CONSTEXPR operator TValue() const @@ -245,11 +243,9 @@ namespace etl } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator =(const type_def& rhs) - { - value = rhs.value; - return *this; - } +#if ETL_USING_CPP11 + ETL_CONSTEXPR14 type_def& operator =(const type_def& rhs) = default; +#endif //********************************************************************* TValue& get() diff --git a/include/etl/type_list.h b/include/etl/type_list.h new file mode 100644 index 00000000..4dbc66ec --- /dev/null +++ b/include/etl/type_list.h @@ -0,0 +1,293 @@ +/****************************************************************************** +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_TYPE_LIST_INCLUDED +#define ETL_TYPE_LIST_INCLUDED + +#include "platform.h" + +#include "algorithm.h" +#include "index_of_type.h" +#include "integral_limits.h" +#include "static_assert.h" +#include "type_traits.h" +#include "utility.h" +#include "largest.h" + +#if ETL_USING_CPP11 +namespace etl +{ + //*************************************************************************** + /// Defines a no-position constant. + //*************************************************************************** + static ETL_CONSTANT size_t type_list_npos = etl::integral_limits::max; + + //*************************************************************************** + /// Type list forward declaration. + //*************************************************************************** + template + struct type_list; + + //*************************************************************************** + /// The empty type list. + //*************************************************************************** + template <> + struct type_list<> + { + static constexpr size_t size = 0U; + + using index_sequence_type = etl::make_index_sequence<0>; ///< The index_sequence type for this type_list. + + private: + + type_list() ETL_DELETE; + type_list(const type_list&) ETL_DELETE; + type_list& operator =(const type_list&) ETL_DELETE; + }; + + namespace private_type_list + { + // helper to solve the issue that recursed-rest can't be put directly in type_list::tail definition + template + struct recursion_helper + { + using type = type_list; + }; + } + + //*************************************************************************** + /// Recursive type list implementation for multiple types. + //*************************************************************************** + template + struct type_list : type_list + { + using head = THead; + using tail = typename private_type_list::recursion_helper::type; + + static constexpr size_t size = sizeof...(TTail) + 1U; + + using index_sequence_type = etl::make_index_sequence; ///< The index_sequence type for this type_list. + + private: + + type_list() ETL_DELETE; + type_list(const type_list&) ETL_DELETE; + type_list& operator =(const type_list&) ETL_DELETE; + }; + + //*************************************************************************** + /// Type list implementation for one type. + //*************************************************************************** + template + struct type_list : type_list<> + { + using head = THead; + using tail = typename private_type_list::recursion_helper<>::type; + + static constexpr size_t size = 1U; + + using index_sequence_type = etl::make_index_sequence<1>; ///< The index_sequence type for this type_list. + + private: + + type_list() ETL_DELETE; + type_list(const type_list&) ETL_DELETE; + type_list& operator =(const type_list&) ETL_DELETE; + }; + + //*************************************************************************** + /// Type list size. + //*************************************************************************** + template + struct type_list_size; + + template + struct type_list_size> : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_size_v = type_list_size>::value; +#endif + + //*************************************************************************** + /// Defines type as the type found at Index in the type_list. + /// Static asserts if Index is out of range. + //*************************************************************************** + template + struct type_list_type_at_index + { + ETL_STATIC_ASSERT(Index < type_list_size::value, "etl::type_list_type_at_index out of range"); + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); + + using type = typename type_list_type_at_index::type; + }; + + template + struct type_list_type_at_index + { + using type = typename TTypeList::head; + }; + + template + using type_list_type_at_index_t = typename type_list_type_at_index::type; + + //*************************************************************************** + /// Defines an integral constant that is the index of the specified type in the type_list. + /// If the type is not in the type_list, then defined as etl::type_list_npos. + //*************************************************************************** + template + struct type_list_index_of_type + : public etl::integral_constant::value ? 0 : + (type_list_index_of_type::value == etl::type_list_npos ? etl::type_list_npos : + type_list_index_of_type::value + 1)> + { + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); + }; + + template + struct type_list_index_of_type, T> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_index_of_v = etl::type_list_index_of_type::value; +#endif + + //*************************************************************************** + /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. + //*************************************************************************** + template + struct type_list_contains; + + template + struct type_list_contains, T> + : public etl::integral_constant::value> + { + }; + + template + struct type_list_contains, T> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool type_list_contains_v = etl::type_list_contains::value; +#endif + + //*************************************************************************** + /// Defines an integral constant that is maximum sizeof all types in the type_list. + /// If the type_list is empty, then defined as 0. + //*************************************************************************** + template + struct type_list_max_size; + + template + struct type_list_max_size> + : public etl::integral_constant::size> + { + }; + + template <> + struct type_list_max_size> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_max_size_v = etl::type_list_max_size::value; +#endif + + //*************************************************************************** + /// Defines an integral constant that is maximum alignment all types in the type_list. + /// If the type_list is empty, then defined as 1. + //*************************************************************************** + template + struct type_list_max_alignment; + + template + struct type_list_max_alignment> + : public etl::integral_constant::alignment> + { + }; + + template <> + struct type_list_max_alignment> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; +#endif + + //*************************************************************************** + /// Declares a new type_list by selecting types from a given type_list, according to an index sequence. + //*************************************************************************** + template + struct type_list_select + { + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); + + using type = type_list...>; + }; + + template + using type_list_select_t = typename type_list_select::type; + + //*************************************************************************** + /// Concatenates two or more type_lists. + //*************************************************************************** + template + struct type_list_cat; + + template + struct type_list_cat, etl::type_list, TTail...> + { + using type = typename type_list_cat, TTail...>::type; + }; + + template + struct type_list_cat + { + using type = T; + }; + + template + using type_list_cat_t = typename type_list_cat::type; +} +#endif + +#endif diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 47489c2c..44b7805f 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -628,17 +628,12 @@ namespace etl { private: - template struct dummy {}; - struct internal: TDerived, dummy{}; - static TBase* check(TBase*) { return (TBase*)0; } - - template - static char check(dummy*) { return 0; } + static char check(...) { return 0; } public: - static const bool value = (sizeof(check((internal*)0)) == sizeof(TBase*)); + static const bool value = (sizeof(check((TDerived*)0)) == sizeof(TBase*)); }; // For when TBase or TDerived is a fundamental type. @@ -1327,6 +1322,79 @@ typedef integral_constant true_type; // ETL extended type traits. //*************************************************************************** +#if ETL_USING_CPP11 + //*************************************************************************** + /// conjunction +#if ETL_USING_CPP11 + template + struct conjunction : public etl::true_type + { + }; + + template + struct conjunction : public etl::conditional_t, T1> + { + }; + + template + struct conjunction : public T + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool conjunction_v = conjunction::value; +#endif + + //*************************************************************************** + /// disjunction +#if ETL_USING_CPP11 + template + struct disjunction : public etl::false_type + { + }; + + template + struct disjunction : public etl::conditional_t> + { + }; + + template struct disjunction : public T1 + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool disjunction_v = etl::disjunction::value; +#endif + +#endif + + //*************************************************************************** + /// exclusive_disjunction +#if ETL_USING_CPP11 + template + struct exclusive_disjunction; + + template + struct exclusive_disjunction : public etl::bool_constant + { + }; + + // Recursive case: XOR the first two values and recurse + template + struct exclusive_disjunction : public etl::exclusive_disjunction::value && !etl::conjunction::value>, TRest...> + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool exclusive_disjunction_v = etl::exclusive_disjunction::value; +#endif + //*************************************************************************** /// conditional_integral_constant // /\ingroup type_traits @@ -1349,19 +1417,11 @@ typedef integral_constant true_type; #if ETL_USING_CPP11 //*************************************************************************** - /// Template to determine if a type is one of a specified list. + /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types - template - struct is_one_of + template + struct is_one_of : etl::disjunction...> { - static const bool value = etl::is_same::value || - etl::is_one_of::value; - }; - - template - struct is_one_of - { - static const bool value = etl::is_same::value; }; #else //*************************************************************************** @@ -1399,21 +1459,46 @@ typedef integral_constant true_type; inline constexpr bool is_one_of_v = etl::is_one_of::value; #endif +#if ETL_USING_CPP11 + namespace private_type_traits + { + //*************************************************************************** + // Helper to count occurrences of a type in a list of types + template + struct count_type; + + // Base case: zero occurrences + template + struct count_type : etl::integral_constant + { + }; + + // Recursive case: increment count if head is the same as T, otherwise continue with tail + template + struct count_type : etl::integral_constant::value ? 1 : 0) + count_type::value> + { + }; + } + + template + struct has_duplicates_of + : etl::integral_constant::value > 1)> + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool has_duplicates_of_v = etl::has_duplicates_of::value; +#endif + #if ETL_USING_CPP11 //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types - template - struct is_base_of_all + template + struct is_base_of_all : etl::conjunction...> { - static const bool value = etl::is_base_of::value && - etl::is_base_of_all::value; - }; - - template - struct is_base_of_all - { - static const bool value = etl::is_base_of::value; }; #endif @@ -1426,18 +1511,11 @@ typedef integral_constant true_type; //*************************************************************************** /// Template to determine if a type is a base of any type in a specified list. ///\ingroup types - template - struct is_base_of_any + template + struct is_base_of_any : etl::disjunction...> { - static const bool value = etl::is_base_of::value || - etl::is_base_of_any::value; }; - template - struct is_base_of_any - { - static const bool value = etl::is_base_of::value; - }; #endif #if ETL_USING_CPP17 @@ -1445,6 +1523,28 @@ typedef integral_constant true_type; inline constexpr bool is_base_of_any_v = etl::is_base_of_any::value; #endif + //*************************************************************************** + /// Get the Nth base of a recursively inherited type. + /// Requires that the class has defined 'base_type'. + //*************************************************************************** + // Recursive definition of the type. + template + struct nth_base + { + typedef typename nth_base::type type; + }; + + template + struct nth_base<0, TType> + { + typedef TType type; + }; + +#if ETL_USING_CPP11 + template + using nth_base_t = typename nth_base::type; +#endif + //*************************************************************************** /// A set of templates to allow related types to be derived. ///\ingroup types @@ -1598,70 +1698,15 @@ typedef integral_constant true_type; #if ETL_USING_CPP11 //*************************************************************************** /// are_all_same - template - struct are_all_same - { - static const bool value = etl::is_same::value && - etl::are_all_same::value; - }; - - template - struct are_all_same - { - static const bool value = etl::is_same::value; - }; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool are_all_same_v = are_all_same::value; -#endif - - //*************************************************************************** - /// conjunction -#if ETL_USING_CPP11 - template - struct conjunction : public etl::true_type - { - }; - - template - struct conjunction : public etl::conditional_t, T1> - { - }; - - template - struct conjunction : public T + template + struct are_all_same : etl::conjunction...> { }; #endif #if ETL_USING_CPP17 - template - inline constexpr bool conjunction_v = conjunction::value; -#endif - - //*************************************************************************** - /// disjunction -#if ETL_USING_CPP11 - template - struct disjunction : public etl::false_type - { - }; - - template - struct disjunction : public etl::conditional_t> - { - }; - - template struct disjunction : public T1 - { - }; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool disjunction_v = etl::disjunction::value; + template + inline constexpr bool are_all_same_v = are_all_same::value; #endif //*************************************************************************** @@ -2342,18 +2387,6 @@ typedef integral_constant true_type; template inline constexpr size_t count_of_v = etl::count_of::value; #endif - -#if ETL_USING_CPP11 - //********************************************* - // has_duplicates_of - template - struct has_duplicates_of : etl::bool_constant<(etl::count_of::value > 1U)> {}; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool has_duplicates_of_v = etl::has_duplicates_of::value; -#endif } // Helper macros diff --git a/include/etl/u16string.h b/include/etl/u16string.h index c0fea3a2..e886a4ec 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -46,7 +46,7 @@ namespace etl { inline namespace string_literals { - constexpr etl::u16string_view operator ""_sv(const char16_t* str, size_t length) noexcept + inline constexpr etl::u16string_view operator ""_sv(const char16_t* str, size_t length) noexcept { return etl::u16string_view{ str, length }; } @@ -227,6 +227,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u16string& operator = (const etl::u16string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -366,8 +376,8 @@ namespace etl #endif //************************************************************************* - /// From u16string_view. - ///\param view The u16string_view. + /// From string_view. + ///\param view The string_view. //************************************************************************* explicit u16string_ext(const etl::u16string_view& view, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) @@ -388,7 +398,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -412,6 +421,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u16string_ext& operator = (const etl::u16string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 766a0cbc..2ca6717c 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -46,7 +46,7 @@ namespace etl { inline namespace string_literals { - constexpr etl::u32string_view operator ""_sv(const char32_t* str, size_t length) noexcept + inline constexpr etl::u32string_view operator ""_sv(const char32_t* str, size_t length) noexcept { return etl::u32string_view{ str, length }; } @@ -227,6 +227,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u32string& operator = (const etl::u32string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -366,8 +376,8 @@ namespace etl #endif //************************************************************************* - /// From u32string_view. - ///\param view The u32string_view. + /// From string_view. + ///\param view The string_view. //************************************************************************* explicit u32string_ext(const etl::u32string_view& view, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) @@ -388,7 +398,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -412,6 +421,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u32string_ext& operator = (const etl::u32string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u8string.h b/include/etl/u8string.h index 015ef3c1..595c45bb 100644 --- a/include/etl/u8string.h +++ b/include/etl/u8string.h @@ -49,7 +49,7 @@ namespace etl { inline namespace string_literals { - constexpr etl::u8string_view operator ""_sv(const char8_t* str, size_t length) noexcept + inline constexpr etl::u8string_view operator ""_sv(const char8_t* str, size_t length) noexcept { return etl::u8string_view{ str, length }; } @@ -244,6 +244,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u8string& operator = (const etl::u8string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -409,7 +419,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -433,6 +442,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u8string_ext& operator = (const etl::u8string_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/unaligned_type.h b/include/etl/unaligned_type.h index 9b4ae662..87519dbf 100644 --- a/include/etl/unaligned_type.h +++ b/include/etl/unaligned_type.h @@ -41,46 +41,76 @@ SOFTWARE. #include "iterator.h" #include "algorithm.h" #include "bit.h" +#include "binary.h" +#include "array.h" +#include "exception.h" +#include "file_error_numbers.h" + +#if ETL_USING_CPP20 && ETL_USING_STL + #include +#endif #include namespace etl { + struct unaligned_type_exception : public etl::exception + { + public: + + unaligned_type_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + //*************************************************************************** + /// Buffer size exception. + //*************************************************************************** + class unaligned_type_buffer_size : public unaligned_type_exception + { + public: + + unaligned_type_buffer_size(string_type file_name_, numeric_type line_number_) + : unaligned_type_exception(ETL_ERROR_TEXT("unaligned_type:buffer size", ETL_UNALIGNED_TYPE_FILE_ID"A"), file_name_, line_number_) + { + } + }; + namespace private_unaligned_type { //************************************************************************* /// unaligned_type_common /// Contains all functionality that doesn't require the type. + /// ETL_PACKED ensures that GCC does not complain when used in a packed object. //************************************************************************* - template - class unaligned_type_common + template + ETL_PACKED_CLASS(unaligned_type_common) { public: - static ETL_CONSTANT size_t Size = Size_; - + typedef TDerivedType derived_type; typedef unsigned char storage_type; - typedef storage_type* pointer; - typedef const storage_type* const_pointer; - typedef storage_type* iterator; - typedef const storage_type* const_iterator; + typedef storage_type* pointer; + typedef const storage_type* const_pointer; + typedef storage_type* iterator; + typedef const storage_type* const_iterator; typedef etl::reverse_iterator reverse_iterator; typedef etl::reverse_iterator const_reverse_iterator; //************************************************************************* /// Default constructor //************************************************************************* - ETL_CONSTEXPR unaligned_type_common() - : storage() + unaligned_type_common() { } //************************************************************************* /// Size of the storage. //************************************************************************* - ETL_CONSTEXPR size_t size() const + size_t size() const { - return Size; + return Size_; } //************************************************************************* @@ -88,15 +118,15 @@ namespace etl //************************************************************************* pointer data() { - return storage; + return get_storage(); } //************************************************************************* /// Const pointer to the beginning of the storage. //************************************************************************* - ETL_CONSTEXPR const_pointer data() const + const_pointer data() const { - return storage; + return get_storage(); } //************************************************************************* @@ -104,23 +134,23 @@ namespace etl //************************************************************************* iterator begin() { - return iterator(storage); + return iterator(get_storage()); } //************************************************************************* /// Const iterator to the beginning of the storage. //************************************************************************* - ETL_CONSTEXPR const_iterator begin() const + const_iterator begin() const { - return const_iterator(storage); + return const_iterator(get_storage()); } //************************************************************************* /// Const iterator to the beginning of the storage. //************************************************************************* - ETL_CONSTEXPR const_iterator cbegin() const + const_iterator cbegin() const { - return const_iterator(storage); + return const_iterator(get_storage()); } //************************************************************************* @@ -128,23 +158,23 @@ namespace etl //************************************************************************* reverse_iterator rbegin() { - return reverse_iterator(storage + Size); + return reverse_iterator(get_storage() + Size_); } //************************************************************************* /// Const reverse iterator to the beginning of the storage. //************************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator rbegin() const + const_reverse_iterator rbegin() const { - return const_reverse_iterator(storage + Size); + return const_reverse_iterator(get_storage() + Size_); } //************************************************************************* /// Const reverse iterator to the beginning of the storage. //************************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator crbegin() const + const_reverse_iterator crbegin() const { - return const_reverse_iterator(storage + Size); + return const_reverse_iterator(get_storage() + Size_); } //************************************************************************* @@ -152,23 +182,23 @@ namespace etl //************************************************************************* iterator end() { - return iterator(storage + Size); + return iterator(get_storage() + Size_); } //************************************************************************* /// Const iterator to the end of the storage. //************************************************************************* - ETL_CONSTEXPR const_iterator end() const + const_iterator end() const { - return const_iterator(storage + Size); + return const_iterator(get_storage() + Size_); } //************************************************************************* /// Const iterator to the end of the storage. //************************************************************************* - ETL_CONSTEXPR const_iterator cend() const + const_iterator cend() const { - return const_iterator(storage + Size); + return const_iterator(get_storage() + Size_); } //************************************************************************* @@ -176,23 +206,23 @@ namespace etl //************************************************************************* reverse_iterator rend() { - return reverse_iterator(storage); + return reverse_iterator(get_storage()); } //************************************************************************* /// Const reverse iterator to the end of the storage. //************************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator rend() const + const_reverse_iterator rend() const { - return const_reverse_iterator(storage); + return const_reverse_iterator(get_storage()); } //************************************************************************* /// Const reverse iterator to the end of the storage. //************************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator crend() const + const_reverse_iterator crend() const { - return const_reverse_iterator(storage); + return const_reverse_iterator(get_storage()); } //************************************************************************* @@ -200,24 +230,215 @@ namespace etl //************************************************************************* storage_type& operator[](int i) { - return storage[i]; + return get_storage()[i]; } //************************************************************************* /// Const index operator. //************************************************************************* - ETL_CONSTEXPR const storage_type& operator[](int i) const + const storage_type& operator[](int i) const { - return storage[i]; + return get_storage()[i]; } + private: + + //************************************************************************* + /// Get a pointer to the storage. + //************************************************************************* + pointer get_storage() + { + return static_cast(this)->storage; + } + + //************************************************************************* + /// Get a const pointer to the storage. + //************************************************************************* + const_pointer get_storage() const + { + return static_cast(this)->storage; + } + }; ETL_END_PACKED + + //************************************************************************* + /// unaligned_type_storage + /// Contains the fixed storage for a type. + /// ETL_PACKED ensures that GCC does not complain when used in a packed object. + //************************************************************************* + template + ETL_PACKED_CLASS(unaligned_type_storage) : public unaligned_type_common > + { + public: + + friend class unaligned_type_common >; + protected: - unsigned char storage[Size]; - }; + //******************************* + unaligned_type_storage() + : storage() + { + } + unsigned char storage[Size_]; + }; ETL_END_PACKED + + //************************************************************************* + /// unaligned_type_storage_ext + /// Contains a pointer to the fixed storage for a type. + /// ETL_PACKED ensures that GCC does not complain when used in a packed object. + //************************************************************************* template - ETL_CONSTANT size_t unaligned_type_common::Size; + ETL_PACKED_CLASS(unaligned_type_storage_ext) : public unaligned_type_common > + { + public: + + friend class unaligned_type_common >; + + protected: + + //******************************* + unaligned_type_storage_ext(unsigned char* storage_) + : storage(storage_) + { + } + + //******************************* + unaligned_type_storage_ext(const unaligned_type_storage_ext& other) + : storage(other.storage) + { + } + + //******************************* + unaligned_type_storage_ext& operator =(const unaligned_type_storage_ext& other) + { + storage = other.storage; + + return *this; + } + + unsigned char* storage; + }; ETL_END_PACKED + + //************************************************************************* + /// Unaligned copy + //************************************************************************* + template + class unaligned_copy; + + //************************************************************************* + /// Unaligned copy + /// For integrals. + //************************************************************************* + template + ETL_PACKED_CLASS(unaligned_copy) + { + public: + + typedef typename private_unaligned_type::unaligned_type_storage::storage_type storage_type; + typedef typename private_unaligned_type::unaligned_type_storage::pointer pointer; + typedef typename private_unaligned_type::unaligned_type_storage::const_pointer const_pointer; + + //******************************* + template + static void copy_value_to_store(const T& value, pointer store) + { + memcpy(store, &value, Size_); + +#if ETL_HAS_CONSTEXPR_ENDIANESS + if ETL_IF_CONSTEXPR(Endian_ == etl::endianness::value()) +#else + if (Endian_ != etl::endianness::value()) +#endif + { + etl::reverse(store, store + Size_); + } + } + + //******************************* + template + static void copy_store_to_value(const_pointer store, T& value) + { + memcpy(&value, store, Size_); + +#if ETL_HAS_CONSTEXPR_ENDIANESS + if ETL_IF_CONSTEXPR(Endian == etl::endianness::value()) +#else + if (Endian_ != etl::endianness::value()) +#endif + { + value = etl::reverse_bytes(value); + } + } + + //******************************* + static void copy_store_to_store(const_pointer src, int endian_src, pointer dst) + { + memcpy(dst, src, Size_); + + if (Endian_ != endian_src) + { + etl::reverse(dst, dst + Size_); + } + } + }; ETL_END_PACKED + + //************************************************************************* + /// Unaligned copy + /// For floating point. + //************************************************************************* + template + ETL_PACKED_CLASS(unaligned_copy) + { + public: + + typedef typename private_unaligned_type::unaligned_type_storage::storage_type storage_type; + typedef typename private_unaligned_type::unaligned_type_storage::pointer pointer; + typedef typename private_unaligned_type::unaligned_type_storage::const_pointer const_pointer; + + //******************************* + template + static void copy_value_to_store(const T& value, pointer store) + { + memcpy(store, &value, Size_); + +#if ETL_HAS_CONSTEXPR_ENDIANESS + if ETL_IF_CONSTEXPR(Endian_ == etl::endianness::value()) +#else + if (Endian_ != etl::endianness::value()) +#endif + { + etl::reverse(store, store + Size_); + } + } + + //******************************* + template + static void copy_store_to_value(const_pointer store, T& value) + { + memcpy(&value, store, Size_); + +#if ETL_HAS_CONSTEXPR_ENDIANESS + if ETL_IF_CONSTEXPR(Endian == etl::endianness::value()) +#else + if (Endian_ != etl::endianness::value()) +#endif + { + etl::reverse(reinterpret_cast(&value), reinterpret_cast(&value) + Size_); + } + } + + //******************************* + static void copy_store_to_store(const_pointer src, int endian_src, pointer dst) + { + memcpy(dst, src, Size_); + + if (Endian_ != endian_src) + { + etl::reverse(dst, dst + Size_); + } + } + }; ETL_END_PACKED } //************************************************************************* @@ -227,7 +448,7 @@ namespace etl ///\tparam Endian The endianness of the arithmetic type. //************************************************************************* template - class unaligned_type : public private_unaligned_type::unaligned_type_common + ETL_PACKED_CLASS(unaligned_type) : public private_unaligned_type::unaligned_type_storage { public: @@ -235,47 +456,85 @@ namespace etl typedef T value_type; - typedef typename private_unaligned_type::unaligned_type_common::storage_type storage_type; - typedef typename private_unaligned_type::unaligned_type_common::pointer pointer; - typedef typename private_unaligned_type::unaligned_type_common::const_pointer const_pointer; - typedef typename private_unaligned_type::unaligned_type_common::iterator iterator; - typedef typename private_unaligned_type::unaligned_type_common::const_iterator const_iterator; - typedef typename private_unaligned_type::unaligned_type_common::reverse_iterator reverse_iterator; - typedef typename private_unaligned_type::unaligned_type_common::const_reverse_iterator const_reverse_iterator; + typedef private_unaligned_type::unaligned_copy::value ? false : true> unaligned_copy; - static ETL_CONSTANT int Endian = Endian_; - static ETL_CONSTANT size_t Size = private_unaligned_type::unaligned_type_common::Size; + typedef typename private_unaligned_type::unaligned_type_storage::storage_type storage_type; + typedef typename private_unaligned_type::unaligned_type_storage::pointer pointer; + typedef typename private_unaligned_type::unaligned_type_storage::const_pointer const_pointer; + typedef typename private_unaligned_type::unaligned_type_storage::iterator iterator; + typedef typename private_unaligned_type::unaligned_type_storage::const_iterator const_iterator; + typedef typename private_unaligned_type::unaligned_type_storage::reverse_iterator reverse_iterator; + typedef typename private_unaligned_type::unaligned_type_storage::const_reverse_iterator const_reverse_iterator; + + static ETL_CONSTANT int Endian = Endian_; + static ETL_CONSTANT size_t Size = sizeof(T); //************************************************************************* /// Default constructor //************************************************************************* - ETL_CONSTEXPR unaligned_type() + unaligned_type() { } //************************************************************************* /// Construct from a value. //************************************************************************* - ETL_CONSTEXPR14 unaligned_type(T value) + unaligned_type(T value) { - unaligned_copy::copy(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); + } + + //************************************************************************* + /// Construct from an address. + //************************************************************************* + unaligned_type(const void* address) + { + etl::copy_n(reinterpret_cast(address), sizeof(T), this->storage); + } + + //************************************************************************* + /// Construct from an address and buffer size. + //************************************************************************* + unaligned_type(const void* address, size_t buffer_size) + { + ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::unaligned_type_buffer_size)); + + etl::copy_n(reinterpret_cast(address), sizeof(T), this->storage); + } + + //************************************************************************* + /// Copy constructor + //************************************************************************* + unaligned_type(const unaligned_type& other) + { + unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage); } //************************************************************************* /// Copy constructor //************************************************************************* template - ETL_CONSTEXPR14 unaligned_type(const unaligned_type& other) + unaligned_type(const unaligned_type& other) { - unaligned_copy::copy(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); } //************************************************************************* /// Assignment operator //************************************************************************* - ETL_CONSTEXPR14 unaligned_type& operator =(T value) + unaligned_type& operator =(T value) { - unaligned_copy::copy(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); + + return *this; + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + unaligned_type& operator =(const unaligned_type& other) + { + unaligned_copy::copy_store_to_store(other.data(), Endian_, this->storage); return *this; } @@ -284,9 +543,9 @@ namespace etl /// Assignment operator from other endianness. //************************************************************************* template - ETL_CONSTEXPR14 unaligned_type& operator =(const unaligned_type& other) + unaligned_type& operator =(const unaligned_type& other) { - unaligned_copy::copy(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); return *this; } @@ -294,11 +553,11 @@ namespace etl //************************************************************************* /// Conversion operator //************************************************************************* - ETL_CONSTEXPR14 operator T() const + operator T() const { T value = T(); - unaligned_copy::copy(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -306,430 +565,15 @@ namespace etl //************************************************************************* /// Get the value. //************************************************************************* - ETL_CONSTEXPR14 T value() const + T value() const { T value = T(); - unaligned_copy::copy(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } - - //************************************************************************* - /// Unaligned copy - //************************************************************************* - template - struct unaligned_copy; - - //******************************************* - /// Unaligned copy - /// Size == 1 - //******************************************* - template - struct unaligned_copy - { - //******************************* - static ETL_CONSTEXPR14 void copy(T value, pointer store) - { - store[0] = static_cast(value); - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer store, T& value) - { - value = static_cast(store[0]); - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer src, int /*endian_src*/, unsigned char* dst) - { - dst[0] = src[0]; - } - }; - - //******************************************* - /// Unaligned copy - /// Size == 2 - //******************************************* - template - struct unaligned_copy::value>::type> - { - //******************************* - static ETL_CONSTEXPR14 void copy(T value, unsigned char* store) - { - if (Endian == etl::endianness::value()) - { - store[0] = static_cast(value); - store[1] = static_cast(value >> (1U * CHAR_BIT)); - } - else - { - store[1] = static_cast(value); - store[0] = static_cast(value >> (1U * CHAR_BIT)); - } - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer store, T& value) - { - if (Endian == etl::endianness::value()) - { - value = static_cast(static_cast(store[0])); - value |= static_cast(static_cast(store[1])) << (1U * CHAR_BIT); - } - else - { - value = static_cast(static_cast(store[1])); - value |= static_cast(static_cast(store[0])) << (1U * CHAR_BIT); - } - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer src, int endian_src, unsigned char* dst) - { - if (Endian == endian_src) - { - dst[0] = src[0]; - dst[1] = src[1]; - } - else - { - dst[0] = src[1]; - dst[1] = src[0]; - } - } - }; - - //******************************************* - /// Unaligned copy - /// Size == 4 - /// Integrals - //******************************************* - template - struct unaligned_copy::value>::type> - { - static ETL_CONSTEXPR14 void copy(T value, unsigned char* store) - { - if (Endian == etl::endianness::value()) - { - store[0] = static_cast(value); - store[1] = static_cast(value >> (1U * CHAR_BIT)); - store[2] = static_cast(value >> (2U * CHAR_BIT)); - store[3] = static_cast(value >> (3U * CHAR_BIT)); - } - else - { - store[3] = static_cast(value); - store[2] = static_cast(value >> (1U * CHAR_BIT)); - store[1] = static_cast(value >> (2U * CHAR_BIT)); - store[0] = static_cast(value >> (3U * CHAR_BIT)); - } - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer store, T& value) - { - if (Endian == etl::endianness::value()) - { - value = static_cast(static_cast(store[0])); - value |= static_cast(static_cast(store[1])) << (1U * CHAR_BIT); - value |= static_cast(static_cast(store[2])) << (2U * CHAR_BIT); - value |= static_cast(static_cast(store[3])) << (3U * CHAR_BIT); - } - else - { - value = static_cast(static_cast(store[3])); - value |= static_cast(static_cast(store[2])) << (1U * CHAR_BIT); - value |= static_cast(static_cast(store[1])) << (2U * CHAR_BIT); - value |= static_cast(static_cast(store[0])) << (3U * CHAR_BIT); - } - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer src, int endian_src, unsigned char* dst) - { - if (Endian == endian_src) - { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - } - else - { - dst[0] = src[3]; - dst[1] = src[2]; - dst[2] = src[1]; - dst[3] = src[0]; - } - } - }; - - //******************************************* - /// Unaligned copy - /// Size == 4 - /// Floating point - //******************************************* - template - struct unaligned_copy::value>::type> - { - static void copy(T value, unsigned char* store) - { - memcpy(store, &value, 4U); - - if (Endian != etl::endianness::value()) - { - etl::reverse(store, store + 4U); - } - } - - //******************************* - static void copy(const_pointer store, T& value) - { - unsigned char temp[4U]; - memcpy(temp, store, 4U); - - if (Endian != etl::endianness::value()) - { - etl::reverse(temp, temp + 4U); - } - - memcpy(&value, temp, 4U); - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer src, int endian_src, unsigned char* dst) - { - memcpy(dst, src, 4U); - - if (Endian != endian_src) - { - etl::reverse(dst, dst + 4U); - } - } - }; - - //******************************************* - /// Unaligned copy - /// Size == 8 - /// Integrals - //******************************************* - template - struct unaligned_copy::value>::type> - { - static ETL_CONSTEXPR14 void copy(T value, unsigned char* store) - { - if (Endian == etl::endianness::value()) - { - store[0] = static_cast(value); - store[1] = static_cast(value >> (1U * CHAR_BIT)); - store[2] = static_cast(value >> (2U * CHAR_BIT)); - store[3] = static_cast(value >> (3U * CHAR_BIT)); - store[4] = static_cast(value >> (4U * CHAR_BIT)); - store[5] = static_cast(value >> (5U * CHAR_BIT)); - store[6] = static_cast(value >> (6U * CHAR_BIT)); - store[7] = static_cast(value >> (7U * CHAR_BIT)); - } - else - { - store[7] = static_cast(value); - store[6] = static_cast(value >> (1U * CHAR_BIT)); - store[5] = static_cast(value >> (2U * CHAR_BIT)); - store[4] = static_cast(value >> (3U * CHAR_BIT)); - store[3] = static_cast(value >> (4U * CHAR_BIT)); - store[2] = static_cast(value >> (5U * CHAR_BIT)); - store[1] = static_cast(value >> (6U * CHAR_BIT)); - store[0] = static_cast(value >> (7U * CHAR_BIT)); - } - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer store, T& value) - { - if (Endian == etl::endianness::value()) - { - value = static_cast(static_cast(store[0])); - value |= static_cast(static_cast(store[1])) << (1U * CHAR_BIT); - value |= static_cast(static_cast(store[2])) << (2U * CHAR_BIT); - value |= static_cast(static_cast(store[3])) << (3U * CHAR_BIT); - value |= static_cast(static_cast(store[4])) << (4U * CHAR_BIT); - value |= static_cast(static_cast(store[5])) << (5U * CHAR_BIT); - value |= static_cast(static_cast(store[6])) << (6U * CHAR_BIT); - value |= static_cast(static_cast(store[7])) << (7U * CHAR_BIT); - } - else - { - value = static_cast(static_cast(store[7])); - value |= static_cast(static_cast(store[6])) << (1U * CHAR_BIT); - value |= static_cast(static_cast(store[5])) << (2U * CHAR_BIT); - value |= static_cast(static_cast(store[4])) << (3U * CHAR_BIT); - value |= static_cast(static_cast(store[3])) << (4U * CHAR_BIT); - value |= static_cast(static_cast(store[2])) << (5U * CHAR_BIT); - value |= static_cast(static_cast(store[1])) << (6U * CHAR_BIT); - value |= static_cast(static_cast(store[0])) << (7U * CHAR_BIT); - } - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer src, int endian_src, unsigned char* dst) - { - if (Endian == endian_src) - { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - dst[4] = src[4]; - dst[5] = src[5]; - dst[6] = src[6]; - dst[7] = src[7]; - } - else - { - dst[0] = src[7]; - dst[1] = src[6]; - dst[2] = src[5]; - dst[3] = src[4]; - dst[4] = src[3]; - dst[5] = src[2]; - dst[6] = src[1]; - dst[7] = src[0]; - } - } - }; - - //******************************************* - /// Unaligned copy - /// Size == 8 - /// Floating point - //******************************************* - template - struct unaligned_copy::value>::type> - { - static void copy(T value, unsigned char* store) - { - memcpy(store, &value, 8U); - - if (Endian != etl::endianness::value()) - { - etl::reverse(store, store + 8U); - } - } - - //******************************* - static void copy(const_pointer store, T& value) - { - unsigned char temp[8U]; - memcpy(temp, store, 8U); - - if (Endian != etl::endianness::value()) - { - etl::reverse(temp, temp + 8U); - } - - memcpy(&value, temp, 8U); - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer src, int endian_src, unsigned char* dst) - { - memcpy(dst, src, 8U); - - if (Endian != endian_src) - { - etl::reverse(dst, dst + 8U); - } - } - }; - - //******************************************* - /// Unaligned copy - /// Size == 12 - /// Floating point - //******************************************* - template - struct unaligned_copy::value>::type> - { - static void copy(T value, unsigned char* store) - { - memcpy(store, &value, 12U); - - if (Endian != etl::endianness::value()) - { - etl::reverse(store, store + 12U); - } - } - - //******************************* - static void copy(const_pointer store, T& value) - { - unsigned char temp[12U]; - memcpy(temp, store, 12U); - - if (Endian != etl::endianness::value()) - { - etl::reverse(temp, temp + 12U); - } - - memcpy(&value, temp, 12U); - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer src, int endian_src, unsigned char* dst) - { - memcpy(dst, src, 12U); - - if (Endian != endian_src) - { - etl::reverse(dst, dst + 12U); - } - } - }; - - //******************************************* - /// Unaligned copy - /// Size == 16 - /// Floating point - //******************************************* - template - struct unaligned_copy::value>::type> - { - static void copy(T value, unsigned char* store) - { - memcpy(store, &value, 16U); - - if (Endian != etl::endianness::value()) - { - etl::reverse(store, store + 16U); - } - } - - //******************************* - static void copy(const_pointer store, T& value) - { - unsigned char temp[16U]; - memcpy(temp, store, 16U); - - if (Endian != etl::endianness::value()) - { - etl::reverse(temp, temp + 16U); - } - - memcpy(&value, temp, 16U); - } - - //******************************* - static ETL_CONSTEXPR14 void copy(const_pointer src, int endian_src, unsigned char* dst) - { - memcpy(dst, src, 16U); - - if (Endian != endian_src) - { - etl::reverse(dst, dst + 16U); - } - } - }; - }; + }; ETL_END_PACKED template ETL_CONSTANT int unaligned_type::Endian; @@ -737,6 +581,199 @@ namespace etl template ETL_CONSTANT size_t unaligned_type::Size; + //************************************************************************* + /// unaligned_type_ext + ///\brief Allows an arithmetic type to be stored at an unaligned address. + /// Uses an external buffer. + ///\tparam T The arithmetic type. + ///\tparam Endian The endianness of the arithmetic type. + //************************************************************************* + template + ETL_PACKED_CLASS(unaligned_type_ext) : public private_unaligned_type::unaligned_type_storage_ext + { + public: + + ETL_STATIC_ASSERT(etl::is_integral::value || etl::is_floating_point::value, "Unaligned type must be integral or floating point"); + + template + friend class unaligned_type_ext; + + typedef T value_type; + + typedef private_unaligned_type::unaligned_copy::value ? false : true> unaligned_copy; + + typedef typename private_unaligned_type::unaligned_type_storage_ext::storage_type storage_type; + typedef typename private_unaligned_type::unaligned_type_storage_ext::pointer pointer; + typedef typename private_unaligned_type::unaligned_type_storage_ext::const_pointer const_pointer; + typedef typename private_unaligned_type::unaligned_type_storage_ext::iterator iterator; + typedef typename private_unaligned_type::unaligned_type_storage_ext::const_iterator const_iterator; + typedef typename private_unaligned_type::unaligned_type_storage_ext::reverse_iterator reverse_iterator; + typedef typename private_unaligned_type::unaligned_type_storage_ext::const_reverse_iterator const_reverse_iterator; + + static ETL_CONSTANT int Endian = Endian_; + static ETL_CONSTANT size_t Size = sizeof(T); + + //************************************************************************* + /// Construct from a storage pointer + //************************************************************************* + unaligned_type_ext(pointer storage_) + : private_unaligned_type::unaligned_type_storage_ext(storage_) + { + } + + //************************************************************************* + /// Construct from a value and storage pointer + //************************************************************************* + unaligned_type_ext(T value, pointer storage_) + : private_unaligned_type::unaligned_type_storage_ext(storage_) + { + unaligned_copy::copy_value_to_store(value, this->storage); + } + + //************************************************************************* + /// Copy constructor with storage pointer + //************************************************************************* + template + unaligned_type_ext(const unaligned_type_ext& other, pointer storage_) + : private_unaligned_type::unaligned_type_storage_ext(storage_) + { + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); + } + +#if ETL_USING_CPP11 + //************************************************************************* + /// Move constructor + //************************************************************************* + unaligned_type_ext(unaligned_type_ext&& other) + : private_unaligned_type::unaligned_type_storage_ext(other.storage) + { + other.storage = ETL_NULLPTR; + } + + //************************************************************************* + /// Move constructor + //************************************************************************* + template + unaligned_type_ext(unaligned_type_ext&& other) + : private_unaligned_type::unaligned_type_storage_ext(other.storage) + { + // If we're constructing from a different endianess then we need to reverse the data order. + if (Endian != Endian_Other) + { + etl::reverse(this->begin(), this->end()); + } + + other.storage = ETL_NULLPTR; + } +#endif + + //************************************************************************* + /// Assignment operator + //************************************************************************* + unaligned_type_ext& operator =(T value) + { + unaligned_copy::copy_value_to_store(value, this->storage); + + return *this; + } + + //************************************************************************* + /// Copy assignment operator from other endianness. + //************************************************************************* + unaligned_type_ext& operator =(const unaligned_type_ext& other) + { + unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage); + + return *this; + } + + //************************************************************************* + /// Copy assignment operator from other endianness. + //************************************************************************* + template + unaligned_type_ext& operator =(const unaligned_type_ext& other) + { + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); + + return *this; + } + +#if ETL_USING_CPP11 + //************************************************************************* + /// Move assignment operator from other endianness. + //************************************************************************* + unaligned_type_ext& operator =(unaligned_type_ext&& other) + { + this->storage = other.storage; + other.storage = ETL_NULLPTR; + + return *this; + } + + //************************************************************************* + /// Move assignment operator from other endianness. + //************************************************************************* + template + unaligned_type_ext& operator =(unaligned_type_ext&& other) + { + this->storage = other.storage; + + // If we're assigning from a different endianess then we need to reverse the data order. + if (Endian != Endian_Other) + { + etl::reverse(this->begin(), this->end()); + } + + other.storage = ETL_NULLPTR; + + return *this; + } +#endif + + //************************************************************************* + /// Conversion operator + //************************************************************************* + operator T() const + { + T value = T(); + + unaligned_copy::copy_store_to_value(this->storage, value); + + return value; + } + + //************************************************************************* + /// Get the value. + //************************************************************************* + T value() const + { + T value = T(); + + unaligned_copy::copy_store_to_value(this->storage, value); + + return value; + } + + //************************************************************************* + /// Sets the storage for the type. + //************************************************************************* + void set_storage(pointer storage_) + { + this->storage = storage_; + } + + private: + + unaligned_type_ext() ETL_DELETE; + + }; ETL_END_PACKED + + template + ETL_CONSTANT int unaligned_type_ext::Endian; + + template + ETL_CONSTANT size_t unaligned_type_ext::Size; + #if ETL_HAS_CONSTEXPR_ENDIANNESS // Host order typedef unaligned_type host_char_t; @@ -860,6 +897,132 @@ namespace etl template constexpr size_t unaligned_type_v = etl::unaligned_type::Size; #endif + +#if ETL_HAS_CONSTEXPR_ENDIANNESS + // Host order + typedef unaligned_type_ext host_char_ext_t; + typedef unaligned_type_ext host_schar_ext_t; + typedef unaligned_type_ext host_uchar_ext_t; + typedef unaligned_type_ext host_short_ext_t; + typedef unaligned_type_ext host_ushort_ext_t; + typedef unaligned_type_ext host_int_ext_t; + typedef unaligned_type_ext host_uint_ext_t; + typedef unaligned_type_ext host_long_ext_t; + typedef unaligned_type_ext host_ulong_ext_t; + typedef unaligned_type_ext host_long_long_ext_t; + typedef unaligned_type_ext host_ulong_long_ext_t; +#if ETL_USING_8BIT_TYPES + typedef unaligned_type_ext host_int8_ext_t; + typedef unaligned_type_ext host_uint8_ext_t; +#endif + typedef unaligned_type_ext host_int16_ext_t; + typedef unaligned_type_ext host_uint16_ext_t; + typedef unaligned_type_ext host_int32_ext_t; + typedef unaligned_type_ext host_uint32_ext_t; +#if ETL_USING_64BIT_TYPES + typedef unaligned_type_ext host_int64_ext_t; + typedef unaligned_type_ext host_uint64_ext_t; +#endif + typedef unaligned_type_ext host_float_ext_t; + typedef unaligned_type_ext host_double_ext_t; + typedef unaligned_type_ext host_long_double_ext_t; +#endif + + // Little Endian + typedef unaligned_type_ext le_char_ext_t; + typedef unaligned_type_ext le_schar_ext_t; + typedef unaligned_type_ext le_uchar_ext_t; + typedef unaligned_type_ext le_short_ext_t; + typedef unaligned_type_ext le_ushort_ext_t; + typedef unaligned_type_ext le_int_ext_t; + typedef unaligned_type_ext le_uint_ext_t; + typedef unaligned_type_ext le_long_ext_t; + typedef unaligned_type_ext le_ulong_ext_t; + typedef unaligned_type_ext le_long_long_ext_t; + typedef unaligned_type_ext le_ulong_long_ext_t; + #if ETL_USING_8BIT_TYPES + typedef unaligned_type_ext le_int8_ext_t; + typedef unaligned_type_ext le_uint8_ext_t; + #endif + typedef unaligned_type_ext le_int16_ext_t; + typedef unaligned_type_ext le_uint16_ext_t; + typedef unaligned_type_ext le_int32_ext_t; + typedef unaligned_type_ext le_uint32_ext_t; + #if ETL_USING_64BIT_TYPES + typedef unaligned_type_ext le_int64_ext_t; + typedef unaligned_type_ext le_uint64_ext_t; + #endif + typedef unaligned_type_ext le_float_ext_t; + typedef unaligned_type_ext le_double_ext_t; + typedef unaligned_type_ext le_long_double_ext_t; + + // Big Endian + typedef unaligned_type_ext be_char_ext_t; + typedef unaligned_type_ext be_schar_ext_t; + typedef unaligned_type_ext be_uchar_ext_t; + typedef unaligned_type_ext be_short_ext_t; + typedef unaligned_type_ext be_ushort_ext_t; + typedef unaligned_type_ext be_int_ext_t; + typedef unaligned_type_ext be_uint_ext_t; + typedef unaligned_type_ext be_long_ext_t; + typedef unaligned_type_ext be_ulong_ext_t; + typedef unaligned_type_ext be_long_long_ext_t; + typedef unaligned_type_ext be_ulong_long_ext_t; + #if ETL_USING_8BIT_TYPES + typedef unaligned_type_ext be_int8_ext_t; + typedef unaligned_type_ext be_uint8_ext_t; + #endif + typedef unaligned_type_ext be_int16_ext_t; + typedef unaligned_type_ext be_uint16_ext_t; + typedef unaligned_type_ext be_int32_ext_t; + typedef unaligned_type_ext be_uint32_ext_t; + #if ETL_USING_64BIT_TYPES + typedef unaligned_type_ext be_int64_ext_t; + typedef unaligned_type_ext be_uint64_ext_t; + #endif + typedef unaligned_type_ext be_float_ext_t; + typedef unaligned_type_ext be_double_ext_t; + typedef unaligned_type_ext be_long_double_ext_t; + + // Network Order + typedef be_char_ext_t net_char_ext_t; + typedef be_schar_ext_t net_schar_ext_t; + typedef be_uchar_ext_t net_uchar_ext_t; + typedef be_short_ext_t net_short_ext_t; + typedef be_ushort_ext_t net_ushort_ext_t; + typedef be_int_ext_t net_int_ext_t; + typedef be_uint_ext_t net_uint_ext_t; + typedef be_long_ext_t net_long_ext_t; + typedef be_ulong_ext_t net_ulong_ext_t; + typedef be_long_long_ext_t net_long_long_ext_t; + typedef be_ulong_long_ext_t net_ulong_long_ext_t; +#if ETL_USING_8BIT_TYPES + typedef be_int8_ext_t net_int8_ext_t; + typedef be_uint8_ext_t net_uint8_ext_t; +#endif + typedef be_int16_ext_t net_int16_ext_t; + typedef be_uint16_ext_t net_uint16_ext_t; + typedef be_int32_ext_t net_int32_ext_t; + typedef be_uint32_ext_t net_uint32_ext_t; +#if ETL_USING_64BIT_TYPES + typedef be_int64_ext_t net_int64_ext_t; + typedef be_uint64_ext_t net_uint64_ext_t; +#endif + typedef be_float_ext_t net_float_ext_t; + typedef be_double_ext_t net_double_ext_t; + typedef be_long_double_ext_t net_long_double_ext_t; + +#if ETL_USING_CPP11 + template + using unaligned_type_ext_t = typename etl::unaligned_type_ext::type; +#endif + +#if ETL_USING_CPP17 + template + constexpr size_t unaligned_type_ext_t_v = etl::unaligned_type_ext::Size; +#endif } + + #endif diff --git a/include/etl/uncopyable.h b/include/etl/uncopyable.h new file mode 100644 index 00000000..324e977d --- /dev/null +++ b/include/etl/uncopyable.h @@ -0,0 +1,59 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2024 BMW AG + +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_UNCOPYABLE_INCLUDED +#define ETL_UNCOPYABLE_INCLUDED + +#include "platform.h" + +namespace etl +{ +#if ETL_USING_CPP11 + //*************************************************************************** + /// An uncopyable base class. + /// Can be used to make a class uncopyable by deriving from it. + //*************************************************************************** + class uncopyable + { + public: + + uncopyable(uncopyable const&) = delete; + uncopyable& operator=(uncopyable const&) = delete; + + protected: + + uncopyable() = default; + ~uncopyable() = default; + }; + +#endif +} + +#endif diff --git a/include/etl/unordered_map.h b/include/etl/unordered_map.h index d8ed62a5..54d0bafa 100644 --- a/include/etl/unordered_map.h +++ b/include/etl/unordered_map.h @@ -52,6 +52,8 @@ SOFTWARE. #include "placement_new.h" #include "initializer_list.h" +#include "private/comparator_is_transparent.h" + #include //***************************************************************************** @@ -599,6 +601,18 @@ namespace etl return key_hash_function(key) % number_of_buckets; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns the bucket index for the key. + ///\return The bucket index for the key. + //********************************************************************* + template ::value, int> = 0> + size_type get_bucket_index(const K& key) const + { + return key_hash_function(key) % number_of_buckets; + } +#endif + //********************************************************************* /// Returns the size of the bucket key. ///\return The bucket size of the bucket key. @@ -610,6 +624,20 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns the size of the bucket key. + ///\return The bucket size of the bucket key. + //********************************************************************* + template ::value, int> = 0> + size_type bucket_size(const K& key) const + { + size_t index = bucket(key); + + return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); + } +#endif + //********************************************************************* /// Returns the maximum number of the buckets the container can hold. ///\return The maximum number of the buckets the container can hold. @@ -716,6 +744,52 @@ namespace etl return pbucket->begin()->key_value_pair.second; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a reference to the value at index 'key' + ///\param key The key. + ///\return A reference to the value at index 'key' + //********************************************************************* + template ::value, int> = 0> + mapped_reference operator [](const K& key) + { + // Find the bucket. + bucket_t* pbucket = pbuckets + get_bucket_index(key); + + // Find the first node in the bucket. + local_iterator inode = pbucket->begin(); + + // Walk the list looking for the right one. + while (inode != pbucket->end()) + { + // Equal keys? + if (key_equal_function(key, inode->key_value_pair.first)) + { + // Found a match. + return inode->key_value_pair.second; + } + else + { + ++inode; + } + } + + // Doesn't exist, so add a new one. + // Get a new node. + node_t* node = allocate_data_node(); + node->clear(); + ::new ((void*)etl::addressof(node->key_value_pair.first)) key_type(key); + ::new ((void*)etl::addressof(node->key_value_pair.second)) mapped_type(); + ETL_INCREMENT_DEBUG_COUNT; + + pbucket->insert_after(pbucket->before_begin(), *node); + + adjust_first_last_markers_after_insert(pbucket); + + return pbucket->begin()->key_value_pair.second; + } +#endif + //********************************************************************* /// Returns a reference to the value at index 'key' /// If asserts or exceptions are enabled, emits an etl::unordered_map_out_of_range if the key is not in the range. @@ -786,6 +860,82 @@ namespace etl return begin()->second; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a reference to the value at index 'key' + /// If asserts or exceptions are enabled, emits an etl::unordered_map_out_of_range if the key is not in the range. + ///\param key The key. + ///\return A reference to the value at index 'key' + //********************************************************************* + template ::value, int> = 0> + mapped_reference at(const K& key) + { + // Find the bucket. + bucket_t* pbucket = pbuckets + get_bucket_index(key); + + // Find the first node in the bucket. + local_iterator inode = pbucket->begin(); + + // Walk the list looking for the right one. + while (inode != pbucket->end()) + { + // Equal keys? + if (key_equal_function(key, inode->key_value_pair.first)) + { + // Found a match. + return inode->key_value_pair.second; + } + else + { + ++inode; + } + } + + // Doesn't exist. + ETL_ASSERT(false, ETL_ERROR(unordered_map_out_of_range)); + + return begin()->second; + } +#endif + +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a const reference to the value at index 'key' + /// If asserts or exceptions are enabled, emits an etl::unordered_map_out_of_range if the key is not in the range. + ///\param key The key. + ///\return A const reference to the value at index 'key' + //********************************************************************* + template ::value, int> = 0> + const_mapped_reference at(const K& key) const + { + // Find the bucket. + bucket_t* pbucket = pbuckets + get_bucket_index(key); + + // Find the first node in the bucket. + local_iterator inode = pbucket->begin(); + + // Walk the list looking for the right one. + while (inode != pbucket->end()) + { + // Equal keys? + if (key_equal_function(key, inode->key_value_pair.first)) + { + // Found a match. + return inode->key_value_pair.second; + } + else + { + ++inode; + } + } + + // Doesn't exist. + ETL_ASSERT(false, ETL_ERROR(unordered_map_out_of_range)); + + return begin()->second; + } +#endif + //********************************************************************* /// Assigns values to the unordered_map. /// If asserts or exceptions are enabled, emits unordered_map_full if the unordered_map does not have enough free space. @@ -1040,6 +1190,41 @@ namespace etl return n; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Erases an element. + ///\param key The key to erase. + ///\return The number of elements erased. 0 or 1. + //********************************************************************* + template ::value, int> = 0> + size_t erase(const K& key) + { + size_t n = 0UL; + size_t index = get_bucket_index(key); + + bucket_t& bucket = pbuckets[index]; + + local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = bucket.begin(); + + // Search for the key, if we have it. + while ((icurrent != bucket.end()) && (!key_equal_function(icurrent->key_value_pair.first, key))) + { + ++iprevious; + ++icurrent; + } + + // Did we find it? + if (icurrent != bucket.end()) + { + delete_data_node(iprevious, icurrent, bucket); + n = 1; + } + + return n; + } +#endif + //********************************************************************* /// Erases an element. ///\param ielement Iterator to the element. @@ -1141,6 +1326,19 @@ namespace etl return (find(key) == end()) ? 0 : 1; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Counts an element. + ///\param key The key to search for. + ///\return 1 if the key exists, otherwise 0. + //********************************************************************* + template ::value, int> = 0> + size_t count(const K& key) const + { + return (find(key) == end()) ? 0 : 1; + } +#endif + //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1209,6 +1407,80 @@ namespace etl return end(); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + iterator find(const K& key) + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key_value_pair.first)) + { + return iterator((pbuckets + number_of_buckets), pbucket, inode); + } + + ++inode; + } + } + + return end(); + } +#endif + +#if ETL_USING_CPP11 + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + const_iterator find(const K& key) const + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key_value_pair.first)) + { + return iterator((pbuckets + number_of_buckets), pbucket, inode); + } + + ++inode; + } + } + + return end(); + } +#endif + //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1251,6 +1523,54 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return An iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) + { + iterator f = find(key); + iterator l = f; + + if (l != end()) + { + ++l; + } + + return ETL_OR_STD::pair(f, l); + } +#endif + +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return A const iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) const + { + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + } + + return ETL_OR_STD::pair(f, l); + } +#endif + //************************************************************************* /// Gets the size of the unordered_map. //************************************************************************* @@ -1361,6 +1681,25 @@ namespace etl } #endif + //************************************************************************* + /// Check if the unordered_map contains the key. + //************************************************************************* + bool contains(const_key_reference key) const + { + return find(key) != end(); + } + +#if ETL_USING_CPP11 + //************************************************************************* + /// Check if the unordered_map contains the key. + //************************************************************************* + template ::value, int> = 0> + bool contains(const K& key) const + { + return find(key) != end(); + } +#endif + protected: //********************************************************************* diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index bb1ac4bf..3db0d1f5 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -52,6 +52,8 @@ SOFTWARE. #include "placement_new.h" #include "initializer_list.h" +#include "private/comparator_is_transparent.h" + #include //***************************************************************************** @@ -597,6 +599,18 @@ namespace etl return key_hash_function(key) % number_of_buckets; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns the bucket index for the key. + ///\return The bucket index for the key. + //********************************************************************* + template ::value, int> = 0> + size_type get_bucket_index(const K& key) const + { + return key_hash_function(key) % number_of_buckets; + } +#endif + //********************************************************************* /// Returns the size of the bucket key. ///\return The bucket size of the bucket key. @@ -608,6 +622,20 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns the size of the bucket key. + ///\return The bucket size of the bucket key. + //********************************************************************* + template ::value, int> = 0> + size_type bucket_size(const K& key) const + { + size_t index = bucket(key); + + return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); + } +#endif + //********************************************************************* /// Returns the maximum number of the buckets the container can hold. ///\return The maximum number of the buckets the container can hold. @@ -868,6 +896,43 @@ namespace etl return n; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Erases an element. + ///\param key The key to erase. + ///\return The number of elements erased. + //********************************************************************* + template ::value, int> = 0> + size_t erase(const K& key) + { + size_t n = 0UL; + size_t bucket_id = get_bucket_index(key); + + bucket_t& bucket = pbuckets[bucket_id]; + + local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = bucket.begin(); + + while (icurrent != bucket.end()) + { + if (key_equal_function(icurrent->key_value_pair.first, key)) + { + delete_data_node(iprevious, icurrent, bucket); + ++n; + icurrent = iprevious; + } + else + { + ++iprevious; + } + + ++icurrent; + } + + return n; + } +#endif + //********************************************************************* /// Erases an element. ///\param ielement Iterator to the element. @@ -985,6 +1050,35 @@ namespace etl return n; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Counts an element. + ///\param key The key to search for. + ///\return 1 if the key exists, otherwise 0. + //********************************************************************* + template ::value, int> = 0> + size_t count(const K& key) const + { + size_t n = 0UL; + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + ++n; + + while ((l != end()) && key_equal_function(key, l->first)) + { + ++l; + ++n; + } + } + + return n; + } +#endif + //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1053,6 +1147,80 @@ namespace etl return end(); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + iterator find(const K& key) + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key_value_pair.first)) + { + return iterator((pbuckets + number_of_buckets), pbucket, inode); + } + + ++inode; + } + } + + return end(); + } +#endif + +#if ETL_USING_CPP11 + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + const_iterator find(const K& key) const + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key_value_pair.first)) + { + return const_iterator((pbuckets + number_of_buckets), pbucket, inode); + } + + ++inode; + } + } + + return end(); + } +#endif + //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1105,6 +1273,64 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return An iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) + { + iterator f = find(key); + iterator l = f; + + if (l != end()) + { + ++l; + + while ((l != end()) && key_equal_function(key, l->first)) + { + ++l; + } + } + + return ETL_OR_STD::pair(f, l); + } +#endif + +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return A const iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) const + { + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + + while ((l != end()) && key_equal_function(key, l->first)) + { + ++l; + } + } + + return ETL_OR_STD::pair(f, l); + } +#endif + //************************************************************************* /// Gets the size of the unordered_multimap. //************************************************************************* @@ -1216,6 +1442,25 @@ namespace etl } #endif + //************************************************************************* + /// Check if the unordered_multimap contains the key. + //************************************************************************* + bool contains(const_key_reference key) const + { + return find(key) != end(); + } + +#if ETL_USING_CPP11 + //************************************************************************* + /// Check if the unordered_map contains the key. + //************************************************************************* + template ::value, int> = 0> + bool contains(const K& key) const + { + return find(key) != end(); + } +#endif + protected: //********************************************************************* diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index 212344b9..e0cf1590 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -51,6 +51,8 @@ SOFTWARE. #include "placement_new.h" #include "initializer_list.h" +#include "private/comparator_is_transparent.h" + #include //***************************************************************************** @@ -588,6 +590,18 @@ namespace etl return key_hash_function(key) % number_of_buckets; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns the bucket index for the key. + ///\return The bucket index for the key. + //********************************************************************* + template ::value, int> = 0> + size_type get_bucket_index(const K& key) const + { + return key_hash_function(key) % number_of_buckets; + } +#endif + //********************************************************************* /// Returns the size of the bucket key. ///\return The bucket size of the bucket key. @@ -599,6 +613,20 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns the size of the bucket key. + ///\return The bucket size of the bucket key. + //********************************************************************* + template ::value, int> = 0> + size_type bucket_size(const K& key) const + { + size_t index = bucket(key); + + return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); + } +#endif + //********************************************************************* /// Returns the maximum number of the buckets the container can hold. ///\return The maximum number of the buckets the container can hold. @@ -712,6 +740,79 @@ namespace etl return result; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Inserts a value to the unordered_multiset. + /// If asserts or exceptions are enabled, emits unordered_multiset_full if the unordered_multiset is already full. + ///\param value The value to insert. + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair insert(const K& key) + { + ETL_OR_STD::pair result(end(), false); + + ETL_ASSERT(!full(), ETL_ERROR(unordered_multiset_full)); + + // Get the hash index. + size_t index = get_bucket_index(key); + + // Get the bucket & bucket iterator. + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // The first one in the bucket? + if (bucket.empty()) + { + // Get a new node. + node_t* node = allocate_data_node(); + node->clear(); + ::new (&node->key) value_type(key); + ETL_INCREMENT_DEBUG_COUNT; + + // Just add the pointer to the bucket; + bucket.insert_after(bucket.before_begin(), *node); + adjust_first_last_markers_after_insert(&bucket); + + result.first = iterator((pbuckets + number_of_buckets), pbucket, pbucket->begin()); + result.second = true; + } + else + { + // Step though the bucket looking for a place to insert. + local_iterator inode_previous = bucket.before_begin(); + local_iterator inode = bucket.begin(); + + while (inode != bucket.end()) + { + // Do we already have this key? + if (key_equal_function(inode->key, key)) + { + break; + } + + ++inode_previous; + ++inode; + } + + // Get a new node. + node_t* node = allocate_data_node(); + node->clear(); + ::new (&node->key) value_type(key); + ETL_INCREMENT_DEBUG_COUNT; + + // Add the node to the end of the bucket; + bucket.insert_after(inode_previous, *node); + adjust_first_last_markers_after_insert(&bucket); + ++inode_previous; + + result.first = iterator((pbuckets + number_of_buckets), pbucket, inode_previous); + result.second = true; + } + + return result; + } +#endif + #if ETL_USING_CPP11 //********************************************************************* /// Inserts a value to the unordered_multiset. @@ -846,6 +947,43 @@ namespace etl return n; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Erases an element. + ///\param key The key to erase. + ///\return The number of elements erased. 0 or 1. + //********************************************************************* + template ::value, int> = 0> + size_t erase(const K& key) + { + size_t n = 0UL; + size_t bucket_id = get_bucket_index(key); + + bucket_t& bucket = pbuckets[bucket_id]; + + local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = bucket.begin(); + + while (icurrent != bucket.end()) + { + if (key_equal_function(icurrent->key, key)) + { + delete_data_node(iprevious, icurrent, bucket); + ++n; + icurrent = iprevious; + } + else + { + ++iprevious; + } + + ++icurrent; + } + + return n; + } +#endif + //********************************************************************* /// Erases an element. ///\param ielement Iterator to the element. @@ -963,6 +1101,35 @@ namespace etl return n; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Counts an element. + ///\param key The key to search for. + ///\return 1 if the key exists, otherwise 0. + //********************************************************************* + template ::value, int> = 0> + size_t count(const K& key) const + { + size_t n = 0UL; + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + ++n; + + while ((l != end()) && key_equal_function(key, *l)) + { + ++l; + ++n; + } + } + + return n; + } +#endif + //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -997,6 +1164,43 @@ namespace etl return end(); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + iterator find(const K& key) + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key)) + { + return iterator((pbuckets + number_of_buckets), pbucket, inode); + } + + ++inode; + } + } + + return end(); + } +#endif + //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1031,6 +1235,43 @@ namespace etl return end(); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + const_iterator find(const K& key) const + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key)) + { + return iterator((pbuckets + number_of_buckets), pbucket, inode); + } + + ++inode; + } + } + + return end(); + } +#endif + //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1057,6 +1298,35 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return An iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) + { + iterator f = find(key); + iterator l = f; + + if (l != end()) + { + ++l; + + while ((l != end()) && key_equal_function(key, *l)) + { + ++l; + } + } + + return ETL_OR_STD::pair(f, l); + } +#endif + //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1083,6 +1353,35 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return A const iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) const + { + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + + while ((l != end()) && key_equal_function(key, *l)) + { + ++l; + } + } + + return ETL_OR_STD::pair(f, l); + } +#endif + //************************************************************************* /// Gets the size of the unordered_multiset. //************************************************************************* @@ -1194,6 +1493,25 @@ namespace etl } #endif + //************************************************************************* + /// Check if the unordered_multiset contains the key. + //************************************************************************* + bool contains(key_parameter_t key) const + { + return find(key) != end(); + } + +#if ETL_USING_CPP11 + //************************************************************************* + /// Check if the unordered_map contains the key. + //************************************************************************* + template ::value, int> = 0> + bool contains(const K& key) const + { + return find(key) != end(); + } +#endif + protected: //********************************************************************* diff --git a/include/etl/unordered_set.h b/include/etl/unordered_set.h index 2b426ac5..795eabfd 100644 --- a/include/etl/unordered_set.h +++ b/include/etl/unordered_set.h @@ -52,6 +52,8 @@ SOFTWARE. #include "placement_new.h" #include "initializer_list.h" +#include "private/comparator_is_transparent.h" + #include //***************************************************************************** @@ -589,6 +591,18 @@ namespace etl return key_hash_function(key) % number_of_buckets; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns the bucket index for the key. + ///\return The bucket index for the key. + //********************************************************************* + template ::value, int> = 0> + size_type get_bucket_index(const K& key) const + { + return key_hash_function(key) % number_of_buckets; + } +#endif + //********************************************************************* /// Returns the size of the bucket key. ///\return The bucket size of the bucket key. @@ -600,6 +614,20 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns the size of the bucket key. + ///\return The bucket size of the bucket key. + //********************************************************************* + template ::value, int> = 0> + size_type bucket_size(const K& key) const + { + size_t index = bucket(key); + + return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); + } +#endif + //********************************************************************* /// Returns the maximum number of the buckets the container can hold. ///\return The maximum number of the buckets the container can hold. @@ -730,6 +758,96 @@ namespace etl return result; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Inserts a value to the unordered_set. + /// If asserts or exceptions are enabled, emits unordered_set_full if the unordered_set is already full. + ///\param value The value to insert. + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair insert(const K& key) + { + ETL_OR_STD::pair result(end(), false); + + if (full()) + { + iterator iter = find(key); + if (iter == end()) + { + ETL_ASSERT_FAIL(ETL_ERROR(unordered_set_full)); + } + else + { + result.first = iter; + result.second = false; + return result; + } + } + + // Get the hash index. + size_t index = get_bucket_index(key); + + // Get the bucket & bucket iterator. + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // The first one in the bucket? + if (bucket.empty()) + { + // Get a new node. + node_t* node = allocate_data_node(); + node->clear(); + ::new (&node->key) value_type(key); + ETL_INCREMENT_DEBUG_COUNT; + + // Just add the pointer to the bucket; + bucket.insert_after(bucket.before_begin(), *node); + adjust_first_last_markers_after_insert(&bucket); + + result.first = iterator(pbuckets + number_of_buckets, pbucket, pbucket->begin()); + result.second = true; + } + else + { + // Step though the bucket looking for a place to insert. + local_iterator inode_previous = bucket.before_begin(); + local_iterator inode = bucket.begin(); + + while (inode != bucket.end()) + { + // Do we already have this key? + if (key_equal_function(inode->key, key)) + { + break; + } + + ++inode_previous; + ++inode; + } + + // Not already there? + if (inode == bucket.end()) + { + // Get a new node. + node_t* node = allocate_data_node(); + node->clear(); + ::new (&node->key) value_type(key); + ETL_INCREMENT_DEBUG_COUNT; + + // Add the node to the end of the bucket; + bucket.insert_after(inode_previous, *node); + adjust_first_last_markers_after_insert(&bucket); + ++inode_previous; + + result.first = iterator(pbuckets + number_of_buckets, pbucket, inode_previous); + result.second = true; + } + } + + return result; + } +#endif + #if ETL_USING_CPP11 //********************************************************************* /// Inserts a value to the unordered_set. @@ -892,6 +1010,41 @@ namespace etl return n; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Erases an element. + ///\param key The key to erase. + ///\return The number of elements erased. 0 or 1. + //********************************************************************* + template ::value, int> = 0> + size_t erase(const K& key) + { + size_t n = 0UL; + size_t index = get_bucket_index(key); + + bucket_t& bucket = pbuckets[index]; + + local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = bucket.begin(); + + // Search for the key, if we have it. + while ((icurrent != bucket.end()) && (!key_equal_function(icurrent->key, key))) + { + ++iprevious; + ++icurrent; + } + + // Did we find it? + if (icurrent != bucket.end()) + { + delete_data_node(iprevious, icurrent, bucket); + n = 1; + } + + return n; + } +#endif + //********************************************************************* /// Erases an element. ///\param ielement Iterator to the element. @@ -993,6 +1146,19 @@ namespace etl return (find(key) == end()) ? 0 : 1; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Counts an element. + ///\param key The key to search for. + ///\return 1 if the key exists, otherwise 0. + //********************************************************************* + template ::value, int> = 0> + size_t count(const K& key) const + { + return (find(key) == end()) ? 0 : 1; + } +#endif + //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1061,6 +1227,80 @@ namespace etl return end(); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + iterator find(const K& key) + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key)) + { + return iterator(pbuckets + number_of_buckets, pbucket, inode); + } + + ++inode; + } + } + + return end(); + } +#endif + +#if ETL_USING_CPP11 + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + const_iterator find(const K& key) const + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key)) + { + return iterator(pbuckets + number_of_buckets, pbucket, inode); + } + + ++inode; + } + } + + return end(); + } +#endif + //********************************************************************* /// Returns a range containing all elements with key 'key' in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1103,6 +1343,54 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a range containing all elements with key 'key' in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return An iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) + { + iterator f = find(key); + iterator l = f; + + if (l != end()) + { + ++l; + } + + return ETL_OR_STD::pair(f, l); + } +#endif + +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a range containing all elements with key 'key' in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return A const iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) const + { + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + } + + return ETL_OR_STD::pair(f, l); + } +#endif + //************************************************************************* /// Gets the size of the unordered_set. //************************************************************************* @@ -1214,6 +1502,25 @@ namespace etl } #endif + //************************************************************************* + /// Check if the unordered_set contains the key. + //************************************************************************* + bool contains(key_parameter_t key) const + { + return find(key) != end(); + } + +#if ETL_USING_CPP11 + //************************************************************************* + /// Check if the unordered_map contains the key. + //************************************************************************* + template ::value, int> = 0> + bool contains(const K& key) const + { + return find(key) != end(); + } +#endif + protected: //********************************************************************* diff --git a/include/etl/utility.h b/include/etl/utility.h index 52cf0d37..15b450e8 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -34,6 +34,9 @@ SOFTWARE. #include "platform.h" #include "type_traits.h" +#include "private/tuple_element.h" +#include "private/tuple_size.h" + #if defined(ETL_IN_UNIT_TEST) || ETL_USING_STL #if ETL_USING_CPP11 #include @@ -325,6 +328,33 @@ namespace etl } #endif +#if ETL_USING_CPP11 + //****************************************************************************** + template + struct tuple_element > + { + ETL_STATIC_ASSERT(Index < 2U, "pair has only 2 elements"); + }; + + template + struct tuple_element<0U, ETL_OR_STD::pair > + { + typedef T1 type; + }; + + template + struct tuple_element<1U, ETL_OR_STD::pair > + { + typedef T2 type; + }; + + //****************************************************************************** + template + struct tuple_size> : public etl::integral_constant + { + }; +#endif + //****************************************************************************** template inline void swap(pair& a, pair& b) @@ -332,7 +362,7 @@ namespace etl a.swap(b); } - /// Two pairs of the same type are equal iff their members are equal. + /// Two pairs of the same type are equal if their members are equal. template inline bool operator ==(const pair& a, const pair& b) { @@ -512,13 +542,13 @@ namespace etl template struct make_index_sequence> { - typedef typename make_index_sequence>::type type; + using type = typename make_index_sequence>::type; }; template struct make_index_sequence<0, etl::integer_sequence> { - typedef etl::integer_sequence type; + using type = etl::integer_sequence; }; } @@ -526,9 +556,15 @@ namespace etl template using make_index_sequence = typename private_integer_sequence::make_index_sequence>::type; + template + using make_index_sequence_for = typename private_integer_sequence::make_index_sequence>::type; + //*********************************** template using index_sequence = etl::integer_sequence; + + template + using index_sequence_for = typename etl::make_index_sequence_for; #endif //*************************************************************************** @@ -601,10 +637,13 @@ namespace etl #if ETL_USING_CPP11 //************************************************************************* - /// A function wrapper for free/global functions. + // A function wrapper for free/global functions. + // Deprecated. + // See etl::function_ptr_as_functor for a runtime time wrapper option. + // See etl::function_as_functor for a compile time wrapper option. //************************************************************************* template - class functor + class ETL_DEPRECATED functor { public: @@ -629,18 +668,18 @@ namespace etl /// The pointer to the function. TReturn(*ptr)(TParams...); }; -#endif -#if ETL_USING_CPP11 //***************************************************************************** - // A wrapper for a member function + // Wrap a member function with a static free function. // Creates a static member function that calls the specified member function. + // Deprecated + // See etl::member_function_as_static //***************************************************************************** template class member_function_wrapper; template - class member_function_wrapper + class ETL_DEPRECATED member_function_wrapper { public: @@ -650,12 +689,12 @@ namespace etl return (Instance.*Method)(etl::forward(params)...); } }; -#endif -#if ETL_USING_CPP11 //***************************************************************************** - // A wrapper for a functor + // Wrap a functor with a static free function. // Creates a static member function that calls the specified functor. + // Deprecated + // See etl::functor_as_static //***************************************************************************** template class functor_wrapper; @@ -672,6 +711,104 @@ namespace etl } }; #endif + +#if ETL_USING_CPP17 + //***************************************************************************** + // Wraps a functor with a static free function at compile time. + // Creates a static member 'call' that calls the specified functor. + //***************************************************************************** + template + struct functor_as_static + { + template + static constexpr auto call(TArgs&&... args) + { + return (Instance.operator())(etl::forward(args)...); + } + }; + + //***************************************************************************** + // Wraps a member function with a static free function at compile time. + // Creates a static member 'call' that calls the specified member function. + //***************************************************************************** + template + struct member_function_as_static + { + template + static constexpr auto call(TArgs&&... args) + { + return (Instance.*Method)(etl::forward(args)...); + } + }; + + //***************************************************************************** + // Wraps a member function with a functor at compile time. + // Creates a functor that calls the specified member function. + //***************************************************************************** + template + class member_function_as_functor + { + public: + + template + constexpr auto operator()(TArgs&&... args) const -> decltype((Instance.*Method)(etl::forward(args)...)) + { + return (Instance.*Method)(etl::forward(args)...); + } + }; + + //***************************************************************************** + // Wraps a function with a functor at compile time. + // Creates a functor that calls the specified free function. + //***************************************************************************** + template + class function_as_functor + { + public: + + template + constexpr auto operator()(TArgs&&... args) const -> decltype(Function(etl::forward(args)...)) + { + return Function(etl::forward(args)...); + } + }; +#endif + +#if ETL_USING_CPP11 + //***************************************************************************** + // Wraps a function pointer with a functor at run time. + // Creates a functor that calls the specified free function. + //***************************************************************************** + template + class function_ptr_as_functor; + + template + class function_ptr_as_functor + { + public: + + //********************************* + /// Constructor. + //********************************* + constexpr function_ptr_as_functor(TReturn(*ptr_)(TArgs...)) + : ptr(ptr_) + { + } + + //********************************* + /// Const function operator. + //********************************* + constexpr TReturn operator()(TArgs... args) const + { + return ptr(etl::forward(args)...); + } + + private: + + /// The pointer to the function. + TReturn(*ptr)(TArgs...); + }; +#endif } #endif diff --git a/include/etl/vector.h b/include/etl/vector.h index 80994bd5..f2c1b646 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -47,7 +47,6 @@ SOFTWARE. #include "functional.h" #include "static_assert.h" #include "placement_new.h" -#include "algorithm.h" #include "initializer_list.h" #include diff --git a/include/etl/version.h b/include/etl/version.h index db5ed6d7..62fc3f73 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,8 +39,8 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 20 -#define ETL_VERSION_MINOR 39 -#define ETL_VERSION_PATCH 4 +#define ETL_VERSION_MINOR 40 +#define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRING(ETL_VERSION_MAJOR) "." ETL_STRING(ETL_VERSION_MINOR) "." ETL_STRING(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_WIDE_STRING(ETL_VERSION_MAJOR) L"." ETL_WIDE_STRING(ETL_VERSION_MINOR) L"." ETL_WIDE_STRING(ETL_VERSION_PATCH) diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 683359de..90325b71 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -46,7 +46,7 @@ namespace etl { inline namespace string_literals { - constexpr etl::wstring_view operator ""_sv(const wchar_t* str, size_t length) noexcept + inline constexpr etl::wstring_view operator ""_sv(const wchar_t* str, size_t length) noexcept { return etl::wstring_view{ str, length }; } @@ -227,6 +227,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + wstring& operator = (const etl::wstring_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -366,8 +376,8 @@ namespace etl #endif //************************************************************************* - /// From wstring_view. - ///\param view The wstring_view. + /// From string_view. + ///\param view The string_view. //************************************************************************* explicit wstring_ext(const etl::wstring_view& view, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) @@ -388,7 +398,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -412,6 +421,16 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + wstring_ext& operator = (const etl::wstring_view& view) + { + this->assign(view); + + return *this; + } + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/library.json b/library.json index 12bca01e..86f93c6c 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "20.39.4", + "version": "20.40.0", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 99401ff4..0e051388 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=20.39.4 +version=20.40.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 97daedfd..262dcbbb 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,4 +1,68 @@ =============================================================================== +20.40.0 + +Updates: +Added new C++17 function wrappers +Simplified definition of is_base_of +Fixed static definition for etl::string +Redefined ETL_DEPRECATED +Updated nth_type to handle a type list of zero length +Updated Github Actions to checkout@v4 +Added make_delegate for C++17 +Added starts_with and ends_with to basic_string +Made construction from std::basic_string_view explicit +Added contains member function to string_view +Fixed possible null dereference for etl::multi_span operator -> +Fixed shadowing warnings +Changed etl::mem_cast to support bidirectional iterators +Make 'packed' have better cross platform functionality + +Fixes: +#937 ETL_USING_LEGACY_VARIANT Is always getting evaluated to 1 +#940 Allow etl::observer notification without argument +#942 Warning on pragma c++20-compat +#951 Can't get call_if to work because of etl::optional +#956 Fix build error (etl::circular_buffer) +#957 Support heterogenous lookup for maps +#959 Treat bitset with size_type +#972 Template not allowed warning in parameter pack +#979 QueuedMessageRouter does not work : message are not sent to queue +#980 Documentation clarification: Add link from endianess to unaligned_type +#982 Added return to etl::optional emplace, fixed typo +#984 Update Base64 Documentation +#986 Added const iterators to span +#987 Fix test loop +#992 Return reference from emplace() in etl::queue. Added return reference from stack::emplace +#993 Need "lighter weight" ETL_ASSERT +#997 Request: operator[ ] for containers can be configured to emit an exception +#1000 Make ETL_TYPEDEF Trivially Copyable +#1017 etl::max_element has undefined behavior if the range is empty +#1016 Allow compile time CRC calculation +#1019 UB when passing a temporary lambda to a delegate +#1022 Request: Add option to disable non-lock-free atomics - Added is_always_lock_free member constant to etl::atomic +#1030 Modify etl::message_packet to not require polymorphic messages +#1031 etl::string is invalid if calling assign() with itself. Added additional checks for self assignment. +#1032 Tasking Compiler Failure For parameter_pack.h + +Pull Requests: +#947 Remove unused git submodule config +#965 Fix accident creation of a delegate to an rvalue delegate when copying/assigning from delegate with mismatching signature +#985 Add uncopyable.h, class uncopyable +#986 Added const iterators to span +#989 Packed unaligned_type +#990 Add contains() method to etl::unordered_map and etl::unordered_set +#992 Return reference from emplace() in etl::queue +#999 Add at_address() to etl::unaligned_type. Added etl::unaligned_type_ext instead at_address() +#1001 Add max_item_size() to etl::ipool +#1002 Add singleton_base +#1005 Fixed memory.h: mem_copy, mem_move, mem_compare for pointers to const +#1006 Fix arm64 signed char +#1007 Fix fixed extent span empty() +#1021 Some minor cleanup changes +#1014 Added missing rational arithmetic functions from +#1027 Add etl::make_span() + +=============================================================================== 20.39.4 #948 Bug in queue pop can break queue.empty() @@ -13,6 +77,8 @@ Removed C++11 restriction on etl::observer::notification Fixes: #917 unaligned_type doesn't compile with floating point types +#923 Missing equality operator for class expected +#930 Unused parameter warnings Pull Requests: #946 Make include paths to private files relative diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 87fe5d39..bac99736 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5.0) +cmake_minimum_required(VERSION 3.10.0) project(etl_unit_tests LANGUAGES CXX) #include(FetchContent) @@ -410,6 +410,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") -Wuseless-cast -Wshadow -Wnull-dereference + -g ) endif () diff --git a/test/data.h b/test/data.h index 9f5bf7f0..4e352431 100644 --- a/test/data.h +++ b/test/data.h @@ -209,6 +209,13 @@ public: other.valid = false; } + TestDataM(const TestDataM&& other) noexcept + : value(std::move(other.value)) + , valid(true) + { + other.valid = false; + } + virtual ~TestDataM() { valid = false; @@ -249,8 +256,8 @@ public: return valid; } - T value; - bool valid; + T value; + mutable bool valid; private: diff --git a/test/etl_error_handler/assert_function/CMakeLists.txt b/test/etl_error_handler/assert_function/CMakeLists.txt new file mode 100644 index 00000000..e996a4e3 --- /dev/null +++ b/test/etl_error_handler/assert_function/CMakeLists.txt @@ -0,0 +1,124 @@ +cmake_minimum_required(VERSION 3.5.0) +project(etl_error_handler_unit_tests) + +add_definitions(-DETL_DEBUG) +add_definitions(-DETL_USE_ASSERT_FUNCTION) +add_definitions(-DETL_VERBOSE_ERRORS) + +include_directories(${PROJECT_SOURCE_DIR}/../../../include) + +set(TEST_SOURCE_FILES + assert_function.cpp + test_error_handler.cpp + ) + +add_executable(etl_tests + ${TEST_SOURCE_FILES} + ) + +if (ETL_CXX_STANDARD MATCHES "98") + message(STATUS "Compiling for C++98") + set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98) +elseif (ETL_CXX_STANDARD MATCHES "03") + message(STATUS "Compiling for C++98") + set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98) +elseif (ETL_CXX_STANDARD MATCHES "11") + message(STATUS "Compiling for C++11") + set_property(TARGET etl_tests PROPERTY CXX_STANDARD 11) +elseif (ETL_CXX_STANDARD MATCHES "14") + message(STATUS "Compiling for C++14") + set_property(TARGET etl_tests PROPERTY CXX_STANDARD 14) +elseif (ETL_CXX_STANDARD MATCHES "17") + message(STATUS "Compiling for C++17") + set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17) +else() + message(STATUS "Compiling for C++20") + set_property(TARGET etl_tests PROPERTY CXX_STANDARD 20) +endif() + +if (ETL_OPTIMISATION MATCHES "-O1") + message(STATUS "Compiling with -O1 optimisations") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1") +endif() + +if (ETL_OPTIMISATION MATCHES "-O2") + message(STATUS "Compiling with -O2 optimisations") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2") +endif() + +if (ETL_OPTIMISATION MATCHES "-O3") + message(STATUS "Compiling with -O3 optimisations") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") +endif() + +target_include_directories(etl_tests + PUBLIC + ${CMAKE_CURRENT_LIST_DIR} + ) + +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + message(STATUS "Using GCC compiler") +endif () + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + message(STATUS "Using Clang compiler") +endif () + +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + target_compile_options(etl_tests + PRIVATE + -fno-omit-frame-pointer + -fno-common + -Wno-deprecated-declarations + -Wall + -Wextra + -Werror + -Wfloat-equal + -Wuseless-cast + -Wshadow + -Wnull-dereference + ) +endif () + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_options(etl_tests + PRIVATE + -fno-omit-frame-pointer + -fno-common + -Wno-deprecated-declarations + -Wall + -Wextra + -Werror + -Wfloat-equal + -Wshadow + -Wnull-dereference + ) +endif () + +if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + if (ETL_ENABLE_SANITIZER MATCHES "ON") + message(STATUS "Compiling with Sanitizer enabled") + # MinGW doesn't presently support sanitization + if (NOT MINGW) + target_compile_options(etl_tests + PRIVATE + -fsanitize=address,undefined,bounds + ) + + target_link_options(etl_tests + PRIVATE + -fsanitize=address,undefined,bounds + ) + endif() + endif () +endif () + +# Enable the 'make test' CMake target using the executable defined above +add_test(etl_error_handler_unit_tests etl_tests) + +# Since ctest will only show you the results of the single executable +# define a target that will output all of the failing or passing tests +# as they appear from UnitTest++ +add_custom_target(test_verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose) + + diff --git a/test/etl_error_handler/assert_function/assert_function.cpp b/test/etl_error_handler/assert_function/assert_function.cpp new file mode 100644 index 00000000..a9827650 --- /dev/null +++ b/test/etl_error_handler/assert_function/assert_function.cpp @@ -0,0 +1,3 @@ + +#include "etl/exception.h" + diff --git a/test/etl_error_handler/assert_function/assert_function.h b/test/etl_error_handler/assert_function/assert_function.h new file mode 100644 index 00000000..e31f2c77 --- /dev/null +++ b/test/etl_error_handler/assert_function/assert_function.h @@ -0,0 +1,5 @@ +#include "etl/exception.h" + +extern void AssertFunction(const etl::exception& /*e*/); + +#define ETL_ASSERT_FUNCTION AssertFunction diff --git a/test/etl_error_handler/assert_function/etl_profile.h b/test/etl_error_handler/assert_function/etl_profile.h new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/etl_error_handler/assert_function/etl_profile.h @@ -0,0 +1 @@ + diff --git a/test/etl_error_handler/assert_function/test_error_handler.cpp b/test/etl_error_handler/assert_function/test_error_handler.cpp new file mode 100644 index 00000000..fa767c50 --- /dev/null +++ b/test/etl_error_handler/assert_function/test_error_handler.cpp @@ -0,0 +1,167 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/std +https://www.etlcpp.com + +Copyright(c) 2022 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "etl/error_handler.h" + +#include +#include + +#include "assert_function.h" + +int assert_return_count = 0; +int assert_count = 0; + +//***************************************************************************** +void assert_function(const etl::exception& e) +{ + std::cout << "Exception " << e.what() << " raised\n"; + + ++assert_count; +} + +//***************************************************************************** +class test_exception : public etl::exception +{ +public: + + test_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } +}; + +//***************************************************************************** +class test_exception_1 : public test_exception +{ +public: + + test_exception_1(string_type file_name_, numeric_type line_number_) + : test_exception(ETL_ERROR_TEXT("Test Exception 1", "1A"), file_name_, line_number_) + { + } +}; + +//***************************************************************************** +void Assert(bool state) +{ + ETL_ASSERT(state, ETL_ERROR(test_exception_1)); +} + +//***************************************************************************** +void AssertFail() +{ + ETL_ASSERT_FAIL(ETL_ERROR(test_exception_1)); +} + +//***************************************************************************** +void AssertAndReturn(bool state) +{ + ETL_ASSERT_OR_RETURN(state, ETL_ERROR(test_exception_1)); + + ++assert_return_count; +} + +//***************************************************************************** +void AssertFailAndReturn() +{ + ETL_ASSERT_FAIL_AND_RETURN(ETL_ERROR(test_exception_1)); + + ++assert_return_count; +} + +//***************************************************************************** +bool AssertAndReturnValue(bool state) +{ + ETL_ASSERT_OR_RETURN_VALUE(state, ETL_ERROR(test_exception_1), true); + + ++assert_return_count; + return false; +} + +//***************************************************************************** +bool AssertFailAndReturnValue() +{ + ETL_ASSERT_FAIL_AND_RETURN_VALUE(ETL_ERROR(test_exception_1), true); + + ++assert_return_count; + return false; +} + +//***************************************************************************** +int main() +{ + etl::set_assert_function(assert_function); + + Assert(false); + Assert(true); + AssertFail(); + + AssertAndReturn(false); + AssertAndReturn(true); + AssertFailAndReturn(); + + if (AssertAndReturnValue(false)) + { + ++assert_return_count; + } + + if (AssertAndReturnValue(true)) + { + ++assert_return_count; + } + + if (AssertFailAndReturnValue()) + { + ++assert_return_count; + } + + bool assert_count_passed = (assert_count == 6); + + if (assert_count_passed) + { + std::cout << "Log Count Passed\n"; + } + else + { + std::cout << "Log Count Failed\n"; + } + + bool return_count_passed = (assert_return_count == 4); + + if (return_count_passed) + { + std::cout << "Return Count Passed\n"; + } + else + { + std::cout << "Return Count Failed\n"; + } + + return (assert_count_passed && return_count_passed) ? 0 : 1; +} + diff --git a/test/etl_error_handler/log_errors/CMakeLists.txt b/test/etl_error_handler/log_errors/CMakeLists.txt index 4019cf25..b76f17bb 100644 --- a/test/etl_error_handler/log_errors/CMakeLists.txt +++ b/test/etl_error_handler/log_errors/CMakeLists.txt @@ -67,6 +67,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") PRIVATE -fno-omit-frame-pointer -fno-common + -fno-exceptions -Wall -Wextra -Werror @@ -82,6 +83,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") PRIVATE -fno-omit-frame-pointer -fno-common + -fno-exceptions -Wall -Wextra -Werror diff --git a/test/run-syntax-checks.sh b/test/run-syntax-checks.sh index d2d06c7a..92efb1b9 100644 --- a/test/run-syntax-checks.sh +++ b/test/run-syntax-checks.sh @@ -8,6 +8,7 @@ configuration_name="Configuration Name Not Set" FailColour='\033[38;2;255;128;128m' PassColour='\033[38;2;128;255;128m' TitleColour='\033[38;2;107;210;255m' +HelpColour='\033[38;2;250;180;250m' NoColour='\033[0m' ParseGitBranch() @@ -22,23 +23,36 @@ SetCxxStandard() SetConfigurationName() { - configuration_name=$1 + configuration_name=$1 } PrintHeader() { echo "$TitleColour" echo "============================================================================" | tee -a log.txt - echo " Configuration : $configuration_name" | tee -a log.txt - echo " Compiler : $compiler " | tee -a log.txt - echo " Language : C++$cxx_standard " | tee -a log.txt - echo " ETL version : $etl_version " | tee -a log.txt - echo " Git branch : $(ParseGitBranch) " | tee -a log.txt - echo " Processes : ${CMAKE_BUILD_PARALLEL_LEVEL}" | tee -a log.txt + echo " Configuration : $configuration_name" | tee -a log.txt + echo " Compiler : $compiler " | tee -a log.txt + echo " Language : C++$cxx_standard " | tee -a log.txt + echo " Compiler select : $compiler_enabled " | tee -a log.txt + echo " ETL version : $etl_version " | tee -a log.txt + echo " Git branch : $(ParseGitBranch) " | tee -a log.txt + echo " Processes : ${CMAKE_BUILD_PARALLEL_LEVEL}" | tee -a log.txt echo "============================================================================" | tee -a log.txt echo "$NoColour" } +PrintHelp() +{ + echo "$HelpColour" + echo "----------------------------------------------------------------------------------" + echo " Syntax : ./runtests.sh " + echo " C++ Standard : a, 03, 11, 14, 17 or 20 (a = All standards) " + echo " Threads : Number of threads to use. Default = 4 " + echo " Compiler select : gcc or clang. Default All compilers " + echo "----------------------------------------------------------------------------------" + echo "$NoColour" +} + PassedCompilation() { echo "$PassColour" @@ -70,12 +84,46 @@ cd syntax_check || exit 1 echo "" > log.txt #****************************************************************************** -# Set the number of concurrent processes to use. +# Set the language standard. #****************************************************************************** -if [ $# -eq 0 ]; then +if [ "$1" = "3" ]; then + requested_cxx_standard="03" +elif [ "$1" = "03" ]; then + requested_cxx_standard="03" +elif [ "$1" = "11" ]; then + requested_cxx_standard="11" +elif [ "$1" = "14" ]; then + requested_cxx_standard="14" +elif [ "$1" = "17" ]; then + requested_cxx_standard="17" +elif [ "$1" = "20" ]; then + requested_cxx_standard="20" +elif [ "$1" = "A" ]; then + requested_cxx_standard="All" +elif [ "$1" = "a" ]; then + requested_cxx_standard="All" +else + PrintHelp +fi + +#****************************************************************************** +# Set the number of concurrent processes to use. Default 4 +#****************************************************************************** +if [ $# -le 1 ]; then export CMAKE_BUILD_PARALLEL_LEVEL=4 else - export CMAKE_BUILD_PARALLEL_LEVEL=$1 + export CMAKE_BUILD_PARALLEL_LEVEL=$2 +fi + +#****************************************************************************** +# Set the compiler enable. Default GCC and Clang +#****************************************************************************** +if [ "$3" = "gcc" ]; then + compiler_enabled="gcc" +elif [ "$3" = "clang" ]; then + compiler_enabled="clang" +else + compiler_enabled="All compilers" fi #****************************************************************************** @@ -91,17 +139,17 @@ gcc_compiler=$(g++ --version | grep g++) clang_compiler=$(clang++ --version | grep clang) ############################################################################### -cd c++03 || exit 1 - +if [ "$requested_cxx_standard" = "03" ] || [ "$requested_cxx_standard" = "All" ]; then SetCxxStandard "03 (98)" +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -109,14 +157,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -124,14 +174,16 @@ else FailedCompilation exit $? fi +fi -##SetConfigurationName "No STL - User defined traits" +#if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then +#SetConfigurationName "No STL - User defined traits" #compiler=$gcc_compiler # PrintHeader #rm -rdf bgcc #rm -rdf bclang #cmake -E make_directory bgcc bclang -#CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +#CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. #cmake --build bgcc #if [ $? -eq 0 ]; then # PassedCompilation @@ -139,14 +191,16 @@ fi # FailedCompilation # exit $? #fi +#fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Built-in traits" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -154,14 +208,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Built-in traits" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -169,14 +225,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -184,14 +242,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -199,14 +259,16 @@ else FailedCompilation exit $? fi +fi +#if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then #SetConfigurationName "No STL - User defined traits" #compiler=$clang_compiler #PrintHeader #rm -rdf bgcc #rm -rdf bclang #cmake -E make_directory bgcc bclang -#CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +#CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. #cmake --build bclang #if [ $? -eq 0 ]; then # PassedCompilation @@ -214,14 +276,16 @@ fi # FailedCompilation # exit $? #fi +#fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Built-in traits" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -229,14 +293,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Built-in traits" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -244,19 +310,23 @@ else FailedCompilation exit $? fi +fi + +fi ############################################################################### -cd ../c++11 || exit 1 +if [ "$requested_cxx_standard" = "11" ] || [ "$requested_cxx_standard" = "All" ]; then SetCxxStandard "11" +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -264,14 +334,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Force C++03" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -279,14 +351,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -294,14 +368,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Force C++03" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -309,14 +385,16 @@ else FailedCompilation exit $? fi +fi +#if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then #SetConfigurationName "No STL - User defined traits" #compiler=$gcc_compiler #PrintHeader #rm -rdf bgcc #rm -rdf bclang #cmake -E make_directory bgcc bclang -#CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +#CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. #cmake --build bgcc #if [ $? -eq 0 ]; then # PassedCompilation @@ -324,14 +402,16 @@ fi # FailedCompilation # exit $? #fi +#fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Built-in traits" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -339,14 +419,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Built-in traits" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -354,14 +436,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -369,14 +453,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Force C++03" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -384,14 +470,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -399,14 +487,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Force C++03" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -414,14 +504,16 @@ else FailedCompilation exit $? fi +fi +#if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then #SetConfigurationName "No STL - User defined traits" #compiler=$clang_compiler #PrintHeader #rm -rdf bgcc #rm -rdf bclang #cmake -E make_directory bgcc bclang -##CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +##CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. #cmake --build bclang #if [ $? -eq 0 ]; then # PassedCompilation @@ -429,14 +521,16 @@ fi # FailedCompilation # exit $? #fi +#fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Built-in traits" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -444,14 +538,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Built-in traits" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -459,19 +555,22 @@ else FailedCompilation exit $? fi +fi + +fi ############################################################################### -cd ../c++14 || exit 1 - +if [ "$requested_cxx_standard" = "14" ] || [ "$requested_cxx_standard" = "All" ]; then SetCxxStandard "14" +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -479,14 +578,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Force C++03" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -494,14 +595,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -509,14 +612,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Force C++03" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -524,14 +629,16 @@ else FailedCompilation exit $? fi +fi +#if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then #SetConfigurationName "No STL - User defined traits" #compiler=$gcc_compiler #PrintHeader #rm -rdf bgcc #rm -rdf bclang #cmake -E make_directory bgcc bclang -#CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +#CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. #cmake --build bgcc #if [ $? -eq 0 ]; then # PassedCompilation @@ -539,14 +646,16 @@ fi # FailedCompilation # exit $? #fi +#fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Built-in traits" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -554,14 +663,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Built-in traits" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -569,14 +680,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -584,14 +697,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Force C++03" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -599,14 +714,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -614,14 +731,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Force C++03" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -629,14 +748,16 @@ else FailedCompilation exit $? fi +fi +#if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then #SetConfigurationName "No STL - User defined traits" #compiler=$clang_compiler #PrintHeader #rm -rdf bgcc #rm -rdf bclang #cmake -E make_directory bgcc bclang -##CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +##CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. #cmake --build bclang #if [ $? -eq 0 ]; then # PassedCompilation @@ -644,14 +765,16 @@ fi # FailedCompilation # exit $? #fi +#fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Built-in traits" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -659,14 +782,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Built-in traits" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -674,19 +799,22 @@ else FailedCompilation exit $? fi +fi + +fi ############################################################################### -cd ../c++17 || exit 1 - +if [ "$requested_cxx_standard" = "17" ] || [ "$requested_cxx_standard" = "All" ]; then SetCxxStandard "17" +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -694,14 +822,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Force C++03" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -709,14 +839,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -724,14 +856,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Force C++03" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -739,14 +873,16 @@ else FailedCompilation exit $? fi +fi +#if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then #SetConfigurationName "No STL - User defined traits" #compiler=$gcc_compiler #PrintHeader #rm -rdf bgcc #rm -rdf bclang #cmake -E make_directory bgcc bclang -#CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +#CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. #cmake --build bgcc #if [ $? -eq 0 ]; then # PassedCompilation @@ -754,14 +890,16 @@ fi # FailedCompilation # exit $? #fi +#fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Built-in traits" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -769,14 +907,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Built-in traits" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -784,14 +924,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -799,14 +941,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Force C++03" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -814,14 +958,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -829,14 +975,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Force C++03" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -844,14 +992,16 @@ else FailedCompilation exit $? fi +fi +#if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then #SetConfigurationName "No STL - User defined traits" #compiler=$clang_compiler #PrintHeader #rm -rdf bgcc #rm -rdf bclang #cmake -E make_directory bgcc bclang -#CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +#CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. #cmake --build bclang #if [ $? -eq 0 ]; then # PassedCompilation @@ -859,14 +1009,16 @@ fi # FailedCompilation # exit $? #fi +#fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Built-in traits" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -874,14 +1026,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Built-in traits" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -889,19 +1043,22 @@ else FailedCompilation exit $? fi +fi + +fi ############################################################################### -cd ../c++20 || exit 1 - +if [ "$requested_cxx_standard" = "20" ] || [ "$requested_cxx_standard" = "All" ]; then SetCxxStandard "20" +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -909,14 +1066,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Force C++03" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -924,14 +1083,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -939,14 +1100,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Force C++03" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -954,14 +1117,16 @@ else FailedCompilation exit $? fi +fi +#if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then #SetConfigurationName "No STL - User defined traits" #compiler=$gcc_compiler #PrintHeader #rm -rdf bgcc #rm -rdf bclang #cmake -E make_directory bgcc bclang -#CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +#CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. #cmake --build bgcc #if [ $? -eq 0 ]; then # PassedCompilation @@ -969,14 +1134,16 @@ fi # FailedCompilation # exit $? #fi +#fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Built-in traits" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -984,14 +1151,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Built-in traits" compiler=$gcc_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -999,14 +1168,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -1014,14 +1185,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Force C++03" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -1029,14 +1202,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -1044,14 +1219,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Force C++03" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bclang if [ $? -eq 0 ]; then PassedCompilation @@ -1059,14 +1236,16 @@ else FailedCompilation exit $? fi +fi +#if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then #SetConfigurationName "No STL - User defined traits" #compiler=$clang_compiler #PrintHeader #rm -rdf bgcc #rm -rdf bclang #cmake -E make_directory bgcc bclang -#CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +#CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=ON -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. #cmake --build bclang #if [ $? -eq 0 ]; then # PassedCompilation @@ -1074,14 +1253,16 @@ fi # FailedCompilation # exit $? #fi +#fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "STL - Built-in traits" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -1089,14 +1270,16 @@ else FailedCompilation exit $? fi +fi +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then SetConfigurationName "No STL - Built-in traits" compiler=$clang_compiler PrintHeader rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang -CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=$cxx_standard .. cmake --build bgcc if [ $? -eq 0 ]; then PassedCompilation @@ -1104,5 +1287,8 @@ else FailedCompilation exit $? fi +fi + +fi ChecksCompleted diff --git a/test/run-tests.sh b/test/run-tests.sh index cb5a9d12..fbd01519 100644 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -38,14 +38,15 @@ PrintHeader() { echo "$TitleColour" echo "============================================================================" | tee -a log.txt - echo " Configuration : $configuration_name" | tee -a log.txt - echo " Compiler : $compiler " | tee -a log.txt - echo " Language : C++$cxx_standard " | tee -a log.txt - echo " Optimisation : $opt " | tee -a log.txt - echo " Sanitizer : $sanitize " | tee -a log.txt - echo " ETL version : $etl_version " | tee -a log.txt - echo " Git branch : $(ParseGitBranch) " | tee -a log.txt - echo " Processes : ${CMAKE_BUILD_PARALLEL_LEVEL}" | tee -a log.txt + echo " Configuration : $configuration_name" | tee -a log.txt + echo " Compiler : $compiler " | tee -a log.txt + echo " Language : C++$cxx_standard " | tee -a log.txt + echo " Optimisation : $opt " | tee -a log.txt + echo " Sanitizer : $sanitize " | tee -a log.txt + echo " Compiler select : $compiler_enabled " | tee -a log.txt + echo " ETL version : $etl_version " | tee -a log.txt + echo " Git branch : $(ParseGitBranch) " | tee -a log.txt + echo " Processes : ${CMAKE_BUILD_PARALLEL_LEVEL}" | tee -a log.txt echo "============================================================================" | tee -a log.txt echo "$NoColour" } @@ -53,13 +54,14 @@ PrintHeader() PrintHelp() { echo "$HelpColour" - echo "----------------------------------------------------------------------------------" - echo " Syntax : ./runtests.sh " - echo " C++ Standard : 11, 14, 17 or 20 " - echo " Optimisation : 0, 1, 2 or 3. Default = 0 " - echo " Threads : Number of threads to use. Default = 4 " - echo " Sanitizer : S enables sanitizer checks. Default disabled " - echo "----------------------------------------------------------------------------------" + echo "--------------------------------------------------------------------------------------------" + echo " Syntax : ./runtests.sh " + echo " C++ Standard : 11, 14, 17 or 20 " + echo " Optimisation : 0, 1, 2 or 3. Default = 0 " + echo " Threads : Number of threads to use. Default = 4 " + echo " Sanitizer : s enables sanitizer checks, n disables. Default disabled " + echo " Compiler : gcc or clang. Default All compilers " + echo "--------------------------------------------------------------------------------------------" echo "$NoColour" } @@ -153,10 +155,23 @@ fi #****************************************************************************** # Set the sanitizer enable. Default OFF #****************************************************************************** -if [ "$4" = "S" ]; then - sanitize="ON" +if [ "$4" = "s" ]; then + sanitize="On" +elif [ "$4" = "n" ]; then + sanitize="Off" else - sanitize="OFF" + sanitize="Off" +fi + +#****************************************************************************** +# Set the compiler enable. Default GCC and Clang +#****************************************************************************** +if [ "$5" = "gcc" ]; then + compiler_enabled="gcc" +elif [ "$5" = "clang" ]; then + compiler_enabled="clang" +else + compiler_enabled="All compilers" fi #****************************************************************************** @@ -174,6 +189,7 @@ clang_compiler=$(clang++ --version | grep clang) #****************************************************************************** # GCC #****************************************************************************** +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$gcc_compiler SetConfigurationName "STL" PrintHeader @@ -193,8 +209,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$gcc_compiler SetConfigurationName "STL - Non-virtual messages" PrintHeader @@ -214,8 +232,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$gcc_compiler SetConfigurationName "STL - Force C++03" PrintHeader @@ -235,8 +255,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$gcc_compiler SetConfigurationName "No STL" PrintHeader @@ -256,8 +278,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$gcc_compiler SetConfigurationName "No STL - Force C++03" PrintHeader @@ -277,10 +301,12 @@ else FailedTests exit $? fi +fi #****************************************************************************** # CLANG #****************************************************************************** +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$clang_compiler SetConfigurationName "STL" PrintHeader @@ -300,8 +326,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$clang_compiler SetConfigurationName "STL - Force C++03" PrintHeader @@ -321,8 +349,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$clang_compiler SetConfigurationName "No STL" PrintHeader @@ -342,8 +372,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$clang_compiler SetConfigurationName "No STL - Force C++03" PrintHeader @@ -363,8 +395,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$gcc_compiler SetConfigurationName "Initializer list test" PrintHeader @@ -387,8 +421,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$clang_compiler SetConfigurationName "Initializer list test" PrintHeader @@ -408,8 +444,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$gcc_compiler SetConfigurationName "Error macros 'log_errors' test" PrintHeader @@ -432,8 +470,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$gcc_compiler SetConfigurationName "Error macros 'exceptions' test" PrintHeader @@ -456,8 +496,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$gcc_compiler SetConfigurationName "Error macros 'log_errors and exceptions' test" PrintHeader @@ -480,8 +522,36 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then +compiler=$gcc_compiler +SetConfigurationName "Error macros 'assert function' test" +PrintHeader +cd ../../../etl_error_handler/assert_function +mkdir -p build-make || exit 1 +cd build-make || exit 1 +rm * -rf +cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +cmake --build . +if [ $? -eq 0 ]; then + PassedCompilation +else + FailedCompilation + exit $? +fi +./etl_tests +if [ $? -eq 0 ]; then + PassedTests +else + FailedTests + exit $? +fi +fi + +#****************************************************************************** +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$clang_compiler SetConfigurationName "Error macros 'log_errors' test" PrintHeader @@ -504,8 +574,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$clang_compiler SetConfigurationName "Error macros 'exceptions' test" PrintHeader @@ -528,8 +600,10 @@ else FailedTests exit $? fi +fi #****************************************************************************** +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then compiler=$clang_compiler SetConfigurationName "Error macros 'log_errors and exceptions' test" PrintHeader @@ -552,6 +626,33 @@ else FailedTests exit $? fi +fi + +#****************************************************************************** +if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then +compiler=$clang_compiler +SetConfigurationName "Error macros 'assert function' test" +PrintHeader +cd ../../../etl_error_handler/assert_function +mkdir -p build-make || exit 1 +cd build-make || exit 1 +rm * -rf +cmake -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +cmake --build . +if [ $? -eq 0 ]; then + PassedCompilation +else + FailedCompilation + exit $? +fi +./etl_tests +if [ $? -eq 0 ]; then + PassedTests +else + FailedTests + exit $? +fi +fi cd ../.. diff --git a/test/syntax_check/CMakeLists.txt b/test/syntax_check/CMakeLists.txt new file mode 100644 index 00000000..5eeb8ee2 --- /dev/null +++ b/test/syntax_check/CMakeLists.txt @@ -0,0 +1,337 @@ +cmake_minimum_required(VERSION 3.10.0) +project(etl_syntax_check) + +add_definitions(-DETL_DEBUG) + +option(NO_STL "No STL" OFF) + +if (NO_STL) + message(STATUS "Compiling for No STL") + add_definitions(-DETL_NO_STL) +else() + message(STATUS "Compiling for STL") +endif() + +if (ETL_USE_TYPE_TRAITS_BUILTINS) + message(STATUS "Compiling for built-in type traits") + add_definitions(-DETL_USE_TYPE_TRAITS_BUILTINS) +endif() + +if (ETL_USER_DEFINED_TYPE_TRAITS) + message(STATUS "Compiling for user defined type traits") + add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS) +endif() + +if (ETL_FORCE_TEST_CPP03_IMPLEMENTATION) + message(STATUS "Force C++03 implementations") + add_definitions(-DETL_FORCE_TEST_CPP03_IMPLEMENTATION) +endif() + +add_library(tests OBJECT) +target_compile_definitions(tests PRIVATE __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS __STDC_FORMAT_MACROS) +target_include_directories(tests PRIVATE "") +target_include_directories(tests SYSTEM PRIVATE ../../include) +set_target_properties(tests PROPERTIES + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS ON + ) +target_compile_options(tests + PRIVATE + -fsyntax-only + ) + +if (ETL_CXX_STANDARD MATCHES "98") + message(STATUS "Compiling for C++98") + set_property(TARGET tests PROPERTY CXX_STANDARD 98) +elseif (ETL_CXX_STANDARD MATCHES "03") + message(STATUS "Compiling for C++03 (C++98)") + set_property(TARGET tests PROPERTY CXX_STANDARD 98) +elseif (ETL_CXX_STANDARD MATCHES "11") + message(STATUS "Compiling for C++11") + set_property(TARGET tests PROPERTY CXX_STANDARD 11) +elseif (ETL_CXX_STANDARD MATCHES "14") + message(STATUS "Compiling for C++14") + set_property(TARGET tests PROPERTY CXX_STANDARD 14) +elseif (ETL_CXX_STANDARD MATCHES "17") + message(STATUS "Compiling for C++17") + set_property(TARGET tests PROPERTY CXX_STANDARD 17) +else() + message(STATUS "Compiling for C++20") + set_property(TARGET tests PROPERTY CXX_STANDARD 20) +endif() + +target_sources(tests PRIVATE + etl_profile.h + absolute.h.t.cpp + algorithm.h.t.cpp + alignment.h.t.cpp + array.h.t.cpp + array_view.h.t.cpp + array_wrapper.h.t.cpp + atomic.h.t.cpp + base64.h.t.cpp + base64_decoder.h.t.cpp + base64_encoder.h.t.cpp + basic_format_spec.h.t.cpp + basic_string.h.t.cpp + basic_string_stream.h.t.cpp + binary.h.t.cpp + bip_buffer_spsc_atomic.h.t.cpp + bit.h.t.cpp + bitset.h.t.cpp + bit_stream.h.t.cpp + bloom_filter.h.t.cpp + bresenham_line.h.t.cpp + buffer_descriptors.h.t.cpp + byte.h.t.cpp + byte_stream.h.t.cpp + callback.h.t.cpp + callback_service.h.t.cpp + callback_timer.h.t.cpp + callback_timer_atomic.h.t.cpp + callback_timer_interrupt.h.t.cpp + callback_timer_locked.h.t.cpp + char_traits.h.t.cpp + checksum.h.t.cpp + circular_buffer.h.t.cpp + circular_iterator.h.t.cpp + combinations.h.t.cpp + compare.h.t.cpp + constant.h.t.cpp + container.h.t.cpp + correlation.h.t.cpp + covariance.h.t.cpp + crc1.h.t.cpp + crc16.h.t.cpp + crc16_a.h.t.cpp + crc16_arc.h.t.cpp + crc16_aug_ccitt.h.t.cpp + crc16_buypass.h.t.cpp + crc16_ccitt.h.t.cpp + crc16_cdma2000.h.t.cpp + crc16_dds110.h.t.cpp + crc16_dectr.h.t.cpp + crc16_dectx.h.t.cpp + crc16_dnp.h.t.cpp + crc16_en13757.h.t.cpp + crc16_genibus.h.t.cpp + crc16_kermit.h.t.cpp + crc16_m17.h.t.cpp + crc16_maxim.h.t.cpp + crc16_mcrf4xx.h.t.cpp + crc16_modbus.h.t.cpp + crc16_profibus.h.t.cpp + crc16_riello.h.t.cpp + crc16_t10dif.h.t.cpp + crc16_teledisk.h.t.cpp + crc16_tms37157.h.t.cpp + crc16_usb.h.t.cpp + crc16_x25.h.t.cpp + crc16_xmodem.h.t.cpp + crc32.h.t.cpp + crc32_bzip2.h.t.cpp + crc32_c.h.t.cpp + crc32_d.h.t.cpp + crc32_jamcrc.h.t.cpp + crc32_mpeg2.h.t.cpp + crc32_posix.h.t.cpp + crc32_q.h.t.cpp + crc32_xfer.h.t.cpp + crc64_ecma.h.t.cpp + crc8_ccitt.h.t.cpp + crc8_cdma2000.h.t.cpp + crc8_darc.h.t.cpp + crc8_dvbs2.h.t.cpp + crc8_ebu.h.t.cpp + crc8_icode.h.t.cpp + crc8_itu.h.t.cpp + crc8_j1850.h.t.cpp + crc8_j1850_zero.h.t.cpp + crc8_maxim.h.t.cpp + crc8_rohc.h.t.cpp + crc8_wcdma.h.t.cpp + cyclic_value.h.t.cpp + debounce.h.t.cpp + debug_count.h.t.cpp + delegate.h.t.cpp + delegate_service.h.t.cpp + deque.h.t.cpp + endianness.h.t.cpp + enum_type.h.t.cpp + error_handler.h.t.cpp + exception.h.t.cpp + expected.h.t.cpp + factorial.h.t.cpp + fibonacci.h.t.cpp + file_error_numbers.h.t.cpp + fixed_iterator.h.t.cpp + fixed_sized_memory_block_allocator.h.t.cpp + flags.h.t.cpp + flat_map.h.t.cpp + flat_multimap.h.t.cpp + flat_multiset.h.t.cpp + flat_set.h.t.cpp + fnv_1.h.t.cpp + format_spec.h.t.cpp + forward_list.h.t.cpp + frame_check_sequence.h.t.cpp + fsm.h.t.cpp + function.h.t.cpp + functional.h.t.cpp + function_traits.h.t.cpp + gamma.h.t.cpp + gcd.h.t.cpp + generic_pool.h.t.cpp + hash.h.t.cpp + hfsm.h.t.cpp + histogram.h.t.cpp + ihash.h.t.cpp + imemory_block_allocator.h.t.cpp + indirect_vector.h.t.cpp + initializer_list.h.t.cpp + instance_count.h.t.cpp + integral_limits.h.t.cpp + intrusive_forward_list.h.t.cpp + intrusive_links.h.t.cpp + intrusive_list.h.t.cpp + intrusive_queue.h.t.cpp + intrusive_stack.h.t.cpp + invert.h.t.cpp + io_port.h.t.cpp + ipool.h.t.cpp + ireference_counted_message_pool.h.t.cpp + iterator.h.t.cpp + jenkins.h.t.cpp + largest.h.t.cpp + lcm.h.t.cpp + limiter.h.t.cpp + limits.h.t.cpp + list.h.t.cpp + log.h.t.cpp + macros.h.t.cpp + map.h.t.cpp + math.h.t.cpp + math_constants.h.t.cpp + mean.h.t.cpp + memory.h.t.cpp + memory_model.h.t.cpp + mem_cast.h.t.cpp + message.h.t.cpp + message_broker.h.t.cpp + message_bus.h.t.cpp + message_packet.h.t.cpp + message_router.h.t.cpp + message_router_registry.h.t.cpp + message_timer.h.t.cpp + message_timer_atomic.h.t.cpp + message_timer_interrupt.h.t.cpp + message_timer_locked.h.t.cpp + message_types.h.t.cpp + multimap.h.t.cpp + multiset.h.t.cpp + multi_array.h.t.cpp + multi_range.h.t.cpp + multi_span.h.t.cpp + multi_vector.h.t.cpp + murmur3.h.t.cpp + mutex.h.t.cpp + negative.h.t.cpp + nth_type.h.t.cpp + nullptr.h.t.cpp + null_type.h.t.cpp + numeric.h.t.cpp + observer.h.t.cpp + optional.h.t.cpp + overload.h.t.cpp + packet.h.t.cpp + parameter_pack.h.t.cpp + parameter_type.h.t.cpp + pearson.h.t.cpp + permutations.h.t.cpp + placement_new.h.t.cpp + platform.h.t.cpp + poly_span.h.t.cpp + pool.h.t.cpp + power.h.t.cpp + priority_queue.h.t.cpp + pseudo_moving_average.h.t.cpp + quantize.h.t.cpp + queue.h.t.cpp + queue_lockable.h.t.cpp + queue_mpmc_mutex.h.t.cpp + queue_spsc_atomic.h.t.cpp + queue_spsc_isr.h.t.cpp + queue_spsc_locked.h.t.cpp + radix.h.t.cpp + random.h.t.cpp + ratio.h.t.cpp + reference_counted_message.h.t.cpp + reference_counted_message_pool.h.t.cpp + reference_counted_object.h.t.cpp + reference_flat_map.h.t.cpp + reference_flat_multimap.h.t.cpp + reference_flat_multiset.h.t.cpp + reference_flat_set.h.t.cpp + rescale.h.t.cpp + result.h.t.cpp + rms.h.t.cpp + scaled_rounding.h.t.cpp + scheduler.h.t.cpp + set.h.t.cpp + shared_message.h.t.cpp + singleton.h.t.cpp + singleton_base.h.t.cpp + smallest.h.t.cpp + span.h.t.cpp + sqrt.h.t.cpp + stack.h.t.cpp + standard_deviation.h.t.cpp + state_chart.h.t.cpp + static_assert.h.t.cpp + string.h.t.cpp + stringify.h.t.cpp + string_stream.h.t.cpp + string_utilities.h.t.cpp + string_view.h.t.cpp + successor.h.t.cpp + task.h.t.cpp + threshold.h.t.cpp + timer.h.t.cpp + to_arithmetic.h.t.cpp + to_string.h.t.cpp + to_u16string.h.t.cpp + to_u32string.h.t.cpp + to_u8string.h.t.cpp + to_wstring.h.t.cpp + tuple.h.t.cpp + type_def.h.t.cpp + type_lookup.h.t.cpp + type_select.h.t.cpp + type_traits.h.t.cpp + u16format_spec.h.t.cpp + u16string.h.t.cpp + u16string_stream.h.t.cpp + u32format_spec.h.t.cpp + u32string.h.t.cpp + u32string_stream.h.t.cpp + u8format_spec.h.t.cpp + u8string.h.t.cpp + u8string_stream.h.t.cpp + unaligned_type.h.t.cpp + uncopyable.h.t.cpp + unordered_map.h.t.cpp + unordered_multimap.h.t.cpp + unordered_multiset.h.t.cpp + unordered_set.h.t.cpp + user_type.h.t.cpp + utility.h.t.cpp + variance.h.t.cpp + variant.h.t.cpp + variant_pool.h.t.cpp + vector.h.t.cpp + version.h.t.cpp + visitor.h.t.cpp + wformat_spec.h.t.cpp + wstring.h.t.cpp + wstring_stream.h.t.cpp + ) diff --git a/test/syntax_check/c++03/CMakeLists.txt b/test/syntax_check/c++03/CMakeLists.txt deleted file mode 100644 index fad0c6eb..00000000 --- a/test/syntax_check/c++03/CMakeLists.txt +++ /dev/null @@ -1,314 +0,0 @@ -cmake_minimum_required(VERSION 3.5.0) -project(etl_03_syntax_check) - -add_definitions(-DETL_DEBUG) - -option(NO_STL "No STL" OFF) - -message(STATUS "Compiling for C++03") - -if (NO_STL) - message(STATUS "Compiling for No STL") - add_definitions(-DETL_NO_STL) -else() - message(STATUS "Compiling for STL") -endif() - -if (ETL_USE_TYPE_TRAITS_BUILTINS) - message(STATUS "Compiling for built-in type traits") - add_definitions(-DETL_USE_TYPE_TRAITS_BUILTINS) -endif() - -if (ETL_USER_DEFINED_TYPE_TRAITS) - message(STATUS "Compiling for user defined type traits") - add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS) -endif() - -if (ETL_FORCE_TEST_CPP03_IMPLEMENTATION) - message(STATUS "Force C++03 implementations") - add_definitions(-DETL_FORCE_TEST_CPP03_IMPLEMENTATION) -endif() - -add_library(t98 OBJECT) -target_compile_definitions(t98 PRIVATE __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS __STDC_FORMAT_MACROS) -target_include_directories(t98 PRIVATE "") -target_include_directories(t98 SYSTEM PRIVATE ../../../include) -set_target_properties(t98 PROPERTIES - CXX_STANDARD 98 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS ON - ) -target_compile_options(t98 - PRIVATE - -fsyntax-only - ) -target_sources(t98 PRIVATE etl_profile.h - ../absolute.h.t.cpp - ../algorithm.h.t.cpp - ../alignment.h.t.cpp - ../array.h.t.cpp - ../array_view.h.t.cpp - ../array_wrapper.h.t.cpp - ../atomic.h.t.cpp - ../base64.h.t.cpp - ../base64_decoder.h.t.cpp - ../base64_encoder.h.t.cpp - ../basic_format_spec.h.t.cpp - ../basic_string.h.t.cpp - ../basic_string_stream.h.t.cpp - ../binary.h.t.cpp - ../bip_buffer_spsc_atomic.h.t.cpp - ../bit.h.t.cpp - ../bitset.h.t.cpp - ../bit_stream.h.t.cpp - ../bloom_filter.h.t.cpp - ../bresenham_line.h.t.cpp - ../buffer_descriptors.h.t.cpp - ../byte.h.t.cpp - ../byte_stream.h.t.cpp - ../callback.h.t.cpp - ../callback_service.h.t.cpp - ../callback_timer.h.t.cpp - ../callback_timer_atomic.h.t.cpp - ../callback_timer_interrupt.h.t.cpp - ../callback_timer_locked.h.t.cpp - ../char_traits.h.t.cpp - ../checksum.h.t.cpp - ../circular_buffer.h.t.cpp - ../circular_iterator.h.t.cpp - ../combinations.h.t.cpp - ../compare.h.t.cpp - ../constant.h.t.cpp - ../container.h.t.cpp - ../correlation.h.t.cpp - ../covariance.h.t.cpp - ../crc1.h.t.cpp - ../crc16.h.t.cpp - ../crc16_a.h.t.cpp - ../crc16_arc.h.t.cpp - ../crc16_aug_ccitt.h.t.cpp - ../crc16_buypass.h.t.cpp - ../crc16_ccitt.h.t.cpp - ../crc16_cdma2000.h.t.cpp - ../crc16_dds110.h.t.cpp - ../crc16_dectr.h.t.cpp - ../crc16_dectx.h.t.cpp - ../crc16_dnp.h.t.cpp - ../crc16_en13757.h.t.cpp - ../crc16_genibus.h.t.cpp - ../crc16_kermit.h.t.cpp - ../crc16_m17.h.t.cpp - ../crc16_maxim.h.t.cpp - ../crc16_mcrf4xx.h.t.cpp - ../crc16_modbus.h.t.cpp - ../crc16_profibus.h.t.cpp - ../crc16_riello.h.t.cpp - ../crc16_t10dif.h.t.cpp - ../crc16_teledisk.h.t.cpp - ../crc16_tms37157.h.t.cpp - ../crc16_usb.h.t.cpp - ../crc16_x25.h.t.cpp - ../crc16_xmodem.h.t.cpp - ../crc32.h.t.cpp - ../crc32_bzip2.h.t.cpp - ../crc32_c.h.t.cpp - ../crc32_d.h.t.cpp - ../crc32_jamcrc.h.t.cpp - ../crc32_mpeg2.h.t.cpp - ../crc32_posix.h.t.cpp - ../crc32_q.h.t.cpp - ../crc32_xfer.h.t.cpp - ../crc64_ecma.h.t.cpp - ../crc8_ccitt.h.t.cpp - ../crc8_cdma2000.h.t.cpp - ../crc8_darc.h.t.cpp - ../crc8_dvbs2.h.t.cpp - ../crc8_ebu.h.t.cpp - ../crc8_icode.h.t.cpp - ../crc8_itu.h.t.cpp - ../crc8_j1850.h.t.cpp - ../crc8_j1850_zero.h.t.cpp - ../crc8_maxim.h.t.cpp - ../crc8_rohc.h.t.cpp - ../crc8_wcdma.h.t.cpp - ../cyclic_value.h.t.cpp - ../debounce.h.t.cpp - ../debug_count.h.t.cpp - ../delegate.h.t.cpp - ../delegate_service.h.t.cpp - ../deque.h.t.cpp - ../endianness.h.t.cpp - ../enum_type.h.t.cpp - ../error_handler.h.t.cpp - ../exception.h.t.cpp - ../expected.h.t.cpp - ../factorial.h.t.cpp - ../fibonacci.h.t.cpp - ../file_error_numbers.h.t.cpp - ../fixed_iterator.h.t.cpp - ../fixed_sized_memory_block_allocator.h.t.cpp - ../flags.h.t.cpp - ../flat_map.h.t.cpp - ../flat_multimap.h.t.cpp - ../flat_multiset.h.t.cpp - ../flat_set.h.t.cpp - ../fnv_1.h.t.cpp - ../format_spec.h.t.cpp - ../forward_list.h.t.cpp - ../frame_check_sequence.h.t.cpp - ../fsm.h.t.cpp - ../function.h.t.cpp - ../functional.h.t.cpp - ../gamma.h.t.cpp - ../gcd.h.t.cpp - ../generic_pool.h.t.cpp - ../hash.h.t.cpp - ../hfsm.h.t.cpp - ../histogram.h.t.cpp - ../ihash.h.t.cpp - ../imemory_block_allocator.h.t.cpp - ../indirect_vector.h.t.cpp - ../initializer_list.h.t.cpp - ../instance_count.h.t.cpp - ../integral_limits.h.t.cpp - ../intrusive_forward_list.h.t.cpp - ../intrusive_links.h.t.cpp - ../intrusive_list.h.t.cpp - ../intrusive_queue.h.t.cpp - ../intrusive_stack.h.t.cpp - ../invert.h.t.cpp - ../io_port.h.t.cpp - ../ipool.h.t.cpp - ../ireference_counted_message_pool.h.t.cpp - ../iterator.h.t.cpp - ../jenkins.h.t.cpp - ../largest.h.t.cpp - ../lcm.h.t.cpp - ../limiter.h.t.cpp - ../limits.h.t.cpp - ../list.h.t.cpp - ../log.h.t.cpp - ../macros.h.t.cpp - ../map.h.t.cpp - ../math.h.t.cpp - ../math_constants.h.t.cpp - ../mean.h.t.cpp - ../memory.h.t.cpp - ../memory_model.h.t.cpp - ../mem_cast.h.t.cpp - ../message.h.t.cpp - ../message_broker.h.t.cpp - ../message_bus.h.t.cpp - ../message_packet.h.t.cpp - ../message_router.h.t.cpp - ../message_router_registry.h.t.cpp - ../message_timer.h.t.cpp - ../message_timer_atomic.h.t.cpp - ../message_timer_interrupt.h.t.cpp - ../message_timer_locked.h.t.cpp - ../message_types.h.t.cpp - ../multimap.h.t.cpp - ../multiset.h.t.cpp - ../multi_array.h.t.cpp - ../multi_range.h.t.cpp - ../multi_span.h.t.cpp - ../multi_vector.h.t.cpp - ../murmur3.h.t.cpp - ../mutex.h.t.cpp - ../negative.h.t.cpp - ../nth_type.h.t.cpp - ../nullptr.h.t.cpp - ../null_type.h.t.cpp - ../numeric.h.t.cpp - ../observer.h.t.cpp - ../optional.h.t.cpp - ../overload.h.t.cpp - ../packet.h.t.cpp - ../parameter_pack.h.t.cpp - ../parameter_type.h.t.cpp - ../pearson.h.t.cpp - ../permutations.h.t.cpp - ../placement_new.h.t.cpp - ../platform.h.t.cpp - ../poly_span.h.t.cpp - ../pool.h.t.cpp - ../power.h.t.cpp - ../priority_queue.h.t.cpp - ../pseudo_moving_average.h.t.cpp - ../quantize.h.t.cpp - ../queue.h.t.cpp - ../queue_lockable.h.t.cpp - ../queue_mpmc_mutex.h.t.cpp - ../queue_spsc_atomic.h.t.cpp - ../queue_spsc_isr.h.t.cpp - ../queue_spsc_locked.h.t.cpp - ../radix.h.t.cpp - ../random.h.t.cpp - ../ratio.h.t.cpp - ../reference_counted_message.h.t.cpp - ../reference_counted_message_pool.h.t.cpp - ../reference_counted_object.h.t.cpp - ../reference_flat_map.h.t.cpp - ../reference_flat_multimap.h.t.cpp - ../reference_flat_multiset.h.t.cpp - ../reference_flat_set.h.t.cpp - ../rescale.h.t.cpp - ../result.h.t.cpp - ../rms.h.t.cpp - ../scaled_rounding.h.t.cpp - ../scheduler.h.t.cpp - ../set.h.t.cpp - ../shared_message.h.t.cpp - ../singleton.h.t.cpp - ../smallest.h.t.cpp - ../span.h.t.cpp - ../sqrt.h.t.cpp - ../stack.h.t.cpp - ../standard_deviation.h.t.cpp - ../state_chart.h.t.cpp - ../static_assert.h.t.cpp - ../string.h.t.cpp - ../stringify.h.t.cpp - ../string_stream.h.t.cpp - ../string_utilities.h.t.cpp - ../string_view.h.t.cpp - ../successor.h.t.cpp - ../task.h.t.cpp - ../threshold.h.t.cpp - ../timer.h.t.cpp - ../to_arithmetic.h.t.cpp - ../to_string.h.t.cpp - ../to_u16string.h.t.cpp - ../to_u32string.h.t.cpp - ../to_u8string.h.t.cpp - ../to_wstring.h.t.cpp - ../type_def.h.t.cpp - ../type_lookup.h.t.cpp - ../type_select.h.t.cpp - ../type_traits.h.t.cpp - ../u16format_spec.h.t.cpp - ../u16string.h.t.cpp - ../u16string_stream.h.t.cpp - ../u32format_spec.h.t.cpp - ../u32string.h.t.cpp - ../u32string_stream.h.t.cpp - ../u8format_spec.h.t.cpp - ../u8string.h.t.cpp - ../u8string_stream.h.t.cpp - ../unaligned_type.h.t.cpp - ../unordered_map.h.t.cpp - ../unordered_multimap.h.t.cpp - ../unordered_multiset.h.t.cpp - ../unordered_set.h.t.cpp - ../user_type.h.t.cpp - ../utility.h.t.cpp - ../variance.h.t.cpp - ../variant.h.t.cpp - ../variant_pool.h.t.cpp - ../vector.h.t.cpp - ../version.h.t.cpp - ../visitor.h.t.cpp - ../wformat_spec.h.t.cpp - ../wstring.h.t.cpp - ../wstring_stream.h.t.cpp - ) diff --git a/test/syntax_check/c++03/etl_profile.h b/test/syntax_check/c++03/etl_profile.h deleted file mode 100644 index 2d70da68..00000000 --- a/test/syntax_check/c++03/etl_profile.h +++ /dev/null @@ -1,70 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2021 Bo Rydberg - -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_PROFILE_H__ -#define __ETL_PROFILE_H__ - -#define ETL_TARGET_DEVICE_GENERIC -#define ETL_TARGET_OS_NONE -#define ETL_CPP11_SUPPORTED 0 -#define ETL_CPP14_SUPPORTED 0 -#define ETL_CPP17_SUPPORTED 0 -#define ETL_CPP20_SUPPORTED 0 -#define ETL_IN_UNIT_TEST -#define ETL_CALLBACK_TIMER_USE_INTERRUPT_LOCK -#define ETL_CALLBACK_TIMER_DISABLE_INTERRUPTS -#define ETL_CALLBACK_TIMER_ENABLE_INTERRUPTS -#define ETL_MESSAGE_TIMER_USE_INTERRUPT_LOCK -#define ETL_MESSAGE_TIMER_DISABLE_INTERRUPTS -#define ETL_MESSAGE_TIMER_ENABLE_INTERRUPTS - -#if defined(ETL_FORCE_TEST_CPP03_IMPLEMENTATION) - #define ETL_FUNCTION_FORCE_CPP03_IMPLEMENTATION - #define ETL_PRIORITY_QUEUE_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_ATOMIC_FORCE_CPP03_IMPLEMENTATION - #define ETL_VARIANT_FORCE_CPP03_IMPLEMENTATION - #define ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_ISR_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION - #define ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION - #define ETL_LARGEST_TYPE_FORCE_CPP03_IMPLEMENTATION - #define ETL_TYPE_SELECT_FORCE_CPP03_IMPLEMENTATION - #define ETL_UNINITIALIZED_BUFFER_FORCE_CPP03_IMPLEMENTATION - #define ETL_CRC_FORCE_CPP03_IMPLEMENTATION - #define ETL_MEM_CAST_FORCE_CPP03_IMPLEMENTATION - #define ETL_OBSERVER_FORCE_CPP03_IMPLEMENTATION - #define ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION - #define ETL_OBSERVER_FORCE_CPP03_IMPLEMENTATION - #define ETL_MESSAGE_ROUTER_FORCE_CPP03_IMPLEMENTATION - #define ETL_FSM_FORCE_CPP03_IMPLEMENTATION - #define ETL_SINGLETON_FORCE_CPP03_IMPLEMENTATION -#endif - -#endif diff --git a/test/syntax_check/c++11/CMakeLists.txt b/test/syntax_check/c++11/CMakeLists.txt deleted file mode 100644 index f426cecc..00000000 --- a/test/syntax_check/c++11/CMakeLists.txt +++ /dev/null @@ -1,314 +0,0 @@ -cmake_minimum_required(VERSION 3.5.0) -project(etl_11_syntax_check) - -add_definitions(-DETL_DEBUG) - -option(NO_STL "No STL" OFF) - -message(STATUS "Compiling for C++11") - -if (NO_STL) - message(STATUS "Compiling for No STL") - add_definitions(-DETL_NO_STL) -else() - message(STATUS "Compiling for STL") -endif() - -if (ETL_USE_TYPE_TRAITS_BUILTINS) - message(STATUS "Compiling for built-in type traits") - add_definitions(-DETL_USE_TYPE_TRAITS_BUILTINS) -endif() - -if (ETL_USER_DEFINED_TYPE_TRAITS) - message(STATUS "Compiling for user defined type traits") - add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS) -endif() - -if (ETL_FORCE_TEST_CPP03_IMPLEMENTATION) - message(STATUS "Force C++03 implementations") - add_definitions(-DETL_FORCE_TEST_CPP03_IMPLEMENTATION) -endif() - -add_library(t11 OBJECT) -target_compile_definitions(t11 PRIVATE __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS __STDC_FORMAT_MACROS) -target_include_directories(t11 PRIVATE "") -target_include_directories(t11 SYSTEM PRIVATE ../../../include) -set_target_properties(t11 PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS ON - ) -target_compile_options(t11 - PRIVATE - -fsyntax-only - ) -target_sources(t11 PRIVATE etl_profile.h - ../absolute.h.t.cpp - ../algorithm.h.t.cpp - ../alignment.h.t.cpp - ../array.h.t.cpp - ../array_view.h.t.cpp - ../array_wrapper.h.t.cpp - ../atomic.h.t.cpp - ../base64.h.t.cpp - ../base64_decoder.h.t.cpp - ../base64_encoder.h.t.cpp - ../basic_format_spec.h.t.cpp - ../basic_string.h.t.cpp - ../basic_string_stream.h.t.cpp - ../binary.h.t.cpp - ../bip_buffer_spsc_atomic.h.t.cpp - ../bit.h.t.cpp - ../bitset.h.t.cpp - ../bit_stream.h.t.cpp - ../bloom_filter.h.t.cpp - ../bresenham_line.h.t.cpp - ../buffer_descriptors.h.t.cpp - ../byte.h.t.cpp - ../byte_stream.h.t.cpp - ../callback.h.t.cpp - ../callback_service.h.t.cpp - ../callback_timer.h.t.cpp - ../callback_timer_atomic.h.t.cpp - ../callback_timer_interrupt.h.t.cpp - ../callback_timer_locked.h.t.cpp - ../char_traits.h.t.cpp - ../checksum.h.t.cpp - ../circular_buffer.h.t.cpp - ../circular_iterator.h.t.cpp - ../combinations.h.t.cpp - ../compare.h.t.cpp - ../constant.h.t.cpp - ../container.h.t.cpp - ../correlation.h.t.cpp - ../covariance.h.t.cpp - ../crc1.h.t.cpp - ../crc16.h.t.cpp - ../crc16_a.h.t.cpp - ../crc16_arc.h.t.cpp - ../crc16_aug_ccitt.h.t.cpp - ../crc16_buypass.h.t.cpp - ../crc16_ccitt.h.t.cpp - ../crc16_cdma2000.h.t.cpp - ../crc16_dds110.h.t.cpp - ../crc16_dectr.h.t.cpp - ../crc16_dectx.h.t.cpp - ../crc16_dnp.h.t.cpp - ../crc16_en13757.h.t.cpp - ../crc16_genibus.h.t.cpp - ../crc16_kermit.h.t.cpp - ../crc16_m17.h.t.cpp - ../crc16_maxim.h.t.cpp - ../crc16_mcrf4xx.h.t.cpp - ../crc16_modbus.h.t.cpp - ../crc16_profibus.h.t.cpp - ../crc16_riello.h.t.cpp - ../crc16_t10dif.h.t.cpp - ../crc16_teledisk.h.t.cpp - ../crc16_tms37157.h.t.cpp - ../crc16_usb.h.t.cpp - ../crc16_x25.h.t.cpp - ../crc16_xmodem.h.t.cpp - ../crc32.h.t.cpp - ../crc32_bzip2.h.t.cpp - ../crc32_c.h.t.cpp - ../crc32_d.h.t.cpp - ../crc32_jamcrc.h.t.cpp - ../crc32_mpeg2.h.t.cpp - ../crc32_posix.h.t.cpp - ../crc32_q.h.t.cpp - ../crc32_xfer.h.t.cpp - ../crc64_ecma.h.t.cpp - ../crc8_ccitt.h.t.cpp - ../crc8_cdma2000.h.t.cpp - ../crc8_darc.h.t.cpp - ../crc8_dvbs2.h.t.cpp - ../crc8_ebu.h.t.cpp - ../crc8_icode.h.t.cpp - ../crc8_itu.h.t.cpp - ../crc8_j1850.h.t.cpp - ../crc8_j1850_zero.h.t.cpp - ../crc8_maxim.h.t.cpp - ../crc8_rohc.h.t.cpp - ../crc8_wcdma.h.t.cpp - ../cyclic_value.h.t.cpp - ../debounce.h.t.cpp - ../debug_count.h.t.cpp - ../delegate.h.t.cpp - ../delegate_service.h.t.cpp - ../deque.h.t.cpp - ../endianness.h.t.cpp - ../enum_type.h.t.cpp - ../error_handler.h.t.cpp - ../exception.h.t.cpp - ../expected.h.t.cpp - ../factorial.h.t.cpp - ../fibonacci.h.t.cpp - ../file_error_numbers.h.t.cpp - ../fixed_iterator.h.t.cpp - ../fixed_sized_memory_block_allocator.h.t.cpp - ../flags.h.t.cpp - ../flat_map.h.t.cpp - ../flat_multimap.h.t.cpp - ../flat_multiset.h.t.cpp - ../flat_set.h.t.cpp - ../fnv_1.h.t.cpp - ../format_spec.h.t.cpp - ../forward_list.h.t.cpp - ../frame_check_sequence.h.t.cpp - ../fsm.h.t.cpp - ../function.h.t.cpp - ../functional.h.t.cpp - ../gamma.h.t.cpp - ../gcd.h.t.cpp - ../generic_pool.h.t.cpp - ../hash.h.t.cpp - ../hfsm.h.t.cpp - ../histogram.h.t.cpp - ../ihash.h.t.cpp - ../imemory_block_allocator.h.t.cpp - ../indirect_vector.h.t.cpp - ../initializer_list.h.t.cpp - ../instance_count.h.t.cpp - ../integral_limits.h.t.cpp - ../intrusive_forward_list.h.t.cpp - ../intrusive_links.h.t.cpp - ../intrusive_list.h.t.cpp - ../intrusive_queue.h.t.cpp - ../intrusive_stack.h.t.cpp - ../invert.h.t.cpp - ../io_port.h.t.cpp - ../ipool.h.t.cpp - ../ireference_counted_message_pool.h.t.cpp - ../iterator.h.t.cpp - ../jenkins.h.t.cpp - ../largest.h.t.cpp - ../lcm.h.t.cpp - ../limiter.h.t.cpp - ../limits.h.t.cpp - ../list.h.t.cpp - ../log.h.t.cpp - ../macros.h.t.cpp - ../map.h.t.cpp - ../math.h.t.cpp - ../math_constants.h.t.cpp - ../mean.h.t.cpp - ../memory.h.t.cpp - ../memory_model.h.t.cpp - ../mem_cast.h.t.cpp - ../message.h.t.cpp - ../message_broker.h.t.cpp - ../message_bus.h.t.cpp - ../message_packet.h.t.cpp - ../message_router.h.t.cpp - ../message_router_registry.h.t.cpp - ../message_timer.h.t.cpp - ../message_timer_atomic.h.t.cpp - ../message_timer_interrupt.h.t.cpp - ../message_timer_locked.h.t.cpp - ../message_types.h.t.cpp - ../multimap.h.t.cpp - ../multiset.h.t.cpp - ../multi_array.h.t.cpp - ../multi_range.h.t.cpp - ../multi_span.h.t.cpp - ../multi_vector.h.t.cpp - ../murmur3.h.t.cpp - ../mutex.h.t.cpp - ../negative.h.t.cpp - ../nth_type.h.t.cpp - ../nullptr.h.t.cpp - ../null_type.h.t.cpp - ../numeric.h.t.cpp - ../observer.h.t.cpp - ../optional.h.t.cpp - ../overload.h.t.cpp - ../packet.h.t.cpp - ../parameter_pack.h.t.cpp - ../parameter_type.h.t.cpp - ../pearson.h.t.cpp - ../permutations.h.t.cpp - ../placement_new.h.t.cpp - ../platform.h.t.cpp - ../poly_span.h.t.cpp - ../pool.h.t.cpp - ../power.h.t.cpp - ../priority_queue.h.t.cpp - ../pseudo_moving_average.h.t.cpp - ../quantize.h.t.cpp - ../queue.h.t.cpp - ../queue_lockable.h.t.cpp - ../queue_mpmc_mutex.h.t.cpp - ../queue_spsc_atomic.h.t.cpp - ../queue_spsc_isr.h.t.cpp - ../queue_spsc_locked.h.t.cpp - ../radix.h.t.cpp - ../random.h.t.cpp - ../ratio.h.t.cpp - ../reference_counted_message.h.t.cpp - ../reference_counted_message_pool.h.t.cpp - ../reference_counted_object.h.t.cpp - ../reference_flat_map.h.t.cpp - ../reference_flat_multimap.h.t.cpp - ../reference_flat_multiset.h.t.cpp - ../reference_flat_set.h.t.cpp - ../rescale.h.t.cpp - ../result.h.t.cpp - ../rms.h.t.cpp - ../scaled_rounding.h.t.cpp - ../scheduler.h.t.cpp - ../set.h.t.cpp - ../shared_message.h.t.cpp - ../singleton.h.t.cpp - ../smallest.h.t.cpp - ../span.h.t.cpp - ../sqrt.h.t.cpp - ../stack.h.t.cpp - ../standard_deviation.h.t.cpp - ../state_chart.h.t.cpp - ../static_assert.h.t.cpp - ../string.h.t.cpp - ../stringify.h.t.cpp - ../string_stream.h.t.cpp - ../string_utilities.h.t.cpp - ../string_view.h.t.cpp - ../successor.h.t.cpp - ../task.h.t.cpp - ../threshold.h.t.cpp - ../timer.h.t.cpp - ../to_arithmetic.h.t.cpp - ../to_string.h.t.cpp - ../to_u16string.h.t.cpp - ../to_u32string.h.t.cpp - ../to_u8string.h.t.cpp - ../to_wstring.h.t.cpp - ../type_def.h.t.cpp - ../type_lookup.h.t.cpp - ../type_select.h.t.cpp - ../type_traits.h.t.cpp - ../u16format_spec.h.t.cpp - ../u16string.h.t.cpp - ../u16string_stream.h.t.cpp - ../u32format_spec.h.t.cpp - ../u32string.h.t.cpp - ../u32string_stream.h.t.cpp - ../u8format_spec.h.t.cpp - ../u8string.h.t.cpp - ../u8string_stream.h.t.cpp - ../unaligned_type.h.t.cpp - ../unordered_map.h.t.cpp - ../unordered_multimap.h.t.cpp - ../unordered_multiset.h.t.cpp - ../unordered_set.h.t.cpp - ../user_type.h.t.cpp - ../utility.h.t.cpp - ../variance.h.t.cpp - ../variant.h.t.cpp - ../variant_pool.h.t.cpp - ../vector.h.t.cpp - ../version.h.t.cpp - ../visitor.h.t.cpp - ../wformat_spec.h.t.cpp - ../wstring.h.t.cpp - ../wstring_stream.h.t.cpp - ) diff --git a/test/syntax_check/c++11/etl_profile.h b/test/syntax_check/c++11/etl_profile.h deleted file mode 100644 index 002d5eb9..00000000 --- a/test/syntax_check/c++11/etl_profile.h +++ /dev/null @@ -1,70 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2021 Bo Rydberg - -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_PROFILE_H__ -#define __ETL_PROFILE_H__ - -#define ETL_TARGET_DEVICE_GENERIC -#define ETL_TARGET_OS_NONE -#define ETL_CPP11_SUPPORTED 1 -#define ETL_CPP14_SUPPORTED 0 -#define ETL_CPP17_SUPPORTED 0 -#define ETL_CPP20_SUPPORTED 0 -#define ETL_IN_UNIT_TEST -#define ETL_CALLBACK_TIMER_USE_INTERRUPT_LOCK -#define ETL_CALLBACK_TIMER_DISABLE_INTERRUPTS -#define ETL_CALLBACK_TIMER_ENABLE_INTERRUPTS -#define ETL_MESSAGE_TIMER_USE_INTERRUPT_LOCK -#define ETL_MESSAGE_TIMER_DISABLE_INTERRUPTS -#define ETL_MESSAGE_TIMER_ENABLE_INTERRUPTS - -#if defined(ETL_FORCE_TEST_CPP03_IMPLEMENTATION) - #define ETL_FUNCTION_FORCE_CPP03_IMPLEMENTATION - #define ETL_PRIORITY_QUEUE_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_ATOMIC_FORCE_CPP03_IMPLEMENTATION - #define ETL_VARIANT_FORCE_CPP03_IMPLEMENTATION - #define ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_ISR_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION - #define ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION - #define ETL_LARGEST_TYPE_FORCE_CPP03_IMPLEMENTATION - #define ETL_TYPE_SELECT_FORCE_CPP03_IMPLEMENTATION - #define ETL_UNINITIALIZED_BUFFER_FORCE_CPP03_IMPLEMENTATION - #define ETL_CRC_FORCE_CPP03_IMPLEMENTATION - #define ETL_MEM_CAST_FORCE_CPP03_IMPLEMENTATION - #define ETL_OBSERVER_FORCE_CPP03_IMPLEMENTATION - #define ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION - #define ETL_OBSERVER_FORCE_CPP03_IMPLEMENTATION - #define ETL_MESSAGE_ROUTER_FORCE_CPP03_IMPLEMENTATION - #define ETL_FSM_FORCE_CPP03_IMPLEMENTATION - #define ETL_SINGLETON_FORCE_CPP03_IMPLEMENTATION -#endif - -#endif diff --git a/test/syntax_check/c++14/CMakeLists.txt b/test/syntax_check/c++14/CMakeLists.txt deleted file mode 100644 index b7bc68b9..00000000 --- a/test/syntax_check/c++14/CMakeLists.txt +++ /dev/null @@ -1,314 +0,0 @@ -cmake_minimum_required(VERSION 3.5.0) -project(etl_14_syntax_check) - -add_definitions(-DETL_DEBUG) - -option(NO_STL "No STL" OFF) - -message(STATUS "Compiling for C++14") - -if (NO_STL) - message(STATUS "Compiling for No STL") - add_definitions(-DETL_NO_STL) -else() - message(STATUS "Compiling for STL") -endif() - -if (ETL_USE_TYPE_TRAITS_BUILTINS) - message(STATUS "Compiling for built-in type traits") - add_definitions(-DETL_USE_TYPE_TRAITS_BUILTINS) -endif() - -if (ETL_USER_DEFINED_TYPE_TRAITS) - message(STATUS "Compiling for user defined type traits") - add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS) -endif() - -if (ETL_FORCE_TEST_CPP03_IMPLEMENTATION) - message(STATUS "Force C++03 implementations") - add_definitions(-DETL_FORCE_TEST_CPP03_IMPLEMENTATION) -endif() - -add_library(t14 OBJECT) -target_compile_definitions(t14 PRIVATE __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS __STDC_FORMAT_MACROS) -target_include_directories(t14 PRIVATE "") -target_include_directories(t14 SYSTEM PRIVATE ../../../include) -set_target_properties(t14 PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS ON - ) -target_compile_options(t14 - PRIVATE - -fsyntax-only - ) -target_sources(t14 PRIVATE etl_profile.h - ../absolute.h.t.cpp - ../algorithm.h.t.cpp - ../alignment.h.t.cpp - ../array.h.t.cpp - ../array_view.h.t.cpp - ../array_wrapper.h.t.cpp - ../atomic.h.t.cpp - ../base64.h.t.cpp - ../base64_decoder.h.t.cpp - ../base64_encoder.h.t.cpp - ../basic_format_spec.h.t.cpp - ../basic_string.h.t.cpp - ../basic_string_stream.h.t.cpp - ../binary.h.t.cpp - ../bip_buffer_spsc_atomic.h.t.cpp - ../bit.h.t.cpp - ../bitset.h.t.cpp - ../bit_stream.h.t.cpp - ../bloom_filter.h.t.cpp - ../bresenham_line.h.t.cpp - ../buffer_descriptors.h.t.cpp - ../byte.h.t.cpp - ../byte_stream.h.t.cpp - ../callback.h.t.cpp - ../callback_service.h.t.cpp - ../callback_timer.h.t.cpp - ../callback_timer_atomic.h.t.cpp - ../callback_timer_interrupt.h.t.cpp - ../callback_timer_locked.h.t.cpp - ../char_traits.h.t.cpp - ../checksum.h.t.cpp - ../circular_buffer.h.t.cpp - ../circular_iterator.h.t.cpp - ../combinations.h.t.cpp - ../compare.h.t.cpp - ../constant.h.t.cpp - ../container.h.t.cpp - ../correlation.h.t.cpp - ../covariance.h.t.cpp - ../crc1.h.t.cpp - ../crc16.h.t.cpp - ../crc16_a.h.t.cpp - ../crc16_arc.h.t.cpp - ../crc16_aug_ccitt.h.t.cpp - ../crc16_buypass.h.t.cpp - ../crc16_ccitt.h.t.cpp - ../crc16_cdma2000.h.t.cpp - ../crc16_dds110.h.t.cpp - ../crc16_dectr.h.t.cpp - ../crc16_dectx.h.t.cpp - ../crc16_dnp.h.t.cpp - ../crc16_en13757.h.t.cpp - ../crc16_genibus.h.t.cpp - ../crc16_kermit.h.t.cpp - ../crc16_m17.h.t.cpp - ../crc16_maxim.h.t.cpp - ../crc16_mcrf4xx.h.t.cpp - ../crc16_modbus.h.t.cpp - ../crc16_profibus.h.t.cpp - ../crc16_riello.h.t.cpp - ../crc16_t10dif.h.t.cpp - ../crc16_teledisk.h.t.cpp - ../crc16_tms37157.h.t.cpp - ../crc16_usb.h.t.cpp - ../crc16_x25.h.t.cpp - ../crc16_xmodem.h.t.cpp - ../crc32.h.t.cpp - ../crc32_bzip2.h.t.cpp - ../crc32_c.h.t.cpp - ../crc32_d.h.t.cpp - ../crc32_jamcrc.h.t.cpp - ../crc32_mpeg2.h.t.cpp - ../crc32_posix.h.t.cpp - ../crc32_q.h.t.cpp - ../crc32_xfer.h.t.cpp - ../crc64_ecma.h.t.cpp - ../crc8_ccitt.h.t.cpp - ../crc8_cdma2000.h.t.cpp - ../crc8_darc.h.t.cpp - ../crc8_dvbs2.h.t.cpp - ../crc8_ebu.h.t.cpp - ../crc8_icode.h.t.cpp - ../crc8_itu.h.t.cpp - ../crc8_j1850.h.t.cpp - ../crc8_j1850_zero.h.t.cpp - ../crc8_maxim.h.t.cpp - ../crc8_rohc.h.t.cpp - ../crc8_wcdma.h.t.cpp - ../cyclic_value.h.t.cpp - ../debounce.h.t.cpp - ../debug_count.h.t.cpp - ../delegate.h.t.cpp - ../delegate_service.h.t.cpp - ../deque.h.t.cpp - ../endianness.h.t.cpp - ../enum_type.h.t.cpp - ../error_handler.h.t.cpp - ../exception.h.t.cpp - ../expected.h.t.cpp - ../factorial.h.t.cpp - ../fibonacci.h.t.cpp - ../file_error_numbers.h.t.cpp - ../fixed_iterator.h.t.cpp - ../fixed_sized_memory_block_allocator.h.t.cpp - ../flags.h.t.cpp - ../flat_map.h.t.cpp - ../flat_multimap.h.t.cpp - ../flat_multiset.h.t.cpp - ../flat_set.h.t.cpp - ../fnv_1.h.t.cpp - ../format_spec.h.t.cpp - ../forward_list.h.t.cpp - ../frame_check_sequence.h.t.cpp - ../fsm.h.t.cpp - ../function.h.t.cpp - ../functional.h.t.cpp - ../gamma.h.t.cpp - ../gcd.h.t.cpp - ../generic_pool.h.t.cpp - ../hash.h.t.cpp - ../hfsm.h.t.cpp - ../histogram.h.t.cpp - ../ihash.h.t.cpp - ../imemory_block_allocator.h.t.cpp - ../indirect_vector.h.t.cpp - ../initializer_list.h.t.cpp - ../instance_count.h.t.cpp - ../integral_limits.h.t.cpp - ../intrusive_forward_list.h.t.cpp - ../intrusive_links.h.t.cpp - ../intrusive_list.h.t.cpp - ../intrusive_queue.h.t.cpp - ../intrusive_stack.h.t.cpp - ../invert.h.t.cpp - ../io_port.h.t.cpp - ../ipool.h.t.cpp - ../ireference_counted_message_pool.h.t.cpp - ../iterator.h.t.cpp - ../jenkins.h.t.cpp - ../largest.h.t.cpp - ../lcm.h.t.cpp - ../limiter.h.t.cpp - ../limits.h.t.cpp - ../list.h.t.cpp - ../log.h.t.cpp - ../macros.h.t.cpp - ../map.h.t.cpp - ../math.h.t.cpp - ../math_constants.h.t.cpp - ../mean.h.t.cpp - ../memory.h.t.cpp - ../memory_model.h.t.cpp - ../mem_cast.h.t.cpp - ../message.h.t.cpp - ../message_broker.h.t.cpp - ../message_bus.h.t.cpp - ../message_packet.h.t.cpp - ../message_router.h.t.cpp - ../message_router_registry.h.t.cpp - ../message_timer.h.t.cpp - ../message_timer_atomic.h.t.cpp - ../message_timer_interrupt.h.t.cpp - ../message_timer_locked.h.t.cpp - ../message_types.h.t.cpp - ../multimap.h.t.cpp - ../multiset.h.t.cpp - ../multi_array.h.t.cpp - ../multi_range.h.t.cpp - ../multi_span.h.t.cpp - ../multi_vector.h.t.cpp - ../murmur3.h.t.cpp - ../mutex.h.t.cpp - ../negative.h.t.cpp - ../nth_type.h.t.cpp - ../nullptr.h.t.cpp - ../null_type.h.t.cpp - ../numeric.h.t.cpp - ../observer.h.t.cpp - ../optional.h.t.cpp - ../overload.h.t.cpp - ../packet.h.t.cpp - ../parameter_pack.h.t.cpp - ../parameter_type.h.t.cpp - ../pearson.h.t.cpp - ../permutations.h.t.cpp - ../placement_new.h.t.cpp - ../platform.h.t.cpp - ../poly_span.h.t.cpp - ../pool.h.t.cpp - ../power.h.t.cpp - ../priority_queue.h.t.cpp - ../pseudo_moving_average.h.t.cpp - ../quantize.h.t.cpp - ../queue.h.t.cpp - ../queue_lockable.h.t.cpp - ../queue_mpmc_mutex.h.t.cpp - ../queue_spsc_atomic.h.t.cpp - ../queue_spsc_isr.h.t.cpp - ../queue_spsc_locked.h.t.cpp - ../radix.h.t.cpp - ../random.h.t.cpp - ../ratio.h.t.cpp - ../reference_counted_message.h.t.cpp - ../reference_counted_message_pool.h.t.cpp - ../reference_counted_object.h.t.cpp - ../reference_flat_map.h.t.cpp - ../reference_flat_multimap.h.t.cpp - ../reference_flat_multiset.h.t.cpp - ../reference_flat_set.h.t.cpp - ../rescale.h.t.cpp - ../result.h.t.cpp - ../rms.h.t.cpp - ../scaled_rounding.h.t.cpp - ../scheduler.h.t.cpp - ../set.h.t.cpp - ../shared_message.h.t.cpp - ../singleton.h.t.cpp - ../smallest.h.t.cpp - ../span.h.t.cpp - ../sqrt.h.t.cpp - ../stack.h.t.cpp - ../standard_deviation.h.t.cpp - ../state_chart.h.t.cpp - ../static_assert.h.t.cpp - ../string.h.t.cpp - ../stringify.h.t.cpp - ../string_stream.h.t.cpp - ../string_utilities.h.t.cpp - ../string_view.h.t.cpp - ../successor.h.t.cpp - ../task.h.t.cpp - ../threshold.h.t.cpp - ../timer.h.t.cpp - ../to_arithmetic.h.t.cpp - ../to_string.h.t.cpp - ../to_u16string.h.t.cpp - ../to_u32string.h.t.cpp - ../to_u8string.h.t.cpp - ../to_wstring.h.t.cpp - ../type_def.h.t.cpp - ../type_lookup.h.t.cpp - ../type_select.h.t.cpp - ../type_traits.h.t.cpp - ../u16format_spec.h.t.cpp - ../u16string.h.t.cpp - ../u16string_stream.h.t.cpp - ../u32format_spec.h.t.cpp - ../u32string.h.t.cpp - ../u32string_stream.h.t.cpp - ../u8format_spec.h.t.cpp - ../u8string.h.t.cpp - ../u8string_stream.h.t.cpp - ../unaligned_type.h.t.cpp - ../unordered_map.h.t.cpp - ../unordered_multimap.h.t.cpp - ../unordered_multiset.h.t.cpp - ../unordered_set.h.t.cpp - ../user_type.h.t.cpp - ../utility.h.t.cpp - ../variance.h.t.cpp - ../variant.h.t.cpp - ../variant_pool.h.t.cpp - ../vector.h.t.cpp - ../version.h.t.cpp - ../visitor.h.t.cpp - ../wformat_spec.h.t.cpp - ../wstring.h.t.cpp - ../wstring_stream.h.t.cpp - ) diff --git a/test/syntax_check/c++17/CMakeLists.txt b/test/syntax_check/c++17/CMakeLists.txt deleted file mode 100644 index 5d8761ab..00000000 --- a/test/syntax_check/c++17/CMakeLists.txt +++ /dev/null @@ -1,314 +0,0 @@ -cmake_minimum_required(VERSION 3.5.0) -project(etl_17_syntax_check) - -add_definitions(-DETL_DEBUG) - -option(NO_STL "No STL" OFF) - -message(STATUS "Compiling for C++17") - -if (NO_STL) - message(STATUS "Compiling for No STL") - add_definitions(-DETL_NO_STL) -else() - message(STATUS "Compiling for STL") -endif() - -if (ETL_USE_TYPE_TRAITS_BUILTINS) - message(STATUS "Compiling for built-in type traits") - add_definitions(-DETL_USE_TYPE_TRAITS_BUILTINS) -endif() - -if (ETL_USER_DEFINED_TYPE_TRAITS) - message(STATUS "Compiling for user defined type traits") - add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS) -endif() - -if (ETL_FORCE_TEST_CPP03_IMPLEMENTATION) - message(STATUS "Force C++03 implementations") - add_definitions(-DETL_FORCE_TEST_CPP03_IMPLEMENTATION) -endif() - -add_library(t17 OBJECT) -target_compile_definitions(t17 PRIVATE __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS __STDC_FORMAT_MACROS) -target_include_directories(t17 PRIVATE "") -target_include_directories(t17 SYSTEM PRIVATE ../../../include) -set_target_properties(t17 PROPERTIES - CXX_STANDARD 17 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS ON - ) -target_compile_options(t17 - PRIVATE - -fsyntax-only - ) -target_sources(t17 PRIVATE etl_profile.h - ../absolute.h.t.cpp - ../algorithm.h.t.cpp - ../alignment.h.t.cpp - ../array.h.t.cpp - ../array_view.h.t.cpp - ../array_wrapper.h.t.cpp - ../atomic.h.t.cpp - ../base64.h.t.cpp - ../base64_decoder.h.t.cpp - ../base64_encoder.h.t.cpp - ../basic_format_spec.h.t.cpp - ../basic_string.h.t.cpp - ../basic_string_stream.h.t.cpp - ../binary.h.t.cpp - ../bip_buffer_spsc_atomic.h.t.cpp - ../bit.h.t.cpp - ../bitset.h.t.cpp - ../bit_stream.h.t.cpp - ../bloom_filter.h.t.cpp - ../bresenham_line.h.t.cpp - ../buffer_descriptors.h.t.cpp - ../byte.h.t.cpp - ../byte_stream.h.t.cpp - ../callback.h.t.cpp - ../callback_service.h.t.cpp - ../callback_timer.h.t.cpp - ../callback_timer_atomic.h.t.cpp - ../callback_timer_interrupt.h.t.cpp - ../callback_timer_locked.h.t.cpp - ../char_traits.h.t.cpp - ../checksum.h.t.cpp - ../circular_buffer.h.t.cpp - ../circular_iterator.h.t.cpp - ../combinations.h.t.cpp - ../compare.h.t.cpp - ../constant.h.t.cpp - ../container.h.t.cpp - ../correlation.h.t.cpp - ../covariance.h.t.cpp - ../crc1.h.t.cpp - ../crc16.h.t.cpp - ../crc16_a.h.t.cpp - ../crc16_arc.h.t.cpp - ../crc16_aug_ccitt.h.t.cpp - ../crc16_buypass.h.t.cpp - ../crc16_ccitt.h.t.cpp - ../crc16_cdma2000.h.t.cpp - ../crc16_dds110.h.t.cpp - ../crc16_dectr.h.t.cpp - ../crc16_dectx.h.t.cpp - ../crc16_dnp.h.t.cpp - ../crc16_en13757.h.t.cpp - ../crc16_genibus.h.t.cpp - ../crc16_kermit.h.t.cpp - ../crc16_m17.h.t.cpp - ../crc16_maxim.h.t.cpp - ../crc16_mcrf4xx.h.t.cpp - ../crc16_modbus.h.t.cpp - ../crc16_profibus.h.t.cpp - ../crc16_riello.h.t.cpp - ../crc16_t10dif.h.t.cpp - ../crc16_teledisk.h.t.cpp - ../crc16_tms37157.h.t.cpp - ../crc16_usb.h.t.cpp - ../crc16_x25.h.t.cpp - ../crc16_xmodem.h.t.cpp - ../crc32.h.t.cpp - ../crc32_bzip2.h.t.cpp - ../crc32_c.h.t.cpp - ../crc32_d.h.t.cpp - ../crc32_jamcrc.h.t.cpp - ../crc32_mpeg2.h.t.cpp - ../crc32_posix.h.t.cpp - ../crc32_q.h.t.cpp - ../crc32_xfer.h.t.cpp - ../crc64_ecma.h.t.cpp - ../crc8_ccitt.h.t.cpp - ../crc8_cdma2000.h.t.cpp - ../crc8_darc.h.t.cpp - ../crc8_dvbs2.h.t.cpp - ../crc8_ebu.h.t.cpp - ../crc8_icode.h.t.cpp - ../crc8_itu.h.t.cpp - ../crc8_j1850.h.t.cpp - ../crc8_j1850_zero.h.t.cpp - ../crc8_maxim.h.t.cpp - ../crc8_rohc.h.t.cpp - ../crc8_wcdma.h.t.cpp - ../cyclic_value.h.t.cpp - ../debounce.h.t.cpp - ../debug_count.h.t.cpp - ../delegate.h.t.cpp - ../delegate_service.h.t.cpp - ../deque.h.t.cpp - ../endianness.h.t.cpp - ../enum_type.h.t.cpp - ../error_handler.h.t.cpp - ../exception.h.t.cpp - ../expected.h.t.cpp - ../factorial.h.t.cpp - ../fibonacci.h.t.cpp - ../file_error_numbers.h.t.cpp - ../fixed_iterator.h.t.cpp - ../fixed_sized_memory_block_allocator.h.t.cpp - ../flags.h.t.cpp - ../flat_map.h.t.cpp - ../flat_multimap.h.t.cpp - ../flat_multiset.h.t.cpp - ../flat_set.h.t.cpp - ../fnv_1.h.t.cpp - ../format_spec.h.t.cpp - ../forward_list.h.t.cpp - ../frame_check_sequence.h.t.cpp - ../fsm.h.t.cpp - ../function.h.t.cpp - ../functional.h.t.cpp - ../gamma.h.t.cpp - ../gcd.h.t.cpp - ../generic_pool.h.t.cpp - ../hash.h.t.cpp - ../hfsm.h.t.cpp - ../histogram.h.t.cpp - ../ihash.h.t.cpp - ../imemory_block_allocator.h.t.cpp - ../indirect_vector.h.t.cpp - ../initializer_list.h.t.cpp - ../instance_count.h.t.cpp - ../integral_limits.h.t.cpp - ../intrusive_forward_list.h.t.cpp - ../intrusive_links.h.t.cpp - ../intrusive_list.h.t.cpp - ../intrusive_queue.h.t.cpp - ../intrusive_stack.h.t.cpp - ../invert.h.t.cpp - ../io_port.h.t.cpp - ../ipool.h.t.cpp - ../ireference_counted_message_pool.h.t.cpp - ../iterator.h.t.cpp - ../jenkins.h.t.cpp - ../largest.h.t.cpp - ../lcm.h.t.cpp - ../limiter.h.t.cpp - ../limits.h.t.cpp - ../list.h.t.cpp - ../log.h.t.cpp - ../macros.h.t.cpp - ../map.h.t.cpp - ../math.h.t.cpp - ../math_constants.h.t.cpp - ../mean.h.t.cpp - ../memory.h.t.cpp - ../memory_model.h.t.cpp - ../mem_cast.h.t.cpp - ../message.h.t.cpp - ../message_broker.h.t.cpp - ../message_bus.h.t.cpp - ../message_packet.h.t.cpp - ../message_router.h.t.cpp - ../message_router_registry.h.t.cpp - ../message_timer.h.t.cpp - ../message_timer_atomic.h.t.cpp - ../message_timer_interrupt.h.t.cpp - ../message_timer_locked.h.t.cpp - ../message_types.h.t.cpp - ../multimap.h.t.cpp - ../multiset.h.t.cpp - ../multi_array.h.t.cpp - ../multi_range.h.t.cpp - ../multi_span.h.t.cpp - ../multi_vector.h.t.cpp - ../murmur3.h.t.cpp - ../mutex.h.t.cpp - ../negative.h.t.cpp - ../nth_type.h.t.cpp - ../nullptr.h.t.cpp - ../null_type.h.t.cpp - ../numeric.h.t.cpp - ../observer.h.t.cpp - ../optional.h.t.cpp - ../overload.h.t.cpp - ../packet.h.t.cpp - ../parameter_pack.h.t.cpp - ../parameter_type.h.t.cpp - ../pearson.h.t.cpp - ../permutations.h.t.cpp - ../placement_new.h.t.cpp - ../platform.h.t.cpp - ../poly_span.h.t.cpp - ../pool.h.t.cpp - ../power.h.t.cpp - ../priority_queue.h.t.cpp - ../pseudo_moving_average.h.t.cpp - ../quantize.h.t.cpp - ../queue.h.t.cpp - ../queue_lockable.h.t.cpp - ../queue_mpmc_mutex.h.t.cpp - ../queue_spsc_atomic.h.t.cpp - ../queue_spsc_isr.h.t.cpp - ../queue_spsc_locked.h.t.cpp - ../radix.h.t.cpp - ../random.h.t.cpp - ../ratio.h.t.cpp - ../reference_counted_message.h.t.cpp - ../reference_counted_message_pool.h.t.cpp - ../reference_counted_object.h.t.cpp - ../reference_flat_map.h.t.cpp - ../reference_flat_multimap.h.t.cpp - ../reference_flat_multiset.h.t.cpp - ../reference_flat_set.h.t.cpp - ../rescale.h.t.cpp - ../result.h.t.cpp - ../rms.h.t.cpp - ../scaled_rounding.h.t.cpp - ../scheduler.h.t.cpp - ../set.h.t.cpp - ../shared_message.h.t.cpp - ../singleton.h.t.cpp - ../smallest.h.t.cpp - ../span.h.t.cpp - ../sqrt.h.t.cpp - ../stack.h.t.cpp - ../standard_deviation.h.t.cpp - ../state_chart.h.t.cpp - ../static_assert.h.t.cpp - ../string.h.t.cpp - ../stringify.h.t.cpp - ../string_stream.h.t.cpp - ../string_utilities.h.t.cpp - ../string_view.h.t.cpp - ../successor.h.t.cpp - ../task.h.t.cpp - ../threshold.h.t.cpp - ../timer.h.t.cpp - ../to_arithmetic.h.t.cpp - ../to_string.h.t.cpp - ../to_u16string.h.t.cpp - ../to_u32string.h.t.cpp - ../to_u8string.h.t.cpp - ../to_wstring.h.t.cpp - ../type_def.h.t.cpp - ../type_lookup.h.t.cpp - ../type_select.h.t.cpp - ../type_traits.h.t.cpp - ../u16format_spec.h.t.cpp - ../u16string.h.t.cpp - ../u16string_stream.h.t.cpp - ../u32format_spec.h.t.cpp - ../u32string.h.t.cpp - ../u32string_stream.h.t.cpp - ../u8format_spec.h.t.cpp - ../u8string.h.t.cpp - ../u8string_stream.h.t.cpp - ../unaligned_type.h.t.cpp - ../unordered_map.h.t.cpp - ../unordered_multimap.h.t.cpp - ../unordered_multiset.h.t.cpp - ../unordered_set.h.t.cpp - ../user_type.h.t.cpp - ../utility.h.t.cpp - ../variance.h.t.cpp - ../variant.h.t.cpp - ../variant_pool.h.t.cpp - ../vector.h.t.cpp - ../version.h.t.cpp - ../visitor.h.t.cpp - ../wformat_spec.h.t.cpp - ../wstring.h.t.cpp - ../wstring_stream.h.t.cpp - ) diff --git a/test/syntax_check/c++17/etl_profile.h b/test/syntax_check/c++17/etl_profile.h deleted file mode 100644 index 05efac58..00000000 --- a/test/syntax_check/c++17/etl_profile.h +++ /dev/null @@ -1,69 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2021 Bo Rydberg - -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_PROFILE_H__ -#define __ETL_PROFILE_H__ - -#define ETL_TARGET_DEVICE_GENERIC -#define ETL_TARGET_OS_NONE -#define ETL_CPP11_SUPPORTED 1 -#define ETL_CPP14_SUPPORTED 1 -#define ETL_CPP17_SUPPORTED 1 -#define ETL_CPP20_SUPPORTED 0 -#define ETL_IN_UNIT_TEST -#define ETL_CALLBACK_TIMER_USE_INTERRUPT_LOCK -#define ETL_CALLBACK_TIMER_DISABLE_INTERRUPTS -#define ETL_CALLBACK_TIMER_ENABLE_INTERRUPTS -#define ETL_MESSAGE_TIMER_USE_INTERRUPT_LOCK -#define ETL_MESSAGE_TIMER_DISABLE_INTERRUPTS -#define ETL_MESSAGE_TIMER_ENABLE_INTERRUPTS - -#if defined(ETL_FORCE_TEST_CPP03_IMPLEMENTATION) - #define ETL_FUNCTION_FORCE_CPP03_IMPLEMENTATION - #define ETL_PRIORITY_QUEUE_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_ATOMIC_FORCE_CPP03_IMPLEMENTATION - #define ETL_VARIANT_FORCE_CPP03_IMPLEMENTATION - #define ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_ISR_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION - #define ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION - #define ETL_LARGEST_TYPE_FORCE_CPP03_IMPLEMENTATION - #define ETL_TYPE_SELECT_FORCE_CPP03_IMPLEMENTATION - #define ETL_UNINITIALIZED_BUFFER_FORCE_CPP03_IMPLEMENTATION - #define ETL_CRC_FORCE_CPP03_IMPLEMENTATION - #define ETL_MEM_CAST_FORCE_CPP03_IMPLEMENTATION - #define ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION - #define ETL_OBSERVER_FORCE_CPP03_IMPLEMENTATION - #define ETL_MESSAGE_ROUTER_FORCE_CPP03_IMPLEMENTATION - #define ETL_FSM_FORCE_CPP03_IMPLEMENTATION - #define ETL_SINGLETON_FORCE_CPP03_IMPLEMENTATION -#endif - -#endif diff --git a/test/syntax_check/c++20/CMakeLists.txt b/test/syntax_check/c++20/CMakeLists.txt deleted file mode 100644 index f38c48ad..00000000 --- a/test/syntax_check/c++20/CMakeLists.txt +++ /dev/null @@ -1,314 +0,0 @@ -cmake_minimum_required(VERSION 3.5.0) -project(etl_20_syntax_check) - -add_definitions(-DETL_DEBUG) - -option(NO_STL "No STL" OFF) - -message(STATUS "Compiling for C++20") - -if (NO_STL) - message(STATUS "Compiling for No STL") - add_definitions(-DETL_NO_STL) -else() - message(STATUS "Compiling for STL") -endif() - -if (ETL_USE_TYPE_TRAITS_BUILTINS) - message(STATUS "Compiling for built-in type traits") - add_definitions(-DETL_USE_TYPE_TRAITS_BUILTINS) -endif() - -if (ETL_USER_DEFINED_TYPE_TRAITS) - message(STATUS "Compiling for user defined type traits") - add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS) -endif() - -if (ETL_FORCE_TEST_CPP03_IMPLEMENTATION) - message(STATUS "Force C++03 implementations") - add_definitions(-DETL_FORCE_TEST_CPP03_IMPLEMENTATION) -endif() - -add_library(t20 OBJECT) -target_compile_definitions(t20 PRIVATE __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS __STDC_FORMAT_MACROS) -target_include_directories(t20 PRIVATE "") -target_include_directories(t20 SYSTEM PRIVATE ../../../include) -set_target_properties(t20 PROPERTIES - CXX_STANDARD 20 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS ON - ) -target_compile_options(t20 - PRIVATE - -fsyntax-only - ) -target_sources(t20 PRIVATE etl_profile.h - ../absolute.h.t.cpp - ../algorithm.h.t.cpp - ../alignment.h.t.cpp - ../array.h.t.cpp - ../array_view.h.t.cpp - ../array_wrapper.h.t.cpp - ../atomic.h.t.cpp - ../base64.h.t.cpp - ../base64_decoder.h.t.cpp - ../base64_encoder.h.t.cpp - ../basic_format_spec.h.t.cpp - ../basic_string.h.t.cpp - ../basic_string_stream.h.t.cpp - ../binary.h.t.cpp - ../bip_buffer_spsc_atomic.h.t.cpp - ../bit.h.t.cpp - ../bitset.h.t.cpp - ../bit_stream.h.t.cpp - ../bloom_filter.h.t.cpp - ../bresenham_line.h.t.cpp - ../buffer_descriptors.h.t.cpp - ../byte.h.t.cpp - ../byte_stream.h.t.cpp - ../callback.h.t.cpp - ../callback_service.h.t.cpp - ../callback_timer.h.t.cpp - ../callback_timer_atomic.h.t.cpp - ../callback_timer_interrupt.h.t.cpp - ../callback_timer_locked.h.t.cpp - ../char_traits.h.t.cpp - ../checksum.h.t.cpp - ../circular_buffer.h.t.cpp - ../circular_iterator.h.t.cpp - ../combinations.h.t.cpp - ../compare.h.t.cpp - ../constant.h.t.cpp - ../container.h.t.cpp - ../correlation.h.t.cpp - ../covariance.h.t.cpp - ../crc1.h.t.cpp - ../crc16.h.t.cpp - ../crc16_a.h.t.cpp - ../crc16_arc.h.t.cpp - ../crc16_aug_ccitt.h.t.cpp - ../crc16_buypass.h.t.cpp - ../crc16_ccitt.h.t.cpp - ../crc16_cdma2000.h.t.cpp - ../crc16_dds110.h.t.cpp - ../crc16_dectr.h.t.cpp - ../crc16_dectx.h.t.cpp - ../crc16_dnp.h.t.cpp - ../crc16_en13757.h.t.cpp - ../crc16_genibus.h.t.cpp - ../crc16_kermit.h.t.cpp - ../crc16_m17.h.t.cpp - ../crc16_maxim.h.t.cpp - ../crc16_mcrf4xx.h.t.cpp - ../crc16_modbus.h.t.cpp - ../crc16_profibus.h.t.cpp - ../crc16_riello.h.t.cpp - ../crc16_t10dif.h.t.cpp - ../crc16_teledisk.h.t.cpp - ../crc16_tms37157.h.t.cpp - ../crc16_usb.h.t.cpp - ../crc16_x25.h.t.cpp - ../crc16_xmodem.h.t.cpp - ../crc32.h.t.cpp - ../crc32_bzip2.h.t.cpp - ../crc32_c.h.t.cpp - ../crc32_d.h.t.cpp - ../crc32_jamcrc.h.t.cpp - ../crc32_mpeg2.h.t.cpp - ../crc32_posix.h.t.cpp - ../crc32_q.h.t.cpp - ../crc32_xfer.h.t.cpp - ../crc64_ecma.h.t.cpp - ../crc8_ccitt.h.t.cpp - ../crc8_cdma2000.h.t.cpp - ../crc8_darc.h.t.cpp - ../crc8_dvbs2.h.t.cpp - ../crc8_ebu.h.t.cpp - ../crc8_icode.h.t.cpp - ../crc8_itu.h.t.cpp - ../crc8_j1850.h.t.cpp - ../crc8_j1850_zero.h.t.cpp - ../crc8_maxim.h.t.cpp - ../crc8_rohc.h.t.cpp - ../crc8_wcdma.h.t.cpp - ../cyclic_value.h.t.cpp - ../debounce.h.t.cpp - ../debug_count.h.t.cpp - ../delegate.h.t.cpp - ../delegate_service.h.t.cpp - ../deque.h.t.cpp - ../endianness.h.t.cpp - ../enum_type.h.t.cpp - ../error_handler.h.t.cpp - ../exception.h.t.cpp - ../expected.h.t.cpp - ../factorial.h.t.cpp - ../fibonacci.h.t.cpp - ../file_error_numbers.h.t.cpp - ../fixed_iterator.h.t.cpp - ../fixed_sized_memory_block_allocator.h.t.cpp - ../flags.h.t.cpp - ../flat_map.h.t.cpp - ../flat_multimap.h.t.cpp - ../flat_multiset.h.t.cpp - ../flat_set.h.t.cpp - ../fnv_1.h.t.cpp - ../format_spec.h.t.cpp - ../forward_list.h.t.cpp - ../frame_check_sequence.h.t.cpp - ../fsm.h.t.cpp - ../function.h.t.cpp - ../functional.h.t.cpp - ../gamma.h.t.cpp - ../gcd.h.t.cpp - ../generic_pool.h.t.cpp - ../hash.h.t.cpp - ../hfsm.h.t.cpp - ../histogram.h.t.cpp - ../ihash.h.t.cpp - ../imemory_block_allocator.h.t.cpp - ../indirect_vector.h.t.cpp - ../initializer_list.h.t.cpp - ../instance_count.h.t.cpp - ../integral_limits.h.t.cpp - ../intrusive_forward_list.h.t.cpp - ../intrusive_links.h.t.cpp - ../intrusive_list.h.t.cpp - ../intrusive_queue.h.t.cpp - ../intrusive_stack.h.t.cpp - ../invert.h.t.cpp - ../io_port.h.t.cpp - ../ipool.h.t.cpp - ../ireference_counted_message_pool.h.t.cpp - ../iterator.h.t.cpp - ../jenkins.h.t.cpp - ../largest.h.t.cpp - ../lcm.h.t.cpp - ../limiter.h.t.cpp - ../limits.h.t.cpp - ../list.h.t.cpp - ../log.h.t.cpp - ../macros.h.t.cpp - ../map.h.t.cpp - ../math.h.t.cpp - ../math_constants.h.t.cpp - ../mean.h.t.cpp - ../memory.h.t.cpp - ../memory_model.h.t.cpp - ../mem_cast.h.t.cpp - ../message.h.t.cpp - ../message_broker.h.t.cpp - ../message_bus.h.t.cpp - ../message_packet.h.t.cpp - ../message_router.h.t.cpp - ../message_router_registry.h.t.cpp - ../message_timer.h.t.cpp - ../message_timer_atomic.h.t.cpp - ../message_timer_interrupt.h.t.cpp - ../message_timer_locked.h.t.cpp - ../message_types.h.t.cpp - ../multimap.h.t.cpp - ../multiset.h.t.cpp - ../multi_array.h.t.cpp - ../multi_range.h.t.cpp - ../multi_span.h.t.cpp - ../multi_vector.h.t.cpp - ../murmur3.h.t.cpp - ../mutex.h.t.cpp - ../negative.h.t.cpp - ../nth_type.h.t.cpp - ../nullptr.h.t.cpp - ../null_type.h.t.cpp - ../numeric.h.t.cpp - ../observer.h.t.cpp - ../optional.h.t.cpp - ../overload.h.t.cpp - ../packet.h.t.cpp - ../parameter_pack.h.t.cpp - ../parameter_type.h.t.cpp - ../pearson.h.t.cpp - ../permutations.h.t.cpp - ../placement_new.h.t.cpp - ../platform.h.t.cpp - ../poly_span.h.t.cpp - ../pool.h.t.cpp - ../power.h.t.cpp - ../priority_queue.h.t.cpp - ../pseudo_moving_average.h.t.cpp - ../quantize.h.t.cpp - ../queue.h.t.cpp - ../queue_lockable.h.t.cpp - ../queue_mpmc_mutex.h.t.cpp - ../queue_spsc_atomic.h.t.cpp - ../queue_spsc_isr.h.t.cpp - ../queue_spsc_locked.h.t.cpp - ../radix.h.t.cpp - ../random.h.t.cpp - ../ratio.h.t.cpp - ../reference_counted_message.h.t.cpp - ../reference_counted_message_pool.h.t.cpp - ../reference_counted_object.h.t.cpp - ../reference_flat_map.h.t.cpp - ../reference_flat_multimap.h.t.cpp - ../reference_flat_multiset.h.t.cpp - ../reference_flat_set.h.t.cpp - ../rescale.h.t.cpp - ../result.h.t.cpp - ../rms.h.t.cpp - ../scaled_rounding.h.t.cpp - ../scheduler.h.t.cpp - ../set.h.t.cpp - ../shared_message.h.t.cpp - ../singleton.h.t.cpp - ../smallest.h.t.cpp - ../span.h.t.cpp - ../sqrt.h.t.cpp - ../stack.h.t.cpp - ../standard_deviation.h.t.cpp - ../state_chart.h.t.cpp - ../static_assert.h.t.cpp - ../string.h.t.cpp - ../stringify.h.t.cpp - ../string_stream.h.t.cpp - ../string_utilities.h.t.cpp - ../string_view.h.t.cpp - ../successor.h.t.cpp - ../task.h.t.cpp - ../threshold.h.t.cpp - ../timer.h.t.cpp - ../to_arithmetic.h.t.cpp - ../to_string.h.t.cpp - ../to_u16string.h.t.cpp - ../to_u32string.h.t.cpp - ../to_u8string.h.t.cpp - ../to_wstring.h.t.cpp - ../type_def.h.t.cpp - ../type_lookup.h.t.cpp - ../type_select.h.t.cpp - ../type_traits.h.t.cpp - ../u16format_spec.h.t.cpp - ../u16string.h.t.cpp - ../u16string_stream.h.t.cpp - ../u32format_spec.h.t.cpp - ../u32string.h.t.cpp - ../u32string_stream.h.t.cpp - ../u8format_spec.h.t.cpp - ../u8string.h.t.cpp - ../u8string_stream.h.t.cpp - ../unaligned_type.h.t.cpp - ../unordered_map.h.t.cpp - ../unordered_multimap.h.t.cpp - ../unordered_multiset.h.t.cpp - ../unordered_set.h.t.cpp - ../user_type.h.t.cpp - ../utility.h.t.cpp - ../variance.h.t.cpp - ../variant.h.t.cpp - ../variant_pool.h.t.cpp - ../vector.h.t.cpp - ../version.h.t.cpp - ../visitor.h.t.cpp - ../wformat_spec.h.t.cpp - ../wstring.h.t.cpp - ../wstring_stream.h.t.cpp - ) diff --git a/test/syntax_check/c++20/etl_profile.h b/test/syntax_check/c++20/etl_profile.h deleted file mode 100644 index ab630f66..00000000 --- a/test/syntax_check/c++20/etl_profile.h +++ /dev/null @@ -1,69 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2021 Bo Rydberg - -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_PROFILE_H__ -#define __ETL_PROFILE_H__ - -#define ETL_TARGET_DEVICE_GENERIC -#define ETL_TARGET_OS_NONE -#define ETL_CPP11_SUPPORTED 1 -#define ETL_CPP14_SUPPORTED 1 -#define ETL_CPP17_SUPPORTED 1 -#define ETL_CPP20_SUPPORTED 1 -#define ETL_IN_UNIT_TEST -#define ETL_CALLBACK_TIMER_USE_INTERRUPT_LOCK -#define ETL_CALLBACK_TIMER_DISABLE_INTERRUPTS -#define ETL_CALLBACK_TIMER_ENABLE_INTERRUPTS -#define ETL_MESSAGE_TIMER_USE_INTERRUPT_LOCK -#define ETL_MESSAGE_TIMER_DISABLE_INTERRUPTS -#define ETL_MESSAGE_TIMER_ENABLE_INTERRUPTS - -#if defined(ETL_FORCE_TEST_CPP03_IMPLEMENTATION) - #define ETL_FUNCTION_FORCE_CPP03_IMPLEMENTATION - #define ETL_PRIORITY_QUEUE_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_ATOMIC_FORCE_CPP03_IMPLEMENTATION - #define ETL_VARIANT_FORCE_CPP03_IMPLEMENTATION - #define ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_ISR_FORCE_CPP03_IMPLEMENTATION - #define ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION - #define ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION - #define ETL_LARGEST_TYPE_FORCE_CPP03_IMPLEMENTATION - #define ETL_TYPE_SELECT_FORCE_CPP03_IMPLEMENTATION - #define ETL_UNINITIALIZED_BUFFER_FORCE_CPP03_IMPLEMENTATION - #define ETL_CRC_FORCE_CPP03_IMPLEMENTATION - #define ETL_MEM_CAST_FORCE_CPP03_IMPLEMENTATION - #define ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION - #define ETL_OBSERVER_FORCE_CPP03_IMPLEMENTATION - #define ETL_MESSAGE_ROUTER_FORCE_CPP03_IMPLEMENTATION - #define ETL_FSM_FORCE_CPP03_IMPLEMENTATION - #define ETL_SINGLETON_FORCE_CPP03_IMPLEMENTATION -#endif - -#endif diff --git a/test/syntax_check/c++14/etl_profile.h b/test/syntax_check/etl_profile.h similarity index 96% rename from test/syntax_check/c++14/etl_profile.h rename to test/syntax_check/etl_profile.h index 54451abc..ed633219 100644 --- a/test/syntax_check/c++14/etl_profile.h +++ b/test/syntax_check/etl_profile.h @@ -31,10 +31,6 @@ SOFTWARE. #define ETL_TARGET_DEVICE_GENERIC #define ETL_TARGET_OS_NONE -#define ETL_CPP11_SUPPORTED 1 -#define ETL_CPP14_SUPPORTED 1 -#define ETL_CPP17_SUPPORTED 0 -#define ETL_CPP20_SUPPORTED 0 #define ETL_IN_UNIT_TEST #define ETL_CALLBACK_TIMER_USE_INTERRUPT_LOCK #define ETL_CALLBACK_TIMER_DISABLE_INTERRUPTS diff --git a/test/syntax_check/function_traits.h.t.cpp b/test/syntax_check/function_traits.h.t.cpp new file mode 100644 index 00000000..955b6be0 --- /dev/null +++ b/test/syntax_check/function_traits.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +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 diff --git a/test/syntax_check/singleton_base.h.t.cpp b/test/syntax_check/singleton_base.h.t.cpp new file mode 100644 index 00000000..723ffcf9 --- /dev/null +++ b/test/syntax_check/singleton_base.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2024 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 diff --git a/test/syntax_check/tuple.h.t.cpp b/test/syntax_check/tuple.h.t.cpp new file mode 100644 index 00000000..ed8e8d64 --- /dev/null +++ b/test/syntax_check/tuple.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +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 diff --git a/test/syntax_check/uncopyable.h.t.cpp b/test/syntax_check/uncopyable.h.t.cpp new file mode 100644 index 00000000..90cc67ea --- /dev/null +++ b/test/syntax_check/uncopyable.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2024 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 diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index 43ff2379..f1242718 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -190,6 +190,15 @@ namespace CHECK_EQUAL(std::distance(data.begin(), expected), std::distance(data.begin(), result)); } + //************************************************************************* + TEST(min_element_empty) + { + Vector dataEmpty; + Vector::iterator expected = std::min_element(dataEmpty.begin(), dataEmpty.end()); + Vector::iterator result = etl::min_element(dataEmpty.begin(), dataEmpty.end()); + CHECK_EQUAL(std::distance(dataEmpty.end(), expected), std::distance(dataEmpty.end(), result)); + } + //************************************************************************* TEST(max_element) { @@ -206,6 +215,15 @@ namespace CHECK_EQUAL(std::distance(data.begin(), expected), std::distance(data.begin(), result)); } + //************************************************************************* + TEST(max_element_empty) + { + Vector dataEmpty; + Vector::iterator expected = std::max_element(dataEmpty.begin(), dataEmpty.end()); + Vector::iterator result = etl::max_element(dataEmpty.begin(), dataEmpty.end()); + CHECK_EQUAL(std::distance(dataEmpty.end(), expected), std::distance(dataEmpty.end(), result)); + } + //************************************************************************* TEST(minmax_element) { @@ -224,6 +242,16 @@ namespace CHECK_EQUAL(std::distance(data.begin(), expected.second), std::distance(data.begin(), result.second)); } + //************************************************************************* + TEST(minmax_element_empty) + { + Vector dataEmpty; + std::pair expected = std::minmax_element(dataEmpty.begin(), dataEmpty.end()); + std::pair result = etl::minmax_element(dataEmpty.begin(), dataEmpty.end()); + CHECK_EQUAL(std::distance(dataEmpty.begin(), expected.first), std::distance(dataEmpty.begin(), result.first)); + CHECK_EQUAL(std::distance(dataEmpty.begin(), expected.second), std::distance(dataEmpty.begin(), result.second)); + } + //************************************************************************* TEST(minmax) { @@ -1982,10 +2010,10 @@ namespace { std::shuffle(data.begin(), data.end(), urng); - std::forward_list data1(data.begin(), data.end()); + std::vector data1(data.begin(), data.end()); std::forward_list data2(data.begin(), data.end()); - data1.sort(); + std::sort(data1.begin(), data1.end()); etl::selection_sort(data2.begin(), data2.end()); bool is_same = std::equal(data1.begin(), data1.end(), data2.begin()); diff --git a/test/test_alignment.cpp b/test/test_alignment.cpp index 29de827a..d9a9de57 100644 --- a/test/test_alignment.cpp +++ b/test/test_alignment.cpp @@ -48,6 +48,23 @@ void f(int) { } +struct A_t +{ + A_t(uint32_t v_x, uint8_t v_y) + : x(v_x) + , y(v_y) + { + } + + bool operator==(A_t& other) + { + return other.x == x && other.y == y; + } + + uint32_t x; + uint8_t y; +}; + namespace { SUITE(test_alignment) @@ -155,5 +172,29 @@ namespace CHECK_EQUAL(32, alignof(etl::type_with_alignment_t<32>)); CHECK_EQUAL(64, alignof(etl::type_with_alignment_t<64>)); } + + //************************************************************************* + TEST(test_typed_storage) + { + etl::typed_storage a; + + CHECK_EQUAL(false, a.has_value()); + + auto& b = a.create(123, 4); + + CHECK_EQUAL(true, a.has_value()); + + CHECK_EQUAL(a->x, 123); + CHECK_EQUAL(a->y, 4); + + CHECK_EQUAL(b.x, 123); + CHECK_EQUAL(b.y, 4); + + CHECK_TRUE(*a == b); + + CHECK_EQUAL(true, a.has_value()); + a.destroy(); + CHECK_EQUAL(false, a.has_value()); + } }; } diff --git a/test/test_atomic.cpp b/test/test_atomic.cpp index 091c8b4c..281b7650 100644 --- a/test/test_atomic.cpp +++ b/test/test_atomic.cpp @@ -66,7 +66,7 @@ namespace ETL_END_ENUM_TYPE }; - SUITE(test_atomic_std) + SUITE(test_atomic) { //************************************************************************* TEST(test_atomic_integer_is_lock_free) @@ -75,6 +75,11 @@ namespace etl::atomic test; CHECK_EQUAL(compare.is_lock_free(), test.is_lock_free()); + +#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE + CHECK_TRUE(etl::atomic::is_always_lock_free); + CHECK_TRUE(test.is_always_lock_free); +#endif } //************************************************************************* @@ -84,8 +89,30 @@ namespace etl::atomic test; CHECK_EQUAL(compare.is_lock_free(), test.is_lock_free()); + +#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE + CHECK_TRUE(etl::atomic::is_always_lock_free); + CHECK_TRUE(test.is_always_lock_free); +#endif } +#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE + //************************************************************************* + TEST(test_atomic_is_always_lock_free) + { + struct S + { + int a; + int b; + int c; + }; + + CHECK_TRUE(etl::atomic::is_always_lock_free); + CHECK_TRUE(etl::atomic::is_always_lock_free); + CHECK_FALSE(etl::atomic::is_always_lock_free); + } +#endif + //************************************************************************* TEST(test_atomic_integer_load) { diff --git a/test/test_base64_RFC2152_decoder.cpp b/test/test_base64_RFC2152_decoder.cpp index 2428095e..64cc11ca 100644 --- a/test/test_base64_RFC2152_decoder.cpp +++ b/test/test_base64_RFC2152_decoder.cpp @@ -64,7 +64,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -76,6 +76,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC2152_encoder.cpp b/test/test_base64_RFC2152_encoder.cpp index bd4c2b13..f463da39 100644 --- a/test/test_base64_RFC2152_encoder.cpp +++ b/test/test_base64_RFC2152_encoder.cpp @@ -62,7 +62,7 @@ namespace std::string encoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC3501_decoder.cpp b/test/test_base64_RFC3501_decoder.cpp index 60915724..2e3c2faf 100644 --- a/test/test_base64_RFC3501_decoder.cpp +++ b/test/test_base64_RFC3501_decoder.cpp @@ -61,7 +61,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -73,6 +73,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC3501_encoder.cpp b/test/test_base64_RFC3501_encoder.cpp index de54cbe6..0acc36a3 100644 --- a/test/test_base64_RFC3501_encoder.cpp +++ b/test/test_base64_RFC3501_encoder.cpp @@ -62,7 +62,7 @@ namespace std::string encoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp b/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp index bf8e177e..c1c9280d 100644 --- a/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp @@ -61,7 +61,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -73,6 +73,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_URL_decoder_with_padding.cpp b/test/test_base64_RFC4648_URL_decoder_with_padding.cpp index 96bd3c74..ab75c182 100644 --- a/test/test_base64_RFC4648_URL_decoder_with_padding.cpp +++ b/test/test_base64_RFC4648_URL_decoder_with_padding.cpp @@ -61,7 +61,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -73,6 +73,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp b/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp index 0b97f8c9..56835228 100644 --- a/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp @@ -62,7 +62,7 @@ namespace std::string encoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_URL_encoder_with_padding.cpp b/test/test_base64_RFC4648_URL_encoder_with_padding.cpp index 90a95527..9c9f2e21 100644 --- a/test/test_base64_RFC4648_URL_encoder_with_padding.cpp +++ b/test/test_base64_RFC4648_URL_encoder_with_padding.cpp @@ -62,7 +62,7 @@ namespace std::string encoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_decoder_with_no_padding.cpp b/test/test_base64_RFC4648_decoder_with_no_padding.cpp index ea21ebcc..8fbde338 100644 --- a/test/test_base64_RFC4648_decoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_decoder_with_no_padding.cpp @@ -61,7 +61,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -73,6 +73,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_decoder_with_padding.cpp b/test/test_base64_RFC4648_decoder_with_padding.cpp index 6d910ecd..fef5112a 100644 --- a/test/test_base64_RFC4648_decoder_with_padding.cpp +++ b/test/test_base64_RFC4648_decoder_with_padding.cpp @@ -61,7 +61,7 @@ namespace std::vector decoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -73,6 +73,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_encoder_with_no_padding.cpp b/test/test_base64_RFC4648_encoder_with_no_padding.cpp index 2d964d80..eefe003f 100644 --- a/test/test_base64_RFC4648_encoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_encoder_with_no_padding.cpp @@ -62,7 +62,7 @@ namespace std::string encoded_output; bool received_final_block = false; - codec::callback_type callback = [](const codec::span_type& sp) + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_base64_RFC4648_encoder_with_padding.cpp b/test/test_base64_RFC4648_encoder_with_padding.cpp index 148b1fe4..50b48b3b 100644 --- a/test/test_base64_RFC4648_encoder_with_padding.cpp +++ b/test/test_base64_RFC4648_encoder_with_padding.cpp @@ -61,8 +61,8 @@ namespace std::string encoded_output; bool received_final_block = false; - - codec::callback_type callback = [](const codec::span_type& sp) + + auto lambda = [](const codec::span_type& sp) { if (sp.empty()) { @@ -74,6 +74,8 @@ namespace } }; + codec::callback_type callback = lambda; + std::array input_data = { 0x3B, 0x27, 0x03, 0x43, 0x2D, 0xFB, 0x28, 0x2A, 0x61, 0xAE, 0xBC, 0x49, 0x71, 0x32, 0x01, 0x15, diff --git a/test/test_binary.cpp b/test/test_binary.cpp index 9cff4fb1..32d6343e 100644 --- a/test/test_binary.cpp +++ b/test/test_binary.cpp @@ -256,7 +256,7 @@ namespace CHECK_EQUAL(0x6FU, int(value)); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_rotate_left8_constexpr) { @@ -357,7 +357,7 @@ namespace CHECK_EQUAL(0x6E79U, int(value)); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_rotate_left16_constexpr) { @@ -422,7 +422,7 @@ namespace CHECK_EQUAL(0xDBU, int(value)); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_rotate_right8_constexpr) { @@ -523,7 +523,7 @@ namespace CHECK_EQUAL(0x5B9EU, int(value)); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_rotate_right16_constexpr) { @@ -550,7 +550,7 @@ namespace CHECK_EQUAL(0xCB73U, int(value)); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_rotate16_constexpr) { @@ -591,7 +591,7 @@ namespace CHECK_EQUAL(0x35U, int(value)); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_reverse_bits8_constexpr) { @@ -620,7 +620,7 @@ namespace CHECK_EQUAL(0xA5A5U, value); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_reverse_bits16_constexpr) { @@ -649,7 +649,7 @@ namespace CHECK_EQUAL(uint32_t(0x5A5A5A5AUL), value); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_reverse_bits32_constexpr) { @@ -678,7 +678,7 @@ namespace CHECK_EQUAL(uint64_t(0x5A5A5A5A5A5A5A5AULL), value); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_reverse_bits64_constexpr) { @@ -707,7 +707,7 @@ namespace CHECK_EQUAL(0x5AA5U, value); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_reverse_bytes16_constexpr) { @@ -736,7 +736,7 @@ namespace CHECK_EQUAL(0xA5A55A5AUL, value); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_reverse_bytes32_constexpr) { @@ -765,7 +765,7 @@ namespace CHECK_EQUAL(0xA5A55A5AA5A55A5AULL, value); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_reverse_bytes64_constexpr) { @@ -794,7 +794,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_binary_to_gray8_constexpr) { @@ -823,7 +823,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_binary_to_gray16_constexpr) { @@ -858,7 +858,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_binary_to_gray32_constexpr) { @@ -893,7 +893,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_binary_to_gray64_constexpr) { @@ -914,7 +914,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_gray_to_binary8_constexpr) { @@ -935,7 +935,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_gray_to_binary16_constexpr) { @@ -961,7 +961,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_gray_to_binary32_constexpr) { @@ -987,7 +987,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_gray_to_binary64_constexpr) { @@ -1008,7 +1008,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_bits_8_constexpr) { @@ -1029,7 +1029,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_bits_16_constexpr) { @@ -1056,7 +1056,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_bits_32_constexpr) { @@ -1083,7 +1083,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_bits_64_constexpr) { @@ -1104,7 +1104,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_parity_8_constexpr) { @@ -1125,7 +1125,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_parity_16_constexpr) { @@ -1152,7 +1152,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_parity_32_constexpr) { @@ -1179,7 +1179,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_parity_64_constexpr) { @@ -1260,7 +1260,7 @@ namespace CHECK_EQUAL(test_fold_bits(data, 63), (etl::fold_bits(data))); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_fold_bits_constexpr) { @@ -1459,7 +1459,7 @@ namespace CHECK_EQUAL(178956970, (etl::sign_extend(value32))); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_sign_extend_template1_constexpr) { @@ -1521,7 +1521,7 @@ namespace CHECK_EQUAL(-22, (etl::sign_extend(value))); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_sign_extend_template1b_constexpr) { @@ -1578,7 +1578,7 @@ namespace CHECK_EQUAL(178956970, (etl::sign_extend(value32, 30))); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_sign_extend_template2_constexpr) { @@ -1640,7 +1640,7 @@ namespace CHECK_EQUAL(-22, (etl::sign_extend(value, 6, 26))); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_sign_extend_template2b_constexpr) { @@ -2183,7 +2183,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_trailing_zeros_8_constexpr) { @@ -2210,7 +2210,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_trailing_zeros_16_constexpr) { @@ -2241,7 +2241,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_trailing_zeros_32_constexpr) { @@ -2272,7 +2272,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_trailing_zeros_64_constexpr) { @@ -2299,7 +2299,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_trailing_ones_8_constexpr) { @@ -2326,7 +2326,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_trailing_ones_16_constexpr) { @@ -2357,7 +2357,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_trailing_ones_32_constexpr) { @@ -2387,7 +2387,7 @@ namespace } } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_trailing_ones_64_constexpr) { @@ -2414,7 +2414,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_leading_zeros_8_constexpr) { @@ -2441,7 +2441,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_leading_zeros_16_constexpr) { @@ -2472,7 +2472,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_leading_zeros_32_constexpr) { @@ -2503,7 +2503,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_leading_zeros_64_constexpr) { @@ -2530,7 +2530,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_leading_ones_8_constexpr) { @@ -2557,7 +2557,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_leading_ones_16_constexpr) { @@ -2588,7 +2588,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_leading_ones_32_constexpr) { @@ -2619,7 +2619,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_count_leading_ones_64_constexpr) { diff --git a/test/test_bit.cpp b/test/test_bit.cpp index 78ba4a6b..176345c8 100644 --- a/test/test_bit.cpp +++ b/test/test_bit.cpp @@ -283,7 +283,7 @@ namespace CHECK_EQUAL(0xDBU, int(value)); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_rotl_8_constexpr) { @@ -388,7 +388,7 @@ namespace CHECK_EQUAL(0x5B9EU, int(value)); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_rotl_16_constexpr) { @@ -457,7 +457,7 @@ namespace CHECK_EQUAL(0x6FU, int(value)); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_rotr_8_constexpr) { @@ -562,7 +562,7 @@ namespace CHECK_EQUAL(0x6E79U, int(value)); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_rotr_16_constexpr) { @@ -590,7 +590,7 @@ namespace CHECK_EQUAL(0xCB73U, int(value)); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_rotate16_constexpr) { @@ -611,7 +611,7 @@ namespace CHECK_EQUAL(0x5AU, value); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_byteswap_8_constexpr) { @@ -640,7 +640,7 @@ namespace CHECK_EQUAL(0x5AA5U, value); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_byteswap_16_constexpr) { @@ -669,7 +669,7 @@ namespace CHECK_EQUAL(0xA5A55A5AUL, value); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_byteswap_32_constexpr) { @@ -698,7 +698,7 @@ namespace CHECK_EQUAL(0xA5A55A5AA5A55A5AULL, value); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_byteswap_64_constexpr) { @@ -718,7 +718,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_popcount_8_constexpr) { @@ -738,7 +738,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_popcount_16_constexpr) { @@ -764,7 +764,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_popcount_32_constexpr) { @@ -790,7 +790,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_popcount_64_constexpr) { @@ -814,7 +814,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countr_zero_8_constexpr) { @@ -836,7 +836,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countr_zero_16_constexpr) { @@ -862,7 +862,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countr_zero_32_constexpr) { @@ -888,7 +888,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countr_zero_64_constexpr) { @@ -915,7 +915,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countr_one_8_constexpr) { @@ -941,7 +941,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countr_one_16_constexpr) { @@ -972,7 +972,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countr_one_32_constexpr) { @@ -1002,7 +1002,7 @@ namespace } } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countr_one_64_constexpr) { @@ -1029,7 +1029,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countl_zero_8_constexpr) { @@ -1056,7 +1056,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countl_zero_16_constexpr) { @@ -1087,7 +1087,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countl_zero_32_constexpr) { @@ -1118,7 +1118,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countl_zero_64_constexpr) { @@ -1145,7 +1145,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countl_one_8_constexpr) { @@ -1172,7 +1172,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countl_one_16_constexpr) { @@ -1203,7 +1203,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countl_one_32_constexpr) { @@ -1234,7 +1234,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_countl_one_64_constexpr) { @@ -1256,7 +1256,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_bit_ceil_8_constexpr) { @@ -1287,7 +1287,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_bit_ceil_16_constexpr) { @@ -1318,7 +1318,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_bit_ceil_32_constexpr) { @@ -1349,7 +1349,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_bit_ceil_64_constexpr) { @@ -1391,7 +1391,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_bit_floor_16_constexpr) { @@ -1422,7 +1422,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_bit_floor_32_constexpr) { @@ -1453,7 +1453,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_bit_floor_64_constexpr) { @@ -1475,7 +1475,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_bit_width_8_constexpr) { @@ -1501,7 +1501,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_bit_width_16_constexpr) { @@ -1527,7 +1527,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_bit_width_32_constexpr) { @@ -1553,7 +1553,7 @@ namespace } } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_bit_width_64_constexpr) { diff --git a/test/test_bit_stream.cpp b/test/test_bit_stream.cpp index c0cbd251..666e5911 100644 --- a/test/test_bit_stream.cpp +++ b/test/test_bit_stream.cpp @@ -930,8 +930,8 @@ namespace //************************************************************************* TEST(put_get_multiple_variable_size) { - char c1 = 26; // 6 bits - char c2 = -10; // 7 bits + int8_t c1 = 26; // 6 bits + int8_t c2 = -10; // 7 bits unsigned short s1 = 6742; // 13 bits unsigned short s2 = 1878; // 11 bits int32_t i1 = 2448037L; // 23 bits @@ -983,8 +983,8 @@ namespace bit_stream.restart(); - char rc1 = 0; - char rc2 = 0; + int8_t rc1 = 0; + int8_t rc2 = 0; unsigned short rs1 = 0; unsigned short rs2 = 0; int32_t ri1 = 0; @@ -1075,4 +1075,4 @@ namespace }; } -#include "etl/private/diagnostic_pop.h" \ No newline at end of file +#include "etl/private/diagnostic_pop.h" diff --git a/test/test_bit_stream_reader_big_endian.cpp b/test/test_bit_stream_reader_big_endian.cpp index 4cdf3d29..9c099085 100644 --- a/test/test_bit_stream_reader_big_endian.cpp +++ b/test/test_bit_stream_reader_big_endian.cpp @@ -210,7 +210,7 @@ namespace TEST(test_read_int8_t) { std::array storage = { char(0x01), char(0x5A), char(0xA5), char(0xFF) }; - std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); @@ -246,7 +246,7 @@ namespace TEST(test_read_checked_int8_t_using_non_member_function) { std::array storage = { char(0x01), char(0x5A), char(0xA5), char(0xFF) }; - std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); @@ -282,7 +282,7 @@ namespace TEST(test_read_unchecked_int8_t_using_non_member_function) { std::array storage = { char(0x01), char(0x5A), char(0xA5), char(0xFF) }; - std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); @@ -307,7 +307,7 @@ namespace TEST(test_read_int8_t_5bits) { std::array storage = { char(0x0E), char(0x8B), char(0xF0) }; - std::array expected = { int8_t(0x01), int8_t(0xFA), int8_t(0x05), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0xFA), int8_t(0x05), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); diff --git a/test/test_bit_stream_reader_little_endian.cpp b/test/test_bit_stream_reader_little_endian.cpp index 22c724ff..fcf91b22 100644 --- a/test/test_bit_stream_reader_little_endian.cpp +++ b/test/test_bit_stream_reader_little_endian.cpp @@ -215,7 +215,7 @@ namespace TEST(test_read_int8_t) { std::array storage = { char(0x80), char(0x5A), char(0xA5), char(0xFF) }; - std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little); diff --git a/test/test_bitset_legacy.cpp b/test/test_bitset_legacy.cpp index a64722ba..7723b172 100644 --- a/test/test_bitset_legacy.cpp +++ b/test/test_bitset_legacy.cpp @@ -1493,6 +1493,14 @@ namespace CHECK_EQUAL("...*..*...**.*...*.*.**..****...", stdtext.c_str()); } + //************************************************************************* + TEST(test_global_size) + { + etl::bitset<32> b(0x12345678UL); + + CHECK_EQUAL(32, ETL_OR_STD17::size(b)); + } + //************************************************************************* TEST(test_issue_497_count_inverted_bits) { diff --git a/test/test_bitset_new_default_element_type.cpp b/test/test_bitset_new_default_element_type.cpp index 4e8b5164..0722524e 100644 --- a/test/test_bitset_new_default_element_type.cpp +++ b/test/test_bitset_new_default_element_type.cpp @@ -2722,5 +2722,13 @@ namespace CHECK_EQUAL(test_bit(6), t6); CHECK_EQUAL(test_bit(7), t7); } + + //************************************************************************* + TEST(test_global_size) + { + etl::bitset<32> b(0x12345678UL); + + CHECK_EQUAL(32, ETL_OR_STD17::size(b)); + } }; } diff --git a/test/test_bitset_new_explicit_single_element_type.cpp b/test/test_bitset_new_explicit_single_element_type.cpp index 82badbb0..f06d4d42 100644 --- a/test/test_bitset_new_explicit_single_element_type.cpp +++ b/test/test_bitset_new_explicit_single_element_type.cpp @@ -2815,5 +2815,13 @@ namespace CHECK_EQUAL(test_bit(6), t6); CHECK_EQUAL(test_bit(7), t7); } + + //************************************************************************* + TEST(test_global_size) + { + etl::bitset<32, uint32_t> b(0x12345678UL); + + CHECK_EQUAL(32, ETL_OR_STD17::size(b)); + } }; } diff --git a/test/test_bitset_new_ext_default_element_type.cpp b/test/test_bitset_new_ext_default_element_type.cpp index 64100f3e..6e606c0f 100644 --- a/test/test_bitset_new_ext_default_element_type.cpp +++ b/test/test_bitset_new_ext_default_element_type.cpp @@ -2471,5 +2471,13 @@ namespace CHECK_EQUAL(test_bit(6), t6); CHECK_EQUAL(test_bit(7), t7); } + + //************************************************************************* + TEST(test_global_size) + { + etl::bitset<32> b(0x12345678UL); + + CHECK_EQUAL(32, ETL_OR_STD17::size(b)); + } }; } diff --git a/test/test_bitset_new_ext_explicit_single_element_type.cpp b/test/test_bitset_new_ext_explicit_single_element_type.cpp index 43343448..75c18a5f 100644 --- a/test/test_bitset_new_ext_explicit_single_element_type.cpp +++ b/test/test_bitset_new_ext_explicit_single_element_type.cpp @@ -2619,5 +2619,13 @@ namespace CHECK_EQUAL(test_bit(6), t6); CHECK_EQUAL(test_bit(7), t7); } + + //************************************************************************* + TEST(test_global_size) + { + etl::bitset<32, uint32_t> b(0x12345678UL); + + CHECK_EQUAL(32, ETL_OR_STD17::size(b)); + } }; } diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 96f5e231..e350e894 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -44,7 +44,7 @@ namespace etl namespace { - using Value = char; + using Value = int8_t; using Point = etl::coordinate_2d; diff --git a/test/test_byte_stream.cpp b/test/test_byte_stream.cpp index 13d4eaaa..4d63068d 100644 --- a/test/test_byte_stream.cpp +++ b/test/test_byte_stream.cpp @@ -1318,10 +1318,12 @@ namespace static std::vector result; - etl::byte_stream_writer::callback_type callback([&](etl::byte_stream_writer::callback_parameter_type sp) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(result)); - }); + auto lambda = [&](etl::byte_stream_writer::callback_parameter_type sp) + { + std::copy(sp.begin(), sp.end(), std::back_inserter(result)); + }; + + etl::byte_stream_writer::callback_type callback(lambda); etl::byte_stream_writer writer(storage.data(), storage.size(), etl::endian::big, callback); diff --git a/test/test_char_traits.cpp b/test/test_char_traits.cpp index bb6fb453..ecdf136e 100644 --- a/test/test_char_traits.cpp +++ b/test/test_char_traits.cpp @@ -61,7 +61,7 @@ namespace CHECK_EQUAL(6U, etl::strlen(U"qwerty")); } -#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) +#if ETL_USING_CPP14 //************************************************************************* TEST(test_strlen_constexpr) { diff --git a/test/test_chrono_day.cpp b/test/test_chrono_day.cpp index 7a9432a8..a801f607 100644 --- a/test/test_chrono_day.cpp +++ b/test/test_chrono_day.cpp @@ -37,10 +37,24 @@ SOFTWARE. #include #include +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 0 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + namespace { //************************************************************************* - bool is_day_ok(etl::chrono::day day) + bool expected_day_ok(Chrono::day day) { unsigned d = unsigned(day); @@ -59,7 +73,7 @@ namespace //************************************************************************* TEST(test_default_constructor) { - etl::chrono::day day; + Chrono::day day; CHECK_FALSE(day.ok()); } @@ -69,9 +83,9 @@ namespace { for (unsigned expected = 1U; expected < 31; ++expected) { - etl::chrono::day day(expected); + Chrono::day day(expected); - CHECK_TRUE(is_day_ok(day)); + CHECK_TRUE(expected_day_ok(day)); CHECK_EQUAL(expected, unsigned(day)); } } @@ -79,11 +93,11 @@ namespace //************************************************************************* TEST(test_pre_increment) { - etl::chrono::day day(0); + Chrono::day day(0); for (int expected = 0; expected < 256; ++expected, ++day) { - CHECK_TRUE(is_day_ok(day)); + CHECK_TRUE(expected_day_ok(day)); CHECK_EQUAL(expected, unsigned(day)); } } @@ -91,11 +105,11 @@ namespace //************************************************************************* TEST(test_post_increment) { - etl::chrono::day day(0); + Chrono::day day(0); for (int expected = 0; expected < 256; expected++, day++) { - CHECK_TRUE(is_day_ok(day)); + CHECK_TRUE(expected_day_ok(day)); CHECK_EQUAL(expected, unsigned(day)); } } @@ -103,11 +117,11 @@ namespace //************************************************************************* TEST(test_pre_decrement) { - etl::chrono::day day(255); + Chrono::day day(255); for (int expected = 255; expected > 0; --expected, --day) { - CHECK_TRUE(is_day_ok(day)); + CHECK_TRUE(expected_day_ok(day)); CHECK_EQUAL(expected, unsigned(day)); } } @@ -115,11 +129,11 @@ namespace //************************************************************************* TEST(test_post_decrement) { - etl::chrono::day day(255); + Chrono::day day(255); for (int expected = 255; expected > 0; expected--, day--) { - CHECK_TRUE(is_day_ok(day)); + CHECK_TRUE(expected_day_ok(day)); CHECK_EQUAL(expected, unsigned(day)); } } @@ -127,14 +141,14 @@ namespace //************************************************************************* TEST(test_plus_equal_days) { - etl::chrono::day day(0); - etl::chrono::days days(2); + Chrono::day day(0); + Chrono::days days(2); for (int expected = 2; expected < 256; expected += 2) { day += days; - CHECK_TRUE(is_day_ok(day)); + CHECK_TRUE(expected_day_ok(day)); CHECK_EQUAL(expected, unsigned(day)); } } @@ -146,14 +160,14 @@ namespace { for (int ds = 0; ds < 256; ++ds) { - etl::chrono::day day(d); - etl::chrono::days days(ds); + Chrono::day day(d); + Chrono::days days(ds); day = day + days; unsigned expected = (d + ds) % 256; - CHECK_TRUE(is_day_ok(day)); + CHECK_TRUE(expected_day_ok(day)); CHECK_EQUAL(expected, unsigned(day)); } } @@ -166,14 +180,14 @@ namespace { for (int ds = 0; ds < d; ++ds) { - etl::chrono::day day(d); - etl::chrono::days days(ds); + Chrono::day day(d); + Chrono::days days(ds); day = days + day; unsigned expected = (d + ds) % 256; - CHECK_TRUE(is_day_ok(day)); + CHECK_TRUE(expected_day_ok(day)); CHECK_EQUAL(expected, unsigned(day)); } } @@ -182,14 +196,14 @@ namespace //************************************************************************* TEST(test_minus_equal_days) { - etl::chrono::day day(255); - etl::chrono::days days(2); + Chrono::day day(255); + Chrono::days days(2); for (int expected = 253; expected > 0; expected -= 2) { day -= days; - CHECK_TRUE(is_day_ok(day)); + CHECK_TRUE(expected_day_ok(day)); CHECK_EQUAL(expected, unsigned(day)); } } @@ -197,14 +211,14 @@ namespace //************************************************************************* TEST(test_day_minus_days) { - etl::chrono::day day(255); - etl::chrono::days days(2); + Chrono::day day(255); + Chrono::days days(2); for (int expected = 253; expected > 0; expected -= 2) { day = day - days; - CHECK_TRUE(is_day_ok(day)); + CHECK_TRUE(expected_day_ok(day)); CHECK_EQUAL(expected, unsigned(day)); } } @@ -216,39 +230,43 @@ namespace { for (int d2 = 0; d2 < 256; ++d2) { - etl::chrono::day day1(d1); - etl::chrono::day day2(d2); + Chrono::day day1(d1); + Chrono::day day2(d2); - etl::chrono::days result_days = day1 - day2; + Chrono::days result_days = day1 - day2; int expected_days = d1 - d2; CHECK_EQUAL(expected_days, result_days.count()); } } } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_min_max_day) { - CHECK_EQUAL(1U, etl::chrono::day::min()); - CHECK_EQUAL(31U, etl::chrono::day::max()); + CHECK_EQUAL(1U, Chrono::day::min()); + CHECK_EQUAL(31U, Chrono::day::max()); } +#endif +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_literal_day) { using namespace etl::literals::chrono_literals; - etl::chrono::day day = 25_day; + Chrono::day day = 25_day; CHECK_TRUE(day.ok()); CHECK_EQUAL(25, unsigned(day)); } +#endif //************************************************************************* TEST(test_day_comparison_operators) { - etl::chrono::day day10(10); - etl::chrono::day day20(20); + Chrono::day day10(10); + Chrono::day day20(20); CHECK_TRUE(day10 == day10); CHECK_FALSE(day10 != day10); @@ -272,6 +290,7 @@ namespace #endif } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_day_hashes_are_unique) { @@ -279,12 +298,13 @@ namespace for (int i = 0; i < 256; ++i) { - hashes.push_back(etl::hash()(etl::chrono::day(i))); + hashes.push_back(etl::hash()(Chrono::day(i))); } std::sort(hashes.begin(), hashes.end()); (void)std::unique(hashes.begin(), hashes.end()); CHECK_EQUAL(256U, hashes.size()); } +#endif }; } diff --git a/test/test_chrono_month.cpp b/test/test_chrono_month.cpp index 2dcc7187..3c0ffac8 100644 --- a/test/test_chrono_month.cpp +++ b/test/test_chrono_month.cpp @@ -30,27 +30,65 @@ SOFTWARE. #include "etl/platform.h" -#if ETL_USING_CPP20 - #include "unit_test_framework.h" #include "etl/chrono.h" -#include -#include +#include #include +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + namespace { + //************************************************************************* + unsigned expected_month(int i) + { + i = i % 12; + + if (i < 0) + { + i = 12 + i; + } + + return i == 0 ? 12 : i; + } + + //************************************************************************* + bool expected_month_ok(Chrono::month month) + { + unsigned m = unsigned(month); + + if ((m < 1) || (m > 12)) + { + return (month.ok() == false); + } + else + { + return (month.ok() == true); + } + } + SUITE(test_chrono_month) { //************************************************************************* TEST(test_default_constructor) { - std::chrono::month std_month; - etl::chrono::month month; + Chrono::month month; - CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_TRUE(expected_month_ok(month)); } //************************************************************************* @@ -58,81 +96,66 @@ namespace { for (unsigned i = 0U; i < 256; ++i) { - std::chrono::month std_month(i); - etl::chrono::month month(i); + Chrono::month month(i); - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); + CHECK_TRUE(expected_month_ok(month)); + CHECK_EQUAL(i, unsigned(month)); } } //************************************************************************* TEST(test_pre_increment) { - std::chrono::month std_month(0); - etl::chrono::month month(0); + Chrono::month month(0); - for (int i = 0; i < 255; ++i) + for (int i = 1; i < 256; ++i) { - ++std_month; ++month; - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); + CHECK_TRUE(expected_month_ok(month)); + CHECK_EQUAL(expected_month(i), unsigned(month)); } } //************************************************************************* TEST(test_post_increment) { - std::chrono::month std_month(0); - etl::chrono::month month(0); + Chrono::month month(0); - for (int i = 0; i < 256; ++i) + for (int i = 1; i < 256; ++i) { - std::chrono::month std_last_month = std_month++; - etl::chrono::month last_month = month++; + month++; - CHECK_EQUAL(std_last_month.ok(), last_month.ok()); - CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); + CHECK_TRUE(expected_month_ok(month)); + CHECK_EQUAL(expected_month(i), unsigned(month)); } } //************************************************************************* TEST(test_pre_decrement) { - std::chrono::month std_month(255); - etl::chrono::month month(255); + Chrono::month month(255); - for (int i = 0; i < 256; ++i) + for (int i = 254; i > 1; --i) { - --std_month; --month; - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); + CHECK_TRUE(expected_month_ok(month)); + CHECK_EQUAL(expected_month(i), unsigned(month)); } } //************************************************************************* TEST(test_post_decrement) { - std::chrono::month std_month(255); - etl::chrono::month month(255); + Chrono::month month(255); - for (int i = 0; i < 256; ++i) + for (int i = 254; i > 1; --i) { - std::chrono::month std_last_month = std_month--; - etl::chrono::month last_month = month--; + month--; - CHECK_EQUAL(std_last_month.ok(), last_month.ok()); - CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); + CHECK_TRUE(expected_month_ok(month)); + CHECK_EQUAL(expected_month(i), unsigned(month)); } } @@ -143,17 +166,12 @@ namespace { for (int ms = 0; ms <= 24; ++ms) { - std::chrono::month std_month(m); - etl::chrono::month month(m); + Chrono::month month(m); + Chrono::months months(ms); + month += months; - std::chrono::months std_months(ms); - etl::chrono::months months(ms); - - std_month += std_months; - month += months; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); + CHECK_TRUE(expected_month_ok(month)); + CHECK_EQUAL(expected_month(m + ms), unsigned(month)); } } } @@ -165,17 +183,12 @@ namespace { for (int ms = 0; ms <= 24; ++ms) { - std::chrono::month std_month(m); - etl::chrono::month month(m); + Chrono::month month(m); + Chrono::months months(ms); + month = month + months; - std::chrono::months std_months(ms); - etl::chrono::months months(ms); - - std_month = std_month + std_months; - month = month + months; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); + CHECK_TRUE(expected_month_ok(month)); + CHECK_EQUAL(expected_month(m + ms), unsigned(month)); } } } @@ -187,17 +200,12 @@ namespace { for (int ms = 0; ms <= 24; ++ms) { - std::chrono::month std_month(m); - etl::chrono::month month(m); + Chrono::month month(m); + Chrono::months months(ms); + month = months + month; - std::chrono::months std_months(ms); - etl::chrono::months months(ms); - - std_month = std_months + std_month; - month = months + month; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); + CHECK_TRUE(expected_month_ok(month)); + CHECK_EQUAL(expected_month(m + ms), unsigned(month)); } } } @@ -209,17 +217,12 @@ namespace { for (int ms = 0; ms <= 24; ++ms) { - std::chrono::month std_month(m); - etl::chrono::month month(m); + Chrono::month month(m); + Chrono::months months(ms); + month -= months; - std::chrono::months std_months(ms); - etl::chrono::months months(ms); - - std_month -= std_months; - month -= months; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); + CHECK_TRUE(expected_month_ok(month)); + CHECK_EQUAL(expected_month(m - ms), unsigned(month)); } } } @@ -231,17 +234,12 @@ namespace { for (int ms = 0; ms <= 24; ++ms) { - std::chrono::month std_month(m); - etl::chrono::month month(m); + Chrono::month month(m); + Chrono::months months(ms); + month = month - months; - std::chrono::months std_months(ms); - etl::chrono::months months(ms); - - std_month = std_month - std_months; - month = month - months; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); + CHECK_TRUE(expected_month_ok(month)); + CHECK_EQUAL(expected_month(m - ms), unsigned(month)); } } } @@ -249,49 +247,58 @@ namespace //************************************************************************* TEST(test_month_minus_month) { - for (int m = 0; m < 256; ++m) + for (int m = 1; m < 13; ++m) { - std::chrono::month std_month1(m); - std::chrono::month std_month2(255 - m); + int m1 = m; + int m2 = 13 - m; - std::chrono::month month1(m); - std::chrono::month month2(255 - m); + Chrono::month month1(m1); + Chrono::month month2(m2); - auto std_months12 = std_month1 - std_month2; - auto std_months21 = std_month2 - std_month1; + Chrono::months months12 = month1 - month2; + Chrono::months months21 = month2 - month1; - auto months12 = month1 - month2; - auto months21 = month2 - month1; + int m12 = months12.count(); + int m21 = months21.count(); - CHECK_EQUAL(std_months12.count(), months12.count()); - CHECK_EQUAL(std_months21.count(), months21.count()); + int difference12 = expected_month(m1) - expected_month(m2); + int difference21 = expected_month(m2) - expected_month(m1); + + difference12 = (difference12 < 0) ? 12 + difference12: difference12; + difference21 = (difference21 < 0) ? 12 + difference21: difference21; + + CHECK_EQUAL(difference12, months12.count()); + CHECK_EQUAL(difference21, months21.count()); } } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_min_max_month) { - CHECK_EQUAL(1U, etl::chrono::month::min()); - CHECK_EQUAL(12U, etl::chrono::month::max()); + CHECK_EQUAL(1U, Chrono::month::min()); + CHECK_EQUAL(12U, Chrono::month::max()); } +#endif +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_literal_month) { using namespace etl::literals::chrono_literals; - etl::chrono::month month1 = 1_month; - etl::chrono::month month2 = 2_month; - etl::chrono::month month3 = 3_month; - etl::chrono::month month4 = 4_month; - etl::chrono::month month5 = 5_month; - etl::chrono::month month6 = 6_month; - etl::chrono::month month7 = 7_month; - etl::chrono::month month8 = 8_month; - etl::chrono::month month9 = 9_month; - etl::chrono::month month10 = 10_month; - etl::chrono::month month11 = 11_month; - etl::chrono::month month12 = 12_month; + Chrono::month month1 = 1_month; + Chrono::month month2 = 2_month; + Chrono::month month3 = 3_month; + Chrono::month month4 = 4_month; + Chrono::month month5 = 5_month; + Chrono::month month6 = 6_month; + Chrono::month month7 = 7_month; + Chrono::month month8 = 8_month; + Chrono::month month9 = 9_month; + Chrono::month month10 = 10_month; + Chrono::month month11 = 11_month; + Chrono::month month12 = 12_month; CHECK_TRUE(month1.ok()); CHECK_TRUE(month2.ok()); @@ -319,12 +326,13 @@ namespace CHECK_EQUAL(11U, unsigned(month11)); CHECK_EQUAL(12U, unsigned(month12)); } +#endif //************************************************************************* TEST(test_month_comparison_operators) { - etl::chrono::month month1(1); - etl::chrono::month month2(2); + Chrono::month month1(1); + Chrono::month month2(2); CHECK_TRUE(month1 == month1); CHECK_FALSE(month1 != month1); @@ -348,6 +356,7 @@ namespace #endif } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_month_hashes_are_unique) { @@ -355,31 +364,30 @@ namespace for (int i = 0; i < 256; ++i) { - hashes.push_back(etl::hash()(etl::chrono::month(i))); + hashes.push_back(etl::hash()(Chrono::month(i))); } std::sort(hashes.begin(), hashes.end()); (void)std::unique(hashes.begin(), hashes.end()); CHECK_EQUAL(256U, hashes.size()); } +#endif //************************************************************************* TEST(test_month_types) { - CHECK_EQUAL(static_cast(std::chrono::January), static_cast(etl::chrono::January)); - CHECK_EQUAL(static_cast(std::chrono::February), static_cast(etl::chrono::February)); - CHECK_EQUAL(static_cast(std::chrono::March), static_cast(etl::chrono::March)); - CHECK_EQUAL(static_cast(std::chrono::April), static_cast(etl::chrono::April)); - CHECK_EQUAL(static_cast(std::chrono::May), static_cast(etl::chrono::May)); - CHECK_EQUAL(static_cast(std::chrono::June), static_cast(etl::chrono::June)); - CHECK_EQUAL(static_cast(std::chrono::July), static_cast(etl::chrono::July)); - CHECK_EQUAL(static_cast(std::chrono::August), static_cast(etl::chrono::August)); - CHECK_EQUAL(static_cast(std::chrono::September), static_cast(etl::chrono::September)); - CHECK_EQUAL(static_cast(std::chrono::October), static_cast(etl::chrono::October)); - CHECK_EQUAL(static_cast(std::chrono::November), static_cast(etl::chrono::November)); - CHECK_EQUAL(static_cast(std::chrono::December), static_cast(etl::chrono::December)); + CHECK_EQUAL(1U, static_cast(Chrono::January)); + CHECK_EQUAL(2U, static_cast(Chrono::February)); + CHECK_EQUAL(3U, static_cast(Chrono::March)); + CHECK_EQUAL(4U, static_cast(Chrono::April)); + CHECK_EQUAL(5U, static_cast(Chrono::May)); + CHECK_EQUAL(6U, static_cast(Chrono::June)); + CHECK_EQUAL(7U, static_cast(Chrono::July)); + CHECK_EQUAL(8U, static_cast(Chrono::August)); + CHECK_EQUAL(9U, static_cast(Chrono::September)); + CHECK_EQUAL(10U, static_cast(Chrono::October)); + CHECK_EQUAL(11U, static_cast(Chrono::November)); + CHECK_EQUAL(12U, static_cast(Chrono::December)); } }; } - -#endif \ No newline at end of file diff --git a/test/test_chrono_month_day.cpp b/test/test_chrono_month_day.cpp index e1e0a5d8..9a7c66b2 100644 --- a/test/test_chrono_month_day.cpp +++ b/test/test_chrono_month_day.cpp @@ -34,12 +34,9 @@ SOFTWARE. #include "etl/chrono.h" -#include -#include +#include #include -#if ETL_USING_CPP20 - namespace { SUITE(test_chrono_month_day) @@ -52,333 +49,331 @@ namespace CHECK_FALSE(md.ok()); } - //************************************************************************* - TEST(test_constructor_in_range) - { - for (unsigned i = 0U; i < 256; ++i) - { - std::chrono::month std_month(i); - etl::chrono::month month(i); - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); - } - } - - //************************************************************************* - TEST(test_pre_increment) - { - std::chrono::month std_month(0); - etl::chrono::month month(0); - - for (int i = 0; i < 255; ++i) - { - ++std_month; - ++month; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); - } - } - - //************************************************************************* - TEST(test_post_increment) - { - std::chrono::month std_month(0); - etl::chrono::month month(0); - - for (int i = 0; i < 256; ++i) - { - std::chrono::month std_last_month = std_month++; - etl::chrono::month last_month = month++; - - CHECK_EQUAL(std_last_month.ok(), last_month.ok()); - CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); - } - } - - //************************************************************************* - TEST(test_pre_decrement) - { - std::chrono::month std_month(255); - etl::chrono::month month(255); - - for (int i = 0; i < 256; ++i) - { - --std_month; - --month; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); - } - } - - //************************************************************************* - TEST(test_post_decrement) - { - std::chrono::month std_month(255); - etl::chrono::month month(255); - - for (int i = 0; i < 256; ++i) - { - std::chrono::month std_last_month = std_month--; - etl::chrono::month last_month = month--; - - CHECK_EQUAL(std_last_month.ok(), last_month.ok()); - CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); - } - } - - //************************************************************************* - TEST(test_plus_equal_months) - { - for (int m = 0; m <= 12; ++m) - { - for (int ms = 0; ms <= 24; ++ms) - { - std::chrono::month std_month(m); - etl::chrono::month month(m); - - std::chrono::months std_months(ms); - etl::chrono::months months(ms); - - std_month += std_months; - month += months; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); - } - } - } - - //************************************************************************* - TEST(test_month_plus_months) - { - for (int m = 0; m <= 12; ++m) - { - for (int ms = 0; ms <= 24; ++ms) - { - std::chrono::month std_month(m); - etl::chrono::month month(m); - - std::chrono::months std_months(ms); - etl::chrono::months months(ms); - - std_month = std_month + std_months; - month = month + months; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); - } - } - } - - //************************************************************************* - TEST(test_months_plus_month) - { - for (int m = 0; m <= 12; ++m) - { - for (int ms = 0; ms <= 24; ++ms) - { - std::chrono::month std_month(m); - etl::chrono::month month(m); - - std::chrono::months std_months(ms); - etl::chrono::months months(ms); - - std_month = std_months + std_month; - month = months + month; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); - } - } - } - - //************************************************************************* - TEST(test_minus_equal_months) - { - for (int m = 0; m <= 12; ++m) - { - for (int ms = 0; ms <= 24; ++ms) - { - std::chrono::month std_month(m); - etl::chrono::month month(m); - - std::chrono::months std_months(ms); - etl::chrono::months months(ms); - - std_month -= std_months; - month -= months; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); - } - } - } - - //************************************************************************* - TEST(test_month_minus_months) - { - for (int m = 0; m <= 12; ++m) - { - for (int ms = 0; ms <= 24; ++ms) - { - std::chrono::month std_month(m); - etl::chrono::month month(m); - - std::chrono::months std_months(ms); - etl::chrono::months months(ms); - - std_month = std_month - std_months; - month = month - months; - - CHECK_EQUAL(std_month.ok(), month.ok()); - CHECK_EQUAL(unsigned(std_month), unsigned(month)); - } - } - } - - //************************************************************************* - TEST(test_month_minus_month) - { - for (int m = 0; m < 256; ++m) - { - std::chrono::month std_month1(m); - std::chrono::month std_month2(255 - m); - - std::chrono::month month1(m); - std::chrono::month month2(255 - m); - - auto std_months12 = std_month1 - std_month2; - auto std_months21 = std_month2 - std_month1; - - auto months12 = month1 - month2; - auto months21 = month2 - month1; - - CHECK_EQUAL(std_months12.count(), months12.count()); - CHECK_EQUAL(std_months21.count(), months21.count()); - } - } - - //************************************************************************* - TEST(test_min_max_month) - { - CHECK_EQUAL(1U, etl::chrono::month::min()); - CHECK_EQUAL(12U, etl::chrono::month::max()); - } - - //************************************************************************* - TEST(test_literal_month) - { - using namespace etl::literals::chrono_literals; - - etl::chrono::month month1 = 1_month; - etl::chrono::month month2 = 2_month; - etl::chrono::month month3 = 3_month; - etl::chrono::month month4 = 4_month; - etl::chrono::month month5 = 5_month; - etl::chrono::month month6 = 6_month; - etl::chrono::month month7 = 7_month; - etl::chrono::month month8 = 8_month; - etl::chrono::month month9 = 9_month; - etl::chrono::month month10 = 10_month; - etl::chrono::month month11 = 11_month; - etl::chrono::month month12 = 12_month; - - CHECK_TRUE(month1.ok()); - CHECK_TRUE(month2.ok()); - CHECK_TRUE(month3.ok()); - CHECK_TRUE(month4.ok()); - CHECK_TRUE(month5.ok()); - CHECK_TRUE(month6.ok()); - CHECK_TRUE(month7.ok()); - CHECK_TRUE(month8.ok()); - CHECK_TRUE(month9.ok()); - CHECK_TRUE(month10.ok()); - CHECK_TRUE(month11.ok()); - CHECK_TRUE(month12.ok()); - - CHECK_EQUAL(1U, unsigned(month1)); - CHECK_EQUAL(2U, unsigned(month2)); - CHECK_EQUAL(3U, unsigned(month3)); - CHECK_EQUAL(4U, unsigned(month4)); - CHECK_EQUAL(5U, unsigned(month5)); - CHECK_EQUAL(6U, unsigned(month6)); - CHECK_EQUAL(7U, unsigned(month7)); - CHECK_EQUAL(8U, unsigned(month8)); - CHECK_EQUAL(9U, unsigned(month9)); - CHECK_EQUAL(10U, unsigned(month10)); - CHECK_EQUAL(11U, unsigned(month11)); - CHECK_EQUAL(12U, unsigned(month12)); - } - - //************************************************************************* - TEST(test_month_comparison_operators) - { - etl::chrono::month month1(1); - etl::chrono::month month2(2); - - CHECK_TRUE(month1 == month1); - CHECK_FALSE(month1 != month1); - CHECK_TRUE(month1 < month2); - CHECK_FALSE(month1 < month1); - CHECK_FALSE(month2 < month1); - CHECK_TRUE(month1 <= month2); - CHECK_TRUE(month1 <= month1); - CHECK_FALSE(month2 <= month1); - CHECK_FALSE(month1 > month2); - CHECK_FALSE(month1 > month1); - CHECK_TRUE(month2 > month1); - CHECK_FALSE(month1 >= month2); - CHECK_TRUE(month1 >= month1); - CHECK_TRUE(month2 >= month1); - -#if ETL_USING_CPP20 - CHECK_TRUE((month1 <=> month1) == 0); - CHECK_TRUE((month1 <=> month2) < 0); - CHECK_TRUE((month2 <=> month1) > 0); -#endif - } - - //************************************************************************* - TEST(test_month_hashes_are_unique) - { - std::vector hashes; - - for (int i = 0; i < 256; ++i) - { - hashes.push_back(etl::hash()(etl::chrono::month(i))); - } - - std::sort(hashes.begin(), hashes.end()); - (void)std::unique(hashes.begin(), hashes.end()); - CHECK_EQUAL(256U, hashes.size()); - } - - //************************************************************************* - TEST(test_month_types) - { - CHECK_EQUAL(static_cast(std::chrono::January), static_cast(etl::chrono::January)); - CHECK_EQUAL(static_cast(std::chrono::February), static_cast(etl::chrono::February)); - CHECK_EQUAL(static_cast(std::chrono::March), static_cast(etl::chrono::March)); - CHECK_EQUAL(static_cast(std::chrono::April), static_cast(etl::chrono::April)); - CHECK_EQUAL(static_cast(std::chrono::May), static_cast(etl::chrono::May)); - CHECK_EQUAL(static_cast(std::chrono::June), static_cast(etl::chrono::June)); - CHECK_EQUAL(static_cast(std::chrono::July), static_cast(etl::chrono::July)); - CHECK_EQUAL(static_cast(std::chrono::August), static_cast(etl::chrono::August)); - CHECK_EQUAL(static_cast(std::chrono::September), static_cast(etl::chrono::September)); - CHECK_EQUAL(static_cast(std::chrono::October), static_cast(etl::chrono::October)); - CHECK_EQUAL(static_cast(std::chrono::November), static_cast(etl::chrono::November)); - CHECK_EQUAL(static_cast(std::chrono::December), static_cast(etl::chrono::December)); - } +// //************************************************************************* +// TEST(test_constructor_in_range) +// { +// for (unsigned i = 0U; i < 256; ++i) +// { +// std::chrono::month std_month(i); +// etl::chrono::month month(i); +// +// CHECK_EQUAL(std_month.ok(), month.ok()); +// CHECK_EQUAL(unsigned(std_month), unsigned(month)); +// } +// } +// +// //************************************************************************* +// TEST(test_pre_increment) +// { +// std::chrono::month std_month(0); +// etl::chrono::month month(0); +// +// for (int i = 0; i < 255; ++i) +// { +// ++std_month; +// ++month; +// +// CHECK_EQUAL(std_month.ok(), month.ok()); +// CHECK_EQUAL(unsigned(std_month), unsigned(month)); +// } +// } +// +// //************************************************************************* +// TEST(test_post_increment) +// { +// std::chrono::month std_month(0); +// etl::chrono::month month(0); +// +// for (int i = 0; i < 256; ++i) +// { +// std::chrono::month std_last_month = std_month++; +// etl::chrono::month last_month = month++; +// +// CHECK_EQUAL(std_last_month.ok(), last_month.ok()); +// CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); +// +// CHECK_EQUAL(std_month.ok(), month.ok()); +// CHECK_EQUAL(unsigned(std_month), unsigned(month)); +// } +// } +// +// //************************************************************************* +// TEST(test_pre_decrement) +// { +// std::chrono::month std_month(255); +// etl::chrono::month month(255); +// +// for (int i = 0; i < 256; ++i) +// { +// --std_month; +// --month; +// +// CHECK_EQUAL(std_month.ok(), month.ok()); +// CHECK_EQUAL(unsigned(std_month), unsigned(month)); +// } +// } +// +// //************************************************************************* +// TEST(test_post_decrement) +// { +// std::chrono::month std_month(255); +// etl::chrono::month month(255); +// +// for (int i = 0; i < 256; ++i) +// { +// std::chrono::month std_last_month = std_month--; +// etl::chrono::month last_month = month--; +// +// CHECK_EQUAL(std_last_month.ok(), last_month.ok()); +// CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); +// +// CHECK_EQUAL(std_month.ok(), month.ok()); +// CHECK_EQUAL(unsigned(std_month), unsigned(month)); +// } +// } +// +// //************************************************************************* +// TEST(test_plus_equal_months) +// { +// for (int m = 0; m <= 12; ++m) +// { +// for (int ms = 0; ms <= 24; ++ms) +// { +// std::chrono::month std_month(m); +// etl::chrono::month month(m); +// +// std::chrono::months std_months(ms); +// etl::chrono::months months(ms); +// +// std_month += std_months; +// month += months; +// +// CHECK_EQUAL(std_month.ok(), month.ok()); +// CHECK_EQUAL(unsigned(std_month), unsigned(month)); +// } +// } +// } +// +// //************************************************************************* +// TEST(test_month_plus_months) +// { +// for (int m = 0; m <= 12; ++m) +// { +// for (int ms = 0; ms <= 24; ++ms) +// { +// std::chrono::month std_month(m); +// etl::chrono::month month(m); +// +// std::chrono::months std_months(ms); +// etl::chrono::months months(ms); +// +// std_month = std_month + std_months; +// month = month + months; +// +// CHECK_EQUAL(std_month.ok(), month.ok()); +// CHECK_EQUAL(unsigned(std_month), unsigned(month)); +// } +// } +// } +// +// //************************************************************************* +// TEST(test_months_plus_month) +// { +// for (int m = 0; m <= 12; ++m) +// { +// for (int ms = 0; ms <= 24; ++ms) +// { +// std::chrono::month std_month(m); +// etl::chrono::month month(m); +// +// std::chrono::months std_months(ms); +// etl::chrono::months months(ms); +// +// std_month = std_months + std_month; +// month = months + month; +// +// CHECK_EQUAL(std_month.ok(), month.ok()); +// CHECK_EQUAL(unsigned(std_month), unsigned(month)); +// } +// } +// } +// +// //************************************************************************* +// TEST(test_minus_equal_months) +// { +// for (int m = 0; m <= 12; ++m) +// { +// for (int ms = 0; ms <= 24; ++ms) +// { +// std::chrono::month std_month(m); +// etl::chrono::month month(m); +// +// std::chrono::months std_months(ms); +// etl::chrono::months months(ms); +// +// std_month -= std_months; +// month -= months; +// +// CHECK_EQUAL(std_month.ok(), month.ok()); +// CHECK_EQUAL(unsigned(std_month), unsigned(month)); +// } +// } +// } +// +// //************************************************************************* +// TEST(test_month_minus_months) +// { +// for (int m = 0; m <= 12; ++m) +// { +// for (int ms = 0; ms <= 24; ++ms) +// { +// std::chrono::month std_month(m); +// etl::chrono::month month(m); +// +// std::chrono::months std_months(ms); +// etl::chrono::months months(ms); +// +// std_month = std_month - std_months; +// month = month - months; +// +// CHECK_EQUAL(std_month.ok(), month.ok()); +// CHECK_EQUAL(unsigned(std_month), unsigned(month)); +// } +// } +// } +// +// //************************************************************************* +// TEST(test_month_minus_month) +// { +// for (int m = 0; m < 256; ++m) +// { +// std::chrono::month std_month1(m); +// std::chrono::month std_month2(255 - m); +// +// std::chrono::month month1(m); +// std::chrono::month month2(255 - m); +// +// auto std_months12 = std_month1 - std_month2; +// auto std_months21 = std_month2 - std_month1; +// +// auto months12 = month1 - month2; +// auto months21 = month2 - month1; +// +// CHECK_EQUAL(std_months12.count(), months12.count()); +// CHECK_EQUAL(std_months21.count(), months21.count()); +// } +// } +// +// //************************************************************************* +// TEST(test_min_max_month) +// { +// CHECK_EQUAL(1U, etl::chrono::month::min()); +// CHECK_EQUAL(12U, etl::chrono::month::max()); +// } +// +// //************************************************************************* +// TEST(test_literal_month) +// { +// using namespace etl::literals::chrono_literals; +// +// etl::chrono::month month1 = 1_month; +// etl::chrono::month month2 = 2_month; +// etl::chrono::month month3 = 3_month; +// etl::chrono::month month4 = 4_month; +// etl::chrono::month month5 = 5_month; +// etl::chrono::month month6 = 6_month; +// etl::chrono::month month7 = 7_month; +// etl::chrono::month month8 = 8_month; +// etl::chrono::month month9 = 9_month; +// etl::chrono::month month10 = 10_month; +// etl::chrono::month month11 = 11_month; +// etl::chrono::month month12 = 12_month; +// +// CHECK_TRUE(month1.ok()); +// CHECK_TRUE(month2.ok()); +// CHECK_TRUE(month3.ok()); +// CHECK_TRUE(month4.ok()); +// CHECK_TRUE(month5.ok()); +// CHECK_TRUE(month6.ok()); +// CHECK_TRUE(month7.ok()); +// CHECK_TRUE(month8.ok()); +// CHECK_TRUE(month9.ok()); +// CHECK_TRUE(month10.ok()); +// CHECK_TRUE(month11.ok()); +// CHECK_TRUE(month12.ok()); +// +// CHECK_EQUAL(1U, unsigned(month1)); +// CHECK_EQUAL(2U, unsigned(month2)); +// CHECK_EQUAL(3U, unsigned(month3)); +// CHECK_EQUAL(4U, unsigned(month4)); +// CHECK_EQUAL(5U, unsigned(month5)); +// CHECK_EQUAL(6U, unsigned(month6)); +// CHECK_EQUAL(7U, unsigned(month7)); +// CHECK_EQUAL(8U, unsigned(month8)); +// CHECK_EQUAL(9U, unsigned(month9)); +// CHECK_EQUAL(10U, unsigned(month10)); +// CHECK_EQUAL(11U, unsigned(month11)); +// CHECK_EQUAL(12U, unsigned(month12)); +// } +// +// //************************************************************************* +// TEST(test_month_comparison_operators) +// { +// etl::chrono::month month1(1); +// etl::chrono::month month2(2); +// +// CHECK_TRUE(month1 == month1); +// CHECK_FALSE(month1 != month1); +// CHECK_TRUE(month1 < month2); +// CHECK_FALSE(month1 < month1); +// CHECK_FALSE(month2 < month1); +// CHECK_TRUE(month1 <= month2); +// CHECK_TRUE(month1 <= month1); +// CHECK_FALSE(month2 <= month1); +// CHECK_FALSE(month1 > month2); +// CHECK_FALSE(month1 > month1); +// CHECK_TRUE(month2 > month1); +// CHECK_FALSE(month1 >= month2); +// CHECK_TRUE(month1 >= month1); +// CHECK_TRUE(month2 >= month1); +// +//#if ETL_USING_CPP20 +// CHECK_TRUE((month1 <=> month1) == 0); +// CHECK_TRUE((month1 <=> month2) < 0); +// CHECK_TRUE((month2 <=> month1) > 0); +//#endif +// } +// +// //************************************************************************* +// TEST(test_month_hashes_are_unique) +// { +// std::vector hashes; +// +// for (int i = 0; i < 256; ++i) +// { +// hashes.push_back(etl::hash()(etl::chrono::month(i))); +// } +// +// std::sort(hashes.begin(), hashes.end()); +// (void)std::unique(hashes.begin(), hashes.end()); +// CHECK_EQUAL(256U, hashes.size()); +// } +// +// //************************************************************************* +// TEST(test_month_types) +// { +// CHECK_EQUAL(static_cast(std::chrono::January), static_cast(etl::chrono::January)); +// CHECK_EQUAL(static_cast(std::chrono::February), static_cast(etl::chrono::February)); +// CHECK_EQUAL(static_cast(std::chrono::March), static_cast(etl::chrono::March)); +// CHECK_EQUAL(static_cast(std::chrono::April), static_cast(etl::chrono::April)); +// CHECK_EQUAL(static_cast(std::chrono::May), static_cast(etl::chrono::May)); +// CHECK_EQUAL(static_cast(std::chrono::June), static_cast(etl::chrono::June)); +// CHECK_EQUAL(static_cast(std::chrono::July), static_cast(etl::chrono::July)); +// CHECK_EQUAL(static_cast(std::chrono::August), static_cast(etl::chrono::August)); +// CHECK_EQUAL(static_cast(std::chrono::September), static_cast(etl::chrono::September)); +// CHECK_EQUAL(static_cast(std::chrono::October), static_cast(etl::chrono::October)); +// CHECK_EQUAL(static_cast(std::chrono::November), static_cast(etl::chrono::November)); +// CHECK_EQUAL(static_cast(std::chrono::December), static_cast(etl::chrono::December)); +// } }; } - -#endif \ No newline at end of file diff --git a/test/test_chrono_weekday.cpp b/test/test_chrono_weekday.cpp index 132160ec..ca65b1ce 100644 --- a/test/test_chrono_weekday.cpp +++ b/test/test_chrono_weekday.cpp @@ -263,7 +263,6 @@ namespace } } -#if ETL_USING_CPP20 //************************************************************************* TEST(test_weekday_minus_weekday) { @@ -285,7 +284,6 @@ namespace CHECK_EQUAL(std_days21.count(), days21.count()); } } -#endif //************************************************************************* TEST(test_min_max_weekday) diff --git a/test/test_chrono_year.cpp b/test/test_chrono_year.cpp index dacb9c06..a3b59450 100644 --- a/test/test_chrono_year.cpp +++ b/test/test_chrono_year.cpp @@ -30,8 +30,6 @@ SOFTWARE. #include "etl/platform.h" -#if ETL_USING_CPP20 - #include "unit_test_framework.h" #include "etl/chrono.h" @@ -313,5 +311,3 @@ namespace } }; } - -#endif \ No newline at end of file diff --git a/test/test_correlation.cpp b/test/test_correlation.cpp index 82f2d032..2bd689f1 100644 --- a/test/test_correlation.cpp +++ b/test/test_correlation.cpp @@ -34,17 +34,17 @@ SOFTWARE. namespace { - std::array input_c + std::array input_c { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - std::array input_c_flat + std::array input_c_flat { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - std::array input_c_inv + std::array input_c_inv { 0, -1, -2, -3, -4, -5, -6, -7, -8, -9 }; @@ -86,7 +86,7 @@ namespace //************************************************************************* TEST(test_char_correlation_default_constructor) { - etl::correlation correlation; + etl::correlation correlation; double correlation_result = correlation; @@ -120,21 +120,21 @@ namespace double covariance_result; // Negative correlation. - etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); correlation_result = correlation1; CHECK_CLOSE(-1.0, correlation_result, 0.1); covariance_result = correlation1.get_covariance(); CHECK_CLOSE(-8.25, covariance_result, 0.1); // Zero correlation - etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); correlation_result = correlation2; CHECK_CLOSE(0.0, correlation_result, 0.1); covariance_result = correlation2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive correlation. - etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); + etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); correlation_result = correlation3; CHECK_CLOSE(1.0, correlation_result, 0.1); covariance_result = correlation3.get_covariance(); @@ -148,21 +148,21 @@ namespace double covariance_result; // Negative correlation. - etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); correlation_result = correlation1; CHECK_CLOSE(-1.0, correlation_result, 0.1); covariance_result = correlation1.get_covariance(); CHECK_CLOSE(-9.17, covariance_result, 0.1); // Zero correlation - etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); correlation_result = correlation2; CHECK_CLOSE(0.0, correlation_result, 0.1); covariance_result = correlation2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive correlation. - etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); + etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); correlation_result = correlation3; CHECK_CLOSE(1.0, correlation_result, 0.1); covariance_result = correlation3.get_covariance(); diff --git a/test/test_covariance.cpp b/test/test_covariance.cpp index a127616c..705f1e12 100644 --- a/test/test_covariance.cpp +++ b/test/test_covariance.cpp @@ -34,17 +34,17 @@ SOFTWARE. namespace { - std::array input_c + std::array input_c { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - std::array input_c_flat + std::array input_c_flat { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - std::array input_c_inv + std::array input_c_inv { 0, -1, -2, -3, -4, -5, -6, -7, -8, -9 }; @@ -86,7 +86,7 @@ namespace //************************************************************************* TEST(test_char_covariance_default_constructor) { - etl::covariance covariance; + etl::covariance covariance; double covariance_result = covariance; @@ -119,17 +119,17 @@ namespace double covariance_result; // Negative covariance. - etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); covariance_result = covariance1.get_covariance(); CHECK_CLOSE(-8.25, covariance_result, 0.1); // Zero covariance - etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); covariance_result = covariance2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive covariance. - etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); + etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); covariance_result = covariance3.get_covariance(); CHECK_CLOSE(8.25, covariance_result, 0.1); } @@ -140,17 +140,17 @@ namespace double covariance_result; // Negative covariance. - etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); covariance_result = covariance1.get_covariance(); CHECK_CLOSE(-9.17, covariance_result, 0.1); // Zero covariance - etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); covariance_result = covariance2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive covariance. - etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); + etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); covariance_result = covariance3.get_covariance(); CHECK_CLOSE(9.17, covariance_result, 0.1); } diff --git a/test/test_crc1.cpp b/test/test_crc1.cpp index fe62b17e..4bbabefa 100644 --- a/test/test_crc1.cpp +++ b/test/test_crc1.cpp @@ -66,6 +66,17 @@ namespace CHECK_EQUAL(calculate_parity(data.begin(), data.end()), int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc1_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc1(data, data + 9); + + CHECK_EQUAL(calculate_parity(data, data + 9), int(crc)); + } +#endif + //************************************************************************* TEST(test_crc1_add_values) { diff --git a/test/test_crc16.cpp b/test/test_crc16.cpp index b1f2328d..33057dae 100644 --- a/test/test_crc16.cpp +++ b/test/test_crc16.cpp @@ -127,6 +127,17 @@ namespace CHECK_EQUAL(0xBB3DU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_t16(data, data + 9); + + CHECK_EQUAL(0xBB3DU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_16_add_values) { @@ -199,6 +210,17 @@ namespace CHECK_EQUAL(0xBB3DU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_t4(data, data + 9); + + CHECK_EQUAL(0xBB3DU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_4_add_values) { diff --git a/test/test_crc16_a.cpp b/test/test_crc16_a.cpp index fe922a2e..778c2f9f 100644 --- a/test/test_crc16_a.cpp +++ b/test/test_crc16_a.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xBF05U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_a_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_a(data, data + 9); + + CHECK_EQUAL(0xBF05U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_a_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xBF05U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_a_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_a_t16(data, data + 9); + + CHECK_EQUAL(0xBF05U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_a_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xBF05U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_a_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_a_t4(data, data + 9); + + CHECK_EQUAL(0xBF05U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_a_4_add_values) { diff --git a/test/test_crc16_arc.cpp b/test/test_crc16_arc.cpp index 3e7768f7..73195d74 100644 --- a/test/test_crc16_arc.cpp +++ b/test/test_crc16_arc.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xBB3DU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_arc_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_arc(data, data + 9); + + CHECK_EQUAL(0xBB3DU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_arc_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xBB3DU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_arc_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_arc_t16(data, data + 9); + + CHECK_EQUAL(0xBB3DU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_arc_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xBB3DU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_arc_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_arc_t4(data, data + 9); + + CHECK_EQUAL(0xBB3DU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_arc_4_add_values) { diff --git a/test/test_crc16_aug_ccitt.cpp b/test/test_crc16_aug_ccitt.cpp index 8f5a1612..1e16bfff 100644 --- a/test/test_crc16_aug_ccitt.cpp +++ b/test/test_crc16_aug_ccitt.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xE5CCU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_aug_ccitt_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_aug_ccitt(data, data + 9); + + CHECK_EQUAL(0xE5CCU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_aug_ccitt_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xE5CCU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_aug_ccitt_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_aug_ccitt_t16(data, data + 9); + + CHECK_EQUAL(0xE5CCU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_aug_ccitt_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xE5CCU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_aug_ccitt_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_aug_ccitt_t4(data, data + 9); + + CHECK_EQUAL(0xE5CCU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_aug_ccitt_4_add_values) { diff --git a/test/test_crc16_buypass.cpp b/test/test_crc16_buypass.cpp index 9aa81364..acd2f76a 100644 --- a/test/test_crc16_buypass.cpp +++ b/test/test_crc16_buypass.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xFEE8U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_buypass_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_buypass(data, data + 9); + + CHECK_EQUAL(0xFEE8U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_buypass_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xFEE8U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_buypass_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_buypass_t16(data, data + 9); + + CHECK_EQUAL(0xFEE8U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_buypass_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xFEE8U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_buypass_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_buypass_t4(data, data + 9); + + CHECK_EQUAL(0xFEE8U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_buypass_4_add_values) { diff --git a/test/test_crc16_ccitt.cpp b/test/test_crc16_ccitt.cpp index e81dce28..90202fa2 100644 --- a/test/test_crc16_ccitt.cpp +++ b/test/test_crc16_ccitt.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x29B1U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_ccitt_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_ccitt(data, data + 9); + + CHECK_EQUAL(0x29B1U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_ccitt_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x29B1U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_ccitt_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_ccitt_t16(data, data + 9); + + CHECK_EQUAL(0x29B1U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_ccitt_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x29B1U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_ccitt_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_ccitt_t4(data, data + 9); + + CHECK_EQUAL(0x29B1U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_ccitt_4_add_values) { diff --git a/test/test_crc16_cdma2000.cpp b/test/test_crc16_cdma2000.cpp index 885a237a..60166f9f 100644 --- a/test/test_crc16_cdma2000.cpp +++ b/test/test_crc16_cdma2000.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x4C06U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_cdma2000_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_cdma2000(data, data + 9); + + CHECK_EQUAL(0x4C06U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_cdma2000_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x4C06U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_cdma2000_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_cdma2000_t16(data, data + 9); + + CHECK_EQUAL(0x4C06U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_cdma2000_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x4C06U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_cdma2000_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_cdma2000_t4(data, data + 9); + + CHECK_EQUAL(0x4C06U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_cdma2000_4_add_values) { diff --git a/test/test_crc16_dds110.cpp b/test/test_crc16_dds110.cpp index 8bed8046..7c7145c4 100644 --- a/test/test_crc16_dds110.cpp +++ b/test/test_crc16_dds110.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x9ECFU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dds110_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dds110(data, data + 9); + + CHECK_EQUAL(0x9ECFU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dds110_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x9ECFU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dds110_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dds110_t16(data, data + 9); + + CHECK_EQUAL(0x9ECFU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dds110_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x9ECFU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dds110_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dds110_t4(data, data + 9); + + CHECK_EQUAL(0x9ECFU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dds110_4_add_values) { diff --git a/test/test_crc16_dectr.cpp b/test/test_crc16_dectr.cpp index d99d9d61..0374c3bc 100644 --- a/test/test_crc16_dectr.cpp +++ b/test/test_crc16_dectr.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x007EU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dect_r_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dectr(data, data + 9); + + CHECK_EQUAL(0x007EU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dect_r_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x007EU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dect_r_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dect_r_t16(data, data + 9); + + CHECK_EQUAL(0x007EU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dect_r_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x007EU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dect_r_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dect_r_t4(data, data + 9); + + CHECK_EQUAL(0x007EU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dect_r_4_add_values) { diff --git a/test/test_crc16_dectx.cpp b/test/test_crc16_dectx.cpp index bf7db423..7dadc3a5 100644 --- a/test/test_crc16_dectx.cpp +++ b/test/test_crc16_dectx.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x007FU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dect_x_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dectx(data, data + 9); + + CHECK_EQUAL(0x007FU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dect_x_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x007FU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dect_x_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dect_x_t16(data, data + 9); + + CHECK_EQUAL(0x007FU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dect_x_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x007FU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dect_x_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dect_x_t4(data, data + 9); + + CHECK_EQUAL(0x007FU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dect_x_4_add_values) { diff --git a/test/test_crc16_dnp.cpp b/test/test_crc16_dnp.cpp index 82069d6a..1de99a59 100644 --- a/test/test_crc16_dnp.cpp +++ b/test/test_crc16_dnp.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xEA82U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dnp_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dnp(data, data + 9); + + CHECK_EQUAL(0xEA82U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dnp_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xEA82U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dnp_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dnp_t16(data, data + 9); + + CHECK_EQUAL(0xEA82U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dnp_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xEA82U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_dnp_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_dnp_t4(data, data + 9); + + CHECK_EQUAL(0xEA82U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_dnp_4_add_values) { diff --git a/test/test_crc16_en13757.cpp b/test/test_crc16_en13757.cpp index f63df0d1..b05de99c 100644 --- a/test/test_crc16_en13757.cpp +++ b/test/test_crc16_en13757.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xC2B7U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_en13757_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_en13757(data, data + 9); + + CHECK_EQUAL(0xC2B7U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_en13757_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xC2B7U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_en13757_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_en13757_t16(data, data + 9); + + CHECK_EQUAL(0xC2B7U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_en13757_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xC2B7U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_en13757_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_en13757_t4(data, data + 9); + + CHECK_EQUAL(0xC2B7U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_en13757_4_add_values) { diff --git a/test/test_crc16_genibus.cpp b/test/test_crc16_genibus.cpp index 3ab8f68b..9e7e15f4 100644 --- a/test/test_crc16_genibus.cpp +++ b/test/test_crc16_genibus.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xD64EU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_genibus_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_genibus(data, data + 9); + + CHECK_EQUAL(0xD64EU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_genibus_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xD64EU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_genibus_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_genibus_t16(data, data + 9); + + CHECK_EQUAL(0xD64EU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_genibus_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xD64EU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_genibus_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_genibus_t4(data, data + 9); + + CHECK_EQUAL(0xD64EU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_genibus_4_add_values) { diff --git a/test/test_crc16_kermit.cpp b/test/test_crc16_kermit.cpp index 62769114..93b044d0 100644 --- a/test/test_crc16_kermit.cpp +++ b/test/test_crc16_kermit.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x2189U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_kermit_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_kermit(data, data + 9); + + CHECK_EQUAL(0x2189U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_kermit_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x2189U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_kermit_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_kermit_t16(data, data + 9); + + CHECK_EQUAL(0x2189U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_kermit_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x2189U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_kermit_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_kermit_t4(data, data + 9); + + CHECK_EQUAL(0x2189U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_kermit_4_add_values) { diff --git a/test/test_crc16_m17.cpp b/test/test_crc16_m17.cpp index b28d624b..9f25eae3 100644 --- a/test/test_crc16_m17.cpp +++ b/test/test_crc16_m17.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x772BU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_m17_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_m17(data, data + 9); + + CHECK_EQUAL(0x772BU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_m17_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x772BU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_m17_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_m17_t16(data, data + 9); + + CHECK_EQUAL(0x772BU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_m17_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x772BU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_m17_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_m17_t4(data, data + 9); + + CHECK_EQUAL(0x772BU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_m17_4_add_values) { diff --git a/test/test_crc16_maxim.cpp b/test/test_crc16_maxim.cpp index a2a92e40..e238dee7 100644 --- a/test/test_crc16_maxim.cpp +++ b/test/test_crc16_maxim.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x44C2U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_maxim_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_maxim(data, data + 9); + + CHECK_EQUAL(0x44C2U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_maxim_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x44C2U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_maxim_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_maxim_t16(data, data + 9); + + CHECK_EQUAL(0x44C2U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_maxim_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x44C2U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_maxim_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_maxim_t4(data, data + 9); + + CHECK_EQUAL(0x44C2U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_maxim_4_add_values) { diff --git a/test/test_crc16_mcrf4xx.cpp b/test/test_crc16_mcrf4xx.cpp index eed2f024..1ea47d4e 100644 --- a/test/test_crc16_mcrf4xx.cpp +++ b/test/test_crc16_mcrf4xx.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x6F91U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_mcrf4xx_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_mcrf4xx(data, data + 9); + + CHECK_EQUAL(0x6F91U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_mcrf4xx_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x6F91U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_mcrf4xx_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_mcrf4xx_t16(data, data + 9); + + CHECK_EQUAL(0x6F91U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_mcrf4xx_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x6F91U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_mcrf4xx_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_mcrf4xx_t4(data, data + 9); + + CHECK_EQUAL(0x6F91U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_mcrf4xx_4_add_values) { diff --git a/test/test_crc16_modbus.cpp b/test/test_crc16_modbus.cpp index 6f5779f9..99fbde1b 100644 --- a/test/test_crc16_modbus.cpp +++ b/test/test_crc16_modbus.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x4B37U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_modbus_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_modbus(data, data + 9); + + CHECK_EQUAL(0x4B37U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_modbus_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x4B37U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_modbus_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_modbus_t16(data, data + 9); + + CHECK_EQUAL(0x4B37U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_modbus_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x4B37U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_modbus_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_modbus_t4(data, data + 9); + + CHECK_EQUAL(0x4B37U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_modbus_4_add_values) { diff --git a/test/test_crc16_profibus.cpp b/test/test_crc16_profibus.cpp index 35139534..f6db3473 100644 --- a/test/test_crc16_profibus.cpp +++ b/test/test_crc16_profibus.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xA819U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_profibus_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_profibus(data, data + 9); + + CHECK_EQUAL(0xA819U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_profibus_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xA819U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_profibus_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_profibus_t16(data, data + 9); + + CHECK_EQUAL(0xA819U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_profibus_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xA819U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_profibus_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_profibus_t4(data, data + 9); + + CHECK_EQUAL(0xA819U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_profibus_4_add_values) { diff --git a/test/test_crc16_riello.cpp b/test/test_crc16_riello.cpp index d54d0fab..60af15ac 100644 --- a/test/test_crc16_riello.cpp +++ b/test/test_crc16_riello.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x63D0U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_riello_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_riello(data, data + 9); + + CHECK_EQUAL(0x63D0U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_riello_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x63D0U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_riello_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_riello_t16(data, data + 9); + + CHECK_EQUAL(0x63D0U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_riello_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x63D0U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_riello_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_riello_t4(data, data + 9); + + CHECK_EQUAL(0x63D0U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_riello_4_add_values) { diff --git a/test/test_crc16_t10dif.cpp b/test/test_crc16_t10dif.cpp index 78e3107d..83c2d973 100644 --- a/test/test_crc16_t10dif.cpp +++ b/test/test_crc16_t10dif.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xD0DBU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_t10dif_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_t10dif(data, data + 9); + + CHECK_EQUAL(0xD0DBU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_t10dif_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xD0DBU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_t10dif_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_t10dif_t16(data, data + 9); + + CHECK_EQUAL(0xD0DBU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_t10dif_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xD0DBU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_t10dif_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_t10dif_t4(data, data + 9); + + CHECK_EQUAL(0xD0DBU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_t10dif_4_add_values) { diff --git a/test/test_crc16_teledisk.cpp b/test/test_crc16_teledisk.cpp index 063c725f..fc3bb741 100644 --- a/test/test_crc16_teledisk.cpp +++ b/test/test_crc16_teledisk.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x0FB3U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_teledisk_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_teledisk(data, data + 9); + + CHECK_EQUAL(0x0FB3U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_teledisk_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x0FB3U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_teledisk_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_teledisk_t16(data, data + 9); + + CHECK_EQUAL(0x0FB3U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_teledisk_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x0FB3U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_teledisk_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_teledisk_t4(data, data + 9); + + CHECK_EQUAL(0x0FB3U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_teledisk_4_add_values) { diff --git a/test/test_crc16_tms37157.cpp b/test/test_crc16_tms37157.cpp index 1fc0d3e6..893e2b4d 100644 --- a/test/test_crc16_tms37157.cpp +++ b/test/test_crc16_tms37157.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x26B1U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_tms37157_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_tms37157(data, data + 9); + + CHECK_EQUAL(0x26B1U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_tms37157_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x26B1U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_tms37157_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_tms37157_t16(data, data + 9); + + CHECK_EQUAL(0x26B1U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_tms37157_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x26B1U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_tms37157_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_tms37157_t4(data, data + 9); + + CHECK_EQUAL(0x26B1U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_tms37157_4_add_values) { diff --git a/test/test_crc16_usb.cpp b/test/test_crc16_usb.cpp index 3f3d23b6..b0203da9 100644 --- a/test/test_crc16_usb.cpp +++ b/test/test_crc16_usb.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xB4C8U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_usb_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_usb(data, data + 9); + + CHECK_EQUAL(0xB4C8U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_usb_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xB4C8U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_usb_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_usb_t16(data, data + 9); + + CHECK_EQUAL(0xB4C8U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_usb_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xB4C8U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_usb_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_usb_t4(data, data + 9); + + CHECK_EQUAL(0xB4C8U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_usb_4_add_values) { diff --git a/test/test_crc16_x25.cpp b/test/test_crc16_x25.cpp index 2906214a..edea98e7 100644 --- a/test/test_crc16_x25.cpp +++ b/test/test_crc16_x25.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x906EU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_x25_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_x25(data, data + 9); + + CHECK_EQUAL(0x906EU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_x25_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x906EU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_x25_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_x25_t16(data, data + 9); + + CHECK_EQUAL(0x906EU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_x25_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x906EU, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_x25_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_x25_t4(data, data + 9); + + CHECK_EQUAL(0x906EU, crc); + } +#endif + //************************************************************************* TEST(test_crc16_x25_4_add_values) { diff --git a/test/test_crc16_xmodem.cpp b/test/test_crc16_xmodem.cpp index e303ee24..a18b072b 100644 --- a/test/test_crc16_xmodem.cpp +++ b/test/test_crc16_xmodem.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x31C3U, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc16_xmodem_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_xmodem(data, data + 9); + + CHECK_EQUAL(0x31C3U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_xmodem_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x31C3U, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc16_xmodem_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_xmodem_t16(data, data + 9); + + CHECK_EQUAL(0x31C3U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_xmodem_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x31C3U, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc16_xmodem_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint16_t crc = etl::crc16_xmodem_t4(data, data + 9); + + CHECK_EQUAL(0x31C3U, crc); + } +#endif + //************************************************************************* TEST(test_crc16_xmodem_4_add_values) { diff --git a/test/test_crc32.cpp b/test/test_crc32.cpp index bbc278e5..4ff6c7dd 100644 --- a/test/test_crc32.cpp +++ b/test/test_crc32.cpp @@ -127,6 +127,17 @@ namespace CHECK_EQUAL(0xCBF43926UL, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc32_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_t16(data, data + 9); + + CHECK_EQUAL(0xCBF43926UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_16_add_values) { @@ -199,6 +210,17 @@ namespace CHECK_EQUAL(0xCBF43926UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_t4(data, data + 9); + + CHECK_EQUAL(0xCBF43926UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_4_add_values) { diff --git a/test/test_crc32_bzip2.cpp b/test/test_crc32_bzip2.cpp index 76655dd0..10367e08 100644 --- a/test/test_crc32_bzip2.cpp +++ b/test/test_crc32_bzip2.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xFC891918UL, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc32_bzip2_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_bzip2(data, data + 9); + + CHECK_EQUAL(0xFC891918UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_bzip2_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xFC891918UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_bzip2_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_bzip2_t16(data, data + 9); + + CHECK_EQUAL(0xFC891918UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_bzip2_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xFC891918UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_bzip2_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_bzip2_t4(data, data + 9); + + CHECK_EQUAL(0xFC891918UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_bzip2_4_add_values) { diff --git a/test/test_crc32_c.cpp b/test/test_crc32_c.cpp index a0259eae..feb44482 100644 --- a/test/test_crc32_c.cpp +++ b/test/test_crc32_c.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xE3069283UL, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc32_c_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_c(data, data + 9); + + CHECK_EQUAL(0xE3069283UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_c_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xE3069283UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_c_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_c_t16(data, data + 9); + + CHECK_EQUAL(0xE3069283UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_c_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xE3069283UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_c_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_c_t4(data, data + 9); + + CHECK_EQUAL(0xE3069283UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_c_4_add_values) { diff --git a/test/test_crc32_d.cpp b/test/test_crc32_d.cpp index 8dc77f71..1ccf3124 100644 --- a/test/test_crc32_d.cpp +++ b/test/test_crc32_d.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x87315576UL, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc32_d_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_d(data, data + 9); + + CHECK_EQUAL(0x87315576UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_d_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x87315576UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_d_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_d_t16(data, data + 9); + + CHECK_EQUAL(0x87315576UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_d_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x87315576UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_d_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_d_t4(data, data + 9); + + CHECK_EQUAL(0x87315576UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_d_4_add_values) { diff --git a/test/test_crc32_jamcrc.cpp b/test/test_crc32_jamcrc.cpp index 167b55de..ad170b44 100644 --- a/test/test_crc32_jamcrc.cpp +++ b/test/test_crc32_jamcrc.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x340BC6D9UL, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc32_jamcrc_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_jamcrc(data, data + 9); + + CHECK_EQUAL(0x340BC6D9UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_jamcrc_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x340BC6D9UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_jamcrc_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_jamcrc_t16(data, data + 9); + + CHECK_EQUAL(0x340BC6D9UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_jamcrc_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x340BC6D9UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_jamcrc_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_jamcrc_t4(data, data + 9); + + CHECK_EQUAL(0x340BC6D9UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_jamcrc_4_add_values) { diff --git a/test/test_crc32_mpeg2.cpp b/test/test_crc32_mpeg2.cpp index d297c389..5c3533a0 100644 --- a/test/test_crc32_mpeg2.cpp +++ b/test/test_crc32_mpeg2.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x0376E6E7UL, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc32_mpeg2_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_mpeg2(data, data + 9); + + CHECK_EQUAL(0x0376E6E7UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_mpeg2_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x0376E6E7UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_mpeg2_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_mpeg2_t16(data, data + 9); + + CHECK_EQUAL(0x0376E6E7UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_mpeg2_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x0376E6E7UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_mpeg2_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_mpeg2_t4(data, data + 9); + + CHECK_EQUAL(0x0376E6E7UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_mpeg2_4_add_values) { diff --git a/test/test_crc32_posix.cpp b/test/test_crc32_posix.cpp index df132d5c..3cfb60cd 100644 --- a/test/test_crc32_posix.cpp +++ b/test/test_crc32_posix.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x765E7680UL, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc32_posix_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_posix(data, data + 9); + + CHECK_EQUAL(0x765E7680UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_posix_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x765E7680UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_posix_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_posix_t16(data, data + 9); + + CHECK_EQUAL(0x765E7680UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_posix_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x765E7680UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_posix_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_posix_t4(data, data + 9); + + CHECK_EQUAL(0x765E7680UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_posix_4_add_values) { diff --git a/test/test_crc32_q.cpp b/test/test_crc32_q.cpp index 0d2dc260..3c0f8cdd 100644 --- a/test/test_crc32_q.cpp +++ b/test/test_crc32_q.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x3010BF7FUL, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc32_q_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_q(data, data + 9); + + CHECK_EQUAL(0x3010BF7FUL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_q_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x3010BF7FUL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_q_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_q_t16(data, data + 9); + + CHECK_EQUAL(0x3010BF7FUL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_q_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x3010BF7FUL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_q_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_q_t4(data, data + 9); + + CHECK_EQUAL(0x3010BF7FUL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_q_4_add_values) { diff --git a/test/test_crc32_xfer.cpp b/test/test_crc32_xfer.cpp index 4c886bbc..75ff0e43 100644 --- a/test/test_crc32_xfer.cpp +++ b/test/test_crc32_xfer.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xBD0BE338UL, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc32_xfer_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_xfer(data, data + 9); + + CHECK_EQUAL(0xBD0BE338UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_xfer_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xBD0BE338UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_xfer_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_xfer_t16(data, data + 9); + + CHECK_EQUAL(0xBD0BE338UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_xfer_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xBD0BE338UL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc32_xfer_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint32_t crc = etl::crc32_xfer_t4(data, data + 9); + + CHECK_EQUAL(0xBD0BE338UL, crc); + } +#endif + //************************************************************************* TEST(test_crc32_xfer_4_add_values) { diff --git a/test/test_crc64_ecma.cpp b/test/test_crc64_ecma.cpp index 1b32ce8f..f5d0ebd1 100644 --- a/test/test_crc64_ecma.cpp +++ b/test/test_crc64_ecma.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x6C40DF5F0B497347ULL, crc); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc64_ecma_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint64_t crc = etl::crc64_ecma(data, data + 9); + + CHECK_EQUAL(0x6C40DF5F0B497347ULL, crc); + } +#endif + //************************************************************************* TEST(test_crc64_ecma_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x6C40DF5F0B497347ULL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc64_ecma_16_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint64_t crc = etl::crc64_ecma_t16(data, data + 9); + + CHECK_EQUAL(0x6C40DF5F0B497347ULL, crc); + } +#endif + //************************************************************************* TEST(test_crc64_ecma_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x6C40DF5F0B497347ULL, crc); } +#if ETL_USING_CPP14 + //************************************************************************* + TEST(test_crc64_ecma_4_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint64_t crc = etl::crc64_ecma_t4(data, data + 9); + + CHECK_EQUAL(0x6C40DF5F0B497347ULL, crc); + } +#endif + //************************************************************************* TEST(test_crc64_ecma_4_add_values) { diff --git a/test/test_crc8_ccitt.cpp b/test/test_crc8_ccitt.cpp index bb531a68..a313c5ad 100644 --- a/test/test_crc8_ccitt.cpp +++ b/test/test_crc8_ccitt.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xF4U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_ccitt_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_ccitt_t4(data, data + 9); + + CHECK_EQUAL(0xF4U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_ccitt_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xF4U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_ccitt_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_ccitt_t16(data, data + 9); + + CHECK_EQUAL(0xF4U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_ccitt_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xF4U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_ccitt_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_ccitt(data, data + 9); + + CHECK_EQUAL(0xF4U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_ccitt_256_add_values) { diff --git a/test/test_crc8_cdma2000.cpp b/test/test_crc8_cdma2000.cpp index bf43d73e..e5bda16f 100644 --- a/test/test_crc8_cdma2000.cpp +++ b/test/test_crc8_cdma2000.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xDAU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_cdma2000_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_cdma2000_t4(data, data + 9); + + CHECK_EQUAL(0xDAU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_cdma2000_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xDAU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_cdma2000_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_cdma2000_t16(data, data + 9); + + CHECK_EQUAL(0xDAU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_cdma2000_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xDAU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_cdma2000_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_cdma2000(data, data + 9); + + CHECK_EQUAL(0xDAU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_cdma2000_256_add_values) { diff --git a/test/test_crc8_darc.cpp b/test/test_crc8_darc.cpp index 098ca4ce..a1898d6b 100644 --- a/test/test_crc8_darc.cpp +++ b/test/test_crc8_darc.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x15U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_darc_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_darc_t4(data, data + 9); + + CHECK_EQUAL(0x15U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_darc_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x15U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_darc_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_darc_t16(data, data + 9); + + CHECK_EQUAL(0x15U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_darc_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x15U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_darc_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_darc(data, data + 9); + + CHECK_EQUAL(0x15U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_darc_256_add_values) { diff --git a/test/test_crc8_dvbs2.cpp b/test/test_crc8_dvbs2.cpp index 54667146..086f4069 100644 --- a/test/test_crc8_dvbs2.cpp +++ b/test/test_crc8_dvbs2.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xBCU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_dvbs2_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_dvbs2_t4(data, data + 9); + + CHECK_EQUAL(0xBCU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_dvbs2_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xBCU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_dvbs2_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_dvbs2_t16(data, data + 9); + + CHECK_EQUAL(0xBCU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_dvbs2_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xBCU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_dvbs2_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_dvbs2(data, data + 9); + + CHECK_EQUAL(0xBCU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_dvbs2_256_add_values) { diff --git a/test/test_crc8_ebu.cpp b/test/test_crc8_ebu.cpp index 0e378e93..662791f9 100644 --- a/test/test_crc8_ebu.cpp +++ b/test/test_crc8_ebu.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x97U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_ebu_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_ebu_t4(data, data + 9); + + CHECK_EQUAL(0x97U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_ebu_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x97U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_ebu_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_ebu_t16(data, data + 9); + + CHECK_EQUAL(0x97U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_ebu_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x97U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_ebu_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_ebu(data, data + 9); + + CHECK_EQUAL(0x97U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_ebu_256_add_values) { diff --git a/test/test_crc8_icode.cpp b/test/test_crc8_icode.cpp index 32fd5468..21639eea 100644 --- a/test/test_crc8_icode.cpp +++ b/test/test_crc8_icode.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x7EU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_icode_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_icode_t4(data, data + 9); + + CHECK_EQUAL(0x7EU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_icode_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x7EU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_icode_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_icode_t16(data, data + 9); + + CHECK_EQUAL(0x7EU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_icode_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x7EU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_icode_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_icode(data, data + 9); + + CHECK_EQUAL(0x7EU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_icode_256_add_values) { diff --git a/test/test_crc8_itu.cpp b/test/test_crc8_itu.cpp index 6a14613f..7156db5a 100644 --- a/test/test_crc8_itu.cpp +++ b/test/test_crc8_itu.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xA1U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_itu_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_itu_t4(data, data + 9); + + CHECK_EQUAL(0xA1U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_itu_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xA1U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_itu_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_itu_t16(data, data + 9); + + CHECK_EQUAL(0xA1U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_itu_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xA1U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_itu_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_itu(data, data + 9); + + CHECK_EQUAL(0xA1U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_itu_256_add_values) { diff --git a/test/test_crc8_j1850.cpp b/test/test_crc8_j1850.cpp index 1b50b14a..cbea4c08 100644 --- a/test/test_crc8_j1850.cpp +++ b/test/test_crc8_j1850.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x4BU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_j1850_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_j1850_t4(data, data + 9); + + CHECK_EQUAL(0x4BU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_j1850_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x4BU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_j1850_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_j1850_t16(data, data + 9); + + CHECK_EQUAL(0x4BU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_j1850_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x4BU, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_j1850_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_j1850(data, data + 9); + + CHECK_EQUAL(0x4BU, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_j1850_256_add_values) { diff --git a/test/test_crc8_j1850_zero.cpp b/test/test_crc8_j1850_zero.cpp index 3ab0bae3..caa1ed70 100644 --- a/test/test_crc8_j1850_zero.cpp +++ b/test/test_crc8_j1850_zero.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x37U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_j1850_zero_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_j1850_zero_t4(data, data + 9); + + CHECK_EQUAL(0x37U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_j1850_zero_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x37U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_j1850_zero_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_j1850_zero_t16(data, data + 9); + + CHECK_EQUAL(0x37U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_j1850_zero_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x37U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_j1850_zero_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_j1850_zero(data, data + 9); + + CHECK_EQUAL(0x37U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_j1850_zero_256_add_values) { diff --git a/test/test_crc8_maxim.cpp b/test/test_crc8_maxim.cpp index 8c68d85c..4e1b9d11 100644 --- a/test/test_crc8_maxim.cpp +++ b/test/test_crc8_maxim.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xA1U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_maxim_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_maxim_t4(data, data + 9); + + CHECK_EQUAL(0xA1U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_maxim_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xA1U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_maxim_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_maxim_t16(data, data + 9); + + CHECK_EQUAL(0xA1U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_maxim_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xA1U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_maxim_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_maxim(data, data + 9); + + CHECK_EQUAL(0xA1U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_maxim_256_add_values) { diff --git a/test/test_crc8_rohc.cpp b/test/test_crc8_rohc.cpp index 366474fc..d9f3ac22 100644 --- a/test/test_crc8_rohc.cpp +++ b/test/test_crc8_rohc.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0xD0U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_rohc_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_rohc_t4(data, data + 9); + + CHECK_EQUAL(0xD0U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_rohc_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0xD0U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_rohc_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_rohc_t16(data, data + 9); + + CHECK_EQUAL(0xD0U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_rohc_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0xD0U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_rohc_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_rohc(data, data + 9); + + CHECK_EQUAL(0xD0U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_rohc_256_add_values) { diff --git a/test/test_crc8_wcdma.cpp b/test/test_crc8_wcdma.cpp index 7dfc5215..f5bd9156 100644 --- a/test/test_crc8_wcdma.cpp +++ b/test/test_crc8_wcdma.cpp @@ -55,6 +55,17 @@ namespace CHECK_EQUAL(0x25U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_wcdma_4_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_wcdma_t4(data, data + 9); + + CHECK_EQUAL(0x25U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_wcdma_4_add_values) { @@ -127,6 +138,17 @@ namespace CHECK_EQUAL(0x25U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_wcdma_16_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_wcdma_t16(data, data + 9); + + CHECK_EQUAL(0x25U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_wcdma_16_add_values) { @@ -199,6 +221,17 @@ namespace CHECK_EQUAL(0x25U, int(crc)); } +#if ETL_USING_CPP14 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + //************************************************************************* + TEST(test_crc8_wcdma_256_constructor_constexpr) + { + constexpr char data[] = "123456789"; + constexpr uint8_t crc = etl::crc8_wcdma(data, data + 9); + + CHECK_EQUAL(0x25U, int(crc)); + } +#endif + //************************************************************************* TEST(test_crc8_wcdma_256_add_values) { diff --git a/test/test_cyclic_value.cpp b/test/test_cyclic_value.cpp index face6086..f1f9e193 100644 --- a/test/test_cyclic_value.cpp +++ b/test/test_cyclic_value.cpp @@ -287,7 +287,7 @@ namespace int expected[8] = { 2, 7, 6, 5, 4, 3, 2, 7 }; - for (int i = 0; i > 8; ++i) + for (int i = 0; i < 8; ++i) { CHECK_EQUAL(expected[i], value); --value; @@ -303,7 +303,7 @@ namespace int expected[8] = { 2, 7, 6, 5, 4, 3, 2, 7 }; - for (int i = 0; i > 8; ++i) + for (int i = 0; i < 8; ++i) { CHECK_EQUAL(expected[i], value); --value; diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index 0f9d29a8..302787b5 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -221,8 +221,6 @@ namespace parameter_correct = (data.d == VALUE1) && (j == VALUE2); } - //******************************************* - // operator() void operator()() { function_called = FunctionCalled::Operator_Called; @@ -234,6 +232,26 @@ namespace } }; + //******************************************* + // Functor with non-const operator() + struct Functor + { + void operator()() + { + function_called = FunctionCalled::Operator_Called; + } + }; + + //******************************************* + // Functor with const operator() + struct FunctorConst + { + void operator()() const + { + function_called = FunctionCalled::Operator_Const_Called; + } + }; + //******************************************* int times_2(int a) { @@ -242,6 +260,15 @@ namespace Object object_static; const Object const_object_static; + +#if ETL_USING_CPP17 + Functor functor_static; + const FunctorConst const_functor_static; +#endif + +#if ETL_USING_CPP17 + static auto global_lambda = [](int i, int j) { return i + j; }; +#endif } namespace @@ -287,7 +314,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_is_valid_true) { - etl::delegate d([] {}); + auto lambda = [] {}; + + etl::delegate d(lambda); CHECK(d.is_valid()); CHECK(d); @@ -297,7 +326,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_is_valid_after_clear) { - etl::delegate d([] {}); + auto lambda = [] {}; + + etl::delegate d(lambda); CHECK_TRUE(d.is_valid()); d.clear(); @@ -314,6 +345,18 @@ namespace CHECK(function_called == FunctionCalled::Free_Void_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_void) + { + auto d = etl::make_delegate<&free_void>(); + + d(); + + CHECK(function_called == FunctionCalled::Free_Void_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_free_void_constexpr) @@ -326,6 +369,18 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_void_constexpr) + { + constexpr auto d = etl::make_delegate<&free_void>(); + + d(); + + CHECK(function_called == FunctionCalled::Free_Void_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_free_int) { @@ -337,6 +392,19 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_int) + { + auto d = etl::make_delegate<&free_int>(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Free_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_free_int_constexpr) @@ -350,6 +418,19 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_int_constexpr) + { + constexpr auto d = etl::make_delegate<&free_int>(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Free_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_free_reference) { @@ -364,6 +445,22 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_reference) + { + etl::delegate d = etl::make_delegate<&free_reference>(); + + Data data; + data.d = VALUE1; + + d(data, VALUE2); + + CHECK(function_called == FunctionCalled::Free_Reference_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_free_reference_constexpr) @@ -380,6 +477,22 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_reference_constexpr) + { + constexpr etl::delegate d = etl::make_delegate<&free_reference>(); + + Data data; + data.d = VALUE1; + + d(data, VALUE2); + + CHECK(function_called == FunctionCalled::Free_Reference_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_free_moveableonly) { @@ -394,6 +507,22 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_moveableonly) + { + auto d = etl::make_delegate<&free_moveableonly>(); + + MoveableOnlyData data; + data.d = VALUE1; + + d(std::move(data)); + + CHECK(function_called == FunctionCalled::Free_Moveableonly_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_free_moveableonly_constexpr) @@ -410,10 +539,28 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_moveableonly_constexpr) + { + constexpr auto d = etl::make_delegate<&free_moveableonly>(); + + MoveableOnlyData data; + data.d = VALUE1; + + d(std::move(data)); + + CHECK(function_called == FunctionCalled::Free_Moveableonly_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_lambda_int) { - etl::delegate d([](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); }); + auto lambda = [](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); }; + + etl::delegate d(lambda); d(VALUE1, VALUE2); @@ -421,6 +568,20 @@ namespace CHECK(parameter_correct); } +#if ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constexpr_lambda_int) + { + static constexpr int(*global_func_ptr)(int, int) = global_lambda; + + auto d = etl::delegate::create(); + + int result = d(VALUE1, VALUE2); + + CHECK_EQUAL(result, VALUE1 + VALUE2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_lambda_int_create) { @@ -434,6 +595,21 @@ namespace CHECK(parameter_correct); } +#if ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_make_delegate_lambda_int_create) + { + auto lambda = [](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); }; + + auto d = etl::make_delegate(lambda); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Lambda_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_operator_void) { @@ -446,6 +622,20 @@ namespace CHECK(function_called == FunctionCalled::Operator_Called); } +#if ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void) + { + Functor object; + + auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_operator_void_create) { @@ -459,7 +649,7 @@ namespace } //************************************************************************* -#if ETL_USING_CPP14 +#if ETL_USING_CPP17 TEST_FIXTURE(SetupFixture, test_member_operator_void_create_constexpr) { static Object object; @@ -484,7 +674,21 @@ namespace CHECK(function_called == FunctionCalled::Operator_Const_Called); } -#if !defined(ETL_COMPILER_GCC) + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void_const) + { + const FunctorConst object; + + auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Const_Called); + } +#endif + +#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8)) //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_operator_void_compile_time) { @@ -495,6 +699,18 @@ namespace CHECK(function_called == FunctionCalled::Operator_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void_compile_time) + { + auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_operator_void_compile_time_constexpr) @@ -507,6 +723,18 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void_compile_time_constexpr) + { + constexpr auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_operator_void_compile_time_const) { @@ -517,6 +745,18 @@ namespace CHECK(function_called == FunctionCalled::Operator_Const_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void_compile_time_const) + { + auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Const_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_operator_void_compile_time_const_constexpr) @@ -528,6 +768,18 @@ namespace CHECK(function_called == FunctionCalled::Operator_Const_Called); } #endif + + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void_compile_time_const_constexpr) + { + constexpr auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Const_Called); + } +#endif #endif //************************************************************************* @@ -556,6 +808,20 @@ namespace CHECK(function_called == FunctionCalled::Member_Void_Called); } +#if ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void) + { + Object object; + + auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_void_constexpr) @@ -570,6 +836,20 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_constexpr) + { + static Object object; + + constexpr auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_void_const) { @@ -582,6 +862,20 @@ namespace CHECK(function_called == FunctionCalled::Member_Void_Const_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_const) + { + const Object object; + + auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_void_const_constexpr) @@ -596,6 +890,20 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_const_constexpr) + { + static const Object object; + + constexpr auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int) { @@ -609,6 +917,21 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int) + { + Object object; + + auto d = etl::make_delegate(object); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_int_constexpr) @@ -624,6 +947,21 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_constexpr) + { + static Object object; + + constexpr auto d = etl::make_delegate(object); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int_const) { @@ -637,6 +975,21 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_const) + { + const Object object; + + auto d = etl::make_delegate(object); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_int_const_constexpr) @@ -652,6 +1005,21 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_const_constexpr) + { + static const Object object; + + constexpr auto d = etl::make_delegate(object); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_reference) { @@ -762,6 +1130,22 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +//#if ETL_USING_CPP17 +// TEST_FIXTURE(SetupFixture, test_make_delegate_member_static) +// { +// auto d = etl::make_delegate(); +// +// Data data; +// data.d = VALUE1; +// +// d(data, VALUE2); +// +// CHECK(function_called == FunctionCalled::Member_Static_Called); +// CHECK(parameter_correct); +// } +//#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_static_constexpr) @@ -778,6 +1162,22 @@ namespace } #endif + //************************************************************************* +//#if ETL_USING_CPP17 +// TEST_FIXTURE(SetupFixture, test_make_delegate_member_static_constexpr) +// { +// constexpr auto d = etl::make_delegate(); +// +// Data data; +// data.d = VALUE1; +// +// d(data, VALUE2); +// +// CHECK(function_called == FunctionCalled::Member_Static_Called); +// CHECK(parameter_correct); +// } +//#endif + #if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 5)) //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_void_compile_time) @@ -799,6 +1199,18 @@ namespace CHECK(function_called == FunctionCalled::Member_Void_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_compile_time_new_api) + { + auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_void_compile_time_constexpr) @@ -823,6 +1235,18 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_compile_time_constexpr_new_api) + { + constexpr auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_void_const_compile_time) { @@ -843,6 +1267,18 @@ namespace CHECK(function_called == FunctionCalled::Member_Void_Const_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_const_compile_time_new_api) + { + auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_void_const_compile_time_constexpr) @@ -867,6 +1303,18 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_const_compile_time_constexpr_new_api) + { + constexpr auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int_compile_time) { @@ -889,6 +1337,19 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_compile_time_new_api) + { + auto d = etl::make_delegate(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_int_compile_time_constexpr) @@ -915,6 +1376,19 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_compile_time_constexpr_new_api) + { + constexpr auto d = etl::make_delegate(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int_const_compile_time) { @@ -937,6 +1411,19 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_const_compile_tim1e_new_api) + { + auto d = etl::make_delegate(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_int_const_compile_time_constexpr) @@ -963,6 +1450,19 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_const_compile_time_constexpr_new_api) + { + constexpr auto d = etl::make_delegate(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_reference_compile_time) { diff --git a/test/test_etl_traits.cpp b/test/test_etl_traits.cpp index a071960e..24123ad3 100644 --- a/test/test_etl_traits.cpp +++ b/test/test_etl_traits.cpp @@ -77,6 +77,7 @@ namespace CHECK_EQUAL((ETL_HAS_IDEQUE_REPAIR == 1), etl::traits::has_ideque_repair); CHECK_EQUAL((ETL_HAS_MUTABLE_ARRAY_VIEW == 1), etl::traits::has_mutable_array_view); CHECK_EQUAL((ETL_HAS_VIRTUAL_MESSAGES == 1), etl::traits::has_virtual_messages); + CHECK_EQUAL((ETL_HAS_PACKED == 1), etl::traits::has_packed); CHECK_EQUAL((ETL_IS_DEBUG_BUILD == 1), etl::traits::is_debug_build); CHECK_EQUAL(__cplusplus, etl::traits::cplusplus); diff --git a/test/test_expected.cpp b/test/test_expected.cpp index 11f2d8b3..d7df3577 100644 --- a/test/test_expected.cpp +++ b/test/test_expected.cpp @@ -161,6 +161,39 @@ namespace CHECK_TRUE(output.v == input.v); } + //************************************************************************* + TEST(test_constructor_in_place_result_with_value) + { + struct ValueInPlace + { + ValueInPlace() + : a(0) + , b(0) + { + } + + ValueInPlace(int a_, int b_) + : a(a_) + , b(b_) + { + } + + int a; + int b; + }; + + using ExpectedInPlace = etl::expected; + + ExpectedInPlace expected(etl::in_place_t(), 1, 2); + + ValueInPlace output = expected.value(); + + CHECK_TRUE(expected.has_value()); + CHECK_TRUE(bool(expected)); + CHECK_TRUE(output.a == 1); + CHECK_TRUE(output.b == 2); + } + //************************************************************************* TEST(test_constructor_for_const_result_with_value) { diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 4f46eefe..494b69c7 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -1075,14 +1075,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_empty) { - CompareDataNDC compare_data; DataNDC data; - compare_data.reverse(); data.reverse(); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); - CHECK(are_equal); + CHECK_TRUE(data.empty()); + CHECK_FALSE(data.full()); + CHECK_EQUAL(0, data.size()); } //************************************************************************* diff --git a/test/test_forward_list_shared_pool.cpp b/test/test_forward_list_shared_pool.cpp index 82830124..6500805a 100644 --- a/test/test_forward_list_shared_pool.cpp +++ b/test/test_forward_list_shared_pool.cpp @@ -1478,20 +1478,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_empty) { - CompareDataNDC compare_data; PoolNDC2 pool; DataNDC data1(pool); DataNDC data2(pool); - compare_data.reverse(); data1.reverse(); data2.reverse(); - are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); - CHECK(are_equal); + CHECK_TRUE(data1.empty()); + CHECK_FALSE(data1.full()); + CHECK_EQUAL(0, data1.size()); - are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); - CHECK(are_equal); + CHECK_TRUE(data2.empty()); + CHECK_FALSE(data2.full()); + CHECK_EQUAL(0, data2.size()); } //************************************************************************* diff --git a/test/test_function_traits.cpp b/test/test_function_traits.cpp new file mode 100644 index 00000000..3e065f58 --- /dev/null +++ b/test/test_function_traits.cpp @@ -0,0 +1,211 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2024 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 "etl/function_traits.h" +#include "etl/type_list.h" + +namespace +{ + //***************************************************************************** + // The free function taking no parameters. + //***************************************************************************** + void free_void() + { + } + + //***************************************************************************** + // The free function taking an int parameter. + //***************************************************************************** + int free_int(int i, int j) + { + return i + j; + } + + //***************************************************************************** + // The test class with member functions. + //***************************************************************************** + class Object + { + public: + + //******************************************* + // void + void member_void() + { + } + + void member_void_const() const + { + } + + //******************************************* + // int + int member_int(int i, int j) + { + return i + j; + } + + int member_int_const(int i, int j) const + { + return i + j; + } + + //******************************************* + // static + static void member_static(int j) + { + (void)j; + } + }; +} + +namespace +{ + SUITE(test_function_traits) + { + //************************************************************************* + TEST(test_free_function_free_void) + { + free_void(); // Keep clang happy + + using traits = etl::function_traits; + + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same, traits::argument_types>::value)); + + CHECK_TRUE(traits::is_function); + CHECK_FALSE(traits::is_member_function); + CHECK_FALSE(traits::is_const); + CHECK_EQUAL(0, traits::argument_count); + } + + //************************************************************************* + TEST(test_free_function_free_int) + { + free_int(1, 2); // Keep clang happy + + using traits = etl::function_traits; + + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same, traits::argument_types>::value)); + + CHECK_TRUE(traits::is_function); + CHECK_FALSE(traits::is_member_function); + CHECK_FALSE(traits::is_const); + CHECK_EQUAL(2 , traits::argument_count); + } + + //************************************************************************* + TEST(test_member_function_void) + { + using traits = etl::function_traits; + + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same, traits::argument_types>::value)); + + CHECK_FALSE(traits::is_function); + CHECK_TRUE(traits::is_member_function); + CHECK_FALSE(traits::is_const); + CHECK_EQUAL(0, traits::argument_count); + } + + //************************************************************************* + TEST(test_member_function_void_const) + { + using traits = etl::function_traits; + + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same, traits::argument_types>::value)); + + CHECK_FALSE(traits::is_function); + CHECK_TRUE(traits::is_member_function); + CHECK_TRUE(traits::is_const); + CHECK_EQUAL(0, traits::argument_count); + } + + //************************************************************************* + TEST(test_member_function_int) + { + using traits = etl::function_traits; + + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same, traits::argument_types>::value)); + + CHECK_FALSE(traits::is_function); + CHECK_TRUE(traits::is_member_function); + CHECK_FALSE(traits::is_const); + CHECK_EQUAL(2, traits::argument_count); + } + + //************************************************************************* + TEST(test_member_function_int_const) + { + using traits = etl::function_traits; + + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same, traits::argument_types>::value)); + + CHECK_FALSE(traits::is_function); + CHECK_TRUE(traits::is_member_function); + CHECK_TRUE(traits::is_const); + CHECK_EQUAL(2, traits::argument_count); + } + + //************************************************************************* + TEST(test_member_function_static) + { + using traits = etl::function_traits; + + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same, traits::argument_types>::value)); + + CHECK_TRUE(traits::is_function); + CHECK_FALSE(traits::is_member_function); + CHECK_FALSE(traits::is_const); + CHECK_EQUAL(1, traits::argument_count); + } + }; +} diff --git a/test/test_index_of_type.cpp b/test/test_index_of_type.cpp new file mode 100644 index 00000000..60d211e8 --- /dev/null +++ b/test/test_index_of_type.cpp @@ -0,0 +1,58 @@ +/****************************************************************************** +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/index_of_type.h" +#include + +namespace +{ + SUITE(test_index_of_type) + { + //************************************************************************* + TEST(test_index_of_type) + { + CHECK_EQUAL(0, (etl::index_of_type::value)); + CHECK_EQUAL(1, (etl::index_of_type::value)); + CHECK_EQUAL(2, (etl::index_of_type::value)); + CHECK_EQUAL(etl::index_of_type_npos, (etl::index_of_type::value)); + } + + //************************************************************************* +#if ETL_USING_CPP17 + TEST(test_index_of_type_v) + { + CHECK_EQUAL(0, (etl::index_of_type_v)); + CHECK_EQUAL(1, (etl::index_of_type_v)); + CHECK_EQUAL(2, (etl::index_of_type_v)); + CHECK_EQUAL(etl::index_of_type_npos, (etl::index_of_type_v)); + } +#endif + } +} diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 20c8d830..9e854486 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -183,6 +183,42 @@ namespace CHECK_EQUAL(sorted_data.size(), data0.size()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_single) + { + DataNDC0 data0(sorted_data[0]); + + CHECK(!data0.empty()); + CHECK_EQUAL(1, data0.size()); + CHECK_EQUAL(sorted_data[0], data0.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_multiple) + { + DataNDC0 data0(sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9]); + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_initializer_list) + { + DataNDC0 data0 = { sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9] }; + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { @@ -699,6 +735,90 @@ namespace CHECK(ETL_NULLPTR == p_next5); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_by_node_pointer) + { + bool are_equal; + + std::vector compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC0 data0(sorted_data.begin(), sorted_data.end()); + DataNDC1 data1(sorted_data.begin(), sorted_data.end()); + + // Move to the third value and erase. + std::vector::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, 3); + + DataNDC0::iterator i_data = data0.begin(); + std::advance(i_data, 3); + + ItemNDCNode& node1 = *i_data; + ItemNDCNode* p_next1 = static_cast(node1.FirstLink::get_next()); + ItemNDCNode* p_node1 = data0.erase(&node1); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next1, p_node1); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the first value and erase. + i_compare_data = compare_data.begin(); + i_compare_data = compare_data.erase(i_compare_data); + + i_data = data0.begin(); + + ItemNDCNode& node2 = *i_data; + ItemNDCNode* p_next2 = static_cast(node2.FirstLink::get_next()); + ItemNDCNode* p_node2 = data0.erase(&node2); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next2, p_node2); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the last value and erase. + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, compare_data.size() - 1); + + i_data = data0.begin(); + std::advance(i_data, data0.size() - 1); + + ItemNDCNode& node3 = *i_data; + ItemNDCNode* p_next3 = static_cast(node3.FirstLink::get_next()); + ItemNDCNode* p_node3 = data0.erase(&node3); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_NOT_EQUAL(p_next3, p_node3); + CHECK(ETL_NULLPTR == p_node3); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Try removing a node that isn't in the list. + auto node_not_in_list = ItemNDCNode("9"); + + ItemNDCNode* p_node4 = data0.erase(&node_not_in_list); + CHECK(p_node4 == ETL_NULLPTR); + + // Try removing the only node in the list. + while (data0.size() > 1) + { + data0.pop_front(); + } + + ItemNDCNode* p_node5 = &data0.front(); + + ItemNDCNode* p_next5 = static_cast(p_node5->FirstLink::get_next()); + p_next5 = data0.erase(p_node5); + CHECK(ETL_NULLPTR == p_next5); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_after_range) { @@ -859,6 +979,35 @@ namespace CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_remove_by_pointer) + { + std::forward_list compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC0 data0(sorted_data.begin(), sorted_data.end()); + DataNDC1 data1(sorted_data.begin(), sorted_data.end()); + + auto it = data0.begin(); + for (int i = 0; i < 7; ++i) + { + it++; + } + ItemNDCNode* element = ⁢ + + compare_data.remove(ItemNDCNode("7")); + data0.remove(*element); + + bool are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); + + are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); + CHECK(are_equal); + CHECK_EQUAL(sorted_data.size(), data1.size()); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_remove_if) { @@ -1166,5 +1315,77 @@ namespace CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); CHECK_EQUAL(size_t(std::distance(compare1.begin(), compare1.end())), data1.size()); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_node) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains_node(node0)); + CHECK_TRUE(data0.contains_node(node1)); + CHECK_TRUE(data0.contains_node(node2)); + CHECK_TRUE(data0.contains_node(node3)); + CHECK_TRUE(data0.contains_node(node4)); + CHECK_TRUE(data0.contains_node(node5)); + + CHECK_FALSE(data0.contains_node(node6)); + CHECK_FALSE(data0.contains_node(node7)); + CHECK_FALSE(data0.contains_node(node8)); + CHECK_FALSE(data0.contains_node(node9)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains(ItemNDCNode("0"))); + + ItemNDCNode compare_node1("1"); + + CHECK_TRUE(data0.contains(compare_node1)); + + CHECK_FALSE(data0.contains(ItemNDCNode("6"))); + + ItemNDCNode compare_node2("7"); + + CHECK_FALSE(data0.contains(compare_node2)); + } }; } diff --git a/test/test_intrusive_links.cpp b/test/test_intrusive_links.cpp index 13a09c5b..cdfa1d8c 100644 --- a/test/test_intrusive_links.cpp +++ b/test/test_intrusive_links.cpp @@ -32,6 +32,8 @@ SOFTWARE. #include "etl/intrusive_links.h" +#include + namespace { //******************************************************* @@ -157,6 +159,166 @@ namespace CHECK_EQUAL(0, pdata->value); } + //************************************************************************* + TEST(test_create_linked_list_multiple_forward_links_as_references) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + FLink0* last0 = etl::create_linked_list(data0, data1, data2, data3); + CHECK(last0 == &data3); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + FLink1* last1 = etl::create_linked_list(data3, data2, data1, data0); + CHECK(last1 == &data0); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data1); + CHECK(data1.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + + FData* pdata; + + pdata = static_cast(data0.FLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.FLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + FData data4(4); + FData data5(5); + FData data6(6); + FData data7(7); + + auto last2 = etl::create_linked_list(*last0, data4, data5, data6, data7); + CHECK(last2 == &data7); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == &data4); + CHECK(data4.FLink0::etl_next == &data5); + CHECK(data5.FLink0::etl_next == &data6); + CHECK(data6.FLink0::etl_next == &data7); + CHECK(data7.FLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_create_linked_list_multiple_forward_links_as_pointers) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + FLink0* last0 = etl::create_linked_list(&data0, &data1, &data2, &data3); + CHECK(last0 == &data3); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + FLink1* last1 = etl::create_linked_list(&data3, &data2, &data1, &data0); + CHECK(last1 == &data0); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data1); + CHECK(data1.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + + FData* pdata; + + pdata = static_cast(data0.FLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.FLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + FData data4(4); + FData data5(5); + FData data6(6); + FData data7(7); + + auto last2 = etl::create_linked_list(last0, &data4, &data5, &data6, &data7); + CHECK(last2 == &data7); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == &data4); + CHECK(data4.FLink0::etl_next == &data5); + CHECK(data5.FLink0::etl_next == &data6); + CHECK(data6.FLink0::etl_next == &data7); + CHECK(data7.FLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_forward_links_as_references) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(data0); + etl::detach_linked_list(data3); + + CHECK(data0.FLink0::etl_next == ETL_NULLPTR); + CHECK(data1.FLink0::etl_next == ETL_NULLPTR); + CHECK(data2.FLink0::etl_next == ETL_NULLPTR); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + CHECK(data1.FLink1::etl_next == ETL_NULLPTR); + CHECK(data2.FLink1::etl_next == ETL_NULLPTR); + CHECK(data3.FLink1::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_forward_links_as_pointers) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(&data0); + etl::detach_linked_list(&data3); + + CHECK(data0.FLink0::etl_next == ETL_NULLPTR); + CHECK(data1.FLink0::etl_next == ETL_NULLPTR); + CHECK(data2.FLink0::etl_next == ETL_NULLPTR); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + CHECK(data1.FLink1::etl_next == ETL_NULLPTR); + CHECK(data2.FLink1::etl_next == ETL_NULLPTR); + CHECK(data3.FLink1::etl_next == ETL_NULLPTR); + } + //************************************************************************* TEST(test_link_forward_link_get_set) { @@ -537,6 +699,181 @@ namespace data2.BLink0::unlink(); } + //************************************************************************* + TEST(test_create_linked_list_multiple_bidirectional_links_as_references) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + BLink0* last0 = etl::create_linked_list(data0, data1, data2, data3); + CHECK(last0 == &data3); + CHECK(data0.BLink0::etl_previous == ETL_NULLPTR); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + BLink1* last1 = etl::create_linked_list(data3, data2, data1, data0); + CHECK(last1 == &data0); + CHECK(data3.BLink1::etl_previous == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_previous == &data3); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_previous == &data2); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_previous == &data1); + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + + BData* pdata; + + pdata = static_cast(data0.BLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.BLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + BData data4(4); + BData data5(5); + BData data6(6); + BData data7(7); + + auto last2 = etl::create_linked_list(*last0, data4, data5, data6, data7); + CHECK(last2 == &data7); + CHECK(data0.BLink0::etl_previous == ETL_NULLPTR); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == &data4); + CHECK(data4.BLink0::etl_previous == &data3); + CHECK(data4.BLink0::etl_next == &data5); + CHECK(data5.BLink0::etl_previous == &data4); + CHECK(data5.BLink0::etl_next == &data6); + CHECK(data6.BLink0::etl_previous == &data5); + CHECK(data6.BLink0::etl_next == &data7); + CHECK(data7.BLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_create_linked_list_multiple_bidirectional_links_as_pointers) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + BLink0* last0 = etl::create_linked_list(&data0, &data1, &data2, &data3); + CHECK(last0 == &data3); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + BLink1* last1 = etl::create_linked_list(&data3, &data2, &data1, &data0); + CHECK(last1 == &data0); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + + BData* pdata; + + pdata = static_cast(data0.BLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.BLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + BData data4(4); + BData data5(5); + BData data6(6); + BData data7(7); + + auto last2 = etl::create_linked_list(last0, &data4, &data5, &data6, &data7); + CHECK(last2 == &data7); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_next == &data4); + CHECK(data4.BLink0::etl_next == &data5); + CHECK(data5.BLink0::etl_next == &data6); + CHECK(data6.BLink0::etl_next == &data7); + CHECK(data7.BLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_bidirectional_links_as_references) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(data0); + etl::detach_linked_list(data3); + + CHECK(data0.BLink0::etl_next == ETL_NULLPTR); + CHECK(data1.BLink0::etl_next == ETL_NULLPTR); + CHECK(data2.BLink0::etl_next == ETL_NULLPTR); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + CHECK(data1.BLink1::etl_next == ETL_NULLPTR); + CHECK(data2.BLink1::etl_next == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_bidirectional_links_as_pointers) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(&data0); + etl::detach_linked_list(&data3); + + CHECK(data0.BLink0::etl_next == ETL_NULLPTR); + CHECK(data1.BLink0::etl_next == ETL_NULLPTR); + CHECK(data2.BLink0::etl_next == ETL_NULLPTR); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + CHECK(data1.BLink1::etl_next == ETL_NULLPTR); + CHECK(data2.BLink1::etl_next == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == ETL_NULLPTR); + } + //************************************************************************* TEST(test_link_bidirectional_link_get_set) { diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 33aa4467..45de6003 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -196,6 +196,42 @@ namespace CHECK_EQUAL(sorted_data.size(), data0.size()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_single) + { + DataNDC0 data0(sorted_data[0]); + + CHECK(!data0.empty()); + CHECK_EQUAL(1, data0.size()); + CHECK_EQUAL(sorted_data[0], data0.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_multiple) + { + DataNDC0 data0(sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9]); + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_initializer_list) + { + DataNDC0 data0 = { sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9] }; + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { @@ -840,6 +876,90 @@ namespace CHECK(ETL_NULLPTR == p_next5); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_by_node_pointer) + { + bool are_equal; + + std::vector compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC0 data0(sorted_data.begin(), sorted_data.end()); + DataNDC1 data1(sorted_data.begin(), sorted_data.end()); + + // Move to the third value and erase. + std::vector::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, 3); + + DataNDC0::iterator i_data = data0.begin(); + std::advance(i_data, 3); + + ItemNDCNode& node1 = *i_data; + ItemNDCNode* p_next1 = static_cast(node1.FirstLink::get_next()); + ItemNDCNode* p_node1 = data0.erase(&node1); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next1, p_node1); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the first value and erase. + i_compare_data = compare_data.begin(); + i_compare_data = compare_data.erase(i_compare_data); + + i_data = data0.begin(); + + ItemNDCNode& node2 = *i_data; + ItemNDCNode* p_next2 = static_cast(node2.FirstLink::get_next()); + ItemNDCNode* p_node2 = data0.erase(&node2); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next2, p_node2); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the last value and erase. + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, compare_data.size() - 1); + + i_data = data0.begin(); + std::advance(i_data, data0.size() - 1); + + ItemNDCNode& node3 = *i_data; + ItemNDCNode* p_next3 = static_cast(node3.FirstLink::get_next()); + ItemNDCNode* p_node3 = data0.erase(&node3); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_NOT_EQUAL(p_next3, p_node3); + CHECK(ETL_NULLPTR == p_node3); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Try removing a node that isn't in the list. + auto node_not_in_list = ItemNDCNode("9"); + + ItemNDCNode* p_node4 = data0.erase(&node_not_in_list); + CHECK(p_node4 == ETL_NULLPTR); + + // Try removing the only node in the list. + while (data0.size() > 1) + { + data0.pop_back(); + } + + ItemNDCNode* p_node5 = &data0.front(); + + ItemNDCNode* p_next5 = static_cast(p_node5->FirstLink::get_next()); + p_next5 = data0.erase(p_node5); + CHECK(ETL_NULLPTR == p_next5); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -1412,5 +1532,77 @@ namespace CHECK_EQUAL(data0.size(), compare0.size()); CHECK_EQUAL(data1.size(), compare1.size()); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_node) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains_node(node0)); + CHECK_TRUE(data0.contains_node(node1)); + CHECK_TRUE(data0.contains_node(node2)); + CHECK_TRUE(data0.contains_node(node3)); + CHECK_TRUE(data0.contains_node(node4)); + CHECK_TRUE(data0.contains_node(node5)); + + CHECK_FALSE(data0.contains_node(node6)); + CHECK_FALSE(data0.contains_node(node7)); + CHECK_FALSE(data0.contains_node(node8)); + CHECK_FALSE(data0.contains_node(node9)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains(ItemNDCNode("0"))); + + ItemNDCNode compare_node1("1"); + + CHECK_TRUE(data0.contains(compare_node1)); + + CHECK_FALSE(data0.contains(ItemNDCNode("6"))); + + ItemNDCNode compare_node2("7"); + + CHECK_FALSE(data0.contains(compare_node2)); + } }; } diff --git a/test/test_map.cpp b/test/test_map.cpp index bd8817ce..2c19e4e4 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -37,6 +37,7 @@ SOFTWARE. #include #include "etl/map.h" +#include "etl/string.h" #include "data.h" @@ -1575,7 +1576,7 @@ namespace #if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST_FIXTURE(SetupFixture, test_map_template_deduction) { - using Pair = std::pair; + using Pair = std::pair, int>; etl::map data { Pair{"0", 0}, Pair{"1", 1}, Pair{"2", 2}, Pair{"3", 3}, Pair{"4", 4}, Pair{"5", 5} }; @@ -1596,9 +1597,9 @@ namespace #if ETL_HAS_INITIALIZER_LIST TEST_FIXTURE(SetupFixture, test_make_map) { - using Pair = ETL_OR_STD::pair; + using Pair = ETL_OR_STD::pair, int>; - auto data = etl::make_map>(Pair{ "0", 0 }, Pair{ "1", 1 }, Pair{ "2", 2 }, Pair{ "3", 3 }, Pair{ "4", 4 }, Pair{ "5", 5 }); + auto data = etl::make_map, int, std::less>>(Pair{ "0", 0 }, Pair{ "1", 1 }, Pair{ "2", 2 }, Pair{ "3", 3 }, Pair{ "4", 4 }, Pair{ "5", 5 }); auto v = *data.begin(); using Type = decltype(v); diff --git a/test/test_mem_cast.cpp b/test/test_mem_cast.cpp index e8f5d986..406231e9 100644 --- a/test/test_mem_cast.cpp +++ b/test/test_mem_cast.cpp @@ -189,13 +189,22 @@ namespace { MemCast memCast; - memCast.emplace(123); + char mc1 = memCast.emplace(123); CHECK_EQUAL(123, memCast.ref()); + CHECK_EQUAL(123, mc1); - memCast.emplace(1.23); + double mc2 = memCast.emplace(1.23); CHECK_EQUAL(1.23, memCast.ref()); + CHECK_EQUAL(1.23, mc2); + + Data& mc3 = memCast.emplace(123, 1.23, std::array{ 1, 2, 3 }); + + CHECK_EQUAL(123, mc3.c); + CHECK_EQUAL(1.23, mc3.d); + CHECK_EQUAL(1, mc3.a[0]); + CHECK_EQUAL(2, mc3.a[1]); + CHECK_EQUAL(3, mc3.a[2]); - memCast.emplace(123, 1.23, std::array{ 1, 2, 3 }); CHECK_EQUAL(123, memCast.ref().c); CHECK_EQUAL(1.23, memCast.ref().d); CHECK_EQUAL(1, memCast.ref().a[0]); @@ -209,14 +218,32 @@ namespace MemCast memCast; using Array = std::array; - Array a{ 1, 2, 3 }; + Array compare{ 4, 5, 6 }; - size_t offset = offsetof(Data, a); + constexpr size_t ArrayOffset = offsetof(Data, a); - memCast.emplace_at_offset(offset, a); - CHECK_EQUAL(a[0], memCast.ref().a[0]); - CHECK_EQUAL(a[1], memCast.ref().a[1]); - CHECK_EQUAL(a[2], memCast.ref().a[2]); + Array& data = memCast.emplace_at_offset(ArrayOffset, compare); + const MemCast& constMemCastRef = memCast; + + CHECK_EQUAL(compare[0], memCast.ref().a[0]); + CHECK_EQUAL(compare[1], memCast.ref().a[1]); + CHECK_EQUAL(compare[2], memCast.ref().a[2]); + + CHECK_EQUAL(compare[0], (memCast.ref_at_offset(ArrayOffset)[0])); + CHECK_EQUAL(compare[1], (memCast.ref_at_offset(ArrayOffset)[1])); + CHECK_EQUAL(compare[2], (memCast.ref_at_offset(ArrayOffset)[2])); + + CHECK_EQUAL(compare[0], constMemCastRef.ref().a[0]); + CHECK_EQUAL(compare[1], constMemCastRef.ref().a[1]); + CHECK_EQUAL(compare[2], constMemCastRef.ref().a[2]); + + CHECK_EQUAL(compare[0], (constMemCastRef.ref_at_offset(ArrayOffset)[0])); + CHECK_EQUAL(compare[1], (constMemCastRef.ref_at_offset(ArrayOffset)[1])); + CHECK_EQUAL(compare[2], (constMemCastRef.ref_at_offset(ArrayOffset)[2])); + + CHECK_EQUAL(compare[0], data[0]); + CHECK_EQUAL(compare[1], data[1]); + CHECK_EQUAL(compare[2], data[2]); } //************************************************************************* @@ -225,14 +252,32 @@ namespace MemCast memCast; using Array = std::array; - Array a{ 1, 2, 3 }; + Array compare{ 4, 5, 6 }; - constexpr size_t Offset = offsetof(Data, a); + constexpr size_t ArrayOffset = offsetof(Data, a); - memCast.emplace_at_offset(a); - CHECK_EQUAL(a[0], memCast.ref().a[0]); - CHECK_EQUAL(a[1], memCast.ref().a[1]); - CHECK_EQUAL(a[2], memCast.ref().a[2]); + Array& data = memCast.emplace_at_offset(compare); + const MemCast& constMemCastRef = memCast; + + CHECK_EQUAL(compare[0], memCast.ref().a[0]); + CHECK_EQUAL(compare[1], memCast.ref().a[1]); + CHECK_EQUAL(compare[2], memCast.ref().a[2]); + + CHECK_EQUAL(compare[0], (memCast.ref_at_offset()[0])); + CHECK_EQUAL(compare[1], (memCast.ref_at_offset()[1])); + CHECK_EQUAL(compare[2], (memCast.ref_at_offset()[2])); + + CHECK_EQUAL(compare[0], constMemCastRef.ref().a[0]); + CHECK_EQUAL(compare[1], constMemCastRef.ref().a[1]); + CHECK_EQUAL(compare[2], constMemCastRef.ref().a[2]); + + CHECK_EQUAL(compare[0], (constMemCastRef.ref_at_offset()[0])); + CHECK_EQUAL(compare[1], (constMemCastRef.ref_at_offset()[1])); + CHECK_EQUAL(compare[2], (constMemCastRef.ref_at_offset()[2])); + + CHECK_EQUAL(compare[0], data[0]); + CHECK_EQUAL(compare[1], data[1]); + CHECK_EQUAL(compare[2], data[2]); } //************************************************************************* diff --git a/test/test_mem_cast_ptr.cpp b/test/test_mem_cast_ptr.cpp index ec8eadef..e22c4322 100644 --- a/test/test_mem_cast_ptr.cpp +++ b/test/test_mem_cast_ptr.cpp @@ -237,20 +237,29 @@ namespace { char* pbuffer = reinterpret_cast(&buffer); - using Array = std::array; - MemCast memCast(pbuffer); - memCast.emplace(123); + char mc1 = memCast.emplace(123); CHECK_EQUAL(123, memCast.ref()); + CHECK_EQUAL(123, mc1); - memCast.emplace(1.23); + double mc2 = memCast.emplace(1.23); CHECK_EQUAL(1.23, memCast.ref()); + CHECK_EQUAL(1.23, mc2); - memCast.emplace(123, 1.23, std::array{ 1, 2, 3 }); - CHECK_EQUAL(123, memCast.ref().c); + Data& mc3 = memCast.emplace(123, 1.23, std::array{ 1, 2, 3 }); + + CHECK_EQUAL(123, mc3.c); + CHECK_EQUAL(1.23, mc3.d); + CHECK_EQUAL(1, mc3.a[0]); + CHECK_EQUAL(2, mc3.a[1]); + CHECK_EQUAL(3, mc3.a[2]); + + CHECK_EQUAL(123, memCast.ref().c); CHECK_EQUAL(1.23, memCast.ref().d); - CHECK((Array{ 1, 2, 3 }) == memCast.ref().a); + CHECK_EQUAL(1, memCast.ref().a[0]); + CHECK_EQUAL(2, memCast.ref().a[1]); + CHECK_EQUAL(3, memCast.ref().a[2]); } //************************************************************************* @@ -261,12 +270,32 @@ namespace MemCast memCast(pbuffer); using Array = std::array; - Array a{ 1, 2, 3 }; + Array compare{ 4, 5, 6 }; - size_t offset = offsetof(Data, a); + constexpr size_t ArrayOffset = offsetof(Data, a); - memCast.emplace_at_offset(offset, a); - CHECK(a == memCast.ref().a); + Array& data = memCast.emplace_at_offset(ArrayOffset, compare); + const MemCast& constMemCastRef = memCast; + + CHECK_EQUAL(compare[0], memCast.ref().a[0]); + CHECK_EQUAL(compare[1], memCast.ref().a[1]); + CHECK_EQUAL(compare[2], memCast.ref().a[2]); + + CHECK_EQUAL(compare[0], (memCast.ref_at_offset(ArrayOffset)[0])); + CHECK_EQUAL(compare[1], (memCast.ref_at_offset(ArrayOffset)[1])); + CHECK_EQUAL(compare[2], (memCast.ref_at_offset(ArrayOffset)[2])); + + CHECK_EQUAL(compare[0], constMemCastRef.ref().a[0]); + CHECK_EQUAL(compare[1], constMemCastRef.ref().a[1]); + CHECK_EQUAL(compare[2], constMemCastRef.ref().a[2]); + + CHECK_EQUAL(compare[0], (constMemCastRef.ref_at_offset(ArrayOffset)[0])); + CHECK_EQUAL(compare[1], (constMemCastRef.ref_at_offset(ArrayOffset)[1])); + CHECK_EQUAL(compare[2], (constMemCastRef.ref_at_offset(ArrayOffset)[2])); + + CHECK_EQUAL(compare[0], data[0]); + CHECK_EQUAL(compare[1], data[1]); + CHECK_EQUAL(compare[2], data[2]); } //************************************************************************* @@ -274,15 +303,35 @@ namespace { char* pbuffer = reinterpret_cast(&buffer); - MemCast memCast(pbuffer); + MemCast memCast(pbuffer); using Array = std::array; - Array a{ 1, 2, 3 }; + Array compare{ 4, 5, 6 }; - constexpr size_t Offset = offsetof(Data, a); + constexpr size_t ArrayOffset = offsetof(Data, a); - memCast.emplace_at_offset(a); - CHECK(a == memCast.ref().a); + Array& data = memCast.emplace_at_offset(compare); + const MemCast& constMemCastRef = memCast; + + CHECK_EQUAL(compare[0], memCast.ref().a[0]); + CHECK_EQUAL(compare[1], memCast.ref().a[1]); + CHECK_EQUAL(compare[2], memCast.ref().a[2]); + + CHECK_EQUAL(compare[0], (memCast.ref_at_offset()[0])); + CHECK_EQUAL(compare[1], (memCast.ref_at_offset()[1])); + CHECK_EQUAL(compare[2], (memCast.ref_at_offset()[2])); + + CHECK_EQUAL(compare[0], constMemCastRef.ref().a[0]); + CHECK_EQUAL(compare[1], constMemCastRef.ref().a[1]); + CHECK_EQUAL(compare[2], constMemCastRef.ref().a[2]); + + CHECK_EQUAL(compare[0], (constMemCastRef.ref_at_offset()[0])); + CHECK_EQUAL(compare[1], (constMemCastRef.ref_at_offset()[1])); + CHECK_EQUAL(compare[2], (constMemCastRef.ref_at_offset()[2])); + + CHECK_EQUAL(compare[0], data[0]); + CHECK_EQUAL(compare[1], data[1]); + CHECK_EQUAL(compare[2], data[2]); } //************************************************************************* diff --git a/test/test_memory.cpp b/test/test_memory.cpp index 9838094d..9546afef 100644 --- a/test/test_memory.cpp +++ b/test/test_memory.cpp @@ -29,6 +29,7 @@ SOFTWARE. #include "unit_test_framework.h" #include "etl/memory.h" +#include "etl/list.h" #include "etl/debug_count.h" #include "data.h" @@ -1180,6 +1181,17 @@ namespace CHECK(std::equal(src, src + 8, dst)); } + //************************************************************************* + TEST(test_mem_copy_const_pointer_const_pointer_pointer) + { + const uint32_t src[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t dst[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + + etl::mem_copy(src, src + 8, dst); + + CHECK(std::equal(src, src + 8, dst)); + } + //************************************************************************* TEST(test_mem_copy_pointer_length_pointer) { @@ -1187,7 +1199,16 @@ namespace uint32_t dst[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; etl::mem_copy(src, 8, dst); + CHECK(std::equal(src, src + 8, dst)); + } + //************************************************************************* + TEST(test_mem_copy_const_pointer_length_pointer) + { + const uint32_t src[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t dst[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + + etl::mem_copy(src, 8, dst); CHECK(std::equal(src, src + 8, dst)); } @@ -1202,6 +1223,19 @@ namespace CHECK(std::equal(expected, expected + 8, data + 4)); } + //************************************************************************* + TEST(test_mem_move_const_pointer_const_pointer_pointer) + { + uint32_t expected[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t data[12] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201, 0, 0, 0, 0 }; + const uint32_t* data_begin = &data[0]; + const uint32_t* data_end = &data[8]; + + etl::mem_move(data_begin, data_end, data + 4); + + CHECK(std::equal(expected, expected + 8, data + 4)); + } + //************************************************************************* TEST(test_mem_move_pointer_length_pointer) { @@ -1213,6 +1247,17 @@ namespace CHECK(std::equal(expected, expected + 8, data + 4)); } + //************************************************************************* + TEST(test_mem_move_const_pointer_length_pointer) + { + uint32_t expected[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t data[12] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201, 0, 0, 0, 0 }; + const uint32_t* data_begin = &data[0]; + etl::mem_move(data_begin, 8, data + 4); + + CHECK(std::equal(expected, expected + 8, data + 4)); + } + //************************************************************************* TEST(test_mem_compare_pointer_pointer_pointer) { @@ -1226,6 +1271,32 @@ namespace CHECK(etl::mem_compare(data, data + 8, less) < 0); } + //************************************************************************* + TEST(test_mem_compare_const_pointer_const_pointer_pointer) + { + const uint32_t data[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t same[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t grtr[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67235501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t less[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67134501, 0x45016723, 0x01324576, 0x76453201 }; + + CHECK(etl::mem_compare(data, data + 8, same) == 0); + CHECK(etl::mem_compare(data, data + 8, grtr) > 0); + CHECK(etl::mem_compare(data, data + 8, less) < 0); + } + + //************************************************************************* + TEST(test_mem_compare_const_pointer_const_pointer_const_pointer) + { + const uint32_t data[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + const uint32_t same[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t grtr[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67235501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t less[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67134501, 0x45016723, 0x01324576, 0x76453201 }; + + CHECK(etl::mem_compare(data, data + 8, same) == 0); + CHECK(etl::mem_compare(data, data + 8, grtr) > 0); + CHECK(etl::mem_compare(data, data + 8, less) < 0); + } + //************************************************************************* TEST(test_mem_compare_pointer_length_pointer) { @@ -1239,6 +1310,32 @@ namespace CHECK(etl::mem_compare(data, 8, less) < 0); } + //************************************************************************* + TEST(test_mem_compare_const_pointer_length_pointer) + { + const uint32_t data[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t same[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t grtr[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67235501, 0x45016723, 0x01324576, 0x76453201 }; + uint32_t less[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67134501, 0x45016723, 0x01324576, 0x76453201 }; + + CHECK(etl::mem_compare(data, 8, same) == 0); + CHECK(etl::mem_compare(data, 8, grtr) > 0); + CHECK(etl::mem_compare(data, 8, less) < 0); + } + + //************************************************************************* + TEST(test_mem_compare_const_pointer_length_const_pointer) + { + const uint32_t data[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + const uint32_t same[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67234501, 0x45016723, 0x01324576, 0x76453201 }; + const uint32_t grtr[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67235501, 0x45016723, 0x01324576, 0x76453201 }; + const uint32_t less[8] = { 0x12345678, 0x76543210, 0x01452367, 0x23670145, 0x67134501, 0x45016723, 0x01324576, 0x76453201 }; + + CHECK(etl::mem_compare(data, 8, same) == 0); + CHECK(etl::mem_compare(data, 8, grtr) > 0); + CHECK(etl::mem_compare(data, 8, less) < 0); + } + //************************************************************************* TEST(test_mem_set_pointer_pointer) { @@ -1354,7 +1451,7 @@ namespace CHECK(ptr.get() == ETL_NULLPTR); } - //************************************************************************* + struct Flags { Flags() @@ -1527,5 +1624,20 @@ namespace CHECK_THROW(etl::destroy_object_at(pbuffer1), etl::alignment_error); } + + //************************************************************************* + TEST(test_to_address) + { + int i; + int* pi = &i; + + etl::list container = { 1, 2, 3, 4 }; + etl::list::iterator itr = container.begin(); + std::advance(itr, 2); + int* plist_item = &*itr; + + CHECK_EQUAL(&i, etl::to_address(pi)); + CHECK_EQUAL(plist_item, etl::to_address(itr)); + } }; } diff --git a/test/test_message_packet.cpp b/test/test_message_packet.cpp index 426c520c..a13830c8 100644 --- a/test/test_message_packet.cpp +++ b/test/test_message_packet.cpp @@ -30,8 +30,6 @@ SOFTWARE. #include "etl/platform.h" -#if ETL_HAS_VIRTUAL_MESSAGES - #include "etl/message_packet.h" #include @@ -52,21 +50,24 @@ namespace struct Message1 : public etl::message { Message1(int x_) - : x(x_) + : etl::message() + , x(x_) , moved(false) , copied(false) { } Message1(const Message1& other) - : x(other.x) + : etl::message() + , x(other.x) , moved(false) , copied(true) { } Message1(Message1&& other) - : x(std::move(other.x)) + : etl::message() + , x(std::move(other.x)) , moved(true) , copied(false) { @@ -96,21 +97,24 @@ namespace struct Message2 : public etl::message { Message2(double x_) - : x(x_) + : etl::message() + , x(x_) , moved(false) , copied(false) { } Message2(const Message2& other) - : x(other.x) + : etl::message() + , x(other.x) , moved(false) , copied(true) { } Message2(Message2&& other) - : x(std::move(other.x)) + : etl::message() + , x(std::move(other.x)) , moved(true) , copied(false) { @@ -140,28 +144,32 @@ namespace struct Message3 : public etl::message { Message3(const std::string& x_) - : x(x_) + : etl::message() + , x(x_) , moved(false) , copied(false) { } Message3(std::string&& x_) - : x(std::move(x_)) + : etl::message() + , x(std::move(x_)) , moved(true) , copied(false) { } Message3(const Message3& other) - : x(other.x) + : etl::message() + , x(other.x) , moved(false) , copied(true) { } Message3(Message3&& other) - : x(std::move(other.x)) + : etl::message() + , x(std::move(other.x)) , moved(true) , copied(false) { @@ -481,5 +489,3 @@ namespace } }; } - -#endif diff --git a/test/test_message_router.cpp b/test/test_message_router.cpp index b5936d62..43bf1174 100644 --- a/test/test_message_router.cpp +++ b/test/test_message_router.cpp @@ -253,6 +253,77 @@ namespace int sender_id; }; + //*************************************************************************** + // Router that handles messages 1, 2, 3. + // 'receive' is overridden. + //*************************************************************************** + class Router3 : public etl::message_router + { + public: + + using base = etl::message_router; + + Router3() + : message_router(ROUTER3) + , message1_received(false) + , message2_received(false) + , message3_received(false) + , unknown_message_received(false) + { + } + + void receive(const etl::imessage& msg) override + { + switch (msg.get_message_id()) + { + case MESSAGE1: + { + message1_received = true; + break; + } + + case MESSAGE2: + { + message2_received = true; + break; + } + + case MESSAGE3: + { + message3_received = true; + break; + } + + default: + { + unknown_message_received = true; + break; + } + } + } + + void on_receive(const Message1&) + { + } + + void on_receive(const Message2&) + { + } + + void on_receive(const Message3&) + { + } + + void on_receive_unknown(const etl::imessage&) + { + } + + bool message1_received; + bool message2_received; + bool message3_received; + bool unknown_message_received; + }; + etl::imessage_router* p_router; SUITE(test_message_router) @@ -641,5 +712,26 @@ namespace CHECK_EQUAL(0, r1.message4_count); CHECK_EQUAL(0, r1.message_unknown_count); } + + //************************************************************************* + TEST(message_router_with_overloaded_receive) + { + Router3 router; + + Message1 message1(router); + Message2 message2(router); + Message3 message3(router); + + router.receive(message1); + CHECK_TRUE(router.message1_received); + + router.receive(message2); + CHECK_TRUE(router.message2_received); + + router.receive(message3); + CHECK_TRUE(router.message3_received); + + CHECK_FALSE(router.unknown_message_received); + } }; } diff --git a/test/test_multi_span.cpp b/test/test_multi_span.cpp index 8658630b..19fbee95 100644 --- a/test/test_multi_span.cpp +++ b/test/test_multi_span.cpp @@ -28,7 +28,6 @@ SOFTWARE. #include "unit_test_framework.h" -#include "etl/multi_span.h" #include "etl/multi_span.h" #include @@ -37,15 +36,20 @@ SOFTWARE. namespace { - const int data1[] = { 0, 1, 2, 3 }; - const int data2[] = { 4, 5, 6 }; - const int data3[] = { 7 }; - const int data4[] = { 8, 9 }; + constexpr int Sentinal1 = 91; + constexpr int Sentinal2 = 92; + constexpr int Sentinal3 = 93; + constexpr int Sentinal4 = 94; - int data5[4]; - int data6[3]; - int data7[1]; - int data8[2]; + const std::array data1 = { 0, 1, 2, 3, Sentinal1 }; + const std::array data2 = { 4, 5, 6, Sentinal2 }; + const std::array data3 = { 7, Sentinal3 }; + const std::array data4 = { 8, 9, Sentinal4 }; + + int data5[] = { 0, 0, 0, 0 }; + int data6[] = { 0, 0, 0 }; + int data7[] = { 0 }; + int data8[] = { 0, 0 }; struct Data { @@ -58,18 +62,100 @@ namespace SUITE(test_multi_span) { //************************************************************************* - TEST(test_constructor) + TEST(test_construct_from_span_list) { std::vector> span_list = { - etl::span(data1), - etl::span(data2), + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), etl::span(), // Empty span. - etl::span(data3), - etl::span(data4) + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) }; - etl::multi_span ms_int(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span::span_list_type list(span_list.data(), span_list.size()); + + etl::multi_span ms_int(list); + + CHECK(!ms_int.empty()); + CHECK_EQUAL(5U, ms_int.size_spans()); + CHECK_EQUAL(40U, ms_int.size_bytes()); + CHECK_EQUAL(10U, ms_int.size()); + } + + //************************************************************************* + TEST(test_construct_from_container) + { + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span ms_int(span_list); + + CHECK(!ms_int.empty()); + CHECK_EQUAL(5U, ms_int.size_spans()); + CHECK_EQUAL(40U, ms_int.size_bytes()); + CHECK_EQUAL(10U, ms_int.size()); + } + + //************************************************************************* + TEST(test_construct_from_const_container) + { + const std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span ms_int(span_list); + + CHECK(!ms_int.empty()); + CHECK_EQUAL(5U, ms_int.size_spans()); + CHECK_EQUAL(40U, ms_int.size_bytes()); + CHECK_EQUAL(10U, ms_int.size()); + } + + //************************************************************************* + TEST(test_construct_from_iterators) + { + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span ms_int(span_list.data(), span_list.size()); + + CHECK(!ms_int.empty()); + CHECK_EQUAL(5U, ms_int.size_spans()); + CHECK_EQUAL(40U, ms_int.size_bytes()); + CHECK_EQUAL(10U, ms_int.size()); + } + + //************************************************************************* + TEST(test_construct_from_iterators_and_length) + { + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span ms_int(span_list.data(), span_list.size()); CHECK(!ms_int.empty()); CHECK_EQUAL(5U, ms_int.size_spans()); @@ -85,7 +171,7 @@ namespace etl::span() // Empty span. }; - etl::multi_span ms_int(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span ms_int(span_list.data(), span_list.size()); CHECK(ms_int.empty()); CHECK_EQUAL(1U, ms_int.size_spans()); @@ -113,14 +199,14 @@ namespace { std::vector> span_list = { - etl::span(data1), - etl::span(data2), + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), etl::span(), // Empty span. - etl::span(data3), - etl::span(data4) + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) }; - etl::multi_span ms_int(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span ms_int(span_list.data(), span_list.size()); std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::vector result; @@ -142,7 +228,7 @@ namespace etl::span(data8) }; - etl::multi_span ms_int(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span ms_int(span_list.data(), span_list.size()); std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -159,7 +245,7 @@ namespace etl::span(struct_data2) }; - etl::multi_span ms_data(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span ms_data(span_list.data(), span_list.size()); etl::multi_span::iterator itr = ms_data.begin(); CHECK_EQUAL(struct_data1[0].i, itr->i); @@ -187,7 +273,7 @@ namespace etl::span() }; - etl::multi_span ms_data(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span ms_data(span_list.data(), span_list.size()); etl::multi_span::iterator itr = ms_data.begin(); @@ -205,5 +291,475 @@ namespace ++itr; CHECK(ETL_NULLPTR == itr.operator->()); } + + //************************************************************************* + TEST(test_increment_iterator_read) + { + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin(); + + etl::multi_span::iterator ms_itr = ms_int.begin(); + etl::multi_span::iterator ms_end_itr = ms_int.end(); + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + ++ms_itr; + ++exp_itr; + } + } + + //************************************************************************* + TEST(test_increment_iterator_write) + { + std::vector> span_list = + { + etl::span(data5), + etl::span(data6), + etl::span(), // Empty span. + etl::span(data7), + etl::span(data8) + }; + + etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin(); + + etl::multi_span::iterator ms_itr = ms_int.begin(); + etl::multi_span::iterator ms_end_itr = ms_int.end(); + + while (ms_itr != ms_end_itr) + { + // Fill the multi span + *ms_itr++ = *exp_itr++; + } + + ms_itr = ms_int.begin(); + exp_itr = expected.begin(); + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + ++ms_itr; + ++exp_itr; + } + } + + //************************************************************************* + TEST(test_decrement_iterator_read) + { + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin() + expected.size() - 1; + + etl::multi_span::iterator ms_itr = ms_int.begin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i != 0) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_decrement_iterator_write) + { + std::vector> span_list = + { + etl::span(data5), + etl::span(data6), + etl::span(), // Empty span. + etl::span(data7), + etl::span(data8) + }; + + etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin() + expected.size() - 1; + + etl::multi_span::iterator ms_itr = ms_int.begin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + *ms_itr = *exp_itr; + + if (i != 0) + { + --ms_itr; + --exp_itr; + } + } + + ms_itr = ms_int.begin(); + std::advance(ms_itr, ms_int.size() - 1); + exp_itr = expected.begin() + expected.size() - 1; + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i != 0) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_increment_const_iterator_read) + { + const std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + const etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin(); + + etl::multi_span::const_iterator ms_itr = ms_int.begin(); + etl::multi_span::const_iterator ms_end_itr = ms_int.end(); + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + ++ms_itr; + ++exp_itr; + } + } + + //************************************************************************* + TEST(test_decrement_const_iterator_read) + { + const std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + const etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin() + expected.size() - 1; + + etl::multi_span::const_iterator ms_itr = ms_int.begin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i != 0) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_reverse_increment_iterator_read) + { + using span_type = etl::span; + using multi_span_type = etl::multi_span; + + std::vector span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin(); + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + multi_span_type::reverse_iterator ms_end_itr = ms_int.rend(); + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + ++ms_itr; + ++exp_itr; + } + } + + //************************************************************************* + TEST(test_reverse_increment_iterator_write) + { + using span_type = etl::span; + using multi_span_type = etl::multi_span; + + std::vector span_list = + { + span_type(data5), + span_type(data6), + span_type(), // Empty span. + span_type(data7), + span_type(data8) + }; + + multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin(); + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + multi_span_type::reverse_iterator ms_end_itr = ms_int.rend(); + + while (ms_itr != ms_end_itr) + { + // Fill the multi span + *ms_itr++ = *exp_itr++; + } + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*++exp_itr, *++ms_itr); + } + } + + //************************************************************************* + TEST(test_reverse_decrement_iterator_read) + { + using multi_span_type = etl::multi_span; + + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin() + expected.size() - 1; + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i < expected.size() - 1) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_reverse_decrement_iterator_write) + { + using span_type = etl::span; + using multi_span_type = etl::multi_span; + + std::vector> span_list = + { + span_type(data5), + span_type(data6), + span_type(), // Empty span. + span_type(data7), + span_type(data8) + }; + + multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin() + expected.size() - 1; + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + *ms_itr = *exp_itr; + + if (i < expected.size() - 1) + { + --ms_itr; + --exp_itr; + } + } + + ms_itr = ms_int.rbegin(); + std::advance(ms_itr, ms_int.size() - 1); + exp_itr = expected.rbegin() + expected.size() - 1; + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i < expected.size() - 1) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_const_reverse_increment_iterator_read) + { + using span_type = etl::span; + using multi_span_type = etl::multi_span; + + const std::vector span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + const multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin(); + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + multi_span_type::reverse_iterator ms_end_itr = ms_int.rend(); + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + ++ms_itr; + ++exp_itr; + } + } + + //************************************************************************* + TEST(test_const_reverse_decrement_iterator_read) + { + using multi_span_type = etl::multi_span; + + const std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + const multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin() + expected.size() - 1; + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i < expected.size() - 1) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_index_operator_read) + { + const std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + const etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(expected[i], ms_int[i]); + } + } + + //************************************************************************* + TEST(test_index_operator_write) + { + const std::vector> span_list = + { + etl::span(data5), + etl::span(data6), + etl::span(), // Empty span. + etl::span(data7), + etl::span(data8) + }; + + const etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + for (size_t i = 0; i < expected.size(); ++i) + { + ms_int[i] = expected[i]; + + CHECK_EQUAL(expected[i], ms_int[i]); + } + } }; } diff --git a/test/test_optional.cpp b/test/test_optional.cpp index 61e68672..87ee24c7 100644 --- a/test/test_optional.cpp +++ b/test/test_optional.cpp @@ -157,6 +157,16 @@ namespace CHECK_EQUAL(0, int(result.value())); } + //************************************************************************* + TEST(test_emplace_return) + { + etl::optional data; + + DataM* datam = &data.emplace(1U); + CHECK_EQUAL(datam, &data.value()); + CHECK(datam != nullptr); + } + //************************************************************************* TEST(test_moveable) { diff --git a/test/test_parameter_pack.cpp b/test/test_parameter_pack.cpp index 4c8adf8b..83aa08d6 100644 --- a/test/test_parameter_pack.cpp +++ b/test/test_parameter_pack.cpp @@ -34,7 +34,7 @@ namespace { using Pack = etl::parameter_pack; - SUITE(test_type_lookup) + SUITE(test_parameter_pack) { //************************************************************************* TEST(test_index_of_type) diff --git a/test/test_pool.cpp b/test/test_pool.cpp index 48f2881a..2866ab1d 100644 --- a/test/test_pool.cpp +++ b/test/test_pool.cpp @@ -288,6 +288,14 @@ namespace CHECK(pool.max_size() == 4U); } + //************************************************************************* + TEST(test_max_item_size) + { + etl::pool pool; + + CHECK(pool.max_item_size() == sizeof(Test_Data)); + } + //************************************************************************* TEST(test_size) { diff --git a/test/test_queue.cpp b/test/test_queue.cpp index ff966e3f..71d033f1 100644 --- a/test/test_queue.cpp +++ b/test/test_queue.cpp @@ -369,11 +369,17 @@ namespace { etl::queue queue; - queue.emplace(); - queue.emplace('b', 2, 2.3); - queue.emplace('c', 3, 3.4); - queue.emplace('d', 4, 4.5); - queue.emplace('e', 5, 5.6); + Item& item_a = queue.emplace(); + Item& item_b = queue.emplace('b', 2, 2.3); + Item& item_c = queue.emplace('c', 3, 3.4); + Item& item_d = queue.emplace('d', 4, 4.5); + Item& item_e = queue.emplace('e', 5, 5.6); + + CHECK(item_a == Item('a', 1, 1.2)); + CHECK(item_b == Item('b', 2, 2.3)); + CHECK(item_c == Item('c', 3, 3.4)); + CHECK(item_d == Item('d', 4, 4.5)); + CHECK(item_e == Item('e', 5, 5.6)); CHECK(queue.front() == Item('a', 1, 1.2)); queue.pop(); diff --git a/test/test_ratio.cpp b/test/test_ratio.cpp index fc7d5f06..784ff364 100644 --- a/test/test_ratio.cpp +++ b/test/test_ratio.cpp @@ -92,6 +92,12 @@ namespace CHECK_TRUE((std::is_same>::value)); CHECK_EQUAL(1, ratio::num); CHECK_EQUAL(2, ratio::den); + using r1 = etl::ratio<1, 2>; + using r2 = etl::ratio<2, 3>; + using r3 = etl::ratio_subtract; + + CHECK((etl::ratio_equal>::value)); + CHECK((!etl::ratio_equal>::value)); } //************************************************************************* @@ -104,6 +110,12 @@ namespace CHECK_TRUE((std::is_same>::value)); CHECK_EQUAL(1, ratio::num); CHECK_EQUAL(9, ratio::den); + using r1 = etl::ratio<1, 2>; + using r2 = etl::ratio<2, 3>; + using r3 = etl::ratio_multiply; + + CHECK((etl::ratio_equal>::value)); + CHECK((!etl::ratio_equal>::value)); } //************************************************************************* @@ -116,136 +128,103 @@ namespace CHECK_TRUE((std::is_same>::value)); CHECK_EQUAL(4, ratio::num); CHECK_EQUAL(1, ratio::den); + using r1 = etl::ratio<1, 2>; + using r2 = etl::ratio<2, 3>; + using r3 = etl::ratio_divide; + + CHECK((!etl::ratio_not_equal>::value)); + CHECK((etl::ratio_not_equal>::value)); } //************************************************************************* TEST(test_ratio_equal) { - using ratio1 = etl::ratio<5, 32>; - using ratio2 = etl::ratio<3, 16>; // 6/32 + using r1 = etl::ratio<1, 2>; + using r2 = etl::ratio<2, 3>; - CHECK_TRUE((etl::ratio_equal::value)); - CHECK_FALSE((etl::ratio_equal::value)); - CHECK_FALSE((etl::ratio_equal::value)); + CHECK((etl::ratio_equal::value)); + CHECK((!etl::ratio_equal::value)); + +#if ETL_USING_CPP14 + CHECK((etl::ratio_equal_v)); + CHECK((!etl::ratio_equal_v)); +#endif } //************************************************************************* TEST(test_ratio_not_equal) { - using ratio1 = etl::ratio<5, 32>; - using ratio2 = etl::ratio<3, 16>; // 6/32 + using r1 = etl::ratio<1, 2>; + using r2 = etl::ratio<2, 3>; - CHECK_FALSE((etl::ratio_not_equal::value)); - CHECK_TRUE((etl::ratio_not_equal::value)); - CHECK_TRUE((etl::ratio_not_equal::value)); + CHECK((!etl::ratio_not_equal::value)); + CHECK((etl::ratio_not_equal::value)); + +#if ETL_USING_CPP14 + CHECK((!etl::ratio_not_equal_v)); + CHECK((etl::ratio_not_equal_v)); +#endif } //************************************************************************* TEST(test_ratio_less) { - using ratio1 = etl::ratio<5, 32>; - using ratio2 = etl::ratio<3, 16>; // 6/32 + using r1 = etl::ratio<1, 2>; + using r2 = etl::ratio<2, 3>; - CHECK_FALSE((etl::ratio_less::value)); - CHECK_TRUE((etl::ratio_less::value)); - CHECK_FALSE((etl::ratio_less::value)); + CHECK((etl::ratio_less::value)); + CHECK((!etl::ratio_less::value)); + +#if ETL_USING_CPP14 + CHECK((etl::ratio_less_v)); + CHECK((!etl::ratio_less_v)); +#endif } //************************************************************************* TEST(test_ratio_less_equal) { - using ratio1 = etl::ratio<5, 32>; - using ratio2 = etl::ratio<3, 16>; // 6/32 + using r1 = etl::ratio<1, 2>; + using r2 = etl::ratio<2, 3>; - CHECK_TRUE((etl::ratio_less_equal::value)); - CHECK_TRUE((etl::ratio_less_equal::value)); - CHECK_FALSE((etl::ratio_less_equal::value)); + CHECK((etl::ratio_less_equal::value)); + CHECK((etl::ratio_less_equal::value)); + +#if ETL_USING_CPP14 + CHECK((etl::ratio_less_equal_v)); + CHECK((etl::ratio_less_equal_v)); +#endif } //************************************************************************* TEST(test_ratio_greater) { - using ratio1 = etl::ratio<5, 32>; - using ratio2 = etl::ratio<3, 16>; // 6/32 + using r1 = etl::ratio<4, 3>; + using r2 = etl::ratio<2, 3>; - CHECK_FALSE((etl::ratio_greater::value)); - CHECK_FALSE((etl::ratio_greater::value)); - CHECK_TRUE((etl::ratio_greater::value)); + CHECK((etl::ratio_greater::value)); + CHECK((!etl::ratio_greater::value)); + +#if ETL_USING_CPP14 + CHECK((etl::ratio_greater_v)); + CHECK((!etl::ratio_greater_v)); +#endif } //************************************************************************* TEST(test_ratio_greater_equal) { - using ratio1 = etl::ratio<5, 32>; - using ratio2 = etl::ratio<3, 16>; // 6/32 + using r1 = etl::ratio<4, 3>; + using r2 = etl::ratio<2, 3>; - CHECK_TRUE((etl::ratio_greater_equal::value)); - CHECK_FALSE((etl::ratio_greater_equal::value)); - CHECK_TRUE((etl::ratio_greater_equal::value)); - } + CHECK((etl::ratio_greater_equal::value)); + CHECK((etl::ratio_greater_equal::value)); - //************************************************************************* - TEST(test_predefined_ratios) - { -#if INT_MAX > INT32_MAX - CHECK_EQUAL(etl::atto::num, 1); - CHECK_EQUAL(etl::atto::den, 1000000000000000000); - CHECK_EQUAL(etl::femto::num, 1); - CHECK_EQUAL(etl::femto::den, 1000000000000000); - CHECK_EQUAL(etl::pico::num, 1); - CHECK_EQUAL(etl::pico::den, 1000000000000); +#if ETL_USING_CPP14 + CHECK((etl::ratio_greater_equal_v)); + CHECK((etl::ratio_greater_equal_v)); #endif -#if (INT_MAX >= INT32_MAX) - CHECK_EQUAL(etl::nano::num, 1); - CHECK_EQUAL(etl::nano::den, 1000000000); - CHECK_EQUAL(etl::micro::num, 1); - CHECK_EQUAL(etl::micro::den, 1000000); -#endif -#if (INT_MAX >= INT16_MAX) - CHECK_EQUAL(etl::milli::num, 1); - CHECK_EQUAL(etl::milli::den, 1000); - CHECK_EQUAL(etl::centi::num, 1); - CHECK_EQUAL(etl::centi::den, 100); - CHECK_EQUAL(etl::deci::num, 1); - CHECK_EQUAL(etl::deci::den, 10); - CHECK_EQUAL(etl::deca::num, 10); - CHECK_EQUAL(etl::deca::den, 1); - CHECK_EQUAL(etl::hecto::num, 100); - CHECK_EQUAL(etl::hecto::den, 1); - CHECK_EQUAL(etl::kilo::num, 1000); - CHECK_EQUAL(etl::kilo::den, 1); -#endif -#if (INT_MAX >= INT32_MAX) - CHECK_EQUAL(etl::mega::num, 1000000); - CHECK_EQUAL(etl::mega::den, 1); - CHECK_EQUAL(etl::giga::num, 1000000000); - CHECK_EQUAL(etl::giga::den, 1); -#endif - -#if INT_MAX > INT32_MAX - CHECK_EQUAL(etl::tera::num, 1000000000000); - CHECK_EQUAL(etl::tera::den, 1); - CHECK_EQUAL(etl::peta::num, 1000000000000000); - CHECK_EQUAL(etl::peta::den, 1); - CHECK_EQUAL(etl::exa::num, 1000000000000000000); - CHECK_EQUAL(etl::exa::den, 1); -#endif - - double expected_pi = 3.1415926535897931; - double actual_pi = double(etl::ratio_pi::num) / double(etl::ratio_pi::den); - CHECK_CLOSE(expected_pi, actual_pi, 0.0000003); - - double expected_root_2 = 1.414213562373095; - double actual_root_2 = double(etl::ratio_root2::num) / double(etl::ratio_root2::den); - CHECK_CLOSE(expected_root_2, actual_root_2, 0.00002); - - double expected_1_over_root_2 = 1.0 / 1.414213562373095; - double actual_1_over_root_2 = double(etl::ratio_1_over_root2::num) / double(etl::ratio_1_over_root2::den); - CHECK_CLOSE(expected_1_over_root_2, actual_1_over_root_2, 0.000007); - - double expected_e = 2.7182818284590451; - double actual_e = double(etl::ratio_e::num) / double(etl::ratio_e::den); - CHECK_CLOSE(expected_e, actual_e, 0.0004); } }; + } diff --git a/test/test_rms.cpp b/test/test_rms.cpp index cbc19884..39ae6753 100644 --- a/test/test_rms.cpp +++ b/test/test_rms.cpp @@ -34,7 +34,7 @@ SOFTWARE. namespace { - std::array input_c + std::array input_c { // Sawtooth wave 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -8, -7, -6, -5, -4, -3, -2, -1 @@ -52,7 +52,7 @@ namespace //************************************************************************* TEST(test_char_rms) { - etl::rms rms(input_c.begin(), input_c.end()); + etl::rms rms(input_c.begin(), input_c.end()); double result = rms.get_rms(); CHECK_CLOSE(5.21, result, 0.05); diff --git a/test/test_scaled_rounding.cpp b/test/test_scaled_rounding.cpp index 5099a20e..518eada2 100644 --- a/test/test_scaled_rounding.cpp +++ b/test/test_scaled_rounding.cpp @@ -34,312 +34,1814 @@ SOFTWARE. namespace { - std::array source = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + std::array source = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; SUITE(test_scaled_rounding) { //************************************************************************* TEST(round_ceiling_scaled) { - std::array expected = { 60, 60, 60, 70, 70, 70, -50, -50, -50, -60, -60, -60 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60 }; - CHECK_EQUAL(expected[0], etl::round_ceiling_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_ceiling_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_ceiling_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_ceiling_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_ceiling_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_ceiling_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_ceiling_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_ceiling_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_ceiling_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_ceiling_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_ceiling_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_ceiling_scaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_ceiling_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_ceiling_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_ceiling_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_ceiling_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_ceiling_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_ceiling_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_ceiling_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_ceiling_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_ceiling_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_ceiling_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_ceiling_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_ceiling_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_ceiling_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_ceiling_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_ceiling_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_ceiling_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_ceiling_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_ceiling_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_ceiling_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_ceiling_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_ceiling_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_ceiling_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_ceiling_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_ceiling_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_ceiling_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_ceiling_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_ceiling_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_ceiling_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_ceiling_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_ceiling_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_ceiling_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_ceiling_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_ceiling_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_ceiling_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_ceiling_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_ceiling_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_ceiling_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_ceiling_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_ceiling_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_ceiling_scaled(source[39])); } //************************************************************************* TEST(round_ceiling_unscaled) { - std::array expected = { 6, 6, 6, 7, 7, 7, -5, -5, -5, -6, -6, -6 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6 }; - CHECK_EQUAL(expected[0], etl::round_ceiling_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_ceiling_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_ceiling_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_ceiling_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_ceiling_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_ceiling_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_ceiling_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_ceiling_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_ceiling_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_ceiling_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_ceiling_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_ceiling_unscaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_ceiling_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_ceiling_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_ceiling_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_ceiling_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_ceiling_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_ceiling_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_ceiling_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_ceiling_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_ceiling_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_ceiling_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_ceiling_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_ceiling_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_ceiling_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_ceiling_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_ceiling_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_ceiling_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_ceiling_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_ceiling_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_ceiling_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_ceiling_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_ceiling_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_ceiling_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_ceiling_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_ceiling_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_ceiling_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_ceiling_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_ceiling_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_ceiling_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_ceiling_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_ceiling_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_ceiling_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_ceiling_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_ceiling_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_ceiling_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_ceiling_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_ceiling_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_ceiling_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_ceiling_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_ceiling_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_ceiling_unscaled(source[39])); + } + + //************************************************************************* + TEST(round_ceiling_scaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_ceiling_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_ceiling_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_ceiling_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_ceiling_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_ceiling_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_ceiling_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_ceiling_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_ceiling_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_ceiling_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_ceiling_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_ceiling_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_ceiling_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_ceiling_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_ceiling_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_ceiling_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_ceiling_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_ceiling_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_ceiling_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_ceiling_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_ceiling_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_ceiling_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_ceiling_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_ceiling_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_ceiling_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_ceiling_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_ceiling_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_ceiling_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_ceiling_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_ceiling_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_ceiling_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_ceiling_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_ceiling_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_ceiling_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_ceiling_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_ceiling_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_ceiling_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_ceiling_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_ceiling_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_ceiling_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_ceiling_scaled(source[39])); + } + + //************************************************************************* + TEST(round_ceiling_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_ceiling_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_ceiling_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_ceiling_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_ceiling_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_ceiling_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_ceiling_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_ceiling_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_ceiling_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_ceiling_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_ceiling_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_ceiling_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_ceiling_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_ceiling_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_ceiling_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_ceiling_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_ceiling_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_ceiling_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_ceiling_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_ceiling_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_ceiling_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_ceiling_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_ceiling_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_ceiling_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_ceiling_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_ceiling_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_ceiling_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_ceiling_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_ceiling_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_ceiling_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_ceiling_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_ceiling_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_ceiling_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_ceiling_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_ceiling_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_ceiling_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_ceiling_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_ceiling_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_ceiling_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_ceiling_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_ceiling_unscaled(source[39])); } //************************************************************************* TEST(round_floor_scaled) { - std::array expected = { 50, 50, 50, 60, 60, 60, -60, -60, -60, -70, -70, -70 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70, -70, -70, -70, -70, -70 }; - CHECK_EQUAL(expected[0], etl::round_floor_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_floor_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_floor_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_floor_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_floor_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_floor_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_floor_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_floor_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_floor_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_floor_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_floor_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_floor_scaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_floor_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_floor_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_floor_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_floor_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_floor_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_floor_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_floor_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_floor_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_floor_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_floor_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_floor_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_floor_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_floor_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_floor_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_floor_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_floor_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_floor_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_floor_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_floor_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_floor_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_floor_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_floor_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_floor_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_floor_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_floor_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_floor_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_floor_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_floor_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_floor_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_floor_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_floor_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_floor_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_floor_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_floor_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_floor_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_floor_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_floor_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_floor_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_floor_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_floor_scaled(source[39])); } //************************************************************************* TEST(round_floor_unscaled) { - std::array expected = { 5, 5, 5, 6, 6, 6, -6, -6, -6, -7, -7, -7 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7, -7, -7, -7, -7, -7 }; - CHECK_EQUAL(expected[0], etl::round_floor_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_floor_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_floor_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_floor_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_floor_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_floor_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_floor_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_floor_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_floor_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_floor_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_floor_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_floor_unscaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_floor_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_floor_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_floor_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_floor_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_floor_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_floor_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_floor_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_floor_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_floor_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_floor_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_floor_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_floor_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_floor_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_floor_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_floor_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_floor_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_floor_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_floor_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_floor_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_floor_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_floor_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_floor_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_floor_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_floor_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_floor_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_floor_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_floor_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_floor_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_floor_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_floor_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_floor_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_floor_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_floor_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_floor_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_floor_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_floor_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_floor_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_floor_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_floor_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_floor_unscaled(source[39])); + } + + //************************************************************************* + TEST(round_floor_scaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_floor_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_floor_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_floor_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_floor_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_floor_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_floor_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_floor_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_floor_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_floor_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_floor_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_floor_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_floor_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_floor_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_floor_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_floor_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_floor_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_floor_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_floor_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_floor_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_floor_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_floor_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_floor_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_floor_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_floor_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_floor_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_floor_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_floor_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_floor_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_floor_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_floor_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_floor_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_floor_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_floor_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_floor_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_floor_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_floor_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_floor_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_floor_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_floor_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_floor_scaled(source[39])); + } + + //************************************************************************* + TEST(round_floor_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_floor_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_floor_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_floor_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_floor_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_floor_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_floor_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_floor_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_floor_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_floor_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_floor_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_floor_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_floor_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_floor_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_floor_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_floor_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_floor_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_floor_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_floor_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_floor_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_floor_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_floor_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_floor_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_floor_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_floor_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_floor_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_floor_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_floor_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_floor_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_floor_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_floor_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_floor_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_floor_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_floor_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_floor_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_floor_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_floor_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_floor_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_floor_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_floor_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_floor_unscaled(source[39])); } //************************************************************************* TEST(round_half_up_scaled) { - std::array expected = { 50, 60, 60, 60, 70, 70, -50, -60, -60, -60, -70, -70 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70, -70 }; - CHECK_EQUAL(expected[0], etl::round_half_up_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_up_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_up_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_up_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_up_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_up_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_up_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_up_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_up_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_up_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_up_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_up_scaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_up_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_up_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_up_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_up_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_up_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_up_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_up_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_up_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_up_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_up_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_up_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_up_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_up_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_up_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_up_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_up_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_up_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_up_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_up_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_up_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_up_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_up_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_up_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_up_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_up_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_up_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_up_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_up_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_up_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_up_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_up_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_up_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_up_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_up_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_up_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_up_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_up_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_up_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_up_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_up_scaled(source[39])); } //************************************************************************* TEST(round_half_up_unscaled) { - std::array expected = { 5, 6, 6, 6, 7, 7, -5, -6, -6, -6, -7, -7 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7, -7 }; - CHECK_EQUAL(expected[0], etl::round_half_up_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_up_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_up_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_up_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_up_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_up_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_up_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_up_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_up_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_up_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_up_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_up_unscaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_up_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_up_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_up_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_up_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_up_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_up_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_up_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_up_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_up_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_up_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_up_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_up_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_up_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_up_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_up_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_up_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_up_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_up_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_up_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_up_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_up_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_up_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_up_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_up_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_up_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_up_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_up_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_up_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_up_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_up_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_up_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_up_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_up_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_up_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_up_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_up_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_up_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_up_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_up_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_up_unscaled(source[39])); + } + + //************************************************************************* + TEST(round_half_up_scaled_with_scaling_of_2) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 52, 52, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -52, -52, -54, -54, -56, -56, -58, -58, -60, -60, -62, -62, -64, -64, -66, -66, -68, -68, -70 }; + + const size_t Scale = 2; + + CHECK_EQUAL(expected[0], etl::round_half_up_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_up_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_up_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_up_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_up_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_up_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_up_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_up_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_up_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_up_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_up_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_up_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_up_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_up_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_up_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_up_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_up_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_up_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_up_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_up_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_up_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_up_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_up_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_up_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_up_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_up_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_up_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_up_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_up_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_up_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_up_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_up_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_up_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_up_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_up_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_up_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_up_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_up_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_up_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_up_scaled(source[39])); + } + + //************************************************************************* + TEST(round_half_up_unscaled_with_scaling_of_2) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -25, -26, -26, -27, -27, -28, -28, -29, -29, -30, -30, -31, -31, -32, -32, -33, -33, -34, -34, -35 }; + + const size_t Scale = 2; + + CHECK_EQUAL(expected[0], etl::round_half_up_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_up_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_up_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_up_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_up_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_up_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_up_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_up_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_up_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_up_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_up_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_up_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_up_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_up_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_up_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_up_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_up_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_up_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_up_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_up_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_up_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_up_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_up_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_up_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_up_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_up_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_up_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_up_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_up_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_up_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_up_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_up_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_up_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_up_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_up_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_up_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_up_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_up_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_up_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_up_unscaled(source[39])); } //************************************************************************* TEST(round_half_down_scaled) { - std::array expected = { 50, 50, 60, 60, 60, 70, -50, -50, -60, -60, -60, -70 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70 }; - CHECK_EQUAL(expected[0], etl::round_half_down_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_down_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_down_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_down_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_down_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_down_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_down_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_down_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_down_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_down_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_down_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_down_scaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_down_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_down_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_down_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_down_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_down_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_down_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_down_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_down_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_down_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_down_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_down_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_down_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_down_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_down_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_down_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_down_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_down_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_down_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_down_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_down_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_down_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_down_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_down_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_down_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_down_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_down_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_down_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_down_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_down_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_down_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_down_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_down_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_down_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_down_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_down_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_down_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_down_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_down_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_down_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_down_scaled(source[39])); + } + + ////************************************************************************* + TEST(round_half_down_unscaled) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_down_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_down_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_down_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_down_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_down_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_down_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_down_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_down_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_down_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_down_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_down_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_down_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_down_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_down_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_down_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_down_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_down_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_down_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_down_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_down_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_down_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_down_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_down_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_down_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_down_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_down_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_down_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_down_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_down_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_down_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_down_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_down_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_down_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_down_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_down_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_down_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_down_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_down_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_down_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_down_unscaled(source[39])); } //************************************************************************* - TEST(round_half_down_unscaled) + TEST(round_half_down_scaled_with_scaling_of_1) { - std::array expected = { 5, 5, 6, 6, 6, 7, -5, -5, -6, -6, -6, -7 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; - CHECK_EQUAL(expected[0], etl::round_half_down_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_down_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_down_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_down_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_down_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_down_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_down_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_down_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_down_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_down_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_down_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_down_unscaled<10>(source[11])); + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_half_down_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_down_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_down_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_down_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_down_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_down_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_down_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_down_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_down_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_down_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_down_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_down_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_down_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_down_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_down_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_down_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_down_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_down_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_down_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_down_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_down_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_down_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_down_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_down_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_down_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_down_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_down_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_down_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_down_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_down_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_down_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_down_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_down_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_down_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_down_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_down_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_down_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_down_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_down_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_down_scaled(source[39])); + } + + //************************************************************************* + TEST(round_half_down_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_half_down_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_down_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_down_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_down_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_down_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_down_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_down_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_down_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_down_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_down_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_down_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_down_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_down_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_down_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_down_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_down_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_down_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_down_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_down_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_down_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_down_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_down_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_down_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_down_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_down_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_down_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_down_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_down_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_down_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_down_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_down_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_down_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_down_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_down_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_down_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_down_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_down_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_down_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_down_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_down_unscaled(source[39])); } //************************************************************************* TEST(round_zero_scaled) { - std::array expected = { 50, 50, 50, 60, 60, 60, -50, -50, -50, -60, -60, -60 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60 }; - CHECK_EQUAL(expected[0], etl::round_zero_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_zero_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_zero_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_zero_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_zero_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_zero_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_zero_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_zero_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_zero_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_zero_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_zero_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_zero_scaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_zero_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_zero_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_zero_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_zero_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_zero_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_zero_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_zero_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_zero_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_zero_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_zero_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_zero_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_zero_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_zero_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_zero_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_zero_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_zero_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_zero_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_zero_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_zero_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_zero_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_zero_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_zero_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_zero_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_zero_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_zero_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_zero_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_zero_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_zero_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_zero_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_zero_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_zero_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_zero_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_zero_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_zero_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_zero_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_zero_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_zero_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_zero_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_zero_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_zero_scaled(source[39])); } //************************************************************************* TEST(round_zero_unscaled) { - std::array expected = { 5, 5, 5, 6, 6, 6, -5, -5, -5, -6, -6, -6 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6 }; - CHECK_EQUAL(expected[0], etl::round_zero_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_zero_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_zero_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_zero_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_zero_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_zero_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_zero_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_zero_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_zero_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_zero_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_zero_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_zero_unscaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_zero_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_zero_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_zero_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_zero_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_zero_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_zero_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_zero_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_zero_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_zero_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_zero_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_zero_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_zero_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_zero_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_zero_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_zero_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_zero_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_zero_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_zero_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_zero_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_zero_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_zero_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_zero_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_zero_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_zero_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_zero_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_zero_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_zero_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_zero_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_zero_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_zero_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_zero_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_zero_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_zero_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_zero_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_zero_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_zero_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_zero_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_zero_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_zero_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_zero_unscaled(source[39])); + } + + //************************************************************************* + TEST(round_zero_scaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_zero_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_zero_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_zero_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_zero_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_zero_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_zero_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_zero_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_zero_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_zero_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_zero_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_zero_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_zero_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_zero_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_zero_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_zero_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_zero_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_zero_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_zero_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_zero_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_zero_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_zero_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_zero_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_zero_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_zero_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_zero_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_zero_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_zero_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_zero_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_zero_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_zero_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_zero_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_zero_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_zero_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_zero_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_zero_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_zero_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_zero_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_zero_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_zero_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_zero_scaled(source[39])); + } + + //************************************************************************* + TEST(round_zero_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_zero_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_zero_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_zero_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_zero_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_zero_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_zero_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_zero_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_zero_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_zero_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_zero_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_zero_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_zero_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_zero_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_zero_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_zero_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_zero_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_zero_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_zero_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_zero_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_zero_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_zero_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_zero_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_zero_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_zero_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_zero_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_zero_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_zero_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_zero_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_zero_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_zero_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_zero_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_zero_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_zero_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_zero_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_zero_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_zero_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_zero_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_zero_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_zero_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_zero_scaled(source[39])); } //************************************************************************* TEST(round_infinity_scaled) { - std::array expected = { 60, 60, 60, 70, 70, 70, -60, -60, -60, -70, -70, -70 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70, -70, -70, -70, -70, -70 }; - CHECK_EQUAL(expected[0], etl::round_infinity_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_infinity_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_infinity_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_infinity_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_infinity_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_infinity_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_infinity_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_infinity_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_infinity_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_infinity_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_infinity_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_infinity_scaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_infinity_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_infinity_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_infinity_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_infinity_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_infinity_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_infinity_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_infinity_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_infinity_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_infinity_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_infinity_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_infinity_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_infinity_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_infinity_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_infinity_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_infinity_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_infinity_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_infinity_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_infinity_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_infinity_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_infinity_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_infinity_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_infinity_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_infinity_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_infinity_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_infinity_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_infinity_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_infinity_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_infinity_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_infinity_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_infinity_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_infinity_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_infinity_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_infinity_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_infinity_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_infinity_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_infinity_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_infinity_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_infinity_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_infinity_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_infinity_scaled(source[39])); } //************************************************************************* TEST(round_infinity_unscaled) { - std::array expected = { 6, 6, 6, 7, 7, 7, -6, -6, -6, -7, -7, -7 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7, -7, -7, -7, -7, -7 }; - CHECK_EQUAL(expected[0], etl::round_infinity_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_infinity_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_infinity_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_infinity_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_infinity_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_infinity_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_infinity_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_infinity_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_infinity_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_infinity_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_infinity_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_infinity_unscaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_infinity_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_infinity_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_infinity_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_infinity_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_infinity_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_infinity_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_infinity_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_infinity_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_infinity_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_infinity_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_infinity_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_infinity_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_infinity_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_infinity_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_infinity_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_infinity_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_infinity_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_infinity_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_infinity_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_infinity_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_infinity_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_infinity_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_infinity_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_infinity_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_infinity_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_infinity_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_infinity_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_infinity_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_infinity_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_infinity_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_infinity_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_infinity_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_infinity_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_infinity_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_infinity_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_infinity_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_infinity_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_infinity_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_infinity_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_infinity_unscaled(source[39])); + } + + //************************************************************************* + TEST(round_infinity_scaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_infinity_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_infinity_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_infinity_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_infinity_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_infinity_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_infinity_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_infinity_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_infinity_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_infinity_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_infinity_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_infinity_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_infinity_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_infinity_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_infinity_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_infinity_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_infinity_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_infinity_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_infinity_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_infinity_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_infinity_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_infinity_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_infinity_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_infinity_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_infinity_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_infinity_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_infinity_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_infinity_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_infinity_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_infinity_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_infinity_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_infinity_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_infinity_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_infinity_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_infinity_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_infinity_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_infinity_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_infinity_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_infinity_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_infinity_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_infinity_scaled(source[39])); + } + + //************************************************************************* + TEST(round_infinity_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_infinity_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_infinity_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_infinity_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_infinity_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_infinity_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_infinity_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_infinity_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_infinity_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_infinity_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_infinity_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_infinity_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_infinity_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_infinity_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_infinity_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_infinity_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_infinity_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_infinity_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_infinity_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_infinity_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_infinity_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_infinity_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_infinity_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_infinity_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_infinity_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_infinity_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_infinity_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_infinity_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_infinity_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_infinity_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_infinity_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_infinity_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_infinity_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_infinity_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_infinity_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_infinity_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_infinity_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_infinity_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_infinity_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_infinity_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_infinity_scaled(source[39])); } //************************************************************************* TEST(round_half_even_scaled) { - std::array expected = { 50, 60, 60, 60, 60, 70, -50, -60, -60, -60, -60, -70 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70 }; - CHECK_EQUAL(expected[0], etl::round_half_even_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_even_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_even_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_even_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_even_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_even_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_even_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_even_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_even_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_even_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_even_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_even_scaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_even_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_even_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_even_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_even_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_even_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_even_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_even_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_even_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_even_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_even_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_even_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_even_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_even_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_even_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_even_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_even_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_even_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_even_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_even_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_even_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_even_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_even_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_even_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_even_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_even_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_even_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_even_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_even_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_even_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_even_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_even_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_even_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_even_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_even_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_even_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_even_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_even_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_even_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_even_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_even_scaled(source[39])); } //************************************************************************* TEST(round_half_even_unscaled) { - std::array expected = { 5, 6, 6, 6, 6, 7, -5, -6, -6, -6, -6, -7 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7 }; - CHECK_EQUAL(expected[0], etl::round_half_even_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_even_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_even_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_even_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_even_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_even_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_even_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_even_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_even_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_even_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_even_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_even_unscaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_even_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_even_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_even_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_even_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_even_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_even_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_even_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_even_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_even_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_even_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_even_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_even_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_even_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_even_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_even_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_even_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_even_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_even_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_even_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_even_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_even_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_even_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_even_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_even_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_even_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_even_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_even_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_even_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_even_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_even_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_even_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_even_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_even_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_even_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_even_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_even_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_even_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_even_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_even_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_even_unscaled(source[39])); + } + + //************************************************************************* + TEST(round_half_even_scaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_half_even_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_even_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_even_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_even_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_even_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_even_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_even_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_even_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_even_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_even_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_even_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_even_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_even_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_even_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_even_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_even_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_even_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_even_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_even_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_even_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_even_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_even_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_even_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_even_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_even_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_even_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_even_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_even_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_even_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_even_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_even_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_even_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_even_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_even_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_even_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_even_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_even_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_even_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_even_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_even_scaled(source[39])); + } + + //************************************************************************* + TEST(round_half_even_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_half_even_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_even_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_even_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_even_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_even_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_even_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_even_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_even_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_even_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_even_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_even_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_even_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_even_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_even_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_even_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_even_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_even_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_even_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_even_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_even_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_even_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_even_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_even_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_even_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_even_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_even_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_even_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_even_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_even_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_even_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_even_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_even_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_even_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_even_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_even_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_even_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_even_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_even_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_even_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_even_unscaled(source[39])); } //************************************************************************* TEST(round_half_odd_scaled) { - std::array expected = { 50, 50, 60, 60, 70, 70, -50, -50, -60, -60, -70, -70 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70, -70 }; - CHECK_EQUAL(expected[0], etl::round_half_odd_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_odd_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_odd_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_odd_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_odd_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_odd_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_odd_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_odd_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_odd_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_odd_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_odd_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_odd_scaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_odd_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_odd_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_odd_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_odd_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_odd_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_odd_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_odd_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_odd_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_odd_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_odd_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_odd_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_odd_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_odd_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_odd_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_odd_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_odd_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_odd_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_odd_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_odd_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_odd_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_odd_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_odd_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_odd_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_odd_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_odd_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_odd_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_odd_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_odd_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_odd_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_odd_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_odd_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_odd_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_odd_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_odd_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_odd_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_odd_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_odd_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_odd_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_odd_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_odd_scaled(source[39])); } //************************************************************************* TEST(round_half_odd_unscaled) { - std::array expected = { 5, 5, 6, 6, 7, 7, -5, -5, -6, -6, -7, -7 }; + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7, -7 }; - CHECK_EQUAL(expected[0], etl::round_half_odd_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_odd_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_odd_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_odd_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_odd_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_odd_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_odd_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_odd_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_odd_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_odd_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_odd_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_odd_unscaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_odd_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_odd_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_odd_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_odd_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_odd_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_odd_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_odd_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_odd_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_odd_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_odd_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_odd_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_odd_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_odd_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_odd_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_odd_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_odd_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_odd_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_odd_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_odd_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_odd_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_odd_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_odd_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_odd_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_odd_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_odd_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_odd_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_odd_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_odd_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_odd_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_odd_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_odd_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_odd_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_odd_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_odd_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_odd_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_odd_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_odd_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_odd_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_odd_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_odd_unscaled(source[39])); } + + //************************************************************************* + TEST(round_half_odd_scaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_half_odd_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_odd_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_odd_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_odd_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_odd_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_odd_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_odd_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_odd_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_odd_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_odd_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_odd_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_odd_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_odd_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_odd_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_odd_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_odd_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_odd_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_odd_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_odd_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_odd_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_odd_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_odd_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_odd_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_odd_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_odd_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_odd_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_odd_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_odd_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_odd_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_odd_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_odd_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_odd_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_odd_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_odd_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_odd_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_odd_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_odd_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_odd_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_odd_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_odd_scaled(source[39])); + } + + //************************************************************************* + TEST(round_half_odd_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_half_odd_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_odd_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_odd_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_odd_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_odd_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_odd_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_odd_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_odd_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_odd_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_odd_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_odd_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_odd_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_odd_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_odd_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_odd_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_odd_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_odd_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_odd_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_odd_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_odd_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_odd_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_odd_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_odd_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_odd_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_odd_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_odd_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_odd_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_odd_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_odd_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_odd_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_odd_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_odd_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_odd_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_odd_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_odd_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_odd_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_odd_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_odd_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_odd_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_odd_unscaled(source[39])); + } + +#if ETL_USING_CPP14 + //************************************************************************* + TEST(round_constexpr_scaled_rounding) + { + constexpr int round_ceiling = etl::round_ceiling_scaled<10>(10); + constexpr int round_floor = etl::round_floor_scaled<10>(10); + constexpr int round_half_down_scaled = etl::round_half_down_scaled<10>(10); + constexpr int round_half_even_scaled = etl::round_half_even_scaled<10>(10); + constexpr int round_half_odd_scaled = etl::round_half_odd_scaled<10>(10); + constexpr int round_half_up_scaled = etl::round_half_up_scaled<10>(10); + constexpr int round_infinity = etl::round_infinity_scaled<10>(10); + constexpr int round_zero = etl::round_zero_scaled<10>(10); + + // Ensure that the value are constexpr. + std::array a{}; + std::array b{}; + std::array c{}; + std::array d{}; + std::array e{}; + std::array f{}; + std::array g{}; + std::array h{}; + + (void)a; + (void)b; + (void)c; + (void)d; + (void)e; + (void)f; + (void)g; + (void)h; + + CHECK_EQUAL(10, round_ceiling); + CHECK_EQUAL(10, round_floor); + CHECK_EQUAL(10, round_half_down_scaled); + CHECK_EQUAL(10, round_half_even_scaled); + CHECK_EQUAL(10, round_half_odd_scaled); + CHECK_EQUAL(10, round_half_up_scaled); + CHECK_EQUAL(10, round_infinity); + CHECK_EQUAL(10, round_zero); + } +#endif }; } diff --git a/test/test_singleton_base.cpp b/test/test_singleton_base.cpp new file mode 100644 index 00000000..fec07c59 --- /dev/null +++ b/test/test_singleton_base.cpp @@ -0,0 +1,104 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2022 John Wellbelove +Copyright(c) 2024 BMW AG + +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/singleton_base.h" + +#include +#include + +class Test_Singleton: public etl::singleton_base +{ +public: + + Test_Singleton(int i_, std::string text_) + : ::etl::singleton_base(*this) + , i(i_) + , text(text_) + { + } + + void Increment() + { + ++i; + text += "*"; + } + + int i; + std::string text; +}; + +namespace +{ + SUITE(test_singleton) + { + //************************************************************************* + TEST(test1) + { + CHECK(!Test_Singleton::is_valid()); + CHECK_THROW(Test_Singleton::instance(), etl::singleton_base_not_created); + + { + Test_Singleton singleton(1, "Start:"); + CHECK(Test_Singleton::is_valid()); + + Test_Singleton& ts = Test_Singleton::instance(); + + CHECK_EQUAL(1, ts.i); + CHECK_EQUAL("Start:", ts.text); + + ts.Increment(); + + CHECK_EQUAL(2, ts.i); + CHECK_EQUAL("Start:*", ts.text); + + Test_Singleton* pts = &Test_Singleton::instance(); + + CHECK_EQUAL(2, ts.i); + CHECK_EQUAL(2, pts->i); + CHECK_EQUAL("Start:*", ts.text); + CHECK_EQUAL("Start:*", pts->text); + + pts->Increment(); + + CHECK_EQUAL(3, ts.i); + CHECK_EQUAL(3, pts->i); + CHECK_EQUAL("Start:**", ts.text); + CHECK_EQUAL("Start:**", pts->text); + + CHECK_THROW(Test_Singleton(2, "XYZ"), etl::singleton_base_already_created); + } + + CHECK(!Test_Singleton::is_valid()); + CHECK_THROW(Test_Singleton::instance(), etl::singleton_base_not_created); + } + } +} + diff --git a/test/test_span_dynamic_extent.cpp b/test/test_span_dynamic_extent.cpp index 3d7df1ec..ee85f843 100644 --- a/test/test_span_dynamic_extent.cpp +++ b/test/test_span_dynamic_extent.cpp @@ -30,6 +30,7 @@ SOFTWARE. #include "etl/span.h" #include "etl/array.h" +#include "etl/unaligned_type.h" #include #include @@ -409,15 +410,19 @@ namespace View view(etldata.begin(), etldata.end()); CView cview(etldata.begin(), etldata.end()); + CHECK_EQUAL(etldata.cbegin(), view.cbegin()); CHECK_EQUAL(etldata.begin(), view.begin()); CHECK_EQUAL(etldata.begin(), cview.begin()); + CHECK_EQUAL(etldata.cend(), view.crbegin().base()); CHECK_EQUAL(etldata.end(), view.rbegin().base()); CHECK_EQUAL(etldata.end(), cview.rbegin().base()); + CHECK_EQUAL(etldata.cend(), view.cend()); CHECK_EQUAL(etldata.end(), view.end()); CHECK_EQUAL(etldata.end(), cview.end()); + CHECK_EQUAL(etldata.cbegin(), view.crend().base()); CHECK_EQUAL(etldata.begin(), view.rend().base()); CHECK_EQUAL(etldata.begin(), cview.rend().base()); } @@ -445,6 +450,22 @@ namespace CHECK_EQUAL(etldata.data(), cview.data()); } + //************************************************************************* + TEST(test_at) + { + View view(etldata.begin(), etldata.end()); + CView cview(etldata.begin(), etldata.end()); + + for (size_t i = 0UL; i < etldata.size(); ++i) + { + CHECK_EQUAL(etldata.at(i), view.at(i)); + CHECK_EQUAL(etldata.at(i), cview.at(i)); + } + + CHECK_THROW({ int d = view.at(view.size()); (void)d; }, etl::array_out_of_range); + CHECK_THROW({ int d = cview.at(cview.size()); (void)d; }, etl::array_out_of_range); + } + //************************************************************************* TEST(test_index_operator) { @@ -1205,6 +1226,150 @@ namespace } } + //************************************************************************* + TEST(test_make_span_container) + { + { + auto s = etl::make_span(etldata); + + CHECK_EQUAL(s.size(), 10); + View view(etldata); + CHECK_TRUE(etl::equal(s, view)); + } + { + auto s = etl::make_span(cetldata); + + CHECK_EQUAL(s.size(), 10); + View view(etldata); + CHECK_TRUE(etl::equal(s, view)); + } + } + + //************************************************************************* + TEST(test_advance) + { + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + CHECK_EQUAL(data0.size(), 5); + data0.advance(1); + CHECK_EQUAL(data0.size(), 4); + CHECK_EQUAL(data0[0], 0x02); + data0.advance(2); + CHECK_EQUAL(data0.size(), 2); + CHECK_EQUAL(data0[0], 0x04); + data0.advance(1); + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data0[0], 0x05); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + } + { + const uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + CHECK_EQUAL(data0.size(), 5); + data0.advance(1); + CHECK_EQUAL(data0.size(), 4); + CHECK_EQUAL(data0[0], 0x02); + data0.advance(2); + CHECK_EQUAL(data0.size(), 2); + CHECK_EQUAL(data0[0], 0x04); + data0.advance(1); + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data0[0], 0x05); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + data0.advance(100); + CHECK_EQUAL(data0.size(), 0); + } + } + + //************************************************************************* + TEST(test_reinterpret_as) + { + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + etl::span data1 = data0.reinterpret_as(); + + CHECK_EQUAL(data1.size(), 2); + CHECK(data1[0] == 0x102); + CHECK(data1[1] == 0x304); + } + { + uint32_t data[] = { 0x01020304 }; + etl::span data0 = data; + etl::span data1 = data0.reinterpret_as(); + data1 = data1.first(3); + etl::span data2 = data1.reinterpret_as(); + CHECK_EQUAL(data2.size(), 0); + } + { + uint32_t data[] = { 0x01020304, 0x06070809 }; + etl::span data0 = data; + etl::span data1 = data0.reinterpret_as(); + data1 = data1.first(6); + etl::span data2 = data1.reinterpret_as(); + CHECK_EQUAL(data2.size(), 1); + + auto it = data2.begin(); + CHECK_NOT_EQUAL(it, data2.end()); + ++it; + CHECK_EQUAL(it, data2.end()); + } + } + + //************************************************************************* + TEST(test_reinterpret_as_aligned) + { + uint32_t data[] = { 0x01020304, 0x020406080, 0x03400560}; + etl::span data0 = data; + CHECK_EQUAL(data0.size(), 3); + + etl::span data1 = data0.reinterpret_as(); + CHECK_EQUAL(data1.size(), 12); + + etl::span data2 = data1.subspan(2).reinterpret_as(); + CHECK_EQUAL(data2.size(), 5); + + CHECK_THROW(data2 = data1.subspan(1).reinterpret_as(), etl::span_alignment_exception); + } + + //************************************************************************* + TEST(test_copy) + { + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + uint8_t dst[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + etl::span data0 = src; + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + + data1 = data1.subspan(1); + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + + data1 = data1.subspan(1); + + CHECK_EQUAL(etl::copy(data0, data1), false); + + data0 = data0.subspan(0, 0); + + CHECK_EQUAL(etl::copy(data0, data1), true); + + data0 = src; + data1 = src; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + #include "etl/private/diagnostic_pop.h" }; } diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 157170a0..fe6b50e4 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -30,6 +30,7 @@ SOFTWARE. #include "etl/span.h" #include "etl/array.h" +#include "etl/unaligned_type.h" #include #include @@ -52,6 +53,7 @@ namespace typedef etl::span View; typedef etl::span SView; typedef etl::span CView; + typedef etl::span EView; #if ETL_USING_CPP20 using StdView = std::span; @@ -397,15 +399,19 @@ namespace View view(etldata.begin(), etldata.end()); CView cview(etldata.begin(), etldata.end()); + CHECK_EQUAL(etldata.cbegin(), view.cbegin()); CHECK_EQUAL(etldata.begin(), view.begin()); CHECK_EQUAL(etldata.begin(), cview.begin()); + CHECK_EQUAL(etldata.cend(), view.crbegin().base()); CHECK_EQUAL(etldata.end(), view.rbegin().base()); CHECK_EQUAL(etldata.end(), cview.rbegin().base()); + CHECK_EQUAL(etldata.cend(), view.cend()); CHECK_EQUAL(etldata.end(), view.end()); CHECK_EQUAL(etldata.end(), cview.end()); + CHECK_EQUAL(etldata.cbegin(), view.crend().base()); CHECK_EQUAL(etldata.begin(), view.rend().base()); CHECK_EQUAL(etldata.begin(), cview.rend().base()); } @@ -433,6 +439,22 @@ namespace CHECK_EQUAL(etldata.data(), cview.data()); } + //************************************************************************* + TEST(test_at) + { + View view(etldata.begin(), etldata.end()); + CView cview(etldata.begin(), etldata.end()); + + for (size_t i = 0UL; i < etldata.size(); ++i) + { + CHECK_EQUAL(etldata.at(i), view.at(i)); + CHECK_EQUAL(etldata.at(i), cview.at(i)); + } + + CHECK_THROW({ int d = view.at(view.size()); (void)d; }, etl::array_out_of_range); + CHECK_THROW({ int d = cview.at(cview.size()); (void)d; }, etl::array_out_of_range); + } + //************************************************************************* TEST(test_index_operator) { @@ -464,6 +486,9 @@ namespace { View view1(etldata.begin(), etldata.begin()); CHECK(!view1.empty()); + + EView view2(etldata.begin(), etldata.begin()); + CHECK(view2.empty()); } //************************************************************************* @@ -1123,6 +1148,118 @@ namespace } } + //************************************************************************* + TEST(test_make_span_c_array) + { + { + auto s = etl::make_span(cdata); + + CHECK_EQUAL(s.size(), 10); + View view(etldata); + CHECK_TRUE(etl::equal(s, view)); + } + { + auto s = etl::make_span(ccdata); + + CHECK_EQUAL(s.size(), 10); + View view(etldata); + CHECK_TRUE(etl::equal(s, view)); + } + } + + //************************************************************************* + TEST(test_span_issue_1050_questions_on_span_constructors) + { + int arr[5]{}; + etl::span span1(arr); + etl::span span2(span1); + //etl::span span3(span1); // This line should fail to compile. + } + + //************************************************************************* + TEST(test_reinterpret_as) + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + etl::span data1 = data0.reinterpret_as(); + + CHECK_EQUAL(data1.size(), 2); + CHECK(data1[0] == 0x102); + CHECK(data1[1] == 0x304); + } + + //************************************************************************* + TEST(test_reinterpret_as_aligned) + { + uint32_t data[] = { 0x01020304, 0x020406080, 0x03400560}; + etl::span data0 = data; + CHECK_EQUAL(data0.size(), 3); + + etl::span data1 = data0.reinterpret_as(); + CHECK_EQUAL(data1.size(), 12); + + etl::span data2 = data1.subspan(2).reinterpret_as(); + CHECK_EQUAL(data2.size(), 5); + + CHECK_THROW(data2 = data1.subspan(1).reinterpret_as(), etl::span_alignment_exception); + } + + //************************************************************************* + TEST(test_copy) + { + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + uint8_t dst[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + { + etl::span data0 = src; + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + } + { + etl::span data0 = src; + etl::span data1(&dst[1], 5); + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + } + + { + etl::span data0 = src; + etl::span data1(&dst[2], 4); + + CHECK_EQUAL(etl::copy(data0, data1), false); + } + { + etl::span data0(&src[0], 0); + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + { + etl::span data0 = src; + etl::span data1 = src; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + } + + //************************************************************************* + TEST(test_dynamic_span_to_fixed_span) + { + int data[5] = { 0, 1, 2, 3, 4 }; + etl::span sp1(data); + + using span_4 = etl::span; + using span_5 = etl::span; + using span_8 = etl::span; + + CHECK_NO_THROW({ span_5 sp2(sp1); }); + CHECK_THROW({ span_4 sp3(sp1); }, etl::span_size_mismatch); + CHECK_THROW({ span_8 sp4(sp1); }, etl::span_size_mismatch); + } + #include "etl/private/diagnostic_pop.h" }; } diff --git a/test/test_stack.cpp b/test/test_stack.cpp index b27f7e11..81d35b46 100644 --- a/test/test_stack.cpp +++ b/test/test_stack.cpp @@ -231,28 +231,38 @@ namespace { etl::stack stack; - stack.emplace(); + Item& item1 = stack.emplace(); CHECK_EQUAL(1U, stack.size()); - stack.emplace('b', 2, 2.3); + Item& item2 = stack.emplace('b', 2, 2.3); CHECK_EQUAL(2U, stack.size()); - stack.emplace('c', 3, 3.4); + Item& item3 = stack.emplace('c', 3, 3.4); CHECK_EQUAL(3U, stack.size()); - stack.emplace('d', 4, 4.5); + Item& item4 = stack.emplace('d', 4, 4.5); CHECK_EQUAL(4U, stack.size()); - stack.emplace('e', 5, 5.6); + Item& item5 = stack.emplace('e', 5, 5.6); CHECK_EQUAL(5U, stack.size()); + CHECK(item1 == Item('a', 1, 1.2)); + CHECK(item2 == Item('b', 2, 2.3)); + CHECK(item3 == Item('c', 3, 3.4)); + CHECK(item4 == Item('d', 4, 4.5)); + CHECK(item5 == Item('e', 5, 5.6)); + CHECK(stack.top() == Item('e', 5, 5.6)); + stack.pop(); CHECK(stack.top() == Item('d', 4, 4.5)); + stack.pop(); CHECK(stack.top() == Item('c', 3, 3.4)); + stack.pop(); CHECK(stack.top() == Item('b', 2, 2.3)); + stack.pop(); CHECK(stack.top() == Item('a', 1, 1.2)); } diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index b49e8814..a0789c1c 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -31,8 +31,10 @@ SOFTWARE. #include #include #include +#include #include "etl/string.h" +#include "etl/string_view.h" #include "etl/fnv_1.h" #undef STR @@ -51,21 +53,22 @@ namespace { static const size_t SIZE = 11UL; - using Text = etl::string; - using IText = etl::istring; - using CompareText = std::string; - using value_t = Text::value_type; - using TextL = etl::string<52>; - using TextS = etl::string<4>; + using Text = etl::string; + using IText = 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; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + 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"); @@ -102,9 +105,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -116,9 +117,7 @@ namespace CHECK(text.cbegin() == text.cend()); CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -127,7 +126,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -136,9 +135,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -148,14 +145,16 @@ namespace CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -163,15 +162,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -180,14 +177,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -195,15 +194,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -212,14 +209,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -227,15 +226,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -244,22 +241,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -272,7 +269,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -288,9 +287,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::string_view view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -305,9 +304,7 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -317,9 +314,7 @@ namespace IText& itext = text; Text text2(itext); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -330,7 +325,9 @@ namespace Text text2(textl); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -340,31 +337,29 @@ namespace Text text(longer_text.c_str()); Text text2(text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + 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); @@ -372,7 +367,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -380,20 +375,18 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + 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(' '), @@ -402,7 +395,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -417,10 +412,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -434,8 +427,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -453,10 +449,8 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text1.is_truncated()); - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -474,8 +468,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -492,10 +489,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -512,8 +507,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -524,11 +522,9 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -538,10 +534,12 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -553,11 +551,9 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); -#endif } //************************************************************************* @@ -568,13 +564,25 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + 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) { @@ -606,9 +614,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -626,9 +632,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -642,7 +646,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -656,9 +662,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -678,9 +682,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -709,7 +711,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* @@ -722,7 +724,7 @@ namespace text.uninitialized_resize(NEW_SIZE); - CHECK_EQUAL(text.size(), SIZE); + CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* @@ -750,7 +752,65 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + 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); } //************************************************************************* @@ -763,10 +823,7 @@ namespace bool is_equal = Equal(expected, text); CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -776,9 +833,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -788,9 +843,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -799,9 +852,7 @@ namespace Text text; CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -811,9 +862,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -823,9 +872,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -834,15 +881,13 @@ namespace Text text; CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -850,15 +895,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -866,15 +909,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -882,17 +923,14 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -900,65 +938,54 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); @@ -967,15 +994,13 @@ namespace compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); const Text text(compare_text.begin(), compare_text.end()); @@ -984,18 +1009,16 @@ namespace compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1003,18 +1026,46 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1023,29 +1074,29 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1053,29 +1104,29 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1085,14 +1136,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1100,9 +1153,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1117,7 +1168,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1137,9 +1190,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1157,14 +1208,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1182,15 +1235,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1201,9 +1252,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1214,14 +1263,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1245,7 +1296,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1265,7 +1316,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); const value_t INITIAL_VALUE = STR('A'); @@ -1276,7 +1327,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1288,7 +1341,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1300,7 +1355,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1310,7 +1367,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INITIAL_SIZE = 5UL; @@ -1324,9 +1381,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1336,7 +1391,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INSERT_SIZE = 4UL; @@ -1350,7 +1405,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1365,7 +1422,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1380,7 +1439,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1395,7 +1456,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1409,7 +1472,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); @@ -1417,10 +1480,8 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); +# bool is_equal = Equal(compare_text, text); CHECK(is_equal); } @@ -1432,7 +1493,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; size_t offset = 0UL; @@ -1444,7 +1505,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1459,7 +1522,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1475,7 +1540,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1490,7 +1557,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); @@ -1498,9 +1565,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1509,7 +1574,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + 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()); @@ -1519,9 +1584,26 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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()); } } @@ -1530,7 +1612,7 @@ namespace { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + 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()); @@ -1541,7 +1623,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1551,7 +1635,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + 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()); @@ -1564,7 +1648,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1572,7 +1658,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + 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()); @@ -1582,9 +1668,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1597,9 +1681,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1610,15 +1692,13 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1628,9 +1708,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1644,7 +1722,42 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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 } @@ -1660,7 +1773,9 @@ namespace text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif //#include "etl/private/diagnostic_pop.h" } @@ -1668,7 +1783,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1678,7 +1793,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1692,25 +1807,27 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + 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, std::string::npos); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Partial string. @@ -1725,7 +1842,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1740,7 +1857,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1755,7 +1874,9 @@ namespace text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1763,7 +1884,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -1773,7 +1894,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1787,7 +1908,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1795,7 +1918,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1805,7 +1928,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1819,7 +1942,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1827,7 +1952,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1837,7 +1962,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1852,7 +1977,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1860,101 +1987,219 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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 } @@ -1962,59 +2207,127 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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 } @@ -2022,115 +2335,247 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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 } @@ -2138,115 +2583,123 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2254,59 +2707,63 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText(STR("Replace with some 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2314,115 +2771,123 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2430,17 +2895,17 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2449,14 +2914,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2465,14 +2932,14 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2481,14 +2948,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2498,7 +2967,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -2508,21 +2977,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + 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, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2536,21 +3005,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2564,21 +3037,21 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + 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, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2592,21 +3065,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2614,7 +3091,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + 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')); @@ -2624,7 +3101,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2638,7 +3115,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2652,7 +3131,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2666,7 +3145,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2674,11 +3155,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + 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)); @@ -2687,7 +3168,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2701,7 +3182,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2715,7 +3198,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2729,58 +3212,60 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -2792,59 +3277,59 @@ namespace CHECK_EQUAL(text.size(), size_t(0)); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3025,7 +3510,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3039,7 +3524,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3059,20 +3544,20 @@ namespace CHECK_EQUAL(0U, length1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + 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, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3080,7 +3565,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3092,7 +3577,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3106,7 +3591,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3120,11 +3605,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); - etl::string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3138,11 +3623,42 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::istring::npos, position2); + 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); } //************************************************************************* @@ -3152,8 +3668,8 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3167,11 +3683,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t *pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3181,8 +3697,8 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3196,11 +3712,137 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::istring::npos, position2); + 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])); } //************************************************************************* @@ -3208,14 +3850,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); - etl::string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3225,9 +3867,37 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::istring::npos, position2); + 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); } //************************************************************************* @@ -3235,13 +3905,13 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3251,9 +3921,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3261,13 +3931,13 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -3278,7 +3948,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3286,11 +3956,11 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - etl::istring::size_type position1 = etl::istring::npos; - size_t position2 = etl::string<50>::npos; + 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); @@ -3301,16 +3971,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -3345,112 +4015,217 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + 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(CompareText(STR("ABCDEE"))); + 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(CompareText(STR("ABCDEG"))); + 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(CompareText(STR("ABCDE"))); + 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(CompareText(STR("ABCDEFG"))); + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + 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, CompareText(STR("ABCDEE"))); + 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, CompareText(STR("ABCDEG"))); + 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, CompareText(STR("ABCDE"))); + 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, CompareText(STR("ABCDEFG"))); + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + 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, CompareText(STR("aaABCDEEbb")), 2, 6); + 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, CompareText(STR("aaABCDEGbb")), 2, 6); + 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, CompareText(STR("aaABCDEbb")), 2, 5); + 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, CompareText(STR("aaABCDEFGbb")), 2, 7); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -3485,7 +4260,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3520,7 +4295,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3555,36 +4330,65 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + 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(CompareText(STR("WXYZ"))); + 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(CompareText(STR("ZCXF")), 3); + 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(CompareText(STR("ZCXF")), 100); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -3613,7 +4417,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -3647,7 +4451,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -3686,41 +4490,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + 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(CompareText(STR("WXYZ")), 3); + 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(CompareText(STR("ZCXE")), 5); + 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(CompareText(STR("ZCXE")), compare_text.size()); + 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(CompareText(STR("ZCXE")), 100); + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -3759,7 +4597,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -3796,7 +4634,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -3835,41 +4673,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + 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(CompareText(STR("ZAXB"))); + 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(CompareText(STR("ZAXB")), 3); + 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(CompareText(STR("ZAXB")), compare_text.size()); + 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(CompareText(STR("ZAXB")), 100); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -3903,7 +4775,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -3942,7 +4814,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -3981,41 +4853,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + 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(CompareText(STR("ZEXD")), 3); + 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(CompareText(STR("ZEXD")), 5); + 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(CompareText(STR("ZEXD")), compare_text.size()); + 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(CompareText(STR("ZEXD")), 100); + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -4049,7 +4955,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -4081,7 +4987,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); @@ -4187,25 +5093,25 @@ namespace TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) { Text text(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -4214,8 +5120,8 @@ namespace Text text1(short_text.c_str()); TextS text2(short_text.c_str()); - CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_FALSE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -4230,7 +5136,7 @@ namespace Text text2(short_text.c_str()); CHECK(text1.is_truncated()); - CHECK(!text2.is_truncated()); + CHECK_FALSE(text2.is_truncated()); // Clear text but not the truncate flag. text1.erase(text1.begin(), text1.end()); @@ -4245,10 +5151,10 @@ namespace TEST_FIXTURE(SetupFixture, test_clear_truncated) { Text text(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -4269,7 +5175,9 @@ namespace 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); @@ -4415,7 +5323,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } @@ -4430,7 +5338,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4445,9 +5353,29 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index d934dafe..1e9e5e44 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -31,8 +31,10 @@ SOFTWARE. #include #include #include +#include #include "etl/string.h" +#include "etl/string_view.h" #include "etl/fnv_1.h" #undef STR @@ -53,24 +55,26 @@ namespace static constexpr size_t SIZE_L = 52UL; static constexpr size_t SIZE_S = 4UL; - using Text = etl::string_ext; - using IText = etl::istring; - using TextL = etl::string; - using CompareText = std::string; - using value_t = Text::value_type; + using Text = etl::string_ext; + using IText = etl::istring; + using TextL = etl::string; + using TextSTD = std::string; + using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + 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"); @@ -113,9 +117,7 @@ namespace CHECK_EQUAL(SIZE, text.capacity()); CHECK_EQUAL(SIZE, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -129,9 +131,7 @@ namespace CHECK_EQUAL(length, text.capacity()); CHECK_EQUAL(length, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -144,9 +144,7 @@ namespace CHECK_EQUAL(etl::strlen(p_text), text.capacity()); CHECK_EQUAL(etl::strlen(p_text), text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -159,9 +157,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -174,9 +170,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -189,9 +183,7 @@ namespace CHECK(text.cbegin() == text.cend()); CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -201,7 +193,7 @@ namespace const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -210,9 +202,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -223,7 +213,9 @@ namespace CHECK_EQUAL(buffer.size() - 1, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -231,7 +223,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -239,15 +231,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -257,14 +247,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -273,15 +265,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -291,14 +281,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -307,15 +299,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -325,23 +315,23 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -355,7 +345,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -372,10 +364,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::string_view view(initial_text.data(), initial_text.size()); - + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -427,7 +418,9 @@ namespace Text text2(textl, buffer2.data(), buffer2.size()); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -441,15 +434,17 @@ namespace Text text2(text, buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -467,8 +462,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -479,7 +474,9 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -487,7 +484,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -495,15 +492,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), @@ -515,7 +510,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -533,10 +530,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -553,8 +548,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -599,8 +597,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -620,10 +621,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -643,8 +642,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -656,11 +658,9 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -671,10 +671,12 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -687,10 +689,12 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -703,13 +707,28 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + 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) { @@ -748,9 +767,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -769,9 +786,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -786,7 +801,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -801,9 +818,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -824,9 +839,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -902,6 +915,67 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.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; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.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) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.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_empty_full) { @@ -910,9 +984,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -923,9 +995,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -935,9 +1005,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -948,9 +1016,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -961,9 +1027,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -973,15 +1037,13 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -991,15 +1053,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1009,15 +1069,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1027,9 +1085,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1037,7 +1093,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1047,9 +1103,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1057,63 +1111,55 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1123,15 +1169,13 @@ namespace compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1141,20 +1185,18 @@ namespace compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1164,20 +1206,51 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assign_string) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + 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()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + View view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + 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) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1188,14 +1261,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1203,15 +1278,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1220,14 +1293,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1235,15 +1310,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1254,14 +1327,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1270,9 +1345,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1288,7 +1361,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1309,9 +1384,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1330,14 +1403,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1357,15 +1432,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1378,9 +1451,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1391,14 +1462,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1424,7 +1497,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1446,7 +1519,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1458,7 +1531,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1470,7 +1545,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1482,7 +1559,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1492,7 +1571,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1507,9 +1586,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1519,7 +1596,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1534,7 +1611,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1549,7 +1628,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1564,7 +1645,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1579,7 +1662,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1593,7 +1678,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1602,9 +1687,7 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1617,7 +1700,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1630,7 +1713,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1645,7 +1730,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1661,7 +1748,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1676,7 +1765,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1686,9 +1775,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1697,8 +1784,8 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1711,9 +1798,28 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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()); + TextBuffer buffer{0}; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + 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()); } } @@ -1722,7 +1828,7 @@ namespace { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1737,7 +1843,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1747,7 +1855,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1765,7 +1873,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1773,7 +1883,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1787,9 +1897,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1802,9 +1910,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1815,15 +1921,13 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1837,9 +1941,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1853,7 +1955,43 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + 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 } @@ -1868,11 +2006,15 @@ namespace Text append(short_text.c_str(), buffers.data(), buffers.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" } @@ -1880,7 +2022,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1891,9 +2033,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(shorter_text.c_str()); @@ -1906,14 +2046,16 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1922,14 +2064,12 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::string::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -1942,9 +2082,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1958,7 +2096,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1972,11 +2112,15 @@ namespace Text append(short_text.c_str(), buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1984,7 +2128,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1995,9 +2139,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2010,7 +2152,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2018,7 +2162,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2029,9 +2173,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2044,7 +2186,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2052,7 +2196,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2065,9 +2209,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2081,7 +2223,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2089,103 +2233,209 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2193,61 +2443,122 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2255,117 +2566,234 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2373,117 +2801,117 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2491,61 +2919,61 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2553,117 +2981,117 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2671,20 +3099,18 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -2692,14 +3118,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2708,15 +3136,13 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -2724,14 +3150,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2741,7 +3169,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2752,23 +3180,19 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2781,21 +3205,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2808,23 +3236,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2837,21 +3261,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2859,7 +3287,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2870,9 +3298,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2885,7 +3311,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2898,9 +3326,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2913,7 +3339,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2921,13 +3349,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + 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)); @@ -2935,9 +3363,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2950,7 +3376,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2963,9 +3391,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2978,14 +3404,16 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -2995,15 +3423,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3014,9 +3440,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3027,69 +3451,59 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3299,7 +3713,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3314,9 +3728,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3335,15 +3747,13 @@ namespace size_t length1 = text.copy(buffer1, 5, SIZE); CHECK_EQUAL(0U, length1); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3351,16 +3761,14 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3371,7 +3779,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3386,9 +3794,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3401,12 +3807,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3423,13 +3829,44 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::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")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + 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(TextL::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3437,7 +3874,7 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3468,7 +3905,7 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3492,23 +3929,168 @@ namespace CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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"); - std::string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3524,20 +4106,47 @@ namespace CHECK_EQUAL(IText::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")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::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"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3558,14 +4167,14 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3586,13 +4195,13 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3609,7 +4218,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3618,35 +4227,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3655,35 +4300,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3692,35 +4373,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, TextL(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")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3757,7 +4474,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3794,7 +4511,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3831,38 +4548,68 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3893,7 +4640,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3929,7 +4676,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3970,43 +4717,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4047,7 +4829,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4088,7 +4870,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4129,43 +4911,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4201,7 +5018,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4242,7 +5059,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4283,43 +5100,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4355,7 +5207,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4389,7 +5241,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4503,25 +5355,25 @@ namespace { TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -4534,7 +5386,7 @@ namespace Text text2(short_text.c_str(), buffers.data(), buffers.size()); CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -4568,10 +5420,10 @@ namespace { TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -4594,7 +5446,9 @@ namespace 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); @@ -4753,9 +5607,7 @@ namespace std::fill(text.data(), text.data() + text.max_size(), STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -4769,9 +5621,7 @@ namespace std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4786,9 +5636,30 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + 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/test_string_u16.cpp b/test/test_string_u16.cpp index 7d529521..d55c64b4 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u16string.h" @@ -66,21 +67,22 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u16string; - using IText = etl::iu16string; - using CompareText = std::u16string; - using value_t = Text::value_type; - using TextL = etl::u16string<52>; - using TextS = etl::u16string<4>; + using Text = etl::u16string; + using IText = etl::iu16string; + using TextSTD = std::u16string; + using value_t = Text::value_type; + using TextL = etl::u16string<52>; + using TextS = etl::u16string<4>; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; + using View = etl::u16string_view; const value_t* pinitial_text = STR("Hello World"); @@ -96,7 +98,6 @@ namespace { SetupFixture() { - initial_text = STR("Hello World"); initial_text = STR("Hello World"); insert_text = STR("Insert"); less_text = STR("Hello Vorld"); @@ -118,9 +119,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -128,22 +127,20 @@ namespace { Text text; - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -152,9 +149,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -164,14 +159,16 @@ namespace CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -179,15 +176,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -196,14 +191,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -211,15 +208,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -228,14 +223,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -243,15 +240,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -260,22 +255,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -288,7 +283,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -304,9 +301,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u16string_view view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -321,9 +318,7 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -333,9 +328,7 @@ namespace IText& itext = text; Text text2(itext); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -346,7 +339,9 @@ namespace Text text2(textl); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -356,31 +351,29 @@ namespace Text text(longer_text.c_str()); Text text2(text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + 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); @@ -388,7 +381,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -396,29 +389,29 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + 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') }; + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -433,10 +426,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -450,8 +441,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -469,10 +463,8 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text1.is_truncated()); - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -490,8 +482,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -508,10 +503,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -528,8 +521,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -540,11 +536,9 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -554,10 +548,12 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -569,11 +565,9 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); -#endif } //************************************************************************* @@ -584,53 +578,64 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + 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(&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(&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 = 5; - const size_t NEW_SIZE = 8; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + 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); @@ -641,46 +646,44 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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); @@ -693,24 +696,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + 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(); + 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); @@ -724,35 +725,35 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + 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(text.size(), SIZE); + CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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(); + 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); @@ -765,7 +766,65 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + 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); } //************************************************************************* @@ -778,10 +837,7 @@ namespace bool is_equal = Equal(expected, text); CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -791,9 +847,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -803,9 +857,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -814,9 +866,7 @@ namespace Text text; CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -826,9 +876,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -838,9 +886,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -849,15 +895,13 @@ namespace Text text; CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -865,15 +909,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -881,15 +923,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -897,17 +937,14 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -915,102 +952,87 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + 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() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1018,18 +1040,46 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1038,29 +1088,29 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1068,29 +1118,29 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1100,14 +1150,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1115,9 +1167,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1132,14 +1182,16 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; @@ -1152,16 +1204,14 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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 + 1; + const size_t EXCESS_SIZE = SIZE + 1UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; compare_text.fill(INITIAL_VALUE); @@ -1172,14 +1222,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1197,15 +1249,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1216,9 +1266,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1229,14 +1277,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1255,12 +1305,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1280,42 +1330,48 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + 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 = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + 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.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + 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.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1325,23 +1381,21 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1351,66 +1405,74 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; - const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const size_t INSERT_SIZE = 4UL; + const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1420,22 +1482,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + 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, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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); } @@ -1444,22 +1504,24 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1469,12 +1531,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1485,12 +1549,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1501,32 +1567,30 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_self) { - size_t length = TextL::MAX_SIZE / 2; + size_t length = TextL::MAX_SIZE / 2UL; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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); @@ -1534,20 +1598,37 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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 = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); - Text text(initial_text.begin(), initial_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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); @@ -1556,7 +1637,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1564,13 +1647,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(longer_text.begin(), longer_text.end()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + 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); @@ -1579,7 +1662,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1587,9 +1672,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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()); @@ -1597,12 +1682,10 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + 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); @@ -1612,12 +1695,10 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + 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()); @@ -1625,15 +1706,13 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1643,9 +1722,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1659,14 +1736,49 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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" + //#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 @@ -1675,15 +1787,17 @@ namespace text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1693,7 +1807,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1707,25 +1821,27 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + 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, std::u16string::npos); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Partial string. @@ -1740,7 +1856,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1755,7 +1871,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1770,7 +1888,9 @@ namespace text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1778,7 +1898,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -1788,7 +1908,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1802,7 +1922,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1810,7 +1932,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1820,7 +1942,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1834,7 +1956,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1842,7 +1966,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1852,7 +1976,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1867,7 +1991,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1875,101 +2001,219 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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 } @@ -1977,59 +2221,127 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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 } @@ -2037,115 +2349,247 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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 } @@ -2153,115 +2597,123 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2269,59 +2721,63 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2329,115 +2785,123 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2445,17 +2909,17 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2464,14 +2928,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2480,14 +2946,14 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2496,14 +2962,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2513,7 +2981,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -2523,21 +2991,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + 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, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2551,21 +3019,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2579,21 +3051,21 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + 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, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2607,21 +3079,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2629,7 +3105,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + 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')); @@ -2639,7 +3115,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2653,7 +3129,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2667,7 +3145,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2681,7 +3159,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2689,11 +3169,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + 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)); @@ -2702,7 +3182,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2716,7 +3196,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2730,7 +3212,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2744,58 +3226,60 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -2807,59 +3291,59 @@ namespace CHECK_EQUAL(text.size(), size_t(0)); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -2904,7 +3388,7 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); const Text greater(greater_text.c_str()); @@ -2919,17 +3403,17 @@ namespace 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((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((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((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)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -2939,8 +3423,8 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + 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)); @@ -2954,17 +3438,17 @@ namespace 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((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((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((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)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -2989,17 +3473,17 @@ namespace 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((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((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((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)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3009,8 +3493,8 @@ namespace 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)); + 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)); @@ -3024,23 +3508,23 @@ namespace 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((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((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((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)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3054,7 +3538,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3074,20 +3558,20 @@ namespace CHECK_EQUAL(0U, length1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + 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, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3095,7 +3579,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3107,7 +3591,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3121,7 +3605,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3135,14 +3619,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); - etl::u16string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); position2 = haystack.find(needle, position2); @@ -3153,11 +3637,42 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u16string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + 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); } //************************************************************************* @@ -3167,11 +3682,11 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1); position2 = haystack.find(needle, position2); @@ -3182,11 +3697,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3196,11 +3711,11 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1, 3); position2 = haystack.find(needle, position2, 3); @@ -3211,11 +3726,137 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iu16string::npos, position2); + 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])); } //************************************************************************* @@ -3223,14 +3864,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); - etl::u16string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3240,23 +3881,51 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3266,23 +3935,23 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -3293,19 +3962,19 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iu16string::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + etl::iu16string::size_type position1 = TextL::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3316,16 +3985,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -3360,112 +4029,217 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + 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(CompareText(STR("ABCDEE"))); + 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(CompareText(STR("ABCDEG"))); + 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(CompareText(STR("ABCDE"))); + 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(CompareText(STR("ABCDEFG"))); + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + 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, CompareText(STR("ABCDEE"))); + 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, CompareText(STR("ABCDEG"))); + 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, CompareText(STR("ABCDE"))); + 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, CompareText(STR("ABCDEFG"))); + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + 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, CompareText(STR("aaABCDEEbb")), 2, 6); + 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, CompareText(STR("aaABCDEGbb")), 2, 6); + 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, CompareText(STR("aaABCDEbb")), 2, 5); + 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, CompareText(STR("aaABCDEFGbb")), 2, 7); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -3500,7 +4274,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3535,7 +4309,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3570,36 +4344,65 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + 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(CompareText(STR("WXYZ"))); + 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(CompareText(STR("ZCXF")), 3); + 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(CompareText(STR("ZCXF")), 100); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -3628,7 +4431,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -3662,7 +4465,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -3701,41 +4504,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + 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(CompareText(STR("WXYZ")), 3); + 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(CompareText(STR("ZCXE")), 5); + 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(CompareText(STR("ZCXE")), compare_text.size()); + 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(CompareText(STR("ZCXE")), 100); + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -3774,7 +4611,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -3811,7 +4648,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -3850,41 +4687,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + 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(CompareText(STR("ZAXB"))); + 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(CompareText(STR("ZAXB")), 3); + 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(CompareText(STR("ZAXB")), compare_text.size()); + 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(CompareText(STR("ZAXB")), 100); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -3918,7 +4789,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -3957,7 +4828,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -3996,41 +4867,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + 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(CompareText(STR("ZEXD")), 3); + 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(CompareText(STR("ZEXD")), 5); + 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(CompareText(STR("ZEXD")), compare_text.size()); + 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(CompareText(STR("ZEXD")), 100); + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -4064,7 +4969,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -4096,7 +5001,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); @@ -4202,25 +5107,25 @@ namespace TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) { Text text(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -4229,8 +5134,8 @@ namespace Text text1(short_text.c_str()); TextS text2(short_text.c_str()); - CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_FALSE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -4245,7 +5150,7 @@ namespace Text text2(short_text.c_str()); CHECK(text1.is_truncated()); - CHECK(!text2.is_truncated()); + CHECK_FALSE(text2.is_truncated()); // Clear text but not the truncate flag. text1.erase(text1.begin(), text1.end()); @@ -4260,10 +5165,10 @@ namespace TEST_FIXTURE(SetupFixture, test_clear_truncated) { Text text(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -4284,7 +5189,9 @@ namespace 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); @@ -4430,7 +5337,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } @@ -4445,7 +5352,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4460,7 +5367,9 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index 8e271ad6..fffa53c7 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u16string.h" #include "etl/fnv_1.h" @@ -72,20 +73,22 @@ namespace using Text = etl::u16string_ext; using IText = etl::iu16string; using TextL = etl::u16string; - using CompareText = std::u16string; + using TextSTD = std::u16string; using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using View = etl::u16string_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"); @@ -128,9 +131,7 @@ namespace CHECK_EQUAL(SIZE, text.capacity()); CHECK_EQUAL(SIZE, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -144,9 +145,7 @@ namespace CHECK_EQUAL(length, text.capacity()); CHECK_EQUAL(length, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -159,9 +158,7 @@ namespace CHECK_EQUAL(etl::strlen(p_text), text.capacity()); CHECK_EQUAL(etl::strlen(p_text), text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -174,9 +171,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -189,9 +184,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -200,23 +193,21 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -225,9 +216,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -238,7 +227,9 @@ namespace CHECK_EQUAL(buffer.size() - 1, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -246,7 +237,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -254,15 +245,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -272,14 +261,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -288,15 +279,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -306,14 +295,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -322,15 +313,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -340,23 +329,23 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -370,7 +359,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -387,10 +378,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u16string_view view(initial_text.data(), initial_text.size()); - + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -442,7 +432,9 @@ namespace Text text2(textl, buffer2.data(), buffer2.size()); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -456,15 +448,17 @@ namespace Text text2(text, buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -482,8 +476,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -494,7 +488,9 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -502,7 +498,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -510,27 +506,27 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { 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') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -548,10 +544,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -568,8 +562,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -614,8 +611,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -635,10 +635,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -658,8 +656,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -671,11 +672,9 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -686,10 +685,12 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -702,10 +703,12 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -718,13 +721,28 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + 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) { @@ -763,9 +781,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -784,9 +800,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -801,7 +815,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -816,9 +832,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -839,15 +853,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -891,7 +903,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -918,21 +930,64 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; - text.fill(STR('B')); + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); - bool is_equal = Equal(expected, text); - CHECK(is_equal); + // 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; + } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.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) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); } //************************************************************************* @@ -943,9 +998,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -956,9 +1009,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -968,9 +1019,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -981,9 +1030,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -994,9 +1041,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1006,15 +1051,13 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1024,15 +1067,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1042,15 +1083,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1060,9 +1099,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1070,7 +1107,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1080,9 +1117,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1090,104 +1125,92 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1197,20 +1220,51 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assign_string) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + 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()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + View view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + 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) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1221,14 +1275,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1236,15 +1292,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1253,14 +1307,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1268,15 +1324,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1287,14 +1341,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1303,9 +1359,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1321,7 +1375,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1342,9 +1398,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1363,14 +1417,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1390,15 +1446,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1411,9 +1465,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1424,14 +1476,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1453,11 +1507,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1479,7 +1533,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1491,7 +1545,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1503,7 +1559,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1515,7 +1573,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1525,7 +1585,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1540,9 +1600,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1552,7 +1610,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1567,7 +1625,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1582,7 +1642,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1597,7 +1659,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1612,7 +1676,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1626,7 +1692,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1635,9 +1701,7 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1650,7 +1714,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1663,7 +1727,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1678,7 +1744,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1694,7 +1762,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1709,7 +1779,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1719,27 +1789,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - size_t s = short_text.size(); - (void)s; - - assert(s <= 5); - - for (size_t offset = s; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; + buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1748,30 +1812,42 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_2) + 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()); + TextBuffer buffer{0}; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + 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) { -#include "etl/private/diagnostic_array_bounds_push.h" for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); - TextBuffer buffer{ 0 }; + TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1781,10 +1857,11 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } -#include "etl/private/diagnostic_pop.h" } //************************************************************************* @@ -1792,7 +1869,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1810,7 +1887,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1818,7 +1897,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1832,9 +1911,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1847,9 +1924,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1860,15 +1935,13 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1882,9 +1955,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1898,7 +1969,43 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + 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 } @@ -1913,11 +2020,15 @@ namespace Text append(short_text.c_str(), buffers.data(), buffers.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" } @@ -1925,7 +2036,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1936,9 +2047,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(shorter_text.c_str()); @@ -1951,14 +2060,16 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1967,14 +2078,12 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::u16string::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -1987,9 +2096,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2003,7 +2110,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2017,11 +2126,15 @@ namespace Text append(short_text.c_str(), buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2029,7 +2142,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2040,9 +2153,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2055,7 +2166,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2063,7 +2176,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2074,9 +2187,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2089,7 +2200,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2097,7 +2210,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2110,9 +2223,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2126,7 +2237,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2134,103 +2247,209 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2238,61 +2457,122 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2300,117 +2580,234 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2418,117 +2815,117 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2536,61 +2933,61 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2598,117 +2995,117 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2716,20 +3113,18 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -2737,14 +3132,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2753,15 +3150,13 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -2769,14 +3164,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2786,7 +3183,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2797,23 +3194,19 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2826,21 +3219,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2853,23 +3250,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2882,21 +3275,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2904,7 +3301,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2915,9 +3312,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2930,7 +3325,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2943,9 +3340,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2958,7 +3353,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2966,13 +3363,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + 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)); @@ -2980,9 +3377,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2995,7 +3390,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3008,9 +3405,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3023,62 +3418,43 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); - - CompareText::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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::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); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3089,69 +3465,59 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3208,7 +3574,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3225,17 +3591,17 @@ namespace 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((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((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((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)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3248,8 +3614,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3265,17 +3631,17 @@ namespace 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((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((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((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)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3305,17 +3671,17 @@ namespace 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((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((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((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)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3328,8 +3694,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3345,24 +3711,24 @@ namespace 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((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((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((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)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3376,9 +3742,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3397,15 +3761,13 @@ namespace size_t length1 = text.copy(buffer1, 5, SIZE); CHECK_EQUAL(0U, length1); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3413,16 +3775,14 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3433,7 +3793,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3448,9 +3808,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3463,12 +3821,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3485,13 +3843,44 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u16string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::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")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + 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(TextL::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3499,7 +3888,7 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3518,7 +3907,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } @@ -3530,7 +3919,7 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3549,28 +3938,173 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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"); - std::u16string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3587,19 +4121,46 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::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); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3618,16 +4179,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3646,15 +4207,15 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3671,7 +4232,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3680,35 +4241,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3717,35 +4314,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3754,35 +4387,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, TextL(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")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3819,7 +4488,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3856,7 +4525,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3893,38 +4562,68 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3955,7 +4654,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3991,7 +4690,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4032,43 +4731,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4109,7 +4843,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4139,16 +4873,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4189,43 +4925,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4261,7 +5032,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4302,7 +5073,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4343,43 +5114,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4415,7 +5221,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4449,7 +5255,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4563,25 +5369,25 @@ namespace { TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -4594,7 +5400,7 @@ namespace Text text2(short_text.c_str(), buffers.data(), buffers.size()); CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -4628,10 +5434,10 @@ namespace { TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -4654,7 +5460,9 @@ namespace 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); @@ -4813,9 +5621,7 @@ namespace std::fill(text.data(), text.data() + text.max_size(), STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -4829,9 +5635,7 @@ namespace std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4846,7 +5650,9 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index fa1c199c..0da7930e 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u32string.h" @@ -66,21 +67,22 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u32string; - using IText = etl::iu32string; - using CompareText = std::u32string; - using value_t = Text::value_type; - using TextL = etl::u32string<52>; - using TextS = etl::u32string<4>; + using Text = etl::u32string; + using IText = etl::iu32string; + using TextSTD = std::u32string; + using value_t = Text::value_type; + using TextL = etl::u32string<52>; + using TextS = etl::u32string<4>; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; + using View = etl::u32string_view; const value_t* pinitial_text = STR("Hello World"); @@ -96,15 +98,14 @@ namespace { SetupFixture() { - initial_text = STR("Hello World"); - initial_text = STR("Hello World"); - insert_text = STR("Insert"); - less_text = STR("Hello Vorld"); - greater_text = STR("Hello Xorld"); - shorter_text = STR("Hello Worl"); + 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"); + longer_text = STR("Hello World There"); + short_text = STR("Hello"); } }; @@ -118,9 +119,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -128,22 +127,20 @@ namespace { Text text; - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -152,9 +149,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -164,14 +159,16 @@ namespace CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -179,15 +176,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -196,14 +191,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -211,15 +208,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -228,14 +223,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -243,15 +240,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -260,22 +255,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -288,7 +283,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -304,9 +301,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u32string_view view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -321,9 +318,7 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -333,9 +328,7 @@ namespace IText& itext = text; Text text2(itext); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -346,7 +339,9 @@ namespace Text text2(textl); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -356,31 +351,29 @@ namespace Text text(longer_text.c_str()); Text text2(text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + 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); @@ -388,7 +381,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -396,29 +389,29 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + 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') }; + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -433,10 +426,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -450,8 +441,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -469,10 +463,8 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text1.is_truncated()); - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -490,8 +482,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -508,10 +503,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -528,8 +521,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -540,11 +536,9 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -554,10 +548,12 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -569,11 +565,9 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); -#endif } //************************************************************************* @@ -584,23 +578,36 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + 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()); + const Text constText(initial_text.c_str()); CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_end) { @@ -614,23 +621,21 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + 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); @@ -641,46 +646,44 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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); @@ -693,24 +696,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + 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(); + 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); @@ -724,35 +725,35 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + 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(text.size(), SIZE); + CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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(); + 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); @@ -765,7 +766,65 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + 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); } //************************************************************************* @@ -778,10 +837,7 @@ namespace bool is_equal = Equal(expected, text); CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -791,9 +847,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -803,9 +857,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -814,9 +866,7 @@ namespace Text text; CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -826,9 +876,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -838,9 +886,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -849,15 +895,13 @@ namespace Text text; CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -865,15 +909,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -881,15 +923,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -897,17 +937,14 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -915,102 +952,87 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + 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() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1018,18 +1040,46 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1038,29 +1088,29 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1068,29 +1118,29 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1100,14 +1150,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1115,9 +1167,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1132,14 +1182,16 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; @@ -1152,16 +1204,14 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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 + 1; + const size_t EXCESS_SIZE = SIZE + 1UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; compare_text.fill(INITIAL_VALUE); @@ -1172,14 +1222,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1197,15 +1249,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1216,9 +1266,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1229,14 +1277,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1255,12 +1305,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1280,42 +1330,48 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + 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 = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + 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.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + 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.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1325,23 +1381,21 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1351,66 +1405,74 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; - const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const size_t INSERT_SIZE = 4UL; + const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1420,22 +1482,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + 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, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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); } @@ -1444,22 +1504,24 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1469,12 +1531,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1485,12 +1549,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1501,32 +1567,30 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_self) { - size_t length = TextL::MAX_SIZE / 2; + size_t length = TextL::MAX_SIZE / 2UL; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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); @@ -1534,20 +1598,37 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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 = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); - Text text(initial_text.begin(), initial_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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); @@ -1556,7 +1637,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1564,13 +1647,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(longer_text.begin(), longer_text.end()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + 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); @@ -1579,7 +1662,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1587,9 +1672,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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()); @@ -1597,12 +1682,10 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + 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); @@ -1612,12 +1695,10 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + 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()); @@ -1625,15 +1706,13 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1643,9 +1722,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1659,14 +1736,49 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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" + //#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 @@ -1675,15 +1787,17 @@ namespace text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1693,7 +1807,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1707,25 +1821,27 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + 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, std::u32string::npos); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Partial string. @@ -1740,7 +1856,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1755,7 +1871,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1770,7 +1888,9 @@ namespace text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1778,7 +1898,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -1788,7 +1908,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1802,7 +1922,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1810,7 +1932,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1820,7 +1942,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1834,7 +1956,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1842,7 +1966,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1852,7 +1976,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1867,7 +1991,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1875,101 +2001,219 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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 } @@ -1977,59 +2221,127 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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 } @@ -2037,115 +2349,247 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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 } @@ -2153,115 +2597,123 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2269,59 +2721,63 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2329,115 +2785,123 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2445,17 +2909,17 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2464,14 +2928,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2480,14 +2946,14 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2496,14 +2962,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2513,7 +2981,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -2523,21 +2991,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + 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, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2551,21 +3019,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2579,21 +3051,21 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + 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, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2607,21 +3079,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2629,7 +3105,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + 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')); @@ -2639,7 +3115,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2653,7 +3129,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2667,7 +3145,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2681,7 +3159,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2689,11 +3169,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + 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)); @@ -2702,7 +3182,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2716,7 +3196,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2730,7 +3212,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2744,58 +3226,60 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -2807,59 +3291,59 @@ namespace CHECK_EQUAL(text.size(), size_t(0)); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -2904,7 +3388,7 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); const Text greater(greater_text.c_str()); @@ -2919,17 +3403,17 @@ namespace 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((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((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((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)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -2939,8 +3423,8 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + 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)); @@ -2954,17 +3438,17 @@ namespace 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((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((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((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)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -2989,17 +3473,17 @@ namespace 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((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((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((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)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3009,8 +3493,8 @@ namespace 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)); + 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)); @@ -3024,23 +3508,23 @@ namespace 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((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((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((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)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3054,7 +3538,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3074,20 +3558,20 @@ namespace CHECK_EQUAL(0U, length1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + 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, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3095,7 +3579,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3107,7 +3591,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3121,7 +3605,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3135,14 +3619,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); - etl::u32string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); position2 = haystack.find(needle, position2); @@ -3153,11 +3637,42 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u32string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + 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); } //************************************************************************* @@ -3167,11 +3682,11 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1); position2 = haystack.find(needle, position2); @@ -3182,11 +3697,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3196,11 +3711,11 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1, 3); position2 = haystack.find(needle, position2, 3); @@ -3211,11 +3726,137 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iu32string::npos, position2); + 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])); } //************************************************************************* @@ -3223,14 +3864,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); - etl::u32string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3240,23 +3881,51 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3266,23 +3935,23 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -3293,19 +3962,19 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iu32string::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + etl::iu32string::size_type position1 = TextL::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3316,16 +3985,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -3360,112 +4029,217 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + 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(CompareText(STR("ABCDEE"))); + 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(CompareText(STR("ABCDEG"))); + 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(CompareText(STR("ABCDE"))); + 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(CompareText(STR("ABCDEFG"))); + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + 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, CompareText(STR("ABCDEE"))); + 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, CompareText(STR("ABCDEG"))); + 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, CompareText(STR("ABCDE"))); + 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, CompareText(STR("ABCDEFG"))); + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + 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, CompareText(STR("aaABCDEEbb")), 2, 6); + 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, CompareText(STR("aaABCDEGbb")), 2, 6); + 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, CompareText(STR("aaABCDEbb")), 2, 5); + 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, CompareText(STR("aaABCDEFGbb")), 2, 7); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -3500,7 +4274,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3535,7 +4309,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3570,36 +4344,65 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + 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(CompareText(STR("WXYZ"))); + 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(CompareText(STR("ZCXF")), 3); + 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(CompareText(STR("ZCXF")), 100); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -3628,7 +4431,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -3662,7 +4465,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -3701,41 +4504,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + 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(CompareText(STR("WXYZ")), 3); + 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(CompareText(STR("ZCXE")), 5); + 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(CompareText(STR("ZCXE")), compare_text.size()); + 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(CompareText(STR("ZCXE")), 100); + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -3774,7 +4611,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -3811,7 +4648,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -3850,41 +4687,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + 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(CompareText(STR("ZAXB"))); + 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(CompareText(STR("ZAXB")), 3); + 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(CompareText(STR("ZAXB")), compare_text.size()); + 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(CompareText(STR("ZAXB")), 100); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -3918,7 +4789,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -3957,7 +4828,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -3996,41 +4867,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + 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(CompareText(STR("ZEXD")), 3); + 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(CompareText(STR("ZEXD")), 5); + 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(CompareText(STR("ZEXD")), compare_text.size()); + 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(CompareText(STR("ZEXD")), 100); + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -4064,7 +4969,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -4096,7 +5001,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); @@ -4202,25 +5107,25 @@ namespace TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) { Text text(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -4229,8 +5134,8 @@ namespace Text text1(short_text.c_str()); TextS text2(short_text.c_str()); - CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_FALSE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -4245,7 +5150,7 @@ namespace Text text2(short_text.c_str()); CHECK(text1.is_truncated()); - CHECK(!text2.is_truncated()); + CHECK_FALSE(text2.is_truncated()); // Clear text but not the truncate flag. text1.erase(text1.begin(), text1.end()); @@ -4260,10 +5165,10 @@ namespace TEST_FIXTURE(SetupFixture, test_clear_truncated) { Text text(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -4284,7 +5189,9 @@ namespace 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); @@ -4430,7 +5337,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } @@ -4445,7 +5352,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4460,7 +5367,9 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 96650015..3c02629c 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u32string.h" #include "etl/fnv_1.h" @@ -72,20 +73,22 @@ namespace using Text = etl::u32string_ext; using IText = etl::iu32string; using TextL = etl::u32string; - using CompareText = std::u32string; + using TextSTD = std::u32string; using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using View = etl::u32string_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"); @@ -128,9 +131,7 @@ namespace CHECK_EQUAL(SIZE, text.capacity()); CHECK_EQUAL(SIZE, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -144,9 +145,7 @@ namespace CHECK_EQUAL(length, text.capacity()); CHECK_EQUAL(length, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -159,9 +158,7 @@ namespace CHECK_EQUAL(etl::strlen(p_text), text.capacity()); CHECK_EQUAL(etl::strlen(p_text), text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -174,9 +171,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -189,9 +184,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -200,23 +193,21 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -225,9 +216,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -238,7 +227,9 @@ namespace CHECK_EQUAL(buffer.size() - 1, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -246,7 +237,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -254,15 +245,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -272,14 +261,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -288,15 +279,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -306,14 +295,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -322,15 +313,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -340,23 +329,23 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -370,7 +359,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -387,10 +378,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u32string_view view(initial_text.data(), initial_text.size()); - + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -442,7 +432,9 @@ namespace Text text2(textl, buffer2.data(), buffer2.size()); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -456,15 +448,17 @@ namespace Text text2(text, buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -482,8 +476,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -494,7 +488,9 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -502,7 +498,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -510,27 +506,27 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { 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') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -548,10 +544,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -568,8 +562,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -614,8 +611,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -635,10 +635,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -658,8 +656,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -671,11 +672,9 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -686,10 +685,12 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -702,10 +703,12 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -718,13 +721,28 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + 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) { @@ -738,6 +756,7 @@ namespace CHECK_EQUAL(&constText[0], constText.begin()); } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_end) { @@ -762,9 +781,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -783,9 +800,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -800,7 +815,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -815,9 +832,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -838,15 +853,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -890,7 +903,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -917,21 +930,64 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; - text.fill(STR('B')); + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); - bool is_equal = Equal(expected, text); - CHECK(is_equal); + // 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; + } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.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) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); } //************************************************************************* @@ -942,9 +998,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -955,9 +1009,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -967,9 +1019,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -980,9 +1030,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -993,9 +1041,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1005,15 +1051,13 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1023,15 +1067,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1041,15 +1083,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1059,9 +1099,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1069,7 +1107,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1079,9 +1117,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1089,104 +1125,92 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1196,20 +1220,51 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assign_string) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + 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()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + View view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + 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) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1220,14 +1275,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1235,15 +1292,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1252,14 +1307,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1267,15 +1324,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1286,14 +1341,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1302,9 +1359,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1320,7 +1375,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1341,9 +1398,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1362,14 +1417,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1389,15 +1446,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1410,9 +1465,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1423,14 +1476,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1452,11 +1507,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1478,7 +1533,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1490,7 +1545,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1502,7 +1559,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1514,7 +1573,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1524,7 +1585,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1539,9 +1600,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1551,7 +1610,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1566,7 +1625,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1581,7 +1642,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1596,7 +1659,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1611,7 +1676,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1625,7 +1692,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1634,9 +1701,7 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1649,7 +1714,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1662,7 +1727,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1677,7 +1744,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1693,7 +1762,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1708,7 +1779,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1718,9 +1789,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1729,13 +1798,12 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2; - buffer2.fill(0); + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1744,9 +1812,28 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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()); + TextBuffer buffer{0}; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + 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()); } } @@ -1755,7 +1842,7 @@ namespace { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1770,7 +1857,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1780,7 +1869,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1798,7 +1887,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1806,7 +1897,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1820,9 +1911,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1835,9 +1924,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1848,15 +1935,13 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1870,9 +1955,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1886,7 +1969,43 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + 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 } @@ -1901,11 +2020,15 @@ namespace Text append(short_text.c_str(), buffers.data(), buffers.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" } @@ -1913,7 +2036,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1924,9 +2047,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(shorter_text.c_str()); @@ -1939,14 +2060,16 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1955,14 +2078,12 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::u32string::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -1975,9 +2096,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1991,7 +2110,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2005,11 +2126,15 @@ namespace Text append(short_text.c_str(), buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2017,7 +2142,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2028,9 +2153,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2043,7 +2166,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2051,7 +2176,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2062,9 +2187,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2077,7 +2200,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2085,7 +2210,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2098,9 +2223,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2114,7 +2237,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2122,103 +2247,209 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2226,61 +2457,122 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2288,117 +2580,234 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2406,117 +2815,117 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2524,61 +2933,61 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2586,117 +2995,117 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2704,20 +3113,18 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -2725,14 +3132,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2741,15 +3150,13 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -2757,14 +3164,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2774,7 +3183,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2785,23 +3194,19 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2814,21 +3219,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2841,23 +3250,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2870,21 +3275,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2892,7 +3301,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2903,9 +3312,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2918,7 +3325,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2931,9 +3340,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2946,7 +3353,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2954,13 +3363,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + 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)); @@ -2968,9 +3377,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2983,7 +3390,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2996,9 +3405,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3011,62 +3418,43 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); - - CompareText::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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::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); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3077,69 +3465,59 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3196,7 +3574,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3213,17 +3591,17 @@ namespace 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((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((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((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)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3236,8 +3614,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3253,17 +3631,17 @@ namespace 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((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((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((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)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3293,17 +3671,17 @@ namespace 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((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((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((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)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3316,8 +3694,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3333,24 +3711,24 @@ namespace 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((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((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((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)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3364,9 +3742,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3385,15 +3761,13 @@ namespace size_t length1 = text.copy(buffer1, 5, SIZE); CHECK_EQUAL(0U, length1); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3401,16 +3775,14 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3421,7 +3793,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3436,9 +3808,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3451,12 +3821,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3473,13 +3843,44 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u32string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::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")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + 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(TextL::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3487,7 +3888,7 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3506,7 +3907,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } @@ -3518,7 +3919,7 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3537,28 +3938,173 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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"); - std::u32string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3575,19 +4121,46 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::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); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3606,16 +4179,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u32string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3634,15 +4207,15 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3659,7 +4232,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3668,35 +4241,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3705,35 +4314,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3742,35 +4387,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, TextL(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")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3807,7 +4488,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3844,7 +4525,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3881,38 +4562,68 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3943,7 +4654,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3979,7 +4690,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4020,43 +4731,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4097,7 +4843,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4127,16 +4873,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4177,43 +4925,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4249,7 +5032,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4290,7 +5073,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4331,43 +5114,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4403,7 +5221,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4437,7 +5255,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4551,25 +5369,25 @@ namespace { TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -4582,7 +5400,7 @@ namespace Text text2(short_text.c_str(), buffers.data(), buffers.size()); CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -4616,10 +5434,10 @@ namespace { TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -4642,7 +5460,9 @@ namespace 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); @@ -4712,6 +5532,23 @@ namespace CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_after_clear) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + 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) { @@ -4784,9 +5621,7 @@ namespace std::fill(text.data(), text.data() + text.max_size(), STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -4800,9 +5635,7 @@ namespace std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4817,7 +5650,9 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index 2165231f..224d24c1 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -34,6 +34,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u8string.h" @@ -69,21 +70,22 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u8string; - using IText = etl::iu8string; - using CompareText = std::u8string; - using value_t = Text::value_type; - using TextL = etl::u8string<52>; - using TextS = etl::u8string<4>; + using Text = etl::u8string; + using IText = etl::iu8string; + using TextSTD = std::u8string; + using value_t = Text::value_type; + using TextL = etl::u8string<52>; + using TextS = etl::u8string<4>; + using View = etl::u8string_view; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + 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"); @@ -99,7 +101,6 @@ namespace { SetupFixture() { - initial_text = STR("Hello World"); initial_text = STR("Hello World"); insert_text = STR("Insert"); less_text = STR("Hello Vorld"); @@ -121,9 +122,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -131,22 +130,20 @@ namespace { Text text; - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -155,9 +152,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -167,14 +162,16 @@ namespace CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -182,15 +179,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -199,14 +194,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -214,15 +211,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -231,14 +226,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -246,15 +243,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -263,22 +258,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -291,7 +286,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -307,9 +304,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u8string_view view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -324,9 +321,7 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -336,9 +331,7 @@ namespace IText& itext = text; Text text2(itext); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -349,7 +342,9 @@ namespace Text text2(textl); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -359,31 +354,29 @@ namespace Text text(longer_text.c_str()); Text text2(text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + 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); @@ -391,7 +384,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -399,29 +392,29 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + 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') }; + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -436,10 +429,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -453,8 +444,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -472,10 +466,8 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text1.is_truncated()); - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -493,8 +485,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -511,10 +506,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -531,8 +524,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -543,11 +539,9 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -557,10 +551,12 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -572,11 +568,9 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); -#endif } //************************************************************************* @@ -587,53 +581,64 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + 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(&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(&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 = 5; - const size_t NEW_SIZE = 8; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + 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); @@ -644,46 +649,44 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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); @@ -696,24 +699,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + 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(); + 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); @@ -727,35 +728,35 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + 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(text.size(), SIZE); + CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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(); + 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); @@ -768,7 +769,65 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + 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); } //************************************************************************* @@ -781,10 +840,7 @@ namespace bool is_equal = Equal(expected, text); CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -794,9 +850,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -806,9 +860,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -817,9 +869,7 @@ namespace Text text; CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -829,9 +879,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -841,9 +889,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -852,15 +898,13 @@ namespace Text text; CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -868,15 +912,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -884,15 +926,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -900,17 +940,14 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -918,102 +955,87 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + 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() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1021,18 +1043,46 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1041,29 +1091,29 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1071,29 +1121,29 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1103,14 +1153,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1118,9 +1170,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1135,14 +1185,16 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; @@ -1155,16 +1207,14 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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 + 1; + const size_t EXCESS_SIZE = SIZE + 1UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; compare_text.fill(INITIAL_VALUE); @@ -1175,14 +1225,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1200,15 +1252,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1219,9 +1269,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1232,14 +1280,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1258,12 +1308,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1283,42 +1333,48 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + 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 = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + 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.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + 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.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1328,23 +1384,21 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1354,66 +1408,74 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; - const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const size_t INSERT_SIZE = 4UL; + const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1423,22 +1485,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + 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, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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); } @@ -1447,22 +1507,24 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1472,12 +1534,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1488,12 +1552,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1504,32 +1570,30 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_self) { - size_t length = TextL::MAX_SIZE / 2; + size_t length = TextL::MAX_SIZE / 2UL; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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); @@ -1537,20 +1601,37 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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 = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); - Text text(initial_text.begin(), initial_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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); @@ -1559,7 +1640,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1567,13 +1650,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(longer_text.begin(), longer_text.end()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + 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); @@ -1582,7 +1665,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1590,9 +1675,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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()); @@ -1600,12 +1685,10 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + 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); @@ -1615,12 +1698,10 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + 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()); @@ -1628,15 +1709,13 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1646,9 +1725,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1662,14 +1739,49 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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" + //#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 @@ -1678,15 +1790,17 @@ namespace text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1696,7 +1810,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1710,25 +1824,27 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + 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, std::u8string::npos); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Partial string. @@ -1743,7 +1859,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1758,7 +1874,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1773,7 +1891,9 @@ namespace text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1781,7 +1901,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -1791,7 +1911,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1805,7 +1925,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1813,7 +1935,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1823,7 +1945,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1837,7 +1959,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1845,7 +1969,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1855,7 +1979,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1870,7 +1994,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1878,101 +2004,219 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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 } @@ -1980,59 +2224,127 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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 } @@ -2040,115 +2352,247 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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 } @@ -2156,115 +2600,123 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2272,59 +2724,63 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText(STR("Replace")).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(!text.is_truncated()); + 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, CompareText(STR("Replace with some 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2332,115 +2788,123 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2448,17 +2912,17 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2467,14 +2931,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2483,14 +2949,14 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2499,14 +2965,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2516,7 +2984,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -2526,21 +2994,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + 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, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2554,21 +3022,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2582,21 +3054,21 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + 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, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2610,21 +3082,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2632,7 +3108,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + 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')); @@ -2642,7 +3118,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2656,7 +3132,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2670,7 +3148,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2684,7 +3162,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2692,11 +3172,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + 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)); @@ -2705,7 +3185,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2719,7 +3199,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2733,7 +3215,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2747,58 +3229,60 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -2810,59 +3294,59 @@ namespace CHECK_EQUAL(text.size(), size_t(0)); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -2907,7 +3391,7 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); const Text greater(greater_text.c_str()); @@ -2922,17 +3406,17 @@ namespace 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((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((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((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)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -2942,8 +3426,8 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + 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)); @@ -2957,17 +3441,17 @@ namespace 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((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((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((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)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -2992,17 +3476,17 @@ namespace 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((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((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((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)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3012,8 +3496,8 @@ namespace 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)); + 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)); @@ -3027,23 +3511,23 @@ namespace 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((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((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((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)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3057,7 +3541,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3077,20 +3561,20 @@ namespace CHECK_EQUAL(0U, length1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + 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, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3098,7 +3582,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3110,7 +3594,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3124,7 +3608,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3138,14 +3622,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); - etl::u8string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); position2 = haystack.find(needle, position2); @@ -3156,11 +3640,42 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u8string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + 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); } //************************************************************************* @@ -3170,11 +3685,11 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1); position2 = haystack.find(needle, position2); @@ -3185,11 +3700,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3199,11 +3714,11 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1, 3); position2 = haystack.find(needle, position2, 3); @@ -3214,11 +3729,137 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iu8string::npos, position2); + 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])); } //************************************************************************* @@ -3226,14 +3867,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); - etl::u8string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3243,23 +3884,51 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3269,23 +3938,23 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -3296,19 +3965,19 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iu8string::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + etl::iu8string::size_type position1 = TextL::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3319,16 +3988,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -3363,112 +4032,217 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + 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(CompareText(STR("ABCDEE"))); + 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(CompareText(STR("ABCDEG"))); + 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(CompareText(STR("ABCDE"))); + 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(CompareText(STR("ABCDEFG"))); + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + 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, CompareText(STR("ABCDEE"))); + 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, CompareText(STR("ABCDEG"))); + 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, CompareText(STR("ABCDE"))); + 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, CompareText(STR("ABCDEFG"))); + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + 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, CompareText(STR("aaABCDEEbb")), 2, 6); + 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, CompareText(STR("aaABCDEGbb")), 2, 6); + 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, CompareText(STR("aaABCDEbb")), 2, 5); + 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, CompareText(STR("aaABCDEFGbb")), 2, 7); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -3503,7 +4277,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3538,7 +4312,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3573,36 +4347,65 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + 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(CompareText(STR("WXYZ"))); + 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(CompareText(STR("ZCXF")), 3); + 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(CompareText(STR("ZCXF")), 100); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -3631,7 +4434,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -3665,7 +4468,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -3704,41 +4507,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + 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(CompareText(STR("WXYZ")), 3); + 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(CompareText(STR("ZCXE")), 5); + 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(CompareText(STR("ZCXE")), compare_text.size()); + 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(CompareText(STR("ZCXE")), 100); + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -3777,7 +4614,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -3814,7 +4651,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -3853,41 +4690,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + 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(CompareText(STR("ZAXB"))); + 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(CompareText(STR("ZAXB")), 3); + 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(CompareText(STR("ZAXB")), compare_text.size()); + 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(CompareText(STR("ZAXB")), 100); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -3921,7 +4792,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -3960,7 +4831,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -3999,41 +4870,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + 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(CompareText(STR("ZEXD")), 3); + 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(CompareText(STR("ZEXD")), 5); + 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(CompareText(STR("ZEXD")), compare_text.size()); + 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(CompareText(STR("ZEXD")), 100); + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -4067,7 +4972,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -4099,7 +5004,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); @@ -4205,25 +5110,25 @@ namespace TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) { Text text(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -4232,8 +5137,8 @@ namespace Text text1(short_text.c_str()); TextS text2(short_text.c_str()); - CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_FALSE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -4248,7 +5153,7 @@ namespace Text text2(short_text.c_str()); CHECK(text1.is_truncated()); - CHECK(!text2.is_truncated()); + CHECK_FALSE(text2.is_truncated()); // Clear text but not the truncate flag. text1.erase(text1.begin(), text1.end()); @@ -4263,10 +5168,10 @@ namespace TEST_FIXTURE(SetupFixture, test_clear_truncated) { Text text(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -4287,7 +5192,9 @@ namespace 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); @@ -4433,7 +5340,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } @@ -4448,7 +5355,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4463,11 +5370,12 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } }; } - -#endif +#endif \ No newline at end of file diff --git a/test/test_string_u8_external_buffer.cpp b/test/test_string_u8_external_buffer.cpp index bc2caaaf..296ee669 100644 --- a/test/test_string_u8_external_buffer.cpp +++ b/test/test_string_u8_external_buffer.cpp @@ -34,6 +34,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u8string.h" #include "etl/fnv_1.h" @@ -75,20 +76,22 @@ namespace using Text = etl::u8string_ext; using IText = etl::iu8string; using TextL = etl::u8string; - using CompareText = std::u8string; + using TextSTD = std::u8string; using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using View = etl::u8string_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"); @@ -131,9 +134,7 @@ namespace CHECK_EQUAL(SIZE, text.capacity()); CHECK_EQUAL(SIZE, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -147,9 +148,7 @@ namespace CHECK_EQUAL(length, text.capacity()); CHECK_EQUAL(length, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -162,9 +161,7 @@ namespace CHECK_EQUAL(etl::strlen(p_text), text.capacity()); CHECK_EQUAL(etl::strlen(p_text), text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -177,9 +174,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -192,9 +187,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -203,23 +196,21 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -228,9 +219,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -241,7 +230,9 @@ namespace CHECK_EQUAL(buffer.size() - 1, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -249,7 +240,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -257,15 +248,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -275,14 +264,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -291,15 +282,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -309,14 +298,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -325,15 +316,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -343,23 +332,23 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -373,7 +362,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -390,10 +381,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u8string_view view(initial_text.data(), initial_text.size()); - + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -445,7 +435,9 @@ namespace Text text2(textl, buffer2.data(), buffer2.size()); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -459,15 +451,17 @@ namespace Text text2(text, buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -485,8 +479,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -497,7 +491,9 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -505,7 +501,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -513,27 +509,27 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { 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') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -551,10 +547,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -571,8 +565,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -617,8 +614,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -638,10 +638,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -661,8 +659,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -674,11 +675,9 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -689,10 +688,12 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -705,10 +706,12 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -721,13 +724,28 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + 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) { @@ -766,9 +784,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -787,9 +803,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -804,7 +818,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -819,9 +835,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -842,15 +856,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -894,7 +906,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -921,21 +933,64 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; - text.fill(STR('B')); + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); - bool is_equal = Equal(expected, text); - CHECK(is_equal); + // 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; + } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.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) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); } //************************************************************************* @@ -946,9 +1001,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -959,9 +1012,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -971,9 +1022,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -984,9 +1033,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -997,9 +1044,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1009,15 +1054,13 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1027,15 +1070,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1045,15 +1086,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1063,9 +1102,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1073,7 +1110,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1083,9 +1120,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1093,104 +1128,92 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1200,20 +1223,51 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assign_string) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + 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()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + View view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + 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) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1224,14 +1278,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1239,15 +1295,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1256,14 +1310,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1271,15 +1327,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1290,14 +1344,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1306,9 +1362,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1324,7 +1378,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1345,9 +1401,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1366,14 +1420,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1393,15 +1449,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1414,9 +1468,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1427,14 +1479,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1456,11 +1510,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1482,7 +1536,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1494,7 +1548,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1506,7 +1562,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1518,7 +1576,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1528,7 +1588,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1543,9 +1603,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1555,7 +1613,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1570,7 +1628,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1585,7 +1645,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1600,7 +1662,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1615,7 +1679,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1629,7 +1695,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1638,9 +1704,7 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1653,7 +1717,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1666,7 +1730,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1681,7 +1747,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1697,7 +1765,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1712,7 +1782,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1722,27 +1792,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - size_t s = short_text.size(); - (void)s; - - assert(s <= 5); - - for (size_t offset = s; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer{0}; + buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1751,30 +1815,42 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_2) + 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()); + TextBuffer buffer{0}; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + 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) { -#include "etl/private/diagnostic_array_bounds_push.h" for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); - TextBuffer buffer{ 0 }; + TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1784,10 +1860,11 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } -#include "etl/private/diagnostic_pop.h" } //************************************************************************* @@ -1795,7 +1872,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1813,7 +1890,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1821,7 +1900,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1835,9 +1914,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1850,9 +1927,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1863,15 +1938,13 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1885,9 +1958,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1901,7 +1972,43 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + 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 } @@ -1916,11 +2023,15 @@ namespace Text append(short_text.c_str(), buffers.data(), buffers.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" } @@ -1928,7 +2039,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1939,9 +2050,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(shorter_text.c_str()); @@ -1954,14 +2063,16 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1970,14 +2081,12 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::u8string::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -1990,9 +2099,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2006,7 +2113,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2020,11 +2129,15 @@ namespace Text append(short_text.c_str(), buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2032,7 +2145,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2043,9 +2156,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2058,7 +2169,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2066,7 +2179,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2077,9 +2190,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2092,7 +2203,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2100,7 +2213,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2113,9 +2226,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2129,7 +2240,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2137,103 +2250,209 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2241,61 +2460,122 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2303,117 +2583,234 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2421,117 +2818,117 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2539,61 +2936,61 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some 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(text.is_truncated()); + 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, CompareText(STR("Replace")).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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2601,117 +2998,117 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2719,20 +3116,18 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -2740,14 +3135,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2756,15 +3153,13 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -2772,14 +3167,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2789,7 +3186,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2800,23 +3197,19 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2829,21 +3222,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2856,23 +3253,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2885,21 +3278,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2907,7 +3304,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2918,9 +3315,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2933,7 +3328,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2946,9 +3343,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2961,7 +3356,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2969,13 +3366,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + 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)); @@ -2983,9 +3380,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2998,7 +3393,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3011,9 +3408,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3026,62 +3421,43 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); - - CompareText::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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::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); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3092,69 +3468,59 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3211,7 +3577,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3228,17 +3594,17 @@ namespace 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((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((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((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)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3251,8 +3617,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3268,17 +3634,17 @@ namespace 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((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((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((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)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3308,17 +3674,17 @@ namespace 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((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((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((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)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3331,8 +3697,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3348,24 +3714,24 @@ namespace 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((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((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((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)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3379,9 +3745,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3400,15 +3764,13 @@ namespace size_t length1 = text.copy(buffer1, 5, SIZE); CHECK_EQUAL(0U, length1); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3416,16 +3778,14 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3436,7 +3796,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3451,9 +3811,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3466,12 +3824,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3488,13 +3846,44 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u8string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::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")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + 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(TextL::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3502,7 +3891,7 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3521,7 +3910,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } @@ -3533,7 +3922,7 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3552,28 +3941,173 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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"); - std::u8string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3590,19 +4124,46 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::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); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3621,16 +4182,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u8string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3649,15 +4210,15 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3674,7 +4235,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3683,35 +4244,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3720,35 +4317,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3757,35 +4390,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, TextL(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")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3822,7 +4491,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3859,7 +4528,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3896,38 +4565,68 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3958,7 +4657,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3994,7 +4693,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4035,43 +4734,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4112,7 +4846,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4142,16 +4876,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4192,43 +4928,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4264,7 +5035,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4305,7 +5076,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4346,43 +5117,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4418,7 +5224,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4452,7 +5258,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4566,25 +5372,25 @@ namespace { TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -4597,7 +5403,7 @@ namespace Text text2(short_text.c_str(), buffers.data(), buffers.size()); CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -4631,10 +5437,10 @@ namespace { TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -4657,7 +5463,9 @@ namespace 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); @@ -4816,9 +5624,7 @@ namespace std::fill(text.data(), text.data() + text.max_size(), STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -4832,9 +5638,7 @@ namespace std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4849,7 +5653,9 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index 08c28a55..598f6332 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include "etl/string_view.h" #include "etl/string.h" #include "etl/wstring.h" +#include "etl/u8string.h" #include "etl/u16string.h" #include "etl/u32string.h" #include "etl/hash.h" @@ -45,12 +46,18 @@ namespace { using View = etl::string_view; using WView = etl::wstring_view; +#if ETL_USING_CPP20 + using U8View = etl::u8string_view; +#endif using U16View = etl::u16string_view; using U32View = etl::u32string_view; etl::string<11> etltext = "Hello World"; std::string text = "Hello World"; std::wstring wtext = L"Hello World"; +#if ETL_USING_CPP20 + std::u8string u8text = u8"Hello World"; +#endif std::u16string u16text = u"Hello World"; std::u32string u32text = U"Hello World"; std::string text_smaller = "Hello Worlc"; @@ -735,6 +742,39 @@ namespace CHECK(!view.ends_with("Hello Worldxxxxxx")); } + //************************************************************************* + TEST(test_contains) + { + const char* s1 = "Hello"; + const char* s2 = "llo Wor"; + const char* s3 = "World"; + const char* s4 = "Xorld"; + const char* s5 = "Hello Worldxxxxxx"; + + View view(text.c_str()); + View v1(s1); + View v2(s2); + View v3(s3); + View v4(s4); + View v5(s5); + + CHECK_TRUE(view.contains(v1)); + CHECK_TRUE(view.contains(v2)); + CHECK_TRUE(view.contains(v3)); + CHECK_FALSE(view.contains(v4)); + CHECK_FALSE(view.contains(v5)); + + CHECK_TRUE(view.contains('H')); + CHECK_TRUE(view.contains('l')); + CHECK_FALSE(view.contains('X')); + + CHECK_TRUE(view.contains(s1)); + CHECK_TRUE(view.contains(s2)); + CHECK_TRUE(view.contains(s3)); + CHECK_FALSE(view.contains(s4)); + CHECK_FALSE(view.contains(s5)); + } + //************************************************************************* TEST(test_find) { @@ -1080,5 +1120,40 @@ namespace CHECK_TRUE((u16view == U16View{ u"Hello World", etl::strlen(u"Hello World") })); CHECK_TRUE((u32view == U32View{ U"Hello World", etl::strlen(U"Hello World") })); } + + //************************************************************************* +#if ETL_USING_STL + TEST(write_to_std_stream) + { + View view{ "Hello World" }; + WView wview{ L"Hello World" }; + U16View u16view{ u"Hello World" }; + U32View u32view{ U"Hello World" }; + + std::stringstream sstream; + std::wstringstream wsstream; + std::basic_stringstream u16sstream; + std::basic_stringstream u32sstream; + + sstream << view; + std::string sstream_string = sstream.str(); + wsstream << wview; + std::wstring wsstream_string = wsstream.str(); + u16sstream << u16view; + std::u16string u16sstream_string = u16sstream.str(); + u32sstream << u32view; + std::u32string u32sstream_string = u32sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + WView wsstream_view(wsstream_string.data(), wsstream_string.size()); + U16View u16sstream_view(u16sstream_string.data(), u16sstream_string.size()); + U32View u32sstream_view(u32sstream_string.data(), u32sstream_string.size()); + + CHECK_TRUE(view == sstream_view); + CHECK_TRUE(wview == wsstream_view); + CHECK_TRUE(u16view == u16sstream_view); + CHECK_TRUE(u32view == u32sstream_view); + } +#endif }; } diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index f3e852b7..1a2acec5 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/wstring.h" @@ -66,23 +67,25 @@ namespace { static const size_t SIZE = 11; - using Text = etl::wstring; - using IText = etl::iwstring; - using CompareText = std::wstring; - using value_t = Text::value_type; - using TextL = etl::wstring<52>; - using TextS = etl::wstring<4>; + using Text = etl::wstring; + using IText = etl::iwstring; + using TextSTD = std::wstring; + using value_t = Text::value_type; + using TextL = etl::wstring<52>; + using TextS = etl::wstring<4>; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText short_text; - CompareText longer_text; + 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 Text::value_type* pinitial_text = STR("Hello World"); + using View = etl::wstring_view; + + const value_t* pinitial_text = STR("Hello World"); //************************************************************************* template @@ -96,7 +99,6 @@ namespace { SetupFixture() { - initial_text = STR("Hello World"); initial_text = STR("Hello World"); insert_text = STR("Insert"); less_text = STR("Hello Vorld"); @@ -118,9 +120,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -128,22 +128,20 @@ namespace { Text text; - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -152,9 +150,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -164,14 +160,16 @@ namespace CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -179,15 +177,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -196,14 +192,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -211,15 +209,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -228,14 +224,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -243,15 +241,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -260,22 +256,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -288,7 +284,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -304,9 +302,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::wstring_view view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -321,9 +319,7 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -333,9 +329,7 @@ namespace IText& itext = text; Text text2(itext); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -346,7 +340,9 @@ namespace Text text2(textl); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -356,31 +352,29 @@ namespace Text text(longer_text.c_str()); Text text2(text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + 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); @@ -388,7 +382,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -396,29 +390,29 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + 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') }; + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -433,10 +427,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -450,8 +442,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -469,10 +464,8 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text1.is_truncated()); - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -490,8 +483,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -508,10 +504,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -528,8 +522,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -540,11 +537,9 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -554,10 +549,12 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -569,11 +566,9 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); -#endif } //************************************************************************* @@ -584,23 +579,36 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + 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) { @@ -614,23 +622,21 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + 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); @@ -641,46 +647,44 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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); @@ -693,24 +697,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + 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(); + 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); @@ -724,35 +726,35 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + 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(text.size(), SIZE); + CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + 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(); + 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); @@ -765,7 +767,65 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + 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); } //************************************************************************* @@ -778,10 +838,7 @@ namespace bool is_equal = Equal(expected, text); CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -791,9 +848,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -803,9 +858,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -814,9 +867,7 @@ namespace Text text; CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -826,9 +877,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -838,9 +887,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -849,15 +896,13 @@ namespace Text text; CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -865,15 +910,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -881,15 +924,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -897,17 +938,14 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -915,102 +953,87 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + 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() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1018,18 +1041,46 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1038,29 +1089,29 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1068,29 +1119,29 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1100,14 +1151,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1115,9 +1168,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1132,14 +1183,16 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; @@ -1152,16 +1205,14 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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 + 1; + const size_t EXCESS_SIZE = SIZE + 1UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; compare_text.fill(INITIAL_VALUE); @@ -1172,14 +1223,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1197,15 +1250,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1216,9 +1267,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1229,14 +1278,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1255,12 +1306,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1280,42 +1331,48 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + 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 = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + 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.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + 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.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1325,23 +1382,21 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1351,66 +1406,74 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; - const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const size_t INSERT_SIZE = 4UL; + const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + 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.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1420,22 +1483,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + 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, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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); } @@ -1444,22 +1505,24 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1469,12 +1532,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1485,12 +1550,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1501,32 +1568,30 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_self) { - size_t length = TextL::MAX_SIZE / 2; + size_t length = TextL::MAX_SIZE / 2UL; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + 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); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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); @@ -1534,20 +1599,37 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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 = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); - Text text(initial_text.begin(), initial_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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); @@ -1556,7 +1638,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1564,13 +1648,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(longer_text.begin(), longer_text.end()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + 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); @@ -1579,7 +1663,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1587,9 +1673,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + 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()); @@ -1597,12 +1683,10 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + 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); @@ -1612,12 +1696,10 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + 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()); @@ -1625,15 +1707,13 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1643,9 +1723,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1659,14 +1737,49 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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" + //#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 @@ -1675,15 +1788,17 @@ namespace text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1693,7 +1808,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1707,25 +1822,27 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + 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, std::wstring::npos); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Partial string. @@ -1740,7 +1857,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1755,7 +1872,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1770,7 +1889,9 @@ namespace text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1778,7 +1899,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -1788,7 +1909,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1802,7 +1923,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1810,7 +1933,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1820,7 +1943,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1834,7 +1957,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1842,7 +1967,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1852,7 +1977,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1867,7 +1992,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1875,101 +2002,219 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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 } @@ -1977,59 +2222,127 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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 } @@ -2037,115 +2350,247 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); + 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, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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 } @@ -2153,115 +2598,123 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2269,59 +2722,63 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); + 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2329,115 +2786,123 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + 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, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2445,17 +2910,17 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2464,14 +2929,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2480,14 +2947,14 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2496,14 +2963,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2513,7 +2982,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -2523,21 +2992,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + 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, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2551,21 +3020,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2579,21 +3052,21 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + 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, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2607,21 +3080,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2629,7 +3106,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + 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')); @@ -2639,7 +3116,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2653,7 +3130,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2667,7 +3146,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2681,7 +3160,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2689,11 +3170,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + 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)); @@ -2702,7 +3183,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2716,7 +3197,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2730,7 +3213,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2744,58 +3227,60 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -2807,59 +3292,59 @@ namespace CHECK_EQUAL(text.size(), size_t(0)); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + 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(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -2904,7 +3389,7 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); const Text greater(greater_text.c_str()); @@ -2919,17 +3404,17 @@ namespace 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((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((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((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)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -2939,8 +3424,8 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + 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)); @@ -2954,17 +3439,17 @@ namespace 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((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((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((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)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -2989,17 +3474,17 @@ namespace 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((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((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((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)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3009,8 +3494,8 @@ namespace 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)); + 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)); @@ -3024,23 +3509,23 @@ namespace 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((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((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((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)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3054,7 +3539,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3074,20 +3559,20 @@ namespace CHECK_EQUAL(0U, length1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + 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, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3095,7 +3580,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3107,7 +3592,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3121,7 +3606,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3135,14 +3620,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); - etl::wstring<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); position2 = haystack.find(needle, position2); @@ -3153,11 +3638,42 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::wstring<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + 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); } //************************************************************************* @@ -3167,11 +3683,11 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1); position2 = haystack.find(needle, position2); @@ -3182,11 +3698,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3196,11 +3712,11 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1, 3); position2 = haystack.find(needle, position2, 3); @@ -3211,11 +3727,137 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iwstring::npos, position2); + 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])); } //************************************************************************* @@ -3223,14 +3865,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); - etl::wstring<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3240,23 +3882,51 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3266,23 +3936,23 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -3293,19 +3963,19 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iwstring::npos, position2); + 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"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + etl::iwstring::size_type position1 = TextL::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3316,16 +3986,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -3360,112 +4030,217 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + 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(CompareText(STR("ABCDEE"))); + 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(CompareText(STR("ABCDEG"))); + 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(CompareText(STR("ABCDE"))); + 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(CompareText(STR("ABCDEFG"))); + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + 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, CompareText(STR("ABCDEE"))); + 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, CompareText(STR("ABCDEG"))); + 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, CompareText(STR("ABCDE"))); + 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, CompareText(STR("ABCDEFG"))); + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + 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, CompareText(STR("aaABCDEEbb")), 2, 6); + 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, CompareText(STR("aaABCDEGbb")), 2, 6); + 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, CompareText(STR("aaABCDEbb")), 2, 5); + 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, CompareText(STR("aaABCDEFGbb")), 2, 7); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -3500,7 +4275,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3535,7 +4310,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -3570,36 +4345,65 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + 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(CompareText(STR("WXYZ"))); + 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(CompareText(STR("ZCXF")), 3); + 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(CompareText(STR("ZCXF")), 100); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -3628,7 +4432,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -3662,7 +4466,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -3701,41 +4505,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + 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(CompareText(STR("WXYZ")), 3); + 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(CompareText(STR("ZCXE")), 5); + 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(CompareText(STR("ZCXE")), compare_text.size()); + 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(CompareText(STR("ZCXE")), 100); + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -3774,7 +4612,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -3811,7 +4649,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -3850,41 +4688,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + 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(CompareText(STR("ZAXB"))); + 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(CompareText(STR("ZAXB")), 3); + 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(CompareText(STR("ZAXB")), compare_text.size()); + 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(CompareText(STR("ZAXB")), 100); + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -3918,7 +4790,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -3957,7 +4829,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -3996,41 +4868,75 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + 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(CompareText(STR("ZEXD")), 3); + 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(CompareText(STR("ZEXD")), 5); + 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(CompareText(STR("ZEXD")), compare_text.size()); + 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(CompareText(STR("ZEXD")), 100); + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -4064,7 +4970,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -4096,7 +5002,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); @@ -4202,25 +5108,25 @@ namespace TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) { Text text(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -4229,8 +5135,8 @@ namespace Text text1(short_text.c_str()); TextS text2(short_text.c_str()); - CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_FALSE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -4245,7 +5151,7 @@ namespace Text text2(short_text.c_str()); CHECK(text1.is_truncated()); - CHECK(!text2.is_truncated()); + CHECK_FALSE(text2.is_truncated()); // Clear text but not the truncate flag. text1.erase(text1.begin(), text1.end()); @@ -4260,10 +5166,10 @@ namespace TEST_FIXTURE(SetupFixture, test_clear_truncated) { Text text(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -4284,7 +5190,9 @@ namespace 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); @@ -4430,7 +5338,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } @@ -4445,7 +5353,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4460,9 +5368,29 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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::wstringstream 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/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index a30dc63f..36d18c8f 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/wstring.h" #include "etl/fnv_1.h" @@ -69,24 +70,28 @@ namespace static constexpr size_t SIZE_L = 52; static constexpr size_t SIZE_S = 4; - using Text = etl::wstring_ext; - using IText = etl::iwstring; - using TextL = etl::wstring; - using CompareText = std::wstring; - using value_t = Text::value_type; + using Text = etl::wstring_ext; + using IText = etl::iwstring; + using TextL = etl::wstring; + using TextSTD = std::wstring; + using value_t = Text::value_type; + + using View = etl::wstring_view; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using View = etl::wstring_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"); @@ -129,9 +134,7 @@ namespace CHECK_EQUAL(SIZE, text.capacity()); CHECK_EQUAL(SIZE, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -145,9 +148,7 @@ namespace CHECK_EQUAL(length, text.capacity()); CHECK_EQUAL(length, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -160,9 +161,7 @@ namespace CHECK_EQUAL(etl::strlen(p_text), text.capacity()); CHECK_EQUAL(etl::strlen(p_text), text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -175,9 +174,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -190,9 +187,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -201,23 +196,21 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -226,9 +219,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -239,7 +230,9 @@ namespace CHECK_EQUAL(buffer.size() - 1, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -247,7 +240,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -255,15 +248,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -273,14 +264,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -289,15 +282,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -307,14 +298,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -323,15 +316,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -341,23 +332,23 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -371,7 +362,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -388,10 +381,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::wstring_view view(initial_text.data(), initial_text.size()); - + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -443,7 +435,9 @@ namespace Text text2(textl, buffer2.data(), buffer2.size()); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -457,15 +451,17 @@ namespace Text text2(text, buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -483,8 +479,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -495,7 +491,9 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -503,7 +501,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -511,27 +509,27 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { 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') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -549,10 +547,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -569,8 +565,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -615,8 +614,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -636,10 +638,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -659,8 +659,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -672,11 +675,9 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -687,10 +688,12 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -703,10 +706,12 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -719,13 +724,28 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + 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) { @@ -734,7 +754,7 @@ namespace TextBuffer buffer2{0}; const Text constText(initial_text.c_str(), buffer2.data(), buffer2.size()); - + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } @@ -764,9 +784,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -785,9 +803,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -802,7 +818,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -817,9 +835,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -840,15 +856,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -892,7 +906,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -919,21 +933,64 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; - text.fill(STR('B')); + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); - bool is_equal = Equal(expected, text); - CHECK(is_equal); + // 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; + } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.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) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); } //************************************************************************* @@ -944,9 +1001,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -957,9 +1012,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -969,9 +1022,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -982,9 +1033,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -995,9 +1044,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1007,15 +1054,13 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1025,15 +1070,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1043,15 +1086,13 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1061,9 +1102,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1071,7 +1110,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1081,9 +1120,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1091,104 +1128,92 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1198,20 +1223,51 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assign_string) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + 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()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + View view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + 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) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1222,14 +1278,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1237,15 +1295,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1254,14 +1310,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1269,15 +1327,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1288,14 +1344,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1304,9 +1362,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1322,7 +1378,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1343,9 +1401,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1364,14 +1420,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1391,15 +1449,13 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1412,9 +1468,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1425,14 +1479,16 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1454,11 +1510,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1480,7 +1536,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1492,7 +1548,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1504,7 +1562,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1516,7 +1576,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1526,7 +1588,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1541,9 +1603,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1553,7 +1613,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1568,7 +1628,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1583,7 +1645,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1598,7 +1662,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1613,7 +1679,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1627,7 +1695,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1636,9 +1704,7 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1651,7 +1717,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1664,7 +1730,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1679,7 +1747,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1695,7 +1765,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1710,7 +1782,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1720,9 +1792,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1731,8 +1801,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; + buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); TextBuffer buffer2{0}; @@ -1744,9 +1815,28 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + 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()); + TextBuffer buffer{0}; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + 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()); } } @@ -1755,7 +1845,7 @@ namespace { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1770,7 +1860,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1780,7 +1872,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1798,7 +1890,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1806,7 +1900,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1820,9 +1914,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1835,9 +1927,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1848,15 +1938,13 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1870,9 +1958,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1886,7 +1972,43 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + 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 } @@ -1901,11 +2023,15 @@ namespace Text append(short_text.c_str(), buffers.data(), buffers.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" } @@ -1913,7 +2039,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1924,9 +2050,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(shorter_text.c_str()); @@ -1939,14 +2063,16 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1955,14 +2081,12 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::wstring::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -1975,9 +2099,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1991,7 +2113,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2005,11 +2129,15 @@ namespace Text append(short_text.c_str(), buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2017,7 +2145,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2028,9 +2156,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2043,7 +2169,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2051,7 +2179,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2062,9 +2190,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2077,7 +2203,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2085,7 +2213,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2098,9 +2226,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2114,7 +2240,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2122,103 +2250,209 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2226,61 +2460,122 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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, CompareText(STR("Replace"))); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some text"))); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2288,117 +2583,234 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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, CompareText(STR("Replace")), 1, 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + 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(text.is_truncated()); + 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, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + 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(text.is_truncated()); + 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()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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); + CHECK_FALSE(text.is_truncated()); + + // 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 } @@ -2406,117 +2818,117 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2524,61 +2936,61 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, CompareText(STR("Replace with some 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, STR("Replace with some text")); + 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(text.is_truncated()); + 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, STR("Replace")); + 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, STR("Replace")); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // 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, STR("Replace with some text")); + 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, STR("Replace with some text")); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2586,117 +2998,117 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + 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, CompareText::npos, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2704,20 +3116,18 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -2725,14 +3135,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2741,15 +3153,13 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + 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, STR("Replace"), 5); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -2757,14 +3167,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + 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, STR("Replace with some text"), 15); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2774,7 +3186,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2785,23 +3197,19 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2814,21 +3222,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2841,23 +3253,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2870,21 +3278,25 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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, CompareText::npos, 15, STR('A')); + 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(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2892,7 +3304,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2903,9 +3315,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2918,7 +3328,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2931,9 +3343,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2946,7 +3356,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2954,13 +3366,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + 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)); @@ -2968,9 +3380,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2983,7 +3393,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2996,9 +3408,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3011,62 +3421,43 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); - - CompareText::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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::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); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3077,69 +3468,59 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3196,7 +3577,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3213,17 +3594,17 @@ namespace 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((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((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((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)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3236,8 +3617,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3253,17 +3634,17 @@ namespace 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((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((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((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)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3293,17 +3674,17 @@ namespace 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((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((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((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)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3316,8 +3697,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3333,24 +3714,24 @@ namespace 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((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((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((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)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3364,9 +3745,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3385,15 +3764,13 @@ namespace size_t length1 = text.copy(buffer1, 5, SIZE); CHECK_EQUAL(0U, length1); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3401,16 +3778,14 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + 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(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3421,7 +3796,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3436,9 +3811,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3451,12 +3824,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3473,13 +3846,44 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::wstring<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::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")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + 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(TextL::npos, position2); + + View pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3487,7 +3891,7 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3506,7 +3910,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } @@ -3518,7 +3922,7 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3537,28 +3941,173 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + 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"); - std::wstring compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3575,19 +4124,46 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + View needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::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); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3606,16 +4182,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::wstring::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3634,15 +4210,15 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -3659,7 +4235,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3668,35 +4244,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3705,35 +4317,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, TextL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, TextL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, TextL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, TextL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, TextL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3742,35 +4390,71 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, TextL(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")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3807,7 +4491,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3844,7 +4528,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3881,38 +4565,68 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3943,7 +4657,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3979,7 +4693,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4020,43 +4734,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4097,7 +4846,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4127,16 +4876,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4177,43 +4928,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4249,7 +5035,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4290,7 +5076,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4331,43 +5117,78 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(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")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + 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) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4403,7 +5224,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4437,7 +5258,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4551,25 +5372,25 @@ namespace { TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -4582,7 +5403,7 @@ namespace Text text2(short_text.c_str(), buffers.data(), buffers.size()); CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -4616,10 +5437,10 @@ namespace { TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -4642,7 +5463,9 @@ namespace 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); @@ -4712,6 +5535,23 @@ namespace CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_after_clear) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + 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) { @@ -4784,9 +5624,7 @@ namespace std::fill(text.data(), text.data() + text.max_size(), STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -4800,9 +5638,7 @@ namespace std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -4817,9 +5653,30 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + 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) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::wstringstream 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/test_tuple.cpp b/test/test_tuple.cpp new file mode 100644 index 00000000..f4af43f3 --- /dev/null +++ b/test/test_tuple.cpp @@ -0,0 +1,643 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2024 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 "data.h" + +#include "etl/tuple.h" +#include "etl/private/tuple_size.h" + +#include +#include +#include + +namespace +{ + using Data = TestDataDC; + using DataM = TestDataM; + + template + auto to_array(etl::index_sequence) + -> std::array + { + return std::array{Indices...}; + } + + SUITE(test_tuple) + { + //************************************************************************* + TEST(test_tuple_size) + { + using Tuple = etl::tuple; + + Tuple tp; + + CHECK_EQUAL(4U, etl::tuple_size::value); + CHECK_EQUAL(4U, tp.size()); + +#if (ETL_USING_CPP17) + CHECK_EQUAL(4U, etl::tuple_size_v); +#endif + } + + //************************************************************************* + TEST(test_tuple_element) + { + using Tuple = etl::tuple; + + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + } + + //************************************************************************* + TEST(test_default_constructor) + { + etl::tuple tp; + + int i0 = etl::get<0>(tp); + double d1 = etl::get<1>(tp); + int i2 = etl::get<2>(tp); + std::string& s3 = etl::get<3>(tp).value; + + CHECK_EQUAL(0, i0); + CHECK_EQUAL(0, d1); + CHECK_EQUAL(0, i2); + CHECK_TRUE(s3.empty()); + } + + //************************************************************************* + TEST(test_constructor_single_element) + { + etl::tuple tp(1); + + CHECK_EQUAL(1, etl::get<0>(tp)); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + etl::tuple tp; + etl::tuple otherTuple(tp); + } + + //************************************************************************* + TEST(test_copy_constructor_single_element) + { + etl::tuple tp(1); + etl::tuple otherTuple(tp); + } + + //************************************************************************* + TEST(test_copy_assignment) + { + etl::tuple tp(1, 2.2, 3, Data("4")); + etl::tuple otherTuple(5, 6.6, 7, Data("8")); + + otherTuple = tp; + + CHECK_EQUAL(etl::get<0>(tp), etl::get<0>(otherTuple)); + CHECK_EQUAL(etl::get<1>(tp), etl::get<1>(otherTuple)); + CHECK_EQUAL(etl::get<2>(tp), etl::get<2>(otherTuple)); + CHECK_EQUAL(etl::get<3>(tp), etl::get<3>(otherTuple)); + } + + //************************************************************************* + TEST(test_move_assignment) + { + etl::tuple tp(1, 2.2, 3, DataM("4")); + etl::tuple otherTuple(5, 6.6, 7, DataM("8")); + + otherTuple = std::move(tp); + + CHECK_EQUAL(etl::get<0>(otherTuple), 1); + CHECK_EQUAL(etl::get<1>(otherTuple), 2.2); + CHECK_EQUAL(etl::get<2>(otherTuple), 3); + CHECK_EQUAL(etl::get<3>(otherTuple), DataM("4")); + } + + //************************************************************************* + TEST(test_construct_from_parameters) + { + etl::tuple tp(1, 2.2, 3, Data("4")); + + int i0 = etl::get<0>(tp); + double d1 = etl::get<1>(tp); + int i2 = etl::get<2>(tp); + std::string& s3 = etl::get<3>(tp).value; + + CHECK_EQUAL(1, i0); + CHECK_CLOSE(2.2, d1, 0.01); + CHECK_EQUAL(3, i2); + CHECK_EQUAL(std::string("4"), s3); + } + + //************************************************************************* + TEST(test_construct_from_convertible_types) + { + etl::tuple tp(char(1), float(2.2), short(3)); + + int i0 = etl::get<0>(tp); + double d1 = etl::get<1>(tp); + int i2 = etl::get<2>(tp); + + CHECK_EQUAL(1, i0); + CHECK_CLOSE(2.2, d1, 0.01); + CHECK_EQUAL(3, i2); + } + + //************************************************************************* + TEST(test_construct_from_parameters_including_move_only) + { + etl::tuple tp(1, 2.2, 3, etl::move(DataM("4"))); + + int i0 = etl::get<0>(tp); + double d1 = etl::get<1>(tp); + int i2 = etl::get<2>(tp); + std::string& s3 = etl::get<3>(tp).value; + + CHECK_EQUAL(1, i0); + CHECK_CLOSE(2.2, d1, 0.01); + CHECK_EQUAL(3, i2); + CHECK_EQUAL(std::string("4"), s3); + } + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_constructor_from_parameters_using_template_deduction_guideline) + { + etl::tuple tp(1, 2.2, 3, Data("4")); + + int i0 = etl::get<0>(tp); + double d1 = etl::get<1>(tp); + int i2 = etl::get<2>(tp); + std::string& s3 = etl::get<3>(tp).value; + + CHECK_EQUAL(1, i0); + CHECK_CLOSE(2.2, d1, 0.01); + CHECK_EQUAL(3, i2); + CHECK_EQUAL(std::string("4"), s3); + } +#endif + + //************************************************************************* + TEST(test_make_tuple) + { + auto tp1 = etl::make_tuple(1, 2.2, 3, Data("4")); + + int i0 = etl::get<0>(tp1); + double d1 = etl::get<1>(tp1); + int i2 = etl::get<2>(tp1); + std::string& s3 = etl::get<3>(tp1).value; + + CHECK_EQUAL(1, i0); + CHECK_CLOSE(2.2, d1, 0.01); + CHECK_EQUAL(3, i2); + CHECK_EQUAL(std::string("4"), s3); + } + + //************************************************************************* + TEST(test_swap) + { + etl::tuple tp1(1, 2); + etl::tuple tp2(3, 4); + + swap(tp1, tp2); + + CHECK_EQUAL(3, etl::get<0>(tp1)); + CHECK_EQUAL(4, etl::get<1>(tp1)); + + CHECK_EQUAL(1, etl::get<0>(tp2)); + CHECK_EQUAL(2, etl::get<1>(tp2)); + } + + //************************************************************************* + TEST(test_get_using_index_lvalue) + { + etl::tuple data(Data("1"), DataM("3")); + const etl::tuple const_data(Data("2"), DataM("4")); + + Data d0 = etl::get<0>(data); + Data d1 = etl::get<0>(const_data); + DataM d2 = etl::move(etl::get<1>(data)); + DataM d3 = etl::move(etl::get<1>(const_data)); + + CHECK_EQUAL(std::string("1"), d0.value); + CHECK_EQUAL(std::string("2"), d1.value); + CHECK_EQUAL(std::string("3"), d2.value); + CHECK_EQUAL(std::string("4"), d3.value); + } + + //************************************************************************* + TEST(test_get_using_index_rvalue) + { + etl::tuple data(Data("1"), DataM("3")); + const etl::tuple const_data(Data("2"), DataM("4")); + + Data&& d0 = etl::get<0>(etl::move(data)); + const Data&& d1 = etl::get<0>(etl::move(const_data)); + DataM&& d2 = etl::move(etl::get<1>(etl::move(data))); + const DataM&& d3 = etl::move(etl::get<1>(etl::move(const_data))); + + CHECK_EQUAL(std::string("1"), d0.value); + CHECK_EQUAL(std::string("2"), d1.value); + CHECK_EQUAL(std::string("3"), d2.value); + CHECK_EQUAL(std::string("4"), d3.value); + } + + //************************************************************************* + TEST(test_get_using_type_lvalue) + { + etl::tuple data(Data("1"), DataM("3")); + const etl::tuple const_data(Data("2"), DataM("4")); + + Data d0 = etl::get(data); + Data d1 = etl::get(const_data); + DataM d2 = etl::move(etl::get(data)); + DataM d3 = etl::move(etl::get(const_data)); + + CHECK_EQUAL(std::string("1"), d0.value); + CHECK_EQUAL(std::string("2"), d1.value); + CHECK_EQUAL(std::string("3"), d2.value); + CHECK_EQUAL(std::string("4"), d3.value); + } + + //************************************************************************* + TEST(test_get_using_type_rvalue) + { + etl::tuple data(Data("1"), DataM("3")); + const etl::tuple const_data(Data("2"), DataM("4")); + + Data&& d0 = etl::get(etl::move(data)); + const Data&& d1 = etl::get(etl::move(const_data)); + DataM&& d2 = etl::move(etl::get(etl::move(data))); + const DataM&& d3 = etl::move(etl::get(etl::move(const_data))); + + CHECK_EQUAL(std::string("1"), d0.value); + CHECK_EQUAL(std::string("2"), d1.value); + CHECK_EQUAL(std::string("3"), d2.value); + CHECK_EQUAL(std::string("4"), d3.value); + } + + //************************************************************************* + TEST(test_construct_from_pair) + { + ETL_OR_STD::pair p(1, Data("2")); + + etl::tuple tp(p); + + int i = etl::get<0>(tp); + Data d = etl::get<1>(tp); + + CHECK_EQUAL(1, i); + CHECK_EQUAL(std::string("2"), d.value); + } + + //************************************************************************* + TEST(test_construct_from_const_pair) + { + const ETL_OR_STD::pair p(1, Data("2")); + + etl::tuple tp(p); + + int i = etl::get<0>(tp); + Data d = etl::get<1>(tp); + + CHECK_EQUAL(1, i); + CHECK_EQUAL(std::string("2"), d.value); + } + + //************************************************************************* + TEST(test_construct_from_move_only_pair) + { + ETL_OR_STD::pair p(1, etl::move(DataM("2"))); + + etl::tuple tp(etl::move(p)); + + int i = etl::get<0>(tp); + DataM d = etl::move(etl::get<1>(tp)); + + CHECK_EQUAL(1, i); + CHECK_EQUAL(std::string("2"), d.value); + } + + //************************************************************************* + ETL_NODISCARD bool Get() + { + return true; + } + + TEST(test_ignore_t) + { + // Should compile without error. + etl::ignore = Get(); + } + + //************************************************************************* + TEST(test_tie) + { + etl::tuple tp{1, 2.3, 4, Data("Data", 5)}; + + int i1; + double d; + int i2; + Data data; + + etl::tie(i1, d, i2, data) = tp; + + CHECK_EQUAL(etl::get<0>(tp), i1); + CHECK_CLOSE(etl::get<1>(tp), d, 0.01); + CHECK_EQUAL(etl::get<2>(tp), i2); + CHECK_EQUAL(etl::get<3>(tp), data); + } + + //************************************************************************* + TEST(test_moved_tie) + { + etl::tuple tp{1, 2.3, 4, Data("Data", 5)}; + + int i1; + double d; + int i2; + Data data; + + etl::tie(i1, d, i2, data) = etl::move(tp); + + CHECK_EQUAL(etl::get<0>(tp), i1); + CHECK_CLOSE(etl::get<1>(tp), d, 0.01); + CHECK_EQUAL(etl::get<2>(tp), i2); + CHECK_EQUAL(etl::get<3>(tp), data); + } + + //************************************************************************* + TEST(test_tie_from_convertible_types) + { + etl::tuple tp{1, 2.3, 4, Data("Data", 5)}; + + char c; + long double ld; + short s; + Data data; + + etl::tie(c, ld, s, data) = tp; + + CHECK_EQUAL(etl::get<0>(tp), c); + CHECK_CLOSE(etl::get<1>(tp), ld, 0.01); + CHECK_EQUAL(etl::get<2>(tp), s); + CHECK_EQUAL(etl::get<3>(tp), data); + } + + //************************************************************************* + TEST(test_tuple_cat) + { + etl::tuple tp1{1, 2.3}; + etl::tuple tp2{4, Data("Data", 5)}; + + auto tp3 = etl::tuple_cat(tp1, tp2); + + CHECK_EQUAL(etl::get<0>(tp3), etl::get<0>(tp1)); + CHECK_EQUAL(etl::get<1>(tp3), etl::get<1>(tp1)); + CHECK_EQUAL(etl::get<2>(tp3), etl::get<0>(tp2)); + CHECK_EQUAL(etl::get<3>(tp3), etl::get<1>(tp2)); + } + + //************************************************************************* + TEST(test_forward_as_tuple) + { + char v1 = 1; + int v2 = 2; + std::string v3 = "Hello"; + + auto tp = etl::forward_as_tuple(v1, v2, v3); + + CHECK_EQUAL(v1, etl::get<0>(tp)); + CHECK_EQUAL(v2, etl::get<1>(tp)); + CHECK_EQUAL(v3, etl::get<2>(tp)); + } + + ////************************************************************************* + // Uncomment to test. + // TEST(test_static_assert) + //{ + // etl::tuple tp; + + // auto result = etl::get<4>(tp); + //} + + //************************************************************************* + TEST(test_select_tuple_run_time) + { + using Tuple1 = etl::tuple; + using Tuple2 = etl::tuple; + + Tuple1 tp1{1, 2.3, 4, Data("Data", 5)}; + + using Sequence = etl::index_sequence<3, 2, 1, 0>; + Tuple2 tp2 = etl::select_from_tuple(tp1, Sequence()); + + CHECK_EQUAL(etl::get<0>(tp1), etl::get<3>(tp2)); + CHECK_EQUAL(etl::get<1>(tp1), etl::get<2>(tp2)); + CHECK_EQUAL(etl::get<2>(tp1), etl::get<1>(tp2)); + CHECK_EQUAL(etl::get<3>(tp1), etl::get<0>(tp2)); + } + + //************************************************************************* + TEST(test_select_a_subset_of_a_tuple_using_a_run_time_index_sequence) + { + using Tuple1 = etl::tuple; + using Tuple2 = etl::tuple; + + Tuple1 tp1{1, 2.3, 4, Data("Data", 5)}; + + using Sequence = etl::index_sequence<1, 0>; + Tuple2 tp2 = etl::select_from_tuple(tp1, Sequence()); + + CHECK_EQUAL(etl::get<1>(tp1), etl::get<0>(tp2)); + CHECK_EQUAL(etl::get<0>(tp1), etl::get<1>(tp2)); + } + + //************************************************************************* + TEST(test_select_a_subset_of_a_tuple_using_a_compile_time_index_sequence) + { + using Tuple1 = etl::tuple; + using Tuple2 = etl::tuple; + + Tuple1 tp1{1, 2.3, 4, Data("Data", 5)}; + Tuple2 tp2 = etl::select_from_tuple<1, 0>(tp1); + + CHECK_EQUAL(etl::get<1>(tp1), etl::get<0>(tp2)); + CHECK_EQUAL(etl::get<0>(tp1), etl::get<1>(tp2)); + } + + //************************************************************************* + TEST(test_move_select_tuple) + { + using Tuple1 = etl::tuple; + using Tuple2 = etl::tuple; + + Tuple1 tp1{1, 2.3, 4, DataM("DataM")}; + + using Sequence = etl::index_sequence<3, 2, 1, 0>; + Tuple2 tp2 = etl::select_from_tuple(etl::move(tp1), Sequence()); + + CHECK_EQUAL(etl::get<0>(tp1), etl::get<3>(tp2)); + CHECK_EQUAL(etl::get<1>(tp1), etl::get<2>(tp2)); + CHECK_EQUAL(etl::get<2>(tp1), etl::get<1>(tp2)); + CHECK_EQUAL(std::string("DataM"), etl::get<0>(tp2).value); + CHECK_EQUAL(true, etl::get<0>(tp2).valid); + + // Check that the data was moved. + CHECK_EQUAL(std::string(""), etl::get<3>(tp1).value); + CHECK_EQUAL(false, etl::get<3>(tp1).valid); + } + + //************************************************************************* + TEST(test_index_sequence_type) + { + using Tuple = etl::tuple; + + auto actual = to_array(Tuple::index_sequence_type{}); + decltype(actual) expected{0, 1, 2, 3}; + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), expected.size()); + } + + //************************************************************************* + TEST(test_comparison_operators) + { + etl::tuple tp1(1, 2); + etl::tuple tp2(1, 2); + etl::tuple tp3(3, 4); + etl::tuple tp4(4, 3); + + CHECK_TRUE(tp1 == tp2); + CHECK_FALSE(tp1 == tp3); + + CHECK_FALSE(tp1 != tp2); + CHECK_TRUE(tp1 != tp3); + + CHECK_TRUE(tp1 < tp3); + CHECK_FALSE(tp3 < tp1); + CHECK_TRUE(tp3 < tp4); + CHECK_FALSE(tp4 < tp3); + + CHECK_TRUE(tp1 <= tp2); + CHECK_TRUE(tp1 <= tp3); + CHECK_FALSE(tp3 <= tp1); + CHECK_TRUE(tp3 <= tp4); + CHECK_FALSE(tp4 <= tp3); + + CHECK_FALSE(tp1 > tp3); + CHECK_TRUE(tp3 > tp1); + CHECK_FALSE(tp3 > tp4); + CHECK_TRUE(tp4 > tp3); + + CHECK_TRUE(tp1 >= tp2); + CHECK_FALSE(tp1 >= tp3); + CHECK_TRUE(tp3 >= tp1); + CHECK_FALSE(tp3 >= tp4); + CHECK_TRUE(tp4 >= tp3); + } + +#if ETL_USING_STL + //************************************************************************* + TEST(test_to_etl) + { + char v1 = 1; + int v2 = 2; + std::string v3 = "Hello"; + std::string v4 = ""; + + std::tuple tp_std(v1, v2, v3); + + auto tp_etl = etl::to_etl(tp_std); + auto tp_etl_moved = etl::to_etl(etl::move(tp_std)); + + CHECK_EQUAL(v1, etl::get<0>(tp_etl)); + CHECK_EQUAL(v2, etl::get<1>(tp_etl)); + CHECK_EQUAL(v3, etl::get<2>(tp_etl)); + + CHECK_EQUAL(v1, etl::get<0>(tp_etl_moved)); + CHECK_EQUAL(v2, etl::get<1>(tp_etl_moved)); + CHECK_EQUAL(v3, etl::get<2>(tp_etl_moved)); + + CHECK_EQUAL(v4, std::get<2>(tp_std)); + } + + //************************************************************************* + TEST(test_to_std) + { + char v1 = 1; + int v2 = 2; + std::string v3 = "Hello"; + std::string v4 = ""; + + etl::tuple tp_etl(v1, v2, v3); + + auto tp_std = etl::to_std(tp_etl); + auto tp_std_moved = etl::to_std(etl::move(tp_etl)); + + CHECK_EQUAL(v1, std::get<0>(tp_std)); + CHECK_EQUAL(v2, std::get<1>(tp_std)); + CHECK_EQUAL(v3, std::get<2>(tp_std)); + + CHECK_EQUAL(v1, std::get<0>(tp_std_moved)); + CHECK_EQUAL(v2, std::get<1>(tp_std_moved)); + CHECK_EQUAL(v3, std::get<2>(tp_std_moved)); + + CHECK_EQUAL(v4, etl::get<2>(tp_etl)); + } +#endif + + //************************************************************************* + TEST(test_common_type) + { + using Tuple = etl::tuple; + using Type = etl::common_type::type; + + CHECK_TRUE((std::is_same::value)); + } + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_structured_bindings) + { + etl::tuple tp(1, 2, "Hello"); + + const auto &[c, i, s] = tp; + + CHECK_EQUAL(etl::get<0>(tp), c); + CHECK_EQUAL(etl::get<1>(tp), i); + CHECK_EQUAL(etl::get<2>(tp), s); + } +#endif + } +} diff --git a/test/test_type_def.cpp b/test/test_type_def.cpp index b30278a9..f42b593b 100644 --- a/test/test_type_def.cpp +++ b/test/test_type_def.cpp @@ -51,6 +51,7 @@ namespace uint32_t i2 = t2.get(); CHECK_EQUAL(i1, i2); + CHECK_TRUE(std::is_trivially_copyable::value); } //************************************************************************* diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp new file mode 100644 index 00000000..de9be9fc --- /dev/null +++ b/test/test_type_list.cpp @@ -0,0 +1,185 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 BMW AG + +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/type_list.h" + +#include + +namespace +{ +#if ETL_USING_CPP11 + SUITE(test_type_list) + { + //************************************************************************* + TEST(test_type_list_select) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + + CHECK_TRUE((std::is_same::type, t2>::value)); + CHECK_TRUE((std::is_same, t2>::value)); + } + + //************************************************************************* + TEST(test_type_list_size) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list<> t3; + + CHECK_EQUAL(etl::type_list_size::value, 3); + CHECK_EQUAL(etl::type_list_size::value, 2); + CHECK_EQUAL(etl::type_list_size::value, 0); + } + + //************************************************************************* + TEST(test_type_list_cat) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list<> t3; + + typedef etl::type_list t_cat1; + typedef etl::type_list t_cat2; + + CHECK_TRUE((std::is_same::type, t_cat1>::value)); + CHECK_TRUE((std::is_same::type, t_cat1>::value)); + CHECK_FALSE((std::is_same::type, t_cat2>::value)); + + CHECK_TRUE((std::is_same, t_cat1>::value)); + CHECK_TRUE((std::is_same, t_cat1>::value)); + CHECK_FALSE((std::is_same, t_cat2>::value)); + } + + //************************************************************************* + TEST(test_type_list_contains) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + +#if ETL_USING_CPP17 + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); +#endif + } + + //************************************************************************* + TEST(test_type_list_index_of_type) + { + typedef etl::type_list t1; + typedef etl::type_list<> t2; + + CHECK_EQUAL((etl::type_list_index_of_type::value), 0); + CHECK_EQUAL((etl::type_list_index_of_type::value), 1); + CHECK_EQUAL((etl::type_list_index_of_type::value), 2); + CHECK_EQUAL((etl::type_list_index_of_type::value), etl::type_list_npos); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_index_of_v), 0); + CHECK_EQUAL((etl::type_list_index_of_v), 1); + CHECK_EQUAL((etl::type_list_index_of_v), 2); + CHECK_EQUAL((etl::type_list_index_of_v), etl::type_list_npos); +#endif + } + + //************************************************************************* + TEST(test_type_list_type_at_index) + { + typedef etl::type_list t1; + + CHECK_TRUE((std::is_same::type>::value)); + CHECK_TRUE((std::is_same::type>::value)); + CHECK_TRUE((std::is_same::type>::value)); + + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + } + + //************************************************************************* + TEST(test_type_list_max_sizeof_type) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_EQUAL(etl::type_list_max_size::value, 4); + CHECK_EQUAL(etl::type_list_max_size::value, 2); + CHECK_EQUAL(etl::type_list_max_size::value, 4); + CHECK_EQUAL(etl::type_list_max_size::value, 0); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_max_size_v), 4); + CHECK_EQUAL((etl::type_list_max_size_v), 2); + CHECK_EQUAL((etl::type_list_max_size_v), 4); + CHECK_EQUAL((etl::type_list_max_size_v), 0); +#endif + } + + //************************************************************************* + TEST(test_type_list_max_alignment) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, 1); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), 1); +#endif + } + + }; +#endif +} diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 4316a697..a01e1b0a 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -1098,11 +1098,11 @@ namespace TEST(test_conjunction) { #if ETL_USING_CPP17 - CHECK((etl::conjunction_v)); - CHECK((!etl::conjunction_v)); + CHECK_TRUE((etl::conjunction_v)); + CHECK_FALSE((etl::conjunction_v)); #else - CHECK((etl::conjunction::value)); - CHECK((!etl::conjunction::value)); + CHECK_TRUE((etl::conjunction::value)); + CHECK_FALSE((etl::conjunction::value)); #endif } @@ -1110,11 +1110,25 @@ namespace TEST(test_disjunction) { #if ETL_USING_CPP17 - CHECK((etl::disjunction_v)); - CHECK((!etl::disjunction_v)); + CHECK_TRUE((etl::disjunction_v)); + CHECK_FALSE((etl::disjunction_v)); #else - CHECK((etl::disjunction::value)); - CHECK((!etl::disjunction::value)); + CHECK_TRUE((etl::disjunction::value)); + CHECK_FALSE((etl::disjunction::value)); +#endif + } + + //************************************************************************* + TEST(test_exclusive_disjunction) + { +#if ETL_USING_CPP17 + CHECK_TRUE((etl::exclusive_disjunction_v)); + CHECK_FALSE((etl::exclusive_disjunction_v)); + CHECK_FALSE((etl::exclusive_disjunction_v)); +#else + CHECK_TRUE((etl::exclusive_disjunction::value)); + CHECK_FALSE((etl::exclusive_disjunction::value)); + CHECK_FALSE((etl::exclusive_disjunction::value)); #endif } @@ -1328,6 +1342,22 @@ namespace #endif } + //************************************************************************* + TEST(test_nth_base) + { + struct D0 { }; + struct D1 : D0 { using base_type = D0; }; + struct D2 : D1 { using base_type = D1; }; + struct D3 : D2 { using base_type = D2; }; + struct D4 : D3 { using base_type = D3; }; + + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + } + //************************************************************************* TEST(test_type_identity) { diff --git a/test/test_unaligned_type.cpp b/test/test_unaligned_type.cpp index 16fb31b2..e80eeaeb 100644 --- a/test/test_unaligned_type.cpp +++ b/test/test_unaligned_type.cpp @@ -33,6 +33,8 @@ SOFTWARE. #include "etl/private/diagnostic_useless_cast_push.h" +#include + namespace { SUITE(test_unaligned_type) @@ -149,6 +151,30 @@ namespace CHECK_EQUAL(3.1415927L, be_v3); } + //************************************************************************* + TEST(test_construction_from_buffer) + { + const std::array buffer = { 0x12, 0x34, 0x56, 0x78 }; + + const uint32_t le_value = 0x78563412; + const uint32_t be_value = 0x12345678; + + etl::le_uint32_t le_v1(buffer.data()); + etl::be_uint32_t be_v1(buffer.data()); + + etl::le_uint32_t le_v2(buffer.data(), buffer.size()); + etl::be_uint32_t be_v2(buffer.data(), buffer.size()); + + CHECK_EQUAL(le_value, le_v1); + CHECK_EQUAL(be_value, be_v1); + + CHECK_EQUAL(le_value, le_v2); + CHECK_EQUAL(be_value, be_v2); + + CHECK_THROW(etl::le_uint32_t le_v3(buffer.data(), buffer.size() - 1), etl::unaligned_type_buffer_size); + CHECK_THROW(etl::be_uint32_t be_v3(buffer.data(), buffer.size() - 1), etl::unaligned_type_buffer_size); + } + //************************************************************************* TEST(test_endianness) { @@ -182,6 +208,16 @@ namespace CHECK_EQUAL(sizeof(uint32_t), etl::le_uint32_t::Size); CHECK_EQUAL(sizeof(int64_t), etl::le_int64_t::Size); CHECK_EQUAL(sizeof(uint64_t), etl::le_uint64_t::Size); + + // check if net size equals gross size on platform + CHECK_EQUAL(sizeof(int8_t), sizeof(etl::le_int8_t)); + CHECK_EQUAL(sizeof(uint8_t), sizeof(etl::le_uint8_t)); + CHECK_EQUAL(sizeof(int16_t), sizeof(etl::le_int16_t)); + CHECK_EQUAL(sizeof(uint16_t), sizeof(etl::le_uint16_t)); + CHECK_EQUAL(sizeof(int32_t), sizeof(etl::le_int32_t)); + CHECK_EQUAL(sizeof(uint32_t), sizeof(etl::le_uint32_t)); + CHECK_EQUAL(sizeof(int64_t), sizeof(etl::le_int64_t)); + CHECK_EQUAL(sizeof(uint64_t), sizeof(etl::le_uint64_t)); } //************************************************************************* @@ -210,6 +246,16 @@ namespace CHECK_EQUAL(sizeof(uint32_t), etl::be_uint32_t::Size); CHECK_EQUAL(sizeof(int64_t), etl::be_int64_t::Size); CHECK_EQUAL(sizeof(uint64_t), etl::be_uint64_t::Size); + + // check if net size equals gross size on platform + CHECK_EQUAL(sizeof(int8_t), sizeof(etl::be_int8_t)); + CHECK_EQUAL(sizeof(uint8_t), sizeof(etl::be_uint8_t)); + CHECK_EQUAL(sizeof(int16_t), sizeof(etl::be_int16_t)); + CHECK_EQUAL(sizeof(uint16_t), sizeof(etl::be_uint16_t)); + CHECK_EQUAL(sizeof(int32_t), sizeof(etl::be_int32_t)); + CHECK_EQUAL(sizeof(uint32_t), sizeof(etl::be_uint32_t)); + CHECK_EQUAL(sizeof(int64_t), sizeof(etl::be_int64_t)); + CHECK_EQUAL(sizeof(uint64_t), sizeof(etl::be_uint64_t)); } //************************************************************************* @@ -329,19 +375,19 @@ namespace } // float - CHECK_FLOAT_SAME(etl::le_float_t(3.1415927f), etl::le_float_t(3.1415927f)); - CHECK_FLOAT_SAME(3.1415927f, etl::le_float_t(3.1415927f)); - CHECK_FLOAT_SAME(etl::le_float_t(3.1415927f), 3.1415927f); + CHECK_CLOSE(etl::le_float_t(3.1415927f), etl::le_float_t(3.1415927f), 0.001); + CHECK_CLOSE(3.1415927f, etl::le_float_t(3.1415927f), 0.001); + CHECK_CLOSE(etl::le_float_t(3.1415927f), 3.1415927f, 0.001); // double - CHECK_FLOAT_SAME(etl::le_double_t(3.1415927), etl::le_double_t(3.1415927)); - CHECK_FLOAT_SAME(3.1415927, etl::le_double_t(3.1415927)); - CHECK_FLOAT_SAME(etl::le_double_t(3.1415927), 3.1415927); + CHECK_CLOSE(etl::le_double_t(3.1415927), etl::le_double_t(3.1415927), 0.001); + CHECK_CLOSE(3.1415927, etl::le_double_t(3.1415927), 0.001); + CHECK_CLOSE(etl::le_double_t(3.1415927), 3.1415927, 0.001); // long double - CHECK_FLOAT_SAME(etl::le_long_double_t(3.1415927L), etl::le_long_double_t(3.1415927L)); - CHECK_FLOAT_SAME(3.1415927L, etl::le_long_double_t(3.1415927L)); - CHECK_FLOAT_SAME(etl::le_long_double_t(3.1415927L), 3.1415927L); + CHECK_CLOSE(etl::le_long_double_t(3.1415927L), etl::le_long_double_t(3.1415927L), 0.001); + CHECK_CLOSE(3.1415927L, etl::le_long_double_t(3.1415927L), 0.001); + CHECK_CLOSE(etl::le_long_double_t(3.1415927L), 3.1415927L, 0.001); } //************************************************************************* @@ -477,19 +523,19 @@ namespace } // float - CHECK_FLOAT_SAME(etl::be_float_t(3.1415927f), etl::be_float_t(3.1415927f)); - CHECK_FLOAT_SAME(3.1415927f, etl::be_float_t(3.1415927f)); - CHECK_FLOAT_SAME(etl::be_float_t(3.1415927f), 3.1415927f); + CHECK_CLOSE(etl::be_float_t(3.1415927f), etl::be_float_t(3.1415927f), 0.001); + CHECK_CLOSE(3.1415927f, etl::be_float_t(3.1415927f), 0.001); + CHECK_CLOSE(etl::be_float_t(3.1415927f), 3.1415927f, 0.001); // double - CHECK_FLOAT_SAME(etl::be_double_t(3.1415927), etl::be_double_t(3.1415927)); - CHECK_FLOAT_SAME(3.1415927, etl::be_double_t(3.1415927)); - CHECK_FLOAT_SAME(etl::be_double_t(3.1415927), 3.1415927); + CHECK_CLOSE(etl::be_double_t(3.1415927), etl::be_double_t(3.1415927), 0.001); + CHECK_CLOSE(3.1415927, etl::be_double_t(3.1415927), 0.001); + CHECK_CLOSE(etl::be_double_t(3.1415927), 3.1415927, 0.001); // long double - CHECK_FLOAT_SAME(etl::be_long_double_t(3.1415927L), etl::be_long_double_t(3.1415927L)); - CHECK_FLOAT_SAME(3.1415927L, etl::be_long_double_t(3.1415927L)); - CHECK_FLOAT_SAME(etl::be_long_double_t(3.1415927L), 3.1415927L); + CHECK_CLOSE(etl::be_long_double_t(3.1415927L), etl::be_long_double_t(3.1415927L), 0.001); + CHECK_CLOSE(3.1415927L, etl::be_long_double_t(3.1415927L), 0.001); + CHECK_CLOSE(etl::be_long_double_t(3.1415927L), 3.1415927L, 0.001); } //************************************************************************* @@ -622,17 +668,17 @@ namespace // float etl::le_float_t le_float; le_float = 3.1415927f; - CHECK_FLOAT_SAME(3.1415927f, le_float); + CHECK_CLOSE(3.1415927f, le_float, 0.001); // double etl::le_double_t le_double; le_double = 3.1415927; - CHECK_FLOAT_SAME(3.1415927, le_double); + CHECK_CLOSE(3.1415927, le_double, 0.001); // long double etl::le_long_double_t le_long_double; le_long_double = 3.1415927L; - CHECK_FLOAT_SAME(3.1415927L, le_long_double); + CHECK_CLOSE(3.1415927L, le_long_double, 0.001); } //************************************************************************* @@ -691,17 +737,17 @@ namespace // float etl::be_float_t be_float; be_float = 3.1415927f; - CHECK_FLOAT_SAME(3.1415927f, be_float); + CHECK_CLOSE(3.1415927f, be_float, 0.001); // double etl::be_double_t be_double; be_double = 3.1415927; - CHECK_FLOAT_SAME(3.1415927, be_double); + CHECK_CLOSE(3.1415927, be_double, 0.001); // long double etl::be_long_double_t be_long_double; be_long_double = 3.1415927L; - CHECK_FLOAT_SAME(3.1415927L, be_long_double); + CHECK_CLOSE(3.1415927L, be_long_double, 0.001); } //************************************************************************* @@ -740,10 +786,10 @@ namespace le_v3 = be_v1; // Assign le from be. be_v3 = le_v1; // Assign be from le. - CHECK_FLOAT_SAME(3.1415927f, le_v2); - CHECK_FLOAT_SAME(3.1415927f, be_v2); - CHECK_FLOAT_SAME(3.1415927f, le_v3); - CHECK_FLOAT_SAME(3.1415927f, be_v3); + CHECK_CLOSE(3.1415927f, le_v2, 0.001); + CHECK_CLOSE(3.1415927f, be_v2, 0.001); + CHECK_CLOSE(3.1415927f, le_v3, 0.001); + CHECK_CLOSE(3.1415927f, be_v3, 0.001); } //************************************************************************* @@ -761,10 +807,10 @@ namespace le_v3 = be_v1; // Assign le from be. be_v3 = le_v1; // Assign be from le. - CHECK_FLOAT_SAME(3.1415927, le_v2); - CHECK_FLOAT_SAME(3.1415927, be_v2); - CHECK_FLOAT_SAME(3.1415927, le_v3); - CHECK_FLOAT_SAME(3.1415927, be_v3); + CHECK_CLOSE(3.1415927, le_v2, 0.001); + CHECK_CLOSE(3.1415927, be_v2, 0.001); + CHECK_CLOSE(3.1415927, le_v3, 0.001); + CHECK_CLOSE(3.1415927, be_v3, 0.001); } //************************************************************************* @@ -782,10 +828,10 @@ namespace le_v3 = be_v1; // Assign le from be. be_v3 = le_v1; // Assign be from le. - CHECK_FLOAT_SAME(3.1415927L, le_v2); - CHECK_FLOAT_SAME(3.1415927L, be_v2); - CHECK_FLOAT_SAME(3.1415927L, le_v3); - CHECK_FLOAT_SAME(3.1415927L, be_v3); + CHECK_CLOSE(3.1415927L, le_v2, 0.001); + CHECK_CLOSE(3.1415927L, be_v2, 0.001); + CHECK_CLOSE(3.1415927L, le_v3, 0.001); + CHECK_CLOSE(3.1415927L, be_v3, 0.001); } //************************************************************************* diff --git a/test/test_unaligned_type_constexpr.cpp b/test/test_unaligned_type_constexpr.cpp deleted file mode 100644 index b12e6ce6..00000000 --- a/test/test_unaligned_type_constexpr.cpp +++ /dev/null @@ -1,650 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2022 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/unaligned_type.h" -#include "etl/integral_limits.h" - -#if ETL_USING_CPP14 - -#include "etl/private/diagnostic_useless_cast_push.h" - -namespace -{ - SUITE(test_unaligned_type_constexpr) - { - //************************************************************************* - TEST(test_construction) - { - constexpr etl::le_uint32_t le_v1(0x01234567); - constexpr etl::be_uint32_t be_v1(0x01234567); - - CHECK_EQUAL(int(0x01234567), int(le_v1)); - CHECK_EQUAL(int(0x01234567), int(be_v1)); - } - - //************************************************************************* - TEST(test_copy_construction) - { - constexpr etl::le_uint32_t le_v1(0x01234567); - constexpr etl::be_uint32_t be_v1(0x01234567); - constexpr etl::le_uint32_t le_v2(le_v1); // Copy construct le from le. - constexpr etl::be_uint32_t be_v2(be_v1); // Copy construct be from be. - constexpr etl::le_uint32_t le_v3(be_v1); // Copy construct le from be. - constexpr etl::be_uint32_t be_v3(le_v1); // Copy construct be from le. - - CHECK_EQUAL(int(0x01234567), int(le_v2)); - CHECK_EQUAL(int(0x01234567), int(be_v2)); - CHECK_EQUAL(int(0x01234567), int(le_v3)); - CHECK_EQUAL(int(0x01234567), int(be_v3)); - } - - //************************************************************************* - TEST(test_le_equality) - { - constexpr bool check_char1 = etl::le_char_t(0x01) == etl::le_char_t(0x01); - constexpr bool check_char2 = (char)(0x01) == etl::le_char_t(0x01); - constexpr bool check_char3 = etl::le_char_t(0x01) == (char)(0x01); - - CHECK_EQUAL(true, check_char1); - CHECK(check_char2); - CHECK(check_char3); - - constexpr bool check_schar1 = etl::le_schar_t(0x01) == etl::le_schar_t(0x01); - constexpr bool check_schar2 = (signed char)(0x01) == etl::le_schar_t(0x01); - constexpr bool check_schar3 = etl::le_schar_t(0x01) == (signed char)(0x01); - - CHECK(check_schar1); - CHECK(check_schar2); - CHECK(check_schar3); - - constexpr bool check_uchar1 = etl::le_uchar_t(0x01) == etl::le_uchar_t(0x01); - constexpr bool check_uchar2 = (unsigned char)(0x01) == etl::le_uchar_t(0x01); - constexpr bool check_uchar3 = etl::le_uchar_t(0x01) == (unsigned char)(0x01); - - CHECK(check_uchar1); - CHECK(check_uchar2); - CHECK(check_uchar3); - - constexpr bool check_short1 = (short)(0x0123) == etl::le_short_t(0x0123); - constexpr bool check_short2 = etl::le_short_t(0x0123) == (short)(0x0123); - constexpr bool check_short3 = (short)(0x0123) == etl::le_short_t(0x0123); - - CHECK(check_short1); - CHECK(check_short2); - CHECK(check_short3); - - constexpr bool check_ushort1 = (unsigned short)(0x0123) == etl::le_ushort_t(0x0123); - constexpr bool check_ushort2 = etl::le_ushort_t(0x0123) == (unsigned short)(0x0123); - constexpr bool check_ushort3 = (unsigned short)(0x0123) == etl::le_ushort_t(0x0123); - - CHECK(check_ushort1); - CHECK(check_ushort2); - CHECK(check_ushort3); - - constexpr bool check_int1 = (int)(0x01234567) == etl::le_int_t(0x01234567); - constexpr bool check_int2 = etl::le_int_t(0x01234567) == (int)(0x01234567); - constexpr bool check_int3 = (int)(0x01234567) == etl::le_int_t(0x01234567); - - CHECK(check_int1); - CHECK(check_int2); - CHECK(check_int3); - - constexpr bool check_uint1 = (unsigned int)(0x01234567) == etl::le_uint_t(0x01234567); - constexpr bool check_uint2 = etl::le_uint_t(0x01234567) == (unsigned int)(0x01234567); - constexpr bool check_uint3 = (unsigned int)(0x01234567) == etl::le_uint_t(0x01234567); - - CHECK(check_uint1); - CHECK(check_uint2); - CHECK(check_uint3); - - if (sizeof(long) == 4U) - { - constexpr bool check_long1 = (long)(0x01234567) == etl::le_long_t(0x01234567); - constexpr bool check_long2 = etl::le_long_t(0x01234567) == (long)(0x01234567); - constexpr bool check_long3 = (long)(0x01234567) == etl::le_long_t(0x01234567); - - CHECK(check_long1); - CHECK(check_long2); - CHECK(check_long3); - - constexpr bool check_ulong1 = (unsigned long)(0x01234567) == etl::le_ulong_t(0x01234567); - constexpr bool check_ulong2 = etl::le_ulong_t(0x01234567) == (unsigned long)(0x01234567); - constexpr bool check_ulong3 = (unsigned long)(0x01234567) == etl::le_ulong_t(0x01234567); - - CHECK(check_ulong1); - CHECK(check_ulong2); - CHECK(check_ulong3); - } - - if (sizeof(long long) == 8U) - { - constexpr bool check_long_long1 = (long long)(0x0123456789ABCDEF) == etl::le_long_long_t(0x0123456789ABCDEF); - constexpr bool check_long_long2 = etl::le_long_long_t(0x0123456789ABCDEF) == (long long)(0x0123456789ABCDEF); - constexpr bool check_long_long3 = (long long)(0x0123456789ABCDEF) == etl::le_long_long_t(0x0123456789ABCDEF); - - CHECK(check_long_long1); - CHECK(check_long_long2); - CHECK(check_long_long3); - - constexpr bool check_ulong_long1 = (unsigned long long)(0x0123456789ABCDEF) == etl::le_ulong_long_t(0x0123456789ABCDEF); - constexpr bool check_ulong_long2 = etl::le_ulong_long_t(0x0123456789ABCDEF) == (unsigned long long)(0x0123456789ABCDEF); - constexpr bool check_ulong_long3 = (unsigned long long)(0x0123456789ABCDEF) == etl::le_ulong_long_t(0x0123456789ABCDEF); - - CHECK(check_ulong_long1); - CHECK(check_ulong_long2); - CHECK(check_ulong_long3); - } - } - - //************************************************************************* - TEST(test_le_inequality) - { - constexpr bool check_char1 = etl::le_char_t(0x01) != etl::le_char_t(0x02); - constexpr bool check_char2 = (char)(0x01) != etl::le_char_t(0x02); - constexpr bool check_char3 = etl::le_char_t(0x01) != (char)(0x02); - - CHECK(check_char1); - CHECK(check_char2); - CHECK(check_char3); - - constexpr bool check_schar1 = etl::le_schar_t(0x01) != etl::le_schar_t(0x02); - constexpr bool check_schar2 = (signed char)(0x01) != etl::le_schar_t(0x02); - constexpr bool check_schar3 = etl::le_schar_t(0x01) != (signed char)(0x02); - - CHECK(check_schar1); - CHECK(check_schar2); - CHECK(check_schar3); - - constexpr bool check_uchar1 = etl::le_uchar_t(0x01) != etl::le_uchar_t(0x02); - constexpr bool check_uchar2 = (unsigned char)(0x01) != etl::le_uchar_t(0x02); - constexpr bool check_uchar3 = etl::le_uchar_t(0x01) != (unsigned char)(0x02); - - CHECK(check_uchar1); - CHECK(check_uchar2); - CHECK(check_uchar3); - - constexpr bool check_short1 = (short)(0x0123) != etl::le_short_t(0x0124); - constexpr bool check_short2 = etl::le_short_t(0x0123) != (short)(0x0124); - constexpr bool check_short3 = (short)(0x0123) != etl::le_short_t(0x0124); - - CHECK(check_short1); - CHECK(check_short2); - CHECK(check_short3); - - constexpr bool check_ushort1 = (unsigned short)(0x0123) != etl::le_ushort_t(0x0124); - constexpr bool check_ushort2 = etl::le_ushort_t(0x0123) != (unsigned short)(0x0124); - constexpr bool check_ushort3 = (unsigned short)(0x0123) != etl::le_ushort_t(0x0124); - - CHECK(check_ushort1); - CHECK(check_ushort2); - CHECK(check_ushort3); - - constexpr bool check_int1 = (int)(0x01234567) != etl::le_int_t(0x01244567); - constexpr bool check_int2 = etl::le_int_t(0x01234567) != (int)(0x01244567); - constexpr bool check_int3 = (int)(0x01234567) != etl::le_int_t(0x01244567); - - CHECK(check_int1); - CHECK(check_int2); - CHECK(check_int3); - - constexpr bool check_uint1 = (unsigned int)(0x01234567) != etl::le_uint_t(0x01244567); - constexpr bool check_uint2 = etl::le_uint_t(0x01234567) != (unsigned int)(0x01244567); - constexpr bool check_uint3 = (unsigned int)(0x01234567) != etl::le_uint_t(0x01244567); - - CHECK(check_uint1); - CHECK(check_uint2); - CHECK(check_uint3); - - if (sizeof(long) == 4U) - { - constexpr bool check_long1 = (long)(0x01234567) != etl::le_long_t(0x01244567); - constexpr bool check_long2 = etl::le_long_t(0x01234567) != (long)(0x01244567); - constexpr bool check_long3 = (long)(0x01234567) != etl::le_long_t(0x01244567); - - CHECK(check_long1); - CHECK(check_long2); - CHECK(check_long3); - - constexpr bool check_ulong1 = (unsigned long)(0x01234567) != etl::le_ulong_t(0x01244567); - constexpr bool check_ulong2 = etl::le_ulong_t(0x01234567) != (unsigned long)(0x01244567); - constexpr bool check_ulong3 = (unsigned long)(0x01234567) != etl::le_ulong_t(0x01244567); - - CHECK(check_ulong1); - CHECK(check_ulong2); - CHECK(check_ulong3); - } - - if (sizeof(long long) == 8U) - { - constexpr bool check_long_long1 = (long long)(0x0123456789ABCDEF) != etl::le_long_long_t(0x0123457789ABCDEF); - constexpr bool check_long_long2 = etl::le_long_long_t(0x0123456789ABCDEF) != (long long)(0x0123457789ABCDEF); - constexpr bool check_long_long3 = (long long)(0x0123456789ABCDEF) != etl::le_long_long_t(0x0123457789ABCDEF); - - CHECK(check_long_long1); - CHECK(check_long_long2); - CHECK(check_long_long3); - - constexpr bool check_ulong_long1 = (unsigned long long)(0x0123456789ABCDEF) != etl::le_ulong_long_t(0x0123457789ABCDEF); - constexpr bool check_ulong_long2 = etl::le_ulong_long_t(0x0123456789ABCDEF) != (unsigned long long)(0x0123457789ABCDEF); - constexpr bool check_ulong_long3 = (unsigned long long)(0x0123456789ABCDEF) != etl::le_ulong_long_t(0x0123457789ABCDEF); - - CHECK(check_ulong_long1); - CHECK(check_ulong_long2); - CHECK(check_ulong_long3); - } - } - - //************************************************************************* - TEST(test_be_equality) - { - constexpr bool check_char1 = etl::be_char_t(0x01) == etl::be_char_t(0x01); - constexpr bool check_char2 = (char)(0x01) == etl::be_char_t(0x01); - constexpr bool check_char3 = etl::be_char_t(0x01) == (char)(0x01); - - CHECK(check_char1); - CHECK(check_char2); - CHECK(check_char3); - - constexpr bool check_schar1 = etl::be_schar_t(0x01) == etl::be_schar_t(0x01); - constexpr bool check_schar2 = (signed char)(0x01) == etl::be_schar_t(0x01); - constexpr bool check_schar3 = etl::be_schar_t(0x01) == (signed char)(0x01); - - CHECK(check_schar1); - CHECK(check_schar2); - CHECK(check_schar3); - - constexpr bool check_uchar1 = etl::be_uchar_t(0x01) == etl::be_uchar_t(0x01); - constexpr bool check_uchar2 = (unsigned char)(0x01) == etl::be_uchar_t(0x01); - constexpr bool check_uchar3 = etl::be_uchar_t(0x01) == (unsigned char)(0x01); - - CHECK(check_uchar1); - CHECK(check_uchar2); - CHECK(check_uchar3); - - constexpr bool check_short1 = (short)(0x0123) == etl::be_short_t(0x0123); - constexpr bool check_short2 = etl::be_short_t(0x0123) == (short)(0x0123); - constexpr bool check_short3 = (short)(0x0123) == etl::be_short_t(0x0123); - - CHECK(check_short1); - CHECK(check_short2); - CHECK(check_short3); - - constexpr bool check_ushort1 = (unsigned short)(0x0123) == etl::be_ushort_t(0x0123); - constexpr bool check_ushort2 = etl::be_ushort_t(0x0123) == (unsigned short)(0x0123); - constexpr bool check_ushort3 = (unsigned short)(0x0123) == etl::be_ushort_t(0x0123); - - CHECK(check_ushort1); - CHECK(check_ushort2); - CHECK(check_ushort3); - - constexpr bool check_int1 = (int)(0x01234567) == etl::be_int_t(0x01234567); - constexpr bool check_int2 = etl::be_int_t(0x01234567) == (int)(0x01234567); - constexpr bool check_int3 = (int)(0x01234567) == etl::be_int_t(0x01234567); - - CHECK(check_int1); - CHECK(check_int2); - CHECK(check_int3); - - constexpr bool check_uint1 = (unsigned int)(0x01234567) == etl::be_uint_t(0x01234567); - constexpr bool check_uint2 = etl::be_uint_t(0x01234567) == (unsigned int)(0x01234567); - constexpr bool check_uint3 = (unsigned int)(0x01234567) == etl::be_uint_t(0x01234567); - - CHECK(check_uint1); - CHECK(check_uint2); - CHECK(check_uint3); - - if (sizeof(long) == 4U) - { - constexpr bool check_long1 = (long)(0x01234567) == etl::be_long_t(0x01234567); - constexpr bool check_long2 = etl::be_long_t(0x01234567) == (long)(0x01234567); - constexpr bool check_long3 = (long)(0x01234567) == etl::be_long_t(0x01234567); - - CHECK(check_long1); - CHECK(check_long2); - CHECK(check_long3); - - constexpr bool check_ulong1 = (unsigned long)(0x01234567) == etl::be_ulong_t(0x01234567); - constexpr bool check_ulong2 = etl::be_ulong_t(0x01234567) == (unsigned long)(0x01234567); - constexpr bool check_ulong3 = (unsigned long)(0x01234567) == etl::be_ulong_t(0x01234567); - - CHECK(check_ulong1); - CHECK(check_ulong2); - CHECK(check_ulong3); - } - - if (sizeof(long long) == 8U) - { - constexpr bool check_long_long1 = (long long)(0x0123456789ABCDEF) == etl::be_long_long_t(0x0123456789ABCDEF); - constexpr bool check_long_long2 = etl::be_long_long_t(0x0123456789ABCDEF) == (long long)(0x0123456789ABCDEF); - constexpr bool check_long_long3 = (long long)(0x0123456789ABCDEF) == etl::be_long_long_t(0x0123456789ABCDEF); - - CHECK(check_long_long1); - CHECK(check_long_long2); - CHECK(check_long_long3); - - constexpr bool check_ulong_long1 = (unsigned long long)(0x0123456789ABCDEF) == etl::be_ulong_long_t(0x0123456789ABCDEF); - constexpr bool check_ulong_long2 = etl::be_ulong_long_t(0x0123456789ABCDEF) == (unsigned long long)(0x0123456789ABCDEF); - constexpr bool check_ulong_long3 = (unsigned long long)(0x0123456789ABCDEF) == etl::be_ulong_long_t(0x0123456789ABCDEF); - - CHECK(check_ulong_long1); - CHECK(check_ulong_long2); - CHECK(check_ulong_long3); - } - } - - //************************************************************************* - TEST(test_be_inequality) - { - constexpr bool check_char1 = etl::be_char_t(0x01) != etl::be_char_t(0x02); - constexpr bool check_char2 = (char)(0x01) != etl::be_char_t(0x02); - constexpr bool check_char3 = etl::be_char_t(0x01) != (char)(0x02); - - CHECK(check_char1); - CHECK(check_char2); - CHECK(check_char3); - - constexpr bool check_schar1 = etl::be_schar_t(0x01) != etl::be_schar_t(0x02); - constexpr bool check_schar2 = (signed char)(0x01) != etl::be_schar_t(0x02); - constexpr bool check_schar3 = etl::be_schar_t(0x01) != (signed char)(0x02); - - CHECK(check_schar1); - CHECK(check_schar2); - CHECK(check_schar3); - - constexpr bool check_uchar1 = etl::be_uchar_t(0x01) != etl::be_uchar_t(0x02); - constexpr bool check_uchar2 = (unsigned char)(0x01) != etl::be_uchar_t(0x02); - constexpr bool check_uchar3 = etl::be_uchar_t(0x01) != (unsigned char)(0x02); - - CHECK(check_uchar1); - CHECK(check_uchar2); - CHECK(check_uchar3); - - constexpr bool check_short1 = (short)(0x0123) != etl::be_short_t(0x0124); - constexpr bool check_short2 = etl::be_short_t(0x0123) != (short)(0x0124); - constexpr bool check_short3 = (short)(0x0123) != etl::be_short_t(0x0124); - - CHECK(check_short1); - CHECK(check_short2); - CHECK(check_short3); - - constexpr bool check_ushort1 = (unsigned short)(0x0123) != etl::be_ushort_t(0x0124); - constexpr bool check_ushort2 = etl::be_ushort_t(0x0123) != (unsigned short)(0x0124); - constexpr bool check_ushort3 = (unsigned short)(0x0123) != etl::be_ushort_t(0x0124); - - CHECK(check_ushort1); - CHECK(check_ushort2); - CHECK(check_ushort3); - - constexpr bool check_int1 = (int)(0x01234567) != etl::be_int_t(0x01244567); - constexpr bool check_int2 = etl::be_int_t(0x01234567) != (int)(0x01244567); - constexpr bool check_int3 = (int)(0x01234567) != etl::be_int_t(0x01244567); - - CHECK(check_int1); - CHECK(check_int2); - CHECK(check_int3); - - constexpr bool check_uint1 = (unsigned int)(0x01234567) != etl::be_uint_t(0x01244567); - constexpr bool check_uint2 = etl::be_uint_t(0x01234567) != (unsigned int)(0x01244567); - constexpr bool check_uint3 = (unsigned int)(0x01234567) != etl::be_uint_t(0x01244567); - - CHECK(check_uint1); - CHECK(check_uint2); - CHECK(check_uint3); - - if (sizeof(long) == 4U) - { - constexpr bool check_long1 = (long)(0x01234567) != etl::be_long_t(0x01244567); - constexpr bool check_long2 = etl::be_long_t(0x01234567) != (long)(0x01244567); - constexpr bool check_long3 = (long)(0x01234567) != etl::be_long_t(0x01244567); - - CHECK(check_long1); - CHECK(check_long2); - CHECK(check_long3); - - constexpr bool check_ulong1 = (unsigned long)(0x01234567) != etl::be_ulong_t(0x01244567); - constexpr bool check_ulong2 = etl::be_ulong_t(0x01234567) != (unsigned long)(0x01244567); - constexpr bool check_ulong3 = (unsigned long)(0x01234567) != etl::be_ulong_t(0x01244567); - - CHECK(check_ulong1); - CHECK(check_ulong2); - CHECK(check_ulong3); - } - - if (sizeof(long long) == 8U) - { - constexpr bool check_long_long1 = (long long)(0x0123456789ABCDEF) != etl::be_long_long_t(0x0123457789ABCDEF); - constexpr bool check_long_long2 = etl::be_long_long_t(0x0123456789ABCDEF) != (long long)(0x0123457789ABCDEF); - constexpr bool check_long_long3 = (long long)(0x0123456789ABCDEF) != etl::be_long_long_t(0x0123457789ABCDEF); - - CHECK(check_long_long1); - CHECK(check_long_long2); - CHECK(check_long_long3); - - constexpr bool check_ulong_long1 = (unsigned long long)(0x0123456789ABCDEF) != etl::be_ulong_long_t(0x0123457789ABCDEF); - constexpr bool check_ulong_long2 = etl::be_ulong_long_t(0x0123456789ABCDEF) != (unsigned long long)(0x0123457789ABCDEF); - constexpr bool check_ulong_long3 = (unsigned long long)(0x0123456789ABCDEF) != etl::be_ulong_long_t(0x0123457789ABCDEF); - - CHECK(check_ulong_long1); - CHECK(check_ulong_long2); - CHECK(check_ulong_long3); - } - } - - //************************************************************************* - TEST(test_le_assignment) - { - constexpr etl::le_char_t le_char = 0x01; - CHECK(0x01 == (signed char)le_char); - - constexpr etl::le_schar_t le_schar = 0x01; - CHECK(0x01 == (signed char)le_schar); - - constexpr etl::le_uchar_t le_uchar = 0x01; - CHECK(0x01 == (unsigned char)le_uchar); - - constexpr etl::le_short_t le_short = 0x0123; - CHECK(0x0123 == (short)le_short); - - constexpr etl::le_ushort_t le_ushort = 0x0123; - CHECK(0x0123 == (unsigned short)le_ushort); - - constexpr etl::le_int_t le_int = 0x01234567; - CHECK(0x01234567 == (int)le_int); - - constexpr etl::le_uint_t le_uint = 0x01234567; - CHECK(0x01234567 == (unsigned int)le_uint); - - if (sizeof(long) == 4U) - { - constexpr etl::le_long_t le_long = 0x01234567; - CHECK(0x01234567 == (long)le_long); - - constexpr etl::le_ulong_t le_ulong = 0x01234567; - CHECK(0x01234567 == (unsigned long)le_ulong); - } - - if (sizeof(long long) == 8U) - { - constexpr etl::le_long_long_t le_long = 0x0123456789ABCDEF; - CHECK(0x0123456789ABCDEF == (long long)le_long); - - constexpr etl::le_ulong_long_t le_ulong = 0x0123456789ABCDEF; - CHECK(0x0123456789ABCDEF == (unsigned long long)le_ulong); - } - } - - //************************************************************************* - TEST(test_be_assignment) - { - constexpr etl::be_char_t be_char = 0x01; - CHECK(0x01 == (signed char)be_char); - - constexpr etl::be_schar_t be_schar = 0x01; - CHECK(0x01 == (signed char)be_schar); - - constexpr etl::be_uchar_t be_uchar = 0x01; - CHECK(0x01 == (unsigned char)be_uchar); - - constexpr etl::be_short_t be_short = 0x0123; - CHECK(0x0123 == (short)be_short); - - constexpr etl::be_ushort_t be_ushort = 0x0123; - CHECK(0x0123 == (unsigned short)be_ushort); - - constexpr etl::be_int_t be_int = 0x01234567; - CHECK(0x01234567 == (int)be_int); - - constexpr etl::be_uint_t be_uint = 0x01234567; - CHECK(0x01234567 == (unsigned int)be_uint); - - if (sizeof(long) == 4U) - { - constexpr etl::be_long_t be_long = 0x01234567; - CHECK(0x01234567 == (long)be_long); - - constexpr etl::be_ulong_t be_ulong = 0x01234567; - CHECK(0x01234567 == (unsigned long)be_ulong); - } - - if (sizeof(long long) == 8U) - { - constexpr etl::be_long_long_t be_long = 0x0123456789ABCDEF; - CHECK(0x0123456789ABCDEF == (long long)be_long); - - constexpr etl::be_ulong_long_t be_ulong = 0x0123456789ABCDEF; - CHECK(0x0123456789ABCDEF == (unsigned long long)be_ulong); - } - } - - //************************************************************************* - TEST(test_data) - { - static constexpr etl::be_uint16_t test(0x1234); - - constexpr etl::be_uint16_t::const_pointer p1 = test.data(); - constexpr etl::be_uint16_t::const_pointer p2 = test.data() + 1U; - - CHECK_EQUAL(0x12, *p1); - CHECK_EQUAL(0x34, *p2); - } - - //************************************************************************* - TEST(test_begin_end_iterator) - { - using const_iterator = etl::be_uint16_t::const_iterator; - - static constexpr etl::be_uint16_t test(0x1234); - - //******************************* - constexpr const_iterator itr1 = test.begin(); - CHECK_EQUAL(int(0x12), int(*itr1)); - - constexpr const_iterator itr2 = test.begin() + 1U; - CHECK_EQUAL(int(0x34), int(*itr2)); - - constexpr const_iterator itr3 = test.begin() + 2U; - CHECK(test.end() == itr3); - } - - //************************************************************************* - TEST(test_rbegin_rend_iterator) - { - using const_reverse_iterator = etl::be_uint16_t::const_reverse_iterator; - - static constexpr etl::be_uint16_t test(0x1234); - - //******************************* - constexpr const_reverse_iterator itr1 = test.rbegin(); - CHECK_EQUAL(int(0x34), int(*itr1)); - - constexpr const_reverse_iterator itr2 = test.rbegin() + 1U; - CHECK_EQUAL(int(0x12), int(*itr2)); - - constexpr const_reverse_iterator itr3 = test.rbegin() + 2U; - CHECK(test.rend() == itr3); - } - - //************************************************************************* - TEST(test_index_operator) - { - constexpr etl::le_uint16_t test_le(0x1234); - constexpr etl::be_uint16_t test_be(0x1234); - - constexpr const char lea = test_le[0]; - constexpr const char leb = test_le[1]; - - constexpr const char bea = test_be[0]; - constexpr const char beb = test_be[1]; - - CHECK_EQUAL(0x34, lea); - CHECK_EQUAL(0x12, leb); - - CHECK_EQUAL(0x12, bea); - CHECK_EQUAL(0x34, beb); - } - - //************************************************************************* - TEST(test_value) - { - constexpr etl::le_uint16_t test_le(0x1234); - constexpr etl::be_uint16_t test_be(0x1234); - - constexpr uint16_t lev = test_le.value(); - constexpr uint16_t bev = test_be.value(); - - CHECK_EQUAL(0x1234, lev); - CHECK_EQUAL(0x1234, bev); - } - - //************************************************************************* - TEST(test_storage_bytes) - { - constexpr etl::le_uint16_t test_le(0x1234); - constexpr etl::be_uint16_t test_be(0x1234); - - constexpr int lev0 = test_le[0]; - constexpr int lev1 = test_le[1]; - - constexpr int bev0 = test_be[0]; - constexpr int bev1 = test_be[1]; - - CHECK_EQUAL(0x34, lev0); - CHECK_EQUAL(0x12, lev1); - CHECK_EQUAL(0x12, bev0); - CHECK_EQUAL(0x34, bev1); - } - }; -} - -#include "etl/private/diagnostic_pop.h" - -#endif - - diff --git a/test/test_unaligned_type_ext.cpp b/test/test_unaligned_type_ext.cpp new file mode 100644 index 00000000..5d3b5975 --- /dev/null +++ b/test/test_unaligned_type_ext.cpp @@ -0,0 +1,1526 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2022 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/unaligned_type.h" +#include "etl/integral_limits.h" + +#include "etl/private/diagnostic_useless_cast_push.h" + +#include + +namespace +{ + using storage_c_t = std::array; + using storage_s_t = std::array; + using storage_i_t = std::array; + using storage_l_t = std::array; + using storage_ll_t = std::array; + using storage_f_t = std::array; + using storage_d_t = std::array; + using storage_ld_t = std::array; + using storage_i8_t = std::array; + using storage_i16_t = std::array; + using storage_i32_t = std::array; + using storage_i64_t = std::array; + + SUITE(test_unaligned_type_ext) + { + //************************************************************************* + TEST(test_copy_construction_8) + { + storage_i32_t store_le1; + storage_i32_t store_be1; + storage_i32_t store_le2; + storage_i32_t store_be2; + storage_i32_t store_le3; + storage_i32_t store_be3; + + etl::le_uint32_ext_t le_v1(store_le1.data()); + le_v1 = 0xEF; + etl::be_uint32_ext_t be_v1(0xEF, store_be1.data()); + + etl::le_uint32_ext_t le_v2(le_v1, store_le2.data()); // Copy construct le from le. + etl::be_uint32_ext_t be_v2(be_v1, store_be2.data()); // Copy construct be from be. + etl::le_uint32_ext_t le_v3(be_v1, store_le3.data()); // Copy construct le from be. + etl::be_uint32_ext_t be_v3(le_v1, store_be3.data()); // Copy construct be from le. + + CHECK_EQUAL(int(0xEF), int(le_v2)); + CHECK_EQUAL(int(0xEF), int(be_v2)); + CHECK_EQUAL(int(0xEF), int(le_v3)); + CHECK_EQUAL(int(0xEF), int(be_v3)); + } + + //************************************************************************* + TEST(test_move_construction_8) + { + storage_i32_t store_le1; + storage_i32_t store_be1; + + etl::le_uint32_ext_t le_v1(0xEF, store_le1.data()); + etl::be_uint32_ext_t be_v1(0xEF, store_be1.data()); + + etl::le_uint32_ext_t le_v2(etl::move(le_v1)); // Move construct le from le. + etl::be_uint32_ext_t be_v2(etl::move(be_v1)); // Move construct be from be. + + CHECK_TRUE(nullptr == le_v1.data()); + CHECK_TRUE(nullptr == be_v1.data()); + CHECK_EQUAL(int(0xEF), int(le_v2)); + CHECK_EQUAL(int(0xEF), int(be_v2)); + } + + //************************************************************************* + TEST(test_copy_construction_16) + { + storage_i32_t store_le1; + storage_i32_t store_be1; + storage_i32_t store_le2; + storage_i32_t store_be2; + storage_i32_t store_le3; + storage_i32_t store_be3; + + etl::le_uint32_ext_t le_v1(store_le1.data()); + le_v1 = 0xEEEF; + etl::be_uint32_ext_t be_v1(0xEEEF, store_be1.data()); + + etl::le_uint32_ext_t le_v2(le_v1, store_le2.data()); // Copy construct le from le. + etl::be_uint32_ext_t be_v2(be_v1, store_be2.data()); // Copy construct be from be. + etl::le_uint32_ext_t le_v3(be_v1, store_le3.data()); // Copy construct le from be. + etl::be_uint32_ext_t be_v3(le_v1, store_be3.data()); // Copy construct be from le. + + CHECK_EQUAL(int(0xEEEF), int(le_v2)); + CHECK_EQUAL(int(0xEEEF), int(be_v2)); + CHECK_EQUAL(int(0xEEEF), int(le_v3)); + CHECK_EQUAL(int(0xEEEF), int(be_v3)); + } + + //************************************************************************* + TEST(test_move_construction_16) + { + storage_i32_t store_le1; + storage_i32_t store_be1; + + etl::le_uint32_ext_t le_v1(0xEEEF, store_le1.data()); + etl::be_uint32_ext_t be_v1(0xEEEF, store_be1.data()); + + etl::le_uint32_ext_t le_v2(etl::move(le_v1)); // Move construct le from le. + etl::be_uint32_ext_t be_v2(etl::move(be_v1)); // Move construct be from be. + + CHECK_TRUE(nullptr == le_v1.data()); + CHECK_TRUE(nullptr == be_v1.data()); + CHECK_EQUAL(int(0xEEEF), int(le_v2)); + CHECK_EQUAL(int(0xEEEF), int(be_v2)); + } + + //************************************************************************* + TEST(test_copy_construction_32) + { + storage_i32_t store_le1; + storage_i32_t store_be1; + storage_i32_t store_le2; + storage_i32_t store_be2; + storage_i32_t store_le3; + storage_i32_t store_be3; + + etl::le_uint32_ext_t le_v1(store_le1.data()); + le_v1 = 0xEE2345EF; + etl::be_uint32_ext_t be_v1(0xEE2345EF, store_be1.data()); + + etl::le_uint32_ext_t le_v2(le_v1, store_le2.data()); // Copy construct le from le. + etl::be_uint32_ext_t be_v2(be_v1, store_be2.data()); // Copy construct be from be. + etl::le_uint32_ext_t le_v3(be_v1, store_le3.data()); // Copy construct le from be. + etl::be_uint32_ext_t be_v3(le_v1, store_be3.data()); // Copy construct be from le. + + CHECK_EQUAL(int(0xEE2345EF), int(le_v2)); + CHECK_EQUAL(int(0xEE2345EF), int(be_v2)); + CHECK_EQUAL(int(0xEE2345EF), int(le_v3)); + CHECK_EQUAL(int(0xEE2345EF), int(be_v3)); + } + + //************************************************************************* + TEST(test_move_construction_32) + { + storage_i32_t store_le1; + storage_i32_t store_be1; + + etl::le_uint32_ext_t le_v1(0xEE2345EF, store_le1.data()); + etl::be_uint32_ext_t be_v1(0xEE2345EF, store_be1.data()); + + etl::le_uint32_ext_t le_v2(etl::move(le_v1)); // Move construct le from le. + etl::be_uint32_ext_t be_v2(etl::move(be_v1)); // Move construct be from be. + + CHECK_TRUE(nullptr == le_v1.data()); + CHECK_TRUE(nullptr == be_v1.data()); + CHECK_EQUAL(int(0xEE2345EF), int(le_v2)); + CHECK_EQUAL(int(0xEE2345EF), int(be_v2)); + } + + //************************************************************************* + TEST(test_copy_construction_64) + { + storage_i64_t store_le1; + storage_i64_t store_be1; + storage_i64_t store_le2; + storage_i64_t store_be2; + storage_i64_t store_le3; + storage_i64_t store_be3; + + etl::le_uint64_ext_t le_v1(store_le1.data()); + le_v1 = 0xEE23456789ABCDEF; + etl::be_uint64_ext_t be_v1(0xEE23456789ABCDEF, store_be1.data()); + + etl::le_uint64_ext_t le_v2(le_v1, store_le2.data()); // Copy construct le from le. + etl::be_uint64_ext_t be_v2(be_v1, store_be2.data()); // Copy construct be from be. + etl::le_uint64_ext_t le_v3(be_v1, store_le3.data()); // Copy construct le from be. + etl::be_uint64_ext_t be_v3(le_v1, store_be3.data()); // Copy construct be from le. + + CHECK_EQUAL(int(0xEE23456789ABCDEF), int(le_v2)); + CHECK_EQUAL(int(0xEE23456789ABCDEF), int(be_v2)); + CHECK_EQUAL(int(0xEE23456789ABCDEF), int(le_v3)); + CHECK_EQUAL(int(0xEE23456789ABCDEF), int(be_v3)); + } + + //************************************************************************* + TEST(test_move_construction_64) + { + storage_i64_t store_le1; + storage_i64_t store_be1; + + etl::le_uint64_ext_t le_v1(0xEE23456789ABCDEF, store_le1.data()); + etl::be_uint64_ext_t be_v1(0xEE23456789ABCDEF, store_be1.data()); + + etl::le_uint64_ext_t le_v2(etl::move(le_v1)); // Move construct le from le. + etl::be_uint64_ext_t be_v2(etl::move(be_v1)); // Move construct be from be. + + CHECK_TRUE(nullptr == le_v1.data()); + CHECK_TRUE(nullptr == be_v1.data()); + CHECK_EQUAL(int(0xEE23456789ABCDEF), int(le_v2)); + CHECK_EQUAL(int(0xEE23456789ABCDEF), int(be_v2)); + } + + //************************************************************************* + TEST(test_copy_construction_float) + { + storage_f_t store_le1; + storage_f_t store_be1; + storage_f_t store_le2; + storage_f_t store_be2; + storage_f_t store_le3; + storage_f_t store_be3; + + etl::le_float_ext_t le_v1(store_le1.data()); + le_v1 = 3.1415927f; + etl::be_float_ext_t be_v1(3.1415927f, store_be1.data()); + + etl::le_float_ext_t le_v2(le_v1, store_le2.data()); // Copy construct le from le. + etl::be_float_ext_t be_v2(be_v1, store_be2.data()); // Copy construct be from be. + etl::le_float_ext_t le_v3(be_v1, store_le3.data()); // Copy construct le from be. + etl::be_float_ext_t be_v3(le_v1, store_be3.data()); // Copy construct be from le. + + CHECK_EQUAL(3.1415927f, le_v2); + CHECK_EQUAL(3.1415927f, be_v2); + CHECK_EQUAL(3.1415927f, le_v3); + CHECK_EQUAL(3.1415927f, be_v3); + } + + //************************************************************************* + TEST(test_move_construction_float) + { + storage_f_t store_le1; + storage_f_t store_be1; + + etl::le_float_ext_t le_v1(3.1415927f, store_le1.data()); + etl::be_float_ext_t be_v1(3.1415927f, store_be1.data()); + + etl::le_float_ext_t le_v2(etl::move(le_v1)); // Move construct le from le. + etl::be_float_ext_t be_v2(etl::move(be_v1)); // Move construct be from be. + + CHECK_TRUE(nullptr == le_v1.data()); + CHECK_TRUE(nullptr == be_v1.data()); + CHECK_EQUAL(3.1415927f, le_v2); + CHECK_EQUAL(3.1415927f, be_v2); + } + + //************************************************************************* + TEST(test_copy_construction_double) + { + storage_d_t store_le1; + storage_d_t store_be1; + storage_d_t store_le2; + storage_d_t store_be2; + storage_d_t store_le3; + storage_d_t store_be3; + + etl::le_double_ext_t le_v1(store_le1.data()); + le_v1 = 3.1415927; + etl::be_double_ext_t be_v1(3.1415927, store_be1.data()); + + etl::le_double_ext_t le_v2(le_v1, store_le2.data()); // Copy construct le from le. + etl::be_double_ext_t be_v2(be_v1, store_be2.data()); // Copy construct be from be. + etl::le_double_ext_t le_v3(be_v1, store_le3.data()); // Copy construct le from be. + etl::be_double_ext_t be_v3(le_v1, store_be3.data()); // Copy construct be from le. + + CHECK_EQUAL(3.1415927, le_v2); + CHECK_EQUAL(3.1415927, be_v2); + CHECK_EQUAL(3.1415927, le_v3); + CHECK_EQUAL(3.1415927, be_v3); + } + + //************************************************************************* + TEST(test_move_construction_double) + { + storage_d_t store_le1; + storage_d_t store_be1; + + etl::le_double_ext_t le_v1(3.1415927, store_le1.data()); + etl::be_double_ext_t be_v1(3.1415927, store_be1.data()); + + etl::le_double_ext_t le_v2(etl::move(le_v1)); // Move construct le from le. + etl::be_double_ext_t be_v2(etl::move(be_v1)); // Move construct be from be. + + CHECK_TRUE(nullptr == le_v1.data()); + CHECK_TRUE(nullptr == be_v1.data()); + CHECK_EQUAL(3.1415927, le_v2); + CHECK_EQUAL(3.1415927, be_v2); + } + + //************************************************************************* + TEST(test_copy_construction_long_double) + { + storage_ld_t store_le1; + storage_ld_t store_be1; + storage_ld_t store_le2; + storage_ld_t store_be2; + storage_ld_t store_le3; + storage_ld_t store_be3; + + etl::le_long_double_ext_t le_v1(store_le1.data()); + le_v1 = 3.1415927L; + etl::be_long_double_ext_t be_v1(3.1415927L, store_be1.data()); + + etl::le_long_double_ext_t le_v2(le_v1, store_le2.data()); // Copy construct le from le. + etl::be_long_double_ext_t be_v2(be_v1, store_be2.data()); // Copy construct be from be. + etl::le_long_double_ext_t le_v3(be_v1, store_le3.data()); // Copy construct le from be. + etl::be_long_double_ext_t be_v3(le_v1, store_be3.data()); // Copy construct be from le. + + CHECK_EQUAL(3.1415927L, le_v2); + CHECK_EQUAL(3.1415927L, be_v2); + CHECK_EQUAL(3.1415927L, le_v3); + CHECK_EQUAL(3.1415927L, be_v3); + } + + //************************************************************************* + TEST(test_move_construction_long_double) + { + storage_ld_t store_le1; + storage_ld_t store_be1; + + etl::le_long_double_ext_t le_v1(3.1415927L, store_le1.data()); + etl::be_long_double_ext_t be_v1(3.1415927L, store_be1.data()); + + etl::le_long_double_ext_t le_v2(etl::move(le_v1)); // Move construct le from le. + etl::be_long_double_ext_t be_v2(etl::move(be_v1)); // Move construct be from be. + + CHECK_TRUE(nullptr == le_v1.data()); + CHECK_TRUE(nullptr == be_v1.data()); + CHECK_EQUAL(3.1415927L, le_v2); + CHECK_EQUAL(3.1415927L, be_v2); + } + + //************************************************************************* + TEST(test_construction_from_buffer) + { + std::array buffer = { 0x12, 0x34, 0x56, 0x78 }; + + const uint32_t le_value = 0x78563412; + const uint32_t be_value = 0x12345678; + + etl::le_uint32_ext_t le_v1(buffer.data()); + etl::be_uint32_ext_t be_v1(buffer.data()); + + CHECK_EQUAL(le_value, le_v1); + CHECK_EQUAL(be_value, be_v1); + } + + //************************************************************************* + TEST(test_set_storage_buffers) + { + // Define storeage buffers. + storage_i32_t store_le1; + storage_i32_t store_le2; + + storage_i32_t store_be1; + storage_i32_t store_be2; + + // Fill each with data. + const uint32_t value1 = 0x01234567; + const uint32_t value2 = 0x12345678; + + etl::le_uint32_ext_t le_v1(value1, store_le1.data()); + etl::le_uint32_ext_t le_v2(value2, store_le2.data()); + + etl::be_uint32_ext_t be_v1(value1, store_be1.data()); + etl::be_uint32_ext_t be_v2(value2, store_be2.data()); + + // Check each little endian storage. + etl::le_uint32_ext_t le_v(nullptr); + + le_v.set_storage(store_le1.data()); + CHECK_EQUAL(value1, le_v); + CHECK_EQUAL(store_le1.data(), le_v.data()); + + le_v.set_storage(store_le2.data()); + CHECK_EQUAL(value2, le_v); + CHECK_EQUAL(store_le2.data(), le_v.data()); + + // Check each big endian storage. + etl::be_uint32_ext_t be_v(nullptr); + + be_v.set_storage(store_be1.data()); + CHECK_EQUAL(value1, be_v); + CHECK_EQUAL(store_be1.data(), be_v.data()); + + be_v.set_storage(store_be2.data()); + CHECK_EQUAL(value2, be_v); + CHECK_EQUAL(store_be2.data(), be_v.data()); + } + + //************************************************************************* + TEST(test_endianness) + { + CHECK_EQUAL(etl::endian::big, etl::be_int16_ext_t::Endian); + CHECK_EQUAL(etl::endian::little, etl::le_int16_ext_t::Endian); + } + + //************************************************************************* + TEST(test_le_sizes) + { + CHECK_EQUAL(sizeof(char), etl::le_char_ext_t::Size); + CHECK_EQUAL(sizeof(signed char), etl::le_schar_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned char), etl::le_uchar_ext_t::Size); + CHECK_EQUAL(sizeof(short), etl::le_short_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned short), etl::le_ushort_ext_t::Size); + CHECK_EQUAL(sizeof(int), etl::le_int_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned int), etl::le_uint_ext_t::Size); + CHECK_EQUAL(sizeof(long), etl::le_long_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned long), etl::le_ulong_ext_t::Size); + CHECK_EQUAL(sizeof(long long), etl::le_long_long_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned long long), etl::le_ulong_long_ext_t::Size); + CHECK_EQUAL(sizeof(float), etl::le_float_ext_t::Size); + CHECK_EQUAL(sizeof(double), etl::le_double_ext_t::Size); + CHECK_EQUAL(sizeof(long double), etl::le_long_double_ext_t::Size); + + CHECK_EQUAL(sizeof(int8_t), etl::le_int8_ext_t::Size); + CHECK_EQUAL(sizeof(uint8_t), etl::le_uint8_ext_t::Size); + CHECK_EQUAL(sizeof(int16_t), etl::le_int16_ext_t::Size); + CHECK_EQUAL(sizeof(uint16_t), etl::le_uint16_ext_t::Size); + CHECK_EQUAL(sizeof(int32_t), etl::le_int32_ext_t::Size); + CHECK_EQUAL(sizeof(uint32_t), etl::le_uint32_ext_t::Size); + CHECK_EQUAL(sizeof(int64_t), etl::le_int64_ext_t::Size); + CHECK_EQUAL(sizeof(uint64_t), etl::le_uint64_ext_t::Size); + } + + //************************************************************************* + TEST(test_be_sizes) + { + CHECK_EQUAL(sizeof(char), etl::be_char_ext_t::Size); + CHECK_EQUAL(sizeof(signed char), etl::be_schar_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned char), etl::be_uchar_ext_t::Size); + CHECK_EQUAL(sizeof(short), etl::be_short_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned short), etl::be_ushort_ext_t::Size); + CHECK_EQUAL(sizeof(int), etl::be_int_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned int), etl::be_uint_ext_t::Size); + CHECK_EQUAL(sizeof(long), etl::be_long_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned long), etl::be_ulong_ext_t::Size); + CHECK_EQUAL(sizeof(long long), etl::be_long_long_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned long long), etl::be_ulong_long_ext_t::Size); + CHECK_EQUAL(sizeof(float), etl::be_float_ext_t::Size); + CHECK_EQUAL(sizeof(double), etl::be_double_ext_t::Size); + CHECK_EQUAL(sizeof(long double), etl::be_long_double_ext_t::Size); + + CHECK_EQUAL(sizeof(int8_t), etl::be_int8_ext_t::Size); + CHECK_EQUAL(sizeof(uint8_t), etl::be_uint8_ext_t::Size); + CHECK_EQUAL(sizeof(int16_t), etl::be_int16_ext_t::Size); + CHECK_EQUAL(sizeof(uint16_t), etl::be_uint16_ext_t::Size); + CHECK_EQUAL(sizeof(int32_t), etl::be_int32_ext_t::Size); + CHECK_EQUAL(sizeof(uint32_t), etl::be_uint32_ext_t::Size); + CHECK_EQUAL(sizeof(int64_t), etl::be_int64_ext_t::Size); + CHECK_EQUAL(sizeof(uint64_t), etl::be_uint64_ext_t::Size); + } + + //************************************************************************* + TEST(test_net_sizes) + { + CHECK_EQUAL(sizeof(char), etl::net_char_ext_t::Size); + CHECK_EQUAL(sizeof(signed char), etl::net_schar_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned char), etl::net_uchar_ext_t::Size); + CHECK_EQUAL(sizeof(short), etl::net_short_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned short), etl::net_ushort_ext_t::Size); + CHECK_EQUAL(sizeof(int), etl::net_int_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned int), etl::net_uint_ext_t::Size); + CHECK_EQUAL(sizeof(long), etl::net_long_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned long), etl::net_ulong_ext_t::Size); + CHECK_EQUAL(sizeof(long long), etl::net_long_long_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned long long), etl::net_ulong_long_ext_t::Size); + CHECK_EQUAL(sizeof(float), etl::net_float_ext_t::Size); + CHECK_EQUAL(sizeof(double), etl::net_double_ext_t::Size); + CHECK_EQUAL(sizeof(long double), etl::net_long_double_ext_t::Size); + + CHECK_EQUAL(sizeof(int8_t), etl::net_int8_ext_t::Size); + CHECK_EQUAL(sizeof(uint8_t), etl::net_uint8_ext_t::Size); + CHECK_EQUAL(sizeof(int16_t), etl::net_int16_ext_t::Size); + CHECK_EQUAL(sizeof(uint16_t), etl::net_uint16_ext_t::Size); + CHECK_EQUAL(sizeof(int32_t), etl::net_int32_ext_t::Size); + CHECK_EQUAL(sizeof(uint32_t), etl::net_uint32_ext_t::Size); + CHECK_EQUAL(sizeof(int64_t), etl::net_int64_ext_t::Size); + CHECK_EQUAL(sizeof(uint64_t), etl::net_uint64_ext_t::Size); + } + +#if ETL_HAS_CONSTEXPR_ENDIANNESS + //************************************************************************* + TEST(test_host_sizes) + { + CHECK_EQUAL(sizeof(char), etl::host_char_ext_t::Size); + CHECK_EQUAL(sizeof(signed char), etl::host_schar_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned char), etl::host_uchar_ext_t::Size); + CHECK_EQUAL(sizeof(short), etl::host_short_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned short), etl::host_ushort_ext_t::Size); + CHECK_EQUAL(sizeof(int), etl::host_int_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned int), etl::host_uint_ext_t::Size); + CHECK_EQUAL(sizeof(long), etl::host_long_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned long), etl::host_ulong_ext_t::Size); + CHECK_EQUAL(sizeof(long long), etl::host_long_long_ext_t::Size); + CHECK_EQUAL(sizeof(unsigned long long), etl::host_ulong_long_ext_t::Size); + CHECK_EQUAL(sizeof(float), etl::host_float_ext_t::Size); + CHECK_EQUAL(sizeof(double), etl::host_double_ext_t::Size); + CHECK_EQUAL(sizeof(long double), etl::host_long_double_ext_t::Size); + + CHECK_EQUAL(sizeof(int8_t), etl::host_int8_ext_t::Size); + CHECK_EQUAL(sizeof(uint8_t), etl::host_uint8_t::Size); + CHECK_EQUAL(sizeof(int16_t), etl::host_int16_ext_t::Size); + CHECK_EQUAL(sizeof(uint16_t), etl::host_uint16_ext_t::Size); + CHECK_EQUAL(sizeof(int32_t), etl::host_int32_ext_t::Size); + CHECK_EQUAL(sizeof(uint32_t), etl::host_uint32_ext_t::Size); + CHECK_EQUAL(sizeof(int64_t), etl::host_int64_ext_t::Size); + CHECK_EQUAL(sizeof(uint64_t), etl::host_uint64_ext_t::Size); + } +#endif + + //************************************************************************* + TEST(test_le_equality) + { + // char + storage_c_t store_c1; + storage_c_t store_c2; + storage_c_t store_c3; + storage_c_t store_c4; + + CHECK(etl::le_char_ext_t(0x01, store_c1.data()) == etl::le_char_ext_t(0x01, store_c2.data())); + CHECK(char(0x01) == etl::le_char_ext_t(0x01, store_c3.data())); + CHECK(etl::le_char_ext_t(0x01, store_c4.data()) == char(0x01)); + + CHECK(etl::le_schar_ext_t(0x01, store_c1.data()) == etl::le_schar_ext_t(0x01, store_c2.data())); + CHECK((signed char)(0x01) == etl::le_schar_ext_t(0x01, store_c3.data())); + CHECK(etl::le_schar_ext_t(0x01, store_c4.data()) == (signed char)(0x01)); + + CHECK(etl::le_uchar_ext_t(0x01U, store_c1.data()) == etl::le_uchar_ext_t(0x01U, store_c2.data())); + CHECK(0x01U == etl::le_uchar_ext_t(0x01U, store_c3.data())); + CHECK(etl::le_uchar_ext_t(0x01U, store_c4.data()) == 0x01U); + + // short + storage_s_t store_s1; + storage_s_t store_s2; + storage_s_t store_s3; + storage_s_t store_s4; + + CHECK(etl::le_short_ext_t(0x0123, store_s1.data()) == etl::le_short_ext_t(0x0123, store_s2.data())); + CHECK(short(0x0123) == etl::le_short_ext_t(0x0123, store_s3.data())); + CHECK(etl::le_short_ext_t(0x0123, store_s4.data()) == short(0x0123)); + + CHECK(etl::le_ushort_ext_t(0x0123, store_s1.data()) == etl::le_ushort_ext_t(0x0123, store_s2.data())); + CHECK((unsigned short)(0x0123) == etl::le_ushort_ext_t(0x0123, store_s3.data())); + CHECK(etl::le_ushort_ext_t(0x0123, store_s4.data()) == (unsigned short)(0x0123)); + + // int + storage_i_t store_i1; + storage_i_t store_i2; + storage_i_t store_i3; + storage_i_t store_i4; + + CHECK(etl::le_int_ext_t(0x01234567, store_i1.data()) == etl::le_int_ext_t(0x01234567, store_i2.data())); + CHECK(int(0x01234567) == etl::le_int_ext_t(0x01234567, store_i3.data())); + CHECK(etl::le_int_ext_t(0x01234567, store_i4.data()) == int(0x01234567)); + + CHECK(etl::le_uint_ext_t(0x01234567U, store_i1.data()) == etl::le_uint_ext_t(0x01234567U, store_i2.data())); + CHECK((unsigned int)(0x01234567U) == etl::le_uint_ext_t(0x01234567U, store_i3.data())); + CHECK(etl::le_uint_ext_t(0x01234567U, store_i4.data()) == (unsigned int)(0x01234567U)); + + if (sizeof(long) == 4U) + { + // long + storage_l_t store_l1; + storage_l_t store_l2; + storage_l_t store_l3; + storage_l_t store_l4; + + CHECK(etl::le_long_ext_t(0x01234567L, store_l1.data()) == etl::le_long_ext_t(0x01234567L, store_l2.data())); + CHECK(long(0x01234567L) == etl::le_long_ext_t(0x01234567L, store_l3.data())); + CHECK(etl::le_long_ext_t(0x01234567L, store_l4.data()) == long(0x01234567L)); + + CHECK(etl::le_ulong_ext_t(0x01234567UL, store_l1.data()) == etl::le_ulong_ext_t(0x01234567UL, store_l2.data())); + CHECK((unsigned long)(0x01234567UL) == etl::le_ulong_ext_t(0x01234567UL, store_l3.data())); + CHECK(etl::le_ulong_ext_t(0x01234567UL, store_l4.data()) == (unsigned long)(0x01234567UL)); + } + + if (sizeof(long long) == 8U) + { + // long long + storage_ll_t store_ll1; + storage_ll_t store_ll2; + storage_ll_t store_ll3; + storage_ll_t store_ll4; + + CHECK(etl::le_long_long_ext_t(0x0123456789ABCDEF, store_ll1.data()) == etl::le_long_long_ext_t(0x0123456789ABCDEF, store_ll2.data())); + CHECK((long long)(0x0123456789ABCDEF) == etl::le_long_long_ext_t(0x0123456789ABCDEF, store_ll3.data())); + CHECK(etl::le_long_long_ext_t(0x0123456789ABCDEF, store_ll4.data()) == (long long)(0x0123456789ABCDEF)); + + CHECK(etl::le_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll1.data()) == etl::le_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll2.data())); + CHECK((unsigned long long)(0x0123456789ABCDEFU) == etl::le_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll3.data())); + CHECK(etl::le_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll4.data()) == (unsigned long long)(0x0123456789ABCDEFU)); + } + + // float + storage_f_t store_f1; + storage_f_t store_f2; + storage_f_t store_f3; + storage_f_t store_f4; + + CHECK_CLOSE(etl::le_float_ext_t(3.1415927f, store_f1.data()), etl::le_float_ext_t(3.1415927f, store_f2.data()), 0.001); + CHECK_CLOSE(3.1415927f, etl::le_float_ext_t(3.1415927f, store_f3.data()), 0.001); + CHECK_CLOSE(etl::le_float_ext_t(3.1415927f, store_f4.data()), 3.1415927f, 0.001); + + // double + storage_d_t store_d1; + storage_d_t store_d2; + storage_d_t store_d3; + storage_d_t store_d4; + + CHECK_CLOSE(etl::le_double_ext_t(3.1415927, store_d1.data()), etl::le_double_ext_t(3.1415927, store_d2.data()), 0.001); + CHECK_CLOSE(3.1415927, etl::le_double_ext_t(3.1415927, store_d3.data()), 0.001); + CHECK_CLOSE(etl::le_double_ext_t(3.1415927, store_d4.data()), 3.1415927, 0.001); + + // long double + storage_ld_t store_ld1; + storage_ld_t store_ld2; + storage_ld_t store_ld3; + storage_ld_t store_ld4; + + CHECK_CLOSE(etl::le_long_double_ext_t(3.1415927L, store_ld1.data()).value(), etl::le_long_double_ext_t(3.1415927L, store_ld2.data()).value(), 0.001); + CHECK_CLOSE(3.1415927L, etl::le_long_double_ext_t(3.1415927L, store_ld3.data()).value(), 0.001); + CHECK_CLOSE(etl::le_long_double_ext_t(3.1415927L, store_ld4.data()).value(), 3.1415927L, 0.001); + } + + //************************************************************************* + TEST(test_le_inequality) + { + // char + storage_c_t store_c1; + storage_c_t store_c2; + storage_c_t store_c3; + storage_c_t store_c4; + + CHECK(etl::le_char_ext_t(0x01, store_c1.data()) != etl::le_char_ext_t(0x02, store_c2.data())); + CHECK(char(0x01) != etl::le_char_ext_t(0x02, store_c3.data())); + CHECK(etl::le_char_ext_t(0x01, store_c4.data()) != char(0x02)); + + CHECK(etl::le_schar_ext_t(0x01, store_c1.data()) != etl::le_schar_ext_t(0x02, store_c2.data())); + CHECK((signed char)(0x01) != etl::le_schar_ext_t(0x02, store_c3.data())); + CHECK(etl::le_schar_ext_t(0x01, store_c4.data()) != (signed char)(0x02)); + + CHECK(etl::le_uchar_ext_t(0x01U, store_c1.data()) != etl::le_uchar_ext_t(0x02U, store_c2.data())); + CHECK(0x01U != etl::le_uchar_ext_t(0x02U, store_c3.data())); + CHECK(etl::le_uchar_ext_t(0x01U, store_c4.data()) != 0x02U); + + // short + storage_s_t store_s1; + storage_s_t store_s2; + storage_s_t store_s3; + storage_s_t store_s4; + + CHECK(etl::le_short_ext_t(0x0123, store_s1.data()) != etl::le_short_ext_t(0x0223, store_s2.data())); + CHECK(short(0x0123) != etl::le_short_ext_t(0x0223, store_s3.data())); + CHECK(etl::le_short_ext_t(0x0123, store_s4.data()) != short(0x0223)); + + CHECK(etl::le_ushort_ext_t(0x0123, store_s1.data()) != etl::le_ushort_ext_t(0x0223, store_s2.data())); + CHECK((unsigned short)(0x0123) != etl::le_ushort_ext_t(0x0223, store_s3.data())); + CHECK(etl::le_ushort_ext_t(0x0123, store_s4.data()) != (unsigned short)(0x0223)); + + // int + storage_i_t store_i1; + storage_i_t store_i2; + storage_i_t store_i3; + storage_i_t store_i4; + + CHECK(etl::le_int_ext_t(0x01234567, store_i1.data()) != etl::le_int_ext_t(0x02234567, store_i2.data())); + CHECK(int(0x01234567) != etl::le_int_ext_t(0x02234567, store_i3.data())); + CHECK(etl::le_int_ext_t(0x01234567, store_i4.data()) != int(0x02234567)); + + CHECK(etl::le_uint_ext_t(0x01234567U, store_i1.data()) != etl::le_uint_ext_t(0x02234567U, store_i2.data())); + CHECK((unsigned int)(0x01234567U) != etl::le_uint_ext_t(0x02234567U, store_i3.data())); + CHECK(etl::le_uint_ext_t(0x01234567U, store_i4.data()) != (unsigned int)(0x02234567U)); + + if (sizeof(long) != 4U) + { + // long + storage_l_t store_l1; + storage_l_t store_l2; + storage_l_t store_l3; + storage_l_t store_l4; + + CHECK(etl::le_long_ext_t(0x01234567L, store_l1.data()) != etl::le_long_ext_t(0x02234567L, store_l2.data())); + CHECK(long(0x01234567L) != etl::le_long_ext_t(0x02234567L, store_l3.data())); + CHECK(etl::le_long_ext_t(0x01234567L, store_l4.data()) != long(0x02234567L)); + + CHECK(etl::le_ulong_ext_t(0x01234567UL, store_l1.data()) != etl::le_ulong_ext_t(0x02234567UL, store_l2.data())); + CHECK((unsigned long)(0x01234567UL) != etl::le_ulong_ext_t(0x02234567UL, store_l3.data())); + CHECK(etl::le_ulong_ext_t(0x01234567UL, store_l4.data()) != (unsigned long)(0x02234567UL)); + } + + if (sizeof(long long) == 8U) + { + // long long + storage_ll_t store_ll1; + storage_ll_t store_ll2; + storage_ll_t store_ll3; + storage_ll_t store_ll4; + + CHECK(etl::le_long_long_ext_t(0x0123456789ABCDEF, store_ll1.data()) != etl::le_long_long_ext_t(0x0223456789ABCDEF, store_ll2.data())); + CHECK((long long)(0x0123456789ABCDEF) != etl::le_long_long_ext_t(0x0223456789ABCDEF, store_ll3.data())); + CHECK(etl::le_long_long_ext_t(0x0123456789ABCDEF, store_ll4.data()) != (long long)(0x0223456789ABCDEF)); + + CHECK(etl::le_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll1.data()) != etl::le_ulong_long_ext_t(0x0223456789ABCDEFU, store_ll2.data())); + CHECK((unsigned long long)(0x0123456789ABCDEFU) != etl::le_ulong_long_ext_t(0x0223456789ABCDEFU, store_ll3.data())); + CHECK(etl::le_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll4.data()) != (unsigned long long)(0x0223456789ABCDEFU)); + } + + // float + storage_f_t store_f1; + storage_f_t store_f2; + storage_f_t store_f3; + storage_f_t store_f4; + + CHECK_FLOAT_DIFFERENT(etl::le_float_ext_t(3.1415927f, store_f1.data()), etl::le_float_ext_t(2.1415927f, store_f2.data())); + CHECK_FLOAT_DIFFERENT(3.1415927f, etl::le_float_ext_t(2.1415927f, store_f3.data())); + CHECK_FLOAT_DIFFERENT(etl::le_float_ext_t(3.1415927f, store_f4.data()), 2.1415927f); + + // double + storage_d_t store_d1; + storage_d_t store_d2; + storage_d_t store_d3; + storage_d_t store_d4; + + CHECK_FLOAT_DIFFERENT(etl::le_double_ext_t(3.1415927, store_d1.data()), etl::le_double_ext_t(2.1415927, store_d2.data())); + CHECK_FLOAT_DIFFERENT(3.1415927, etl::le_double_ext_t(2.1415927, store_d3.data())); + CHECK_FLOAT_DIFFERENT(etl::le_double_ext_t(3.1415927, store_d4.data()), 2.1415927); + + // long double + storage_ld_t store_ld1; + storage_ld_t store_ld2; + storage_ld_t store_ld3; + storage_ld_t store_ld4; + + CHECK_FLOAT_DIFFERENT(etl::le_long_double_ext_t(3.1415927L, store_ld1.data()), etl::le_long_double_ext_t(2.1415927L, store_ld2.data())); + CHECK_FLOAT_DIFFERENT(3.1415927L, etl::le_long_double_ext_t(2.1415927L, store_ld3.data())); + CHECK_FLOAT_DIFFERENT(etl::le_long_double_ext_t(3.1415927L, store_ld4.data()), 2.1415927L); + } + + //************************************************************************* + TEST(test_be_equality) + { + // char + storage_c_t store_c_be1; + storage_c_t store_c_be2; + storage_c_t store_c_be3; + storage_c_t store_c_be4; + + CHECK(etl::be_char_ext_t(0x01, store_c_be1.data()) == etl::be_char_ext_t(0x01, store_c_be2.data())); + CHECK(char(0x01) == etl::be_char_ext_t(0x01, store_c_be3.data())); + CHECK(etl::be_char_ext_t(0x01, store_c_be4.data()) == char(0x01)); + + CHECK(etl::be_schar_ext_t(0x01, store_c_be1.data()) == etl::be_schar_ext_t(0x01, store_c_be2.data())); + CHECK((signed char)(0x01) == etl::be_schar_ext_t(0x01, store_c_be3.data())); + CHECK(etl::be_schar_ext_t(0x01, store_c_be4.data()) == (signed char)(0x01)); + + CHECK(etl::be_uchar_ext_t(0x01U, store_c_be1.data()) == etl::be_uchar_ext_t(0x01U, store_c_be2.data())); + CHECK(0x01U == etl::be_uchar_ext_t(0x01U, store_c_be3.data())); + CHECK(etl::be_uchar_ext_t(0x01U, store_c_be4.data()) == 0x01U); + + // short + storage_s_t store_s_be1; + storage_s_t store_s_be2; + storage_s_t store_s_be3; + storage_s_t store_s_be4; + + CHECK(etl::be_short_ext_t(0x0123, store_s_be1.data()) == etl::be_short_ext_t(0x0123, store_s_be2.data())); + CHECK(short(0x0123) == etl::be_short_ext_t(0x0123, store_s_be3.data())); + CHECK(etl::be_short_ext_t(0x0123, store_s_be4.data()) == short(0x0123)); + + CHECK(etl::be_ushort_ext_t(0x0123, store_s_be1.data()) == etl::be_ushort_ext_t(0x0123, store_s_be2.data())); + CHECK((unsigned short)(0x0123) == etl::be_ushort_ext_t(0x0123, store_s_be3.data())); + CHECK(etl::be_ushort_ext_t(0x0123, store_s_be4.data()) == (unsigned short)(0x0123)); + + // int + storage_i_t store_i_be1; + storage_i_t store_i_be2; + storage_i_t store_i_be3; + storage_i_t store_i_be4; + + CHECK(etl::be_int_ext_t(0x01234567, store_i_be1.data()) == etl::be_int_ext_t(0x01234567, store_i_be2.data())); + CHECK(int(0x01234567) == etl::be_int_ext_t(0x01234567, store_i_be3.data())); + CHECK(etl::be_int_ext_t(0x01234567, store_i_be4.data()) == int(0x01234567)); + + CHECK(etl::be_uint_ext_t(0x01234567U, store_i_be1.data()) == etl::be_uint_ext_t(0x01234567U, store_i_be2.data())); + CHECK((unsigned int)(0x01234567U) == etl::be_uint_ext_t(0x01234567U, store_i_be3.data())); + CHECK(etl::be_uint_ext_t(0x01234567U, store_i_be4.data()) == (unsigned int)(0x01234567U)); + + if (sizeof(long) == 4U) + { + // long + storage_l_t store_l_be1; + storage_l_t store_l_be2; + storage_l_t store_l_be3; + storage_l_t store_l_be4; + + CHECK(etl::be_long_ext_t(0x01234567L, store_l_be1.data()) == etl::be_long_ext_t(0x01234567L, store_l_be2.data())); + CHECK(long(0x01234567L) == etl::be_long_ext_t(0x01234567L, store_l_be3.data())); + CHECK(etl::be_long_ext_t(0x01234567L, store_l_be4.data()) == long(0x01234567L)); + + CHECK(etl::be_ulong_ext_t(0x01234567UL, store_l_be1.data()) == etl::be_ulong_ext_t(0x01234567UL, store_l_be2.data())); + CHECK((unsigned long)(0x01234567UL) == etl::be_ulong_ext_t(0x01234567UL, store_l_be3.data())); + CHECK(etl::be_ulong_ext_t(0x01234567UL, store_l_be4.data()) == (unsigned long)(0x01234567UL)); + } + + if (sizeof(long long) == 8U) + { + // long long + storage_ll_t store_ll_be1; + storage_ll_t store_ll_be2; + storage_ll_t store_ll_be3; + storage_ll_t store_ll_be4; + + CHECK(etl::be_long_long_ext_t(0x0123456789ABCDEF, store_ll_be1.data()) == etl::be_long_long_ext_t(0x0123456789ABCDEF, store_ll_be2.data())); + CHECK((long long)(0x0123456789ABCDEF) == etl::be_long_long_ext_t(0x0123456789ABCDEF, store_ll_be3.data())); + CHECK(etl::be_long_long_ext_t(0x0123456789ABCDEF, store_ll_be4.data()) == (long long)(0x0123456789ABCDEF)); + + CHECK(etl::be_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll_be1.data()) == etl::be_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll_be2.data())); + CHECK((unsigned long long)(0x0123456789ABCDEFU) == etl::be_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll_be3.data())); + CHECK(etl::be_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll_be4.data()) == (unsigned long long)(0x0123456789ABCDEFU)); + } + + // float + storage_f_t store_f_be1; + storage_f_t store_f_be2; + storage_f_t store_f_be3; + storage_f_t store_f_be4; + + CHECK_CLOSE(etl::be_float_ext_t(3.1415927f, store_f_be1.data()), etl::be_float_ext_t(3.1415927f, store_f_be2.data()), 0.001); + CHECK_CLOSE(3.1415927f, etl::be_float_ext_t(3.1415927f, store_f_be3.data()), 0.001); + CHECK_CLOSE(etl::be_float_ext_t(3.1415927f, store_f_be4.data()), 3.1415927f, 0.001); + + // double + storage_d_t store_d_be1; + storage_d_t store_d_be2; + storage_d_t store_d_be3; + storage_d_t store_d_be4; + + CHECK_CLOSE(etl::be_double_ext_t(3.1415927, store_d_be1.data()), etl::be_double_ext_t(3.1415927, store_d_be2.data()), 0.001); + CHECK_CLOSE(3.1415927, etl::be_double_ext_t(3.1415927, store_d_be3.data()), 0.001); + CHECK_CLOSE(etl::be_double_ext_t(3.1415927, store_d_be4.data()), 3.1415927, 0.001); + + // long double + storage_ld_t store_ld_be1; + storage_ld_t store_ld_be2; + storage_ld_t store_ld_be3; + storage_ld_t store_ld_be4; + + CHECK_CLOSE(etl::be_long_double_ext_t(3.1415927L, store_ld_be1.data()).value(), etl::be_long_double_ext_t(3.1415927L, store_ld_be2.data()).value(), 0.001); + CHECK_CLOSE(3.1415927L, etl::be_long_double_ext_t(3.1415927L, store_ld_be3.data()).value(), 0.001); + CHECK_CLOSE(etl::be_long_double_ext_t(3.1415927L, store_ld_be4.data()).value(), 3.1415927L, 0.001); + } + + //************************************************************************* + TEST(test_be_inequality) + { + // char + storage_c_t store_c_be1; + storage_c_t store_c_be2; + storage_c_t store_c_be3; + storage_c_t store_c_be4; + + CHECK(etl::be_char_ext_t(0x01, store_c_be1.data()) != etl::be_char_ext_t(0x02, store_c_be2.data())); + CHECK(char(0x01) != etl::be_char_ext_t(0x02, store_c_be3.data())); + CHECK(etl::be_char_ext_t(0x01, store_c_be4.data()) != char(0x02)); + + CHECK(etl::be_schar_ext_t(0x01, store_c_be1.data()) != etl::be_schar_ext_t(0x02, store_c_be2.data())); + CHECK((signed char)(0x01) != etl::be_schar_ext_t(0x02, store_c_be3.data())); + CHECK(etl::be_schar_ext_t(0x01, store_c_be4.data()) != (signed char)(0x02)); + + CHECK(etl::be_uchar_ext_t(0x01U, store_c_be1.data()) != etl::be_uchar_ext_t(0x02U, store_c_be2.data())); + CHECK(0x01U != etl::be_uchar_ext_t(0x02U, store_c_be3.data())); + CHECK(etl::be_uchar_ext_t(0x01U, store_c_be4.data()) != 0x02U); + + // short + storage_s_t store_s_be1; + storage_s_t store_s_be2; + storage_s_t store_s_be3; + storage_s_t store_s_be4; + + CHECK(etl::be_short_ext_t(0x0123, store_s_be1.data()) != etl::be_short_ext_t(0x0223, store_s_be2.data())); + CHECK(short(0x0123) != etl::be_short_ext_t(0x0223, store_s_be3.data())); + CHECK(etl::be_short_ext_t(0x0123, store_s_be4.data()) != short(0x0223)); + + CHECK(etl::be_ushort_ext_t(0x0123, store_s_be1.data()) != etl::be_ushort_ext_t(0x0223, store_s_be2.data())); + CHECK((unsigned short)(0x0123) != etl::be_ushort_ext_t(0x0223, store_s_be3.data())); + CHECK(etl::be_ushort_ext_t(0x0123, store_s_be4.data()) != (unsigned short)(0x0223)); + + // int + storage_i_t store_i_be1; + storage_i_t store_i_be2; + storage_i_t store_i_be3; + storage_i_t store_i_be4; + + CHECK(etl::be_int_ext_t(0x01234567, store_i_be1.data()) != etl::be_int_ext_t(0x02234567, store_i_be2.data())); + CHECK(int(0x01234567) != etl::be_int_ext_t(0x02234567, store_i_be3.data())); + CHECK(etl::be_int_ext_t(0x01234567, store_i_be4.data()) != int(0x02234567)); + + CHECK(etl::be_uint_ext_t(0x01234567U, store_i_be1.data()) != etl::be_uint_ext_t(0x02234567U, store_i_be2.data())); + CHECK((unsigned int)(0x01234567U) != etl::be_uint_ext_t(0x02234567U, store_i_be3.data())); + CHECK(etl::be_uint_ext_t(0x01234567U, store_i_be4.data()) != (unsigned int)(0x02234567U)); + + if (sizeof(long) != 4U) + { + // long + storage_l_t store_l_be1; + storage_l_t store_l_be2; + storage_l_t store_l_be3; + storage_l_t store_l_be4; + + CHECK(etl::be_long_ext_t(0x01234567L, store_l_be1.data()) != etl::be_long_ext_t(0x02234567L, store_l_be2.data())); + CHECK(long(0x01234567L) != etl::be_long_ext_t(0x02234567L, store_l_be3.data())); + CHECK(etl::be_long_ext_t(0x01234567L, store_l_be4.data()) != long(0x02234567L)); + + CHECK(etl::be_ulong_ext_t(0x01234567UL, store_l_be1.data()) != etl::be_ulong_ext_t(0x02234567UL, store_l_be2.data())); + CHECK((unsigned long)(0x01234567UL) != etl::be_ulong_ext_t(0x02234567UL, store_l_be3.data())); + CHECK(etl::be_ulong_ext_t(0x01234567UL, store_l_be4.data()) != (unsigned long)(0x02234567UL)); + } + + if (sizeof(long long) == 8U) + { + // long long + storage_ll_t store_ll_be1; + storage_ll_t store_ll_be2; + storage_ll_t store_ll_be3; + storage_ll_t store_ll_be4; + + CHECK(etl::be_long_long_ext_t(0x0123456789ABCDEF, store_ll_be1.data()) != etl::be_long_long_ext_t(0x0223456789ABCDEF, store_ll_be2.data())); + CHECK((long long)(0x0123456789ABCDEF) != etl::be_long_long_ext_t(0x0223456789ABCDEF, store_ll_be3.data())); + CHECK(etl::be_long_long_ext_t(0x0123456789ABCDEF, store_ll_be4.data()) != (long long)(0x0223456789ABCDEF)); + + CHECK(etl::be_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll_be1.data()) != etl::be_ulong_long_ext_t(0x0223456789ABCDEFU, store_ll_be2.data())); + CHECK((unsigned long long)(0x0123456789ABCDEFU) != etl::be_ulong_long_ext_t(0x0223456789ABCDEFU, store_ll_be3.data())); + CHECK(etl::be_ulong_long_ext_t(0x0123456789ABCDEFU, store_ll_be4.data()) != (unsigned long long)(0x0223456789ABCDEFU)); + } + + // float + storage_f_t store_f_be1; + storage_f_t store_f_be2; + storage_f_t store_f_be3; + storage_f_t store_f_be4; + + CHECK_FLOAT_DIFFERENT(etl::be_float_ext_t(3.1415927f, store_f_be1.data()), etl::be_float_ext_t(2.1415927f, store_f_be2.data())); + CHECK_FLOAT_DIFFERENT(3.1415927f, etl::be_float_ext_t(2.1415927f, store_f_be3.data())); + CHECK_FLOAT_DIFFERENT(etl::be_float_ext_t(3.1415927f, store_f_be4.data()), 2.1415927f); + + // double + storage_d_t store_d_be1; + storage_d_t store_d_be2; + storage_d_t store_d_be3; + storage_d_t store_d_be4; + + CHECK_FLOAT_DIFFERENT(etl::be_double_ext_t(3.1415927, store_d_be1.data()), etl::be_double_ext_t(2.1415927, store_d_be2.data())); + CHECK_FLOAT_DIFFERENT(3.1415927, etl::be_double_ext_t(2.1415927, store_d_be3.data())); + CHECK_FLOAT_DIFFERENT(etl::be_double_ext_t(3.1415927, store_d_be4.data()), 2.1415927); + + // long double + storage_ld_t store_ld_be1; + storage_ld_t store_ld_be2; + storage_ld_t store_ld_be3; + storage_ld_t store_ld_be4; + + CHECK_FLOAT_DIFFERENT(etl::be_long_double_ext_t(3.1415927L, store_ld_be1.data()), etl::be_long_double_ext_t(2.1415927L, store_ld_be2.data())); + CHECK_FLOAT_DIFFERENT(3.1415927L, etl::be_long_double_ext_t(2.1415927L, store_ld_be3.data())); + CHECK_FLOAT_DIFFERENT(etl::be_long_double_ext_t(3.1415927L, store_ld_be4.data()), 2.1415927L); + } + + //************************************************************************* + TEST(test_le_assignment) + { + storage_c_t store_c1; + storage_c_t store_c2; + storage_c_t store_c3; + + etl::le_char_ext_t le_char(store_c1.data()); + le_char = 0x01; + CHECK(0x01 == (char)le_char); + + etl::le_schar_ext_t le_schar(store_c2.data()); + le_schar = 0x01; + CHECK(0x01 == (signed char)le_schar); + + etl::le_uchar_ext_t le_uchar(store_c3.data()); + le_uchar = 0x01; + CHECK(0x01 == (unsigned char)le_uchar); + + storage_s_t store_s1; + storage_s_t store_s2; + + etl::le_short_ext_t le_short(store_s1.data()); + le_short = 0x0123; + CHECK(0x0123 == (short)le_short); + + etl::le_ushort_ext_t le_ushort(store_s2.data()); + le_ushort = 0x0123; + CHECK(0x0123 == (unsigned short)le_ushort); + + storage_i_t store_i1; + storage_i_t store_i2; + + etl::le_int_ext_t le_int(store_i1.data()); + le_int = 0x01234567; + CHECK(0x01234567 == (int)le_int); + + etl::le_uint_ext_t le_uint(store_i2.data()); + le_uint = 0x01234567; + CHECK(0x01234567 == (unsigned int)le_uint); + + storage_l_t store_l1; + storage_l_t store_l2; + + if (sizeof(long) == 4U) + { + etl::le_long_ext_t le_long(store_l1.data()); + le_long = 0x01234567; + CHECK(0x01234567 == (long)le_long); + + etl::le_ulong_ext_t le_ulong(store_l2.data()); + le_ulong = 0x01234567; + CHECK(0x01234567 == (unsigned long)le_ulong); + } + + if (sizeof(long long) == 8U) + { + storage_ll_t store_ll1; + storage_ll_t store_ll2; + + etl::le_long_long_ext_t le_long(store_ll1.data()); + le_long = 0x0123456789ABCDEF; + CHECK(0x0123456789ABCDEF == (long long)le_long); + + etl::le_ulong_long_ext_t le_ulong(store_ll2.data()); + le_ulong = 0x0123456789ABCDEF; + CHECK(0x0123456789ABCDEF == (unsigned long long)le_ulong); + } + + // float + storage_f_t store_f; + + etl::le_float_ext_t le_float(store_f.data()); + le_float = 3.1415927f; + CHECK_CLOSE(3.1415927f, le_float, 0.001); + + // double + storage_d_t store_d; + + etl::le_double_ext_t le_double(store_d.data()); + le_double = 3.1415927; + CHECK_CLOSE(3.1415927, le_double, 0.001); + + // long double + storage_ld_t store_ld; + + etl::le_long_double_ext_t le_long_double(store_ld.data()); + le_long_double = 3.1415927L; + CHECK_CLOSE(3.1415927L, le_long_double, 0.001); + } + + //************************************************************************* + TEST(test_be_assignment) + { + storage_c_t store_c1; + storage_c_t store_c2; + storage_c_t store_c3; + + etl::be_char_ext_t be_char(store_c1.data()); + be_char = 0x01; + CHECK(0x01 == (char)be_char); + + etl::be_schar_ext_t be_schar(store_c2.data()); + be_schar = 0x01; + CHECK(0x01 == (signed char)be_schar); + + etl::be_uchar_ext_t be_uchar(store_c3.data()); + be_uchar = 0x01; + CHECK(0x01 == (unsigned char)be_uchar); + + storage_s_t store_s1; + storage_s_t store_s2; + + etl::be_short_ext_t be_short(store_s1.data()); + be_short = 0x0123; + CHECK(0x0123 == (short)be_short); + + etl::be_ushort_ext_t be_ushort(store_s2.data()); + be_ushort = 0x0123; + CHECK(0x0123 == (unsigned short)be_ushort); + + storage_i_t store_i1; + storage_i_t store_i2; + + etl::be_int_ext_t be_int(store_i1.data()); + be_int = 0x01234567; + CHECK(0x01234567 == (int)be_int); + + etl::be_uint_ext_t be_uint(store_i2.data()); + be_uint = 0x01234567; + CHECK(0x01234567 == (unsigned int)be_uint); + + storage_l_t store_l1; + storage_l_t store_l2; + + if (sizeof(long) == 4U) + { + etl::be_long_ext_t be_long(store_l1.data()); + be_long = 0x01234567; + CHECK(0x01234567 == (long)be_long); + + etl::be_ulong_ext_t be_ulong(store_l2.data()); + be_ulong = 0x01234567; + CHECK(0x01234567 == (unsigned long)be_ulong); + } + + if (sizeof(long long) == 8U) + { + storage_ll_t store_ll1; + storage_ll_t store_ll2; + + etl::be_long_long_ext_t be_long(store_ll1.data()); + be_long = 0x0123456789ABCDEF; + CHECK(0x0123456789ABCDEF == (long long)be_long); + + etl::be_ulong_long_ext_t be_ulong(store_ll2.data()); + be_ulong = 0x0123456789ABCDEF; + CHECK(0x0123456789ABCDEF == (unsigned long long)be_ulong); + } + + // float + storage_f_t store_f; + + etl::be_float_ext_t be_float(store_f.data()); + be_float = 3.1415927f; + CHECK_CLOSE(3.1415927f, be_float, 0.001); + + // double + storage_d_t store_d; + + etl::be_double_ext_t be_double(store_d.data()); + be_double = 3.1415927; + CHECK_CLOSE(3.1415927, be_double, 0.001); + + // long double + storage_ld_t store_ld; + + etl::be_long_double_ext_t be_long_double(store_ld.data()); + be_long_double = 3.1415927L; + CHECK_CLOSE(3.1415927L, be_long_double, 0.001); + } + + //************************************************************************* + TEST(test_cross_assignment) + { + storage_i32_t store_le1; + storage_i32_t store_be1; + storage_i32_t store_le2; + storage_i32_t store_be2; + + etl::le_uint32_ext_t le_v1(0x01234567, store_le1.data()); + etl::be_uint32_ext_t be_v1(0x01234567, store_be1.data()); + etl::le_uint32_ext_t le_v2(store_le2.data()); + etl::be_uint32_ext_t be_v2(store_be2.data()); + + le_v2 = be_v1; // Assign le from be. + be_v2 = le_v1; // Assign be from le. + + CHECK_EQUAL(int(0x01234567), int(le_v2)); + CHECK_EQUAL(int(0x01234567), int(be_v2)); + } + + //************************************************************************* + TEST(test_cross_move_assignment) + { + storage_i32_t store_le1; + storage_i32_t store_be1; + storage_i32_t store_le2; + storage_i32_t store_be2; + + etl::le_uint32_ext_t le_v1(0x01234567, store_le1.data()); + etl::be_uint32_ext_t be_v1(0x01234567, store_be1.data()); + etl::le_uint32_ext_t le_v2(store_le2.data()); + etl::be_uint32_ext_t be_v2(store_be2.data()); + + le_v2 = etl::move(be_v1); // Assign le from be. + be_v2 = etl::move(le_v1); // Assign be from le. + + CHECK_TRUE(nullptr == le_v1.data()); + CHECK_TRUE(nullptr == be_v1.data()); + CHECK_EQUAL(int(0x01234567), int(le_v2)); + CHECK_EQUAL(int(0x01234567), int(be_v2)); + } + + //************************************************************************* + TEST(test_cross_assignment_float) + { + storage_f_t store_le1; + storage_f_t store_be1; + storage_f_t store_le2; + storage_f_t store_be2; + storage_f_t store_le3; + storage_f_t store_be3; + + etl::le_float_ext_t le_v1(3.1415927f, store_le1.data()); + etl::be_float_ext_t be_v1(3.1415927f, store_be1.data()); + etl::le_float_ext_t le_v2(store_le2.data()); + etl::be_float_ext_t be_v2(store_be2.data()); + etl::le_float_ext_t le_v3(store_le3.data()); + etl::be_float_ext_t be_v3(store_be3.data()); + + le_v2 = le_v1; // Assign le from le. + be_v2 = be_v1; // Assign be from be. + le_v3 = be_v1; // Assign le from be. + be_v3 = le_v1; // Assign be from le. + + CHECK_CLOSE(3.1415927f, le_v2, 0.001); + CHECK_CLOSE(3.1415927f, be_v2, 0.001); + CHECK_CLOSE(3.1415927f, le_v3, 0.001); + CHECK_CLOSE(3.1415927f, be_v3, 0.001); + } + + //************************************************************************* + TEST(test_cross_assignment_double) + { + storage_d_t store_le1; + storage_d_t store_be1; + storage_d_t store_le2; + storage_d_t store_be2; + storage_d_t store_le3; + storage_d_t store_be3; + + etl::le_double_ext_t le_v1(3.1415927, store_le1.data()); + etl::be_double_ext_t be_v1(3.1415927, store_be1.data()); + etl::le_double_ext_t le_v2(store_le2.data()); + etl::be_double_ext_t be_v2(store_be2.data()); + etl::le_double_ext_t le_v3(store_le3.data()); + etl::be_double_ext_t be_v3(store_be3.data()); + + le_v2 = le_v1; // Assign le from le. + be_v2 = be_v1; // Assign be from be. + le_v3 = be_v1; // Assign le from be. + be_v3 = le_v1; // Assign be from le. + + CHECK_CLOSE(3.1415927, le_v2, 0.001); + CHECK_CLOSE(3.1415927, be_v2, 0.001); + CHECK_CLOSE(3.1415927, le_v3, 0.001); + CHECK_CLOSE(3.1415927, be_v3, 0.001); + } + + //************************************************************************* + TEST(test_cross_assignment_long_double) + { + storage_ld_t store_le1; + storage_ld_t store_be1; + storage_ld_t store_le2; + storage_ld_t store_be2; + storage_ld_t store_le3; + storage_ld_t store_be3; + + etl::le_long_double_ext_t le_v1(3.1415927L, store_le1.data()); + etl::be_long_double_ext_t be_v1(3.1415927L, store_be1.data()); + etl::le_long_double_ext_t le_v2(store_le2.data()); + etl::be_long_double_ext_t be_v2(store_be2.data()); + etl::le_long_double_ext_t le_v3(store_le3.data()); + etl::be_long_double_ext_t be_v3(store_be3.data()); + + le_v2 = le_v1; // Assign le from le. + be_v2 = be_v1; // Assign be from be. + le_v3 = be_v1; // Assign le from be. + be_v3 = le_v1; // Assign be from le. + + CHECK_CLOSE(3.1415927L, le_v2, 0.001); + CHECK_CLOSE(3.1415927L, be_v2, 0.001); + CHECK_CLOSE(3.1415927L, le_v3, 0.001); + CHECK_CLOSE(3.1415927L, be_v3, 0.001); + } + + //************************************************************************* + TEST(test_data) + { + storage_s_t store_s; + + etl::be_uint16_ext_t test(0x1234, store_s.data()); + + CHECK_EQUAL(0x12, *test.data()); + CHECK_EQUAL(0x34, *(test.data() + 1U)); + } + + //************************************************************************* + TEST(test_begin_end_iterator) + { + using iterator = etl::be_uint16_t::iterator; + using const_iterator = etl::be_uint16_t::const_iterator; + + storage_i16_t store_i1; + storage_i16_t store_i2; + + etl::be_uint16_ext_t test(0x1234, store_i1.data()); + const etl::be_uint16_ext_t const_test(0x1234, store_i2.data()); + + iterator itr; + const_iterator citr; + + //******************************* + itr = test.begin(); + CHECK_EQUAL(int(0x12), int(*itr)); + ++itr; + CHECK_EQUAL(int(0x34), int(*itr)); + ++itr; + CHECK(itr == test.end()); + + //******************************* + itr = test.begin(); + *itr = 0x34; + CHECK_EQUAL(int(0x34), int(*itr)); + ++itr; + *itr = 0x12; + CHECK_EQUAL(0x12, *itr); + ++itr; + CHECK(itr == test.end()); + + //******************************* + citr = const_test.begin(); + CHECK_EQUAL(0x12, *citr); + ++citr; + CHECK_EQUAL(0x34, *citr); + ++citr; + CHECK(citr == const_test.end()); + + //******************************* + citr = const_test.cbegin(); + CHECK_EQUAL(0x12, *citr); + ++citr; + CHECK_EQUAL(0x34, *citr); + ++citr; + CHECK(citr == const_test.cend()); + } + + //************************************************************************* + TEST(test_rbegin_rend_iterator) + { + using reverse_iterator = etl::be_uint16_t::reverse_iterator; + using const_reverse_iterator = etl::be_uint16_t::const_reverse_iterator; + + storage_i16_t store_i1; + storage_i16_t store_i2; + + etl::be_uint16_ext_t test(0x1234, store_i1.data()); + const etl::be_uint16_ext_t const_test(0x1234, store_i2.data()); + + reverse_iterator itr; + const_reverse_iterator citr; + + //******************************* + itr = test.rbegin(); + CHECK_EQUAL(0x34, *itr); + ++itr; + CHECK_EQUAL(0x12, *itr); + ++itr; + CHECK(itr == test.rend()); + + //******************************* + itr = test.rbegin(); + *itr = 0x12; + CHECK_EQUAL(0x12, *itr); + ++itr; + *itr = 0x34; + CHECK_EQUAL(0x34, *itr); + ++itr; + CHECK(itr == test.rend()); + + //******************************* + citr = const_test.rbegin(); + CHECK_EQUAL(0x34, *citr); + ++citr; + CHECK_EQUAL(0x12, *citr); + ++citr; + CHECK(citr == const_test.rend()); + + //******************************* + citr = const_test.crbegin(); + CHECK_EQUAL(0x34, *citr); + ++citr; + CHECK_EQUAL(0x12, *citr); + ++citr; + CHECK(citr == const_test.crend()); + } + + //************************************************************************* + TEST(test_index_operator) + { + storage_i16_t store_i1; + storage_i16_t store_i2; + storage_i16_t store_i3; + storage_i16_t store_i4; + + etl::le_uint16_ext_t test_le(0x1234, store_i1.data()); + const etl::le_uint16_ext_t const_test_le(0x1234, store_i2.data()); + + etl::be_uint16_ext_t test_be(0x1234, store_i3.data()); + const etl::be_uint16_ext_t const_test_be(0x1234, store_i4.data()); + + CHECK_EQUAL(0x34, test_le[0]); + CHECK_EQUAL(0x12, test_le[1]); + + test_le[0] = 0x56; + test_le[1] = 0x78; + CHECK_EQUAL(0x56, test_le[0]); + CHECK_EQUAL(0x78, test_le[1]); + + CHECK_EQUAL(0x34, const_test_le[0]); + CHECK_EQUAL(0x12, const_test_le[1]); + + CHECK_EQUAL(0x12, test_be[0]); + CHECK_EQUAL(0x34, test_be[1]); + + test_be[0] = 0x56; + test_be[1] = 0x78; + CHECK_EQUAL(0x56, test_be[0]); + CHECK_EQUAL(0x78, test_be[1]); + + CHECK_EQUAL(0x12, const_test_be[0]); + CHECK_EQUAL(0x34, const_test_be[1]); + } + + //************************************************************************* + TEST(test_le_negative_numbers) + { + storage_c_t store_c1; + storage_c_t store_c2; + storage_c_t store_c3; + storage_s_t store_s1; + storage_s_t store_s2; + storage_i_t store_i1; + storage_i_t store_i2; + storage_l_t store_l1; + storage_l_t store_l2; + storage_ll_t store_ll1; + storage_ll_t store_ll2; + + // char + CHECK(char(0xFE) == etl::le_char_ext_t(char(0xFE), store_c1.data())); + CHECK((signed char)(0xFE) == etl::le_schar_ext_t((signed char)(0xFE), store_c2.data())); + CHECK((unsigned char)(0xFEU) == etl::le_uchar_ext_t((unsigned char)(0xFEU), store_c3.data())); + + // short + CHECK(short(0xFEFD) == etl::le_short_ext_t(short(0xFEFD), store_s1.data())); + CHECK((unsigned short)(0xFEFD) == etl::le_ushort_ext_t((unsigned short)(0xFEFD), store_s2.data())); + + // int + CHECK(int(0xFEFDFCFB) == etl::le_int_ext_t(0xFEFDFCFB, store_i1.data())); + CHECK((unsigned int)(0xFEFDFCFBU) == etl::le_uint_ext_t(0xFEFDFCFBU, store_i2.data())); + + if (sizeof(long) == 4U) + { + // long + CHECK(long(0xFEFDFCFB) == etl::le_long_ext_t(0xFEFDFCFB, store_l1.data())); + CHECK((unsigned long)(0xFEFDFCFBU) == etl::le_ulong_ext_t(0xFEFDFCFBU, store_l2.data())); + } + + if (sizeof(long long) == 8U) + { + // long long + CHECK((long long)(0xFEFDFCFBFAF9F8F7) == etl::le_long_long_ext_t(0xFEFDFCFBFAF9F8F7, store_ll1.data())); + CHECK((unsigned long long)(0xFEFDFCFBFAF9F8F7U) == etl::le_ulong_long_ext_t(0xFEFDFCFBFAF9F8F7U, store_ll2.data())); + } + } + + //************************************************************************* + TEST(test_value) + { + storage_i16_t store_i16_1; + storage_i16_t store_i16_2; + + etl::le_uint16_ext_t test_le(0x1234, store_i16_1.data()); + etl::be_uint16_ext_t test_be(0x1234, store_i16_2.data()); + + CHECK_EQUAL(0x1234, test_le.value()); + CHECK_EQUAL(0x1234, test_be.value()); + } + + //************************************************************************* + TEST(test_storage_bytes) + { + storage_i16_t store_i16_1; + storage_i16_t store_i16_2; + + etl::le_uint16_ext_t test_le(0x1234, store_i16_1.data()); + etl::be_uint16_ext_t test_be(0x1234, store_i16_2.data()); + + int lev0 = test_le[0]; + int lev1 = test_le[1]; + + int bev0 = test_be[0]; + int bev1 = test_be[1]; + + CHECK_EQUAL(0x34, lev0); + CHECK_EQUAL(0x12, lev1); + CHECK_EQUAL(0x12, bev0); + CHECK_EQUAL(0x34, bev1); + } + }; +} + +#include "etl/private/diagnostic_pop.h" diff --git a/test/test_uncopyable.cpp b/test/test_uncopyable.cpp new file mode 100644 index 00000000..f059dfa7 --- /dev/null +++ b/test/test_uncopyable.cpp @@ -0,0 +1,66 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2024 BMW AG + +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/uncopyable.h" + +namespace +{ + class UncopyableClass: public etl::uncopyable + { + }; + + SUITE(test_uncopyable) + { + //************************************************************************* + TEST(test_construct) + { + UncopyableClass uc; + + (void) uc; + } + + //************************************************************************* + // This code is intentionally not compilable when activated +#if 0 + TEST(test_copy) + { + UncopyableClass uc1; + + // Can't be copied by construction + UncopyableClass uc2{uc1}; // compile error + (void) uc2; + + // Can't be copied by copy assignment + UncopyableClass uc3; + uc3 = uc1; // compile error + } +#endif + }; +} diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 93f66457..c38fb0dd 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -130,11 +130,30 @@ namespace return true; } - typedef TestDataDC DC; - typedef TestDataNDC NDC; + //************************************************************************* + struct transparent_hash + { + typedef int is_transparent; - typedef ETL_OR_STD::pair ElementDC; - typedef ETL_OR_STD::pair ElementNDC; + size_t operator ()(const char* s) const + { + size_t sum = 0U; + size_t length = etl::strlen(s); + + return std::accumulate(s, s + length, sum); + } + + size_t operator ()(const std::string& text) const + { + return std::accumulate(text.begin(), text.end(), 0); + } + }; + + using DC = TestDataDC; + using NDC = TestDataNDC; + + using ElementDC = ETL_OR_STD::pair; + using ElementNDC = ETL_OR_STD::pair; } namespace etl @@ -201,20 +220,22 @@ namespace using ItemM = TestDataM; using DataM = etl::unordered_map>; - typedef etl::unordered_map DataDC; - typedef etl::unordered_map DataNDC; - typedef etl::iunordered_map IDataNDC; + using DataDC = etl::unordered_map; + using DataNDC = etl::unordered_map; + using IDataNDC = etl::iunordered_map; + using DataNDCTransparent = etl::unordered_map>; + using DataDCTransparent = etl::unordered_map>; - NDC N0 = NDC("A"); - NDC N1 = NDC("B"); - NDC N2 = NDC("C"); - NDC N3 = NDC("D"); - NDC N4 = NDC("E"); - NDC N5 = NDC("F"); - NDC N6 = NDC("G"); - NDC N7 = NDC("H"); - NDC N8 = NDC("I"); - NDC N9 = NDC("J"); + NDC N0 = NDC("A"); + NDC N1 = NDC("B"); + NDC N2 = NDC("C"); + NDC N3 = NDC("D"); + NDC N4 = NDC("E"); + NDC N5 = NDC("F"); + NDC N6 = NDC("G"); + NDC N7 = NDC("H"); + NDC N8 = NDC("I"); + NDC N9 = NDC("J"); NDC N10 = NDC("K"); NDC N11 = NDC("L"); NDC N12 = NDC("M"); @@ -226,16 +247,16 @@ namespace NDC N18 = NDC("S"); NDC N19 = NDC("T"); - DC M0 = DC("A"); - DC M1 = DC("B"); - DC M2 = DC("C"); - DC M3 = DC("D"); - DC M4 = DC("E"); - DC M5 = DC("F"); - DC M6 = DC("G"); - DC M7 = DC("H"); - DC M8 = DC("I"); - DC M9 = DC("J"); + DC M0 = DC("A"); + DC M1 = DC("B"); + DC M2 = DC("C"); + DC M3 = DC("D"); + DC M4 = DC("E"); + DC M5 = DC("F"); + DC M6 = DC("G"); + DC M7 = DC("H"); + DC M8 = DC("I"); + DC M9 = DC("J"); DC M10 = DC("K"); DC M11 = DC("L"); DC M12 = DC("M"); @@ -247,26 +268,47 @@ namespace DC M18 = DC("S"); DC M19 = DC("T"); - const char* K0 = "FF"; // 0 - const char* K1 = "FG"; // 1 - const char* K2 = "FH"; // 2 - const char* K3 = "FI"; // 3 - const char* K4 = "FJ"; // 4 - const char* K5 = "FK"; // 5 - const char* K6 = "FL"; // 6 - const char* K7 = "FM"; // 7 - const char* K8 = "FN"; // 8 - const char* K9 = "FO"; // 9 - const char* K10 = "FP"; // 0 - const char* K11 = "FQ"; // 1 - const char* K12 = "FR"; // 2 - const char* K13 = "FS"; // 3 - const char* K14 = "FT"; // 4 - const char* K15 = "FU"; // 5 - const char* K16 = "FV"; // 6 - const char* K17 = "FW"; // 7 - const char* K18 = "FX"; // 8 - const char* K19 = "FY"; // 9 + const char* CK0 = "FF"; // 0 + const char* CK1 = "FG"; // 1 + const char* CK2 = "FH"; // 2 + const char* CK3 = "FI"; // 3 + const char* CK4 = "FJ"; // 4 + const char* CK5 = "FK"; // 5 + const char* CK6 = "FL"; // 6 + const char* CK7 = "FM"; // 7 + const char* CK8 = "FN"; // 8 + const char* CK9 = "FO"; // 9 + const char* CK10 = "FP"; // 0 + const char* CK11 = "FQ"; // 1 + const char* CK12 = "FR"; // 2 + const char* CK13 = "FS"; // 3 + const char* CK14 = "FT"; // 4 + const char* CK15 = "FU"; // 5 + const char* CK16 = "FV"; // 6 + const char* CK17 = "FW"; // 7 + const char* CK18 = "FX"; // 8 + const char* CK19 = "FY"; // 9 + + std::string K0 = CK0; // 0 + std::string K1 = CK1; // 1 + std::string K2 = CK2; // 2 + std::string K3 = CK3; // 3 + std::string K4 = CK4; // 4 + std::string K5 = CK5; // 5 + std::string K6 = CK6; // 6 + std::string K7 = CK7; // 7 + std::string K8 = CK8; // 8 + std::string K9 = CK9; // 9 + std::string K10 = CK10; // 0 + std::string K11 = CK11; // 1 + std::string K12 = CK12; // 2 + std::string K13 = CK13; // 3 + std::string K14 = CK14; // 4 + std::string K15 = CK15; // 5 + std::string K16 = CK16; // 6 + std::string K17 = CK17; // 7 + std::string K18 = CK18; // 8 + std::string K19 = CK19; // 9 std::string K[] = { K0, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, K12, K13, K14, K15, K16, K17, K18, K19 }; @@ -502,6 +544,23 @@ namespace CHECK_EQUAL(M9, data[K9]); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_index_read_using_transparent_comparator_and_hasher) + { + DataDCTransparent data(initial_data_dc.begin(), initial_data_dc.end()); + + CHECK_EQUAL(M0, data[CK0]); + CHECK_EQUAL(M1, data[CK1]); + CHECK_EQUAL(M2, data[CK2]); + CHECK_EQUAL(M3, data[CK3]); + CHECK_EQUAL(M4, data[CK4]); + CHECK_EQUAL(M5, data[CK5]); + CHECK_EQUAL(M6, data[CK6]); + CHECK_EQUAL(M7, data[CK7]); + CHECK_EQUAL(M8, data[CK8]); + CHECK_EQUAL(M9, data[CK9]); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_write) { @@ -530,6 +589,34 @@ namespace CHECK_EQUAL(M0, data[K9]); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_index_write_using_transparent_comparator_and_hasher) + { + DataDCTransparent data(initial_data_dc.begin(), initial_data_dc.end()); + + data[CK0] = M9; + data[CK1] = M8; + data[CK2] = M7; + data[CK3] = M6; + data[CK4] = M5; + data[CK5] = M4; + data[CK6] = M3; + data[CK7] = M2; + data[CK8] = M1; + data[CK9] = M0; + + CHECK_EQUAL(M9, data[CK0]); + CHECK_EQUAL(M8, data[CK1]); + CHECK_EQUAL(M7, data[CK2]); + CHECK_EQUAL(M6, data[CK3]); + CHECK_EQUAL(M5, data[CK4]); + CHECK_EQUAL(M4, data[CK5]); + CHECK_EQUAL(M3, data[CK6]); + CHECK_EQUAL(M2, data[CK7]); + CHECK_EQUAL(M1, data[CK8]); + CHECK_EQUAL(M0, data[CK9]); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { @@ -547,6 +634,23 @@ namespace CHECK_EQUAL(data.at(K9), N9); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_at_using_transparent_comparator_and_hasher) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + CHECK_EQUAL(data.at(CK0), N0); + CHECK_EQUAL(data.at(CK1), N1); + CHECK_EQUAL(data.at(CK2), N2); + CHECK_EQUAL(data.at(CK3), N3); + CHECK_EQUAL(data.at(CK4), N4); + CHECK_EQUAL(data.at(CK5), N5); + CHECK_EQUAL(data.at(CK6), N6); + CHECK_EQUAL(data.at(CK7), N7); + CHECK_EQUAL(data.at(CK8), N8); + CHECK_EQUAL(data.at(CK9), N9); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { @@ -564,6 +668,23 @@ namespace CHECK_EQUAL(data.at(K9), N9); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_at_const_using_transparent_comparator_and_hasher) + { + const DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + CHECK_EQUAL(data.at(CK0), N0); + CHECK_EQUAL(data.at(CK1), N1); + CHECK_EQUAL(data.at(CK2), N2); + CHECK_EQUAL(data.at(CK3), N3); + CHECK_EQUAL(data.at(CK4), N4); + CHECK_EQUAL(data.at(CK5), N5); + CHECK_EQUAL(data.at(CK6), N6); + CHECK_EQUAL(data.at(CK7), N7); + CHECK_EQUAL(data.at(CK8), N8); + CHECK_EQUAL(data.at(CK9), N9); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { @@ -687,6 +808,23 @@ namespace CHECK(!data.empty()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_key_using_transparent_comparator) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + size_t count = data.erase(CK5); + + CHECK_EQUAL(1U, count); + + DataNDCTransparent::iterator idata = data.find(CK5); + CHECK(idata == data.end()); + + // Test that erase really does erase from the pool. + CHECK(!data.full()); + CHECK(!data.empty()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { @@ -837,6 +975,18 @@ namespace CHECK_EQUAL(0U, count); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_count_key_using_transparent_comparator) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + size_t count = data.count(CK5); + CHECK_EQUAL(1U, count); + + count = data.count(CK12); + CHECK_EQUAL(0U, count); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal_range) { @@ -863,6 +1013,32 @@ namespace CHECK_EQUAL(result.first->first, K9); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_equal_range_using_transparent_comparator) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + ETL_OR_STD::pair result; + + result = data.equal_range("FF"); + CHECK(result.first == data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FF"); + + result = data.equal_range("FJ"); + CHECK(result.first != data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FJ"); + + result = data.equal_range("FO"); + CHECK(result.first != data.begin()); + CHECK(result.second == data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FO"); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal_range_const) { @@ -889,6 +1065,32 @@ namespace CHECK_EQUAL(result.first->first, K9); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_equal_range_const_using_transparent_comparator) + { + const DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + ETL_OR_STD::pair result; + + result = data.equal_range("FF"); + CHECK(result.first == data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FF"); + + result = data.equal_range("FJ"); + CHECK(result.first != data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FJ"); + + result = data.equal_range("FO"); + CHECK(result.first != data.begin()); + CHECK(result.second == data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FO"); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal) { @@ -1207,5 +1409,27 @@ namespace CHECK_TRUE(map1 == map2a); CHECK_FALSE(map1 == map2b); } + + //************************************************************************* + TEST(test_contains) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + const char* not_inserted = "ZZ"; + + CHECK_TRUE(data.contains(K0)); + CHECK_FALSE(data.contains(std::string(not_inserted))); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + const char* not_inserted = "ZZ"; + + CHECK_TRUE(data.contains("FF")); + CHECK_FALSE(data.contains(not_inserted)); + } }; } diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index 38d198bf..716636e0 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -85,11 +85,30 @@ namespace return true; } - typedef TestDataDC DC; - typedef TestDataNDC NDC; + //************************************************************************* + struct transparent_hash + { + typedef int is_transparent; - typedef ETL_OR_STD::pair ElementDC; - typedef ETL_OR_STD::pair ElementNDC; + size_t operator ()(const char* s) const + { + size_t sum = 0U; + size_t length = etl::strlen(s); + + return std::accumulate(s, s + length, sum); + } + + size_t operator ()(const std::string& text) const + { + return std::accumulate(text.begin(), text.end(), 0); + } + }; + + using DC = TestDataDC; + using NDC = TestDataNDC; + + using ElementDC = ETL_OR_STD::pair; + using ElementNDC = ETL_OR_STD::pair; //*************************************************************************** struct CustomHashFunction @@ -175,6 +194,8 @@ namespace typedef etl::unordered_multimap DataDC; typedef etl::unordered_multimap DataNDC; typedef etl::iunordered_multimap IDataNDC; + typedef etl::unordered_multimap> DataNDCTransparent; + typedef etl::unordered_multimap> DataDCTransparent; using ItemM = TestDataM; using DataM = etl::unordered_multimap>; @@ -200,26 +221,47 @@ namespace NDC N18 = NDC("S"); NDC N19 = NDC("T"); - const char* K0 = "FF"; // 0 - const char* K1 = "FG"; // 1 - const char* K2 = "FH"; // 2 - const char* K3 = "FI"; // 3 - const char* K4 = "FJ"; // 4 - const char* K5 = "FK"; // 5 - const char* K6 = "FL"; // 6 - const char* K7 = "FM"; // 7 - const char* K8 = "FN"; // 8 - const char* K9 = "FO"; // 9 - const char* K10 = "FP"; // 0 - const char* K11 = "FQ"; // 1 - const char* K12 = "FR"; // 2 - const char* K13 = "FS"; // 3 - const char* K14 = "FT"; // 4 - const char* K15 = "FU"; // 5 - const char* K16 = "FV"; // 6 - const char* K17 = "FW"; // 7 - const char* K18 = "FX"; // 8 - const char* K19 = "FY"; // 9 + const char* CK0 = "FF"; // 0 + const char* CK1 = "FG"; // 1 + const char* CK2 = "FH"; // 2 + const char* CK3 = "FI"; // 3 + const char* CK4 = "FJ"; // 4 + const char* CK5 = "FK"; // 5 + const char* CK6 = "FL"; // 6 + const char* CK7 = "FM"; // 7 + const char* CK8 = "FN"; // 8 + const char* CK9 = "FO"; // 9 + const char* CK10 = "FP"; // 0 + const char* CK11 = "FQ"; // 1 + const char* CK12 = "FR"; // 2 + const char* CK13 = "FS"; // 3 + const char* CK14 = "FT"; // 4 + const char* CK15 = "FU"; // 5 + const char* CK16 = "FV"; // 6 + const char* CK17 = "FW"; // 7 + const char* CK18 = "FX"; // 8 + const char* CK19 = "FY"; // 9 + + std::string K0 = CK0; // 0 + std::string K1 = CK1; // 1 + std::string K2 = CK2; // 2 + std::string K3 = CK3; // 3 + std::string K4 = CK4; // 4 + std::string K5 = CK5; // 5 + std::string K6 = CK6; // 6 + std::string K7 = CK7; // 7 + std::string K8 = CK8; // 8 + std::string K9 = CK9; // 9 + std::string K10 = CK10; // 0 + std::string K11 = CK11; // 1 + std::string K12 = CK12; // 2 + std::string K13 = CK13; // 3 + std::string K14 = CK14; // 4 + std::string K15 = CK15; // 5 + std::string K16 = CK16; // 6 + std::string K17 = CK17; // 7 + std::string K18 = CK18; // 8 + std::string K19 = CK19; // 9 std::string K[] = { K0, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, K12, K13, K14, K15, K16, K17, K18, K19 }; @@ -572,6 +614,26 @@ namespace CHECK(idata == data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_key_using_transparent_comparator) + { + DataNDCTransparent data(equal_data.begin(), equal_data.end()); + + size_t count = data.erase("FP"); + + CHECK_EQUAL(1U, count); + + DataNDCTransparent::iterator idata = data.find("FP"); + CHECK(idata == data.end()); + + count = data.erase("FQ"); + + CHECK_EQUAL(3U, count); + + idata = data.find("FQ"); + CHECK(idata == data.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { @@ -717,7 +779,6 @@ namespace CHECK_EQUAL(data.size(), size_t(0)); } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_count_key) { @@ -733,6 +794,31 @@ namespace CHECK_EQUAL(0U, count); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_count_key_using_transparent_comparator) + { + DataNDCTransparent data(equal_data.begin(), equal_data.end()); + + size_t count = data.count(K10); + CHECK_EQUAL(1U, count); + + count = data.count(K11); + CHECK_EQUAL(3U, count); + + count = data.count(K1); + CHECK_EQUAL(0U, count); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator idata = data.find(K3); + + CHECK(idata != data.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_const) { @@ -743,6 +829,26 @@ namespace CHECK(idata != data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_using_transparent_comparator) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + DataNDCTransparent::iterator idata = data.find(CK3); + + CHECK(idata != data.end()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_const_using_transparent_comparator) + { + const DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + DataNDCTransparent::const_iterator idata = data.find(CK3); + + CHECK(idata != data.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal_range) { @@ -795,6 +901,58 @@ namespace CHECK_EQUAL(result.first->first, K12); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_equal_range_using_transparent_comparator) + { + DataNDCTransparent data(equal_data.begin(), equal_data.end()); + + ETL_OR_STD::pair result; + + result = data.equal_range(CK10); + CHECK(result.first == data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, CK10); + + result = data.equal_range(CK11); + CHECK(result.first != data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 3); + CHECK_EQUAL(result.first->first, CK11); + + result = data.equal_range(CK12); + CHECK(result.first != data.begin()); + CHECK(result.second == data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, CK12); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_equal_range_const_using_transparent_comparator) + { + const DataNDCTransparent data(equal_data.begin(), equal_data.end()); + + ETL_OR_STD::pair result; + + result = data.equal_range(CK10); + CHECK(result.first == data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, CK10); + + result = data.equal_range(CK11); + CHECK(result.first != data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 3); + CHECK_EQUAL(result.first->first, CK11); + + result = data.equal_range(CK12); + CHECK(result.first != data.begin()); + CHECK(result.second == data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, CK12); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal) { @@ -1068,5 +1226,27 @@ namespace CHECK_TRUE(map1 == map2a); CHECK_FALSE(map1 == map2b); } + + //************************************************************************* + TEST(test_contains) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + const char* not_inserted = "ZZ"; + + CHECK_TRUE(data.contains(K0)); + CHECK_FALSE(data.contains(not_inserted)); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + const char* not_inserted = "ZZ"; + + CHECK_TRUE(data.contains("FF")); + CHECK_FALSE(data.contains(not_inserted)); + } }; } diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 8337a015..27bfe310 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -45,8 +45,8 @@ SOFTWARE. namespace { - typedef TestDataDC DC; - typedef TestDataNDC NDC; + using DC = TestDataDC; + using NDC = TestDataNDC; } namespace etl @@ -135,6 +135,23 @@ namespace } }; + //************************************************************************* + struct transparent_hash + { + typedef int is_transparent; + + size_t operator ()(const char* s) const + { + return std::accumulate(s, s + etl::strlen(s), 0); + } + + size_t operator ()(const std::string& s) const + { + return std::accumulate(s.begin(), s.end(), 0); + } + }; + + //*************************************************************************** SUITE(test_unordered_multiset) { static const size_t SIZE = 10; @@ -161,30 +178,52 @@ namespace using DataM = etl::unordered_multiset; - typedef etl::unordered_multiset DataDC; - typedef etl::unordered_multiset DataNDC; - typedef etl::iunordered_multiset IDataNDC; + using DataDC = etl::unordered_multiset; + using DataNDC = etl::unordered_multiset; + using IDataNDC = etl::iunordered_multiset; + using DataTransparent = etl::unordered_multiset>; - NDC N0 = NDC("FF"); - NDC N1 = NDC("FG"); - NDC N2 = NDC("FH"); - NDC N3 = NDC("FI"); - NDC N4 = NDC("FJ"); - NDC N5 = NDC("FK"); - NDC N6 = NDC("FL"); - NDC N7 = NDC("FM"); - NDC N8 = NDC("FN"); - NDC N9 = NDC("FO"); - NDC N10 = NDC("FP"); - NDC N11 = NDC("FQ"); - NDC N12 = NDC("FR"); - NDC N13 = NDC("FS"); - NDC N14 = NDC("FT"); - NDC N15 = NDC("FU"); - NDC N16 = NDC("FV"); - NDC N17 = NDC("FW"); - NDC N18 = NDC("FX"); - NDC N19 = NDC("FY"); + const char* CK0 = "FF"; // 0 + const char* CK1 = "FG"; // 1 + const char* CK2 = "FH"; // 2 + const char* CK3 = "FI"; // 3 + const char* CK4 = "FJ"; // 4 + const char* CK5 = "FK"; // 5 + const char* CK6 = "FL"; // 6 + const char* CK7 = "FM"; // 7 + const char* CK8 = "FN"; // 8 + const char* CK9 = "FO"; // 9 + const char* CK10 = "FP"; // 0 + const char* CK11 = "FQ"; // 1 + const char* CK12 = "FR"; // 2 + const char* CK13 = "FS"; // 3 + const char* CK14 = "FT"; // 4 + const char* CK15 = "FU"; // 5 + const char* CK16 = "FV"; // 6 + const char* CK17 = "FW"; // 7 + const char* CK18 = "FX"; // 8 + const char* CK19 = "FY"; // 9 + + NDC N0 = NDC(CK0); + NDC N1 = NDC(CK1); + NDC N2 = NDC(CK2); + NDC N3 = NDC(CK3); + NDC N4 = NDC(CK4); + NDC N5 = NDC(CK5); + NDC N6 = NDC(CK6); + NDC N7 = NDC(CK7); + NDC N8 = NDC(CK8); + NDC N9 = NDC(CK9); + NDC N10 = NDC(CK10); + NDC N11 = NDC(CK11); + NDC N12 = NDC(CK12); + NDC N13 = NDC(CK13); + NDC N14 = NDC(CK14); + NDC N15 = NDC(CK15); + NDC N16 = NDC(CK16); + NDC N17 = NDC(CK17); + NDC N18 = NDC(CK18); + NDC N19 = NDC(CK19); std::vector initial_data; std::vector excess_data; @@ -394,6 +433,24 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data; + + data.assign(initial.begin(), initial.end()); + + DataTransparent::iterator idata; + + for (size_t i = 0UL; i < 8; ++i) + { + idata = data.find(initial[i]); + CHECK(idata != data.end()); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_value) { @@ -431,6 +488,38 @@ namespace CHECK(*idata == N11); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_value_using_transparent_comparator) + { + DataTransparent data; + + data.insert(CK0); // Inserted + data.insert(CK2); // Inserted + data.insert(CK1); // Inserted + data.insert(CK11); // Duplicate hash. Inserted + data.insert(CK3); // Inserted + + CHECK_EQUAL(5U, data.size()); + + DataTransparent::iterator idata; + + idata = data.find(CK0); + CHECK(idata != data.end()); + CHECK(*idata == CK0); + + idata = data.find(CK1); + CHECK(idata != data.end()); + CHECK(*idata == CK1); + + idata = data.find(CK2); + CHECK(idata != data.end()); + CHECK(*idata == CK2); + + idata = data.find(CK11); + CHECK(idata != data.end()); + CHECK(*idata == CK11); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_value_excess) { @@ -453,6 +542,24 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_range_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data; + + data.insert(initial.begin(), initial.end()); + + DataTransparent::iterator idata; + + for (size_t i = 0UL; i < 8; ++i) + { + idata = data.find(initial[i]); + CHECK(idata != data.end()); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_range_excess) { @@ -505,6 +612,21 @@ namespace CHECK(idata == data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_key_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + size_t count = data.erase("CC"); + + CHECK_EQUAL(1U, count); + + DataTransparent::iterator idata = data.find("CC"); + CHECK(idata == data.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { @@ -665,6 +787,20 @@ namespace CHECK_EQUAL(0U, count); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_count_key_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + size_t count = data.count("CC"); + CHECK_EQUAL(1U, count); + + count = data.count("II"); + CHECK_EQUAL(0U, count); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_const) { @@ -943,5 +1079,29 @@ namespace CHECK_TRUE(set1 == set2a); CHECK_FALSE(set1 == set2b); } + + //************************************************************************* + TEST(test_contains) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + NDC not_inserted = NDC("ZZ"); + + CHECK_TRUE(data.contains(N0)); + CHECK_FALSE(data.contains(not_inserted)); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + const char* not_inserted = "ZZ"; + + CHECK_TRUE(data.contains("FF")); + CHECK_FALSE(data.contains(not_inserted)); + } }; } diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index 7a4210cc..189f9761 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -45,8 +45,8 @@ SOFTWARE. namespace { - typedef TestDataDC DC; - typedef TestDataNDC NDC; + using DC = TestDataDC; + using NDC = TestDataNDC; } namespace etl @@ -135,6 +135,22 @@ namespace } }; + //************************************************************************* + struct transparent_hash + { + typedef int is_transparent; + + size_t operator ()(const char* s) const + { + return std::accumulate(s, s + etl::strlen(s), 0); + } + + size_t operator ()(const std::string& s) const + { + return std::accumulate(s.begin(), s.end(), 0); + } + }; + //*************************************************************************** SUITE(test_unordered_set) { @@ -162,30 +178,52 @@ namespace using DataM = etl::unordered_set; - typedef etl::unordered_set DataDC; - typedef etl::unordered_set DataNDC; - typedef etl::iunordered_set IDataNDC; + using DataDC = etl::unordered_set; + using DataNDC = etl::unordered_set; + using IDataNDC = etl::iunordered_set; + using DataTransparent = etl::unordered_set>; - NDC N0 = NDC("FF"); - NDC N1 = NDC("FG"); - NDC N2 = NDC("FH"); - NDC N3 = NDC("FI"); - NDC N4 = NDC("FJ"); - NDC N5 = NDC("FK"); - NDC N6 = NDC("FL"); - NDC N7 = NDC("FM"); - NDC N8 = NDC("FN"); - NDC N9 = NDC("FO"); - NDC N10 = NDC("FP"); - NDC N11 = NDC("FQ"); - NDC N12 = NDC("FR"); - NDC N13 = NDC("FS"); - NDC N14 = NDC("FT"); - NDC N15 = NDC("FU"); - NDC N16 = NDC("FV"); - NDC N17 = NDC("FW"); - NDC N18 = NDC("FX"); - NDC N19 = NDC("FY"); + const char* CK0 = "FF"; // 0 + const char* CK1 = "FG"; // 1 + const char* CK2 = "FH"; // 2 + const char* CK3 = "FI"; // 3 + const char* CK4 = "FJ"; // 4 + const char* CK5 = "FK"; // 5 + const char* CK6 = "FL"; // 6 + const char* CK7 = "FM"; // 7 + const char* CK8 = "FN"; // 8 + const char* CK9 = "FO"; // 9 + const char* CK10 = "FP"; // 0 + const char* CK11 = "FQ"; // 1 + const char* CK12 = "FR"; // 2 + const char* CK13 = "FS"; // 3 + const char* CK14 = "FT"; // 4 + const char* CK15 = "FU"; // 5 + const char* CK16 = "FV"; // 6 + const char* CK17 = "FW"; // 7 + const char* CK18 = "FX"; // 8 + const char* CK19 = "FY"; // 9 + + NDC N0 = NDC(CK0); + NDC N1 = NDC(CK1); + NDC N2 = NDC(CK2); + NDC N3 = NDC(CK3); + NDC N4 = NDC(CK4); + NDC N5 = NDC(CK5); + NDC N6 = NDC(CK6); + NDC N7 = NDC(CK7); + NDC N8 = NDC(CK8); + NDC N9 = NDC(CK9); + NDC N10 = NDC(CK10); + NDC N11 = NDC(CK11); + NDC N12 = NDC(CK12); + NDC N13 = NDC(CK13); + NDC N14 = NDC(CK14); + NDC N15 = NDC(CK15); + NDC N16 = NDC(CK16); + NDC N17 = NDC(CK17); + NDC N18 = NDC(CK18); + NDC N19 = NDC(CK19); std::vector initial_data; std::vector excess_data; @@ -378,6 +416,24 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data; + + data.assign(initial.begin(), initial.end()); + + DataTransparent::iterator idata; + + for (size_t i = 0UL; i < 8; ++i) + { + idata = data.find(initial[i]); + CHECK(idata != data.end()); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_value) { @@ -409,6 +465,38 @@ namespace CHECK(idata != data.end()); CHECK(*idata == N11); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_value_using_transparent_comparator) + { + DataTransparent data; + + data.insert(CK0); // Inserted + data.insert(CK2); // Inserted + data.insert(CK1); // Inserted + data.insert(CK11); // Duplicate hash. Inserted + data.insert(CK3); // Inserted + + CHECK_EQUAL(5U, data.size()); + + DataTransparent::iterator idata; + + idata = data.find(CK0); + CHECK(idata != data.end()); + CHECK(*idata == CK0); + + idata = data.find(CK1); + CHECK(idata != data.end()); + CHECK(*idata == CK1); + + idata = data.find(CK2); + CHECK(idata != data.end()); + CHECK(*idata == CK2); + + idata = data.find(CK11); + CHECK(idata != data.end()); + CHECK(*idata == CK11); + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_value_excess) @@ -432,6 +520,24 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_range_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data; + + data.insert(initial.begin(), initial.end()); + + DataTransparent::iterator idata; + + for (size_t i = 0UL; i < 8; ++i) + { + idata = data.find(initial[i]); + CHECK(idata != data.end()); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_range_excess) { @@ -508,6 +614,21 @@ namespace CHECK(idata == data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_key_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + size_t count = data.erase("CC"); + + CHECK_EQUAL(1U, count); + + DataTransparent::iterator idata = data.find("CC"); + CHECK(idata == data.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { @@ -665,6 +786,20 @@ namespace CHECK_EQUAL(0U, count); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_count_key_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + size_t count = data.count("CC"); + CHECK_EQUAL(1U, count); + + count = data.count("II"); + CHECK_EQUAL(0U, count); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal) { @@ -909,5 +1044,29 @@ namespace CHECK_TRUE(set1 == set2a); CHECK_FALSE(set1 == set2b); } + + //************************************************************************* + TEST(test_contains) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + NDC not_inserted = NDC("ZZ"); + + CHECK_TRUE(data.contains(N0)); + CHECK_FALSE(data.contains(not_inserted)); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + const char* not_inserted = "ZZ"; + + CHECK_TRUE(data.contains("FF")); + CHECK_FALSE(data.contains(not_inserted)); + } }; } diff --git a/test/test_utility.cpp b/test/test_utility.cpp index a1f28e95..e049198d 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -412,14 +412,14 @@ namespace } //************************************************************************* - TEST(test_functor) + TEST(test_functor_deprecated) { constexpr etl::functor fw1(TestGlobal); CHECK_EQUAL(2, fw1(1)); } //************************************************************************* - TEST(test_member_function_wrapper) + TEST(test_member_function_wrapper_deprecated) { constexpr int(*pf)(int) = &etl::member_function_wrapper::function; @@ -427,13 +427,65 @@ namespace } //************************************************************************* - TEST(test_functor_wrapper) + TEST(test_functor_wrapper_deprecated) { constexpr int(*pf)(int) = &etl::functor_wrapper::function; CHECK_EQUAL(2, pf(1)); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST(test_function_as_functor) + { + constexpr etl::function_as_functor faf; + + CHECK_EQUAL(2, faf(1)); + } +#endif + + //************************************************************************* + TEST(test_function_ptr_as_functor) + { + using function_type = decltype(TestGlobal); + + constexpr function_type* fptr = TestGlobal; + + constexpr etl::function_ptr_as_functor fpaf(fptr); + + CHECK_EQUAL(2, fpaf(1)); + } + + //************************************************************************* +#if ETL_USING_CPP17 + TEST(test_functor_as_static) + { + using fas_t = etl::functor_as_static; + + CHECK_EQUAL(2, fas_t::call(1)); + } +#endif + + //************************************************************************* +#if ETL_USING_CPP17 + TEST(test_member_function_as_static) + { + using mfas_t = etl::member_function_as_static<&TestClass::MemberFunction, test>; + + CHECK_EQUAL(2, mfas_t::call(1)); + } +#endif + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_member_function_as_functor) + { + constexpr etl::member_function_as_functor<&TestClass::MemberFunction, test> mfaf; + + CHECK_EQUAL(2, mfaf(1)); + } +#endif + //************************************************************************* struct SF { @@ -666,5 +718,31 @@ namespace CHECK_EQUAL(forward_like_call_type::ConstRValue, template_function_fl(etl::move(u4))); CHECK_EQUAL(forward_like_call_type::ConstRValue, template_function_fl(etl::move(u4))); } + +#if ETL_HAS_PACKED + //********************************* + TEST(test_packed) + { + struct Unpacked + { + uint32_t a = 0x12345678; + uint8_t b = 0x9A; + uint32_t c = 0x87654321; + }; + + ETL_PACKED_STRUCT(Packed) + { + uint32_t a = 0x12345678; + uint8_t b = 0x9A; + uint32_t c = 0x87654321; + }; ETL_END_PACKED + + Unpacked unpacked; + Packed packed; + + CHECK_TRUE(sizeof(unpacked) > sizeof(packed)); + CHECK_EQUAL(9U, sizeof(packed)); + } +#endif }; } diff --git a/test/test_variant_legacy.cpp b/test/test_variant_legacy.cpp index 4e53473b..73c26ef7 100644 --- a/test/test_variant_legacy.cpp +++ b/test/test_variant_legacy.cpp @@ -204,7 +204,7 @@ namespace typedef etl::legacy::variant test_variant_emplace; - SUITE(test_variant) + SUITE(test_variant_legacy) { TEST(test_alignment) { @@ -258,6 +258,34 @@ namespace CHECK_EQUAL(text, variant_text.get()); } + //************************************************************************* + TEST(test_constructor_in_place_value) + { + // Char. + char c = 'a'; + test_variant_3a variant_char(etl::in_place_index_t<0>(), c); + + CHECK(variant_char.is_type()); + CHECK(variant_char.is_valid()); + CHECK_EQUAL(c, variant_char.get()); + + // Int. + int i = 1; + test_variant_3a variant_int(etl::in_place_index_t<1>(), i); + + CHECK(variant_int.is_type()); + CHECK(variant_int.is_valid()); + CHECK_EQUAL(i, variant_int.get()); + + // String. + std::string text("Some Text"); + test_variant_3a variant_text(etl::in_place_index_t<2>(), text); + + CHECK(variant_text.is_type()); + CHECK(variant_text.is_valid()); + CHECK_EQUAL(text, variant_text.get()); + } + //************************************************************************* TEST(test_copy_constructor) { diff --git a/test/vs2022/etl.sln b/test/vs2022/etl.sln index 3b5f836e..c002c8f2 100644 --- a/test/vs2022/etl.sln +++ b/test/vs2022/etl.sln @@ -17,6 +17,8 @@ Global Debug MSVC C++17 - No STL|x64 = Debug MSVC C++17 - No STL|x64 Debug MSVC C++17|Win32 = Debug MSVC C++17|Win32 Debug MSVC C++17|x64 = Debug MSVC C++17|x64 + Debug MSVC C++20 - Force C++03 - No virtual messages|Win32 = Debug MSVC C++20 - Force C++03 - No virtual messages|Win32 + Debug MSVC C++20 - Force C++03 - No virtual messages|x64 = Debug MSVC C++20 - Force C++03 - No virtual messages|x64 Debug MSVC C++20 - Force C++03|Win32 = Debug MSVC C++20 - Force C++03|Win32 Debug MSVC C++20 - Force C++03|x64 = Debug MSVC C++20 - Force C++03|x64 Debug MSVC C++20 - No STL|Win32 = Debug MSVC C++20 - No STL|Win32 @@ -53,6 +55,10 @@ Global {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++17|Win32.Build.0 = Debug MSVC C++17|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++17|x64.ActiveCfg = Debug MSVC C++17|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++17|x64.Build.0 = Debug MSVC C++17|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03 - No virtual messages|Win32.ActiveCfg = Debug MSVC C++20 - Forve C++03 - No virtual messages|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03 - No virtual messages|Win32.Build.0 = Debug MSVC C++20 - Forve C++03 - No virtual messages|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03 - No virtual messages|x64.ActiveCfg = Debug MSVC C++20 - Forve C++03 - No virtual messages|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03 - No virtual messages|x64.Build.0 = Debug MSVC C++20 - Forve C++03 - No virtual messages|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03|Win32.ActiveCfg = Debug MSVC C++20 - Force C++03|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03|Win32.Build.0 = Debug MSVC C++20 - Force C++03|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03|x64.ActiveCfg = Debug MSVC C++20 - Force C++03|x64 diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 8c275868..65b50b51 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -49,6 +49,14 @@ Debug MSVC C++20 - Force C++03 x64 + + Debug MSVC C++20 - Forve C++03 - No virtual messages + Win32 + + + Debug MSVC C++20 - Forve C++03 - No virtual messages + x64 + Debug MSVC C++20 - No STL Win32 @@ -142,6 +150,13 @@ Unicode false + + Application + true + v143 + Unicode + false + Application true @@ -381,6 +396,12 @@ v143 Unicode + + Application + true + v143 + Unicode + Application true @@ -632,6 +653,9 @@ + + + @@ -740,6 +764,9 @@ + + + @@ -875,6 +902,11 @@ true $(Configuration)\ + + true + true + $(Configuration)\ + true true @@ -1057,6 +1089,10 @@ true true + + true + true + true true @@ -1315,6 +1351,32 @@ "$(OutDir)\etl.exe" + + + + + 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) + ../../../unittest-cpp/;../../include;../../test + + + true + stdcpp20 + EditAndContinue + /Zc:__cplusplus %(AdditionalOptions) + true + EnableFastChecks + false + + + Console + true + + + "$(OutDir)\etl.exe" + + @@ -2196,6 +2258,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ../../unittest-cpp/UnitTest++/;../../include/etl;../../test + + + false + stdcpp14 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -3085,10 +3168,13 @@ + + + @@ -3111,6 +3197,10 @@ + + + + @@ -3201,6 +3291,7 @@ + @@ -3258,6 +3349,8 @@ + + @@ -3268,6 +3361,7 @@ + @@ -3359,11 +3453,28 @@ + + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true true true true + true true true true @@ -3402,6 +3513,7 @@ true true true + true true true true @@ -3440,6 +3552,7 @@ true true true + true true true true @@ -3478,6 +3591,7 @@ true true true + true true true true @@ -3555,11 +3669,44 @@ + + true + true + true + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true true true true + true true true true @@ -3598,6 +3745,7 @@ true true true + true true true true @@ -3636,6 +3784,7 @@ true true true + true true true true @@ -3674,6 +3823,7 @@ true true true + true true true true @@ -3723,6 +3873,7 @@ true true true + true true @@ -3738,6 +3889,7 @@ true true true + true true @@ -3753,6 +3905,7 @@ true true true + true true @@ -3768,6 +3921,7 @@ true true true + true true @@ -3783,6 +3937,7 @@ true true true + true true @@ -3798,6 +3953,7 @@ true true true + true true @@ -3813,6 +3969,7 @@ true true true + true true @@ -3828,6 +3985,7 @@ true true true + true true @@ -3843,6 +4001,7 @@ true true true + true true true true @@ -3856,6 +4015,7 @@ true true true + true true @@ -3871,6 +4031,7 @@ true true true + true true true true @@ -3884,6 +4045,7 @@ true true true + true true @@ -3899,6 +4061,7 @@ true true true + true true @@ -3914,6 +4077,7 @@ true true true + true true @@ -3929,6 +4093,7 @@ true true true + true true @@ -3944,6 +4109,7 @@ true true true + true true @@ -3959,6 +4125,7 @@ true true true + true true @@ -3974,6 +4141,7 @@ true true true + true true @@ -3989,6 +4157,7 @@ true true true + true true true true @@ -4002,6 +4171,7 @@ true true true + true true @@ -4017,6 +4187,7 @@ true true true + true true @@ -4032,6 +4203,7 @@ true true true + true true @@ -4047,6 +4219,7 @@ true true true + true true @@ -4062,6 +4235,7 @@ true true true + true true @@ -4077,6 +4251,7 @@ true true true + true true @@ -4092,6 +4267,7 @@ true true true + true true @@ -4107,6 +4283,7 @@ true true true + true true @@ -4122,6 +4299,7 @@ true true true + true true @@ -4137,6 +4315,7 @@ true true true + true true @@ -4152,6 +4331,7 @@ true true true + true true @@ -4167,6 +4347,7 @@ true true true + true true @@ -4182,6 +4363,7 @@ true true true + true true @@ -4197,6 +4379,7 @@ true true true + true true @@ -4212,6 +4395,7 @@ true true true + true true @@ -4227,6 +4411,7 @@ true true true + true true @@ -4242,6 +4427,7 @@ true true true + true true @@ -4257,6 +4443,7 @@ true true true + true true @@ -4272,6 +4459,7 @@ true true true + true true @@ -4287,6 +4475,7 @@ true true true + true true @@ -4302,6 +4491,7 @@ true true true + true true @@ -4317,6 +4507,7 @@ true true true + true true @@ -4332,6 +4523,7 @@ true true true + true true @@ -4347,6 +4539,7 @@ true true true + true true @@ -4362,6 +4555,7 @@ true true true + true true @@ -4377,6 +4571,7 @@ true true true + true true true true @@ -4390,6 +4585,7 @@ true true true + true true @@ -4405,6 +4601,7 @@ true true true + true true @@ -4420,6 +4617,7 @@ true true true + true true @@ -4435,6 +4633,7 @@ true true true + true true @@ -4450,6 +4649,7 @@ true true true + true true @@ -4465,6 +4665,7 @@ true true true + true true @@ -4480,6 +4681,7 @@ true true true + true true @@ -4495,6 +4697,7 @@ true true true + true true @@ -4510,6 +4713,7 @@ true true true + true true @@ -4525,6 +4729,7 @@ true true true + true true @@ -4540,6 +4745,7 @@ true true true + true true @@ -4555,6 +4761,7 @@ true true true + true true @@ -4570,6 +4777,7 @@ true true true + true true @@ -4585,6 +4793,7 @@ true true true + true true @@ -4600,6 +4809,7 @@ true true true + true true @@ -4615,6 +4825,7 @@ true true true + true true @@ -4630,6 +4841,7 @@ true true true + true true @@ -4645,6 +4857,7 @@ true true true + true true @@ -4660,6 +4873,7 @@ true true true + true true @@ -4675,6 +4889,7 @@ true true true + true true @@ -4690,6 +4905,7 @@ true true true + true true @@ -4705,6 +4921,7 @@ true true true + true true @@ -4720,6 +4937,7 @@ true true true + true true @@ -4735,6 +4953,7 @@ true true true + true true @@ -4750,6 +4969,7 @@ true true true + true true @@ -4765,6 +4985,7 @@ true true true + true true @@ -4780,6 +5001,7 @@ true true true + true true @@ -4795,6 +5017,7 @@ true true true + true true @@ -4810,6 +5033,7 @@ true true true + true true @@ -4825,6 +5049,7 @@ true true true + true true @@ -4840,6 +5065,7 @@ true true true + true true @@ -4855,6 +5081,7 @@ true true true + true true @@ -4870,6 +5097,7 @@ true true true + true true @@ -4885,6 +5113,7 @@ true true true + true true @@ -4900,6 +5129,7 @@ true true true + true true @@ -4915,6 +5145,7 @@ true true true + true true @@ -4930,6 +5161,7 @@ true true true + true true @@ -4945,6 +5177,7 @@ true true true + true true @@ -4960,6 +5193,7 @@ true true true + true true @@ -4975,6 +5209,7 @@ true true true + true true @@ -4990,6 +5225,7 @@ true true true + true true @@ -5005,6 +5241,7 @@ true true true + true true @@ -5020,6 +5257,7 @@ true true true + true true @@ -5035,6 +5273,7 @@ true true true + true true @@ -5050,6 +5289,7 @@ true true true + true true @@ -5065,6 +5305,7 @@ true true true + true true @@ -5080,6 +5321,7 @@ true true true + true true @@ -5095,6 +5337,7 @@ true true true + true true @@ -5110,6 +5353,7 @@ true true true + true true @@ -5125,6 +5369,7 @@ true true true + true true @@ -5140,6 +5385,7 @@ true true true + true true @@ -5155,6 +5401,7 @@ true true true + true true @@ -5170,6 +5417,7 @@ true true true + true true @@ -5185,6 +5433,7 @@ true true true + true true @@ -5200,6 +5449,7 @@ true true true + true true @@ -5215,6 +5465,7 @@ true true true + true true @@ -5230,6 +5481,7 @@ true true true + true true @@ -5245,6 +5497,7 @@ true true true + true true @@ -5260,6 +5513,7 @@ true true true + true true @@ -5275,6 +5529,7 @@ true true true + true true @@ -5290,6 +5545,7 @@ true true true + true true @@ -5305,6 +5561,7 @@ true true true + true true @@ -5320,6 +5577,7 @@ true true true + true true @@ -5335,6 +5593,7 @@ true true true + true true @@ -5350,6 +5609,7 @@ true true true + true true @@ -5365,6 +5625,7 @@ true true true + true true @@ -5380,6 +5641,7 @@ true true true + true true @@ -5395,6 +5657,7 @@ true true true + true true @@ -5410,6 +5673,7 @@ true true true + true true @@ -5425,6 +5689,7 @@ true true true + true true @@ -5440,6 +5705,7 @@ true true true + true true @@ -5455,6 +5721,7 @@ true true true + true true @@ -5470,6 +5737,7 @@ true true true + true true @@ -5485,6 +5753,7 @@ true true true + true true @@ -5500,6 +5769,7 @@ true true true + true true @@ -5515,6 +5785,7 @@ true true true + true true @@ -5530,6 +5801,7 @@ true true true + true true @@ -5545,6 +5817,23 @@ true true true + true + + + true + true + true + true + true + true + true + true + true + true + true + true + true + true true @@ -5560,6 +5849,7 @@ true true true + true true @@ -5575,6 +5865,7 @@ true true true + true true @@ -5590,6 +5881,7 @@ true true true + true true @@ -5605,6 +5897,7 @@ true true true + true true @@ -5620,6 +5913,7 @@ true true true + true true true true @@ -5633,6 +5927,7 @@ true true true + true true @@ -5648,6 +5943,7 @@ true true true + true true @@ -5663,6 +5959,7 @@ true true true + true true @@ -5678,6 +5975,7 @@ true true true + true true @@ -5693,6 +5991,7 @@ true true true + true true @@ -5708,6 +6007,7 @@ true true true + true true @@ -5723,6 +6023,7 @@ true true true + true true @@ -5738,6 +6039,7 @@ true true true + true true @@ -5753,6 +6055,7 @@ true true true + true true @@ -5768,6 +6071,7 @@ true true true + true true @@ -5783,6 +6087,7 @@ true true true + true true @@ -5798,6 +6103,7 @@ true true true + true true @@ -5813,6 +6119,7 @@ true true true + true true @@ -5828,6 +6135,7 @@ true true true + true true @@ -5843,6 +6151,7 @@ true true true + true true @@ -5858,6 +6167,7 @@ true true true + true true @@ -5873,6 +6183,7 @@ true true true + true true @@ -5888,6 +6199,7 @@ true true true + true true @@ -5903,6 +6215,7 @@ true true true + true true @@ -5918,6 +6231,7 @@ true true true + true true @@ -5933,6 +6247,7 @@ true true true + true true @@ -5948,6 +6263,7 @@ true true true + true true @@ -5963,6 +6279,7 @@ true true true + true true @@ -5978,6 +6295,7 @@ true true true + true true @@ -5993,6 +6311,7 @@ true true true + true true @@ -6008,6 +6327,7 @@ true true true + true true @@ -6023,6 +6343,7 @@ true true true + true true @@ -6038,6 +6359,7 @@ true true true + true true @@ -6053,6 +6375,7 @@ true true true + true true @@ -6068,6 +6391,7 @@ true true true + true true @@ -6083,6 +6407,7 @@ true true true + true true @@ -6098,6 +6423,7 @@ true true true + true true @@ -6113,6 +6439,7 @@ true true true + true true @@ -6128,6 +6455,7 @@ true true true + true true @@ -6143,6 +6471,7 @@ true true true + true true @@ -6158,6 +6487,7 @@ true true true + true true @@ -6173,6 +6503,7 @@ true true true + true true @@ -6188,6 +6519,7 @@ true true true + true true @@ -6203,6 +6535,7 @@ true true true + true true @@ -6218,6 +6551,7 @@ true true true + true true @@ -6233,6 +6567,7 @@ true true true + true true @@ -6248,6 +6583,7 @@ true true true + true true @@ -6263,6 +6599,7 @@ true true true + true true @@ -6278,6 +6615,7 @@ true true true + true true @@ -6293,6 +6631,7 @@ true true true + true true @@ -6308,6 +6647,7 @@ true true true + true true @@ -6323,6 +6663,7 @@ true true true + true true @@ -6338,6 +6679,7 @@ true true true + true true @@ -6353,6 +6695,7 @@ true true true + true true @@ -6368,6 +6711,7 @@ true true true + true true @@ -6383,6 +6727,7 @@ true true true + true true @@ -6398,6 +6743,7 @@ true true true + true true @@ -6413,6 +6759,7 @@ true true true + true true @@ -6428,6 +6775,7 @@ true true true + true true @@ -6443,6 +6791,7 @@ true true true + true true @@ -6458,6 +6807,7 @@ true true true + true true @@ -6473,6 +6823,7 @@ true true true + true true @@ -6488,6 +6839,7 @@ true true true + true true @@ -6503,6 +6855,7 @@ true true true + true true @@ -6518,6 +6871,7 @@ true true true + true true @@ -6533,6 +6887,7 @@ true true true + true true @@ -6548,6 +6903,7 @@ true true true + true true @@ -6563,6 +6919,7 @@ true true true + true true @@ -6578,6 +6935,7 @@ true true true + true true @@ -6593,6 +6951,7 @@ true true true + true true @@ -6608,6 +6967,7 @@ true true true + true true @@ -6623,6 +6983,7 @@ true true true + true true @@ -6638,6 +6999,7 @@ true true true + true true @@ -6653,6 +7015,7 @@ true true true + true true @@ -6668,6 +7031,7 @@ true true true + true true @@ -6683,6 +7047,7 @@ true true true + true true @@ -6698,6 +7063,7 @@ true true true + true true @@ -6713,6 +7079,7 @@ true true true + true true @@ -6728,6 +7095,7 @@ true true true + true true @@ -6743,6 +7111,7 @@ true true true + true true @@ -6758,6 +7127,7 @@ true true true + true true @@ -6773,6 +7143,7 @@ true true true + true true @@ -6788,6 +7159,7 @@ true true true + true true @@ -6803,6 +7175,7 @@ true true true + true true @@ -6818,6 +7191,7 @@ true true true + true true @@ -6833,6 +7207,7 @@ true true true + true true @@ -6848,6 +7223,7 @@ true true true + true true @@ -6863,6 +7239,7 @@ true true true + true true @@ -6878,6 +7255,7 @@ true true true + true true @@ -6893,6 +7271,7 @@ true true true + true true @@ -6908,6 +7287,7 @@ true true true + true true @@ -6923,6 +7303,7 @@ true true true + true true @@ -6938,6 +7319,7 @@ true true true + true true @@ -6953,6 +7335,7 @@ true true true + true true @@ -6968,6 +7351,7 @@ true true true + true true @@ -6983,6 +7367,7 @@ true true true + true true true true @@ -6996,6 +7381,7 @@ true true true + true true @@ -7011,6 +7397,7 @@ true true true + true true @@ -7026,6 +7413,7 @@ true true true + true true @@ -7041,6 +7429,7 @@ true true true + true true @@ -7056,6 +7445,7 @@ true true true + true true @@ -7071,6 +7461,7 @@ true true true + true true @@ -7086,6 +7477,23 @@ true true true + true + + + true + true + true + true + true + true + true + true + true + true + true + true + true + true true @@ -7101,6 +7509,7 @@ true true true + true true @@ -7116,6 +7525,7 @@ true true true + true true @@ -7131,6 +7541,7 @@ true true true + true true @@ -7146,6 +7557,7 @@ true true true + true true @@ -7161,6 +7573,7 @@ true true true + true true @@ -7176,6 +7589,7 @@ true true true + true true @@ -7191,6 +7605,7 @@ true true true + true true @@ -7206,6 +7621,7 @@ true true true + true true @@ -7221,6 +7637,7 @@ true true true + true true true true @@ -7234,6 +7651,7 @@ true true true + true true @@ -7249,6 +7667,7 @@ true true true + true true @@ -7264,6 +7683,7 @@ true true true + true true @@ -7279,6 +7699,7 @@ true true true + true true @@ -7294,6 +7715,7 @@ true true true + true true @@ -7309,6 +7731,7 @@ true true true + true true @@ -7324,6 +7747,7 @@ true true true + true true @@ -7339,6 +7763,7 @@ true true true + true true @@ -7354,6 +7779,7 @@ true true true + true true @@ -7369,6 +7795,7 @@ true true true + true true @@ -7384,6 +7811,7 @@ true true true + true true @@ -7399,6 +7827,7 @@ true true true + true true @@ -7414,6 +7843,7 @@ true true true + true true @@ -7429,6 +7859,23 @@ true true true + true + + + true + true + true + true + true + true + true + true + true + true + true + true + true + true true @@ -7444,6 +7891,7 @@ true true true + true true @@ -7459,6 +7907,7 @@ true true true + true true @@ -7474,6 +7923,7 @@ true true true + true true @@ -7489,6 +7939,7 @@ true true true + true true @@ -7504,6 +7955,7 @@ true true true + true true @@ -7519,6 +7971,7 @@ true true true + true true @@ -7534,6 +7987,7 @@ true true true + true true @@ -7549,6 +8003,7 @@ true true true + true true @@ -7564,6 +8019,7 @@ true true true + true true @@ -7579,6 +8035,7 @@ true true true + true true @@ -7594,6 +8051,7 @@ true true true + true true @@ -7609,6 +8067,7 @@ true true true + true true @@ -7624,6 +8083,7 @@ true true true + true true @@ -7639,6 +8099,23 @@ true true true + true + + + true + true + true + true + true + true + true + true + true + true + true + true + true + true true @@ -7654,6 +8131,7 @@ true true true + true true @@ -7669,6 +8147,7 @@ true true true + true true @@ -7684,6 +8163,7 @@ true true true + true true @@ -7699,6 +8179,7 @@ true true true + true true @@ -7714,6 +8195,7 @@ true true true + true true @@ -7729,6 +8211,7 @@ true true true + true true @@ -7744,6 +8227,7 @@ true true true + true true @@ -7759,6 +8243,7 @@ true true true + true true @@ -7774,6 +8259,7 @@ true true true + true true @@ -7789,6 +8275,7 @@ true true true + true true @@ -7804,6 +8291,7 @@ true true true + true true @@ -7819,6 +8307,7 @@ true true true + true true @@ -7834,6 +8323,7 @@ true true true + true true @@ -7849,6 +8339,7 @@ true true true + true true @@ -7864,6 +8355,7 @@ true true true + true true @@ -7879,6 +8371,7 @@ true true true + true true @@ -7894,6 +8387,7 @@ true true true + true true @@ -7909,6 +8403,7 @@ true true true + true @@ -7931,6 +8426,7 @@ false false false + false @@ -8021,7 +8517,9 @@ + + @@ -8091,6 +8589,7 @@ false false false + false false false false @@ -8131,6 +8630,7 @@ false false false + false false false false @@ -8190,6 +8690,7 @@ false false false + false false false false @@ -8230,6 +8731,7 @@ false false false + false false false false @@ -8284,6 +8786,7 @@ false false false + false false false false @@ -8324,6 +8827,7 @@ false false false + false false false false @@ -8368,6 +8872,7 @@ false false false + false false false false @@ -8408,6 +8913,7 @@ false false false + false false false false @@ -8452,6 +8958,7 @@ false false false + false false false false @@ -8492,6 +8999,7 @@ false false false + false false false false @@ -8536,6 +9044,7 @@ false false false + false false false false @@ -8576,6 +9085,7 @@ false false false + false false false false @@ -8625,6 +9135,7 @@ false false false + false false false false @@ -8665,6 +9176,7 @@ false false false + false false false false @@ -8713,6 +9225,7 @@ false false false + false false false false @@ -8753,6 +9266,7 @@ false false false + false false false false @@ -8809,6 +9323,7 @@ false false false + false false false false @@ -8849,6 +9364,7 @@ false false false + false false false false @@ -8932,6 +9448,7 @@ true + @@ -8978,14 +9495,17 @@ + + - + + @@ -9051,6 +9571,7 @@ + @@ -9087,12 +9608,28 @@ - + + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true true true true + true true true true @@ -9131,6 +9668,7 @@ true true true + true true true true @@ -9169,6 +9707,7 @@ true true true + true true true true @@ -9207,6 +9746,7 @@ true true true + true true true true @@ -9245,6 +9785,7 @@ + true true @@ -9259,6 +9800,7 @@ true true true + true diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 1fb6e5fc..ff4fbc6f 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -235,6 +235,9 @@ {e2e649e4-10ee-4ed7-baa3-eb889e552ba1} + + {f51cb264-5376-47db-89d9-a515e1ac4af7} + @@ -1449,6 +1452,42 @@ ETL\Private + + ETL\Utilities + + + Tests\Error Handler\Assert Function + + + UnitTest++\Header Files + + + UnitTest++\Header Files + + + ETL\Utilities + + + ETL\Utilities + + + ETL\Private + + + ETL\Private + + + ETL\Utilities + + + ETL\Private + + + ETL\Private + + + ETL\Utilities + ETL\Private\chrono @@ -2363,9 +2402,6 @@ Tests\Messaging - - Tests\Types - UnitTest++\Source Files @@ -3440,6 +3476,48 @@ Tests\Syntax Checks\Source + + Tests\Maths + + + Tests\Misc + + + Tests\Syntax Checks\Source + + + Tests\Types + + + Tests\Error Handler\Assert Function + + + Tests\Error Handler\Assert Function + + + Tests\Types + + + Tests\Patterns + + + Tests\Syntax Checks\Source + + + Tests\Syntax Checks\Source + + + Tests\Types + + + Tests\Types + + + Tests\Containers + + + Tests + Tests\Chrono @@ -3610,6 +3688,9 @@ Tests\Scripts + + Resource Files + @@ -3657,8 +3738,11 @@ Tests\Syntax Checks\Source - - Tests\Test Support + + Tests\Error Handler\Assert Function + + + Tests\Syntax Checks diff --git a/version.txt b/version.txt index 55ed5f72..f1a366ea 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -20.39.4 +20.40.0