General bug fixes (#142)
* Core/Bitset: Fix TestAll method * Fix documentation * Fix color and their conversions * Core/ByteStream: Fix return of Write * Fix compiler warnings * Math/Algorithm: Fix angle normalization * Math/BoundingVolume: Fix lerp * Math: Fix relation between Matrix4 and Quaternion * More tests * X11/Window: Fix mouse moved event generated when doing Mouse::SetPosition * Update ChangeLog * Should fix compilation on Windows * Should fix compilation on Windows Forgot to include array for Windows
This commit is contained in:
committed by
Jérôme Leclercq
parent
f2506ee918
commit
f991a9529e
@@ -30,9 +30,63 @@ TEST_CASE("Apply", "[CORE][ALGORITHM]")
|
||||
|
||||
TEST_CASE("ComputeHash", "[CORE][ALGORITHM]")
|
||||
{
|
||||
SECTION("Compute hash of '0'")
|
||||
/*SECTION("Compute CRC32 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_CRC32, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "596A3B55");
|
||||
}
|
||||
|
||||
SECTION("Compute CRC64 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_CRC64, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "33302B9FC23855A8");
|
||||
}
|
||||
|
||||
SECTION("Compute Fletcher16 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_Fletcher16, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "F5CA");
|
||||
}*/
|
||||
|
||||
SECTION("Compute MD5 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_MD5, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "81DC9BDB52D04DC20036DBD8313ED055");
|
||||
}
|
||||
|
||||
SECTION("Compute SHA1 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_SHA1, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "7110EDA4D09E062AA5E4A390B0A572AC0D2C0220");
|
||||
}
|
||||
|
||||
SECTION("Compute SHA224 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_SHA224, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "99FB2F48C6AF4761F904FC85F95EB56190E5D40B1F44EC3A9C1FA319");
|
||||
}
|
||||
|
||||
SECTION("Compute SHA256 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_SHA256, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "03AC674216F3E15C761EE1A5E255F067953623C8B388B4459E13F978D7C846F4");
|
||||
}
|
||||
|
||||
SECTION("Compute SHA384 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_SHA384, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "504F008C8FCF8B2ED5DFCDE752FC5464AB8BA064215D9C5B5FC486AF3D9AB8C81B14785180D2AD7CEE1AB792AD44798C");
|
||||
}
|
||||
|
||||
SECTION("Compute SHA512 of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_SHA512, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "D404559F602EAB6FD602AC7680DACBFAADD13630335E951F097AF3900E9DE176B6DB28512F2E000B9D04FBA5133E8B1C6E8DF59DB3A8AB9D60BE4B97CC9E81DB");
|
||||
}
|
||||
|
||||
SECTION("Compute Whirlpool of '1234'")
|
||||
{
|
||||
auto result = Nz::ComputeHash(Nz::HashType_Whirlpool, "1234");
|
||||
REQUIRE(result.ToHex().ToUpper() == "2F9959B230A44678DD2DC29F037BA1159F233AA9AB183CE3A0678EAAE002E5AA6F27F47144A1A4365116D3DB1B58EC47896623B92D85CB2F191705DAF11858B8");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
template<typename Block> void Check(const char* title);
|
||||
template<typename Block> void CheckAppend(const char* title);
|
||||
template<typename Block> void CheckBitOps(const char* title);
|
||||
template<typename Block> void CheckBitOpsMultipleBlocks(const char* title);
|
||||
template<typename Block> void CheckConstructor(const char* title);
|
||||
template<typename Block> void CheckCopyMoveSwap(const char* title);
|
||||
template<typename Block> void CheckRead(const char* title);
|
||||
@@ -28,6 +29,7 @@ void Check(const char* title)
|
||||
CheckCopyMoveSwap<Block>(title);
|
||||
|
||||
CheckBitOps<Block>(title);
|
||||
CheckBitOpsMultipleBlocks<Block>(title);
|
||||
|
||||
CheckAppend<Block>(title);
|
||||
CheckRead<Block>(title);
|
||||
@@ -111,7 +113,68 @@ void CheckBitOps(const char* title)
|
||||
{
|
||||
CHECK(andBitset == Nz::Bitset<Block>("00001"));
|
||||
CHECK(orBitset == Nz::Bitset<Block>("11111"));
|
||||
CHECK(orBitset.TestAll());
|
||||
CHECK(xorBitset == Nz::Bitset<Block>("11110"));
|
||||
CHECK(!xorBitset.TestAll());
|
||||
CHECK((~orBitset).TestNone());
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We perform bit shifts")
|
||||
{
|
||||
first.ShiftLeft(1);
|
||||
second.ShiftRight(2);
|
||||
|
||||
THEN("We should obtain these")
|
||||
{
|
||||
CHECK(first == Nz::Bitset<Block>("10010"));
|
||||
CHECK(second == Nz::Bitset<Block>("101"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Block>
|
||||
void CheckBitOpsMultipleBlocks(const char* title)
|
||||
{
|
||||
SECTION(title)
|
||||
{
|
||||
GIVEN("Two bitsets")
|
||||
{
|
||||
Nz::Bitset<Block> first("01001011010010101001010011010101001");
|
||||
Nz::Bitset<Block> second("10111111101101110110111101101110110");
|
||||
|
||||
WHEN("We perform operators")
|
||||
{
|
||||
Nz::Bitset<Block> andBitset = first & second;
|
||||
Nz::Bitset<Block> orBitset = first | second;
|
||||
Nz::Bitset<Block> xorBitset = first ^ second;
|
||||
|
||||
THEN("They should operate as logical operators")
|
||||
{
|
||||
CHECK(andBitset == Nz::Bitset<Block>("00001011000000100000010001000100000"));
|
||||
CHECK(orBitset == Nz::Bitset<Block>("11111111111111111111111111111111111"));
|
||||
CHECK(orBitset.TestAll());
|
||||
CHECK(xorBitset == Nz::Bitset<Block>("11110100111111011111101110111011111"));
|
||||
CHECK(!xorBitset.TestAll());
|
||||
CHECK((~orBitset).TestNone());
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We perform bit shifts")
|
||||
{
|
||||
first.ShiftLeft(16);
|
||||
second.ShiftRight(16);
|
||||
|
||||
THEN("We should obtain these")
|
||||
{
|
||||
CHECK(first == Nz::Bitset<Block>("10010100110101010010000000000000000"));
|
||||
first.ShiftLeft(1);
|
||||
CHECK(first == Nz::Bitset<Block>("00101001101010100100000000000000000"));
|
||||
CHECK(second == Nz::Bitset<Block>("1011111110110111011"));
|
||||
second.ShiftRight(1);
|
||||
CHECK(second == Nz::Bitset<Block>("101111111011011101"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
73
tests/Engine/Core/ByteStream.cpp
Normal file
73
tests/Engine/Core/ByteStream.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include <Nazara/Core/ByteStream.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
SCENARIO("ByteStream", "[CORE][BYTESTREAM]")
|
||||
{
|
||||
GIVEN("A bytestream from a bunch of bytes")
|
||||
{
|
||||
const int numberOfBytes = 16;
|
||||
std::array<Nz::Int8, numberOfBytes> data;
|
||||
|
||||
Nz::ByteStream byteStream(data.data(), numberOfBytes);
|
||||
|
||||
WHEN("We write some data in it")
|
||||
{
|
||||
int value = 5;
|
||||
byteStream << value;
|
||||
Nz::String string = "string";
|
||||
byteStream << string;
|
||||
|
||||
byteStream.FlushBits();
|
||||
|
||||
THEN("We can retrieve them")
|
||||
{
|
||||
const void* const ptrData = data.data();
|
||||
Nz::ByteStream readStream;
|
||||
CHECK(readStream.GetSize() == 0);
|
||||
readStream = Nz::ByteStream(ptrData, byteStream.GetSize());
|
||||
int retrievedValue = 0;
|
||||
readStream >> retrievedValue;
|
||||
Nz::String retrievedString;
|
||||
readStream >> retrievedString;
|
||||
|
||||
CHECK(value == retrievedValue);
|
||||
CHECK(string == retrievedString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("A bytestream with a byte array and a different endianness")
|
||||
{
|
||||
const int numberOfBytes = 16;
|
||||
Nz::ByteArray byteArray(numberOfBytes);
|
||||
Nz::ByteStream byteStream(&byteArray);
|
||||
|
||||
byteStream.SetDataEndianness(Nz::GetPlatformEndianness() == Nz::Endianness_BigEndian ? Nz::Endianness_LittleEndian : Nz::Endianness_BigEndian);
|
||||
|
||||
WHEN("We write an integer")
|
||||
{
|
||||
int value = 7;
|
||||
byteStream.Write(&value, sizeof(int));
|
||||
bool boolean = true;
|
||||
byteStream << boolean;
|
||||
byteStream.FlushBits();
|
||||
|
||||
THEN("We can retrieve it properly")
|
||||
{
|
||||
Nz::ByteStream tmpStream(&byteArray);
|
||||
tmpStream.SetDataEndianness(byteStream.GetDataEndianness());
|
||||
|
||||
int retrievedValue = 0;
|
||||
tmpStream.Read(&retrievedValue, sizeof(int));
|
||||
CHECK(value == retrievedValue);
|
||||
|
||||
Nz::ByteStream readStream(std::move(tmpStream));
|
||||
bool retrievedBoolean = false;
|
||||
readStream >> retrievedBoolean;
|
||||
CHECK(boolean == retrievedBoolean);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,24 +6,43 @@ SCENARIO("Clock", "[CORE][CLOCK]")
|
||||
{
|
||||
GIVEN("A clock paused")
|
||||
{
|
||||
Nz::UInt64 initialTime = 1;
|
||||
Nz::UInt64 initialTime = 100;
|
||||
Nz::Clock clock(initialTime, true);
|
||||
|
||||
WHEN("We get time")
|
||||
WHEN("We get time since it is paused")
|
||||
{
|
||||
THEN("Time must be the initialTime")
|
||||
{
|
||||
REQUIRE(clock.GetMicroseconds() == initialTime);
|
||||
CHECK(clock.GetMicroseconds() == initialTime);
|
||||
CHECK(clock.IsPaused());
|
||||
}
|
||||
}
|
||||
|
||||
AND_WHEN("We unpause it")
|
||||
WHEN("We unpause it")
|
||||
{
|
||||
clock.Unpause();
|
||||
REQUIRE(!clock.IsPaused());
|
||||
|
||||
THEN("Time must not be the initialTime")
|
||||
{
|
||||
clock.Unpause();
|
||||
THEN("Time must not be the initialTime")
|
||||
{
|
||||
Nz::Thread::Sleep(1);
|
||||
REQUIRE(clock.GetMicroseconds() != initialTime);
|
||||
}
|
||||
Nz::Thread::Sleep(1);
|
||||
Nz::UInt64 microSeconds = clock.GetMicroseconds();
|
||||
CHECK(microSeconds != initialTime);
|
||||
CHECK(microSeconds / 1000 <= clock.GetMilliseconds());
|
||||
CHECK(microSeconds / (1000.f * 1000.f) <= clock.GetSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We restart it")
|
||||
{
|
||||
clock.Restart();
|
||||
|
||||
THEN("It is unpaused and we can pause it")
|
||||
{
|
||||
CHECK(!clock.IsPaused());
|
||||
clock.Pause();
|
||||
CHECK(clock.IsPaused());
|
||||
CHECK(clock.GetMicroseconds() != initialTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,63 @@
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
const float epsilon = 0.01f;
|
||||
|
||||
void CompareColor(const Nz::Color& lhs, const Nz::Color& rhs)
|
||||
{
|
||||
Nz::UInt8 tolerance = 3;
|
||||
REQUIRE(Nz::NumberEquals(lhs.r, rhs.r, tolerance));
|
||||
REQUIRE(Nz::NumberEquals(lhs.g, rhs.g, tolerance));
|
||||
REQUIRE(Nz::NumberEquals(lhs.b, rhs.b, tolerance));
|
||||
REQUIRE(Nz::NumberEquals(lhs.a, rhs.a, tolerance));
|
||||
}
|
||||
|
||||
void CompareCMY(const Nz::Color& color, float cyan, float magenta, float yellow)
|
||||
{
|
||||
float retrievedCyan = 0.f, retrievedMagenta = 0.f, retrievedYellow = 0.f;
|
||||
Nz::Color::ToCMY(color, &retrievedCyan, &retrievedMagenta, &retrievedYellow);
|
||||
CHECK(retrievedCyan == Approx(cyan).epsilon(epsilon));
|
||||
CHECK(retrievedMagenta == Approx(magenta).epsilon(epsilon));
|
||||
CHECK(retrievedYellow == Approx(yellow).epsilon(epsilon));
|
||||
}
|
||||
|
||||
void CompareCMYK(const Nz::Color& color, float cyan, float magenta, float yellow, float black)
|
||||
{
|
||||
float retrievedCyan = 0.f, retrievedMagenta = 0.f, retrievedYellow = 0.f, retrievedBlack = 0.f;
|
||||
Nz::Color::ToCMYK(color, &retrievedCyan, &retrievedMagenta, &retrievedYellow, &retrievedBlack);
|
||||
CHECK(retrievedCyan == Approx(cyan).epsilon(epsilon));
|
||||
CHECK(retrievedMagenta == Approx(magenta).epsilon(epsilon));
|
||||
CHECK(retrievedYellow == Approx(yellow).epsilon(epsilon));
|
||||
CHECK(retrievedBlack == Approx(black).epsilon(epsilon));
|
||||
}
|
||||
|
||||
void CompareHSL(const Nz::Color& color, float hue, float saturation, float luminosity)
|
||||
{
|
||||
float retrievedHue = 0.f, retrievedSaturation = 0.f, retrievedLuminosity = 0.f;
|
||||
Nz::Color::ToHSL(color, &retrievedHue, &retrievedSaturation, &retrievedLuminosity);
|
||||
CHECK(retrievedHue == Approx(hue).epsilon(epsilon));
|
||||
CHECK(retrievedSaturation == Approx(saturation).epsilon(epsilon));
|
||||
CHECK(retrievedLuminosity == Approx(luminosity).epsilon(epsilon));
|
||||
}
|
||||
|
||||
void CompareHSV(const Nz::Color& color, float hue, float saturation, float value)
|
||||
{
|
||||
float retrievedHue = 0.f, retrievedSaturation = 0.f, retrievedValue = 0.f;
|
||||
Nz::Color::ToHSV(color, &retrievedHue, &retrievedSaturation, &retrievedValue);
|
||||
CHECK(retrievedHue == Approx(hue).epsilon(epsilon));
|
||||
CHECK(retrievedSaturation == Approx(saturation).epsilon(epsilon));
|
||||
CHECK(retrievedValue == Approx(value).epsilon(epsilon));
|
||||
}
|
||||
|
||||
void CompareXYZ(const Nz::Color& color, float x, float y, float z)
|
||||
{
|
||||
Nz::Vector3f retrievedValues = Nz::Vector3f::Zero();
|
||||
Nz::Color::ToXYZ(color, &retrievedValues);
|
||||
CHECK(retrievedValues.x == Approx(x).epsilon(epsilon));
|
||||
CHECK(retrievedValues.y == Approx(y).epsilon(epsilon));
|
||||
CHECK(retrievedValues.z == Approx(z).epsilon(epsilon));
|
||||
}
|
||||
|
||||
SCENARIO("Color", "[CORE][COLOR]")
|
||||
{
|
||||
GIVEN("Two colors, one red (255) and one gray (128)")
|
||||
@@ -19,4 +76,74 @@ SCENARIO("Color", "[CORE][COLOR]")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("A special color in different formats")
|
||||
{
|
||||
struct ColorData
|
||||
{
|
||||
const char* name;
|
||||
Nz::Color rgb;
|
||||
float cyan, magenta, yellow;
|
||||
float cyanK, magentaK, yellowK, black;
|
||||
float hue, saturation, luminosity;
|
||||
float hueV, saturationV, valueV;
|
||||
float x, y, z;
|
||||
};
|
||||
|
||||
std::vector<ColorData> colors;
|
||||
|
||||
colors.push_back({
|
||||
"blue",
|
||||
Nz::Color(0, 0, 255),
|
||||
1.f, 1.f, 0.f, // cmy
|
||||
1.f, 1.f, 0.f, 0.f, // cmyk
|
||||
240.f, 1.f, 0.5f, // hsl
|
||||
240.f, 1.f, 1.f, // hsv
|
||||
18.05f, 7.22f, 95.05f // xyz
|
||||
});
|
||||
|
||||
colors.push_back({
|
||||
"white",
|
||||
Nz::Color(255, 255, 255),
|
||||
0.f, 0.f, 0.f, // cmy
|
||||
0.f, 0.f, 0.f, 0.f, // cmyk
|
||||
0.f, 0.f, 1.f, // hsl
|
||||
0.f, 0.f, 1.f, // hsv
|
||||
95.05f, 100.f, 108.09f // xyz
|
||||
});
|
||||
|
||||
colors.push_back({
|
||||
"greenish",
|
||||
Nz::Color(5, 191, 25),
|
||||
0.980f, 0.251f, 0.902f, // cmy
|
||||
0.974f, 0.000f, 0.869f, 0.251f, // cmyk
|
||||
126.f, 0.95f, 0.38f, // hsl
|
||||
126.f, 0.97f, 0.75f, // hsv
|
||||
18.869f, 37.364f, 7.137f // xyz
|
||||
});
|
||||
|
||||
for (const ColorData& color : colors)
|
||||
{
|
||||
WHEN("We perform conversion for: " + color.name)
|
||||
{
|
||||
THEN("From other color spaces")
|
||||
{
|
||||
CompareColor(color.rgb, Nz::Color::FromCMY(color.cyan, color.magenta, color.yellow));
|
||||
CompareColor(color.rgb, Nz::Color::FromCMYK(color.cyanK, color.magentaK, color.yellowK, color.black));
|
||||
CompareColor(color.rgb, Nz::Color::FromHSL(color.hue, color.saturation, color.luminosity));
|
||||
CompareColor(color.rgb, Nz::Color::FromHSV(color.hueV, color.saturationV, color.valueV));
|
||||
CompareColor(color.rgb, Nz::Color::FromXYZ(Nz::Vector3f(color.x, color.y, color.z)));
|
||||
}
|
||||
|
||||
THEN("To other color spaces")
|
||||
{
|
||||
CompareCMY(color.rgb, color.cyan, color.magenta, color.yellow);
|
||||
CompareCMYK(color.rgb, color.cyanK, color.magentaK, color.yellowK, color.black);
|
||||
CompareHSL(color.rgb, color.hue, color.saturation, color.luminosity);
|
||||
CompareHSV(color.rgb, color.hueV, color.saturationV, color.valueV);
|
||||
CompareXYZ(color.rgb, color.x, color.y, color.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,5 +24,21 @@ SCENARIO("MemoryPool", "[CORE][MEMORYPOOL]")
|
||||
memoryPool.Delete(vector2);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We construct three vectors")
|
||||
{
|
||||
Nz::Vector2<int>* vector1 = memoryPool.New<Nz::Vector2<int>>(1, 2);
|
||||
Nz::Vector2<int>* vector2 = memoryPool.New<Nz::Vector2<int>>(3, 4);
|
||||
Nz::Vector2<int>* vector3 = memoryPool.New<Nz::Vector2<int>>(5, 6);
|
||||
|
||||
THEN("Memory is available")
|
||||
{
|
||||
vector1->x = 3;
|
||||
vector2->y = 5;
|
||||
CHECK(*vector1 == Nz::Vector2<int>(3, 2));
|
||||
CHECK(*vector2 == Nz::Vector2<int>(3, 5));
|
||||
CHECK(vector3->GetSquaredLength() == Approx(61.f));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,35 +3,204 @@
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
void nullAction(void*)
|
||||
{
|
||||
}
|
||||
|
||||
SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
||||
{
|
||||
GIVEN("An empty ParameterList")
|
||||
{
|
||||
Nz::ParameterList parameterList;
|
||||
|
||||
WHEN("We add String 'string'")
|
||||
WHEN("We add Bool 'true' and analogous")
|
||||
{
|
||||
bool boolean = true;
|
||||
parameterList.SetParameter("bool", boolean);
|
||||
|
||||
long long intTrue = 1;
|
||||
parameterList.SetParameter("intTrue", intTrue);
|
||||
long long intFalse = 0;
|
||||
parameterList.SetParameter("intFalse", intFalse);
|
||||
|
||||
Nz::String strTrue = "true";
|
||||
parameterList.SetParameter("strTrue", strTrue);
|
||||
Nz::String strFalse = "false";
|
||||
parameterList.SetParameter("strFalse", strFalse);
|
||||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
bool retrievedValue = false;
|
||||
CHECK(parameterList.GetBooleanParameter("bool", &retrievedValue));
|
||||
CHECK(retrievedValue == boolean);
|
||||
}
|
||||
|
||||
THEN("Conversion from int to bool should also work")
|
||||
{
|
||||
bool retrievedValue = false;
|
||||
CHECK(parameterList.GetBooleanParameter("intTrue", &retrievedValue));
|
||||
CHECK(retrievedValue);
|
||||
CHECK(parameterList.GetBooleanParameter("intFalse", &retrievedValue));
|
||||
CHECK(!retrievedValue);
|
||||
}
|
||||
|
||||
THEN("Conversion from str to bool should also work")
|
||||
{
|
||||
bool retrievedValue = false;
|
||||
CHECK(parameterList.GetBooleanParameter("strTrue", &retrievedValue));
|
||||
CHECK(retrievedValue);
|
||||
CHECK(parameterList.GetBooleanParameter("strFalse", &retrievedValue));
|
||||
CHECK(!retrievedValue);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We add Color 'rgb(1, 2, 3)'")
|
||||
{
|
||||
Nz::Color rgb(1, 2, 3);
|
||||
parameterList.SetParameter("color", rgb);
|
||||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
Nz::Color retrievedColor;
|
||||
CHECK(parameterList.GetColorParameter("color", &retrievedColor));
|
||||
CHECK(retrievedColor == rgb);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We add Double '3.0' and analogous")
|
||||
{
|
||||
double fl = 3.0;
|
||||
parameterList.SetParameter("double", fl);
|
||||
|
||||
long long intDouble = 3;
|
||||
parameterList.SetParameter("intDouble", intDouble);
|
||||
|
||||
Nz::String strDouble = "3.0";
|
||||
parameterList.SetParameter("strDouble", strDouble);
|
||||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
double retrievedValue;
|
||||
CHECK(parameterList.GetDoubleParameter("double", &retrievedValue));
|
||||
CHECK(retrievedValue == fl);
|
||||
}
|
||||
|
||||
THEN("Conversion from int to double should also work")
|
||||
{
|
||||
double retrievedValue;
|
||||
CHECK(parameterList.GetDoubleParameter("intDouble", &retrievedValue));
|
||||
CHECK(retrievedValue == fl);
|
||||
}
|
||||
|
||||
THEN("Conversion from string to double should also work")
|
||||
{
|
||||
double retrievedValue;
|
||||
CHECK(parameterList.GetDoubleParameter("strDouble", &retrievedValue));
|
||||
CHECK(retrievedValue == fl);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We add Int '3' and analogous")
|
||||
{
|
||||
long long i = 3;
|
||||
parameterList.SetParameter("int", i);
|
||||
|
||||
bool trueInt = 1;
|
||||
parameterList.SetParameter("trueInt", trueInt);
|
||||
bool falseInt = 0;
|
||||
parameterList.SetParameter("falseInt", falseInt);
|
||||
|
||||
double doubleInt = 3;
|
||||
parameterList.SetParameter("doubleInt", doubleInt);
|
||||
|
||||
Nz::String strInt = "3";
|
||||
parameterList.SetParameter("strInt", strInt);
|
||||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
long long retrievedValue;
|
||||
CHECK(parameterList.GetIntegerParameter("int", &retrievedValue));
|
||||
CHECK(retrievedValue == i);
|
||||
}
|
||||
|
||||
THEN("Conversion from bool to int should also work")
|
||||
{
|
||||
long long retrievedValue;
|
||||
CHECK(parameterList.GetIntegerParameter("trueInt", &retrievedValue));
|
||||
CHECK(retrievedValue == trueInt);
|
||||
CHECK(parameterList.GetIntegerParameter("falseInt", &retrievedValue));
|
||||
CHECK(retrievedValue == falseInt);
|
||||
}
|
||||
|
||||
THEN("Conversion from double to int should also work")
|
||||
{
|
||||
long long retrievedValue;
|
||||
CHECK(parameterList.GetIntegerParameter("doubleInt", &retrievedValue));
|
||||
CHECK(retrievedValue == i);
|
||||
}
|
||||
|
||||
THEN("Conversion from string to int should also work")
|
||||
{
|
||||
long long retrievedValue;
|
||||
CHECK(parameterList.GetIntegerParameter("strInt", &retrievedValue));
|
||||
CHECK(retrievedValue == i);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We add String 'string' and analogous")
|
||||
{
|
||||
Nz::String string("string");
|
||||
parameterList.SetParameter("string", string);
|
||||
|
||||
bool trueString = 1;
|
||||
parameterList.SetParameter("trueString", trueString);
|
||||
bool falseString = 0;
|
||||
parameterList.SetParameter("falseString", falseString);
|
||||
|
||||
Nz::Color colorString(1, 2, 3);
|
||||
parameterList.SetParameter("colorString", colorString);
|
||||
|
||||
double doubleString = 3.0;
|
||||
parameterList.SetParameter("doubleString", doubleString);
|
||||
|
||||
long long intString = 3;
|
||||
parameterList.SetParameter("intString", intString);
|
||||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
Nz::String newString;
|
||||
REQUIRE(parameterList.GetStringParameter("string", &newString));
|
||||
REQUIRE(newString == string);
|
||||
CHECK(parameterList.GetStringParameter("string", &newString));
|
||||
CHECK(newString == string);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We add Float '3.f'")
|
||||
{
|
||||
double fl = 3.f;
|
||||
parameterList.SetParameter("double", fl);
|
||||
|
||||
THEN("We can get it back")
|
||||
THEN("Conversion from bool to str should also work")
|
||||
{
|
||||
double newFl;
|
||||
REQUIRE(parameterList.GetDoubleParameter("double", &newFl));
|
||||
REQUIRE(newFl == fl);
|
||||
Nz::String retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("trueString", &retrievedValue));
|
||||
CHECK(retrievedValue == "true");
|
||||
CHECK(parameterList.GetStringParameter("falseString", &retrievedValue));
|
||||
CHECK(retrievedValue == "false");
|
||||
}
|
||||
|
||||
THEN("Conversion from color to string should also work")
|
||||
{
|
||||
Nz::String retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("colorString", &retrievedValue));
|
||||
CHECK(retrievedValue == colorString.ToString());
|
||||
}
|
||||
|
||||
THEN("Conversion from string to double should also work")
|
||||
{
|
||||
Nz::String retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("doubleString", &retrievedValue));
|
||||
CHECK(retrievedValue == "3");
|
||||
}
|
||||
|
||||
THEN("Conversion from string to int should also work")
|
||||
{
|
||||
Nz::String retrievedValue;
|
||||
CHECK(parameterList.GetStringParameter("intString", &retrievedValue));
|
||||
CHECK(retrievedValue == "3");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +213,71 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]")
|
||||
THEN("We can get it back")
|
||||
{
|
||||
void* newPtrToStackValue = nullptr;
|
||||
REQUIRE(parameterList.GetPointerParameter("ptr", &newPtrToStackValue));
|
||||
REQUIRE(newPtrToStackValue == ptrToStackValue);
|
||||
CHECK(parameterList.GetPointerParameter("ptr", &newPtrToStackValue));
|
||||
CHECK(newPtrToStackValue == ptrToStackValue);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We set our own data")
|
||||
{
|
||||
struct Data {
|
||||
int i;
|
||||
float f;
|
||||
};
|
||||
|
||||
Data data{ 1, 3.f };
|
||||
parameterList.SetParameter("userData", &data, nullAction);
|
||||
|
||||
THEN("We can get it back")
|
||||
{
|
||||
Data retrievedValue;
|
||||
void* ptrToData = &retrievedValue;
|
||||
|
||||
CHECK(parameterList.GetUserdataParameter("userData", &ptrToData));
|
||||
Data* dataPtr = reinterpret_cast<Data*>(ptrToData);
|
||||
CHECK(dataPtr->i == data.i);
|
||||
CHECK(dataPtr->f == data.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("A parameter list with some values")
|
||||
{
|
||||
Nz::ParameterList parameterList;
|
||||
|
||||
long long i = 3;
|
||||
parameterList.SetParameter("i", i);
|
||||
double d = 1.0;
|
||||
parameterList.SetParameter("d", d);
|
||||
|
||||
parameterList.SetParameter("toaster");
|
||||
parameterList.SetParameter("str", "ing");
|
||||
|
||||
WHEN("We remove two elements")
|
||||
{
|
||||
CHECK(parameterList.HasParameter("i"));
|
||||
CHECK(parameterList.HasParameter("toaster"));
|
||||
|
||||
parameterList.RemoveParameter("i");
|
||||
parameterList.RemoveParameter("toaster");
|
||||
|
||||
THEN("They do not exist anymore")
|
||||
{
|
||||
CHECK(!parameterList.HasParameter("i"));
|
||||
CHECK(!parameterList.HasParameter("toaster"));
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We copy this list")
|
||||
{
|
||||
Nz::ParameterList copy = parameterList;
|
||||
|
||||
THEN("It has the same elements")
|
||||
{
|
||||
CHECK(parameterList.HasParameter("i"));
|
||||
CHECK(parameterList.HasParameter("d"));
|
||||
CHECK(parameterList.HasParameter("toaster"));
|
||||
CHECK(parameterList.HasParameter("str"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user