diff options
Diffstat (limited to 'src/boost/libs/uuid')
39 files changed, 3122 insertions, 0 deletions
diff --git a/src/boost/libs/uuid/Jamfile b/src/boost/libs/uuid/Jamfile new file mode 100644 index 00000000..1e3698c9 --- /dev/null +++ b/src/boost/libs/uuid/Jamfile @@ -0,0 +1,22 @@ +# Boost.Uuid Library Jamfile +# +# Copyright (c) 2017 James E. King III +# +# Use, modification, and distribution are subject to the +# Boost Software License, Version 1.0. (See accompanying file +# LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) + +project libs/uuid + : requirements + + <warnings>all + + <toolset>clang:<cxxflags>-Wextra + <toolset>clang:<cxxflags>-pedantic + + <toolset>gcc:<cxxflags>-Wextra + <toolset>gcc:<cxxflags>-pedantic + ; + +# please order by name to ease maintenance +build-project test ; diff --git a/src/boost/libs/uuid/LICENSE b/src/boost/libs/uuid/LICENSE new file mode 100644 index 00000000..36b7cd93 --- /dev/null +++ b/src/boost/libs/uuid/LICENSE @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +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, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/src/boost/libs/uuid/README.md b/src/boost/libs/uuid/README.md new file mode 100644 index 00000000..aeb527c7 --- /dev/null +++ b/src/boost/libs/uuid/README.md @@ -0,0 +1,61 @@ +Uuid, part of collection of the [Boost C++ Libraries](http://github.com/boostorg), provides a C++ wrapper around [RFC-4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDs. + +### License + +Distributed under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt). + +### Properties + +* C++03 +* Header-only + +### Build Status + +Branch | Travis | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests | +:-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- | +[`master`](https://github.com/boostorg/uuid/tree/master) | [![Build Status](https://travis-ci.org/boostorg/uuid.svg?branch=master)](https://travis-ci.org/boostorg/uuid) | [![Build status](https://ci.appveyor.com/api/projects/status/nuihr6s92fjb9gwy/branch/master?svg=true)](https://ci.appveyor.com/project/jeking3/uuid-gaamf/branch/master) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/13982/badge.svg)](https://scan.coverity.com/projects/boostorg-uuid) | [![codecov](https://codecov.io/gh/boostorg/uuid/branch/master/graph/badge.svg)](https://codecov.io/gh/boostorg/uuid/branch/master)| [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/uuid.html) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](http://www.boost.org/doc/libs/master/doc/html/uuid.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](http://www.boost.org/development/tests/master/developer/uuid.html) +[`develop`](https://github.com/boostorg/uuid/tree/develop) | [![Build Status](https://travis-ci.org/boostorg/uuid.svg?branch=develop)](https://travis-ci.org/boostorg/uuid) | [![Build status](https://ci.appveyor.com/api/projects/status/nuihr6s92fjb9gwy/branch/develop?svg=true)](https://ci.appveyor.com/project/jeking3/uuid-gaamf/branch/develop) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/13982/badge.svg)](https://scan.coverity.com/projects/boostorg-uuid) | [![codecov](https://codecov.io/gh/boostorg/uuid/branch/develop/graph/badge.svg)](https://codecov.io/gh/boostorg/uuid/branch/develop) | [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/uuid.html) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](http://www.boost.org/doc/libs/develop/doc/html/uuid.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](http://www.boost.org/development/tests/develop/developer/uuid.html) + +### Directories + +| Name | Purpose | +| ----------- | ------------------------------ | +| `doc` | documentation | +| `include` | headers | +| `test` | unit tests | + +### More information + +* [Ask questions](http://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-uuid) +* [Report bugs](https://github.com/boostorg/uuid/issues): Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well. +* Submit your patches as pull requests against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt). +* Discussions about the library are held on the [Boost developers mailing list](http://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](http://www.boost.org/community/policy.html) before posting and add the `[uuid]` tag at the beginning of the subject line. + +### Code Example - UUID Generation + + // Copyright 2017 James E. King III + // Distributed under the Boost Software License, Version 1.0. + // (See https://www.boost.org/LICENSE_1_0.txt) + // mkuuid.cpp example + + #include <boost/lexical_cast.hpp> + #include <boost/uuid/random_generator.hpp> + #include <boost/uuid/uuid_io.hpp> + #include <iostream> + + int main(void) + { + boost::uuids::random_generator gen; + std::cout << boost::lexical_cast<std::string>(gen()) << std::endl; + return 0; + } + + ---- + + $ clang++ -ansi -Wall -Wextra -std=c++03 -O3 mkuuid.cpp -o mkuuid + $ ./mkuuid + 2c186eb0-89cf-4a3c-9b97-86db1670d5f4 + $ ./mkuuid + a9d3fbb9-0383-4389-a8a8-61f6629f90b6 + + diff --git a/src/boost/libs/uuid/index.html b/src/boost/libs/uuid/index.html new file mode 100644 index 00000000..6d24d2a0 --- /dev/null +++ b/src/boost/libs/uuid/index.html @@ -0,0 +1,13 @@ +<!-- Copyright (c) 2002-2003 William E. Kempf. + Subject to the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or https://www.boost.org/LICENSE_1_0.txt) +--> + +<html> +<head> +<meta http-equiv="refresh" content="0; URL=doc/index.html"> +</head> +<body> +Automatic redirection failed, please go to <a href="doc/index.html">doc/index.html</a> +</body> +</html> diff --git a/src/boost/libs/uuid/meta/libraries.json b/src/boost/libs/uuid/meta/libraries.json new file mode 100644 index 00000000..2d68ec6c --- /dev/null +++ b/src/boost/libs/uuid/meta/libraries.json @@ -0,0 +1,16 @@ +{ + "key": "uuid", + "name": "Uuid", + "authors": [ + "Andy Tompkins" + ], + "description": "A universally unique identifier.", + "category": [ + "Data", + "Domain" + ], + "maintainers": [ + "Andy Tompkins <atompkins -at- fastmail.fm>", + "James E. King III <jking -at- apache.org>" + ] +} diff --git a/src/boost/libs/uuid/test/Jamfile.v2 b/src/boost/libs/uuid/test/Jamfile.v2 new file mode 100644 index 00000000..f96ca14f --- /dev/null +++ b/src/boost/libs/uuid/test/Jamfile.v2 @@ -0,0 +1,219 @@ +# Copyright 2007 Andy Tompkins. +# Copyright 2017 - 2018 James E. King III +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +lib bcrypt ; + +project libs/uuid/test + : requirements + + # boost.jam defines BOOST_ALL_NO_LIB, this makes library management + # near-impossible with the platform selection logic in the random_provider + <target-os>windows:<define>BOOST_UUID_FORCE_AUTO_LINK + <target-os>windows,<toolset>gcc:<library>bcrypt + + # boost::lexical_cast needs this for a warning-free build (CHAR_MAX) + <toolset>clang:<cxxflags>-Wno-c99-extensions + + # boost::random needs this setting for a warning free build: + <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS + + # link static for easier debugging + <link>static + +; + +import os ; +import path ; +import regex ; +import testing ; + +# this rule enumerates through all the headers and ensures +# that inclusion of the header by itself is sufficient to +# compile successfully, proving the header does not depend +# on any other headers to be included first - adapted from +# logic in the winapi test bjam script +rule test_all +{ + local all_rules = ; + local file ; + local headers_path = [ path.make $(BOOST_ROOT)/libs/uuid/include/boost/uuid ] ; + for file in [ path.glob-tree $(headers_path) : *.hpp : uuid ] + { + local rel_file = [ path.relative-to $(headers_path) $(file) ] ; + # Note: The test name starts with '~' in order to group these tests in the test report table, preferably at the end. + # All '/' are replaced with '-' because apparently test scripts have a problem with test names containing slashes. + local test_name = [ regex.replace $(rel_file) "/" "-" ] ; + local decl_test_name = ~hdr-decl-$(test_name) ; + # ECHO $(rel_file) ; + all_rules += [ compile compile/decl_header.cpp : <define>"BOOST_UUID_TEST_HEADER=$(rel_file)" <dependency>$(file) : $(decl_test_name) ] ; + } + + local tests_path = [ path.make $(BOOST_ROOT)/libs/uuid/test/compile-fail ] ; + for file in [ path.glob-tree $(tests_path) : *.cpp ] + { + local rel_file = [ path.relative-to $(tests_path) $(file) ] ; + local test_name = [ regex.replace [ regex.replace $(rel_file) "/" "-" ] ".cpp" "" ] ; + local decl_test_name = cf-$(test_name) ; + # ECHO $(rel_file) ; + all_rules += [ compile-fail $(file) : : $(decl_test_name) ] ; + } + + # make sure compile time options work in isolation + all_rules += [ compile compile/decl_header.cpp : + <define>"BOOST_UUID_TEST_HEADER=uuid.hpp" + <define>"BOOST_UUID_NO_TYPE_TRAITS" + <dependency>$(BOOST_ROOT)/boost/uuid/uuid.hpp : + compile_uuid_no_type_traits ] ; + all_rules += [ compile compile/decl_header.cpp : + <define>"BOOST_UUID_TEST_HEADER=uuid.hpp" + <define>"BOOST_UUID_NO_SIMD" + <dependency>$(BOOST_ROOT)/boost/uuid/uuid.hpp : + compile_uuid_no_simd ] ; + + # ECHO All rules: $(all_rules) ; + return $(all_rules) ; +} + +# disabled in UBSAN builds due to issues in Boost.Serialization +if ! [ os.environ UBSAN_OPTIONS ] +{ +test-suite uuid-serialization : + # test serializing uuids + [ run test_serialization.cpp ../../serialization/build//boost_serialization ] + + # TODO - This test fails to like with boost_wserialization + # [ run test_wserialization.cpp + # ../../serialization/build//boost_serialization + # ../../serialization/build//boost_wserialization + # : : : <dependency>../../config/test/all//BOOST_NO_STD_WSTREAMBUF + # ] + ; +} + +test-suite uuid : + [ test_all ] + + # test inclucing all .hpp files in 2 translations units + # to look for issues when using multiple translation units + # eg. missing inline on a global functionstate is not missing + [ run test_include1.cpp test_include2.cpp ] + + # main test + [ run test_uuid.cpp ] + [ run test_uuid_no_simd.cpp ] + + # test uuid_io.hpp + [ run test_io.cpp ] + + # test generators + [ run test_nil_generator.cpp ] + [ run test_name_generator.cpp ] + [ run test_name_generator.cpp : : : <define>BOOST_UUID_COMPAT_PRE_1_71_MD5 : test_name_generator_pre_1_71_compat ] + [ run test_string_generator.cpp ] + [ run test_random_generator.cpp ] + + # test tagging an object + [ run test_tagging.cpp ] + + # test use cases + [ run test_uuid_class.cpp ] + [ run test_uuid_in_map.cpp ] + + # test hash functions + [ run test_hash.cpp ] + [ run test_md5.cpp ] + [ run test_md5.cpp : : : <define>BOOST_UUID_COMPAT_PRE_1_71_MD5 : test_md5_pre_1_71_compat ] + [ run test_sha1.cpp ] + + # test MSVC 12 (VS2013) optimizer bug with SIMD operations. + # See https://svn.boost.org/trac/boost/ticket/8509#comment:3 + # Only happens in Release x64 builds. + [ run test_msvc_simd_bug981648_main.cpp + test_msvc_simd_bug981648_foo.cpp + : : : <build>no <toolset>msvc-12.0:<build>yes <variant>release <debug-symbols>on : test_msvc_simd_bug981648 ] + + # a small benchmark test for random generation + [ run test_bench_random.cpp ../../timer/build//boost_timer : : : <toolset>clang-cloudabi:<build>no ] + + [ run test_entropy_error.cpp ] + + # tests for the header-only random provider + # there are a number of variations to test all compile-time branches + # and to make sure we test all the error handling code paths + [ run test_detail_random_provider.cpp + : : : + <define>_WIN32_WINNT=0x0600 # will force bcrypt over wincrypt (on windows) + : test_detail_random_provider_happy ] + + [ run test_detail_random_provider.cpp + : : : + <define>BOOST_UUID_RANDOM_PROVIDER_NO_LIB # disable any auto-linking + <define>BOOST_UUID_TEST_RANDOM_MOCK # mock default provider to force error path testing + <define>_WIN32_WINNT=0x0600 # will force bcrypt over wincrypt (on windows) + : + test_detail_random_provider_sad ] + + # CI builds in appveyor normally select the bcrypt provider, so + # force wincrypt to be selected and test both happy and sad paths: + [ lib mock_random + : mock_random.cpp + : <link>shared + <build>no # do not build on any target-os + <target-os>windows:<build>yes ] # except for windows + + [ run test_detail_random_provider.cpp + : : : + <define>_WIN32_WINNT=0x0501 # will force wincrypt over bcrypt + <build>no # do not build on any target-os + <target-os>windows:<build>yes # except for windows + : test_detail_random_provider_happy_wincrypt ] + + [ run test_detail_random_provider.cpp + mock_random + : : : + <define>_WIN32_WINNT=0x0501 # will force wincrypt over bcrypt + <define>BOOST_UUID_RANDOM_PROVIDER_NO_LIB # disable any auto-linking + <define>BOOST_UUID_TEST_RANDOM_MOCK # mock wincrypt to force error path testing + <build>no # do not build on any target-os + <target-os>windows:<build>yes # except for windows + : test_detail_random_provider_sad_wincrypt ] + + # CI builds in travis will eventually select getrandom/getentropy when they move + # to a version of ubuntu with glibc-2.25 on it, so when that happens keep + # testing the posix provider: + [ run test_detail_random_provider.cpp + : : : + <define>BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX # will force POSIX over getrandom/getentropy + <target-os>windows:<build>no # do not bother running on windows + <toolset>clang-cloudabi:<build>no # no need to build under cloudabi + : test_detail_random_provider_happy_posix ] + + [ run test_detail_random_provider.cpp + : : : + <define>BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX # will force POSIX over getrandom/getentropy + <define>BOOST_UUID_TEST_RANDOM_MOCK # redirect code to use mock system calls + <target-os>windows:<build>no # do not bother running on windows + <toolset>clang-cloudabi:<build>no # no need to build under cloudabi + : test_detail_random_provider_sad_posix ] + + # Force running tests for getentropy despite it's not going to be used on Linux. getentropy + # may be used on systems other than Linux, which are not part of the CI testers pool. + [ run test_detail_random_provider.cpp + : : : + <define>BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETRANDOM # will force getentropy over getrandom + <build>no + <target-os>linux:<build>yes # build only on linux (or any other systems that support getentropy) + : test_detail_random_provider_happy_getentropy ] + + [ run test_detail_random_provider.cpp + : : : + <define>BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETRANDOM # will force getentropy over getrandom + <define>BOOST_UUID_TEST_RANDOM_MOCK # redirect code to use mock system calls + <build>no + <target-os>linux:<build>yes # build only on linux (or any other systems that support getentropy) + : test_detail_random_provider_sad_getentropy ] + + ; diff --git a/src/boost/libs/uuid/test/compile-fail/basic_random_generator_no_copy_assign.cpp b/src/boost/libs/uuid/test/compile-fail/basic_random_generator_no_copy_assign.cpp new file mode 100644 index 00000000..687e2b34 --- /dev/null +++ b/src/boost/libs/uuid/test/compile-fail/basic_random_generator_no_copy_assign.cpp @@ -0,0 +1,18 @@ +// (c) Copyright Andrey Semashev 2018 + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// The test verifies that basic_random_generator is not copy assignable + +#include <boost/uuid/random_generator.hpp> +#include <boost/random/linear_congruential.hpp> + +int main() +{ + boost::uuids::basic_random_generator<boost::rand48> uuid_gen1, uuid_gen2; + uuid_gen2 = uuid_gen1; + + return 1; +} diff --git a/src/boost/libs/uuid/test/compile-fail/basic_random_generator_no_copy_ctor.cpp b/src/boost/libs/uuid/test/compile-fail/basic_random_generator_no_copy_ctor.cpp new file mode 100644 index 00000000..0356bfde --- /dev/null +++ b/src/boost/libs/uuid/test/compile-fail/basic_random_generator_no_copy_ctor.cpp @@ -0,0 +1,18 @@ +// (c) Copyright Andrey Semashev 2018 + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// The test verifies that basic_random_generator is not copy constructible + +#include <boost/uuid/random_generator.hpp> +#include <boost/random/linear_congruential.hpp> + +int main() +{ + boost::uuids::basic_random_generator<boost::rand48> uuid_gen1; + boost::uuids::basic_random_generator<boost::rand48> uuid_gen2(uuid_gen1); + + return 1; +} diff --git a/src/boost/libs/uuid/test/compile-fail/random_generator_no_copy_assign.cpp b/src/boost/libs/uuid/test/compile-fail/random_generator_no_copy_assign.cpp new file mode 100644 index 00000000..0ff28d9e --- /dev/null +++ b/src/boost/libs/uuid/test/compile-fail/random_generator_no_copy_assign.cpp @@ -0,0 +1,17 @@ +// (c) Copyright Andrey Semashev 2018 + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// The test verifies that random_generator is not copy assignable + +#include <boost/uuid/random_generator.hpp> + +int main() +{ + boost::uuids::random_generator uuid_gen1, uuid_gen2; + uuid_gen2 = uuid_gen1; + + return 1; +} diff --git a/src/boost/libs/uuid/test/compile-fail/random_generator_no_copy_ctor.cpp b/src/boost/libs/uuid/test/compile-fail/random_generator_no_copy_ctor.cpp new file mode 100644 index 00000000..9a5da835 --- /dev/null +++ b/src/boost/libs/uuid/test/compile-fail/random_generator_no_copy_ctor.cpp @@ -0,0 +1,17 @@ +// (c) Copyright Andrey Semashev 2018 + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// The test verifies that random_generator is not copy constructible + +#include <boost/uuid/random_generator.hpp> + +int main() +{ + boost::uuids::random_generator uuid_gen1; + boost::uuids::random_generator uuid_gen2(uuid_gen1); + + return 1; +} diff --git a/src/boost/libs/uuid/test/compile/decl_header.cpp b/src/boost/libs/uuid/test/compile/decl_header.cpp new file mode 100644 index 00000000..a707487b --- /dev/null +++ b/src/boost/libs/uuid/test/compile/decl_header.cpp @@ -0,0 +1,24 @@ +/* + * Copyright Andrey Semashev 2015. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * https://www.boost.org/LICENSE_1_0.txt) + */ +/*! + * \file decl_header.cpp + * \author Andrey Semashev + * \date 21.06.2015 + * + * \brief This file contains a test boilerplate for checking that every + * public header is self-contained and does not have any missing + * #includes. + */ + +#define BOOST_UUID_TEST_INCLUDE_HEADER() <boost/uuid/BOOST_UUID_TEST_HEADER> + +#include BOOST_UUID_TEST_INCLUDE_HEADER() + +int main(int, char*[]) +{ + return 0; +} diff --git a/src/boost/libs/uuid/test/compile_uuid.cpp b/src/boost/libs/uuid/test/compile_uuid.cpp new file mode 100644 index 00000000..7387d33a --- /dev/null +++ b/src/boost/libs/uuid/test/compile_uuid.cpp @@ -0,0 +1,13 @@ +// (C) Copyright Andy Tompkins 2008. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// Purpose to make sure that a translation unit consisting of just the contents +// of the header file will compile successfully. + +#include <boost/uuid/uuid.hpp> diff --git a/src/boost/libs/uuid/test/digestutils.hpp b/src/boost/libs/uuid/test/digestutils.hpp new file mode 100644 index 00000000..499d9513 --- /dev/null +++ b/src/boost/libs/uuid/test/digestutils.hpp @@ -0,0 +1,73 @@ +// +// Copyright (C) 2019 James E. King III +// +// Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef BOOST_UUID_TEST_ENDIAN_2019 +#define BOOST_UUID_TEST_ENDIAN_2019 + +#include <boost/predef/other/endian.h> + +namespace boost { +namespace uuids { +namespace test { + +// +// A utility to copy a raw digest out from one of the detail hash functions +// to a byte string for comparisons in testing to known values. +// +static void copy_raw_digest(unsigned char* out, const unsigned int *in, size_t inlen) +{ + for (size_t chunk = 0; chunk < inlen; ++chunk) + { + const unsigned char * cin = reinterpret_cast<const unsigned char *>(&in[chunk]); + for (size_t byte = 0; byte < 4; ++byte) + { +#if BOOST_ENDIAN_LITTLE_BYTE + *out++ = *(cin + (3-byte)); +#else + *out++ = *(cin + byte); +#endif + } + } +} + +// +// A utility to compare and report two raw hashes +// +static void test_digest_equal_array(char const * file, int line, char const * function, + const unsigned char *lhs, + const unsigned char *rhs, + size_t len) +{ + for (size_t i=0; i<len; i++) { + if ( lhs[i] != rhs[i]) { + std::cerr << file << "(" << line << "): digest ["; + for (size_t l=0; l<len; l++) { + std::cerr << std::hex << (int)lhs[l]; + } + + std::cerr << "] not equal ["; + for (size_t r=0; r<len; r++) { + std::cerr << std::hex << (int)rhs[r]; + } + std::cerr << "] in function '" << function << "'" << std::endl; + ++boost::detail::test_errors(); + return; + } + } +} + +} +} +} + +#endif diff --git a/src/boost/libs/uuid/test/mock_random.cpp b/src/boost/libs/uuid/test/mock_random.cpp new file mode 100644 index 00000000..959caa8e --- /dev/null +++ b/src/boost/libs/uuid/test/mock_random.cpp @@ -0,0 +1,115 @@ +// +// Copyright (c) 2017 James E. King III +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) +// +// The contents of this file are compiled into a loadable +// library that is used for mocking purposes so that the error +// paths in the random_provider implementations are exercised. +// + +#include <boost/config.hpp> +#include <boost/core/ignore_unused.hpp> + +#if defined(BOOST_WINDOWS) + +#include <boost/winapi/basic_types.hpp> + +// WinAPI is not currently set up well for building mocks, as +// the definitions of wincrypt APIs all use BOOST_SYMBOL_IMPORT +// therefore we cannot include it, but we need some of the types +// so they are defined here... +namespace boost { +namespace winapi { + typedef ULONG_PTR_ HCRYPTPROV_; +} +} + +// wincrypt has to be mocked through a DLL pretending to be +// the real thing as the official APIs use __declspec(dllimport) + +#include <deque> +std::deque<boost::winapi::BOOL_> wincrypt_next_result; + +BOOST_SYMBOL_EXPORT bool expectations_capable() +{ + return true; +} + +BOOST_SYMBOL_EXPORT bool expectations_met() +{ + return wincrypt_next_result.empty(); +} + +BOOST_SYMBOL_EXPORT void expect_next_call_success(bool success) +{ + wincrypt_next_result.push_back(success ? 1 : 0); +} + +BOOST_SYMBOL_EXPORT bool provider_acquires_context() +{ + return true; +} + +extern "C" { + +BOOST_SYMBOL_EXPORT +boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC +CryptAcquireContextW( + boost::winapi::HCRYPTPROV_ *phProv, + boost::winapi::LPCWSTR_ szContainer, + boost::winapi::LPCWSTR_ szProvider, + boost::winapi::DWORD_ dwProvType, + boost::winapi::DWORD_ dwFlags) +{ + boost::ignore_unused(phProv); + boost::ignore_unused(szContainer); + boost::ignore_unused(szProvider); + boost::ignore_unused(dwProvType); + boost::ignore_unused(dwFlags); + + boost::winapi::BOOL_ result = wincrypt_next_result.front(); + wincrypt_next_result.pop_front(); + return result; +} + +BOOST_SYMBOL_EXPORT +boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC +CryptGenRandom( + boost::winapi::HCRYPTPROV_ hProv, + boost::winapi::DWORD_ dwLen, + boost::winapi::BYTE_ *pbBuffer) +{ + boost::ignore_unused(hProv); + boost::ignore_unused(dwLen); + boost::ignore_unused(pbBuffer); + + boost::winapi::BOOL_ result = wincrypt_next_result.front(); + wincrypt_next_result.pop_front(); + return result; +} + +// the implementation ignores the result of close because it +// happens in a destructor +BOOST_SYMBOL_EXPORT +boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC +CryptReleaseContext( + boost::winapi::HCRYPTPROV_ hProv, +#if defined(_MSC_VER) && (_MSC_VER+0) >= 1500 && (_MSC_VER+0) < 1900 && BOOST_USE_NTDDI_VERSION < BOOST_WINAPI_NTDDI_WINXP + // see winapi crypt.hpp for more details on why these differ... + boost::winapi::ULONG_PTR_ dwFlags +#else + boost::winapi::DWORD_ dwFlags +#endif +) +{ + boost::ignore_unused(hProv); + boost::ignore_unused(dwFlags); + return true; +} + +} // end extern "C" + +#endif diff --git a/src/boost/libs/uuid/test/mock_random.hpp b/src/boost/libs/uuid/test/mock_random.hpp new file mode 100644 index 00000000..6ef864c2 --- /dev/null +++ b/src/boost/libs/uuid/test/mock_random.hpp @@ -0,0 +1,287 @@ +// +// Copyright (c) 2017 James E. King III +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) +// +// Mocks are used to test sad paths by forcing error responses +// + +#include <boost/core/ignore_unused.hpp> +#include <boost/uuid/detail/random_provider_detect_platform.hpp> + +#if defined(BOOST_UUID_TEST_RANDOM_MOCK) + +#if defined(BOOST_UUID_RANDOM_PROVIDER_WINCRYPT) || defined(BOOST_UUID_RANDOM_PROVIDER_POSIX) +#define BOOST_UUID_TEST_RANDOM_MOCK_LINKAGE BOOST_SYMBOL_IMPORT +#else +#define BOOST_UUID_TEST_RANDOM_MOCK_LINKAGE +#endif + +//! \returns true if the provider can be mocked - if not then the test +//! should skip negative testing +BOOST_UUID_TEST_RANDOM_MOCK_LINKAGE bool expectations_capable(); + +//! Ensure all expectations for calls were consumed. This means the number +//! of expected calls was met. +//! \returns true if all expectations were met +BOOST_UUID_TEST_RANDOM_MOCK_LINKAGE bool expectations_met(); + +//! Set the response of the next mocked random/crypto call - builds up +//! a queue of responses. If the queue empties and another call is made, +//! the test will core. +//! \param[in] success true for success response, false for failure +BOOST_UUID_TEST_RANDOM_MOCK_LINKAGE void expect_next_call_success(bool success); + +//! \returns true if the provider acquires a context +BOOST_UUID_TEST_RANDOM_MOCK_LINKAGE bool provider_acquires_context(); + +#if defined(BOOST_UUID_RANDOM_PROVIDER_ARC4RANDOM) + +// arc4random cannot fail therefore it needs no mocking at all! + +bool expectations_capable() +{ + return false; +} + +bool expectations_met() +{ + throw std::logic_error("expectations not supported"); +} + +void expect_next_call_success(bool success) +{ + boost::ignore_unused(success); + throw std::logic_error("expectations not supported"); +} + +bool provider_acquires_context() +{ + throw std::logic_error("expectations not supported"); +} + +#elif defined(BOOST_UUID_RANDOM_PROVIDER_BCRYPT) + +#include <boost/winapi/bcrypt.hpp> +#include <deque> +std::deque<boost::winapi::NTSTATUS_> bcrypt_next_result; + +bool expectations_capable() +{ + return true; +} + +bool expectations_met() +{ + return bcrypt_next_result.empty(); +} + +void expect_next_call_success(bool success) +{ + bcrypt_next_result.push_back(success ? 0 : 17); +} + +bool provider_acquires_context() +{ + return true; +} + +boost::winapi::NTSTATUS_ BOOST_WINAPI_WINAPI_CC +BCryptOpenAlgorithmProvider( + boost::winapi::BCRYPT_ALG_HANDLE_ *phAlgorithm, + boost::winapi::LPCWSTR_ pszAlgId, + boost::winapi::LPCWSTR_ pszImplementation, + boost::winapi::DWORD_ dwFlags +) +{ + boost::ignore_unused(phAlgorithm); + boost::ignore_unused(pszAlgId); + boost::ignore_unused(pszImplementation); + boost::ignore_unused(dwFlags); + + boost::winapi::NTSTATUS_ result = bcrypt_next_result.front(); + bcrypt_next_result.pop_front(); + return result; +} + +boost::winapi::NTSTATUS_ BOOST_WINAPI_WINAPI_CC +BCryptGenRandom( + boost::winapi::BCRYPT_ALG_HANDLE_ hAlgorithm, + boost::winapi::PUCHAR_ pbBuffer, + boost::winapi::ULONG_ cbBuffer, + boost::winapi::ULONG_ dwFlags +) +{ + boost::ignore_unused(hAlgorithm); + boost::ignore_unused(pbBuffer); + boost::ignore_unused(cbBuffer); + boost::ignore_unused(dwFlags); + + boost::winapi::NTSTATUS_ result = bcrypt_next_result.front(); + bcrypt_next_result.pop_front(); + return result; +} + +// the implementation ignores the result of close because it +// happens in a destructor +boost::winapi::NTSTATUS_ BOOST_WINAPI_WINAPI_CC +BCryptCloseAlgorithmProvider( + boost::winapi::BCRYPT_ALG_HANDLE_ hAlgorithm, + boost::winapi::ULONG_ dwFlags +) +{ + boost::ignore_unused(hAlgorithm); + boost::ignore_unused(dwFlags); + return 0; +} + +#elif defined(BOOST_UUID_RANDOM_PROVIDER_GETRANDOM) + +#include <deque> +#include <unistd.h> +std::deque<bool> getrandom_next_result; + +bool expectations_capable() +{ + return true; +} + +bool expectations_met() +{ + return getrandom_next_result.empty(); +} + +void expect_next_call_success(bool success) +{ + getrandom_next_result.push_back(success); +} + +bool provider_acquires_context() +{ + return false; +} + +ssize_t mock_getrandom(void *buffer, size_t length, unsigned int flags) +{ + boost::ignore_unused(buffer); + boost::ignore_unused(length); + boost::ignore_unused(flags); + + bool success = getrandom_next_result.front(); + getrandom_next_result.pop_front(); + return success ? static_cast< ssize_t >(length) : static_cast< ssize_t >(-1); +} + +#define BOOST_UUID_RANDOM_PROVIDER_GETRANDOM_IMPL_GETRANDOM ::mock_getrandom + +#elif defined(BOOST_UUID_RANDOM_PROVIDER_GETENTROPY) + +// +// This stubbing technique works on unix because of how the loader resolves +// functions. Locally defined functions resolve first. +// + +#include <deque> +#include <unistd.h> +std::deque<int> getentropy_next_result; + +bool expectations_capable() +{ + return true; +} + +bool expectations_met() +{ + return getentropy_next_result.empty(); +} + +void expect_next_call_success(bool success) +{ + getentropy_next_result.push_back(success ? 0 : -1); +} + +bool provider_acquires_context() +{ + return false; +} + +int getentropy(void *buffer, size_t length) +{ + boost::ignore_unused(buffer); + boost::ignore_unused(length); + + int result = getentropy_next_result.front(); + getentropy_next_result.pop_front(); + return result; +} + +#elif defined(BOOST_UUID_RANDOM_PROVIDER_POSIX) + +#include <boost/numeric/conversion/cast.hpp> +#include <deque> +#include <stdexcept> +std::deque<bool> posix_next_result; // bool success + +bool expectations_capable() +{ + return true; +} + +bool expectations_met() +{ + return posix_next_result.empty(); +} + +void expect_next_call_success(bool success) +{ + posix_next_result.push_back(success); +} + +bool provider_acquires_context() +{ + return true; +} + +int mockopen(const char *fname, int flags) +{ + boost::ignore_unused(fname); + boost::ignore_unused(flags); + + bool success = posix_next_result.front(); + posix_next_result.pop_front(); + return success ? 17 : -1; +} + +ssize_t mockread(int fd, void *buf, size_t siz) +{ + boost::ignore_unused(fd); + boost::ignore_unused(buf); + + // first call siz is 4, in a success case we return 1 + // forcing a second loop to come through size 3 + + if (siz < 4) { return boost::numeric_cast<ssize_t>(siz); } + if (siz > 4) { throw std::logic_error("unexpected siz"); } + + bool success = posix_next_result.front(); + posix_next_result.pop_front(); + return success ? 1 : -1; +} + +#define BOOST_UUID_RANDOM_PROVIDER_POSIX_IMPL_OPEN mockopen +#define BOOST_UUID_RANDOM_PROVIDER_POSIX_IMPL_READ mockread + +#elif defined(BOOST_UUID_RANDOM_PROVIDER_WINCRYPT) + +// Nothing to declare, since the expectation methods were already +// defined as import, we will link against a mock library + +#else + +#error support needed here for testing + +#endif + +#endif // BOOST_UUID_TEST_RANDOM_MOCK diff --git a/src/boost/libs/uuid/test/test_bench_random.cpp b/src/boost/libs/uuid/test/test_bench_random.cpp new file mode 100644 index 00000000..e86f159e --- /dev/null +++ b/src/boost/libs/uuid/test/test_bench_random.cpp @@ -0,0 +1,187 @@ +// +// Copyright (c) 2017, 2018 James E. King III +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) +// +// benchmark for random_generators in different forms +// + +#include <boost/core/ignore_unused.hpp> +#include <boost/timer/timer.hpp> +#include <boost/predef/os.h> +#include <boost/uuid/random_generator.hpp> +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <iostream> +#include <limits> + +#if !defined(BOOST_NO_STRESS_TEST) +// must be a Valgrind, UBsan, or other stressful job +#define AVG_LOOPS 1 +#define GEN_LOOPS 10 +#define REUSE_LOOPS 100 +#else +#define AVG_LOOPS 10 +#define GEN_LOOPS 10000 +#define REUSE_LOOPS 1000000 +#endif + +template<class Generator> +void auto_timed_generator_ctordtor(size_t count) +{ + boost::timer::auto_cpu_timer t; + for (size_t i = 0; i < count; ++i) + { + Generator gen; + boost::ignore_unused(gen); + } +} + +template<class Generator> +void auto_timed_generator_novel(size_t count) +{ + boost::timer::auto_cpu_timer t; + for (size_t i = 0; i < count; ++i) + { + Generator gen; + boost::uuids::uuid u = gen(); + boost::ignore_unused(u); + } +} + +template<class Generator> +void auto_timed_generator_reuse(size_t count) +{ + Generator gen; + { + boost::timer::auto_cpu_timer t; + for (size_t i = 0; i < count; ++i) + { + boost::uuids::uuid u = gen(); + boost::ignore_unused(u); + } + } +} + +template<class Generator> +boost::timer::cpu_times timed_generator(size_t count) +{ + boost::timer::cpu_timer t; + Generator gen; + for (size_t i = 0; i < count; ++i) + { + boost::uuids::uuid u = gen(); + boost::ignore_unused(u); + } + return t.elapsed(); +} + +int main(int, char*[]) +{ + std::cout << "Operating system entropy provider: " + << boost::uuids::detail::random_provider().name() << std::endl; + +#if !defined(BOOST_NO_STRESS_TEST) + + // + // Determine the cutoff point where it is more wall-clock efficient to + // use the bulk generator over the standard one. + // + + std::cout << "Calculating the number of operator() calls where random_generator" << std::endl; + std::cout << "is more efficient than random_generator_mt19937..." << std::endl; + std::cout << "at "; + bool asterisk = false; + size_t minn = (std::numeric_limits<size_t>::max)(); + size_t summ = 0; + size_t maxx = 0; + for (size_t i = 0; i < AVG_LOOPS + 1; ++i) // the first loop is thrown away, see below + { + size_t answer = 0; + for (size_t count = 1; !answer; ++count) + { + boost::timer::cpu_times standard = timed_generator<boost::uuids::random_generator>(count); + boost::timer::cpu_times pseudo = timed_generator<boost::uuids::random_generator_mt19937>(count); + if (standard.wall > pseudo.wall) + { + answer = count; + } + else if (count >= 999) + { + std::cout << "*"; + asterisk = true; + answer = count; + } + } + + // throw away the first answer in case it contains time related to loading + // or initializing the crypto library being used + if (i > 0) + { + if (minn > answer) minn = answer; + if (maxx < answer) maxx = answer; + summ += answer; + std::cout << answer << " " << std::flush; + } + } + if (asterisk) + { + std::cout << "* = limited to 999" << std::endl; + } + std::cout << "calls to operator()" << std::endl; + size_t answer = summ / AVG_LOOPS; + std::cout << "For this platform, random_generator_mt19937 outperforms " + << "random_generator after " << answer << " generations (min " << minn << " / max " << maxx << ")." + << std::endl; + std::cout << std::endl; + +#endif + + // + // Measure ctor/dtor of both + // + std::cout << "Construction/destruction time for random_generator " + << "(" << GEN_LOOPS << " iterations): " << std::endl; + auto_timed_generator_ctordtor<boost::uuids::random_generator>(GEN_LOOPS); + std::cout << std::endl; + + std::cout << "Construction/destruction time for random_generator_mt19937 " + << "(" << GEN_LOOPS << " iterations): " << std::endl; + auto_timed_generator_ctordtor<boost::uuids::random_generator_mt19937>(GEN_LOOPS); + std::cout << std::endl; + + // + // Two common use cases: + // + // Use an OS provided RNG which has no seed code but is slower to reuse + // Use a PRNG which is expensive to seed once but fast to reuse + // + // Measure the default selections of the library + // + + std::cout << "Benchmark boost::uuids::random_generator " + << "(reused for " << REUSE_LOOPS << " loops):" << std::endl; + auto_timed_generator_reuse<boost::uuids::random_generator>(REUSE_LOOPS); + std::cout << std::endl; + + std::cout << "Benchmark boost::uuids::random_generator_mt19937 " + << "(reused for " << REUSE_LOOPS << " loops):" << std::endl; + auto_timed_generator_reuse<boost::uuids::random_generator_mt19937>(REUSE_LOOPS); + std::cout << std::endl; + + std::cout << "Benchmark boost::uuids::random_generator " + << "(new generator each loop for " << GEN_LOOPS << " loops):" << std::endl; + auto_timed_generator_novel<boost::uuids::random_generator>(GEN_LOOPS); + std::cout << std::endl; + + std::cout << "Benchmark boost::uuids::random_generator_mt19937 " + << "(new generator each loop for " << GEN_LOOPS << " loops):" << std::endl; + auto_timed_generator_novel<boost::uuids::random_generator_mt19937>(GEN_LOOPS); + std::cout << std::endl; + + return 0; +} + + diff --git a/src/boost/libs/uuid/test/test_detail_random_provider.cpp b/src/boost/libs/uuid/test/test_detail_random_provider.cpp new file mode 100644 index 00000000..f4f51eb0 --- /dev/null +++ b/src/boost/libs/uuid/test/test_detail_random_provider.cpp @@ -0,0 +1,77 @@ +// +// Copyright (c) 2017 James E. King III +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) +// +// Positive and negative testing for detail::random_provider +// + +#include <boost/array.hpp> +#include <boost/cstdint.hpp> +#include <boost/detail/lightweight_test.hpp> + +// The mock needs to load first for posix system call redirection to work properly +#include "mock_random.hpp" +#include <boost/uuid/detail/random_provider.hpp> +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <limits> +#include <string.h> + + +int main(int, char*[]) +{ +#if !defined(BOOST_UUID_TEST_RANDOM_MOCK) // Positive Testing + + boost::uuids::detail::random_provider provider; + boost::array<unsigned int, 2> ints; + + // test generator() + ints[0] = 0; + ints[1] = 0; + provider.generate(ints.begin(), ints.end()); + BOOST_TEST_NE(ints[0], ints[1]); + + // test name() + BOOST_TEST_GT(strlen(provider.name()), 4u); + + // test get_random_bytes() + char buf1[64]; + char buf2[64]; + provider.get_random_bytes(buf1, 64); + provider.get_random_bytes(buf2, 64); + BOOST_TEST_NE(0, memcmp(buf1, buf2, 64)); + +#else // Negative Testing + + if (expectations_capable()) + { + // Test fail acquiring context if the provider supports it + if (provider_acquires_context()) + { + expect_next_call_success(false); + BOOST_TEST_THROWS(boost::uuids::detail::random_provider(), + boost::uuids::entropy_error); + BOOST_TEST(expectations_met()); + } + + // Test fail acquiring entropy + if (provider_acquires_context()) + { + expect_next_call_success(true); + } + expect_next_call_success(false); + // 4 is important for the posix negative test (partial read) to work properly + // as it sees a size of 4, returns 1, causing a 2nd loop to read 3 more bytes... + char buf[4]; + BOOST_TEST_THROWS(boost::uuids::detail::random_provider().get_random_bytes(buf, 4), + boost::uuids::entropy_error); + BOOST_TEST(expectations_met()); + } + +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_entropy_error.cpp b/src/boost/libs/uuid/test/test_entropy_error.cpp new file mode 100644 index 00000000..1bb83cd0 --- /dev/null +++ b/src/boost/libs/uuid/test/test_entropy_error.cpp @@ -0,0 +1,24 @@ +// +// Copyright (c) 2017 James E. King III +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) +// +// Entropy error class test +// + +#include <boost/detail/lightweight_test.hpp> +#include <boost/uuid/entropy_error.hpp> +#include <string> + +int main(int, char*[]) +{ + using namespace boost::uuids; + + entropy_error err(6, "foo"); + BOOST_TEST_EQ(6, err.errcode()); + BOOST_TEST_CSTR_EQ("foo", err.what()); + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_generators.cpp b/src/boost/libs/uuid/test/test_generators.cpp new file mode 100644 index 00000000..db6cf61c --- /dev/null +++ b/src/boost/libs/uuid/test/test_generators.cpp @@ -0,0 +1,137 @@ +// (C) Copyright Andy Tompkins 2009. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_generators.cpp -------------------------------// + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_generators.hpp> +#include <boost/uuid/uuid_io.hpp> + +#include <boost/test/included/test_exec_monitor.hpp> +#include <boost/test/test_tools.hpp> + +#include <boost/random.hpp> + +template <typename RandomUuidGenerator> +void check_random_generator(RandomUuidGenerator& uuid_gen) +{ + boost::uuids::uuid u1 = uuid_gen(); + boost::uuids::uuid u2 = uuid_gen(); + + BOOST_CHECK_NE(u1, u2); + + // check variant + BOOST_CHECK_EQUAL(u1.variant(), boost::uuids::uuid::variant_rfc_4122); +// BOOST_CHECK_EQUAL( *(u1.begin()+8) & 0xC0, 0x80); + // version + BOOST_CHECK_EQUAL( *(u1.begin()+6) & 0xF0, 0x40); +} + +int test_main(int, char*[]) +{ + using namespace boost::uuids; + using boost::test_tools::output_test_stream; + + { // test nil generator + uuid u1 = nil_generator()(); + uuid u2 = {{0}}; + BOOST_CHECK_EQUAL(u1, u2); + + uuid u3 = nil_uuid(); + BOOST_CHECK_EQUAL(u3, u2); + } + + { // test string_generator + string_generator gen; + uuid u = gen("00000000-0000-0000-0000-000000000000"); + BOOST_CHECK_EQUAL(u, nil_uuid()); + BOOST_CHECK_EQUAL(u.is_nil(), true); + + const uuid u_increasing = {{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }}; + const uuid u_decreasing = {{ 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }}; + + u = gen("0123456789abcdef0123456789ABCDEF"); + BOOST_CHECK_EQUAL(u, u_increasing); + + u = gen("{0123456789abcdef0123456789ABCDEF}"); + BOOST_CHECK_EQUAL(u, u_increasing); + + u = gen("{01234567-89AB-CDEF-0123-456789abcdef}"); + BOOST_CHECK_EQUAL(u, u_increasing); + + u = gen("01234567-89AB-CDEF-0123-456789abcdef"); + BOOST_CHECK_EQUAL(u, u_increasing); + + u = gen(std::string("fedcba98-7654-3210-fedc-ba9876543210")); + BOOST_CHECK_EQUAL(u, u_decreasing); + +#ifndef BOOST_NO_STD_WSTRING + u = gen(L"fedcba98-7654-3210-fedc-ba9876543210"); + BOOST_CHECK_EQUAL(u, u_decreasing); + + u = gen(std::wstring(L"01234567-89ab-cdef-0123-456789abcdef")); + BOOST_CHECK_EQUAL(u, u_increasing); +#endif //BOOST_NO_STD_WSTRING + } + + { // test name_generator + uuid dns_namespace_uuid = {{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}}; + uuid correct = {{0x21, 0xf7, 0xf8, 0xde, 0x80, 0x51, 0x5b, 0x89, 0x86, 0x80, 0x01, 0x95, 0xef, 0x79, 0x8b, 0x6a}}; + uuid wcorrect = {{0xb9, 0x50, 0x66, 0x13, 0x2c, 0x04, 0x51, 0x2d, 0xb8, 0xfe, 0xbf, 0x8d, 0x0b, 0xa1, 0xb2, 0x71}}; + + name_generator gen(dns_namespace_uuid); + + uuid u = gen("www.widgets.com"); + BOOST_CHECK_EQUAL(u, correct); + BOOST_CHECK_EQUAL(u.variant(), boost::uuids::uuid::variant_rfc_4122); + + u = gen(L"www.widgets.com"); + BOOST_CHECK_EQUAL(u, wcorrect); + BOOST_CHECK_EQUAL(u.variant(), boost::uuids::uuid::variant_rfc_4122); + + u = gen(std::string("www.widgets.com")); + BOOST_CHECK_EQUAL(u, correct); + BOOST_CHECK_EQUAL(u.variant(), boost::uuids::uuid::variant_rfc_4122); + + u = gen(std::wstring(L"www.widgets.com")); + BOOST_CHECK_EQUAL(u, wcorrect); + BOOST_CHECK_EQUAL(u.variant(), boost::uuids::uuid::variant_rfc_4122); + + char name[] = "www.widgets.com"; + u = gen(name, 15); + BOOST_CHECK_EQUAL(u, correct); + BOOST_CHECK_EQUAL(u.variant(), boost::uuids::uuid::variant_rfc_4122); + } + + { // test random_generator + // default random number generator + random_generator uuid_gen1; + check_random_generator(uuid_gen1); + + // specific random number generator + basic_random_generator<boost::rand48> uuid_gen2; + check_random_generator(uuid_gen2); + + // pass by reference + boost::ecuyer1988 ecuyer1988_gen; + basic_random_generator<boost::ecuyer1988> uuid_gen3(ecuyer1988_gen); + check_random_generator(uuid_gen3); + + // pass by pointer + boost::lagged_fibonacci607 lagged_fibonacci607_gen; + basic_random_generator<boost::lagged_fibonacci607> uuid_gen4(&lagged_fibonacci607_gen); + check_random_generator(uuid_gen4); + + // random device + //basic_random_generator<boost::random_device> uuid_gen5; + //check_random_generator(uuid_gen5); + } + + return 0; +} diff --git a/src/boost/libs/uuid/test/test_hash.cpp b/src/boost/libs/uuid/test/test_hash.cpp new file mode 100644 index 00000000..5bd55d06 --- /dev/null +++ b/src/boost/libs/uuid/test/test_hash.cpp @@ -0,0 +1,45 @@ +// +// Copyright (c) 2018 James E. King III +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) +// +// std::hash support for uuid +// + +#include <boost/config.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/uuid/string_generator.hpp> +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_hash.hpp> +#include <iostream> + +#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) +#include <unordered_set> +#endif + +int main(int, char*[]) +{ +#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) + using namespace boost::uuids; + string_generator gen; + + uuid u1 = gen("01234567-89AB-CDEF-0123-456789abcdef"); + uuid u2 = gen("fedcba98-7654-3210-fedc-ba9876543210"); + + std::hash<uuid> hasher; + BOOST_TEST(hasher(u1) != hasher(u2)); + + std::unordered_set<boost::uuids::uuid> uns; + uns.insert(u1); + uns.insert(u2); + + BOOST_TEST_EQ(uns.size(), 2); + + return boost::report_errors(); +#else + std::cout << "test skipped - no library support for std::hash or std::unordered_set" << std::endl; + return 0; +#endif +} diff --git a/src/boost/libs/uuid/test/test_include1.cpp b/src/boost/libs/uuid/test/test_include1.cpp new file mode 100644 index 00000000..90279512 --- /dev/null +++ b/src/boost/libs/uuid/test/test_include1.cpp @@ -0,0 +1,24 @@ +// (C) Copyright Andy Tompkins 2009. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_include1.cpp -------------------------------// + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/uuid/uuid_serialize.hpp> +#include <boost/uuid/uuid_generators.hpp> +#include <boost/uuid/nil_generator.hpp> +#include <boost/uuid/name_generator.hpp> +#include <boost/uuid/string_generator.hpp> +#include <boost/uuid/random_generator.hpp> + +int main(int, char*[]) +{ + return 0; +} diff --git a/src/boost/libs/uuid/test/test_include2.cpp b/src/boost/libs/uuid/test/test_include2.cpp new file mode 100644 index 00000000..1297b287 --- /dev/null +++ b/src/boost/libs/uuid/test/test_include2.cpp @@ -0,0 +1,19 @@ +// (C) Copyright Andy Tompkins 2009. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_include2.cpp -------------------------------// + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/uuid/uuid_generators.hpp> +#include <boost/uuid/uuid_serialize.hpp> +#include <boost/uuid/nil_generator.hpp> +#include <boost/uuid/name_generator.hpp> +#include <boost/uuid/string_generator.hpp> +#include <boost/uuid/random_generator.hpp> diff --git a/src/boost/libs/uuid/test/test_io.cpp b/src/boost/libs/uuid/test/test_io.cpp new file mode 100644 index 00000000..998f612c --- /dev/null +++ b/src/boost/libs/uuid/test/test_io.cpp @@ -0,0 +1,160 @@ +// (C) Copyright Andy Tompkins 2009. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_io.cpp -------------------------------// + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/predef/library/c/cloudabi.h> +#include <string> +#include <sstream> +#include <iomanip> + +#if !BOOST_LIB_C_CLOUDABI +#include <boost/lexical_cast.hpp> +#endif + +using namespace boost::uuids; + +void uufail(const std::string& in) +{ + uuid out; + std::stringstream ss; + ss << in; + ss >> out; + BOOST_TEST_EQ(true, ss.fail()); +} + +#ifndef BOOST_NO_STD_WSTRING +void uufail(const std::wstring& in) +{ + uuid out; + std::wstringstream ss; + ss << in; + ss >> out; + BOOST_TEST_EQ(true, ss.fail()); +} +#endif + +void uuroundtrip(const uuid& in, const std::string& expect) +{ + std::stringstream ss; + ss << in; + BOOST_TEST_EQ(false, ss.fail()); + BOOST_TEST_EQ(expect, ss.str()); + + uuid out; + std::stringstream ss2; + ss2 << expect; + ss2 >> out; + BOOST_TEST_EQ(false, ss2.fail()); + BOOST_TEST_EQ(in, out); +} + +#ifndef BOOST_NO_STD_WSTRING +void uuroundtrip(const uuid& in, const std::wstring& expect) +{ + std::wstringstream ss; + ss << in; + BOOST_TEST_EQ(false, ss.fail()); + BOOST_TEST (expect == ss.str()); + + uuid out; + std::wstringstream ss2; + ss2 << expect; + ss2 >> out; + BOOST_TEST_EQ(false, ss2.fail()); + BOOST_TEST (in == out); +} +#endif + +int main(int, char*[]) +{ + const uuid u1 = {{0}}; + const uuid u2 = {{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}}; + const uuid u3 = {{0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}}; + + uuroundtrip(u1, "00000000-0000-0000-0000-000000000000"); + uuroundtrip(u2, "00010203-0405-0607-0809-0a0b0c0d0e0f"); + uuroundtrip(u3, "12345678-90ab-cdef-1234-567890abcdef"); + + std::stringstream ss5; + ss5 << 'a' << std::right << std::setfill('*') << std::setw(40) << u1 << 'a'; + BOOST_TEST_EQ(ss5.str(), "a****00000000-0000-0000-0000-000000000000a"); + + std::stringstream ss6; + ss6 << std::left << std::setfill('*') << std::setw(45) << u1; + BOOST_TEST_EQ(ss6.str(), "00000000-0000-0000-0000-000000000000*********"); + + std::stringstream ss7; + ss7 << std::left << std::setfill('*') << std::setw(45) << u2; + BOOST_TEST_EQ(ss7.str(), "00010203-0405-0607-0809-0a0b0c0d0e0f*********"); + +#ifndef BOOST_NO_STD_WSTRING + uuroundtrip(u1, L"00000000-0000-0000-0000-000000000000"); + uuroundtrip(u2, L"00010203-0405-0607-0809-0a0b0c0d0e0f"); + uuroundtrip(u3, L"12345678-90ab-cdef-1234-567890abcdef"); +#endif + + const char raw[36] = { '0', '1', '2', '3', '4', '5', '6', '7', '-', + '8', '9', 'a', 'b', '-', + 'c', 'd', 'e', 'f', '-', + 0 , '1', '2', '3', '-', // 0x00 character is intentional + '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + + uufail(std::string(raw, 36)); + uufail("01234567-89ab-cdef-0123456789abcdef"); + uufail("01234567-89ab-cdef0123-456789abcdef"); + uufail("01234567-89abcdef-0123-456789abcdef"); + uufail("0123456789ab-cdef-0123-456789abcdef"); + uufail("{12345678-90ab-cdef-1234-567890abcdef}"); // stream is not as flexible as string + uufail("G1234567-89AB-CDEF-0123-456789abcdef"); + uufail("01234567-89AB-CDEF-0123-456789abcdeg"); + +#ifndef BOOST_NO_STD_WSTRING + uufail(L"01234567-89ab-cdef-"); + uufail(L"01234567-89ab-cdef-0123456789abcdef"); + uufail(L"01234567-89ab-cdef0123-456789abcdef"); + uufail(L"01234567-89abcdef-0123-456789abcdef"); + uufail(L"0123456789ab-cdef-0123-456789abcdef"); + uufail(L"{12345678-90ab-cdef-1234-567890abcdef}"); // stream is not as flexible as string + uufail(L"G1234567-89AB-CDEF-0123-456789abcdef"); + uufail(L"01234567-89AB-CDEF-0123-456789abcdeg"); +#endif + +#if !BOOST_LIB_C_CLOUDABI + // lexical_cast depends on sprintf which is not available in cloudlibc + BOOST_TEST(boost::lexical_cast<std::string>(u1) == std::string("00000000-0000-0000-0000-000000000000")); + BOOST_TEST(boost::lexical_cast<uuid>("00000000-0000-0000-0000-000000000000") == u1); + + BOOST_TEST(boost::lexical_cast<std::string>(u3) == std::string("12345678-90ab-cdef-1234-567890abcdef")); + BOOST_TEST(boost::lexical_cast<uuid>("12345678-90ab-cdef-1234-567890abcdef") == u3); + +#ifndef BOOST_NO_STD_WSTRING + BOOST_TEST(boost::lexical_cast<std::wstring>(u1) == std::wstring(L"00000000-0000-0000-0000-000000000000")); + BOOST_TEST(boost::lexical_cast<uuid>(L"00000000-0000-0000-0000-000000000000") == u1); + + BOOST_TEST(boost::lexical_cast<std::wstring>(u3) == std::wstring(L"12345678-90ab-cdef-1234-567890abcdef")); + BOOST_TEST(boost::lexical_cast<uuid>(L"12345678-90ab-cdef-1234-567890abcdef") == u3); +#endif + +#endif + + BOOST_TEST(to_string(u1) == std::string("00000000-0000-0000-0000-000000000000")); + BOOST_TEST(to_string(u3) == std::string("12345678-90ab-cdef-1234-567890abcdef")); + +#ifndef BOOST_NO_STD_WSTRING + BOOST_TEST(to_wstring(u1) == std::wstring(L"00000000-0000-0000-0000-000000000000")); + BOOST_TEST(to_wstring(u3) == std::wstring(L"12345678-90ab-cdef-1234-567890abcdef")); +#endif + + return boost::report_errors(); +} + diff --git a/src/boost/libs/uuid/test/test_md5.cpp b/src/boost/libs/uuid/test/test_md5.cpp new file mode 100644 index 00000000..5e5c7f46 --- /dev/null +++ b/src/boost/libs/uuid/test/test_md5.cpp @@ -0,0 +1,61 @@ +// libs/uuid/test/test_md5.cpp --------------------------------// + +// (C) Copyright 2017 - 2019 James E. King III + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#include <boost/cstdint.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/uuid/detail/md5.hpp> + +#if !(defined(BOOST_UUID_COMPAT_PRE_1_71_MD5) && BOOST_ENDIAN_LITTLE_BYTE) +#include "digestutils.hpp" +#endif + +#define BOOST_TEST_MD5_DIGEST(lhs, rhs) \ + ( boost::uuids::test::test_digest_equal_array(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, (lhs), (rhs), 16) ) + +int main(int, char**) +{ + typedef struct + { + const char * data; + boost::uint32_t len; + unsigned char expected[16]; + } Expectation; + + /* http://www.febooti.com/products/filetweak/members/hash-and-crc/test-vectors/ */ + Expectation expectations[3] = { + { "The quick brown fox jumps over the lazy dog", 43, + { 0x9e, 0x10, 0x7d, 0x9d, 0x37, 0x2b, 0xb6, 0x82, + 0x6b, 0xd8, 0x1d, 0x35, 0x42, 0xa4, 0x19, 0xd6 }}, + { "Test vector from febooti.com", 28, + { 0x50, 0x0a, 0xb6, 0x61, 0x3c, 0x6d, 0xb7, 0xfb, + 0xd3, 0x0c, 0x62, 0xf5, 0xff, 0x57, 0x3d, 0x0f }}, + { "", 0, + { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, + 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e }} + }; + + for (boost::uint32_t i = 0; i < 3; ++i) { + boost::uuids::detail::md5 hash; + hash.process_bytes(expectations[i].data, expectations[i].len); + boost::uuids::detail::md5::digest_type result; + hash.get_digest(result); +#if defined(BOOST_UUID_COMPAT_PRE_1_71_MD5) && BOOST_ENDIAN_LITTLE_BYTE + // this is the original, incorrect behavior from pre-1.71 + BOOST_TEST_EQ(0, memcmp(result, expectations[i].expected, + sizeof(boost::uuids::detail::md5::digest_type))); +#else + unsigned char raw_result[16]; + boost::uuids::test::copy_raw_digest(raw_result, result, 4); + BOOST_TEST_MD5_DIGEST(raw_result, expectations[i].expected); +#endif + BOOST_TEST_EQ(hash.get_version(), 0x03); + + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_msvc_simd_bug981648.hpp b/src/boost/libs/uuid/test/test_msvc_simd_bug981648.hpp new file mode 100644 index 00000000..a0ad645d --- /dev/null +++ b/src/boost/libs/uuid/test/test_msvc_simd_bug981648.hpp @@ -0,0 +1,34 @@ +/* +* Copyright 2014 Andrey Semashev +* +* Distributed under the Boost Software License, Version 1.0. +* See accompanying file LICENSE_1_0.txt or copy at +* https://www.boost.org/LICENSE_1_0.txt +*/ +/* +* This is a part of the test for a workaround for MSVC 12 (VS2013) optimizer bug +* which causes incorrect SIMD code generation for operator==. See: +* +* https://svn.boost.org/trac/boost/ticket/8509#comment:3 +* https://connect.microsoft.com/VisualStudio/feedbackdetail/view/981648#tabs +* +* The header contains common definitions for the two source files. +*/ +#include <boost/uuid/uuid.hpp> +using boost::uuids::uuid; +class headerProperty +{ +public: +virtual ~headerProperty() {} +}; +class my_obj: +public headerProperty +{ +public: +// This char tmp[8] forces the following uuid to be misaligned. +char tmp[8]; +// This m_uuid is misaligned (not 16-byte aligned) and causes the != operator to crash. +uuid m_uuid; +const uuid &get_marker_id() const { return m_uuid; } +uuid get_id() const { return m_uuid; } +}; diff --git a/src/boost/libs/uuid/test/test_msvc_simd_bug981648_foo.cpp b/src/boost/libs/uuid/test/test_msvc_simd_bug981648_foo.cpp new file mode 100644 index 00000000..fdd1e855 --- /dev/null +++ b/src/boost/libs/uuid/test/test_msvc_simd_bug981648_foo.cpp @@ -0,0 +1,32 @@ +/* +* Copyright 2014 Andrey Semashev +* +* Distributed under the Boost Software License, Version 1.0. +* See accompanying file LICENSE_1_0.txt or copy at +* https://www.boost.org/LICENSE_1_0.txt +*/ +/* +* This is a part of the test for a workaround for MSVC 12 (VS2013) optimizer bug +* which causes incorrect SIMD code generation for operator==. See: +* +* https://svn.boost.org/trac/boost/ticket/8509#comment:3 +* https://connect.microsoft.com/VisualStudio/feedbackdetail/view/981648#tabs +* +* The file contains the function that actually causes the crash. Reproduces only +* in Release x64 builds. +*/ +#include <cstdio> +#include "test_msvc_simd_bug981648.hpp" +void mp_grid_update_marker_parameters(headerProperty* header_prop, my_obj ¤t_marker) +{ +headerProperty *old_header_prop = NULL; +my_obj *p = dynamic_cast<my_obj*>(header_prop); +/* +* This != statement crashes with a GP. +* */ +if (p != NULL && (current_marker.get_id() != p->get_marker_id())) { +std::printf("works okay, if it reaches this printf: %p\n", reinterpret_cast<void *>(p)); +old_header_prop = header_prop; +if (old_header_prop == 0) { fprintf(stderr, "ouch"); } +} +} diff --git a/src/boost/libs/uuid/test/test_msvc_simd_bug981648_main.cpp b/src/boost/libs/uuid/test/test_msvc_simd_bug981648_main.cpp new file mode 100644 index 00000000..88a65816 --- /dev/null +++ b/src/boost/libs/uuid/test/test_msvc_simd_bug981648_main.cpp @@ -0,0 +1,40 @@ +/* +* Copyright 2014 Andrey Semashev +* +* Distributed under the Boost Software License, Version 1.0. +* See accompanying file LICENSE_1_0.txt or copy at +* https://www.boost.org/LICENSE_1_0.txt +*/ +/* +* This is a part of the test for a workaround for MSVC 12 (VS2013) optimizer bug +* which causes incorrect SIMD code generation for operator==. See: +* +* https://svn.boost.org/trac/boost/ticket/8509#comment:3 +* https://connect.microsoft.com/VisualStudio/feedbackdetail/view/981648#tabs +* +* This file contains the main entry point. +*/ +#include <cstdio> +#include "test_msvc_simd_bug981648.hpp" +extern void mp_grid_update_marker_parameters(headerProperty* header_prop, my_obj ¤t_marker); +static my_obj g_my_obj; +int main(void) +{ +my_obj *p = &g_my_obj; +p->m_uuid = uuid(); +uuid one, two; +one.data[0] = 0; two.data[0] = 1; +//***************************************** +// This != statement generates two movdqu statements or pcmpeqd with a memory operand which crashes +if (one != two) { +std::printf("The first != operator works okay if it reaches this printf.\n"); +} +my_obj a; +a.m_uuid.data[0] = 1; +std::printf("There should be a another printf coming next.\n"); +//***************************************** +// The != statement in this function generates a movups and a movdqu statement. +// It also crashes because the optimizer also creates a pcmpeqd for a non-aligned memory location. +mp_grid_update_marker_parameters(p, a); +return 0; +} diff --git a/src/boost/libs/uuid/test/test_name_generator.cpp b/src/boost/libs/uuid/test/test_name_generator.cpp new file mode 100644 index 00000000..18223b7e --- /dev/null +++ b/src/boost/libs/uuid/test/test_name_generator.cpp @@ -0,0 +1,113 @@ +// (C) Copyright Andy Tompkins 2010. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_name_generator.cpp -------------------------------// + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/uuid/name_generator.hpp> +#include <boost/uuid/name_generator_md5.hpp> +#include <boost/uuid/string_generator.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/config.hpp> +#include <boost/predef/library/c/cloudabi.h> + +int main(int, char*[]) +{ + using namespace boost::uuids; + + // Verify well-known uuid namespaces + BOOST_TEST_EQ(ns::dns(), + string_generator()("6ba7b810-9dad-11d1-80b4-00c04fd430c8")); + BOOST_TEST_EQ(ns::url(), + string_generator()("6ba7b811-9dad-11d1-80b4-00c04fd430c8")); + BOOST_TEST_EQ(ns::oid(), + string_generator()("6ba7b812-9dad-11d1-80b4-00c04fd430c8")); + BOOST_TEST_EQ(ns::x500dn(), + string_generator()("6ba7b814-9dad-11d1-80b4-00c04fd430c8")); + + uuid correct_sha1 = {{0x21, 0xf7, 0xf8, 0xde, 0x80, 0x51, 0x5b, 0x89, 0x86, 0x80, 0x01, 0x95, 0xef, 0x79, 0x8b, 0x6a}}; + uuid wcorrect_sha1 = {{0xc3, 0x15, 0x27, 0x0b, 0xa4, 0x66, 0x58, 0x72, 0xac, 0xa4, 0x96, 0x26, 0xce, 0xc0, 0xf4, 0xbe}}; +#if !defined(BOOST_UUID_COMPAT_PRE_1_71_MD5) + // this value is stable across all endian systems + uuid correct_md5 = {{0x06, 0x20, 0x5c, 0xec, 0x25, 0x5b, 0x30, 0x0e, 0xa8, 0xbc, 0xa8, 0x60, 0x5a, 0xb8, 0x24, 0x4e}}; +#else + // code before 1.71 had different results depending on the endianness +# if BOOST_ENDIAN_LITTLE_BYTE + uuid correct_md5 = {{0xec, 0x5c, 0x20, 0x06, 0x0e, 0x00, 0x3b, 0x25, 0xa0, 0xa8, 0xbc, 0xe8, 0x4e, 0x24, 0xb8, 0x5a}}; +# else + uuid correct_md5 = {{0x06, 0x20, 0x5c, 0xec, 0x25, 0x5b, 0x30, 0x0e, 0xa8, 0xbc, 0xa8, 0x60, 0x5a, 0xb8, 0x24, 0x4e}}; +# endif +#endif + + + name_generator_sha1 gen(ns::dns()); + + uuid u = gen("www.widgets.com"); + BOOST_TEST_EQ(u, correct_sha1); + BOOST_TEST_EQ(u.variant(), boost::uuids::uuid::variant_rfc_4122); + BOOST_TEST_EQ(u.version(), boost::uuids::uuid::version_name_based_sha1); + + // RFC 4122 Section 4.3 Bullet 1, same name in same namespace makes the same UUID + u = gen(std::string("www.widgets.com")); + BOOST_TEST_EQ(u, correct_sha1); + BOOST_TEST_EQ(u.variant(), boost::uuids::uuid::variant_rfc_4122); + + // RFC 4122 Section 4.3 Bullet 2, two names in the same namespace makes a different UUID + uuid u2 = gen("www.wonka.com"); + BOOST_TEST_NE(u, u2); + BOOST_TEST_EQ(u.variant(), boost::uuids::uuid::variant_rfc_4122); + + u = gen(L"www.widgets.com"); + BOOST_TEST_EQ(u, wcorrect_sha1); + BOOST_TEST_EQ(u.variant(), boost::uuids::uuid::variant_rfc_4122); + +#ifndef BOOST_NO_STD_WSTRING + u = gen(std::wstring(L"www.widgets.com")); + BOOST_TEST_EQ(u, wcorrect_sha1); + BOOST_TEST_EQ(u.variant(), boost::uuids::uuid::variant_rfc_4122); +#endif + + char name[] = "www.widgets.com"; + u = gen(name, 15); + BOOST_TEST_EQ(u, correct_sha1); + BOOST_TEST_EQ(u.variant(), boost::uuids::uuid::variant_rfc_4122); + + // RFC 4122 Section 4.3 Bullet 3, same name in different namespaces makes a different UUID + name_generator_sha1 other(ns::url()); + uuid u3 = other("www.widgets.com"); + BOOST_TEST_NE(u, u3); + +#if !BOOST_LIB_C_CLOUDABI + // used by documentation + uuid udoc = gen("boost.org"); + std::cout << "boost.org uuid in dns namespace: " << udoc << std::endl; + // boost.org uuid in dns namespace: 0043f363-bbb4-5369-840a-322df6ec1926 +#endif + + // deprecated equality check, make sure boost::uuids::name_generator is a sha1 generator + name_generator other2(ns::url()); + uuid u4 = other2("www.widgets.com"); + BOOST_TEST_EQ(u3, u4); + + // MD5 generator + name_generator_md5 mdgen(ns::url()); + uuid md = mdgen("www.widgets.com"); + BOOST_TEST_NE(u3, md); + BOOST_TEST_EQ(md.variant(), boost::uuids::uuid::variant_rfc_4122); + BOOST_TEST_EQ(md.version(), boost::uuids::uuid::version_name_based_md5); + BOOST_TEST_EQ(md, correct_md5); + + // latest generator is SHA1 (test will break on change, which is good) + name_generator_latest latestgen(ns::dns()); + uuid latest = latestgen("www.widgets.com"); + BOOST_TEST_EQ(latest, correct_sha1); + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_nil_generator.cpp b/src/boost/libs/uuid/test/test_nil_generator.cpp new file mode 100644 index 00000000..dfd6086e --- /dev/null +++ b/src/boost/libs/uuid/test/test_nil_generator.cpp @@ -0,0 +1,29 @@ +// (C) Copyright Andy Tompkins 2010. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_nil_generator.cpp -------------------------------// + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/uuid/nil_generator.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main(int, char*[]) +{ + using namespace boost::uuids; + + uuid u1 = nil_generator()(); + uuid u2 = {{0}}; + BOOST_TEST_EQ(u1, u2); + + uuid u3 = nil_uuid(); + BOOST_TEST_EQ(u3, u2); + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_random_generator.cpp b/src/boost/libs/uuid/test/test_random_generator.cpp new file mode 100644 index 00000000..0d35e84c --- /dev/null +++ b/src/boost/libs/uuid/test/test_random_generator.cpp @@ -0,0 +1,157 @@ +// (C) Copyright Andy Tompkins 2010. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_random_generator.cpp -------------------------------// + +#include <boost/core/ignore_unused.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/predef/library/c/cloudabi.h> +#include <boost/random.hpp> +#include <boost/uuid/entropy_error.hpp> +#include <boost/uuid/random_generator.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/uuid/uuid.hpp> +#include <boost/move/utility_core.hpp> + +template <typename RandomUuidGenerator> +void check_random_generator(RandomUuidGenerator& uuid_gen) +{ + boost::uuids::uuid u1 = uuid_gen(); + boost::uuids::uuid u2 = uuid_gen(); + + BOOST_TEST_NE(u1, u2); + + // check variant + BOOST_TEST_EQ(u1.variant(), boost::uuids::uuid::variant_rfc_4122); + + // version + BOOST_TEST_EQ(u1.version(), boost::uuids::uuid::version_random_number_based); +} + +// This is the example block from the documentation - ensure it works! +void test_examples() +{ + // Depending on the platform there may be a setup cost in + // initializing the generator so plan to reuse it if you can. + boost::uuids::random_generator gen; + boost::uuids::uuid id = gen(); + boost::uuids::uuid id2 = gen(); +#if !BOOST_LIB_C_CLOUDABI + std::cout << id << std::endl; + std::cout << id2 << std::endl; +#endif + BOOST_TEST_NE(id, id2); + boost::ignore_unused(id); + boost::ignore_unused(id2); + + // You can still use a PseudoRandomNumberGenerator to create + // UUIDs, however this is not the preferred mechanism. For + // large numbers of UUIDs this may be more CPU efficient but + // it comes with all the perils of a PRNG. The test code + // in test_bench_random identifies the transition point for + // a given system. + boost::uuids::random_generator_mt19937 bulkgen; + for (size_t i = 0; i < 1000; ++i) + { + boost::uuids::uuid u = bulkgen(); + // do something with u + boost::ignore_unused(u); + } +} + +int main(int, char*[]) +{ + using namespace boost::uuids; + + // default random number generator + { + random_generator uuid_gen1; + check_random_generator(uuid_gen1); +#if !BOOST_LIB_C_CLOUDABI + // dump 10 of them to cout for observation + for (size_t i = 0; i < 10; ++i) + { + std::cout << uuid_gen1() << std::endl; + } +#endif + } + + // specific random number generator + { + basic_random_generator<boost::rand48> uuid_gen2; + check_random_generator(uuid_gen2); + } + + // pass by reference + { + boost::ecuyer1988 ecuyer1988_gen; + basic_random_generator<boost::ecuyer1988> uuid_gen3(ecuyer1988_gen); + check_random_generator(uuid_gen3); + } + + // pass by pointer + { + boost::lagged_fibonacci607 lagged_fibonacci607_gen; + basic_random_generator<boost::lagged_fibonacci607> uuid_gen4(&lagged_fibonacci607_gen); + check_random_generator(uuid_gen4); + } + + // check move construction + { + random_generator uuid_gen1; + random_generator uuid_gen2(boost::move(uuid_gen1)); + boost::ignore_unused(uuid_gen2); + } + { + basic_random_generator<boost::rand48> uuid_gen1; + basic_random_generator<boost::rand48> uuid_gen2(boost::move(uuid_gen1)); + boost::ignore_unused(uuid_gen2); + } + + // check move assignment + { + random_generator uuid_gen1, uuid_gen2; + uuid_gen2 = boost::move(uuid_gen1); + boost::ignore_unused(uuid_gen2); + } + { + basic_random_generator<boost::rand48> uuid_gen1, uuid_gen2; + uuid_gen2 = boost::move(uuid_gen1); + boost::ignore_unused(uuid_gen2); + } + + // there was a bug in basic_random_generator where it did not + // produce very random numbers. This checks for that bug. + { + random_generator_mt19937 bulkgen; + uuid u = bulkgen(); + if ((u.data[4] == u.data[12]) && + (u.data[5] == u.data[9] && u.data[5] == u.data[13]) && + (u.data[7] == u.data[11] && u.data[7] == u.data[15]) && + (u.data[10] == u.data[14])) + { + BOOST_ERROR("basic_random_generator is not producing random uuids"); + } + + // pseudo + check_random_generator(bulkgen); + } + + // make sure default construction seeding is happening for PRNGs + { + random_generator_mt19937 gen1; + random_generator_mt19937 gen2; + BOOST_TEST_NE(gen1(), gen2()); + } + + // The example code snippet in the documentation + test_examples(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_serialization.cpp b/src/boost/libs/uuid/test/test_serialization.cpp new file mode 100644 index 00000000..d24038d5 --- /dev/null +++ b/src/boost/libs/uuid/test/test_serialization.cpp @@ -0,0 +1,71 @@ +// (C) Copyright Andy Tompkins 2007. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// Purpose to test serializing uuids with narrow archives + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <iostream> + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_serialize.hpp> +#include <boost/uuid/uuid_io.hpp> + +#include <boost/archive/text_oarchive.hpp> +#include <boost/archive/text_iarchive.hpp> + +#include <boost/archive/xml_oarchive.hpp> +#include <boost/archive/xml_iarchive.hpp> + +#include <boost/archive/binary_oarchive.hpp> +#include <boost/archive/binary_iarchive.hpp> + +template <class OArchiveType, class IArchiveType, class OStringStreamType, class IStringStreamType> +void test_archive() +{ + using namespace std; + using namespace boost::uuids; + + OStringStreamType o_stream; + + uuid u1 = {{0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef}}; + + uuid u2; + + // save + { + OArchiveType oa(o_stream); + + oa << BOOST_SERIALIZATION_NVP(u1); + } + + //cout << "stream:" << o_stream.str() << "\n\n"; + + // load + { + IStringStreamType i_stream(o_stream.str()); + IArchiveType ia(i_stream); + + ia >> BOOST_SERIALIZATION_NVP(u2); + } + + BOOST_TEST_EQ(u1, u2); +} + +int main( int /* argc */, char* /* argv */[] ) +{ + using namespace std; + using namespace boost::archive; + + test_archive<text_oarchive, text_iarchive, ostringstream, istringstream>(); + test_archive<xml_oarchive, xml_iarchive, ostringstream, istringstream>(); + test_archive<binary_oarchive, binary_iarchive, ostringstream, istringstream>(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_sha1.cpp b/src/boost/libs/uuid/test/test_sha1.cpp new file mode 100644 index 00000000..9685a42d --- /dev/null +++ b/src/boost/libs/uuid/test/test_sha1.cpp @@ -0,0 +1,259 @@ +// (C) Copyright Andy Tompkins 2007. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +// Copyright (C) 2019 James E. King III +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_sha1.cpp -------------------------------// + +#include <boost/uuid/detail/sha1.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <algorithm> +#include <cstring> +#include <cstddef> + +#include "digestutils.hpp" + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std { + using ::strlen; + using ::size_t; +} //namespace std +#endif + +#define BOOST_TEST_SHA1_DIGEST(lhs, rhs) \ + ( boost::uuids::test::test_digest_equal_array(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, (lhs), (rhs), 20) ) + +void test_quick() +{ + typedef struct + { + const char * data; + boost::uint32_t len; + unsigned char expected[20]; + } Expectation; + + /* http://www.febooti.com/products/filetweak/members/hash-and-crc/test-vectors/ */ + Expectation expectations[3] = { + { "The quick brown fox jumps over the lazy dog", 43, + { 0x2f, 0xd4, 0xe1, 0xc6, 0x7a, 0x2d, 0x28, 0xfc, 0xed, 0x84, + 0x9e, 0xe1, 0xbb, 0x76, 0xe7, 0x39, 0x1b, 0x93, 0xeb, 0x12 }}, + { "Test vector from febooti.com", 28, + { 0xa7, 0x63, 0x17, 0x95, 0xf6, 0xd5, 0x9c, 0xd6, 0xd1, 0x4e, + 0xbd, 0x00, 0x58, 0xa6, 0x39, 0x4a, 0x4b, 0x93, 0xd8, 0x68 }}, + { "", 0, + { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, + 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09 }} + }; + + for (boost::uint32_t i = 0; i < 3; ++i) { + boost::uuids::detail::sha1 hash; + hash.process_bytes(expectations[i].data, expectations[i].len); + boost::uuids::detail::sha1::digest_type result; + hash.get_digest(result); + unsigned char raw_result[20]; + boost::uuids::test::copy_raw_digest(raw_result, result, 5); + BOOST_TEST_SHA1_DIGEST(raw_result, expectations[i].expected); + BOOST_TEST_EQ(0, memcmp(raw_result, expectations[i].expected, 20)); + BOOST_TEST_EQ(hash.get_version(), 0x05); + } +} + +//SHA Test Vector for Hashing Byte-Oriented Messages +//http://csrc.nist.gov/cryptval/shs.htm +//http://csrc.nist.gov/cryptval/shs/shabytetestvectors.zip +//values from SHA1ShortMsg.txt +void test_short_messages() +{ + struct test_case + { + char const* message; + unsigned int digest[5]; + }; + test_case cases[] = + { { "", + { 0xda39a3ee, 0x5e6b4b0d, 0x3255bfef, 0x95601890, 0xafd80709 } } + , { "a8", + { 0x99f2aa95, 0xe36f95c2, 0xacb0eaf2, 0x3998f030, 0x638f3f15 } } + , { "3000", + { 0xf944dcd6, 0x35f9801f, 0x7ac90a40, 0x7fbc4799, 0x64dec024 } } + , { "42749e", + { 0xa444319e, 0x9b6cc1e8, 0x464c511e, 0xc0969c37, 0xd6bb2619 } } + , { "9fc3fe08", + { 0x16a0ff84, 0xfcc156fd, 0x5d3ca3a7, 0x44f20a23, 0x2d172253 } } + , { "b5c1c6f1af", + { 0xfec9deeb, 0xfcdedaf6, 0x6dda525e, 0x1be43597, 0xa73a1f93 } } + , { "e47571e5022e", + { 0x8ce05118, 0x1f0ed5e9, 0xd0c498f6, 0xbc4caf44, 0x8d20deb5 } } + , { "3e1b28839fb758", + { 0x67da5383, 0x7d89e03b, 0xf652ef09, 0xc369a341, 0x5937cfd3 } } + , { "a81350cbb224cb90", + { 0x305e4ff9, 0x888ad855, 0xa78573cd, 0xdf4c5640, 0xcce7e946 } } + , { "c243d167923dec3ce1", + { 0x5902b77b, 0x3265f023, 0xf9bbc396, 0xba1a93fa, 0x3509bde7 } } + , { "50ac18c59d6a37a29bf4", + { 0xfcade5f5, 0xd156bf6f, 0x9af97bdf, 0xa9c19bcc, 0xfb4ff6ab } } + , { "98e2b611ad3b1cccf634f6", + { 0x1d20fbe0, 0x0533c10e, 0x3cbd6b27, 0x088a5de0, 0xc632c4b5 } } + , { "73fe9afb68e1e8712e5d4eec", + { 0x7e1b7e0f, 0x7a8f3455, 0xa9c03e95, 0x80fd63ae, 0x205a2d93 } } + , { "9e701ed7d412a9226a2a130e66", + { 0x706f0677, 0x146307b2, 0x0bb0e8d6, 0x311e3299, 0x66884d13 } } + , { "6d3ee90413b0a7cbf69e5e6144ca", + { 0xa7241a70, 0x3aaf0d53, 0xfe142f86, 0xbf2e8492, 0x51fa8dff } } + , { "fae24d56514efcb530fd4802f5e71f", + { 0x400f5354, 0x6916d33a, 0xd01a5e6d, 0xf66822df, 0xbdc4e9e6 } } + , { "c5a22dd6eda3fe2bdc4ddb3ce6b35fd1", + { 0xfac8ab93, 0xc1ae6c16, 0xf0311872, 0xb984f729, 0xdc928ccd } } + , { "d98cded2adabf08fda356445c781802d95", + { 0xfba6d750, 0xc18da58f, 0x6e2aab10, 0x112b9a5e, 0xf3301b3b } } + , { "bcc6d7087a84f00103ccb32e5f5487a751a2", + { 0x29d27c2d, 0x44c205c8, 0x107f0351, 0xb05753ac, 0x708226b6 } } + , { "36ecacb1055434190dbbc556c48bafcb0feb0d", + { 0xb971bfc1, 0xebd6f359, 0xe8d74cb7, 0xecfe7f89, 0x8d0ba845 } } + , { "5ff9edb69e8f6bbd498eb4537580b7fba7ad31d0", + { 0x96d08c43, 0x0094b9fc, 0xc164ad2f, 0xb6f72d0a, 0x24268f68 } } + , { "c95b441d8270822a46a798fae5defcf7b26abace36", + { 0xa287ea75, 0x2a593d52, 0x09e28788, 0x1a09c49f, 0xa3f0beb1 } } + , { "83104c1d8a55b28f906f1b72cb53f68cbb097b44f860", + { 0xa06c7137, 0x79cbd885, 0x19ed4a58, 0x5ac0cb8a, 0x5e9d612b } } + , { "755175528d55c39c56493d697b790f099a5ce741f7754b", + { 0xbff7d52c, 0x13a36881, 0x32a1d407, 0xb1ab40f5, 0xb5ace298 } } + , { "088fc38128bbdb9fd7d65228b3184b3faac6c8715f07272f", + { 0xc7566b91, 0xd7b6f56b, 0xdfcaa978, 0x1a7b6841, 0xaacb17e9 } } + , { "a4a586eb9245a6c87e3adf1009ac8a49f46c07e14185016895", + { 0xffa30c0b, 0x5c550ea4, 0xb1e34f8a, 0x60ec9295, 0xa1e06ac1 } } + , { "8e7c555270c006092c2a3189e2a526b873e2e269f0fb28245256", + { 0x29e66ed2, 0x3e914351, 0xe872aa76, 0x1df6e4f1, 0xa07f4b81 } } + , { "a5f3bfa6bb0ba3b59f6b9cbdef8a558ec565e8aa3121f405e7f2f0", + { 0xb28cf5e5, 0xb806a014, 0x91d41f69, 0xbd924876, 0x5c5dc292 } } + , { "589054f0d2bd3c2c85b466bfd8ce18e6ec3e0b87d944cd093ba36469", + { 0x60224fb7, 0x2c460696, 0x52cd78bc, 0xd08029ef, 0x64da62f3 } } + , { "a0abb12083b5bbc78128601bf1cbdbc0fdf4b862b24d899953d8da0ff3", + { 0xb72c4a86, 0xf72608f2, 0x4c05f3b9, 0x088ef92f, 0xba431df7 } } + , { "82143f4cea6fadbf998e128a8811dc75301cf1db4f079501ea568da68eeb", + { 0x73779ad5, 0xd6b71b9b, 0x8328ef72, 0x20ff12eb, 0x167076ac } } + , { "9f1231dd6df1ff7bc0b0d4f989d048672683ce35d956d2f57913046267e6f3", + { 0xa09671d4, 0x452d7cf5, 0x0015c914, 0xa1e31973, 0xd20cc1a0 } } + , { "041c512b5eed791f80d3282f3a28df263bb1df95e1239a7650e5670fc2187919", + { 0xe88cdcd2, 0x33d99184, 0xa6fd260b, 0x8fca1b7f, 0x7687aee0 } } + , { "17e81f6ae8c2e5579d69dafa6e070e7111461552d314b691e7a3e7a4feb3fae418", + { 0x010def22, 0x850deb11, 0x68d525e8, 0xc84c2811, 0x6cb8a269 } } + , { "d15976b23a1d712ad28fad04d805f572026b54dd64961fda94d5355a0cc98620cf77", + { 0xaeaa40ba, 0x1717ed54, 0x39b1e6ea, 0x901b294b, 0xa500f9ad } } + , { "09fce4d434f6bd32a44e04b848ff50ec9f642a8a85b37a264dc73f130f22838443328f", + { 0xc6433791, 0x238795e3, 0x4f080a5f, 0x1f1723f0, 0x65463ca0 } } + , { "f17af27d776ec82a257d8d46d2b46b639462c56984cc1be9c1222eadb8b26594a25c709d", + { 0xe21e22b8, 0x9c1bb944, 0xa32932e6, 0xb2a2f20d, 0x491982c3 } } + , { "b13ce635d6f8758143ffb114f2f601cb20b6276951416a2f94fbf4ad081779d79f4f195b22", + { 0x575323a9, 0x661f5d28, 0x387964d2, 0xba6ab92c, 0x17d05a8a } } + , { "5498793f60916ff1c918dde572cdea76da8629ba4ead6d065de3dfb48de94d234cc1c5002910", + { 0xfeb44494, 0xaf72f245, 0xbfe68e86, 0xc4d7986d, 0x57c11db7 } } + , { "498a1e0b39fa49582ae688cd715c86fbaf8a81b8b11b4d1594c49c902d197c8ba8a621fd6e3be5", + { 0xcff2290b, 0x3648ba28, 0x31b98dde, 0x436a72f9, 0xebf51eee } } + , { "3a36ae71521f9af628b3e34dcb0d4513f84c78ee49f10416a98857150b8b15cb5c83afb4b570376e", + { 0x9b4efe9d, 0x27b96590, 0x5b0c3dab, 0x67b8d7c9, 0xebacd56c } } + , { "dcc76b40ae0ea3ba253e92ac50fcde791662c5b6c948538cffc2d95e9de99cac34dfca38910db2678f", + { 0xafedb0ff, 0x156205bc, 0xd831cbdb, 0xda43db8b, 0x0588c113 } } + , { "5b5ec6ec4fd3ad9c4906f65c747fd4233c11a1736b6b228b92e90cddabb0c7c2fcf9716d3fad261dff33", + { 0x8deb1e85, 0x8f88293a, 0x5e5e4d52, 0x1a34b2a4, 0xefa70fc4 } } + , { "df48a37b29b1d6de4e94717d60cdb4293fcf170bba388bddf7a9035a15d433f20fd697c3e4c8b8c5f590ab", + { 0x95cbdac0, 0xf74afa69, 0xcebd0e5c, 0x7defbc6f, 0xaf0cbeaf } } + , { "1f179b3b82250a65e1b0aee949e218e2f45c7a8dbfd6ba08de05c55acfc226b48c68d7f7057e5675cd96fcfc", + { 0xf0307bcb, 0x92842e5a, 0xe0cd4f4f, 0x14f3df7f, 0x877fbef2 } } + , { "ee3d72da3a44d971578972a8e6780ce64941267e0f7d0179b214fa97855e1790e888e09fbe3a70412176cb3b54", + { 0x7b13bb0d, 0xbf14964b, 0xd63b133a, 0xc85e2210, 0x0542ef55 } } + , { "d4d4c7843d312b30f610b3682254c8be96d5f6684503f8fbfbcd15774fc1b084d3741afb8d24aaa8ab9c104f7258", + { 0xc314d2b6, 0xcf439be6, 0x78d2a74e, 0x890d96cf, 0xac1c02ed } } + , { "32c094944f5936a190a0877fb9178a7bf60ceae36fd530671c5b38c5dbd5e6a6c0d615c2ac8ad04b213cc589541cf6", + { 0x4d0be361, 0xe410b47a, 0x9d67d8ce, 0x0bb6a8e0, 0x1c53c078 } } + , { "e5d3180c14bf27a5409fa12b104a8fd7e9639609bfde6ee82bbf9648be2546d29688a65e2e3f3da47a45ac14343c9c02", + { 0xe5353431, 0xffae097f, 0x675cbf49, 0x8869f6fb, 0xb6e1c9f2 } } + , { "e7b6e4b69f724327e41e1188a37f4fe38b1dba19cbf5a7311d6e32f1038e97ab506ee05aebebc1eed09fc0e357109818b9", + { 0xb8720a70, 0x68a085c0, 0x18ab1896, 0x1de2765a, 0xa6cd9ac4 } } + , { "bc880cb83b8ac68ef2fedc2da95e7677ce2aa18b0e2d8b322701f67af7d5e7a0d96e9e33326ccb7747cfff0852b961bfd475", + { 0xb0732181, 0x568543ba, 0x85f2b6da, 0x602b4b06, 0x5d9931aa } } + , { "235ea9c2ba7af25400f2e98a47a291b0bccdaad63faa2475721fda5510cc7dad814bce8dabb611790a6abe56030b798b75c944", + { 0x9c22674c, 0xf3222c3b, 0xa9216726, 0x94aafee4, 0xce67b96b } } + , { "07e3e29fed63104b8410f323b975fd9fba53f636af8c4e68a53fb202ca35dd9ee07cb169ec5186292e44c27e5696a967f5e67709", + { 0xd128335f, 0x4cecca90, 0x66cdae08, 0x958ce656, 0xff0b4cfc } } + , { "65d2a1dd60a517eb27bfbf530cf6a5458f9d5f4730058bd9814379547f34241822bf67e6335a6d8b5ed06abf8841884c636a25733f", + { 0x0b67c57a, 0xc578de88, 0xa2ae055c, 0xaeaec8bb, 0x9b0085a0 } } + , { "dcc86b3bd461615bab739d8daafac231c0f462e819ad29f9f14058f3ab5b75941d4241ea2f17ebb8a458831b37a9b16dead4a76a9b0e", + { 0xc766f912, 0xa89d4ccd, 0xa88e0cce, 0x6a713ef5, 0xf178b596 } } + , { "4627d54f0568dc126b62a8c35fb46a9ac5024400f2995e51635636e1afc4373dbb848eb32df23914230560b82477e9c3572647a7f2bb92", + { 0x9aa3925a, 0x9dcb177b, 0x15ccff9b, 0x78e70cf3, 0x44858779 } } + , { "ba531affd4381168ef24d8b275a84d9254c7f5cc55fded53aa8024b2c5c5c8aa7146fe1d1b83d62b70467e9a2e2cb67b3361830adbab28d7", + { 0x4811fa30, 0x042fc076, 0xacf37c8e, 0x2274d025, 0x307e5943 } } + , { "8764dcbcf89dcf4282eb644e3d568bdccb4b13508bfa7bfe0ffc05efd1390be22109969262992d377691eb4f77f3d59ea8466a74abf57b2ef4", + { 0x67430184, 0x50c97307, 0x61ee2b13, 0x0df9b91c, 0x1e118150 } } + , { "497d9df9ddb554f3d17870b1a31986c1be277bc44feff713544217a9f579623d18b5ffae306c25a45521d2759a72c0459b58957255ab592f3be4", + { 0x71ad4a19, 0xd37d92a5, 0xe6ef3694, 0xddbeb5aa, 0x61ada645 } } + , { "72c3c2e065aefa8d9f7a65229e818176eef05da83f835107ba90ec2e95472e73e538f783b416c04654ba8909f26a12db6e5c4e376b7615e4a25819", + { 0xa7d9dc68, 0xdacefb7d, 0x61161860, 0x48cb355c, 0xc548e11d } } + , { "7cc9894454d0055ab5069a33984e2f712bef7e3124960d33559f5f3b81906bb66fe64da13c153ca7f5cabc89667314c32c01036d12ecaf5f9a78de98", + { 0x142e429f, 0x0522ba5a, 0xbf5131fa, 0x81df82d3, 0x55b96909 } } + , { "74e8404d5a453c5f4d306f2cfa338ca65501c840ddab3fb82117933483afd6913c56aaf8a0a0a6b2a342fc3d9dc7599f4a850dfa15d06c61966d74ea59", + { 0xef72db70, 0xdcbcab99, 0x1e963797, 0x6c6faf00, 0xd22caae9 } } + , { "46fe5ed326c8fe376fcc92dc9e2714e2240d3253b105adfbb256ff7a19bc40975c604ad7c0071c4fd78a7cb64786e1bece548fa4833c04065fe593f6fb10", + { 0xf220a745, 0x7f4588d6, 0x39dc2140, 0x7c942e98, 0x43f8e26b } } + , { "836dfa2524d621cf07c3d2908835de859e549d35030433c796b81272fd8bc0348e8ddbc7705a5ad1fdf2155b6bc48884ac0cd376925f069a37849c089c8645", + { 0xddd2117b, 0x6e309c23, 0x3ede85f9, 0x62a0c2fc, 0x215e5c69 } } + , { "7e3a4c325cb9c52b88387f93d01ae86d42098f5efa7f9457388b5e74b6d28b2438d42d8b64703324d4aa25ab6aad153ae30cd2b2af4d5e5c00a8a2d0220c6116", + { 0xa3054427, 0xcdb13f16, 0x4a610b34, 0x8702724c, 0x808a0dcc } } + }; + + char const xdigits[17] = "0123456789abcdef"; + char const*const xdigits_end = xdigits+16; + + for (std::size_t i=0; i!=sizeof(cases)/sizeof(cases[0]); ++i) { + test_case const& tc = cases[i]; + + boost::uuids::detail::sha1 sha; + std::size_t message_length = std::strlen(tc.message); + BOOST_TEST_EQ(message_length % 2, 0u); + + for (std::size_t b=0; b<message_length; b+=2) { + char c = tc.message[b]; + char const* f = std::find(xdigits, xdigits_end, c); + BOOST_TEST_NE(f, xdigits_end); + + unsigned char byte = static_cast<unsigned char>(std::distance(&xdigits[0], f)); + + c = tc.message[b+1]; + f = std::find(xdigits, xdigits_end, c); + BOOST_TEST_NE(f, xdigits_end); + + byte <<= 4; + byte |= static_cast<unsigned char>(std::distance(&xdigits[0], f)); + + sha.process_byte(byte); + } + + unsigned int digest[5]; + sha.get_digest(digest); + + BOOST_TEST_SHA1_DIGEST(reinterpret_cast<const unsigned char *>(&digest[0]), + reinterpret_cast<const unsigned char *>(&tc.digest[0])); + } +} + +void test_version() +{ + boost::uuids::detail::sha1 sha; + BOOST_TEST_EQ(sha.get_version(), 0x05); +} + +int main(int, char*[]) +{ + test_quick(); + test_short_messages(); + test_version(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_string_generator.cpp b/src/boost/libs/uuid/test/test_string_generator.cpp new file mode 100644 index 00000000..5ac943cf --- /dev/null +++ b/src/boost/libs/uuid/test/test_string_generator.cpp @@ -0,0 +1,90 @@ +// (C) Copyright Andy Tompkins 2010. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_string_generator.cpp -------------------------------// + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/uuid/string_generator.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/config.hpp> +#include <stdexcept> +#include <string> + +int main(int, char*[]) +{ + using namespace boost::uuids; + + uuid nil_uuid = {{0}}; + BOOST_TEST_EQ(nil_uuid.is_nil(), true); + + string_generator gen; + uuid u = gen("00000000-0000-0000-0000-000000000000"); + BOOST_TEST_EQ(u, nil_uuid); + BOOST_TEST_EQ(u.is_nil(), true); + + const uuid u_increasing = {{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }}; + const uuid u_decreasing = {{ 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }}; + + u = gen("0123456789abcdef0123456789ABCDEF"); + BOOST_TEST_EQ(memcmp(&u, &u_increasing, sizeof(uuid)), 0); + BOOST_TEST_EQ(u, u_increasing); + + u = gen("{0123456789abcdef0123456789ABCDEF}"); + BOOST_TEST_EQ(u, u_increasing); + + u = gen("{01234567-89AB-CDEF-0123-456789abcdef}"); + BOOST_TEST_EQ(u, u_increasing); + + u = gen("01234567-89AB-CDEF-0123-456789abcdef"); + BOOST_TEST_EQ(u, u_increasing); + + u = gen(std::string("fedcba98-7654-3210-fedc-ba9876543210")); + BOOST_TEST_EQ(u, u_decreasing); + +#ifndef BOOST_NO_STD_WSTRING + u = gen(L"fedcba98-7654-3210-fedc-ba9876543210"); + BOOST_TEST_EQ(u, u_decreasing); + + u = gen(std::wstring(L"01234567-89ab-cdef-0123-456789abcdef")); + BOOST_TEST_EQ(u, u_increasing); + + u = gen(std::wstring(L"{01234567-89ab-cdef-0123-456789abcdef}")); + BOOST_TEST_EQ(u, u_increasing); +#endif //BOOST_NO_STD_WSTRING + + const char raw[36] = { '0', '1', '2', '3', '4', '5', '6', '7', '-', + '8', '9', 'a', 'b', '-', + 'c', 'd', 'e', 'f', '-', + 0 , '1', '2', '3', '-', // 0x00 character is intentional + '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + BOOST_TEST_THROWS(gen(std::string(raw, 36)), std::runtime_error); + + BOOST_TEST_THROWS(gen("01234567-89ab-cdef-0123456789abcdef"), std::runtime_error); + BOOST_TEST_THROWS(gen("01234567-89ab-cdef0123-456789abcdef"), std::runtime_error); + BOOST_TEST_THROWS(gen("01234567-89abcdef-0123-456789abcdef"), std::runtime_error); + BOOST_TEST_THROWS(gen("0123456789ab-cdef-0123-456789abcdef"), std::runtime_error); + + BOOST_TEST_THROWS(gen("{01234567-89AB-CDEF-0123-456789abcdef)"), std::runtime_error); + BOOST_TEST_THROWS(gen("{01234567-89AB-CDEF-0123-456789abcdef"), std::runtime_error); + BOOST_TEST_THROWS(gen("01234567-89AB-CDEF-0123-456789abcdef}"), std::runtime_error); +#ifndef BOOST_NO_STD_WSTRING + BOOST_TEST_THROWS(gen(std::wstring(L"{01234567-89AB-CDEF-0123-456789abcdef)")), std::runtime_error); + BOOST_TEST_THROWS(gen(std::wstring(L"{01234567-89AB-CDEF-0123-456789abcdef")), std::runtime_error); + BOOST_TEST_THROWS(gen(std::wstring(L"01234567-89AB-CDEF-0123-456789abcdef}")), std::runtime_error); + BOOST_TEST_THROWS(gen(std::wstring(L"G1234567-89AB-CDEF-0123-456789abcdef}")), std::runtime_error); +#endif //BOOST_NO_STD_WSTRING + + BOOST_TEST_THROWS(gen("G1234567-89AB-CDEF-0123-456789abcdef"), std::runtime_error); + BOOST_TEST_THROWS(gen("Have a great big roast-beef sandwich!"), std::runtime_error); + + BOOST_TEST_THROWS(gen("83f8638b-8dca-4152-zzzz-2ca8b33039b4"), std::runtime_error); + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_tagging.cpp b/src/boost/libs/uuid/test/test_tagging.cpp new file mode 100644 index 00000000..83b201f5 --- /dev/null +++ b/src/boost/libs/uuid/test/test_tagging.cpp @@ -0,0 +1,80 @@ +// (C) Copyright Andy Tompkins 2009. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_tagging.cpp -------------------------------// + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_generators.hpp> +#include <boost/detail/lightweight_test.hpp> + +class object +{ +public: + object() + : tag(boost::uuids::random_generator()()) + , state(0) + {} + + explicit object(int state) + : tag(boost::uuids::random_generator()()) + , state(state) + {} + + object(object const& rhs) + : tag(rhs.tag) + , state(rhs.state) + {} + + bool operator==(object const& rhs) const { + return tag == rhs.tag; + } + bool operator!=(object const& rhs) const { + return !(operator==(rhs)); + } + + object& operator=(object const& rhs) { + tag = rhs.tag; + state = rhs.state; + return *this; + } + + int get_state() const { return state; } + void set_state(int new_state) { state = new_state; } + +private: + boost::uuids::uuid tag; + + int state; +}; + +template <typename elem, typename traits> +std::basic_ostream<elem, traits>& operator<<(std::basic_ostream<elem, traits>& os, object const& o) +{ + os << o.get_state(); + return os; +} + +int main(int, char*[]) +{ + object o1(1); + + object o2 = o1; + BOOST_TEST_EQ(o1, o2); + + o2.set_state(2); + BOOST_TEST_EQ(o1, o2); + + object o3; + o3.set_state(3); + + BOOST_TEST_NE(o1, o3); + BOOST_TEST_NE(o2, o3); + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_uuid.cpp b/src/boost/libs/uuid/test/test_uuid.cpp new file mode 100644 index 00000000..6b9dc719 --- /dev/null +++ b/src/boost/libs/uuid/test/test_uuid.cpp @@ -0,0 +1,245 @@ +// (C) Copyright Andy Tompkins 2007. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_uuid.cpp -------------------------------// + +#include <iostream> +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/functional/hash.hpp> +#include <boost/current_function.hpp> + +void test_uuid_equal_array(char const * file, int line, char const * function, + boost::uuids::uuid const& lhs, const unsigned char (&rhs)[16]) +{ + for (size_t i=0; i<16; i++) { + if ( *(lhs.begin()+i) != rhs[i]) { + std::cerr << file << "(" << line << "): uuid " << lhs << " not equal " << "{"; + for (size_t j=0; j<16; j++) { + if (j != 0) { + std::cerr << " "; + } + std::cerr << std::hex << (int)rhs[j]; + } + std::cerr << "} in function '" << function << "'" << std::endl; + ++boost::detail::test_errors(); + return; + } + } +} + + +#define BOOST_TEST_UUID(lhs, rhs) ( test_uuid_equal_array(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, lhs, rhs) ) + +int main(int, char*[]) +{ + using namespace boost::uuids; + + // uuid::static_size + BOOST_TEST_EQ(uuid::static_size(), 16U); + + { // uuid::operator=() + uuid u1 = {{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}}; + uuid u2 = u1; + BOOST_TEST_EQ(u2, u1); + } + + { // uuid::begin(), end() + uuid u = {{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}}; + unsigned char values[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; + BOOST_TEST_UUID(u, values); + } + + { // uuid::begin() const, end() const + const uuid u = {{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}}; + unsigned char values[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; + BOOST_TEST_UUID(u, values); + } + + { // uuid::size() + uuid u; // uninitialized + BOOST_TEST_EQ(u.size(), 16U); + } + + { // uuid::is_nil() + uuid u1 = {{0}}; + BOOST_TEST_EQ(u1.is_nil(), true); + + uuid u2 = {{1,0}}; + BOOST_TEST_EQ(u2.is_nil(), false); + } + + { // uuid::variant() + struct Test { + unsigned char octet7; + boost::uuids::uuid::variant_type variant; + }; + const Test tests[] = + { { 0x00, boost::uuids::uuid::variant_ncs } + , { 0x10, boost::uuids::uuid::variant_ncs } + , { 0x20, boost::uuids::uuid::variant_ncs } + , { 0x30, boost::uuids::uuid::variant_ncs } + , { 0x40, boost::uuids::uuid::variant_ncs } + , { 0x50, boost::uuids::uuid::variant_ncs } + , { 0x60, boost::uuids::uuid::variant_ncs } + , { 0x70, boost::uuids::uuid::variant_ncs } + , { 0x80, boost::uuids::uuid::variant_rfc_4122 } + , { 0x90, boost::uuids::uuid::variant_rfc_4122 } + , { 0xa0, boost::uuids::uuid::variant_rfc_4122 } + , { 0xb0, boost::uuids::uuid::variant_rfc_4122 } + , { 0xc0, boost::uuids::uuid::variant_microsoft } + , { 0xd0, boost::uuids::uuid::variant_microsoft } + , { 0xe0, boost::uuids::uuid::variant_future } + , { 0xf0, boost::uuids::uuid::variant_future } + }; + for (size_t i=0; i<sizeof(tests)/sizeof(Test); i++) { + uuid u = { {} }; + u.data[8] = tests[i].octet7; // note that octet7 is array index 8 + + BOOST_TEST_EQ(u.variant(), tests[i].variant); + } + } + + { // uuid::version() + struct Test { + unsigned char octet9; + boost::uuids::uuid::version_type version; + }; + const Test tests[] = + { { 0x00, boost::uuids::uuid::version_unknown } + , { 0x10, boost::uuids::uuid::version_time_based } + , { 0x20, boost::uuids::uuid::version_dce_security } + , { 0x30, boost::uuids::uuid::version_name_based_md5 } + , { 0x40, boost::uuids::uuid::version_random_number_based } + , { 0x50, boost::uuids::uuid::version_name_based_sha1 } + , { 0x60, boost::uuids::uuid::version_unknown } + , { 0x70, boost::uuids::uuid::version_unknown } + , { 0x80, boost::uuids::uuid::version_unknown } + , { 0x90, boost::uuids::uuid::version_unknown } + , { 0xa0, boost::uuids::uuid::version_unknown } + , { 0xb0, boost::uuids::uuid::version_unknown } + , { 0xc0, boost::uuids::uuid::version_unknown } + , { 0xd0, boost::uuids::uuid::version_unknown } + , { 0xe0, boost::uuids::uuid::version_unknown } + , { 0xf0, boost::uuids::uuid::version_unknown } + }; + for (size_t i=0; i<sizeof(tests)/sizeof(Test); i++) { + uuid u = {{0}}; + u.data[6] = tests[i].octet9; // note that octet9 is array index 8 + + BOOST_TEST_EQ(u.version(), tests[i].version); + } + } + + { // uuid::swap(), swap() + uuid u1 = {{0}}; + uuid u2 = {{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}}; + u1.swap(u2); + + unsigned char values1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + unsigned char values2[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; + BOOST_TEST_UUID(u1, values2); + BOOST_TEST_UUID(u2, values1); + + swap(u1, u2); + BOOST_TEST_UUID(u1, values1); + BOOST_TEST_UUID(u2, values2); + } + + { // test comparsion + uuid u1 = {{0}}; + uuid u2 = {{1,0}}; + uuid u3 = {{255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}}; + uuid u4 = {{0,1,0}}; + uuid u5 = {{0,255,0}}; + + BOOST_TEST_EQ(u1, u1); + + BOOST_TEST_NE(u1, u2); + + BOOST_TEST(u1 < u2); + BOOST_TEST(u2 < u3); + BOOST_TEST(u1 < u4); + BOOST_TEST(u1 < u5); + BOOST_TEST(u4 < u5); + BOOST_TEST(u4 < u2); + BOOST_TEST(u5 < u2); + + BOOST_TEST(u1 <= u1); + BOOST_TEST(u1 <= u2); + BOOST_TEST(u2 <= u3); + + BOOST_TEST(u2 >= u1); + BOOST_TEST(u3 >= u1); + + BOOST_TEST(u3 >= u3); + BOOST_TEST(u2 >= u1); + BOOST_TEST(u3 >= u1); + } + + { // ticket 10510 + // the uuids in the report + uuid u6 = {{0x14,0x5c,0xfc,0x95,0x80,0x50,0x45,0x5a,0x83,0x82,0x44,0xca,0x57,0xc1,0x48,0x3b}}; + uuid u7 = {{0x14,0x5c,0xfc,0x95,0x80,0x50,0x45,0x5a,0x83,0x82,0x44,0xca,0x57,0xc1,0x48,0x3c}}; + + // simple uuids to reproduce problem + uuid u8 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}; + uuid u9 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2}}; + uuid u10 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254}}; + uuid u11 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255}}; + + // some additional uuids for testing boundary cases + uuid u12 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}}; + uuid u13 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,2}}; + uuid u14 = {{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}; + uuid u15 = {{255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255}}; + + BOOST_TEST(u6 < u7); + BOOST_TEST(!(u7 < u6)); + + BOOST_TEST(u8 < u9); + BOOST_TEST(!(u9 < u8)); + BOOST_TEST(u8 < u10); + BOOST_TEST(!(u10 < u8)); + BOOST_TEST(u8 < u11); + BOOST_TEST(!(u11 < u8)); + + BOOST_TEST(u9 < u10); + BOOST_TEST(!(u10 < u9)); + BOOST_TEST(u9 < u11); + BOOST_TEST(!(u11 < u9)); + + BOOST_TEST(u10 < u11); + BOOST_TEST(!(u11 < u10)); + + BOOST_TEST(u12 < u13); + BOOST_TEST(!(u13 < u12)); + BOOST_TEST(u14 < u15); + BOOST_TEST(!(u15 < u14)); + } + + { // test hash + uuid u1 = {{0}}; + uuid u2 = {{1,0}}; + uuid u3 = {{255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}}; + + boost::hash<uuid> uuid_hasher; + + BOOST_TEST_NE(uuid_hasher(u1), uuid_hasher(u2)); + BOOST_TEST_NE(uuid_hasher(u1), uuid_hasher(u3)); + BOOST_TEST_NE(uuid_hasher(u2), uuid_hasher(u3)); + } + + { // test is_pod + BOOST_TEST_EQ(boost::is_pod<uuid>::value, true); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_uuid_class.cpp b/src/boost/libs/uuid/test/test_uuid_class.cpp new file mode 100644 index 00000000..03b65382 --- /dev/null +++ b/src/boost/libs/uuid/test/test_uuid_class.cpp @@ -0,0 +1,42 @@ +// (C) Copyright Andy Tompkins 2009. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_uuid_class.cpp -------------------------------// + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_generators.hpp> +#include <boost/uuid/uuid_io.hpp> + +#include <boost/detail/lightweight_test.hpp> + +class uuid_class : public boost::uuids::uuid +{ +public: + uuid_class() + : boost::uuids::uuid(boost::uuids::random_generator()()) + {} + + explicit uuid_class(boost::uuids::uuid const& u) + : boost::uuids::uuid(u) + {} +}; + +int main(int, char*[]) +{ + uuid_class u1; + uuid_class u2; + BOOST_TEST_NE(u1, u2); + BOOST_TEST_EQ(u1.is_nil(), false); + BOOST_TEST_EQ(u2.is_nil(), false); + + u2 = u1; + BOOST_TEST_EQ(u1, u2); + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_uuid_in_map.cpp b/src/boost/libs/uuid/test/test_uuid_in_map.cpp new file mode 100644 index 00000000..e8eeb168 --- /dev/null +++ b/src/boost/libs/uuid/test/test_uuid_in_map.cpp @@ -0,0 +1,36 @@ +// (C) Copyright Andy Tompkins 2011. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_uuid_in_map.cpp -------------------------------// + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_generators.hpp> +#include <map> + +#include <boost/detail/lightweight_test.hpp> + +int main(int, char*[]) +{ + boost::uuids::random_generator gen; + + boost::uuids::uuid u1 = gen(); + boost::uuids::uuid u2 = gen(); + boost::uuids::uuid u3 = gen(); + + std::map<boost::uuids::uuid, int> uuid_map; + uuid_map[u1] = 1; + uuid_map[u2] = 2; + uuid_map[u3] = 3; + + BOOST_TEST_EQ(1, uuid_map[u1]); + BOOST_TEST_EQ(2, uuid_map[u2]); + BOOST_TEST_EQ(3, uuid_map[u3]); + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_uuid_no_simd.cpp b/src/boost/libs/uuid/test/test_uuid_no_simd.cpp new file mode 100644 index 00000000..2a53f81a --- /dev/null +++ b/src/boost/libs/uuid/test/test_uuid_no_simd.cpp @@ -0,0 +1,153 @@ +// (C) Copyright Andy Tompkins 2007. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// libs/uuid/test/test_uuid_no_simd.cpp -------------------------------// + +// This test is a subset of libs/uuid/test/test_uuid.cpp, compiled without any +// SIMD optimizations. The test specifically verifies generic implementations +// of the routines. + +#define BOOST_UUID_NO_SIMD + +#include <iostream> +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_io.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/current_function.hpp> + +void test_uuid_equal_array(char const * file, int line, char const * function, + boost::uuids::uuid const& lhs, const unsigned char (&rhs)[16]) +{ + for (size_t i=0; i<16; i++) { + if ( *(lhs.begin()+i) != rhs[i]) { + std::cerr << file << "(" << line << "): uuid " << lhs << " not equal " << "{"; + for (size_t j=0; j<16; j++) { + if (j != 0) { + std::cerr << " "; + } + std::cerr << std::hex << (int)rhs[j]; + } + std::cerr << "} in function '" << function << "'" << std::endl; + ++boost::detail::test_errors(); + return; + } + } +} + + +#define BOOST_TEST_UUID(lhs, rhs) ( test_uuid_equal_array(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, lhs, rhs) ) + + +int main(int, char*[]) +{ + using namespace boost::uuids; + + { // uuid::operator=() + uuid u1 = {{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}}; + uuid u2 = u1; + BOOST_TEST_EQ(u2, u1); + } + + { // uuid::is_nil() + uuid u1 = {{0}}; + BOOST_TEST_EQ(u1.is_nil(), true); + + uuid u2 = {{1,0}}; + BOOST_TEST_EQ(u2.is_nil(), false); + } + + { // uuid::swap(), swap() + uuid u1 = {{0}}; + uuid u2 = {{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}}; + u1.swap(u2); + + unsigned char values1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + unsigned char values2[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; + BOOST_TEST_UUID(u1, values2); + BOOST_TEST_UUID(u2, values1); + + swap(u1, u2); + BOOST_TEST_UUID(u1, values1); + BOOST_TEST_UUID(u2, values2); + } + + { // test comparsion + uuid u1 = {{0}}; + uuid u2 = {{1,0}}; + uuid u3 = {{255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255}}; + uuid u4 = {{0,1,0}}; + uuid u5 = {{0,255,0}}; + + BOOST_TEST_EQ(u1, u1); + + BOOST_TEST_NE(u1, u2); + + BOOST_TEST(u1 < u2); + BOOST_TEST(u2 < u3); + BOOST_TEST(u1 < u4); + BOOST_TEST(u1 < u5); + BOOST_TEST(u4 < u5); + BOOST_TEST(u4 < u2); + BOOST_TEST(u5 < u2); + + BOOST_TEST(u1 <= u1); + BOOST_TEST(u1 <= u2); + BOOST_TEST(u2 <= u3); + + BOOST_TEST(u2 >= u1); + BOOST_TEST(u3 >= u1); + + BOOST_TEST(u3 >= u3); + BOOST_TEST(u2 >= u1); + BOOST_TEST(u3 >= u1); + } + + { // ticket 10510 + // the uuids in the report + uuid u6 = {{0x14,0x5c,0xfc,0x95,0x80,0x50,0x45,0x5a,0x83,0x82,0x44,0xca,0x57,0xc1,0x48,0x3b}}; + uuid u7 = {{0x14,0x5c,0xfc,0x95,0x80,0x50,0x45,0x5a,0x83,0x82,0x44,0xca,0x57,0xc1,0x48,0x3c}}; + + // simple uuids to reproduce problem + uuid u8 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}; + uuid u9 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2}}; + uuid u10 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254}}; + uuid u11 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255}}; + + // some additional uuids for testing boundary cases + uuid u12 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}}; + uuid u13 = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,2}}; + uuid u14 = {{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}; + uuid u15 = {{255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255}}; + + BOOST_TEST(u6 < u7); + BOOST_TEST(!(u7 < u6)); + + BOOST_TEST(u8 < u9); + BOOST_TEST(!(u9 < u8)); + BOOST_TEST(u8 < u10); + BOOST_TEST(!(u10 < u8)); + BOOST_TEST(u8 < u11); + BOOST_TEST(!(u11 < u8)); + + BOOST_TEST(u9 < u10); + BOOST_TEST(!(u10 < u9)); + BOOST_TEST(u9 < u11); + BOOST_TEST(!(u11 < u9)); + + BOOST_TEST(u10 < u11); + BOOST_TEST(!(u11 < u10)); + + BOOST_TEST(u12 < u13); + BOOST_TEST(!(u13 < u12)); + BOOST_TEST(u14 < u15); + BOOST_TEST(!(u15 < u14)); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/uuid/test/test_wserialization.cpp b/src/boost/libs/uuid/test/test_wserialization.cpp new file mode 100644 index 00000000..4f588723 --- /dev/null +++ b/src/boost/libs/uuid/test/test_wserialization.cpp @@ -0,0 +1,71 @@ +// (C) Copyright Andy Tompkins 2008. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// Purpose to test serializing uuids with wide stream archives + +#include <boost/detail/lightweight_test.hpp> +#include <sstream> +#include <iostream> + +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_serialize.hpp> +#include <boost/uuid/uuid_io.hpp> + +#include <boost/archive/text_woarchive.hpp> +#include <boost/archive/text_wiarchive.hpp> + +#include <boost/archive/xml_woarchive.hpp> +#include <boost/archive/xml_wiarchive.hpp> + +#include <boost/archive/binary_woarchive.hpp> +#include <boost/archive/binary_wiarchive.hpp> + +template <class OArchiveType, class IArchiveType, class OStringStreamType, class IStringStreamType> +void test_archive() +{ + using namespace std; + using namespace boost::uuids; + + OStringStreamType o_stream; + + uuid u1 = {{0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef}}; + + uuid u2; + + // save + { + OArchiveType oa(o_stream); + + oa << BOOST_SERIALIZATION_NVP(u1); + } + + //wcout << "stream:" << o_stream.str() << "\n\n"; + + // load + { + IStringStreamType i_stream(o_stream.str()); + IArchiveType ia(i_stream); + + ia >> BOOST_SERIALIZATION_NVP(u2); + } + + BOOST_TEST_EQ(u1, u2); +} + +int test_main( int /* argc */, char* /* argv */[] ) +{ + using namespace std; + using namespace boost::archive; + + test_archive<text_woarchive, text_wiarchive, wostringstream, wistringstream>(); + test_archive<xml_woarchive, xml_wiarchive, wostringstream, wistringstream>(); + test_archive<binary_woarchive, binary_wiarchive, wostringstream, wistringstream>(); + + return boost::report_errors(); +} |