diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8d41bf4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.7.0) +project(test_uuid) + + +if (UNIX) + message(status "Setting GCC flags") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -fexceptions -g -Wall") +else() + message(status "Setting MSVC flags") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHc /std:c++latest") +endif() +message(status "** CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") + +include_directories(${CMAKE_SOURCE_DIR}/include) + +file(GLOB headers ${CMAKE_SOURCE_DIR}/include/*.h) +file(GLOB SOURCES "test/*.cpp" "include/*.cpp") + +add_executable(test_uuid ${SOURCES} ${headers}) diff --git a/src/uuid.cpp b/include/uuid.cpp similarity index 100% rename from src/uuid.cpp rename to include/uuid.cpp diff --git a/src/uuid.h b/include/uuid.h similarity index 100% rename from src/uuid.h rename to include/uuid.h diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..51683dd --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,99 @@ +#include "..\include\uuid.h" +#include +#include + +int main() +{ + using namespace uuids; + + { + std::cout << "Test nill" << std::endl; + + uuid empty; + assert(empty.is_nil()); + assert(empty.size() == 16); + } + + { + std::cout << "Test make" << std::endl; + + uuid const guid = uuids::make_uuid(); + assert(!guid.is_nil()); + assert(guid.size() == 16); + assert(guid.version() == uuids::version_type::random_number_based); + assert(guid.variant() == uuids::variant_type::rfc); + } + + { + std::cout << "Test comparison" << std::endl; + + uuid empty; + uuid guid = uuids::make_uuid(); + + assert(empty == empty); + assert(guid == guid); + assert(empty != guid); + } + + { + std::cout << "Test swap" << std::endl; + + uuid empty; + uuid guid = uuids::make_uuid(); + + assert(empty.is_nil()); + assert(!guid.is_nil()); + + std::swap(empty, guid); + + assert(!empty.is_nil()); + assert(guid.is_nil()); + + empty.swap(guid); + + assert(empty.is_nil()); + assert(!guid.is_nil()); + } + + { + std::cout << "Test string conversion" << std::endl; + + uuid empty; + assert(empty.string() == "00000000-0000-0000-0000-000000000000"); + assert(empty.wstring() == L"00000000-0000-0000-0000-000000000000"); + } + + { + std::cout << "Test string constructor" << std::endl; + + using namespace std::string_literals; + + auto str = "47183823-2574-4bfd-b411-99ed177d3e43"s; + uuid guid(str); + assert(guid.string() == str); + } + + { + std::cout << "Test wstring constructor" << std::endl; + + using namespace std::string_literals; + + auto str = L"47183823-2574-4bfd-b411-99ed177d3e43"s; + uuid guid(str); + assert(guid.wstring() == str); + } + + { + std::cout << "Test constexpr" << std::endl; + + constexpr uuid empty; + constexpr bool isnil = empty.is_nil(); + constexpr size_t size = empty.size(); + constexpr uuids::variant_type variant = empty.variant(); + constexpr uuids::version_type version = empty.version(); + } + + std::cout << "ALL PASSED" << std::endl; + + return 0; +} diff --git a/test/test_win/.gitignore b/test/test_win/.gitignore deleted file mode 100644 index 02032ac..0000000 --- a/test/test_win/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.vs -Debug -Release diff --git a/test/test_win/test_win.cpp b/test/test_win/test_win.cpp deleted file mode 100644 index 47cdec8..0000000 Binary files a/test/test_win/test_win.cpp and /dev/null differ diff --git a/test/test_win/test_win.sln b/test/test_win/test_win.sln deleted file mode 100644 index 06d07b1..0000000 --- a/test/test_win/test_win.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27004.2010 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_win", "test_win.vcxproj", "{380B7F43-F7E1-4847-960B-978D0DD1E268}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {380B7F43-F7E1-4847-960B-978D0DD1E268}.Debug|x64.ActiveCfg = Debug|x64 - {380B7F43-F7E1-4847-960B-978D0DD1E268}.Debug|x64.Build.0 = Debug|x64 - {380B7F43-F7E1-4847-960B-978D0DD1E268}.Debug|x86.ActiveCfg = Debug|Win32 - {380B7F43-F7E1-4847-960B-978D0DD1E268}.Debug|x86.Build.0 = Debug|Win32 - {380B7F43-F7E1-4847-960B-978D0DD1E268}.Release|x64.ActiveCfg = Release|x64 - {380B7F43-F7E1-4847-960B-978D0DD1E268}.Release|x64.Build.0 = Release|x64 - {380B7F43-F7E1-4847-960B-978D0DD1E268}.Release|x86.ActiveCfg = Release|Win32 - {380B7F43-F7E1-4847-960B-978D0DD1E268}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {78BC8B73-C809-4F3C-9000-66F27E2F5E07} - EndGlobalSection -EndGlobal diff --git a/test/test_win/test_win.vcxproj b/test/test_win/test_win.vcxproj deleted file mode 100644 index 1fe8cc1..0000000 --- a/test/test_win/test_win.vcxproj +++ /dev/null @@ -1,159 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {380B7F43-F7E1-4847-960B-978D0DD1E268} - Win32Proj - testwin - 10.0.16299.0 - - - - Application - true - v141 - Unicode - - - Application - false - v141 - true - Unicode - - - Application - true - v141 - Unicode - - - Application - false - v141 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - true - - - false - - - false - - - - NotUsing - Level3 - Disabled - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - stdcpplatest - - - Console - true - - - - - NotUsing - Level3 - Disabled - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - stdcpplatest - - - Console - true - - - - - NotUsing - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - stdcpplatest - - - Console - true - true - true - - - - - NotUsing - Level3 - MaxSpeed - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - stdcpplatest - - - Console - true - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/test_win/test_win.vcxproj.filters b/test/test_win/test_win.vcxproj.filters deleted file mode 100644 index cc90555..0000000 --- a/test/test_win/test_win.vcxproj.filters +++ /dev/null @@ -1,30 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/test/test_win/test_win.vcxproj.user b/test/test_win/test_win.vcxproj.user deleted file mode 100644 index baf2417..0000000 --- a/test/test_win/test_win.vcxproj.user +++ /dev/null @@ -1,6 +0,0 @@ - - - - false - - \ No newline at end of file