From 08c1e93fa36a49f49325a07fe91ff92c964c2b6c Mon Sep 17 00:00:00 2001 From: Chanho Park Date: Thu, 11 Dec 2014 18:55:56 +0900 Subject: Imported Upstream version 1.57.0 --- libs/uuid/test/Jamfile.v2 | 1 + libs/uuid/test/test_sha1.cpp | 40 +++++++++---- libs/uuid/test/test_uuid.cpp | 8 +++ libs/uuid/test/test_uuid_no_simd.cpp | 112 +++++++++++++++++++++++++++++++++++ libs/uuid/uuid.html | 86 ++++++++++++++++++--------- 5 files changed, 207 insertions(+), 40 deletions(-) create mode 100644 libs/uuid/test/test_uuid_no_simd.cpp (limited to 'libs/uuid') diff --git a/libs/uuid/test/Jamfile.v2 b/libs/uuid/test/Jamfile.v2 index edca46a988..cba5321579 100644 --- a/libs/uuid/test/Jamfile.v2 +++ b/libs/uuid/test/Jamfile.v2 @@ -25,6 +25,7 @@ test-suite uuid : # main test [ run test_uuid.cpp ] + [ run test_uuid_no_simd.cpp ] # test uuid_io.hpp [ run test_io.cpp ] diff --git a/libs/uuid/test/test_sha1.cpp b/libs/uuid/test/test_sha1.cpp index 54fe49e398..ed8e073736 100644 --- a/libs/uuid/test/test_sha1.cpp +++ b/libs/uuid/test/test_sha1.cpp @@ -50,7 +50,7 @@ void test_sha1_digest_equal_array(char const * file, int line, char const * func } -#define BOOST_TEST_SHA1_DEGEST(lhs, rhs) ( test_sha1_digest_equal_array(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, lhs, rhs) ) +#define BOOST_TEST_SHA1_DIGEST(lhs, rhs) ( test_sha1_digest_equal_array(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, lhs, rhs) ) void test_sha1(char const*const message, unsigned int length, const unsigned int (&correct_digest)[5]) { @@ -60,7 +60,7 @@ void test_sha1(char const*const message, unsigned int length, const unsigned int unsigned int digest[5]; sha.get_digest(digest); - BOOST_TEST_SHA1_DEGEST(digest, correct_digest); + BOOST_TEST_SHA1_DIGEST(digest, correct_digest); } void test_quick() @@ -259,32 +259,48 @@ void test_short_messages() unsigned int digest[5]; sha.get_digest(digest); - BOOST_TEST_SHA1_DEGEST(digest, tc.digest); + BOOST_TEST_SHA1_DIGEST(digest, tc.digest); } } +// test long strings of 'a's void test_long() { + // test 1 million 'a's + struct test_case + { + unsigned int count; + unsigned int digest[5]; + }; + test_case cases[] = + { { 1000000, { 0x34aa973c, 0xd4c4daa4, 0xf61eeb2b, 0xdbad2731, 0x6534016f } } + , { 1000000000, { 0xd0f3e4f2, 0xf31c665a, 0xbbd8f518, 0xe848d5cb, 0x80ca78f7 } } + //, { 2000000000, { 0xda19be1b, 0x5ec3bc13, 0xda5533bd, 0x0c225a2f, 0x38da50ed } } + //, { 2147483647, { 0x1e5b490b, 0x10255e37, 0xfd96d096, 0x4f2fbfb9, 0x1ed47536 } } + //, { 4294967295 /*2^32 - 1*/, { 0xd84b866e, 0x70f6348f, 0xb0ddc21f, 0x373fe956, 0x1bf1005d } } + }; - boost::uuids::detail::sha1 sha; - for (size_t i=0; i<1000000; i++) { - sha.process_byte('a'); - } + for (size_t iCase=0; iCase #include #include #include @@ -156,6 +157,8 @@ int main(int, char*[]) 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); @@ -163,6 +166,11 @@ int main(int, char*[]) 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); diff --git a/libs/uuid/test/test_uuid_no_simd.cpp b/libs/uuid/test/test_uuid_no_simd.cpp new file mode 100644 index 0000000000..a1c70f3524 --- /dev/null +++ b/libs/uuid/test/test_uuid_no_simd.cpp @@ -0,0 +1,112 @@ +// (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 +// http://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 +#include +#include +#include +#include + +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); + } + + return boost::report_errors(); +} diff --git a/libs/uuid/uuid.html b/libs/uuid/uuid.html index 3f3a8631c0..03f4e7ca76 100644 --- a/libs/uuid/uuid.html +++ b/libs/uuid/uuid.html @@ -13,6 +13,7 @@
  1. Introduction
  2. +
  3. Configuration
  4. Examples
    • Tagging
    • @@ -103,6 +104,35 @@ generated UUIDs (that is, it has never been generated before and it will never be generated again), or it is extremely likely to be unique (depending on the mechanism). +

      Configuration

      + +

      +The library does not require building or any special configuration to be used. +However, there are a few options that can be enabled by defining macros prior to +including library headers. These macros are summarized in the following table. + +

      + + + + + + + + + + + + + + + + +
      MacroDescription
      BOOST_UUID_NO_SIMDIf defined, disables any optimizations for SIMD-enabled processors. Generic versions of algorithms will be used instead. This may result in suboptimal performance. By default, optimized algorithms are used, when the library is able to detect the availability of SIMD extensions at compile time.
      BOOST_UUID_USE_SSE2If defined, enables optimizations for SSE2 exstensions available in modern x86 processors.
      BOOST_UUID_USE_SSE3If defined, enables optimizations for SSE3 exstensions available in modern x86 processors.
      BOOST_UUID_USE_SSE41If defined, enables optimizations for SSE4.1 exstensions available in modern x86 processors.
      + +

      +By default the library attempts to detect the availability of SIMD extensions in the target CPU at compile time and automatically defines the appropriate macros if succeeded. The BOOST_UUID_USE_SSE* macros can be defined by users, if auto-detection fails and it is known that the target CPU will have the extension. Do not enable these extensions unless you're certain that they will always be available on any machine that will run your program. The library performs no run time checks, so if an extension is missing, the program will likely crash. Note that enabling more advanced extensions implies that more basic ones are also available. +

      Examples

      Tagging

      @@ -119,32 +149,32 @@ public:
               : 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;
           }
      -    
      +
           object& operator=(object const& rhs) {
               tag = rhs.tag;
               state = rhs.state;
           }
      -    
      +
           int get_state() const { return state; }
           void set_state(int new_state) { state = new_state; }
      -    
      +
       private:
           boost::uuids::uuid tag;
      -    
      +
           int state;
       };
       
      @@ -209,7 +239,7 @@ public:
           uuid_class()
               : boost::uuids::uuid(boost::uuids::random_generator()())
           {}
      -    
      +
           explicit uuid_class(boost::uuids::uuid const& u)
               : boost::uuids::uuid(u)
           {}
      @@ -258,25 +288,25 @@ public:
           typedef std::size_t size_type;
           typedef std::ptrdiff_t difference_type;
       
      -    static size_type static_size();
      +    static constexpr size_type static_size() noexcept;
       
           // iteration
      -    iterator begin();
      -    iterator end();
      -    const_iterator begin() const;
      -    const_iterator end() const;
      +    iterator begin() noexcept;
      +    iterator end() noexcept;
      +    const_iterator begin() const noexcept;
      +    const_iterator end() const noexcept;
       
      -    size_type size() const;
      +    constexpr size_type size() const noexcept;
      +
      +    bool is_nil() const noexcept;
       
      -    bool is_nil() const;
      -    
           enum variant_type {
               variant_ncs, // NCS backward compatibility
               variant_rfc_4122, // defined in RFC 4122 document
               variant_microsoft, // Microsoft Corporation backward compatibility
               variant_future // future definition
           };
      -    variant_type variant() const;
      +    variant_type variant() const noexcept;
       
           enum version_type {
               version_unknown = -1,
      @@ -286,25 +316,25 @@ public:
               version_random_number_based = 4,
               version_name_based_sha1 = 5
           };
      -    version_type version() const;
      +    version_type version() const noexcept;
       
           // Swap function
      -    void swap(uuid& rhs);
      +    void swap(uuid& rhs) noexcept;
       
           uint8_t data[static_size()];
       };
       
       // standard operators
      -bool operator==(uuid const& lhs, uuid const& rhs);
      -bool operator!=(uuid const& lhs, uuid const& rhs);
      -bool operator<(uuid const& lhs, uuid const& rhs);
      -bool operator>(uuid const& lhs, uuid const& rhs);
      -bool operator<=(uuid const& lhs, uuid const& rhs);
      -bool operator>=(uuid const& lhs, uuid const& rhs);
      +bool operator==(uuid const& lhs, uuid const& rhs) noexcept;
      +bool operator!=(uuid const& lhs, uuid const& rhs) noexcept;
      +bool operator<(uuid const& lhs, uuid const& rhs) noexcept;
      +bool operator>(uuid const& lhs, uuid const& rhs) noexcept;
      +bool operator<=(uuid const& lhs, uuid const& rhs) noexcept;
      +bool operator>=(uuid const& lhs, uuid const& rhs) noexcept;
       
      -void swap(uuid& lhs, uuid& rhs);
      +void swap(uuid& lhs, uuid& rhs) noexcept;
       
      -std::size_t hash_value(uuid const& u);
      +std::size_t hash_value(uuid const& u) noexcept;
       
       }} // namespace boost::uuids
       
      @@ -335,7 +365,7 @@ both always return 16.

      Nil uuid

      -

      The function, boost::uuids::uuid::is_null() returns true if and +

      The function, boost::uuids::uuid::is_nil() returns true if and only if the uuid is equal to {00000000-0000-0000-0000-000000000000}.

      -- cgit v1.2.3