aboutsummaryrefslogtreecommitdiff
path: root/CST 126/LinkedListUnitTests/crt_check_memory.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'CST 126/LinkedListUnitTests/crt_check_memory.hpp')
-rw-r--r--CST 126/LinkedListUnitTests/crt_check_memory.hpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/CST 126/LinkedListUnitTests/crt_check_memory.hpp b/CST 126/LinkedListUnitTests/crt_check_memory.hpp
new file mode 100644
index 0000000..9cb4ab2
--- /dev/null
+++ b/CST 126/LinkedListUnitTests/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