Skip to content

Commit

Permalink
Fixed Windows get_time_since_epoch() typo and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenick committed Sep 23, 2014
1 parent 5822a46 commit c9b17f1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/get_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ uint64_t get_time_since_epoch() {
_FILETIME ft;
GetSystemTimeAsFileTime(&ft);
uint64_t ns100 = (static_cast<uint64_t>(ft.dwHighDateTime) << 32 |
static_cast<uint64_t>(ft.dwHighDateTime)) -
static_cast<uint64_t>(ft.dwLowDateTime)) -
116444736000000000LL; // 100 nanosecond increments between
// Jan. 1, 1601 - Jan. 1, 1970
return ns100 / 10000; // 100 nanoseconds to milliseconds
Expand Down
50 changes: 50 additions & 0 deletions test/integration_tests/src/uuids.cpp
Original file line number Diff line number Diff line change
@@ -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 <boost/chrono.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/thread.hpp>

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()

0 comments on commit c9b17f1

Please sign in to comment.