diff --git a/SDK/include/NDK/Application.hpp b/SDK/include/NDK/Application.hpp index ef697e48a..5d918ef8e 100644 --- a/SDK/include/NDK/Application.hpp +++ b/SDK/include/NDK/Application.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace Ndk diff --git a/SDK/include/NDK/Application.inl b/SDK/include/NDK/Application.inl index e65d8d5d0..f44ff9e8c 100644 --- a/SDK/include/NDK/Application.inl +++ b/SDK/include/NDK/Application.inl @@ -38,6 +38,7 @@ namespace Ndk s_application = nullptr; } + #ifndef NDK_SERVER template T& Application::AddWindow(Args&&... args) { @@ -46,6 +47,7 @@ namespace Ndk m_windows.emplace_back(new T(std::forward(args)...)); return static_cast(*m_windows.back().get()); } + #endif template World& Application::AddWorld(Args&&... args) diff --git a/SDK/include/NDK/BaseComponent.inl b/SDK/include/NDK/BaseComponent.inl index f6bd79578..71f8ee2c1 100644 --- a/SDK/include/NDK/BaseComponent.inl +++ b/SDK/include/NDK/BaseComponent.inl @@ -2,7 +2,7 @@ // This file is part of the "Nazara Development Kit" // For conditions of distribution and use, see copyright notice in Prerequesites.hpp -#include +#include #include namespace Ndk diff --git a/SDK/src/NDK/LuaBinding_SDK.cpp b/SDK/src/NDK/LuaBinding_SDK.cpp index ec041e4b2..3d5088a7e 100644 --- a/SDK/src/NDK/LuaBinding_SDK.cpp +++ b/SDK/src/NDK/LuaBinding_SDK.cpp @@ -59,6 +59,7 @@ namespace Ndk application.SetMethod("Quit", &Application::Quit); /*********************************** Ndk::Console **********************************/ + #ifndef NDK_SERVER consoleClass.Inherit(nodeClass, [] (ConsoleHandle* handle) -> Nz::Node* { return handle->GetObject(); @@ -84,6 +85,7 @@ namespace Ndk //consoleClass.SetMethod("SetTextFont", &Console::SetTextFont); consoleClass.SetMethod("Show", &Console::Show, true); + #endif /*********************************** Ndk::Entity **********************************/ entityClass.SetMethod("Enable", &Entity::Enable); @@ -248,4 +250,4 @@ namespace Ndk } instance.SetGlobal("ComponentType"); } -} \ No newline at end of file +} diff --git a/SDK/src/NDK/World.cpp b/SDK/src/NDK/World.cpp index 1762f1d12..fc53143dd 100644 --- a/SDK/src/NDK/World.cpp +++ b/SDK/src/NDK/World.cpp @@ -14,7 +14,7 @@ namespace Ndk { - World::~World() + World::~World() noexcept { // La destruction doit se faire dans un ordre précis Clear(); diff --git a/include/Nazara/Audio/OpenAL.hpp b/include/Nazara/Audio/OpenAL.hpp index 5d6fa2634..eab95e6d0 100644 --- a/include/Nazara/Audio/OpenAL.hpp +++ b/include/Nazara/Audio/OpenAL.hpp @@ -87,7 +87,6 @@ namespace Nz static bool OpenDevice(); static OpenALFunc LoadEntry(const char* name, bool throwException = false); }; -} // al NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFER3F alBuffer3f; @@ -186,6 +185,8 @@ NAZARA_AUDIO_API extern OpenALDetail::LPALCOPENDEVICE alcOpenDevice; NAZARA_AUDIO_API extern OpenALDetail::LPALCPROCESSCONTEXT alcProcessContext; NAZARA_AUDIO_API extern OpenALDetail::LPALCSUSPENDCONTEXT alcSuspendContext; +} + #endif // NAZARA_AUDIO_OPENAL #endif // NAZARA_OPENAL_HPP diff --git a/include/Nazara/Core/ResourceSaver.hpp b/include/Nazara/Core/ResourceSaver.hpp index be2880cd0..05b6d7175 100644 --- a/include/Nazara/Core/ResourceSaver.hpp +++ b/include/Nazara/Core/ResourceSaver.hpp @@ -27,6 +27,7 @@ namespace Nz friend Type; public: + using ExtensionGetter = bool (*)(const String& extension); using FormatQuerier = bool (*)(const String& format); using FileSaver = bool (*)(const Type& resource, const String& filePath, const Parameters& parameters); using StreamSaver = bool (*)(const Type& resource, const String& format, Stream& stream, const Parameters& parameters); diff --git a/include/Nazara/Core/ResourceSaver.inl b/include/Nazara/Core/ResourceSaver.inl index 954b86a0e..11d3f2a44 100644 --- a/include/Nazara/Core/ResourceSaver.inl +++ b/include/Nazara/Core/ResourceSaver.inl @@ -28,7 +28,7 @@ namespace Nz { for (Saver& saver : Type::s_savers) { - ExtensionGetter isExtensionSupported = std::get<0>(loader); + ExtensionGetter isExtensionSupported = std::get<0>(saver); if (isExtensionSupported && isExtensionSupported(extension)) return true; diff --git a/include/Nazara/Graphics/SkyboxBackground.hpp b/include/Nazara/Graphics/SkyboxBackground.hpp index 427548dc0..95ce2872a 100644 --- a/include/Nazara/Graphics/SkyboxBackground.hpp +++ b/include/Nazara/Graphics/SkyboxBackground.hpp @@ -30,7 +30,7 @@ namespace Nz SkyboxBackground(TextureRef cubemapTexture = TextureRef()); ~SkyboxBackground() = default; - void Draw(const AbstractViewer* viewer) const; + void Draw(const AbstractViewer* viewer) const override; BackgroundType GetBackgroundType() const override; inline const Vector3f& GetMovementOffset() const; diff --git a/include/Nazara/Math/BoundingVolume.inl b/include/Nazara/Math/BoundingVolume.inl index 15107e755..a1efd8364 100644 --- a/include/Nazara/Math/BoundingVolume.inl +++ b/include/Nazara/Math/BoundingVolume.inl @@ -636,7 +636,7 @@ namespace Nz if (extend > Extend_Max) return false; - boundingVolume->extend = extend; + boundingVolume->extend = static_cast(extend); if (!Unserialize(context, &boundingVolume->aabb)) return false; diff --git a/include/Nazara/Math/Frustum.hpp b/include/Nazara/Math/Frustum.hpp index e170c2e55..2e51c0bd6 100644 --- a/include/Nazara/Math/Frustum.hpp +++ b/include/Nazara/Math/Frustum.hpp @@ -55,6 +55,11 @@ namespace Nz String ToString() const; + template + friend bool Serialize(SerializationContext& context, const Frustum& frustum); + template + friend bool Unserialize(SerializationContext& context, Frustum* frustum); + private: Vector3 m_corners[BoxCorner_Max+1]; Plane m_planes[FrustumPlane_Max+1]; @@ -62,9 +67,6 @@ namespace Nz typedef Frustum Frustumd; typedef Frustum Frustumf; - - template bool Serialize(SerializationContext& context, const Frustum& frustum); - template bool Unserialize(SerializationContext& context, Frustum* frustum); } template diff --git a/include/Nazara/Math/Frustum.inl b/include/Nazara/Math/Frustum.inl index 2e78682d1..b9f56c1e1 100644 --- a/include/Nazara/Math/Frustum.inl +++ b/include/Nazara/Math/Frustum.inl @@ -688,13 +688,13 @@ namespace Nz { for (unsigned int i = 0; i <= BoxCorner_Max; ++i) { - if (!Serialize(context, m_corners[i])) + if (!Serialize(context, frustum.m_corners[i])) return false; } for (unsigned int i = 0; i <= FrustumPlane_Max; ++i) { - if (!Serialize(context, m_planes[i])) + if (!Serialize(context, frustum.m_planes[i])) return false; } @@ -702,24 +702,24 @@ namespace Nz } /*! - * \brief Unserializes a Matrix4 + * \brief Unserializes a Frustum * \return true if successfully unserialized * * \param context Serialization context - * \param matrix Output matrix + * \param matrix Output frustum */ template bool Unserialize(SerializationContext& context, Frustum* frustum) { for (unsigned int i = 0; i <= BoxCorner_Max; ++i) { - if (!Unserialize(context, &m_corners[i])) + if (!Unserialize(context, &frustum->m_corners[i])) return false; } for (unsigned int i = 0; i <= FrustumPlane_Max; ++i) { - if (!Unserialize(context, &m_planes[i])) + if (!Unserialize(context, &frustum->m_planes[i])) return false; } diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index afa8143e3..b0decee2a 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -1792,9 +1792,10 @@ namespace Nz template bool Unserialize(SerializationContext& context, Matrix4* matrix) { + T* head = matrix->operator T*(); for (unsigned int i = 0; i < 16; ++i) { - if (!Unserialize(context, &matrix[i])) + if (!Unserialize(context, head + i)) return false; } diff --git a/include/Nazara/Network/RUdpConnection.hpp b/include/Nazara/Network/RUdpConnection.hpp index 20285b6fc..2896ec6ce 100644 --- a/include/Nazara/Network/RUdpConnection.hpp +++ b/include/Nazara/Network/RUdpConnection.hpp @@ -119,6 +119,10 @@ namespace Nz struct PeerData //TODO: Move this to RUdpClient { + PeerData() = default; + PeerData(PeerData&& other) = default; + PeerData& operator=(PeerData&& other) = default; + std::array, PacketPriority_Max + 1> pendingPackets; std::deque pendingAckQueue; std::set receivedQueue; @@ -153,6 +157,6 @@ namespace Nz }; } -#include +#include -#endif // NAZARA_RUDPSERVER_HPP \ No newline at end of file +#endif // NAZARA_RUDPSERVER_HPP diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index 403a7a534..94d7f891d 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -153,7 +153,6 @@ namespace Nz static void OnContextChanged(const Context* newContext); static void OnContextDestruction(const Context* context); }; -} NAZARA_RENDERER_API extern PFNGLACTIVETEXTUREPROC glActiveTexture; NAZARA_RENDERER_API extern PFNGLATTACHSHADERPROC glAttachShader; @@ -336,6 +335,8 @@ NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapInter NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI; #endif +} + #endif // NAZARA_RENDERER_OPENGL #endif // NAZARA_OPENGL_HPP diff --git a/src/Nazara/Audio/OpenAL.cpp b/src/Nazara/Audio/OpenAL.cpp index 1c30cd5f1..f527b682d 100644 --- a/src/Nazara/Audio/OpenAL.cpp +++ b/src/Nazara/Audio/OpenAL.cpp @@ -372,7 +372,6 @@ namespace Nz return entry; } -} // al OpenALDetail::LPALBUFFER3F alBuffer3f = nullptr; @@ -470,3 +469,5 @@ OpenALDetail::LPALCMAKECONTEXTCURRENT alcMakeContextCurrent = nullptr; OpenALDetail::LPALCOPENDEVICE alcOpenDevice = nullptr; OpenALDetail::LPALCPROCESSCONTEXT alcProcessContext = nullptr; OpenALDetail::LPALCSUSPENDCONTEXT alcSuspendContext = nullptr; + +} diff --git a/src/Nazara/Core/Posix/DirectoryImpl.cpp b/src/Nazara/Core/Posix/DirectoryImpl.cpp index e3add7fd5..e23c82626 100644 --- a/src/Nazara/Core/Posix/DirectoryImpl.cpp +++ b/src/Nazara/Core/Posix/DirectoryImpl.cpp @@ -49,7 +49,7 @@ namespace Nz return true; else { - if (errno != ENOENT) + if (errno == EBADF || errno == EOVERFLOW) NazaraError("Unable to get next result: " + Error::GetLastSystemError()); return false; diff --git a/src/Nazara/Core/Posix/FileImpl.cpp b/src/Nazara/Core/Posix/FileImpl.cpp index 3fa93f6f2..31c1ace73 100644 --- a/src/Nazara/Core/Posix/FileImpl.cpp +++ b/src/Nazara/Core/Posix/FileImpl.cpp @@ -54,11 +54,11 @@ namespace Nz int flags; mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; - if (mode & OpenMode_ReadWrite) + if ((mode & OpenMode_ReadWrite) == OpenMode_ReadWrite) flags = O_CREAT | O_RDWR; - else if (mode & OpenMode_ReadOnly) + else if ((mode & OpenMode_ReadOnly) == OpenMode_ReadOnly) flags = O_RDONLY; - else if (mode & OpenMode_WriteOnly) + else if ((mode & OpenMode_WriteOnly) == OpenMode_WriteOnly) flags = O_CREAT | O_WRONLY; else return false; diff --git a/src/Nazara/Core/String.cpp b/src/Nazara/Core/String.cpp index 3e72e1dce..b94715457 100644 --- a/src/Nazara/Core/String.cpp +++ b/src/Nazara/Core/String.cpp @@ -3204,14 +3204,12 @@ namespace Nz EnsureOwnership(true); m_sharedString->size = 1; - m_sharedString->string[0] = character; m_sharedString->string[1] = '\0'; } else - { - auto newString = std::make_shared(1); - newString->string[0] = character; - } + m_sharedString = std::make_shared(1); + + m_sharedString->string[0] = character; } else ReleaseString(); diff --git a/src/Nazara/Network/RUdpConnection.cpp b/src/Nazara/Network/RUdpConnection.cpp index 12fdc3d22..f8b57cf00 100644 --- a/src/Nazara/Network/RUdpConnection.cpp +++ b/src/Nazara/Network/RUdpConnection.cpp @@ -2,7 +2,7 @@ // This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include #include #include #include @@ -474,7 +474,7 @@ namespace Nz return true; } - inline void RUdpConnection::Uninitialize() + void RUdpConnection::Uninitialize() { } diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index 5cc0865ea..0834999bc 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -2078,7 +2078,6 @@ namespace Nz }; static_assert(VertexComponent_Max + 1 == 16, "Attribute index array is incomplete"); -} PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; PFNGLATTACHSHADERPROC glAttachShader = nullptr; @@ -2260,3 +2259,5 @@ GLX::PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr; GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA = nullptr; GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr; #endif + +} diff --git a/tests/Engine/Core/File.cpp b/tests/Engine/Core/File.cpp index c00af74d1..2a87c8495 100644 --- a/tests/Engine/Core/File.cpp +++ b/tests/Engine/Core/File.cpp @@ -9,7 +9,7 @@ SCENARIO("File", "[CORE][FILE]") { Nz::File file("Test File.txt", Nz::OpenMode_ReadWrite); REQUIRE(file.GetDirectory() == Nz::Directory::GetCurrent() + NAZARA_DIRECTORY_SEPARATOR); - CHECK(file.IsOpen()); + REQUIRE(file.IsOpen()); THEN("We are allowed to write 3 times 'Test String'") { @@ -50,4 +50,38 @@ SCENARIO("File", "[CORE][FILE]") } } } + + GIVEN("The test file") + { + REQUIRE(Nz::File::Exists("resources/Engine/Core/FileTest.txt")); + + Nz::File fileTest("resources/Engine/Core/FileTest.txt", Nz::OpenMode_ReadOnly | Nz::OpenMode_Text); + + WHEN("We read the first line of the file") + { + REQUIRE(fileTest.IsOpen()); + Nz::String content = fileTest.ReadLine(); + + THEN("The content must be 'Test'") + { + REQUIRE(content == "Test"); + } + } + } + + GIVEN("Nothing") + { + WHEN("We get the absolute path of something containing relative path") + { + Nz::String containingDot = "/resources/Spaceship/./spaceship.mtl"; + Nz::String containingDoubleDot = "/resources/Spaceship/../Spaceship/spaceship.mtl"; + + THEN("The relative positioning should disappear") + { + Nz::String containingNoMoreDot = "/resources/Spaceship/spaceship.mtl"; + REQUIRE(Nz::File::AbsolutePath(containingDot) == containingNoMoreDot); + REQUIRE(Nz::File::AbsolutePath(containingDoubleDot) == containingNoMoreDot); + } + } + } } diff --git a/tests/Engine/Core/Serialization.cpp b/tests/Engine/Core/Serialization.cpp new file mode 100644 index 000000000..299b9cc8f --- /dev/null +++ b/tests/Engine/Core/Serialization.cpp @@ -0,0 +1,261 @@ +#include + +#include +#include +#include +#include +#include + +#include + +SCENARIO("Serialization", "[CORE][SERIALIZATION]") +{ + GIVEN("A context of serialization") + { + std::array datas; // The array must be bigger than any of the serializable classes + Nz::MemoryView stream(datas.data(), datas.size()); + + Nz::SerializationContext context; + context.stream = &stream; + + WHEN("We serialize basic types") + { + THEN("Arithmetical types") + { + context.stream->SetCursorPos(0); + REQUIRE(Serialize(context, 3)); + int value = 0; + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &value)); + REQUIRE(value == 3); + } + + THEN("Boolean type") + { + context.stream->SetCursorPos(0); + REQUIRE(Serialize(context, true)); + context.stream->SetCursorPos(0); + bool value = false; + REQUIRE(Unserialize(context, &value)); + REQUIRE(value == true); + } + } + + WHEN("We serialize mathematical classes") + { + THEN("BoudingVolume") + { + context.stream->SetCursorPos(0); + Nz::BoundingVolumef nullVolume = Nz::BoundingVolumef::Null(); + Nz::BoundingVolumef copy(nullVolume); + REQUIRE(Serialize(context, nullVolume)); + nullVolume = Nz::BoundingVolumef::Infinite(); + REQUIRE(nullVolume != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &nullVolume)); + REQUIRE(nullVolume == copy); + } + + THEN("Box") + { + context.stream->SetCursorPos(0); + Nz::Boxf zeroBox = Nz::Boxf::Zero(); + Nz::Boxf copy(zeroBox); + REQUIRE(Serialize(context, zeroBox)); + zeroBox = Nz::Boxf(1, 1, 1, 1, 1, 1); + REQUIRE(zeroBox != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &zeroBox)); + REQUIRE(zeroBox == copy); + } + + THEN("EulerAngles") + { + context.stream->SetCursorPos(0); + Nz::EulerAnglesf zeroEuler = Nz::EulerAnglesf::Zero(); + Nz::EulerAnglesf copy(zeroEuler); + REQUIRE(Serialize(context, zeroEuler)); + zeroEuler = Nz::EulerAnglesf(10, 24, 6); // Random values + REQUIRE(zeroEuler != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &zeroEuler)); + REQUIRE(zeroEuler == copy); + } + + THEN("Frustum") + { + context.stream->SetCursorPos(0); + Nz::Frustumf frustum; + frustum.Build(10, 10, 10, 100, Nz::Vector3f::UnitX(), Nz::Vector3f::UnitZ()); // Random values + Nz::Frustumf copy(frustum); + REQUIRE(Serialize(context, frustum)); + frustum.Build(50, 40, 20, 100, Nz::Vector3f::UnitX(), Nz::Vector3f::UnitZ()); + for (unsigned int i = 0; i <= Nz::BoxCorner_Max; ++i) + REQUIRE(frustum.GetCorner(static_cast(i)) != copy.GetCorner(static_cast(i))); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &frustum)); + for (unsigned int i = 0; i <= Nz::BoxCorner_Max; ++i) + REQUIRE(frustum.GetCorner(static_cast(i)) == copy.GetCorner(static_cast(i))); + } + + THEN("Matrix4") + { + context.stream->SetCursorPos(0); + Nz::Matrix4f zeroMatrix = Nz::Matrix4f::Zero(); + Nz::Matrix4f copy(zeroMatrix); + REQUIRE(Serialize(context, zeroMatrix)); + zeroMatrix = Nz::Matrix4f::Identity(); // Random values + REQUIRE(zeroMatrix != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &zeroMatrix)); + REQUIRE(zeroMatrix == copy); + } + + THEN("OrientedBox") + { + context.stream->SetCursorPos(0); + Nz::OrientedBoxf zeroOBB = Nz::OrientedBoxf::Zero(); + Nz::OrientedBoxf copy(zeroOBB); + REQUIRE(Serialize(context, zeroOBB)); + zeroOBB = Nz::OrientedBoxf(1, 1, 1, 1, 1, 1); // Random values + REQUIRE(zeroOBB != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &zeroOBB)); + REQUIRE(zeroOBB == copy); + } + + THEN("Plane") + { + context.stream->SetCursorPos(0); + Nz::Planef planeXY = Nz::Planef::XY(); + Nz::Planef copy(planeXY); + REQUIRE(Serialize(context, planeXY)); + planeXY = Nz::Planef::YZ(); + REQUIRE(planeXY != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &planeXY)); + REQUIRE(planeXY == copy); + } + + THEN("Quaternion") + { + context.stream->SetCursorPos(0); + Nz::Quaternionf quaternionIdentity = Nz::Quaternionf::Identity(); + Nz::Quaternionf copy(quaternionIdentity); + REQUIRE(Serialize(context, quaternionIdentity)); + quaternionIdentity = Nz::Quaternionf::Zero(); + REQUIRE(quaternionIdentity != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &quaternionIdentity)); + REQUIRE(quaternionIdentity == copy); + } + + THEN("Ray") + { + context.stream->SetCursorPos(0); + Nz::Rayf axisX = Nz::Rayf::AxisX(); + Nz::Rayf copy(axisX); + REQUIRE(Serialize(context, axisX)); + axisX = Nz::Rayf::AxisY(); + REQUIRE(axisX != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &axisX)); + REQUIRE(axisX == copy); + } + + THEN("Rect") + { + context.stream->SetCursorPos(0); + Nz::Rectf zeroRect = Nz::Rectf::Zero(); + Nz::Rectf copy(zeroRect); + REQUIRE(Serialize(context, zeroRect)); + zeroRect = Nz::Rectf(1, 1, 1, 1); // Random values + REQUIRE(zeroRect != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &zeroRect)); + REQUIRE(zeroRect == copy); + } + + THEN("Sphere") + { + context.stream->SetCursorPos(0); + Nz::Spheref zeroSphere = Nz::Spheref::Zero(); + Nz::Spheref copy(zeroSphere); + REQUIRE(Serialize(context, zeroSphere)); + zeroSphere = Nz::Spheref::Unit(); + REQUIRE(zeroSphere != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &zeroSphere)); + REQUIRE(zeroSphere == copy); + } + + THEN("Vector2") + { + context.stream->SetCursorPos(0); + Nz::Vector2f unitX = Nz::Vector2f::UnitX(); + Nz::Vector2f copy(unitX); + REQUIRE(Serialize(context, unitX)); + unitX = Nz::Vector2f::UnitY(); + REQUIRE(unitX != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &unitX)); + REQUIRE(unitX == copy); + } + + THEN("Vector3") + { + context.stream->SetCursorPos(0); + Nz::Vector3f unitX = Nz::Vector3f::UnitX(); + Nz::Vector3f copy(unitX); + REQUIRE(Serialize(context, unitX)); + unitX = Nz::Vector3f::UnitY(); + REQUIRE(unitX != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &unitX)); + REQUIRE(unitX == copy); + } + + THEN("Vector4") + { + context.stream->SetCursorPos(0); + Nz::Vector4f unitX = Nz::Vector4f::UnitX(); + Nz::Vector4f copy(unitX); + REQUIRE(Serialize(context, unitX)); + unitX = Nz::Vector4f::UnitY(); + REQUIRE(unitX != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &unitX)); + REQUIRE(unitX == copy); + } + } + + WHEN("We serialize core classes") + { + THEN("Color") + { + context.stream->SetCursorPos(0); + Nz::Color red = Nz::Color::Red; + Nz::Color copy(red); + REQUIRE(Serialize(context, red)); + red = Nz::Color::Black; + REQUIRE(red != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &red)); + REQUIRE(red == copy); + } + + THEN("String") + { + context.stream->SetCursorPos(0); + Nz::String string = "string"; + Nz::String copy(string); + REQUIRE(Serialize(context, string)); + string = "another"; + REQUIRE(string != copy); + context.stream->SetCursorPos(0); + REQUIRE(Unserialize(context, &string)); + REQUIRE(string == copy); + } + } + } +} diff --git a/tests/Engine/Core/String.cpp b/tests/Engine/Core/String.cpp index a563d0b7f..eac5eaef6 100644 --- a/tests/Engine/Core/String.cpp +++ b/tests/Engine/Core/String.cpp @@ -82,6 +82,21 @@ SCENARIO("String", "[CORE][STRING]") } } + GIVEN("One character string") + { + Nz::String characterString; + + WHEN("We set the string to one character") + { + characterString.Set('/'); + + THEN("The string must contain it") + { + REQUIRE(characterString == '/'); + } + } + } + /* TODO GIVEN("One unicode string") { diff --git a/tests/resources/Engine/Core/FileTest.txt b/tests/resources/Engine/Core/FileTest.txt new file mode 100644 index 000000000..345e6aef7 --- /dev/null +++ b/tests/resources/Engine/Core/FileTest.txt @@ -0,0 +1 @@ +Test