diff options
| author | Chanin Timbal <[email protected]> | 2024-06-01 11:55:26 -0700 |
|---|---|---|
| committer | Chanin Timbal <[email protected]> | 2024-06-01 11:55:26 -0700 |
| commit | e57173d536465fe12cea8a605d7b0d0e4f02bbf1 (patch) | |
| tree | 3d00ca12b96b7c62c80d4914bc9b71e3192ff7d3 /CST 126/UnitTests/crt_check_memory.hpp | |
| parent | attempting rebuild (diff) | |
| download | archived-homework-1-chaninnohea-e57173d536465fe12cea8a605d7b0d0e4f02bbf1.tar.xz archived-homework-1-chaninnohea-e57173d536465fe12cea8a605d7b0d0e4f02bbf1.zip | |
trying to fix!
Diffstat (limited to 'CST 126/UnitTests/crt_check_memory.hpp')
| -rw-r--r-- | CST 126/UnitTests/crt_check_memory.hpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/CST 126/UnitTests/crt_check_memory.hpp b/CST 126/UnitTests/crt_check_memory.hpp new file mode 100644 index 0000000..9cb4ab2 --- /dev/null +++ b/CST 126/UnitTests/crt_check_memory.hpp @@ -0,0 +1,40 @@ +#ifndef CRTCHECKMEMORY_H +#define CRTCHECKMEMORY_H + +#include "pch.h" +#include "CppUnitTest.h" +#include "crtdbg.h" + +#define _CRTDBG_MAP_ALLOC + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace LinkedListUnitTests +{ + struct CrtCheckMemory + { + _CrtMemState state1{}; + _CrtMemState state2{}; + _CrtMemState state3{}; + CrtCheckMemory() + { + _CrtMemCheckpoint(&state1); + } + + CrtCheckMemory(const CrtCheckMemory& copy) = delete; + CrtCheckMemory& operator=(const CrtCheckMemory& copy) = delete; + CrtCheckMemory(CrtCheckMemory&& copy) = delete; + CrtCheckMemory& operator=(CrtCheckMemory&& copy) = delete; + + ~CrtCheckMemory() + { + _CrtMemCheckpoint(&state2); + + if (_CrtMemDifference(&state3, &state1, &state2) != 0) + { + Assert::Fail(L"Detected memory leaks!"); + } + } + }; +} +#endif
\ No newline at end of file |