diff --git a/Hazelnupp.sln b/Hazelnupp.sln
index 81d386f..c71b343 100644
--- a/Hazelnupp.sln
+++ b/Hazelnupp.sln
@@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hazelnupp", "Hazelnupp\Hazelnupp.vcxproj", "{9AEAA0C6-9088-4F6E-9224-5C67D3163A17}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test_Hazelnupp", "Test_Hazelnupp\Test_Hazelnupp.vcxproj", "{B098AA37-A9CC-4BA2-B17D-189B706FDB16}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -21,6 +23,14 @@ Global
{9AEAA0C6-9088-4F6E-9224-5C67D3163A17}.Release|x64.Build.0 = Release|x64
{9AEAA0C6-9088-4F6E-9224-5C67D3163A17}.Release|x86.ActiveCfg = Release|Win32
{9AEAA0C6-9088-4F6E-9224-5C67D3163A17}.Release|x86.Build.0 = Release|Win32
+ {B098AA37-A9CC-4BA2-B17D-189B706FDB16}.Debug|x64.ActiveCfg = Debug|x64
+ {B098AA37-A9CC-4BA2-B17D-189B706FDB16}.Debug|x64.Build.0 = Debug|x64
+ {B098AA37-A9CC-4BA2-B17D-189B706FDB16}.Debug|x86.ActiveCfg = Debug|Win32
+ {B098AA37-A9CC-4BA2-B17D-189B706FDB16}.Debug|x86.Build.0 = Debug|Win32
+ {B098AA37-A9CC-4BA2-B17D-189B706FDB16}.Release|x64.ActiveCfg = Release|x64
+ {B098AA37-A9CC-4BA2-B17D-189B706FDB16}.Release|x64.Build.0 = Release|x64
+ {B098AA37-A9CC-4BA2-B17D-189B706FDB16}.Release|x86.ActiveCfg = Release|Win32
+ {B098AA37-A9CC-4BA2-B17D-189B706FDB16}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Hazelnupp/Hazelnupp.cpp b/Hazelnupp/Hazelnupp.cpp
index 59cfc02..6e0916f 100644
--- a/Hazelnupp/Hazelnupp.cpp
+++ b/Hazelnupp/Hazelnupp.cpp
@@ -296,6 +296,10 @@ const std::string& Hazelnupp::GetExecutableName() const
const Value& Hazelnupp::operator[](const std::string& key) const
{
+ // Throw exception if param is unknown
+ if (!HasParam(key))
+ throw HazelnuppInvalidKeyException();
+
return *parameters.find(key)->second->GetValue();
}
diff --git a/Hazelnupp/Hazelnupp.vcxproj b/Hazelnupp/Hazelnupp.vcxproj
index 88ae8dc..2cb5ad0 100644
--- a/Hazelnupp/Hazelnupp.vcxproj
+++ b/Hazelnupp/Hazelnupp.vcxproj
@@ -27,26 +27,26 @@
- Application
+ StaticLibrary
true
v142
Unicode
- Application
+ StaticLibrary
false
v142
true
Unicode
- Application
+ StaticLibrary
true
v142
Unicode
- Application
+ StaticLibrary
false
v142
true
diff --git a/Hazelnupp/HazelnuppException.h b/Hazelnupp/HazelnuppException.h
index a6319d7..ff04ba8 100644
--- a/Hazelnupp/HazelnuppException.h
+++ b/Hazelnupp/HazelnuppException.h
@@ -19,6 +19,13 @@ protected:
std::string message;
};
+class HazelnuppInvalidKeyException : public HazelnuppException
+{
+public:
+ HazelnuppInvalidKeyException() : HazelnuppException() {};
+ HazelnuppInvalidKeyException(const std::string& msg) : HazelnuppException(msg) {};
+};
+
class HazelnuppConstraintException : public HazelnuppException
{
public:
diff --git a/Test_Hazelnupp/Test_Hazelnupp.cpp b/Test_Hazelnupp/Test_Hazelnupp.cpp
new file mode 100644
index 0000000..7d88034
--- /dev/null
+++ b/Test_Hazelnupp/Test_Hazelnupp.cpp
@@ -0,0 +1,148 @@
+#include "CppUnitTest.h"
+#include "helper.h"
+#include "../Hazelnupp/Hazelnupp.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+namespace TestHazelnupp
+{
+ TEST_CLASS(_Basics)
+ {
+ public:
+
+ // Tests the application path gets exported correctly
+ TEST_METHOD(ApplicationPathWorks)
+ {
+ // Setup
+ ArgList args({
+ "/my/fake/path/wahoo.out"
+ });
+
+ // Exercise
+ Hazelnupp nupp(C_Ify(args));
+
+ // Verify
+ Assert::AreEqual(std::string("/my/fake/path/wahoo.out"), nupp.GetExecutableName());
+
+ return;
+ }
+
+ // Tests keys exist after parsing
+ TEST_METHOD(BasicParsing_KeysExist)
+ {
+ // Setup
+ ArgList args({
+ "/my/fake/path/wahoo.out",
+ "--my_string",
+ "billybob",
+ "--my_void",
+ "--my_float",
+ "-23.199",
+ "--my_int",
+ "199",
+ "--my_num_list",
+ "1",
+ "2",
+ "3",
+ "4",
+ "--my_str_list",
+ "apple",
+ "banana",
+ "pumpkin",
+ });
+
+ // Exercise
+ Hazelnupp nupp(C_Ify(args));
+
+ // Verify
+ Assert::IsTrue(nupp.HasParam("--my_string"));
+ Assert::IsTrue(nupp.HasParam("--my_void"));
+ Assert::IsTrue(nupp.HasParam("--my_float"));
+ Assert::IsTrue(nupp.HasParam("--my_int"));
+ Assert::IsTrue(nupp.HasParam("--my_num_list"));
+ Assert::IsTrue(nupp.HasParam("--my_str_list"));
+
+ return;
+ }
+
+ // Tests keys are of the correct type after parsing
+ TEST_METHOD(BasicParsing_CorrectType)
+ {
+ // Setup
+ ArgList args({
+ "/my/fake/path/wahoo.out",
+ "--my_string",
+ "billybob",
+ "--my_void",
+ "--my_float",
+ "-23.199",
+ "--my_int",
+ "199",
+ "--my_num_list",
+ "1",
+ "2",
+ "3",
+ "4",
+ "--my_str_list",
+ "apple",
+ "banana",
+ "pumpkin",
+ });
+
+ // Exercise
+ Hazelnupp nupp(C_Ify(args));
+
+ // Verify
+ Assert::IsTrue(nupp["--my_string"].GetDataType() == DATA_TYPE::STRING);
+ Assert::IsTrue(nupp["--my_void"].GetDataType() == DATA_TYPE::VOID);
+ Assert::IsTrue(nupp["--my_float"].GetDataType() == DATA_TYPE::FLOAT);
+ Assert::IsTrue(nupp["--my_int"].GetDataType() == DATA_TYPE::INT);
+ Assert::IsTrue(nupp["--my_num_list"].GetDataType() == DATA_TYPE::LIST);
+ Assert::IsTrue(nupp["--my_str_list"].GetDataType() == DATA_TYPE::LIST);
+
+ return;
+ }
+
+ // Tests keys have the correct value after parsing
+ TEST_METHOD(BasicParsing_CorrectValues)
+ {
+ // Setup
+ ArgList args({
+ "/my/fake/path/wahoo.out",
+ "--my_string",
+ "billybob",
+ "--my_void",
+ "--my_float",
+ "-23.199",
+ "--my_int",
+ "199",
+ "--my_num_list",
+ "1",
+ "2",
+ "3",
+ "4",
+ "--my_str_list",
+ "apple",
+ "banana",
+ "pumpkin",
+ });
+
+ // Exercise
+ Hazelnupp nupp(C_Ify(args));
+
+ // Verify
+ Assert::AreEqual(nupp["--my_string"].GetString(), std::string("billybob"));
+ Assert::AreEqual(nupp["--my_float"].GetFloat32(), -23.199);
+ Assert::AreEqual(nupp["--my_int"].GetInt32(), 199);
+ Assert::AreEqual(nupp["--my_num_list"].GetList()[0]->GetInt32(), 1);
+ Assert::AreEqual(nupp["--my_num_list"].GetList()[1]->GetInt32(), 2);
+ Assert::AreEqual(nupp["--my_num_list"].GetList()[2]->GetInt32(), 3);
+ Assert::AreEqual(nupp["--my_num_list"].GetList()[3]->GetInt32(), 4);
+ Assert::AreEqual(nupp["--my_str_list"].GetList()[0]->GetString(), std::string("apple"));
+ Assert::AreEqual(nupp["--my_str_list"].GetList()[1]->GetString(), std::string("banana"));
+ Assert::AreEqual(nupp["--my_str_list"].GetList()[2]->GetString(), std::string("pumpkin"));
+
+ return;
+ }
+ };
+}
diff --git a/Test_Hazelnupp/Test_Hazelnupp.vcxproj b/Test_Hazelnupp/Test_Hazelnupp.vcxproj
new file mode 100644
index 0000000..20b4123
--- /dev/null
+++ b/Test_Hazelnupp/Test_Hazelnupp.vcxproj
@@ -0,0 +1,172 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 16.0
+ {B098AA37-A9CC-4BA2-B17D-189B706FDB16}
+ Win32Proj
+ TestHazelnupp
+ 10.0
+ NativeUnitTestProject
+
+
+
+ DynamicLibrary
+ true
+ v142
+ Unicode
+ false
+
+
+ DynamicLibrary
+ false
+ v142
+ true
+ Unicode
+ false
+
+
+ DynamicLibrary
+ true
+ v142
+ Unicode
+ false
+
+
+ DynamicLibrary
+ false
+ v142
+ true
+ Unicode
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+ true
+
+
+ false
+
+
+ false
+
+
+
+ NotUsing
+ Level3
+ true
+ $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;%(PreprocessorDefinitions)
+ true
+ pch.h
+
+
+ Windows
+ $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)
+
+
+
+
+ NotUsing
+ Level3
+ true
+ $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)
+ _DEBUG;%(PreprocessorDefinitions)
+ true
+ pch.h
+
+
+ Windows
+ $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)
+
+
+
+
+ NotUsing
+ Level3
+ true
+ true
+ true
+ $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;%(PreprocessorDefinitions)
+ true
+ pch.h
+
+
+ Windows
+ true
+ true
+ $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)
+
+
+
+
+ NotUsing
+ Level3
+ true
+ true
+ true
+ $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)
+ NDEBUG;%(PreprocessorDefinitions)
+ true
+ pch.h
+
+
+ Windows
+ true
+ true
+ $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)
+
+
+
+
+
+
+
+ {9aeaa0c6-9088-4f6e-9224-5c67d3163a17}
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Test_Hazelnupp/Test_Hazelnupp.vcxproj.filters b/Test_Hazelnupp/Test_Hazelnupp.vcxproj.filters
new file mode 100644
index 0000000..a79436e
--- /dev/null
+++ b/Test_Hazelnupp/Test_Hazelnupp.vcxproj.filters
@@ -0,0 +1,27 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ Quelldateien
+
+
+
+
+ Headerdateien
+
+
+
\ No newline at end of file
diff --git a/Test_Hazelnupp/helper.h b/Test_Hazelnupp/helper.h
new file mode 100644
index 0000000..0b5a461
--- /dev/null
+++ b/Test_Hazelnupp/helper.h
@@ -0,0 +1,6 @@
+#pragma once
+#include
+
+#define C_Ify(vector) vector.size(), vector.data()
+
+typedef std::vector ArgList;