diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..bd4e83f --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,46 @@ +sourcefiles:=$(shell find . -name "*.cpp") +objfiles:=$(patsubst %.cpp,%.o,$(sourcefiles)) + + +ifndef CXX +CXX = g++ +endif + +ifndef CXXFLAGS +CXXFLAGS = -Wall -pedantic -O2 -std=c++20 -I../src -I/usr/local/include +endif + + + +progname = tests + + +all: $(progname) pikotools + + +$(progname): $(objfiles) pikotools + $(CXX) $(CXXFLAGS) -o $(progname) $(objfiles) ../src/pikotools.a + + +%.o: %.cpp + $(CXX) -c $(CXXFLAGS) -o $@ $< + + +pikotools: FORCE + $(MAKE) -C ../src + + +FORCE: + + +clean: + rm -f $(objfiles) + rm -f $(progname) + + +depend: + makedepend -Y. -I../src -f- $(sourcefiles) > Makefile.dep + + +-include Makefile.dep + diff --git a/tests/Makefile.dep b/tests/Makefile.dep new file mode 100644 index 0000000..d69f60e --- /dev/null +++ b/tests/Makefile.dep @@ -0,0 +1,11 @@ +# DO NOT DELETE + +./main.o: convert.h +./convert.o: convert.h test.h ../src/convert/convert.h +./convert.o: ../src/convert/inttostr.h ../src/convert/patternreplacer.h +./convert.o: ../src/textstream/textstream.h ../src/space/space.h +./convert.o: ../src/textstream/types.h ../src/convert/inttostr.h +./convert.o: ../src/date/date.h ../src/membuffer/membuffer.h +./convert.o: ../src/textstream/types.h ../src/convert/strtoint.h +./convert.o: ../src/convert/text.h ../src/convert/misc.h +./test.o: test.h diff --git a/tests/convert.cpp b/tests/convert.cpp new file mode 100644 index 0000000..7106d95 --- /dev/null +++ b/tests/convert.cpp @@ -0,0 +1,1985 @@ +/* + * This file is a part of PikoTools + * and is distributed under the (new) BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2021, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name Tomasz Sowa nor the names of contributors to this + * project may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "convert.h" +#include "test.h" +#include "convert/convert.h" + + +namespace pt +{ + +// remove me in the future (when PT will be changed to pt) +using namespace PT; + + +namespace pt_convert_tests +{ + +void test_text1() +{ + reset_test_counter("is_white"); + + test(PT::is_white(0), false); + test(PT::is_white(1), false); + test(PT::is_white(9), true); + test(PT::is_white(10), true); + test(PT::is_white(30), false); + test(PT::is_white(32), true); + test(PT::is_white(40), false); + test(PT::is_white('a'), false); + test(PT::is_white(0xabcd), false); + + test(PT::is_white(5, false, false), false); + test(PT::is_white(9, false, false), true); + test(PT::is_white(10, false, false), false); + test(PT::is_white(31, false, false), false); + test(PT::is_white(32, false, false), true); + test(PT::is_white('z', false, false), false); + test(PT::is_white(0xbbcc, false, false), false); + test(PT::is_white(0xffff, false, false), false); + test(PT::is_white(0x10ffff, false, false), false); + + test(PT::is_white(0x000B, false, false), false); + test(PT::is_white(0x00A0, false, false), false); + test(PT::is_white(0x2001, false, false), false); + test(PT::is_white(0x2009, false, false), false); + test(PT::is_white(0xFEFF, false, false), false); + + test(PT::is_white(0x000B, true, false), true); + test(PT::is_white(0x00A0, true, false), true); + test(PT::is_white(0x2001, true, false), true); + test(PT::is_white(0x2009, true, false), true); + test(PT::is_white(0xFEFF, true, false), true); +} + + +void test_text2() +{ + reset_test_counter("is_digit"); + + int digit; + + test(PT::is_digit(0, 10, &digit), false); + test(PT::is_digit(1, 10, &digit), false); + test(PT::is_digit(10, 10, &digit), false); + test(PT::is_digit(32, 10, &digit), false); + test(PT::is_digit('z', 10, &digit), false); + test(PT::is_digit('x', 10, &digit), false); + + test(PT::is_digit('0', 2, &digit), true); + test(digit, 0); + + test(PT::is_digit('1', 2, &digit), true); + test(digit, 1); + + test(PT::is_digit('2', 2, &digit), false); + + + test(PT::is_digit('0', 8, &digit), true); + test(digit, 0); + + test(PT::is_digit('7', 8, &digit), true); + test(digit, 7); + + test(PT::is_digit('8', 8, &digit), false); + + + test(PT::is_digit('0', 10, &digit), true); + test(digit, 0); + + test(PT::is_digit('1', 10, &digit), true); + test(digit, 1); + + test(PT::is_digit('8', 10, &digit), true); + test(digit, 8); + + test(PT::is_digit('9', 10, &digit), true); + test(digit, 9); + + test(PT::is_digit('a', 10, &digit), false); + + + test(PT::is_digit('a', 16, &digit), true); + test(digit, 0x0a); + + test(PT::is_digit('c', 16, &digit), true); + test(digit, 0x0c); + + test(PT::is_digit('f', 16, &digit), true); + test(digit, 0x0f); + + test(PT::is_digit('g', 16, &digit), false); +} + + +void test_text3() +{ + reset_test_counter("skip_white"); + + test(PT::skip_white(""), ""); + test(PT::skip_white(" "), ""); + test(PT::skip_white("\n \n"), ""); + test(PT::skip_white("hello world"), "hello world"); + test(PT::skip_white(" hello world"), "hello world"); + test(PT::skip_white(" hello world"), "hello world"); + test(PT::skip_white(" hello world"), "hello world"); + test(PT::skip_white(" hello world"), "hello world"); + + test(PT::skip_white("\n\nhello world"), "hello world"); + test(PT::skip_white("\n\nhello world", true, true), "hello world"); + test(PT::skip_white("\n\nhello world", true, false), "\n\nhello world"); + test(PT::skip_white("\n\n \n\n \t\t\n\nhello world", true, true), "hello world"); + + test(PT::skip_white(L" hello world"), L"hello world"); + test(PT::skip_white(L" hello world"), L"hello world"); + test(PT::skip_white(L" hello world"), L"hello world"); + test(PT::skip_white(L" hello world"), L"hello world"); + + test(PT::skip_white(L"\n\nhello world", true, true), L"hello world"); + test(PT::skip_white(L"\n\nhello world", true, false), L"\n\nhello world"); + test(PT::skip_white(L"\n\n \n\n \t\t\n\nhello world", true, true), L"hello world"); + + test(PT::skip_white(L"\x000B hello world", true, true), L"hello world"); + test(PT::skip_white(L"\x000B hello world", false, true), L"\x000B hello world"); + + test(PT::skip_white(L"\x2029 hello world", true, true), L"hello world"); + test(PT::skip_white(L"\x2029 hello world", false, true), L"\x2029 hello world"); +} + + + +void test_text4() +{ + reset_test_counter("skip_white_from_back"); + + test(PT::skip_white_from_back(""), ""); + test(PT::skip_white_from_back(" "), " "); + test(PT::skip_white_from_back("\n \n"), "\n \n"); + + test(PT::skip_white_from_back("hello world"), ""); + test(PT::skip_white_from_back("hello world "), " "); + test(PT::skip_white_from_back("hello world "), " "); + test(PT::skip_white_from_back("hello world "), " "); + + test(PT::skip_white_from_back("hello world\n\n"), "\n\n"); + test(PT::skip_white_from_back("hello world\n\n", true, true), "\n\n"); + test(PT::skip_white_from_back("hello world\n\n", true, false), ""); + test(PT::skip_white_from_back("hello world\n\n \n\n \t\t\n\n", true, true), "\n\n \n\n \t\t\n\n"); + + + test(PT::skip_white_from_back(L"hello world "), L" "); + test(PT::skip_white_from_back(L"hello world "), L" "); + test(PT::skip_white_from_back(L"hello world\n\n\n\t\t\t "), L"\n\n\n\t\t\t "); + test(PT::skip_white_from_back(L"hello world "), L" "); + + test(PT::skip_white_from_back(L"hello world\n\n", true, true), L"\n\n"); + test(PT::skip_white_from_back(L"hello world\n\n", true, false), L""); + test(PT::skip_white_from_back(L"hello world\n\n \n\n \t\t\n\n", true, true), L"\n\n \n\n \t\t\n\n"); + + test(PT::skip_white_from_back(L"hello world \x000B", true, true), L" \x000B"); + test(PT::skip_white_from_back(L"hello world \x000B", false, true), L""); + + test(PT::skip_white_from_back(L"hello world \x2029", true, true), L" \x2029"); + test(PT::skip_white_from_back(L"hello world \x2029", false, true), L""); +} + + +void test_text5() +{ + reset_test_counter("to_lower"); + + test(PT::to_lower((char)0), (char)0); + test(PT::to_lower((char)32), (char)32); + test(PT::to_lower((char)127), (char)127); + test(PT::to_lower((char)128), (char)128); + test(PT::to_lower((char)200), (char)200); + test(PT::to_lower((char)255), (char)255); + + test(PT::to_lower('a'), 'a'); + test(PT::to_lower('c'), 'c'); + test(PT::to_lower('t'), 't'); + test(PT::to_lower('z'), 'z'); + test(PT::to_lower('0'), '0'); + test(PT::to_lower('A'), 'a'); + test(PT::to_lower('C'), 'c'); + test(PT::to_lower('X'), 'x'); + test(PT::to_lower('Z'), 'z'); + test(PT::to_lower('@'), '@'); + test(PT::to_lower('['), '['); + test(PT::to_lower('`'), '`'); + test(PT::to_lower('{'), '{'); + + test(PT::to_lower((wchar_t)0), (wchar_t)0); + test(PT::to_lower((wchar_t)32), (wchar_t)32); + test(PT::to_lower((wchar_t)127), (wchar_t)127); + test(PT::to_lower((wchar_t)128), (wchar_t)128); + test(PT::to_lower((wchar_t)200), (wchar_t)200); + test(PT::to_lower((wchar_t)255), (wchar_t)255); + + test(PT::to_lower(L'a'), L'a'); + test(PT::to_lower(L't'), L't'); + test(PT::to_lower(L'z'), L'z'); + test(PT::to_lower(L'0'), L'0'); + test(PT::to_lower(L'A'), L'a'); + test(PT::to_lower(L'C'), L'c'); + test(PT::to_lower(L'X'), L'x'); + test(PT::to_lower(L'Z'), L'z'); + test(PT::to_lower(L'@'), L'@'); + test(PT::to_lower(L'['), L'['); +} + + +void test_text6() +{ + reset_test_counter("to_upper"); + + test(PT::to_upper((char)0), (char)0); + test(PT::to_upper((char)32), (char)32); + test(PT::to_upper((char)127), (char)127); + test(PT::to_upper((char)128), (char)128); + test(PT::to_upper((char)200), (char)200); + test(PT::to_upper((char)255), (char)255); + + test(PT::to_upper('a'), 'A'); + test(PT::to_upper('c'), 'C'); + test(PT::to_upper('t'), 'T'); + test(PT::to_upper('z'), 'Z'); + test(PT::to_upper('0'), '0'); + test(PT::to_upper('A'), 'A'); + test(PT::to_upper('C'), 'C'); + test(PT::to_upper('X'), 'X'); + test(PT::to_upper('Z'), 'Z'); + test(PT::to_upper('@'), '@'); + test(PT::to_upper('['), '['); + test(PT::to_upper('`'), '`'); + test(PT::to_upper('{'), '{'); + + test(PT::to_upper((wchar_t)0), (wchar_t)0); + test(PT::to_upper((wchar_t)32), (wchar_t)32); + test(PT::to_upper((wchar_t)127), (wchar_t)127); + test(PT::to_upper((wchar_t)128), (wchar_t)128); + test(PT::to_upper((wchar_t)200), (wchar_t)200); + test(PT::to_upper((wchar_t)255), (wchar_t)255); + + test(PT::to_upper(L'a'), L'A'); + test(PT::to_upper(L't'), L'T'); + test(PT::to_upper(L'z'), L'Z'); + test(PT::to_upper(L'0'), L'0'); + test(PT::to_upper(L'A'), L'A'); + test(PT::to_upper(L'C'), L'C'); + test(PT::to_upper(L'X'), L'X'); + test(PT::to_upper(L'Z'), L'Z'); + test(PT::to_upper(L'@'), L'@'); + test(PT::to_upper(L'['), L'['); +} + + +void test_text7() +{ + reset_test_counter("to_lower_emplace std::string"); + std::string str1, str2; + + str1 = "abcdefghijklm nopqrstuvwxyz"; + str2 = str1; + to_lower_emplace(str1); + test(str1, str2); + + str1 += "A"; + str2 += "a"; + to_lower_emplace(str1); + test(str1, str2); + + str1 += "B"; + str2 += "b"; + to_lower_emplace(str1); + test(str1, str2); + + str1 += "@[`{CDEFGHIJKLMNOPQRSTUVWXYZ"; + str2 += "@[`{cdefghijklmnopqrstuvwxyz"; + to_lower_emplace(str1); + test(str1, str2); + + str1 += "0123456789"; + str2 += "0123456789"; + to_lower_emplace(str1); + test(str1, str2); + + str1 += "[];'\\!@#$%^&*()_+"; + str2 += "[];'\\!@#$%^&*()_+"; + to_lower_emplace(str1); + test(str1, str2); +} + + +void test_text8() +{ + reset_test_counter("to_lower_emplace std::wstring"); + std::wstring str1, str2; + + str1 = L"abcdefghijklm nopqrstuvwxyz"; + str2 = str1; + to_lower_emplace(str1); + test(str1, str2); + + str1 += L"A"; + str2 += L"a"; + to_lower_emplace(str1); + test(str1, str2); + + str1 += L"B"; + str2 += L"b"; + to_lower_emplace(str1); + test(str1, str2); + + str1 += L"@[`{CDEFGHIJKLMNOPQRSTUVWXYZ"; + str2 += L"@[`{cdefghijklmnopqrstuvwxyz"; + to_lower_emplace(str1); + test(str1, str2); + + str1 += L"0123456789"; + str2 += L"0123456789"; + to_lower_emplace(str1); + test(str1, str2); + + str1 += L"[];'\\!@#$%^&*()_+"; + str2 += L"[];'\\!@#$%^&*()_+"; + to_lower_emplace(str1); + test(str1, str2); + + str1 += L"\xabcd \xf000"; + str2 += L"\xabcd \xf000"; + to_lower_emplace(str1); + test(str1, str2); + + str1 += L"\x0000 \x1234"; + str2 += L"\x0000 \x1234"; + to_lower_emplace(str1); + test(str1, str2); +} + + +void test_text9() +{ + reset_test_counter("to_upper_emplace std::string"); + std::string str1, str2; + + str1 = "ABCDEFGHIJKLM NOPQRSTUVWXYZ"; + str2 = str1; + to_upper_emplace(str1); + test(str1, str2); + + str1 += "a"; + str2 += "A"; + to_upper_emplace(str1); + test(str1, str2); + + str1 += "b"; + str2 += "B"; + to_upper_emplace(str1); + test(str1, str2); + + str1 += "@[`{cdefghijklmnopqrstuvwxyz"; + str2 += "@[`{CDEFGHIJKLMNOPQRSTUVWXYZ"; + to_upper_emplace(str1); + test(str1, str2); + + str1 += "0123456789"; + str2 += "0123456789"; + to_upper_emplace(str1); + test(str1, str2); + + str1 += "[];'\\!@#$%^&*()_+"; + str2 += "[];'\\!@#$%^&*()_+"; + to_upper_emplace(str1); + test(str1, str2); +} + + +void test_text10() +{ + reset_test_counter("to_upper_emplace std::wstring"); + std::wstring str1, str2; + + str1 = L"ABCDEFGHIJKLM NOPQRSTUVWXYZ"; + str2 = str1; + to_upper_emplace(str1); + test(str1, str2); + + str1 += L"a"; + str2 += L"A"; + to_upper_emplace(str1); + test(str1, str2); + + str1 += L"b"; + str2 += L"B"; + to_upper_emplace(str1); + test(str1, str2); + + str1 += L"@[`{cdefghijklmnopqrstuvwxyz"; + str2 += L"@[`{CDEFGHIJKLMNOPQRSTUVWXYZ"; + to_upper_emplace(str1); + test(str1, str2); + + str1 += L"0123456789"; + str2 += L"0123456789"; + to_upper_emplace(str1); + test(str1, str2); + + str1 += L"[];'\\!@#$%^&*()_+"; + str2 += L"[];'\\!@#$%^&*()_+"; + to_upper_emplace(str1); + test(str1, str2); +} + + + +void test_text11() +{ + reset_test_counter("to_lower std::string"); + std::string str1, str2; + + str1 = "abcdefghijklm nopqrstuvwxyz"; + str2 = str1; + test(PT::to_lower(str1), str2); + + str1 += "A"; + str2 += "a"; + test(PT::to_lower(str1), str2); + + str1 += "B"; + str2 += "b"; + test(PT::to_lower(str1), str2); + + str1 += "@[`{CDEFGHIJKLMNOPQRSTUVWXYZ"; + str2 += "@[`{cdefghijklmnopqrstuvwxyz"; + test(PT::to_lower(str1), str2); + + str1 += "0123456789"; + str2 += "0123456789"; + test(PT::to_lower(str1), str2); + + str1 += "[];'\\!@#$%^&*()_+"; + str2 += "[];'\\!@#$%^&*()_+"; + test(PT::to_lower(str1), str2); +} + + +void test_text12() +{ + reset_test_counter("to_lower std::wstring"); + std::wstring str1, str2; + + str1 = L"abcdefghijklm nopqrstuvwxyz"; + str2 = str1; + test(PT::to_lower(str1), str2); + + str1 += L"A"; + str2 += L"a"; + test(PT::to_lower(str1), str2); + + str1 += L"B"; + str2 += L"b"; + test(PT::to_lower(str1), str2); + + str1 += L"@[`{CDEFGHIJKLMNOPQRSTUVWXYZ"; + str2 += L"@[`{cdefghijklmnopqrstuvwxyz"; + test(PT::to_lower(str1), str2); + + str1 += L"0123456789"; + str2 += L"0123456789"; + test(PT::to_lower(str1), str2); + + str1 += L"[];'\\!@#$%^&*()_+"; + str2 += L"[];'\\!@#$%^&*()_+"; + test(PT::to_lower(str1), str2); +} + + +void test_text13() +{ + reset_test_counter("to_upper std::string"); + std::string str1, str2; + + str1 = "ABCDEFGHIJKLM NOPQRSTUVWXYZ"; + str2 = str1; + test(PT::to_upper(str1), str2); + + str1 += "a"; + str2 += "A"; + test(PT::to_upper(str1), str2); + + str1 += "b"; + str2 += "B"; + test(PT::to_upper(str1), str2); + + str1 += "@[`{cdefghijklmnopqrstuvwxyz"; + str2 += "@[`{CDEFGHIJKLMNOPQRSTUVWXYZ"; + test(PT::to_upper(str1), str2); + + str1 += "0123456789"; + str2 += "0123456789"; + test(PT::to_upper(str1), str2); + + str1 += "[];'\\!@#$%^&*()_+"; + str2 += "[];'\\!@#$%^&*()_+"; + test(PT::to_upper(str1), str2); +} + + +void test_text14() +{ + reset_test_counter("to_upper std::wstring"); + std::wstring str1, str2; + + str1 = L"ABCDEFGHIJKLM NOPQRSTUVWXYZ"; + str2 = str1; + test(PT::to_upper(str1), str2); + + str1 += L"a"; + str2 += L"A"; + test(PT::to_upper(str1), str2); + + str1 += L"b"; + str2 += L"B"; + test(PT::to_upper(str1), str2); + + str1 += L"@[`{cdefghijklmnopqrstuvwxyz"; + str2 += L"@[`{CDEFGHIJKLMNOPQRSTUVWXYZ"; + test(PT::to_upper(str1), str2); + + str1 += L"0123456789"; + str2 += L"0123456789"; + test(PT::to_upper(str1), str2); + + str1 += L"[];'\\!@#$%^&*()_+"; + str2 += L"[];'\\!@#$%^&*()_+"; + test(PT::to_upper(str1), str2); +} + + +void test_text15() +{ + reset_test_counter("compare const char *"); + + test(PT::compare("", "") == 0, true); + test(PT::compare("a", "a") == 0, true); + test(PT::compare("abc", "abc") == 0, true); + test(PT::compare("ABC", "ABC") == 0, true); + test(PT::compare("hello world", "hello world") == 0, true); + test(PT::compare("hello world", "HELLO WORLD") > 0, true); + test(PT::compare("HELLO WORLD", "hello world") < 0, true); + test(PT::compare("HEllo WOrld", "heLLO woRLD") < 0, true); + test(PT::compare("heLLO woRLD", "HEllo WOrld") > 0, true); + + test(PT::compare("a", "b") < 0, true); + test(PT::compare("b", "c") < 0, true); + test(PT::compare("x", "z") < 0, true); + test(PT::compare("hello world", "xhelloworld") < 0, true); + + test(PT::compare("c", "b") > 0, true); + test(PT::compare("d", "c") > 0, true); + test(PT::compare("z", "x") > 0, true); + test(PT::compare("xhello world", "helloworld") > 0, true); + + test(PT::compare("abc8", "abc9") < 0, true); + test(PT::compare("abc9", "abc8") > 0, true); + test(PT::compare("abc8abc", "abc9abc") < 0, true); + test(PT::compare("abc9abc", "abc8abc") > 0, true); + test(PT::compare("abc9abc", "abc8") > 0, true); + test(PT::compare("abc8abc", "abc9") < 0, true); + test(PT::compare("abc8", "abc9abc") < 0, true); + test(PT::compare("abc9", "abc8abc") > 0, true); + + char foo[] = {"abc"}; + char bar[] = {"abc"}; + test(PT::compare(foo, bar) == 0, true); + + foo[0] = (char)(unsigned char)127; + bar[0] = (char)(unsigned char)128; + test(PT::compare(foo, bar) < 0, true); + + foo[0] = (char)(unsigned char)128; + bar[0] = (char)(unsigned char)127; + test(PT::compare(foo, bar) > 0, true); + + foo[0] = (char)(unsigned char)1; + bar[0] = (char)(unsigned char)255; + test(PT::compare(foo, bar) < 0, true); + + foo[0] = (char)(unsigned char)255; + bar[0] = (char)(unsigned char)1; + test(PT::compare(foo, bar) > 0, true); + + foo[0] = (char)(unsigned char)0; + bar[0] = (char)(unsigned char)0; + test(PT::compare(foo, bar) == 0, true); + + foo[0] = (char)(unsigned char)0; + bar[0] = (char)(unsigned char)1; + test(PT::compare(foo, bar) < 0, true); + + foo[0] = (char)(unsigned char)1; + bar[0] = (char)(unsigned char)0; + test(PT::compare(foo, bar) > 0, true); +} + + + +void test_text16() +{ + reset_test_counter("compare const wchar_t *"); + + test(PT::compare(L"", L"") == 0, true); + test(PT::compare(L"a", L"a") == 0, true); + test(PT::compare(L"abc", L"abc") == 0, true); + test(PT::compare(L"ABC", L"ABC") == 0, true); + test(PT::compare(L"hello world", L"hello world") == 0, true); + test(PT::compare(L"hello world", L"HELLO WORLD") > 0, true); + test(PT::compare(L"HELLO WORLD", L"hello world") < 0, true); + test(PT::compare(L"HEllo WOrld", L"heLLO woRLD") < 0, true); + test(PT::compare(L"heLLO woRLD", L"HEllo WOrld") > 0, true); + + test(PT::compare(L"a", L"b") < 0, true); + test(PT::compare(L"b", L"c") < 0, true); + test(PT::compare(L"x", L"z") < 0, true); + test(PT::compare(L"hello world", L"xhelloworld") < 0, true); + + test(PT::compare(L"c", L"b") > 0, true); + test(PT::compare(L"d", L"c") > 0, true); + test(PT::compare(L"z", L"x") > 0, true); + test(PT::compare(L"xhello world", L"helloworld") > 0, true); + + test(PT::compare(L"abc8", L"abc9") < 0, true); + test(PT::compare(L"abc9", L"abc8") > 0, true); + test(PT::compare(L"abc8abc", L"abc9abc") < 0, true); + test(PT::compare(L"abc9abc", L"abc8abc") > 0, true); + test(PT::compare(L"abc9abc", L"abc8") > 0, true); + test(PT::compare(L"abc8abc", L"abc9") < 0, true); + test(PT::compare(L"abc8", L"abc9abc") < 0, true); + test(PT::compare(L"abc9", L"abc8abc") > 0, true); + + wchar_t foo[] = {L"abc"}; + wchar_t bar[] = {L"abc"}; + test(PT::compare(foo, bar) == 0, true); + + foo[0] = (wchar_t)127; + bar[0] = (wchar_t)128; + test(PT::compare(foo, bar) < 0, true); + + foo[0] = (wchar_t)128; + bar[0] = (wchar_t)127; + test(PT::compare(foo, bar) > 0, true); + + foo[0] = (wchar_t)1; + bar[0] = (wchar_t)255; + test(PT::compare(foo, bar) < 0, true); + + foo[0] = (wchar_t)255; + bar[0] = (wchar_t)1; + test(PT::compare(foo, bar) > 0, true); + + foo[0] = (wchar_t)0; + bar[0] = (wchar_t)0; + test(PT::compare(foo, bar) == 0, true); + + foo[0] = (wchar_t)0; + bar[0] = (wchar_t)1; + test(PT::compare(foo, bar) < 0, true); + + foo[0] = (wchar_t)1; + bar[0] = (wchar_t)0; + test(PT::compare(foo, bar) > 0, true); + + foo[0] = (wchar_t)1; + bar[0] = (wchar_t)0xffff; + test(PT::compare(foo, bar) < 0, true); + + foo[0] = (wchar_t)127; + bar[0] = (wchar_t)0xffff; + test(PT::compare(foo, bar) < 0, true); + + foo[0] = (wchar_t)128; + bar[0] = (wchar_t)0xffff; + test(PT::compare(foo, bar) < 0, true); + + foo[0] = (wchar_t)0xffff; + bar[0] = (wchar_t)1; + test(PT::compare(foo, bar) > 0, true); + + foo[0] = (wchar_t)0xffff; + bar[0] = (wchar_t)127; + test(PT::compare(foo, bar) > 0, true); + + foo[0] = (wchar_t)0xffff; + bar[0] = (wchar_t)128; + test(PT::compare(foo, bar) > 0, true); +} + +void test_text17() +{ + reset_test_counter("compare std::string"); + + std::string str1, str2; + test(PT::compare(str1, str2) == 0, true); + + str1 = "abc"; + str2 = "abc"; + test(PT::compare(str1, str2) == 0, true); + + str1 = "aBc"; + str2 = "abc"; + test(PT::compare(str1, str2) < 0, true); + + str1 = "abc"; + str2 = "aBc"; + test(PT::compare(str1, str2) > 0, true); + + str1 = "xyz"; + str2 = "abc"; + test(PT::compare(str1, str2) > 0, true); + + str1 = "abc"; + str2 = "xyz"; + test(PT::compare(str1, str2) < 0, true); + + str1 = "abc1"; + str2 = "abc2"; + test(PT::compare(str1, str2) < 0, true); + + str1 = "abc9"; + str2 = "abc8"; + test(PT::compare(str1, str2) > 0, true); +} + +void test_text18() +{ + reset_test_counter("compare std::wstring"); + + std::wstring str1, str2; + test(PT::compare(str1, str2) == 0, true); + + str1 = L"abc"; + str2 = L"abc"; + test(PT::compare(str1, str2) == 0, true); + + str1 = L"aBc"; + str2 = L"abc"; + test(PT::compare(str1, str2) < 0, true); + + str1 = L"abc"; + str2 = L"aBc"; + test(PT::compare(str1, str2) > 0, true); + + str1 = L"xyz"; + str2 = L"abc"; + test(PT::compare(str1, str2) > 0, true); + + str1 = L"abc"; + str2 = L"xyz"; + test(PT::compare(str1, str2) < 0, true); + + str1 = L"abc1"; + str2 = L"abc2"; + test(PT::compare(str1, str2) < 0, true); + + str1 = L"abc9"; + str2 = L"abc8"; + test(PT::compare(str1, str2) > 0, true); +} + +void test_text19() +{ + reset_test_counter("compare const char* str1_begin, str1_end, str2"); + + char foo[] = {"abcdef"}; + char bar[] = {"abcdef"}; + size_t len = sizeof(foo) / sizeof(char) - 1; // minus terminating zero + + test(PT::compare(foo, foo + len, bar) == 0, true); + test(PT::compare(foo, foo + len - 1, bar) < 0, true); + + foo[len - 1] = (char)(unsigned char)127; + bar[len - 1] = (char)(unsigned char)128; + test(PT::compare(foo, foo + len, bar) < 0, true); + + foo[len - 1] = (char)(unsigned char)128; + bar[len - 1] = (char)(unsigned char)127; + test(PT::compare(foo, foo + len, bar) > 0, true); + + foo[len - 1] = (char)(unsigned char)1; + bar[len - 1] = (char)(unsigned char)255; + test(PT::compare(foo, foo + len, bar) < 0, true); + + foo[len - 1] = (char)(unsigned char)255; + bar[len - 1] = (char)(unsigned char)1; + test(PT::compare(foo, foo + len, bar) > 0, true); + + foo[len - 1] = 'f'; + bar[len - 1] = 'f'; + bar[3] = 'X'; + test(PT::compare(foo, foo + len, bar) > 0, true); + foo[3] = 'A'; + test(PT::compare(foo, foo + len, bar) < 0, true); +} + +void test_text20() +{ + reset_test_counter("compare const wchar_t * str1_begin, str1_end, str2"); + + wchar_t foo[] = {L"abcdef"}; + wchar_t bar[] = {L"abcdef"}; + size_t len = sizeof(foo) / sizeof(wchar_t) - 1; // minus terminating zero + + test(PT::compare(foo, foo + len, bar) == 0, true); + test(PT::compare(foo, foo + len - 1, bar) < 0, true); + + foo[len - 1] = (wchar_t)127; + bar[len - 1] = (wchar_t)128; + test(PT::compare(foo, foo + len, bar) < 0, true); + + foo[len - 1] = (wchar_t)128; + bar[len - 1] = (wchar_t)127; + test(PT::compare(foo, foo + len, bar) > 0, true); + + foo[len - 1] = (wchar_t)1; + bar[len - 1] = (wchar_t)255; + test(PT::compare(foo, foo + len, bar) < 0, true); + + foo[len - 1] = (wchar_t)255; + bar[len - 1] = (wchar_t)1; + test(PT::compare(foo, foo + len, bar) > 0, true); + + foo[len - 1] = (wchar_t)1; + bar[len - 1] = (wchar_t)0xffff; + test(PT::compare(foo, foo + len, bar) < 0, true); + + foo[len - 1] = (wchar_t)0xffff; + bar[len - 1] = (wchar_t)1; + test(PT::compare(foo, foo + len, bar) > 0, true); + + foo[len - 1] = L'f'; + bar[len - 1] = L'f'; + bar[3] = L'X'; + test(PT::compare(foo, foo + len, bar) > 0, true); + foo[3] = L'A'; + test(PT::compare(foo, foo + len, bar) < 0, true); +} + + + +void test_text21() +{ + reset_test_counter("compare_nc const char *"); + + test(PT::compare_nc("", "") == 0, true); + test(PT::compare_nc("a", "a") == 0, true); + test(PT::compare_nc("abc", "abc") == 0, true); + test(PT::compare_nc("ABC", "ABC") == 0, true); + test(PT::compare_nc("hello world", "hello world") == 0, true); + test(PT::compare_nc("hello world", "HELLO WORLD") == 0, true); + test(PT::compare_nc("HELLO WORLD", "hello world") == 0, true); + test(PT::compare_nc("HEllo WOrld", "heLLO woRLD") == 0, true); + test(PT::compare_nc("heLLO woRLD", "HEllo WOrld")== 0, true); + + test(PT::compare_nc("a", "b") < 0, true); + test(PT::compare_nc("b", "c") < 0, true); + test(PT::compare_nc("x", "z") < 0, true); + test(PT::compare_nc("hello world", "xhelloworld") < 0, true); + + test(PT::compare_nc("c", "b") > 0, true); + test(PT::compare_nc("d", "c") > 0, true); + test(PT::compare_nc("z", "x") > 0, true); + test(PT::compare_nc("xhello world", "helloworld") > 0, true); + + test(PT::compare_nc("abc8", "abc9") < 0, true); + test(PT::compare_nc("abc9", "abc8") > 0, true); + test(PT::compare_nc("abc8abc", "abc9abc") < 0, true); + test(PT::compare_nc("abc9abc", "abc8abc") > 0, true); + test(PT::compare_nc("abc9abc", "abc8") > 0, true); + test(PT::compare_nc("abc8abc", "abc9") < 0, true); + test(PT::compare_nc("abc8", "abc9abc") < 0, true); + test(PT::compare_nc("abc9", "abc8abc") > 0, true); + + char foo[] = {"abc"}; + char bar[] = {"abc"}; + test(PT::compare_nc(foo, bar) == 0, true); + + foo[0] = (char)(unsigned char)127; + bar[0] = (char)(unsigned char)128; + test(PT::compare_nc(foo, bar) < 0, true); + + foo[0] = (char)(unsigned char)128; + bar[0] = (char)(unsigned char)127; + test(PT::compare_nc(foo, bar) > 0, true); + + foo[0] = (char)(unsigned char)1; + bar[0] = (char)(unsigned char)255; + test(PT::compare_nc(foo, bar) < 0, true); + + foo[0] = (char)(unsigned char)255; + bar[0] = (char)(unsigned char)1; + test(PT::compare_nc(foo, bar) > 0, true); + + foo[0] = (char)(unsigned char)0; + bar[0] = (char)(unsigned char)0; + test(PT::compare_nc(foo, bar) == 0, true); + + foo[0] = (char)(unsigned char)0; + bar[0] = (char)(unsigned char)1; + test(PT::compare_nc(foo, bar) < 0, true); + + foo[0] = (char)(unsigned char)1; + bar[0] = (char)(unsigned char)0; + test(PT::compare_nc(foo, bar) > 0, true); +} + + + +void test_text22() +{ + reset_test_counter("compare_nc const wchar_t *"); + + test(PT::compare_nc(L"", L"") == 0, true); + test(PT::compare_nc(L"a", L"a") == 0, true); + test(PT::compare_nc(L"abc", L"abc") == 0, true); + test(PT::compare_nc(L"ABC", L"ABC") == 0, true); + test(PT::compare_nc(L"hello world", L"hello world") == 0, true); + test(PT::compare_nc(L"hello world", L"HELLO WORLD") == 0, true); + test(PT::compare_nc(L"HELLO WORLD", L"hello world") == 0, true); + test(PT::compare_nc(L"HEllo WOrld", L"heLLO woRLD") == 0, true); + test(PT::compare_nc(L"heLLO woRLD", L"HEllo WOrld") == 0, true); + + test(PT::compare_nc(L"a", L"b") < 0, true); + test(PT::compare_nc(L"b", L"c") < 0, true); + test(PT::compare_nc(L"x", L"z") < 0, true); + test(PT::compare_nc(L"hello world", L"xhelloworld") < 0, true); + + test(PT::compare_nc(L"c", L"b") > 0, true); + test(PT::compare_nc(L"d", L"c") > 0, true); + test(PT::compare_nc(L"z", L"x") > 0, true); + test(PT::compare_nc(L"xhello world", L"helloworld") > 0, true); + + test(PT::compare_nc(L"abc8", L"abc9") < 0, true); + test(PT::compare_nc(L"abc9", L"abc8") > 0, true); + test(PT::compare_nc(L"abc8abc", L"abc9abc") < 0, true); + test(PT::compare_nc(L"abc9abc", L"abc8abc") > 0, true); + test(PT::compare_nc(L"abc9abc", L"abc8") > 0, true); + test(PT::compare_nc(L"abc8abc", L"abc9") < 0, true); + test(PT::compare_nc(L"abc8", L"abc9abc") < 0, true); + test(PT::compare_nc(L"abc9", L"abc8abc") > 0, true); + + wchar_t foo[] = {L"abc"}; + wchar_t bar[] = {L"abc"}; + test(PT::compare_nc(foo, bar) == 0, true); + + foo[0] = (wchar_t)127; + bar[0] = (wchar_t)128; + test(PT::compare_nc(foo, bar) < 0, true); + + foo[0] = (wchar_t)128; + bar[0] = (wchar_t)127; + test(PT::compare_nc(foo, bar) > 0, true); + + foo[0] = (wchar_t)1; + bar[0] = (wchar_t)255; + test(PT::compare_nc(foo, bar) < 0, true); + + foo[0] = (wchar_t)255; + bar[0] = (wchar_t)1; + test(PT::compare_nc(foo, bar) > 0, true); + + foo[0] = (wchar_t)0; + bar[0] = (wchar_t)0; + test(PT::compare_nc(foo, bar) == 0, true); + + foo[0] = (wchar_t)0; + bar[0] = (wchar_t)1; + test(PT::compare_nc(foo, bar) < 0, true); + + foo[0] = (wchar_t)1; + bar[0] = (wchar_t)0; + test(PT::compare_nc(foo, bar) > 0, true); + + foo[0] = (wchar_t)1; + bar[0] = (wchar_t)0xffff; + test(PT::compare_nc(foo, bar) < 0, true); + + foo[0] = (wchar_t)127; + bar[0] = (wchar_t)0xffff; + test(PT::compare_nc(foo, bar) < 0, true); + + foo[0] = (wchar_t)128; + bar[0] = (wchar_t)0xffff; + test(PT::compare_nc(foo, bar) < 0, true); + + foo[0] = (wchar_t)0xffff; + bar[0] = (wchar_t)1; + test(PT::compare_nc(foo, bar) > 0, true); + + foo[0] = (wchar_t)0xffff; + bar[0] = (wchar_t)127; + test(PT::compare_nc(foo, bar) > 0, true); + + foo[0] = (wchar_t)0xffff; + bar[0] = (wchar_t)128; + test(PT::compare_nc(foo, bar) > 0, true); +} + +void test_text23() +{ + reset_test_counter("compare_nc std::string"); + + std::string str1, str2; + test(PT::compare_nc(str1, str2) == 0, true); + + str1 = "abc"; + str2 = "abc"; + test(PT::compare_nc(str1, str2) == 0, true); + + str1 = "aBc"; + str2 = "abc"; + test(PT::compare_nc(str1, str2) == 0, true); + + str1 = "abc"; + str2 = "aBc"; + test(PT::compare_nc(str1, str2) == 0, true); + + str1 = "xyz"; + str2 = "abc"; + test(PT::compare_nc(str1, str2) > 0, true); + + str1 = "abc"; + str2 = "xyz"; + test(PT::compare_nc(str1, str2) < 0, true); + + str1 = "abc1"; + str2 = "abc2"; + test(PT::compare_nc(str1, str2) < 0, true); + + str1 = "abc9"; + str2 = "abc8"; + test(PT::compare_nc(str1, str2) > 0, true); +} + +void test_text24() +{ + reset_test_counter("compare_nc std::wstring"); + + std::wstring str1, str2; + test(PT::compare_nc(str1, str2) == 0, true); + + str1 = L"abc"; + str2 = L"abc"; + test(PT::compare_nc(str1, str2) == 0, true); + + str1 = L"aBc"; + str2 = L"abc"; + test(PT::compare_nc(str1, str2) == 0, true); + + str1 = L"abc"; + str2 = L"aBc"; + test(PT::compare_nc(str1, str2) == 0, true); + + str1 = L"xyz"; + str2 = L"abc"; + test(PT::compare_nc(str1, str2) > 0, true); + + str1 = L"abc"; + str2 = L"xyz"; + test(PT::compare_nc(str1, str2) < 0, true); + + str1 = L"abc1"; + str2 = L"abc2"; + test(PT::compare_nc(str1, str2) < 0, true); + + str1 = L"abc9"; + str2 = L"abc8"; + test(PT::compare_nc(str1, str2) > 0, true); +} + +void test_text25() +{ + reset_test_counter("compare_nc const char* str1_begin, str1_end, str2"); + + char foo[] = {"abcdef"}; + char bar[] = {"abcdef"}; + size_t len = sizeof(foo) / sizeof(char) - 1; // minus terminating zero + + test(PT::compare_nc(foo, foo + len, bar) == 0, true); + test(PT::compare_nc(foo, foo + len - 1, bar) < 0, true); + + foo[len - 1] = (char)(unsigned char)127; + bar[len - 1] = (char)(unsigned char)128; + test(PT::compare_nc(foo, foo + len, bar) < 0, true); + + foo[len - 1] = (char)(unsigned char)128; + bar[len - 1] = (char)(unsigned char)127; + test(PT::compare_nc(foo, foo + len, bar) > 0, true); + + foo[len - 1] = (char)(unsigned char)1; + bar[len - 1] = (char)(unsigned char)255; + test(PT::compare_nc(foo, foo + len, bar) < 0, true); + + foo[len - 1] = (char)(unsigned char)255; + bar[len - 1] = (char)(unsigned char)1; + test(PT::compare_nc(foo, foo + len, bar) > 0, true); + + foo[len - 1] = 'f'; + bar[len - 1] = 'f'; + bar[3] = 'X'; + test(PT::compare_nc(foo, foo + len, bar) < 0, true); + foo[3] = 'Z'; + test(PT::compare_nc(foo, foo + len, bar) > 0, true); +} + +void test_text26() +{ + reset_test_counter("compare_nc const wchar_t * str1_begin, str1_end, str2"); + + wchar_t foo[] = {L"abcdef"}; + wchar_t bar[] = {L"abcdef"}; + size_t len = sizeof(foo) / sizeof(wchar_t) - 1; // minus terminating zero + + test(PT::compare_nc(foo, foo + len, bar) == 0, true); + test(PT::compare_nc(foo, foo + len - 1, bar) < 0, true); + + foo[len - 1] = (wchar_t)127; + bar[len - 1] = (wchar_t)128; + test(PT::compare_nc(foo, foo + len, bar) < 0, true); + + foo[len - 1] = (wchar_t)128; + bar[len - 1] = (wchar_t)127; + test(PT::compare_nc(foo, foo + len, bar) > 0, true); + + foo[len - 1] = (wchar_t)1; + bar[len - 1] = (wchar_t)255; + test(PT::compare_nc(foo, foo + len, bar) < 0, true); + + foo[len - 1] = (wchar_t)255; + bar[len - 1] = (wchar_t)1; + test(PT::compare_nc(foo, foo + len, bar) > 0, true); + + foo[len - 1] = (wchar_t)1; + bar[len - 1] = (wchar_t)0xffff; + test(PT::compare_nc(foo, foo + len, bar) < 0, true); + + foo[len - 1] = (wchar_t)0xffff; + bar[len - 1] = (wchar_t)1; + test(PT::compare_nc(foo, foo + len, bar) > 0, true); + + foo[len - 1] = L'f'; + bar[len - 1] = L'f'; + bar[3] = L'X'; + test(PT::compare_nc(foo, foo + len, bar) < 0, true); + foo[3] = L'Z'; + test(PT::compare_nc(foo, foo + len, bar) > 0, true); +} + + +void test_text27() +{ + reset_test_counter("is_equal char *"); + + test(is_equal("", ""), true); + test(is_equal("", "abc"), false); + test(is_equal("abc", ""), false); + test(is_equal("abc", "abc"), true); + test(is_equal("aBc", "aBc"), true); + test(is_equal("aBc", "abc"), false); + test(is_equal("abc", "aBc"), false); + test(is_equal("abc", "defgh"), false); + test(is_equal("defgh", "abc"), false); +} + +void test_text28() +{ + reset_test_counter("is_equal wchar_t *"); + + test(is_equal(L"", L""), true); + test(is_equal(L"", L"abc"), false); + test(is_equal(L"abc", L""), false); + test(is_equal(L"abc", L"abc"), true); + test(is_equal(L"aBc", L"aBc"), true); + test(is_equal(L"aBc", L"abc"), false); + test(is_equal(L"abc", L"aBc"), false); + test(is_equal(L"abc", L"defgh"), false); + test(is_equal(L"defgh", L"abc"), false); +} + +void test_text29() +{ + reset_test_counter("is_equal std::string"); + + std::string str1, str2; + test(is_equal(str1, str2), true); + + str2 = "xyz"; + test(is_equal(str1, str2), false); + + str1 = "xyz"; + str2 = ""; + test(is_equal(str1, str2), false); + + str1 = "xyz"; + str2 = "xYz"; + test(is_equal(str1, str2), false); + + str1 = "xYz"; + str2 = "xyz"; + test(is_equal(str1, str2), false); + + str1 = "abcxyz"; + str2 = "abc"; + test(is_equal(str1, str2), false); + + str1 = "abc"; + str2 = "abcxyz"; + test(is_equal(str1, str2), false); + + str1 = "xyzabc"; + str2 = "abc"; + test(is_equal(str1, str2), false); + + str1 = "abc"; + str2 = "xyzabc"; + test(is_equal(str1, str2), false); + + str1 = "xyz"; + str2 = "xyz"; + test(is_equal(str1, str2), true); +} + + +void test_text30() +{ + reset_test_counter("is_equal std::wstring"); + + std::wstring str1, str2; + test(is_equal(str1, str2), true); + + str2 = L"xyz"; + test(is_equal(str1, str2), false); + + str1 = L"xyz"; + str2 = L""; + test(is_equal(str1, str2), false); + + str1 = L"xyz"; + str2 = L"xYz"; + test(is_equal(str1, str2), false); + + str1 = L"xYz"; + str2 = L"xyz"; + test(is_equal(str1, str2), false); + + str1 = L"abcxyz"; + str2 = L"abc"; + test(is_equal(str1, str2), false); + + str1 = L"abc"; + str2 = L"abcxyz"; + test(is_equal(str1, str2), false); + + str1 = L"xyzabc"; + str2 = L"abc"; + test(is_equal(str1, str2), false); + + str1 = L"abc"; + str2 = L"xyzabc"; + test(is_equal(str1, str2), false); + + str1 = L"xyz"; + str2 = L"xyz"; + test(is_equal(str1, str2), true); +} + + +void test_text31() +{ + reset_test_counter("is_equal const char*, str1_begin, str1_end, str2"); + + char foo[] = {"ABCDEF"}; + char bar[] = {"ABCDEF"}; + size_t len = sizeof(foo) / sizeof(char) - 1; // minus terminating zero + + test(PT::is_equal(foo, foo + len, bar), true); + test(PT::is_equal(foo, foo + len - 1, bar), false); + + foo[len - 1] = (char)(unsigned char)127; + bar[len - 1] = (char)(unsigned char)128; + test(PT::is_equal(foo, foo + len, bar), false); + + foo[len - 1] = (char)(unsigned char)128; + bar[len - 1] = (char)(unsigned char)127; + test(PT::is_equal(foo, foo + len, bar), false); + + foo[len - 1] = (char)(unsigned char)1; + bar[len - 1] = (char)(unsigned char)255; + test(PT::is_equal(foo, foo + len, bar), false); + + foo[len - 1] = (char)(unsigned char)255; + bar[len - 1] = (char)(unsigned char)1; + test(PT::is_equal(foo, foo + len, bar), false); + + foo[len - 1] = 'f'; + bar[len - 1] = 'f'; + bar[3] = 'X'; + test(PT::is_equal(foo, foo + len, bar), false); + foo[3] = 'A'; + test(PT::is_equal(foo, foo + len, bar), false); + + foo[3] = '1'; + bar[3] = '1'; + test(PT::is_equal(foo, foo + len, bar), true); +} + + +void test_text32() +{ + reset_test_counter("is_equal const wchar_t*, str1_begin, str1_end, str2"); + + wchar_t foo[] = {L"ABCDEF"}; + wchar_t bar[] = {L"ABCDEF"}; + size_t len = sizeof(foo) / sizeof(wchar_t) - 1; // minus terminating zero + + test(PT::is_equal(foo, foo + len, bar), true); + test(PT::is_equal(foo, foo + len - 1, bar), false); + + foo[len - 1] = (wchar_t)127; + bar[len - 1] = (wchar_t)128; + test(PT::is_equal(foo, foo + len, bar), false); + + foo[len - 1] = (wchar_t)128; + bar[len - 1] = (wchar_t)127; + test(PT::is_equal(foo, foo + len, bar), false); + + foo[len - 1] = (wchar_t)1; + bar[len - 1] = (wchar_t)255; + test(PT::is_equal(foo, foo + len, bar), false); + + foo[len - 1] = (wchar_t)255; + bar[len - 1] = (wchar_t)1; + test(PT::is_equal(foo, foo + len, bar), false); + + foo[len - 1] = L'f'; + bar[len - 1] = L'f'; + bar[3] = L'X'; + test(PT::is_equal(foo, foo + len, bar), false); + foo[3] = L'A'; + test(PT::is_equal(foo, foo + len, bar), false); + + foo[3] = L'1'; + bar[3] = L'1'; + test(PT::is_equal(foo, foo + len, bar), true); +} + + + +void test_text33() +{ + reset_test_counter("is_equal_nc char *"); + + test(is_equal_nc("", ""), true); + test(is_equal_nc("", "abc"), false); + test(is_equal_nc("abc", ""), false); + test(is_equal_nc("abc", "abc"), true); + test(is_equal_nc("aBc", "aBc"), true); + test(is_equal_nc("aBc", "abc"), true); + test(is_equal_nc("abc", "aBc"), true); + test(is_equal_nc("abc", "defgh"), false); + test(is_equal_nc("defgh", "abc"), false); +} + +void test_text34() +{ + reset_test_counter("is_equal_nc wchar_t *"); + + test(is_equal_nc(L"", L""), true); + test(is_equal_nc(L"", L"abc"), false); + test(is_equal_nc(L"abc", L""), false); + test(is_equal_nc(L"abc", L"abc"), true); + test(is_equal_nc(L"aBc", L"aBc"), true); + test(is_equal_nc(L"aBc", L"abc"), true); + test(is_equal_nc(L"abc", L"aBc"), true); + test(is_equal_nc(L"abc", L"defgh"), false); + test(is_equal_nc(L"defgh", L"abc"), false); +} + +void test_text35() +{ + reset_test_counter("is_equal_nc std::string"); + + std::string str1, str2; + test(is_equal_nc(str1, str2), true); + + str2 = "xyz"; + test(is_equal_nc(str1, str2), false); + + str1 = "xyz"; + str2 = ""; + test(is_equal_nc(str1, str2), false); + + str1 = "xyz"; + str2 = "xYz"; + test(is_equal_nc(str1, str2), true); + + str1 = "xYz"; + str2 = "xyz"; + test(is_equal_nc(str1, str2), true); + + str1 = "abcxyz"; + str2 = "abc"; + test(is_equal_nc(str1, str2), false); + + str1 = "abc"; + str2 = "abcxyz"; + test(is_equal_nc(str1, str2), false); + + str1 = "xyzabc"; + str2 = "abc"; + test(is_equal_nc(str1, str2), false); + + str1 = "abc"; + str2 = "xyzabc"; + test(is_equal_nc(str1, str2), false); + + str1 = "xyz"; + str2 = "xyz"; + test(is_equal_nc(str1, str2), true); +} + + +void test_text36() +{ + reset_test_counter("is_equal_nc std::wstring"); + + std::wstring str1, str2; + test(is_equal_nc(str1, str2), true); + + str2 = L"xyz"; + test(is_equal_nc(str1, str2), false); + + str1 = L"xyz"; + str2 = L""; + test(is_equal_nc(str1, str2), false); + + str1 = L"xyz"; + str2 = L"xYz"; + test(is_equal_nc(str1, str2), true); + + str1 = L"xYz"; + str2 = L"xyz"; + test(is_equal_nc(str1, str2), true); + + str1 = L"abcxyz"; + str2 = L"abc"; + test(is_equal_nc(str1, str2), false); + + str1 = L"abc"; + str2 = L"abcxyz"; + test(is_equal_nc(str1, str2), false); + + str1 = L"xyzabc"; + str2 = L"abc"; + test(is_equal_nc(str1, str2), false); + + str1 = L"abc"; + str2 = L"xyzabc"; + test(is_equal_nc(str1, str2), false); + + str1 = L"xyz"; + str2 = L"xyz"; + test(is_equal_nc(str1, str2), true); +} + + +void test_text37() +{ + reset_test_counter("is_equal_nc const char*, str1_begin, str1_end, str2"); + + char foo[] = {"ABCDEF"}; + char bar[] = {"ABCDEF"}; + size_t len = sizeof(foo) / sizeof(char) - 1; // minus terminating zero + + test(PT::is_equal_nc(foo, foo + len, bar), true); + test(PT::is_equal_nc(foo, foo + len - 1, bar), false); + + foo[len - 1] = (char)(unsigned char)127; + bar[len - 1] = (char)(unsigned char)128; + test(PT::is_equal_nc(foo, foo + len, bar), false); + + foo[len - 1] = (char)(unsigned char)128; + bar[len - 1] = (char)(unsigned char)127; + test(PT::is_equal_nc(foo, foo + len, bar), false); + + foo[len - 1] = (char)(unsigned char)1; + bar[len - 1] = (char)(unsigned char)255; + test(PT::is_equal_nc(foo, foo + len, bar), false); + + foo[len - 1] = (char)(unsigned char)255; + bar[len - 1] = (char)(unsigned char)1; + test(PT::is_equal_nc(foo, foo + len, bar), false); + + foo[len - 1] = 'f'; + bar[len - 1] = 'f'; + bar[3] = 'X'; + test(PT::is_equal_nc(foo, foo + len, bar), false); + foo[3] = 'A'; + test(PT::is_equal_nc(foo, foo + len, bar), false); + + foo[3] = '1'; + bar[3] = '1'; + test(PT::is_equal_nc(foo, foo + len, bar), true); + + foo[3] = 'h'; + bar[3] = 'H'; + test(PT::is_equal_nc(foo, foo + len, bar), true); + + foo[3] = 'H'; + bar[3] = 'h'; + test(PT::is_equal_nc(foo, foo + len, bar), true); +} + + +void test_text38() +{ + reset_test_counter("is_equal_nc const wchar_t*, str1_begin, str1_end, str2"); + + wchar_t foo[] = {L"ABCDEF"}; + wchar_t bar[] = {L"ABCDEF"}; + size_t len = sizeof(foo) / sizeof(wchar_t) - 1; // minus terminating zero + + test(PT::is_equal_nc(foo, foo + len, bar), true); + test(PT::is_equal_nc(foo, foo + len - 1, bar), false); + + foo[len - 1] = (wchar_t)127; + bar[len - 1] = (wchar_t)128; + test(PT::is_equal_nc(foo, foo + len, bar), false); + + foo[len - 1] = (wchar_t)128; + bar[len - 1] = (wchar_t)127; + test(PT::is_equal_nc(foo, foo + len, bar), false); + + foo[len - 1] = (wchar_t)1; + bar[len - 1] = (wchar_t)255; + test(PT::is_equal_nc(foo, foo + len, bar), false); + + foo[len - 1] = (wchar_t)255; + bar[len - 1] = (wchar_t)1; + test(PT::is_equal_nc(foo, foo + len, bar), false); + + foo[len - 1] = L'f'; + bar[len - 1] = L'f'; + bar[3] = L'X'; + test(PT::is_equal_nc(foo, foo + len, bar), false); + foo[3] = L'A'; + test(PT::is_equal_nc(foo, foo + len, bar), false); + + foo[3] = L'1'; + bar[3] = L'1'; + test(PT::is_equal_nc(foo, foo + len, bar), true); + + foo[3] = L'h'; + bar[3] = L'H'; + test(PT::is_equal_nc(foo, foo + len, bar), true); + + foo[3] = L'H'; + bar[3] = L'h'; + test(PT::is_equal_nc(foo, foo + len, bar), true); +} + + +void test_text39() +{ + reset_test_counter("is_substr const char *"); + + test(PT::is_substr("", ""), true); + test(PT::is_substr("", "a"), true); + test(PT::is_substr("a", ""), false); + test(PT::is_substr("a", "a"), true); + test(PT::is_substr("a", "ab"), true); + test(PT::is_substr("abc", "abb"), false); + test(PT::is_substr("abc", "abcd"), true); + test(PT::is_substr("XYZ", "XYZabc"), true); + test(PT::is_substr("XYZ", "xYz"), false); + test(PT::is_substr("hello world", "hello world"), true); + test(PT::is_substr("hello world", "abc hello world"), false); + test(PT::is_substr("hello world", "hello worldabc"), true); + test(PT::is_substr("Hello World", "hello world"), false); + test(PT::is_substr("hello world", "Hello World"), false); +} + + +void test_text40() +{ + reset_test_counter("is_substr const wchar_t *"); + + test(PT::is_substr(L"", L""), true); + test(PT::is_substr(L"", L"a"), true); + test(PT::is_substr(L"a", L""), false); + test(PT::is_substr(L"a", L"a"), true); + test(PT::is_substr(L"a", L"ab"), true); + test(PT::is_substr(L"abc", L"abb"), false); + test(PT::is_substr(L"abc", L"abcd"), true); + test(PT::is_substr(L"XYZ", L"XYZabc"), true); + test(PT::is_substr(L"XYZ", L"xYz"), false); + test(PT::is_substr(L"hello world", L"hello world"), true); + test(PT::is_substr(L"hello world", L"abc hello world"), false); + test(PT::is_substr(L"hello world", L"hello worldabc"), true); + test(PT::is_substr(L"Hello World", L"hello world"), false); + test(PT::is_substr(L"hello world", L"Hello World"), false); +} + + + +void test_text41() +{ + reset_test_counter("is_substr std::string"); + + std::string str1, str2; + test(PT::is_substr(str1, str2), true); + + str1 = ""; + str2 = "a"; + test(PT::is_substr(str1, str2), true); + + str1 = "a"; + str2 = "a"; + test(PT::is_substr(str1, str2), true); + + str1 = "a"; + str2 = ""; + test(PT::is_substr(str1, str2), false); + + str1 = "abcd"; + str2 = "abcd"; + test(PT::is_substr(str1, str2), true); + + str1 = "abcdefg"; + str2 = "abcd"; + test(PT::is_substr(str1, str2), false); + + str1 = "abcd"; + str2 = "abcdefg"; + test(PT::is_substr(str1, str2), true); + + str1 = "aBCd"; + str2 = "abcd"; + test(PT::is_substr(str1, str2), false); + + str1 = "abcd"; + str2 = "aBCd"; + test(PT::is_substr(str1, str2), false); + + str1 = "aBCdefg"; + str2 = "abcd"; + test(PT::is_substr(str1, str2), false); + + str1 = "aBCd"; + str2 = "abcdefg"; + test(PT::is_substr(str1, str2), false); + + str1 = "abcd"; + str2 = "aBCdefg"; + test(PT::is_substr(str1, str2), false); +} + + +void test_text42() +{ + reset_test_counter("is_substr std::wstring"); + + std::wstring str1, str2; + test(PT::is_substr(str1, str2), true); + + str1 = L""; + str2 = L"a"; + test(PT::is_substr(str1, str2), true); + + str1 = L"a"; + str2 = L"a"; + test(PT::is_substr(str1, str2), true); + + str1 = L"a"; + str2 = L""; + test(PT::is_substr(str1, str2), false); + + str1 = L"abcd"; + str2 = L"abcd"; + test(PT::is_substr(str1, str2), true); + + str1 = L"abcdefg"; + str2 = L"abcd"; + test(PT::is_substr(str1, str2), false); + + str1 = L"abcd"; + str2 = L"abcdefg"; + test(PT::is_substr(str1, str2), true); + + str1 = L"aBCd"; + str2 = L"abcd"; + test(PT::is_substr(str1, str2), false); + + str1 = L"abcd"; + str2 = L"aBCd"; + test(PT::is_substr(str1, str2), false); + + str1 = L"aBCdefg"; + str2 = L"abcd"; + test(PT::is_substr(str1, str2), false); + + str1 = L"aBCd"; + str2 = L"abcdefg"; + test(PT::is_substr(str1, str2), false); + + str1 = L"abcd"; + str2 = L"aBCdefg"; + test(PT::is_substr(str1, str2), false); +} + + + +void test_text43() +{ + reset_test_counter("is_substr_nc const char *"); + + test(PT::is_substr_nc("", ""), true); + test(PT::is_substr_nc("", "a"), true); + test(PT::is_substr_nc("a", ""), false); + test(PT::is_substr_nc("a", "a"), true); + test(PT::is_substr_nc("a", "ab"), true); + test(PT::is_substr_nc("abc", "abb"), false); + test(PT::is_substr_nc("abc", "abcd"), true); + test(PT::is_substr_nc("XYZ", "XYZabc"), true); + test(PT::is_substr_nc("XYZ", "xYz"), true); + test(PT::is_substr_nc("hello world", "hello world"), true); + test(PT::is_substr_nc("hello world", "abc hello world"), false); + test(PT::is_substr_nc("hello world", "hello worldabc"), true); + test(PT::is_substr_nc("Hello World", "hello world"), true); + test(PT::is_substr_nc("hello world", "Hello World"), true); +} + + +void test_text44() +{ + reset_test_counter("is_substr_nc const wchar_t *"); + + test(PT::is_substr_nc(L"", L""), true); + test(PT::is_substr_nc(L"", L"a"), true); + test(PT::is_substr_nc(L"a", L""), false); + test(PT::is_substr_nc(L"a", L"a"), true); + test(PT::is_substr_nc(L"a", L"ab"), true); + test(PT::is_substr_nc(L"abc", L"abb"), false); + test(PT::is_substr_nc(L"abc", L"abcd"), true); + test(PT::is_substr_nc(L"XYZ", L"XYZabc"), true); + test(PT::is_substr_nc(L"XYZ", L"xYz"), true); + test(PT::is_substr_nc(L"hello world", L"hello world"), true); + test(PT::is_substr_nc(L"hello world", L"abc hello world"), false); + test(PT::is_substr_nc(L"hello world", L"hello worldabc"), true); + test(PT::is_substr_nc(L"Hello World", L"hello world"), true); + test(PT::is_substr_nc(L"hello world", L"Hello World"), true); +} + + + +void test_text45() +{ + reset_test_counter("is_substr_nc std::string"); + + std::string str1, str2; + test(PT::is_substr_nc(str1, str2), true); + + str1 = ""; + str2 = "a"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = "a"; + str2 = "a"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = "a"; + str2 = ""; + test(PT::is_substr_nc(str1, str2), false); + + str1 = "abcd"; + str2 = "abcd"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = "abcdefg"; + str2 = "abcd"; + test(PT::is_substr_nc(str1, str2), false); + + str1 = "abcd"; + str2 = "abcdefg"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = "aBCd"; + str2 = "abcd"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = "abcd"; + str2 = "aBCd"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = "aBCdefg"; + str2 = "abcd"; + test(PT::is_substr_nc(str1, str2), false); + + str1 = "aBCd"; + str2 = "abcdefg"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = "abcd"; + str2 = "aBCdefg"; + test(PT::is_substr_nc(str1, str2), true); +} + + + +void test_text46() +{ + reset_test_counter("is_substr_nc std::wstring"); + + std::wstring str1, str2; + test(PT::is_substr_nc(str1, str2), true); + + str1 = L""; + str2 = L"a"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = L"a"; + str2 = L"a"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = L"a"; + str2 = L""; + test(PT::is_substr_nc(str1, str2), false); + + str1 = L"abcd"; + str2 = L"abcd"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = L"abcdefg"; + str2 = L"abcd"; + test(PT::is_substr_nc(str1, str2), false); + + str1 = L"abcd"; + str2 = L"abcdefg"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = L"aBCd"; + str2 = L"abcd"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = L"abcd"; + str2 = L"aBCd"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = L"aBCdefg"; + str2 = L"abcd"; + test(PT::is_substr_nc(str1, str2), false); + + str1 = L"aBCd"; + str2 = L"abcdefg"; + test(PT::is_substr_nc(str1, str2), true); + + str1 = L"abcd"; + str2 = L"aBCdefg"; + test(PT::is_substr_nc(str1, str2), true); +} + + + + +void make_tests() +{ + test_text1(); + test_text2(); + test_text3(); + test_text4(); + test_text5(); + test_text6(); + test_text7(); + test_text8(); + test_text9(); + test_text10(); + test_text11(); + test_text12(); + test_text13(); + test_text14(); + test_text15(); + test_text16(); + test_text17(); + test_text18(); + test_text19(); + test_text20(); + test_text21(); + test_text22(); + test_text23(); + test_text24(); + test_text25(); + test_text26(); + test_text27(); + test_text28(); + test_text29(); + test_text30(); + test_text31(); + test_text32(); + test_text33(); + test_text34(); + test_text35(); + test_text36(); + test_text37(); + test_text38(); + test_text39(); + test_text40(); + test_text41(); + test_text42(); + test_text43(); + test_text44(); + test_text45(); + test_text46(); +} + + +} + +} + + diff --git a/tests/convert.h b/tests/convert.h new file mode 100644 index 0000000..431697e --- /dev/null +++ b/tests/convert.h @@ -0,0 +1,61 @@ +/* + * This file is a part of PikoTools + * and is distributed under the (new) BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2021, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name Tomasz Sowa nor the names of contributors to this + * project may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef headerfile_picotools_tests_convert +#define headerfile_picotools_tests_convert + +namespace pt +{ + +namespace pt_convert_tests +{ + + + + + +void make_tests(); + + + + + +} + +} + +#endif diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 0000000..3d5cc58 --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,67 @@ +/* + * This file is a part of PikoTools + * and is distributed under the (new) BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2021, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name Tomasz Sowa nor the names of contributors to this + * project may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "convert.h" +#include + + +namespace pt +{ +bool was_error = false; +int test_counter = 0; +const char * test_msg = nullptr; +} + + +int main() +{ + pt::pt_convert_tests::make_tests(); + + + if( pt::was_error ) + { + std::cout << "some of the tests failed" << std::endl; + } + else + { + std::cout << "*********************************" << std::endl; + std::cout << "* all tests passed successfully *" << std::endl; + std::cout << "*********************************" << std::endl; + } + + return !pt::was_error ? 0 : 1; +} diff --git a/tests/test.cpp b/tests/test.cpp new file mode 100644 index 0000000..2547c1a --- /dev/null +++ b/tests/test.cpp @@ -0,0 +1,110 @@ +/* + * This file is a part of PikoTools + * and is distributed under the (new) BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2021, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name Tomasz Sowa nor the names of contributors to this + * project may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" + + + +namespace pt +{ + + +void reset_test_counter() +{ + test_counter = 1; + test_msg = nullptr; +} + + +void reset_test_counter(const char * msg) +{ + test_counter = 1; + test_msg = msg; +} + + +void test_status(bool status) +{ + if( status ) + { + std::cout << " OK"; + } + else + { + std::cout << " Fail"; + was_error = true; + } + + std::cout << std::endl; +} + + +template<> +bool test(const char * test_msg, const char * provided, const char * expected) +{ + std::cout << "test " << test_counter << ": "; + + if( test_msg ) + std::cout << test_msg; + + bool status = (std::strcmp(provided, expected) == 0); + test_status(status); + test_counter += 1; + + return status; +} + + +template<> +bool test(const char * test_msg, const wchar_t * provided, const wchar_t * expected) +{ + std::cout << "test " << test_counter << ": "; + + if( test_msg ) + std::cout << test_msg; + + bool status = (std::wcscmp(provided, expected) == 0); + test_status(status); + test_counter += 1; + + return status; +} + + +} + + diff --git a/tests/test.h b/tests/test.h new file mode 100644 index 0000000..46d9da2 --- /dev/null +++ b/tests/test.h @@ -0,0 +1,92 @@ +/* + * This file is a part of PikoTools + * and is distributed under the (new) BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2021, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name Tomasz Sowa nor the names of contributors to this + * project may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef headerfile_picotools_tests_test +#define headerfile_picotools_tests_test + +#include +#include + + + +namespace pt +{ +extern int test_counter; +extern const char * test_msg; +extern bool was_error; + + +void test_status(bool status); +void reset_test_counter(); +void reset_test_counter(const char * msg); + + + +template +bool test(const char * test_msg, type_t provided, type_t expected) +{ + std::cout << "test " << test_counter << ": "; + + if( test_msg ) + std::cout << test_msg; + + bool status = provided == expected; + test_status(status); + test_counter += 1; + + return status; +} + + +template +bool test(type_t provided, type_t expected) +{ + return test(test_msg, provided, expected); +} + + +template<> +bool test(const char * test_msg, const char * provided, const char * expected); + +template<> +bool test(const char * test_msg, const wchar_t * provided, const wchar_t * expected); + + + +} + +#endif