Merge pull request #40 from tusharpm/generators_test_windows
Enable generator tests on Windows CI
This commit is contained in:
commit
4959d46eb4
@ -4,6 +4,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
|||||||
|
|
||||||
option(UUID_BUILD_TESTS "Build the unit tests" ON)
|
option(UUID_BUILD_TESTS "Build the unit tests" ON)
|
||||||
option(UUID_SYSTEM_GENERATOR "Enable operating system uuid generator" OFF)
|
option(UUID_SYSTEM_GENERATOR "Enable operating system uuid generator" OFF)
|
||||||
|
option(UUID_TIME_GENERATOR "Enable experimental time-based uuid generator" OFF)
|
||||||
option(UUID_USING_CXX20_SPAN "Using span from std instead of gsl" OFF)
|
option(UUID_USING_CXX20_SPAN "Using span from std instead of gsl" OFF)
|
||||||
|
|
||||||
# Library target
|
# Library target
|
||||||
@ -29,6 +30,11 @@ if (UUID_SYSTEM_GENERATOR)
|
|||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
# Using time-based generator
|
||||||
|
if (UUID_TIME_GENERATOR)
|
||||||
|
target_compile_definitions(${PROJECT_NAME} INTERFACE UUID_TIME_GENERATOR)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Using span from std
|
# Using span from std
|
||||||
if (NOT UUID_USING_CXX20_SPAN)
|
if (NOT UUID_USING_CXX20_SPAN)
|
||||||
target_include_directories(${PROJECT_NAME} INTERFACE
|
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||||
|
|||||||
@ -9,13 +9,14 @@ environment:
|
|||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||||
CMAKE_GENERATOR: Visual Studio 15 2017
|
CMAKE_GENERATOR: Visual Studio 15 2017
|
||||||
CMAKE_GENERATOR_PLATFORM: x64
|
CMAKE_GENERATOR_PLATFORM: x64
|
||||||
|
CMAKE_CLI_FLAGS: -DUUID_SYSTEM_GENERATOR=ON -DUUID_TIME_GENERATOR=ON
|
||||||
|
|
||||||
init:
|
init:
|
||||||
- cmake --version
|
- cmake --version
|
||||||
- msbuild /version
|
- msbuild /version
|
||||||
|
|
||||||
before_build:
|
before_build:
|
||||||
- cmake -S . -B build
|
- cmake %CMAKE_CLI_FLAGS% -S . -B build
|
||||||
- cd build
|
- cd build
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
|
|||||||
@ -17,23 +17,16 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
|
||||||
#if defined(UUID_TIME_GENERATOR) || defined(UUID_SYSTEM_GENERATOR)
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#endif
|
|
||||||
#ifndef NOMINMAX
|
|
||||||
#define NOMINMAX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef UUID_SYSTEM_GENERATOR
|
#ifdef UUID_SYSTEM_GENERATOR
|
||||||
#include <objbase.h>
|
#include <objbase.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <windows.h>
|
#ifdef UUID_TIME_GENERATOR
|
||||||
#include <intrin.h>
|
|
||||||
#include <iphlpapi.h>
|
#include <iphlpapi.h>
|
||||||
#pragma comment(lib, "IPHLPAPI.lib")
|
#pragma comment(lib, "IPHLPAPI.lib")
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(__linux__) || defined(__unix__)
|
#elif defined(__linux__) || defined(__unix__)
|
||||||
|
|
||||||
@ -47,7 +40,6 @@
|
|||||||
#include <CoreFoundation/CFUUID.h>
|
#include <CoreFoundation/CFUUID.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace uuids
|
namespace uuids
|
||||||
@ -278,10 +270,6 @@ namespace uuids
|
|||||||
size_t m_blockByteIndex;
|
size_t m_blockByteIndex;
|
||||||
size_t m_byteCount;
|
size_t m_byteCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::mt19937 clock_gen(std::random_device{}());
|
|
||||||
static std::uniform_int_distribution<short> clock_dis{ -32768, 32767 };
|
|
||||||
static std::atomic_short clock_sequence = clock_dis(clock_gen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -847,11 +835,15 @@ namespace uuids
|
|||||||
return ns / 100;
|
return ns / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
static unsigned short get_clock_sequence()
|
||||||
uuid_time_generator()
|
|
||||||
{
|
{
|
||||||
|
static std::mt19937 clock_gen(std::random_device{}());
|
||||||
|
static std::uniform_int_distribution<unsigned short> clock_dis;
|
||||||
|
static std::atomic_ushort clock_sequence = clock_dis(clock_gen);
|
||||||
|
return clock_sequence++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
uuid operator()()
|
uuid operator()()
|
||||||
{
|
{
|
||||||
if (get_mac_address())
|
if (get_mac_address())
|
||||||
@ -860,25 +852,22 @@ namespace uuids
|
|||||||
|
|
||||||
auto tm = get_time_intervals();
|
auto tm = get_time_intervals();
|
||||||
|
|
||||||
short clock_seq = detail::clock_sequence++;
|
auto clock_seq = get_clock_sequence();
|
||||||
|
|
||||||
clock_seq &= 0x3FFF;
|
|
||||||
|
|
||||||
auto ptm = reinterpret_cast<uuids::uuid::value_type*>(&tm);
|
auto ptm = reinterpret_cast<uuids::uuid::value_type*>(&tm);
|
||||||
ptm[0] &= 0x0F;
|
|
||||||
|
|
||||||
memcpy(&data[0], ptm + 4, 4);
|
memcpy(&data[0], ptm + 4, 4);
|
||||||
memcpy(&data[4], ptm + 2, 2);
|
memcpy(&data[4], ptm + 2, 2);
|
||||||
memcpy(&data[6], ptm, 2);
|
memcpy(&data[6], ptm, 2);
|
||||||
|
|
||||||
memcpy(&data[8], reinterpret_cast<uuids::uuid::value_type*>(&clock_seq), 2);
|
memcpy(&data[8], &clock_seq, 2);
|
||||||
|
|
||||||
// variant must be 0b10xxxxxx
|
// variant must be 0b10xxxxxx
|
||||||
data[8] &= 0xBF;
|
data[8] &= 0xBF;
|
||||||
data[8] |= 0x80;
|
data[8] |= 0x80;
|
||||||
|
|
||||||
// version must be 0b0001xxxx
|
// version must be 0b0001xxxx
|
||||||
data[6] &= 0x5F;
|
data[6] &= 0x1F;
|
||||||
data[6] |= 0x10;
|
data[6] |= 0x10;
|
||||||
|
|
||||||
memcpy(&data[10], &device_address.value()[0], 6);
|
memcpy(&data[10], &device_address.value()[0], 6);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user