diff options
| author | rPatrickWarner <[email protected]> | 2024-05-22 19:42:15 -0700 |
|---|---|---|
| committer | rPatrickWarner <[email protected]> | 2024-05-22 19:42:15 -0700 |
| commit | 2977e76af7007f470227ccbd6a7e3cd9dd1f4bb3 (patch) | |
| tree | 959af9b8c84de286dda882fb9119feebefd92ffd /CST 126/UnitTester/crt_check_memory.hpp | |
| parent | unit tests added (diff) | |
| download | homework-1-reecepwarner-UnitTesting.tar.xz homework-1-reecepwarner-UnitTesting.zip | |
unit test and memory check addedUnitTesting
Diffstat (limited to 'CST 126/UnitTester/crt_check_memory.hpp')
| -rw-r--r-- | CST 126/UnitTester/crt_check_memory.hpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/CST 126/UnitTester/crt_check_memory.hpp b/CST 126/UnitTester/crt_check_memory.hpp new file mode 100644 index 0000000..9cb4ab2 --- /dev/null +++ b/CST 126/UnitTester/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 |