Index: src/libchcore/ErrorCodes.h =================================================================== diff -u -rbaad6054459abaaf69cbfd1ebad8783085160d99 -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/ErrorCodes.h (.../ErrorCodes.h) (revision baad6054459abaaf69cbfd1ebad8783085160d99) +++ src/libchcore/ErrorCodes.h (.../ErrorCodes.h) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -51,6 +51,7 @@ eErr_CannotSuspendThread = 1008, eErr_CannotSetEvent = 1009, eErr_CannotCreateMutex = 1010, + eErr_MutexAlreadyLocked = 1011, // string errors (1500+) Index: src/libchcore/MathFunctions.cpp =================================================================== diff -u -rd9527df01ee91b35d9a5fdccb80ded25a9c8265f -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/MathFunctions.cpp (.../MathFunctions.cpp) (revision d9527df01ee91b35d9a5fdccb80ded25a9c8265f) +++ src/libchcore/MathFunctions.cpp (.../MathFunctions.cpp) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -15,6 +15,9 @@ LIBCHCORE_API double Div64(unsigned long long ullNumber, double dDenominator) { + if (dDenominator == 0.0) + return 0.0; + return ullNumber / dDenominator; } } Index: src/libchcore/TBaseException.cpp =================================================================== diff -u -rb26ced3298e3e7e51d91f3ac70b56746786da83b -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/TBaseException.cpp (.../TBaseException.cpp) (revision b26ced3298e3e7e51d91f3ac70b56746786da83b) +++ src/libchcore/TBaseException.cpp (.../TBaseException.cpp) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -32,29 +32,6 @@ ATLTRACE(_T("*** Base Exception is being thrown:\n\tMsg: %s\n\tError code: %d\n\tFile: %s\n\tLine number: %ld\n\tFunction: %s\n"), pszMsg, eErrorCode, pszFile, stLineNumber, pszFunction); } - TBaseException::TBaseException(const TBaseException& rSrc) : - m_eErrorCode(rSrc.m_eErrorCode), - m_pszMsg(rSrc.m_pszMsg), - m_pszFile(rSrc.m_pszFile), - m_pszFunction(rSrc.m_pszFunction), - m_stLineNumber(rSrc.m_stLineNumber) - { - } - - TBaseException& TBaseException::operator=(const TBaseException& rSrc) - { - if(this != &rSrc) - { - m_eErrorCode = rSrc.m_eErrorCode; - m_pszMsg = rSrc.m_pszMsg; - m_pszFile = rSrc.m_pszFile; - m_pszFunction = rSrc.m_pszFunction; - m_stLineNumber = rSrc.m_stLineNumber; - } - - return *this; - } - TBaseException::~TBaseException() { } Index: src/libchcore/TBaseException.h =================================================================== diff -u -rb26ced3298e3e7e51d91f3ac70b56746786da83b -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/TBaseException.h (.../TBaseException.h) (revision b26ced3298e3e7e51d91f3ac70b56746786da83b) +++ src/libchcore/TBaseException.h (.../TBaseException.h) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -32,10 +32,6 @@ { public: TBaseException(EGeneralErrors eErrorCode, const wchar_t* pszMsg, const wchar_t* pszFile, size_t stLineNumber, const wchar_t* pszFunction); - TBaseException(const TBaseException& rSrc); - - TBaseException& operator=(const TBaseException&); - virtual ~TBaseException(); // error information Index: src/libchcore/TCoreException.cpp =================================================================== diff -u -rb26ced3298e3e7e51d91f3ac70b56746786da83b -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/TCoreException.cpp (.../TCoreException.cpp) (revision b26ced3298e3e7e51d91f3ac70b56746786da83b) +++ src/libchcore/TCoreException.cpp (.../TCoreException.cpp) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -25,8 +25,4 @@ TBaseException(eErrorCode, pszMsg, pszFile, stLineNumber, pszFunction) { } - - TCoreException::TCoreException(TCoreException&& rSrc) : TBaseException(std::forward(rSrc)) - { - } } Index: src/libchcore/TCoreException.h =================================================================== diff -u -rb26ced3298e3e7e51d91f3ac70b56746786da83b -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/TCoreException.h (.../TCoreException.h) (revision b26ced3298e3e7e51d91f3ac70b56746786da83b) +++ src/libchcore/TCoreException.h (.../TCoreException.h) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -27,7 +27,6 @@ class LIBCHCORE_API TCoreException : public TBaseException { public: - TCoreException(TCoreException&& rSrc); TCoreException(EGeneralErrors eErrorCode, const wchar_t* pszMsg, const wchar_t* pszFile, size_t stLineNumber, const wchar_t* pszFunction); }; } Index: src/libchcore/TIpcMutex.cpp =================================================================== diff -u -ra6b040ed1b328ac7ad30882b07b7ca41e812bbb9 -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/TIpcMutex.cpp (.../TIpcMutex.cpp) (revision a6b040ed1b328ac7ad30882b07b7ca41e812bbb9) +++ src/libchcore/TIpcMutex.cpp (.../TIpcMutex.cpp) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -75,6 +75,11 @@ m_bLocked = false; } + bool TIpcMutex::IsLocked() const + { + return m_bLocked; + } + void TIpcMutex::Close() { if (m_bLocked) Index: src/libchcore/TIpcMutex.h =================================================================== diff -u -rb26ced3298e3e7e51d91f3ac70b56746786da83b -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/TIpcMutex.h (.../TIpcMutex.h) (revision b26ced3298e3e7e51d91f3ac70b56746786da83b) +++ src/libchcore/TIpcMutex.h (.../TIpcMutex.h) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -38,6 +38,7 @@ void Lock(DWORD dwTimeout = INFINITE); void Unlock(); + bool IsLocked() const; private: void Close(); Index: src/libchcore/TIpcMutexLock.cpp =================================================================== diff -u -r306fbe693c70290af9de9a5779084a697de22d75 -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/TIpcMutexLock.cpp (.../TIpcMutexLock.cpp) (revision 306fbe693c70290af9de9a5779084a697de22d75) +++ src/libchcore/TIpcMutexLock.cpp (.../TIpcMutexLock.cpp) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -18,13 +18,16 @@ // ============================================================================ #include "stdafx.h" #include "TIpcMutexLock.h" +#include "TCoreException.h" namespace chcore { - TIpcMutexLock::TIpcMutexLock(TIpcMutex& rMutex) : + TIpcMutexLock::TIpcMutexLock(TIpcMutex& rMutex, DWORD dwTimeout) : m_rMutex(rMutex) { - m_rMutex.Lock(); + if (rMutex.IsLocked()) + throw TCoreException(eErr_MutexAlreadyLocked, L"Mutex already locked", LOCATION); + m_rMutex.Lock(dwTimeout); } TIpcMutexLock::~TIpcMutexLock() Index: src/libchcore/TIpcMutexLock.h =================================================================== diff -u -rb26ced3298e3e7e51d91f3ac70b56746786da83b -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/TIpcMutexLock.h (.../TIpcMutexLock.h) (revision b26ced3298e3e7e51d91f3ac70b56746786da83b) +++ src/libchcore/TIpcMutexLock.h (.../TIpcMutexLock.h) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -26,7 +26,7 @@ class LIBCHCORE_API TIpcMutexLock { public: - explicit TIpcMutexLock(TIpcMutex& rMutex); + TIpcMutexLock(TIpcMutex& rMutex, DWORD dwTimeout = INFINITE); TIpcMutexLock(const TIpcMutexLock&) = delete; ~TIpcMutexLock(); Index: src/libchcore/Tests/TestsMathFunctions.cpp =================================================================== diff -u --- src/libchcore/Tests/TestsMathFunctions.cpp (revision 0) +++ src/libchcore/Tests/TestsMathFunctions.cpp (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -0,0 +1,36 @@ +#include "stdafx.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../MathFunctions.h" + +using namespace chcore; + +TEST(TestsMathFunctions, Div64_64) +{ + EXPECT_EQ(0, Math::Div64(0ULL, 1ULL)); + EXPECT_EQ(1, Math::Div64(1ULL, 1ULL)); + EXPECT_EQ(0, Math::Div64(0ULL, 0xFFFFFFFFFFFFFFFF)); + EXPECT_EQ(1, Math::Div64(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); +} + +TEST(TestsMathFunctions, Div64_64_By0) +{ + EXPECT_EQ(0, Math::Div64(0ULL, 0ULL)); + EXPECT_EQ(0, Math::Div64(1ULL, 0ULL)); + EXPECT_EQ(0, Math::Div64(0ULL, 0ULL)); + EXPECT_EQ(0, Math::Div64(0xFFFFFFFFFFFFFFFF, 0ULL)); +} + +TEST(TestsMathFunctions, Div64_Double) +{ + EXPECT_EQ(0, Math::Div64(0ULL, 1.0)); + EXPECT_EQ(1, Math::Div64(1ULL, 1.0)); +} + +TEST(TestsMathFunctions, Div64_Double_By0) +{ + EXPECT_EQ(0, Math::Div64(0ULL, 0.0)); + EXPECT_EQ(0, Math::Div64(1ULL, 0.0)); + EXPECT_EQ(0, Math::Div64(0ULL, 0.0)); + EXPECT_EQ(0, Math::Div64(0xFFFFFFFFFFFFFFFF, 0.0)); +} Index: src/libchcore/Tests/TestsTFileTime.cpp =================================================================== diff -u --- src/libchcore/Tests/TestsTFileTime.cpp (revision 0) +++ src/libchcore/Tests/TestsTFileTime.cpp (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -0,0 +1,14 @@ +#include "stdafx.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../TFileTime.h" + +using namespace chcore; + +TEST(TestsTFileTime, DefaultConstruction) +{ + TFileTime fTime; + EXPECT_EQ(0, fTime.ToUInt64()); + EXPECT_EQ(0, fTime.GetAsFiletime().dwLowDateTime); + EXPECT_EQ(0, fTime.GetAsFiletime().dwHighDateTime); +} Index: src/libchcore/Tests/TestsTIpcMutex.cpp =================================================================== diff -u --- src/libchcore/Tests/TestsTIpcMutex.cpp (revision 0) +++ src/libchcore/Tests/TestsTIpcMutex.cpp (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -0,0 +1,55 @@ +#include "stdafx.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../TIpcMutex.h" +#include "../TCoreException.h" + +using namespace chcore; + +TEST(TestsTIpcMutex, DefaultConstruction) +{ + TIpcMutex mutex; + + EXPECT_FALSE(mutex.IsLocked()); + EXPECT_THROW(mutex.Lock(), TCoreException); + EXPECT_FALSE(mutex.IsLocked()); + EXPECT_THROW(mutex.Unlock(), TCoreException); + EXPECT_FALSE(mutex.IsLocked()); +} + +TEST(TestsTIpcMutex, NamedConstruction) +{ + TIpcMutex mutex(L"UnitTestsNamedIpcMutex"); + + EXPECT_FALSE(mutex.IsLocked()); + mutex.Lock(100); + EXPECT_TRUE(mutex.IsLocked()); + mutex.Unlock(); + EXPECT_FALSE(mutex.IsLocked()); +} + +TEST(TestsTIpcMutex, SeparateCreation) +{ + TIpcMutex mutex; + mutex.CreateMutex(L"UnitTestsNamedIpcMutex"); + + EXPECT_FALSE(mutex.IsLocked()); + mutex.Lock(); + EXPECT_TRUE(mutex.IsLocked()); + mutex.Unlock(); + EXPECT_FALSE(mutex.IsLocked()); +} + +TEST(TestsTIpcMutex, RecreateMutex) +{ + TIpcMutex mutex(L"UnitTestsNamedIpcMutex2"); + mutex.Lock(); + + mutex.CreateMutex(L"UnitTestsNamedIpcMutex"); + + EXPECT_FALSE(mutex.IsLocked()); + mutex.Lock(); + EXPECT_TRUE(mutex.IsLocked()); + mutex.Unlock(); + EXPECT_FALSE(mutex.IsLocked()); +} Index: src/libchcore/Tests/TestsTIpcMutexLock.cpp =================================================================== diff -u --- src/libchcore/Tests/TestsTIpcMutexLock.cpp (revision 0) +++ src/libchcore/Tests/TestsTIpcMutexLock.cpp (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -0,0 +1,35 @@ +#include "stdafx.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../TIpcMutex.h" +#include "../TIpcMutexLock.h" +#include "../TCoreException.h" + +using namespace chcore; + +TEST(TestsTIpcMutexLock, DefaultConstruction) +{ + TIpcMutex mutex; + + EXPECT_THROW(TIpcMutexLock lock(mutex), TCoreException); +} + +TEST(TestsTIpcMutexLock, ScopedLock) +{ + TIpcMutex mutex(L"UnitTestsNamedIpcMutex"); + + { + TIpcMutexLock lock(mutex); + EXPECT_TRUE(mutex.IsLocked()); + } + + EXPECT_FALSE(mutex.IsLocked()); +} + +TEST(TestsTIpcMutexLock, ScopedLock_AlreadyLocked) +{ + TIpcMutex mutex(L"UnitTestsNamedIpcMutex"); + mutex.Lock(); + EXPECT_TRUE(mutex.IsLocked()); + EXPECT_THROW(TIpcMutexLock lock(mutex, 100), TCoreException); +} Index: src/libchcore/libchcore.vc140.vcxproj =================================================================== diff -u -r0cbc11b231178ea3e8f9fa1d7bcd224bfb7f1d05 -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/libchcore.vc140.vcxproj (.../libchcore.vc140.vcxproj) (revision 0cbc11b231178ea3e8f9fa1d7bcd224bfb7f1d05) +++ src/libchcore/libchcore.vc140.vcxproj (.../libchcore.vc140.vcxproj) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -515,6 +515,10 @@ + + + + true true Index: src/libchcore/libchcore.vc140.vcxproj.filters =================================================================== diff -u -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a -rc1f7af79a52133c6d4b14944c3370288be7f5af5 --- src/libchcore/libchcore.vc140.vcxproj.filters (.../libchcore.vc140.vcxproj.filters) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) +++ src/libchcore/libchcore.vc140.vcxproj.filters (.../libchcore.vc140.vcxproj.filters) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) @@ -167,6 +167,18 @@ Tests + + Tests + + + Tests + + + Tests + + + Tests +