summaryrefslogtreecommitdiff
path: root/libs/uuid
diff options
context:
space:
mode:
authorChanho Park <chanho61.park@samsung.com>2014-12-11 18:55:56 +0900
committerChanho Park <chanho61.park@samsung.com>2014-12-11 18:55:56 +0900
commit08c1e93fa36a49f49325a07fe91ff92c964c2b6c (patch)
tree7a7053ceb8874b28ec4b868d4c49b500008a102e /libs/uuid
parentbb4dd8289b351fae6b55e303f189127a394a1edd (diff)
downloadboost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.gz
boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.bz2
boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.zip
Imported Upstream version 1.57.0upstream/1.57.0
Diffstat (limited to 'libs/uuid')
-rw-r--r--libs/uuid/test/Jamfile.v21
-rw-r--r--libs/uuid/test/test_sha1.cpp40
-rw-r--r--libs/uuid/test/test_uuid.cpp8
-rw-r--r--libs/uuid/test/test_uuid_no_simd.cpp112
-rw-r--r--libs/uuid/uuid.html86
5 files changed, 207 insertions, 40 deletions
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<sizeof(cases)/sizeof(cases[0]); iCase++) {
+ test_case const& tc = cases[iCase];
- unsigned int correct_digest[5] =
- { 0x34aa973c, 0xd4c4daa4, 0xf61eeb2b, 0xdbad2731, 0x6534016f };
+ boost::uuids::detail::sha1 sha;
+ for (size_t i=0; i<tc.count; i++) {
+ sha.process_byte('a');
+ }
- unsigned int digest[5];
- sha.get_digest(digest);
+ unsigned int digest[5];
+ sha.get_digest(digest);
- BOOST_TEST_SHA1_DEGEST(digest, correct_digest);
+ BOOST_TEST_SHA1_DIGEST(digest, tc.digest);
+ }
}
int main(int, char*[])
{
test_quick();
test_short_messages();
+ test_long();
return boost::report_errors();
}
diff --git a/libs/uuid/test/test_uuid.cpp b/libs/uuid/test/test_uuid.cpp
index faf84a0a81..f62acec823 100644
--- a/libs/uuid/test/test_uuid.cpp
+++ b/libs/uuid/test/test_uuid.cpp
@@ -9,6 +9,7 @@
// 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>
@@ -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 <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);
+ }
+
+ 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 @@
<ol>
<li><a href="#Introduction">Introduction</a></li>
+ <li><a href="#Configuration">Configuration</a></li>
<li><a href="#Examples">Examples</a></li>
<ul>
<li><a href="#Tagging">Tagging</a></li>
@@ -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).
+<h2><a name="Configuration">Configuration</a></h2>
+
+<p>
+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.
+
+<p>
+<table border="1">
+<tr>
+<th>Macro</th><th>Description</th>
+</tr>
+<tr>
+<td><tt>BOOST_UUID_NO_SIMD</tt></td><td>If defined, disables any optimizations for <a href="http://en.wikipedia.org/wiki/SIMD">SIMD</a>-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.</td>
+</tr>
+<tr>
+<td><tt>BOOST_UUID_USE_SSE2</tt></td><td>If defined, enables optimizations for <a href="http://en.wikipedia.org/wiki/SSE2">SSE2</a> exstensions available in modern x86 processors.</td>
+</tr>
+<tr>
+<td><tt>BOOST_UUID_USE_SSE3</tt></td><td>If defined, enables optimizations for <a href="http://en.wikipedia.org/wiki/SSE3">SSE3</a> exstensions available in modern x86 processors.</td>
+</tr>
+<tr>
+<td><tt>BOOST_UUID_USE_SSE41</tt></td><td>If defined, enables optimizations for <a href="http://en.wikipedia.org/wiki/SSE4#SSE4.1">SSE4.1</a> exstensions available in modern x86 processors.</td>
+</tr>
+</table>
+
+<p>
+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 <tt>BOOST_UUID_USE_SSE*</tt> 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.
+
<h2><a name="Examples">Examples</a></h2>
<h3><a name="Tagging">Tagging</a></h3>
<pre>
@@ -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&amp; rhs)
: tag(rhs.tag)
, state(rhs.state)
{}
-
+
bool operator==(object const&amp; rhs) const {
return tag == rhs.tag;
}
-
+
object&amp; operator=(object const&amp; 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&amp; 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&amp; rhs);
+ void swap(uuid&amp; rhs) noexcept;
uint8_t data[static_size()];
};
// standard operators
-bool operator==(uuid const&amp; lhs, uuid const&amp; rhs);
-bool operator!=(uuid const&amp; lhs, uuid const&amp; rhs);
-bool operator&lt;(uuid const&amp; lhs, uuid const&amp; rhs);
-bool operator&gt;(uuid const&amp; lhs, uuid const&amp; rhs);
-bool operator&lt;=(uuid const&amp; lhs, uuid const&amp; rhs);
-bool operator&gt;=(uuid const&amp; lhs, uuid const&amp; rhs);
+bool operator==(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
+bool operator!=(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
+bool operator&lt;(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
+bool operator&gt;(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
+bool operator&lt;=(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
+bool operator&gt;=(uuid const&amp; lhs, uuid const&amp; rhs) noexcept;
-void swap(uuid&amp; lhs, uuid&amp; rhs);
+void swap(uuid&amp; lhs, uuid&amp; rhs) noexcept;
-std::size_t hash_value(uuid const&amp; u);
+std::size_t hash_value(uuid const&amp; u) noexcept;
}} // namespace boost::uuids
</pre>
@@ -335,7 +365,7 @@ both always return 16.
</pre>
<h4><a name="Nil">Nil uuid</a></h4>
-<p>The function, <tt>boost::uuids::uuid::is_null()</tt> returns true if and
+<p>The function, <tt>boost::uuids::uuid::is_nil()</tt> returns true if and
only if the <b>uuid</b> is equal to {00000000-0000-0000-0000-000000000000}.
</p>