aboutsummaryrefslogtreecommitdiff
path: root/CST 126/UnitTester
diff options
context:
space:
mode:
authorrPatrickWarner <[email protected]>2024-05-22 19:42:15 -0700
committerrPatrickWarner <[email protected]>2024-05-22 19:42:15 -0700
commit2977e76af7007f470227ccbd6a7e3cd9dd1f4bb3 (patch)
tree959af9b8c84de286dda882fb9119feebefd92ffd /CST 126/UnitTester
parentunit tests added (diff)
downloadhomework-1-reecepwarner-UnitTesting.tar.xz
homework-1-reecepwarner-UnitTesting.zip
unit test and memory check addedUnitTesting
Diffstat (limited to 'CST 126/UnitTester')
-rw-r--r--CST 126/UnitTester/UnitTester.cpp43
-rw-r--r--CST 126/UnitTester/UnitTester.vcxproj1
-rw-r--r--CST 126/UnitTester/UnitTester.vcxproj.filters3
-rw-r--r--CST 126/UnitTester/crt_check_memory.hpp40
4 files changed, 86 insertions, 1 deletions
diff --git a/CST 126/UnitTester/UnitTester.cpp b/CST 126/UnitTester/UnitTester.cpp
index 1ad15fd..aa04fe1 100644
--- a/CST 126/UnitTester/UnitTester.cpp
+++ b/CST 126/UnitTester/UnitTester.cpp
@@ -1,7 +1,10 @@
#include "pch.h"
#include "CppUnitTest.h"
#include "SinglyLinkedList.hpp"
+#include "crt_check_memory.hpp"
+
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace CST_126;
namespace LinkedListUnitTests
{
@@ -216,5 +219,43 @@ namespace LinkedListUnitTests
//}
+
+
+
+
+
};
-}
+ TEST_CLASS(NodeUnitTests)
+ {
+ public:
+ const CrtCheckMemory Check;
+
+
+ TEST_METHOD(NodeConstructor_Success)
+ {
+ Node<int>* NewNode = new Node<int>();
+
+ Assert::IsNotNull(NewNode);
+
+
+ delete NewNode;
+ }
+
+
+
+ TEST_METHOD(NodeLoadedConstructor_Success)
+ {
+ const CrtCheckMemory Check;
+
+ Node<int>* NewNode = new Node<int>(5);
+
+ Assert::IsNotNull(NewNode);
+ Assert::AreEqual(5, NewNode->Data());
+ }
+
+
+ }
+
+
+
+};
diff --git a/CST 126/UnitTester/UnitTester.vcxproj b/CST 126/UnitTester/UnitTester.vcxproj
index 0cbba9e..1c29209 100644
--- a/CST 126/UnitTester/UnitTester.vcxproj
+++ b/CST 126/UnitTester/UnitTester.vcxproj
@@ -166,6 +166,7 @@
<ClCompile Include="UnitTester.cpp" />
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="crt_check_memory.hpp" />
<ClInclude Include="pch.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
diff --git a/CST 126/UnitTester/UnitTester.vcxproj.filters b/CST 126/UnitTester/UnitTester.vcxproj.filters
index 7a76918..a210b65 100644
--- a/CST 126/UnitTester/UnitTester.vcxproj.filters
+++ b/CST 126/UnitTester/UnitTester.vcxproj.filters
@@ -26,5 +26,8 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="crt_check_memory.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project> \ No newline at end of file
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