From c9b17f15f85ef36c37b5bb61c01529d59123f9fb Mon Sep 17 00:00:00 2001 From: mpenick Date: Tue, 23 Sep 2014 14:07:13 -0700 Subject: [PATCH] Fixed Windows get_time_since_epoch() typo and added test --- src/get_time.cpp | 2 +- test/integration_tests/src/uuids.cpp | 50 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/integration_tests/src/uuids.cpp diff --git a/src/get_time.cpp b/src/get_time.cpp index 44f65350f..8e37d1237 100644 --- a/src/get_time.cpp +++ b/src/get_time.cpp @@ -32,7 +32,7 @@ uint64_t get_time_since_epoch() { _FILETIME ft; GetSystemTimeAsFileTime(&ft); uint64_t ns100 = (static_cast(ft.dwHighDateTime) << 32 | - static_cast(ft.dwHighDateTime)) - + static_cast(ft.dwLowDateTime)) - 116444736000000000LL; // 100 nanosecond increments between // Jan. 1, 1601 - Jan. 1, 1970 return ns100 / 10000; // 100 nanoseconds to milliseconds diff --git a/test/integration_tests/src/uuids.cpp b/test/integration_tests/src/uuids.cpp new file mode 100644 index 000000000..3eee774a3 --- /dev/null +++ b/test/integration_tests/src/uuids.cpp @@ -0,0 +1,50 @@ +/* + Copyright (c) 2014 DataStax + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#define BOOST_TEST_DYN_LINK +#ifdef STAND_ALONE +# define BOOST_TEST_MODULE cassandra +#endif + +#include "cassandra.h" + +#include +#include +#include + +BOOST_AUTO_TEST_SUITE(uuids) + +BOOST_AUTO_TEST_CASE(v1) +{ + CassUuid uuid; + cass_uuid_generate_time(uuid); + BOOST_CHECK(cass_uuid_version(uuid) == 1); + + cass_uint64_t last_ts = cass_uuid_timestamp(uuid); + + for (int i = 0; i < 10; ++i) { + boost::this_thread::sleep_for(boost::chrono::milliseconds(1)); + cass_uuid_generate_time(uuid); + + cass_uint64_t ts = cass_uuid_timestamp(uuid); + + BOOST_CHECK(cass_uuid_version(uuid) == 1); + BOOST_CHECK(ts > last_ts); + last_ts = ts; + } +} + +BOOST_AUTO_TEST_SUITE_END()