#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 | |
---|---|---|---|---|---|
#1 | 23398 | ququlala | "Forking branch Mainline of shadauxcat-libsprawl to ququlala-libsprawl." | ||
//guest/ShadauxCat/Sprawl/Mainline/UnitTests/UnitTests_Time.cpp | |||||
#6 | 16768 | ShadauxCat |
Improvements to error handling in builds with exceptions disabled: - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if Get() is called when an error flag is set. (In release buils or with SPRAWL_ERRORSTATE_PERMISSIVE defined, Get() will return junk memory in this case.) - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if its destructor is called without checking the errorstate if an error is present (equivalent to an exception terminating the application if no catch() block is present for it). - On linux builds and when running "Analyze" through visual studio, a warning will be issued if any function returning ErrorState has its return value ignored. (This only applies to builds with exceptions not enabled; when exceptions are enabled no warning is issued) - Many functions that could return ErrorState were having their return values silently ignored in internal sprawl code so the user would not find out about errors if exceptions are disabled; now anything in sprawl code that calls a function returning ErrorState will either handle the error, or (in most cases) surface it back up to the user. - As a positive side-effect of the warnings for ignoring ErrorState, several constructors that were capable of throwing exceptions are no longer capable of doing so. #review-16769 |
||
#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. |