aboutsummaryrefslogtreecommitdiff
path: root/CST 126/LinkedListUnitTests/crt_check_memory.hpp
diff options
context:
space:
mode:
authorWesleyR <[email protected]>2024-06-09 23:09:50 -0700
committerWesleyR <[email protected]>2024-06-09 23:09:50 -0700
commitcb041a37b810a5dfa04c1c7f4315f9c3bbc8df0c (patch)
tree61b0d3d555e1596b5156e2d18e015497b438c2e4 /CST 126/LinkedListUnitTests/crt_check_memory.hpp
parentUpdating before template node branch (diff)
downloadhomework-1-wesleyr23-develop.tar.xz
homework-1-wesleyr23-develop.zip
Submission for HW 3, In-Class Exercise 3, and In-Class Exercise 4HEADdevelopTemplate_Node
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