#include "../time/time.hpp" #include <chrono> #include <iostream> #include "../threading/thread.hpp" #include "gtest_helpers.hpp" #include <gtest/gtest.h> TEST(TimeTest, SystemClockWorks) { typedef std::chrono::system_clock clock; clock::time_point t = clock::now(); auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(t.time_since_epoch()); int64_t startTime = nanoseconds.count(); sprawl::this_thread::Sleep(100 * sprawl::time::Resolution::Milliseconds); int64_t now = sprawl::time::Now(sprawl::time::Resolution::Nanoseconds); t = clock::now(); nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(t.time_since_epoch()); int64_t endTime = nanoseconds.count(); EXPECT_LE(startTime, now); EXPECT_GE(endTime, now); } TEST(TimeTest, SteadyClockWorks) { #ifdef _WIN32 typedef std::chrono::steady_clock clock; clock::time_point t = clock::now(); auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(t.time_since_epoch()); int64_t startTime = nanoseconds.count(); int64_t sprawlStartTime = sprawl::time::SteadyNow(sprawl::time::Resolution::Nanoseconds); sprawl::this_thread::Sleep(100 * sprawl::time::Resolution::Milliseconds); t = clock::now(); nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(t.time_since_epoch()); int64_t endTime = nanoseconds.count(); int64_t sprawlEndTime = sprawl::time::SteadyNow(sprawl::time::Resolution::Nanoseconds); int64_t delta = endTime - startTime; int64_t sprawlDelta = sprawlEndTime - sprawlStartTime; EXPECT_LT(abs(sprawlDelta - delta), 1000000); #else typedef std::chrono::steady_clock clock; clock::time_point t = clock::now(); auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(t.time_since_epoch()); int64_t startTime = nanoseconds.count(); sprawl::this_thread::Sleep(100 * sprawl::time::Resolution::Milliseconds); int64_t now = sprawl::time::SteadyNow(sprawl::time::Resolution::Nanoseconds); t = clock::now(); nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(t.time_since_epoch()); int64_t endTime = nanoseconds.count(); EXPECT_LT(startTime, now); EXPECT_GT(endTime, now); #endif } TEST(TimeTest, ConversionWorks) { int64_t timeInMilliseconds = 10000; int64_t timeInSeconds = sprawl::time::Convert(timeInMilliseconds, sprawl::time::Resolution::Milliseconds, sprawl::time::Resolution::Seconds); int64_t timeInNanoseconds = sprawl::time::Convert(timeInMilliseconds, sprawl::time::Resolution::Milliseconds, sprawl::time::Resolution::Nanoseconds); ASSERT_EQ(int64_t(10), timeInSeconds); ASSERT_EQ(int64_t(10LL * 1000LL * 1000LL * 1000LL), timeInNanoseconds); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 18645 | brandon_m_bare | Integrated latest version of libsprawl. | ||
#1 | 15089 | brandon_m_bare | First integration of sprawl. | ||
//guest/ShadauxCat/Sprawl/Mainline/UnitTests/UnitTests_Time.cpp | |||||
#5 | 14204 | ShadauxCat |
Fixed a discrepency in the time unit tests on windows. #review-14205 |
||
#4 | 14146 | ShadauxCat |
Moving a gtest-specific function out of String.hpp #review-14147 |
||
#3 | 14144 | ShadauxCat |
Switching unit tests to gtest. 100 is a decent number of tests to start with, but it needs to be more like 400 to test the current codebase. #review-14145 |
||
#2 | 13650 | ShadauxCat |
- Windows implementations of thread and time libraries - Added coroutines - Added some more unit tests, fixed some unit tests in windows environments - Fixed an issue where multi threading was not properly detected on Linux - Fixed the makefiles to build with threading by default on linux - Changed the pool allocator to use thread-local pools instead of locking mutexes - Fixed output of sprawl::string in the StringBuilder library to take length into account - Added string builder options for StringLiteral - Added thread local implementation #review |
||
#1 | 11500 | ShadauxCat |
Added sprawl::time library. Fixed JSON Unit Test bug. |