diff --git a/test/bin/premake5 b/test/bin/premake5 new file mode 100644 index 0000000..8adb8d5 Binary files /dev/null and b/test/bin/premake5 differ diff --git a/test/bin/premake5.exe b/test/bin/premake5.exe new file mode 100644 index 0000000..ebe7ae7 Binary files /dev/null and b/test/bin/premake5.exe differ diff --git a/test/create_project.bat b/test/create_project.bat new file mode 100644 index 0000000..ec5e402 --- /dev/null +++ b/test/create_project.bat @@ -0,0 +1,28 @@ +@ECHO OFF + +ECHO Select the type of project you would like to create: +ECHO 1. Visual Studio 2017 Solution +ECHO 2. Visual Studio 2015 Solution +ECHO 3. GNU Makefile + +CHOICE /N /C:123 /M "[1-3]:" + +IF ERRORLEVEL ==3 GOTO THREE +IF ERRORLEVEL ==2 GOTO TWO +IF ERRORLEVEL ==1 GOTO ONE +GOTO END + +:THREE + ECHO Creating GNU Makefile... + bin\premake5.exe gmake + GOTO END +:TWO + ECHO Creating VS2015 Project... + bin\premake5.exe vs2015 + GOTO END +:ONE + ECHO Creating VS2017 Project... + bin\premake5.exe vs2017 + GOTO END + +:END diff --git a/test/create_project.sh b/test/create_project.sh new file mode 100644 index 0000000..ac3558b --- /dev/null +++ b/test/create_project.sh @@ -0,0 +1,39 @@ +# prompt user of no option given on the command line +if [[ $1 ]] ; then + ACTION=$1 +else + echo "Select the type of project you would like to create:" + echo "1. GNU Makefile" + echo "2. Visual Studio 2015 Solution" + echo "3. CodeLite" + read -p "[1-4] " -n 1 -r + echo + ACTION=$REPLY +fi + +if [ $OSTYPE == "msys" ]; then # Windows, MingW + PREMAKE=bin/premake/premake5.exe +else + PREMAKE=bin/premake/premake5 +fi + +# parse string actions into numerics +if [[ $ACTION == "make" ]] || [[ $ACTION == "gmake" ]] ; then + ACTION="1" +elif [[ $ACTION == "codelite" ]] ; then + ACTION="3" +fi + +# perform action +if [[ $ACTION == "1" ]] ; then + echo "Creating GNU Makefile..." + $PREMAKE gmake +elif [[ $ACTION == "2" ]] ; then + echo "Creating VS2015 Project..." + $PREMAKE vs2015 +elif [[ $ACTION == "3" ]] ; then + echo "Creating CodeLite project..." + $PREMAKE codelite +else + echo "Invalid input: "$REPLY +fi diff --git a/test/premake5.lua b/test/premake5.lua new file mode 100644 index 0000000..f062053 --- /dev/null +++ b/test/premake5.lua @@ -0,0 +1,22 @@ +solution "slice" + configurations { "Debug", "Release" } + platforms { "x64", "x86" } --, "Clang" } + + project "slice" + kind "ConsoleApp" + language "C++" + + files { "../include/**", "src/**" } + + includedirs { "../include" } + + filter { "configurations:Debug*" } + defines { "_DEBUG" } + optimize "Off" + symbols "On" + + filter { "configurations:Release*" } + defines { "NDEBUG" } + optimize "Full" + symbols "On" + flags { "NoFramePointer", "NoBufferSecurityCheck" } diff --git a/test/src/test.cpp b/test/src/test.cpp new file mode 100644 index 0000000..1afe4d7 --- /dev/null +++ b/test/src/test.cpp @@ -0,0 +1,130 @@ +#include "sharedarray.h" + +using namespace beautifulcode; + +constexpr int constexpr_data[] = { 1, 2, 3 }; + +void test_slice() +{ + Slice slice({ 1, 2, 3 }); + assert(slice.length == 3); + + + // --- test constexpr --- + + // static_assert(Slice(nullptr).length == 0, "!!!"); // TODO: VS2017 fails on this code! + static_assert(Slice().length == 0, "!!!"); + static_assert(Slice(constexpr_data, 10).length == 10, "!!!"); + static_assert(Slice(constexpr_data).length == 3, "!!!"); + static_assert(Slice(Slice(constexpr_data).slice(0, 1)).length == 1, "!!!"); + static_assert(Slice(constexpr_data).front() == 1, "!!!"); + static_assert(Slice(constexpr_data).back() == 3, "!!!"); + static_assert(Slice(constexpr_data) == Slice(constexpr_data), "!!!"); + // static_assert(Slice(constexpr_data).eq(Slice(constexpr_data)), "!!!"); +} + +void test_string() +{ + const char *pstr = "hello"; + String str(pstr); + assert(str.length == 5); + + // --- test STL --- + std::string s("hello"); + String stl(s); + assert(stl.eq("hello")); + +} + +void test_array() +{ + + // --- test parsing --- + + assert(String("10").parse_int() == 10); + assert(String("0x10").parse_int(true) == 16); + assert(String("$10").parse_int(true) == 16); + assert(String("b10").parse_int(true) == 2); + assert(String("777").parse_int<8>() == 0x1FF); + assert(String("1.5").parse_float() == 1.5); + assert(String("1.5e+3").parse_float() == 1500.0); + assert(String("1.5E-3").parse_float() == 0.0015); +} + +void test_mutablestring() +{ + + // --- test unicode transcoding --- + + MutableString<> ms1("hello"); + MutableString<> ms2(u8"日本語"); + MutableString<> ms3(L"日本語"); + MutableString<> ms4(u"日本語"); + MutableString<> ms5(U"日本語"); + + MutableWString<> mu1("hello"); + MutableWString<> mu2(u8"日本語"); + MutableWString<> mu3(L"日本語"); + MutableWString<> mu4(u"日本語"); + MutableWString<> mu5(U"日本語"); + + MutableDString<> mU1("hello"); + MutableDString<> mU2(u8"日本語"); + MutableDString<> mU3(L"日本語"); + MutableDString<> mU4(u"日本語"); + MutableDString<> mU5(U"日本語"); + + MutableString<> test(Concat, "hello", mU3, 'a', U'日', L'ö', L"löewe"); + Array test2(Concat, "hello", mU3, 'a', U'日', L'ö', L"löewe"); + Array test3(Concat, "hello", mU3, 'a', U'日', L'ö', L"löewe"); + MutableDString<> test4 = test; + + MutableString<> test5(Sprintf, "hey %d %s %ls", 10, "joe", L"king"); + MutableWString<> test7(Sprintf, "hey %d %s %ls", 10, "joe", L"king"); +#if defined(_MSC_VER) + MutableString<> test6(Sprintf, L"hey %d %S %ls", 10, "joe", L"king"); + MutableWString<> test8(Sprintf, L"hey %d %S %ls", 10, "joe", L"king"); +#else + MutableString<> test6(Sprintf, L"hey %d %s %ls", 10, "joe", L"king"); + MutableWString<> test8(Sprintf, L"hey %d %s %ls", 10, "joe", L"king"); +#endif + + test7.append(U'日', 'a', mU2); + + // --- test URL encode/decode --- + test6.url_decode(String("something%2B!+%E6%97%A5%E6%9C%AC%E8%AA%9E+l%C3%B6ewe")); + assert(test6.eq(u8"something+! 日本語 löewe")); + test6.url_decode(Slice(L"something%2B!+%E6%97%A5%E6%9C%AC%E8%AA%9E+l%C3%B6ewe")); + assert(test6.eq(u8"something+! 日本語 löewe")); + test7.url_decode(String("something%2B!+%E6%97%A5%E6%9C%AC%E8%AA%9E+l%C3%B6ewe")); + assert(test7.eq(u"something+! 日本語 löewe")); + test7.url_decode(DString(U"something%2B!+%E6%97%A5%E6%9C%AC%E8%AA%9E+l%C3%B6ewe")); + assert(test7.eq(u"something+! 日本語 löewe")); + + test6.url_encode(test7); + assert(test6.eq("something%2B%21+%E6%97%A5%E6%9C%AC%E8%AA%9E+l%C3%B6ewe")); +} + +void test_sharedarray() +{ + // -- test claiming single-ref --- + SharedArray sa = { 1, 2, 3 }; + int *p = sa.ptr; + Array claimed = sa.claim(); + assert(claimed.ptr == p && sa.ptr == nullptr); +} + +void test_sharedstring() +{ + +} + +void main() +{ + test_slice(); + test_string(); + test_array(); + test_mutablestring(); + test_sharedarray(); + test_sharedstring(); +}