Slight modifications, and added unit tests
This commit is contained in:
@@ -158,5 +158,126 @@ namespace TestHazelnupp
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that abbreviations can be queried
|
||||
TEST_METHOD(Get_Abbreviation)
|
||||
{
|
||||
// Setup
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
nupp.RegisterAbbreviation("-ms", "--my_string");
|
||||
nupp.RegisterAbbreviation("-mv", "--my_void");
|
||||
nupp.RegisterAbbreviation("-mi", "--my_int");
|
||||
nupp.RegisterAbbreviation("-mf", "--my_float");
|
||||
nupp.RegisterAbbreviation("-mnl", "--my_num_list");
|
||||
nupp.RegisterAbbreviation("-msl", "--my_str_list");
|
||||
|
||||
// Exercise, verify
|
||||
Assert::AreEqual(std::string("--my_num_list"), nupp.GetAbbreviation("-mnl"));
|
||||
Assert::AreEqual(std::string("--my_void"), nupp.GetAbbreviation("-mv"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that getting an unknown abbreviation will ersult in an empty string
|
||||
TEST_METHOD(Unknown_Abbrevation_Is_Empty_String)
|
||||
{
|
||||
// Setup
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
nupp.RegisterAbbreviation("-ms", "--my_string");
|
||||
nupp.RegisterAbbreviation("-mv", "--my_void");
|
||||
nupp.RegisterAbbreviation("-mi", "--my_int");
|
||||
nupp.RegisterAbbreviation("-mf", "--my_float");
|
||||
nupp.RegisterAbbreviation("-mnl", "--my_num_list");
|
||||
nupp.RegisterAbbreviation("-msl", "--my_str_list");
|
||||
|
||||
// Exercise
|
||||
nupp.ClearAbbreviations();
|
||||
|
||||
// Verify
|
||||
Assert::AreEqual(std::string(), nupp.GetAbbreviation("-t"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that HasAbbreviation works
|
||||
TEST_METHOD(Has_Abbreviation)
|
||||
{
|
||||
// Setup
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
// Exercise, verify
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-f"));
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-m"));
|
||||
|
||||
nupp.RegisterAbbreviation("-f", "--force");
|
||||
|
||||
Assert::IsTrue(nupp.HasAbbreviation("-f"));
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-m"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that abbreviations can be deleted individually
|
||||
TEST_METHOD(Clear_Abbreviation)
|
||||
{
|
||||
// Setup
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
nupp.RegisterAbbreviation("-ms", "--my_string");
|
||||
nupp.RegisterAbbreviation("-mv", "--my_void");
|
||||
nupp.RegisterAbbreviation("-mi", "--my_int");
|
||||
nupp.RegisterAbbreviation("-mf", "--my_float");
|
||||
nupp.RegisterAbbreviation("-mnl", "--my_num_list");
|
||||
nupp.RegisterAbbreviation("-msl", "--my_str_list");
|
||||
|
||||
// Exercise
|
||||
nupp.ClearAbbreviation("-mv");
|
||||
nupp.ClearAbbreviation("-mf");
|
||||
nupp.ClearAbbreviation("-msl");
|
||||
|
||||
// Verify
|
||||
Assert::IsTrue(nupp.HasAbbreviation("-ms"));
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-mv"));
|
||||
Assert::IsTrue(nupp.HasAbbreviation("-mi"));
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-mf"));
|
||||
Assert::IsTrue(nupp.HasAbbreviation("-mnl"));
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-msl"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that all abbreviations can be deleted at once
|
||||
TEST_METHOD(Clear_Abbreviations)
|
||||
{
|
||||
// Setup
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
nupp.RegisterAbbreviation("-ms" , "--my_string");
|
||||
nupp.RegisterAbbreviation("-mv" , "--my_void");
|
||||
nupp.RegisterAbbreviation("-mi" , "--my_int");
|
||||
nupp.RegisterAbbreviation("-mf" , "--my_float");
|
||||
nupp.RegisterAbbreviation("-mnl", "--my_num_list");
|
||||
nupp.RegisterAbbreviation("-msl", "--my_str_list");
|
||||
|
||||
// Exercise
|
||||
nupp.ClearAbbreviations();
|
||||
|
||||
// Verify
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-ms" ));
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-mv" ));
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-mi" ));
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-mf" ));
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-mnl"));
|
||||
Assert::IsFalse(nupp.HasAbbreviation("-msl"));
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -317,5 +317,125 @@ namespace TestHazelnupp
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that constraints can cleared invidivually
|
||||
TEST_METHOD(Can_Clear_Constraints_Individually)
|
||||
{
|
||||
// Setup
|
||||
ArgList args({
|
||||
"/my/fake/path/wahoo.out",
|
||||
"--dummy",
|
||||
"--empty-list",
|
||||
});
|
||||
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
nupp.RegisterConstraints({
|
||||
ParamConstraint::Require("--not-there", {}, true),
|
||||
ParamConstraint::Require("--default-val", {"32"}, true),
|
||||
});
|
||||
|
||||
// Exercise
|
||||
nupp.ClearConstraint("--not-there");
|
||||
|
||||
|
||||
// Verify
|
||||
nupp.Parse(C_Ify(args));
|
||||
|
||||
// Also verifies that parse does not throw an exception for --not-there
|
||||
|
||||
Assert::IsTrue(nupp.HasParam("--default-val"), L"Default value is missing");
|
||||
Assert::AreEqual(32, nupp["--default-val"].GetInt32(), L"Default value has wrong value");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that constraints can cleared invidivually
|
||||
TEST_METHOD(Can_Clear_All_Constraints)
|
||||
{
|
||||
// Setup
|
||||
ArgList args({
|
||||
"/my/fake/path/wahoo.out",
|
||||
"--dummy",
|
||||
"--empty-list",
|
||||
});
|
||||
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
nupp.RegisterConstraints({
|
||||
ParamConstraint::Require("--not-there", {}, true)
|
||||
});
|
||||
|
||||
// Exercise
|
||||
nupp.ClearConstraints();
|
||||
|
||||
// Verify
|
||||
nupp.Parse(C_Ify(args));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that setting a constraint for a parameter again will overwrite the existing one
|
||||
TEST_METHOD(Can_Override_Constraints)
|
||||
{
|
||||
// Setup
|
||||
ArgList args({
|
||||
"/my/fake/path/wahoo.out",
|
||||
"--dummy",
|
||||
"--empty-list",
|
||||
});
|
||||
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
nupp.RegisterConstraints({
|
||||
ParamConstraint::Require("--not-there", {}, true)
|
||||
});
|
||||
|
||||
//Exercise
|
||||
nupp.RegisterConstraints({
|
||||
ParamConstraint::Require("--not-there", {}, false)
|
||||
});
|
||||
|
||||
// Verify
|
||||
nupp.Parse(C_Ify(args));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that the GetConstraint returns the correct constraint information
|
||||
TEST_METHOD(Get_Constraint)
|
||||
{
|
||||
// Setup
|
||||
ArgList args({
|
||||
"/my/fake/path/wahoo.out",
|
||||
"--dummy",
|
||||
"--empty-list",
|
||||
});
|
||||
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
ParamConstraint dftvalConst_expected = ParamConstraint::Require("--default-val", {"32"}, true);
|
||||
nupp.RegisterConstraints({
|
||||
ParamConstraint::Require("--not-there", {}, true),
|
||||
dftvalConst_expected,
|
||||
ParamConstraint::Require("--another-one", {"bites"}, true),
|
||||
});
|
||||
|
||||
// Exercise
|
||||
ParamConstraint dftvalConst = nupp.GetConstraint("--default-val");
|
||||
|
||||
// Verify
|
||||
Assert::IsTrue(dftvalConst_expected.key == dftvalConst.key, L"key");
|
||||
Assert::IsTrue(dftvalConst_expected.required == dftvalConst.required, L"required");
|
||||
Assert::IsTrue(dftvalConst_expected.defaultValue == dftvalConst.defaultValue, L"defaultValue");
|
||||
Assert::IsTrue(dftvalConst_expected.wantedType == dftvalConst.wantedType, L"wantedType");
|
||||
Assert::IsTrue(dftvalConst_expected.constrainType == dftvalConst.constrainType, L"constrainType");
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
139
Test_Hazelnupp/Descriptions.cpp
Normal file
139
Test_Hazelnupp/Descriptions.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
#include "CppUnitTest.h"
|
||||
#include "helper.h"
|
||||
#include "../Hazelnupp/Hazelnupp.h"
|
||||
#include "../Hazelnupp/HazelnuppException.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace Hazelnp;
|
||||
|
||||
namespace TestHazelnupp
|
||||
{
|
||||
TEST_CLASS(_Descriptions)
|
||||
{
|
||||
public:
|
||||
|
||||
// Tests that the application description can be set and returned
|
||||
TEST_METHOD(Set_Get_Application_Brief)
|
||||
{
|
||||
// Setup
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
std::string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse in quam tincidunt sapien euismod egestas eget vel dolor. Duis non turpis porttitor, convallis velit at.";
|
||||
|
||||
// Exercise
|
||||
nupp.SetBriefDescription(text);
|
||||
|
||||
// Verify
|
||||
Assert::AreEqual(text, nupp.GetBriefDescription());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that a parameters description can be set and returned
|
||||
TEST_METHOD(Can_Set_Parameter_Description)
|
||||
{
|
||||
// Setup
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
// Exercise
|
||||
nupp.RegisterDescription("--force", "Just force it");
|
||||
nupp.RegisterDescription("--lose", "Just lose it");
|
||||
nupp.RegisterDescription("--crazy", "Go crazy");
|
||||
|
||||
// Verify
|
||||
Assert::AreEqual(std::string("Just force it"), nupp.GetDescription("--force"));
|
||||
Assert::AreEqual(std::string("Go crazy"), nupp.GetDescription("--crazy"));
|
||||
Assert::AreEqual(std::string("Just lose it"), nupp.GetDescription("--lose"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//! Tests that HasDescription works
|
||||
TEST_METHOD(Has_Description)
|
||||
{
|
||||
// Setup
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
// Exercise, verify
|
||||
Assert::IsFalse(nupp.HasDescription("--force"));
|
||||
Assert::IsFalse(nupp.HasDescription("--main"));
|
||||
|
||||
nupp.RegisterDescription("--force", "Just force it");
|
||||
|
||||
Assert::IsTrue(nupp.HasDescription("--force"));
|
||||
Assert::IsFalse(nupp.HasDescription("--main"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that an unknown parameter returns an empty string
|
||||
TEST_METHOD(No_Description_Is_Empty_String)
|
||||
{
|
||||
// Setup
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
// Exercise
|
||||
nupp.RegisterDescription("--force", "Just force it");
|
||||
nupp.RegisterDescription("--lose", "Just lose it");
|
||||
nupp.RegisterDescription("--crazy", "Go crazy");
|
||||
|
||||
// Verify
|
||||
Assert::AreEqual(std::string(), nupp.GetDescription("--man"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that a description can be deleted
|
||||
TEST_METHOD(ClearDescription)
|
||||
{
|
||||
// Setup
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
// Exercise
|
||||
nupp.RegisterDescription("--force", "Just force it");
|
||||
nupp.RegisterDescription("--lose", "Just lose it");
|
||||
nupp.RegisterDescription("--crazy", "Go crazy");
|
||||
|
||||
nupp.ClearDescription("--lose");
|
||||
|
||||
// Verify
|
||||
|
||||
// These two should still work
|
||||
Assert::AreEqual(std::string("Just force it"), nupp.GetDescription("--force"));
|
||||
Assert::AreEqual(std::string("Go crazy"), nupp.GetDescription("--crazy"));
|
||||
|
||||
Assert::IsFalse(nupp.HasDescription("--lose"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that all descriptions can be deleted at once
|
||||
TEST_METHOD(ClearDescriptions)
|
||||
{
|
||||
// Setup
|
||||
Hazelnupp nupp;
|
||||
nupp.SetCrashOnFail(false);
|
||||
|
||||
// Exercise
|
||||
nupp.RegisterDescription("--force", "Just force it");
|
||||
nupp.RegisterDescription("--lose", "Just lose it");
|
||||
nupp.RegisterDescription("--crazy", "Go crazy");
|
||||
|
||||
nupp.ClearDescriptions();
|
||||
|
||||
// Verify
|
||||
|
||||
// These two should still work
|
||||
Assert::IsFalse(nupp.HasDescription("--force"));
|
||||
Assert::IsFalse(nupp.HasDescription("--crazy"));
|
||||
Assert::IsFalse(nupp.HasDescription("--lose"));
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
@@ -160,6 +160,7 @@
|
||||
<ClCompile Include="Basics.cpp" />
|
||||
<ClCompile Include="Constraints.cpp" />
|
||||
<ClCompile Include="Conversion.cpp" />
|
||||
<ClCompile Include="Descriptions.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Hazelnupp\Hazelnupp.vcxproj">
|
||||
|
@@ -32,5 +32,8 @@
|
||||
<ClCompile Include="Conversion.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Descriptions.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user