Merge pull request #57 from Gawaboumga/linux-compilation-merge

Linux compilation merge

Former-commit-id: 36205a0bb6c84b55e7af1323aa041fc10f49f894
This commit is contained in:
Lynix 2016-04-04 12:28:25 +02:00
commit f4f799baa1
25 changed files with 360 additions and 34 deletions

View File

@ -11,6 +11,7 @@
#include <NDK/World.hpp> #include <NDK/World.hpp>
#include <Nazara/Core/Clock.hpp> #include <Nazara/Core/Clock.hpp>
#include <Nazara/Utility/Window.hpp> #include <Nazara/Utility/Window.hpp>
#include <list>
#include <vector> #include <vector>
namespace Ndk namespace Ndk

View File

@ -38,6 +38,7 @@ namespace Ndk
s_application = nullptr; s_application = nullptr;
} }
#ifndef NDK_SERVER
template<typename T, typename... Args> template<typename T, typename... Args>
T& Application::AddWindow(Args&&... args) T& Application::AddWindow(Args&&... args)
{ {
@ -46,6 +47,7 @@ namespace Ndk
m_windows.emplace_back(new T(std::forward<Args>(args)...)); m_windows.emplace_back(new T(std::forward<Args>(args)...));
return static_cast<T&>(*m_windows.back().get()); return static_cast<T&>(*m_windows.back().get());
} }
#endif
template<typename... Args> template<typename... Args>
World& Application::AddWorld(Args&&... args) World& Application::AddWorld(Args&&... args)

View File

@ -2,7 +2,7 @@
// This file is part of the "Nazara Development Kit" // This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp // For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <Ndk/BaseComponent.hpp> #include <NDK/BaseComponent.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
namespace Ndk namespace Ndk

View File

@ -59,6 +59,7 @@ namespace Ndk
application.SetMethod("Quit", &Application::Quit); application.SetMethod("Quit", &Application::Quit);
/*********************************** Ndk::Console **********************************/ /*********************************** Ndk::Console **********************************/
#ifndef NDK_SERVER
consoleClass.Inherit<Nz::Node>(nodeClass, [] (ConsoleHandle* handle) -> Nz::Node* consoleClass.Inherit<Nz::Node>(nodeClass, [] (ConsoleHandle* handle) -> Nz::Node*
{ {
return handle->GetObject(); return handle->GetObject();
@ -84,6 +85,7 @@ namespace Ndk
//consoleClass.SetMethod("SetTextFont", &Console::SetTextFont); //consoleClass.SetMethod("SetTextFont", &Console::SetTextFont);
consoleClass.SetMethod("Show", &Console::Show, true); consoleClass.SetMethod("Show", &Console::Show, true);
#endif
/*********************************** Ndk::Entity **********************************/ /*********************************** Ndk::Entity **********************************/
entityClass.SetMethod("Enable", &Entity::Enable); entityClass.SetMethod("Enable", &Entity::Enable);
@ -248,4 +250,4 @@ namespace Ndk
} }
instance.SetGlobal("ComponentType"); instance.SetGlobal("ComponentType");
} }
} }

View File

@ -14,7 +14,7 @@
namespace Ndk namespace Ndk
{ {
World::~World() World::~World() noexcept
{ {
// La destruction doit se faire dans un ordre précis // La destruction doit se faire dans un ordre précis
Clear(); Clear();

View File

@ -87,7 +87,6 @@ namespace Nz
static bool OpenDevice(); static bool OpenDevice();
static OpenALFunc LoadEntry(const char* name, bool throwException = false); static OpenALFunc LoadEntry(const char* name, bool throwException = false);
}; };
}
// al // al
NAZARA_AUDIO_API extern OpenALDetail::LPALBUFFER3F alBuffer3f; 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::LPALCPROCESSCONTEXT alcProcessContext;
NAZARA_AUDIO_API extern OpenALDetail::LPALCSUSPENDCONTEXT alcSuspendContext; NAZARA_AUDIO_API extern OpenALDetail::LPALCSUSPENDCONTEXT alcSuspendContext;
}
#endif // NAZARA_AUDIO_OPENAL #endif // NAZARA_AUDIO_OPENAL
#endif // NAZARA_OPENAL_HPP #endif // NAZARA_OPENAL_HPP

View File

@ -27,6 +27,7 @@ namespace Nz
friend Type; friend Type;
public: public:
using ExtensionGetter = bool (*)(const String& extension);
using FormatQuerier = bool (*)(const String& format); using FormatQuerier = bool (*)(const String& format);
using FileSaver = bool (*)(const Type& resource, const String& filePath, const Parameters& parameters); 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); using StreamSaver = bool (*)(const Type& resource, const String& format, Stream& stream, const Parameters& parameters);

View File

@ -28,7 +28,7 @@ namespace Nz
{ {
for (Saver& saver : Type::s_savers) for (Saver& saver : Type::s_savers)
{ {
ExtensionGetter isExtensionSupported = std::get<0>(loader); ExtensionGetter isExtensionSupported = std::get<0>(saver);
if (isExtensionSupported && isExtensionSupported(extension)) if (isExtensionSupported && isExtensionSupported(extension))
return true; return true;

View File

@ -30,7 +30,7 @@ namespace Nz
SkyboxBackground(TextureRef cubemapTexture = TextureRef()); SkyboxBackground(TextureRef cubemapTexture = TextureRef());
~SkyboxBackground() = default; ~SkyboxBackground() = default;
void Draw(const AbstractViewer* viewer) const; void Draw(const AbstractViewer* viewer) const override;
BackgroundType GetBackgroundType() const override; BackgroundType GetBackgroundType() const override;
inline const Vector3f& GetMovementOffset() const; inline const Vector3f& GetMovementOffset() const;

View File

@ -636,7 +636,7 @@ namespace Nz
if (extend > Extend_Max) if (extend > Extend_Max)
return false; return false;
boundingVolume->extend = extend; boundingVolume->extend = static_cast<Extend>(extend);
if (!Unserialize(context, &boundingVolume->aabb)) if (!Unserialize(context, &boundingVolume->aabb))
return false; return false;

View File

@ -55,6 +55,11 @@ namespace Nz
String ToString() const; String ToString() const;
template<typename U>
friend bool Serialize(SerializationContext& context, const Frustum<U>& frustum);
template<typename U>
friend bool Unserialize(SerializationContext& context, Frustum<U>* frustum);
private: private:
Vector3<T> m_corners[BoxCorner_Max+1]; Vector3<T> m_corners[BoxCorner_Max+1];
Plane<T> m_planes[FrustumPlane_Max+1]; Plane<T> m_planes[FrustumPlane_Max+1];
@ -62,9 +67,6 @@ namespace Nz
typedef Frustum<double> Frustumd; typedef Frustum<double> Frustumd;
typedef Frustum<float> Frustumf; typedef Frustum<float> Frustumf;
template<typename T> bool Serialize(SerializationContext& context, const Frustum<T>& frustum);
template<typename T> bool Unserialize(SerializationContext& context, Frustum<T>* frustum);
} }
template<typename T> template<typename T>

View File

@ -688,13 +688,13 @@ namespace Nz
{ {
for (unsigned int i = 0; i <= BoxCorner_Max; ++i) for (unsigned int i = 0; i <= BoxCorner_Max; ++i)
{ {
if (!Serialize(context, m_corners[i])) if (!Serialize(context, frustum.m_corners[i]))
return false; return false;
} }
for (unsigned int i = 0; i <= FrustumPlane_Max; ++i) for (unsigned int i = 0; i <= FrustumPlane_Max; ++i)
{ {
if (!Serialize(context, m_planes[i])) if (!Serialize(context, frustum.m_planes[i]))
return false; return false;
} }
@ -702,24 +702,24 @@ namespace Nz
} }
/*! /*!
* \brief Unserializes a Matrix4 * \brief Unserializes a Frustum
* \return true if successfully unserialized * \return true if successfully unserialized
* *
* \param context Serialization context * \param context Serialization context
* \param matrix Output matrix * \param matrix Output frustum
*/ */
template<typename T> template<typename T>
bool Unserialize(SerializationContext& context, Frustum<T>* frustum) bool Unserialize(SerializationContext& context, Frustum<T>* frustum)
{ {
for (unsigned int i = 0; i <= BoxCorner_Max; ++i) for (unsigned int i = 0; i <= BoxCorner_Max; ++i)
{ {
if (!Unserialize(context, &m_corners[i])) if (!Unserialize(context, &frustum->m_corners[i]))
return false; return false;
} }
for (unsigned int i = 0; i <= FrustumPlane_Max; ++i) for (unsigned int i = 0; i <= FrustumPlane_Max; ++i)
{ {
if (!Unserialize(context, &m_planes[i])) if (!Unserialize(context, &frustum->m_planes[i]))
return false; return false;
} }

View File

@ -1792,9 +1792,10 @@ namespace Nz
template<typename T> template<typename T>
bool Unserialize(SerializationContext& context, Matrix4<T>* matrix) bool Unserialize(SerializationContext& context, Matrix4<T>* matrix)
{ {
T* head = matrix->operator T*();
for (unsigned int i = 0; i < 16; ++i) for (unsigned int i = 0; i < 16; ++i)
{ {
if (!Unserialize(context, &matrix[i])) if (!Unserialize(context, head + i))
return false; return false;
} }

View File

@ -119,6 +119,10 @@ namespace Nz
struct PeerData //TODO: Move this to RUdpClient struct PeerData //TODO: Move this to RUdpClient
{ {
PeerData() = default;
PeerData(PeerData&& other) = default;
PeerData& operator=(PeerData&& other) = default;
std::array<std::vector<PendingPacket>, PacketPriority_Max + 1> pendingPackets; std::array<std::vector<PendingPacket>, PacketPriority_Max + 1> pendingPackets;
std::deque<PendingAckPacket> pendingAckQueue; std::deque<PendingAckPacket> pendingAckQueue;
std::set<UInt16> receivedQueue; std::set<UInt16> receivedQueue;
@ -153,6 +157,6 @@ namespace Nz
}; };
} }
#include <Nazara/Network/RudpConnection.inl> #include <Nazara/Network/RUdpConnection.inl>
#endif // NAZARA_RUDPSERVER_HPP #endif // NAZARA_RUDPSERVER_HPP

View File

@ -153,7 +153,6 @@ namespace Nz
static void OnContextChanged(const Context* newContext); static void OnContextChanged(const Context* newContext);
static void OnContextDestruction(const Context* context); static void OnContextDestruction(const Context* context);
}; };
}
NAZARA_RENDERER_API extern PFNGLACTIVETEXTUREPROC glActiveTexture; NAZARA_RENDERER_API extern PFNGLACTIVETEXTUREPROC glActiveTexture;
NAZARA_RENDERER_API extern PFNGLATTACHSHADERPROC glAttachShader; NAZARA_RENDERER_API extern PFNGLATTACHSHADERPROC glAttachShader;
@ -336,6 +335,8 @@ NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapInter
NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI; NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;
#endif #endif
}
#endif // NAZARA_RENDERER_OPENGL #endif // NAZARA_RENDERER_OPENGL
#endif // NAZARA_OPENGL_HPP #endif // NAZARA_OPENGL_HPP

View File

@ -372,7 +372,6 @@ namespace Nz
return entry; return entry;
} }
}
// al // al
OpenALDetail::LPALBUFFER3F alBuffer3f = nullptr; OpenALDetail::LPALBUFFER3F alBuffer3f = nullptr;
@ -470,3 +469,5 @@ OpenALDetail::LPALCMAKECONTEXTCURRENT alcMakeContextCurrent = nullptr;
OpenALDetail::LPALCOPENDEVICE alcOpenDevice = nullptr; OpenALDetail::LPALCOPENDEVICE alcOpenDevice = nullptr;
OpenALDetail::LPALCPROCESSCONTEXT alcProcessContext = nullptr; OpenALDetail::LPALCPROCESSCONTEXT alcProcessContext = nullptr;
OpenALDetail::LPALCSUSPENDCONTEXT alcSuspendContext = nullptr; OpenALDetail::LPALCSUSPENDCONTEXT alcSuspendContext = nullptr;
}

View File

@ -49,7 +49,7 @@ namespace Nz
return true; return true;
else else
{ {
if (errno != ENOENT) if (errno == EBADF || errno == EOVERFLOW)
NazaraError("Unable to get next result: " + Error::GetLastSystemError()); NazaraError("Unable to get next result: " + Error::GetLastSystemError());
return false; return false;

View File

@ -54,11 +54,11 @@ namespace Nz
int flags; int flags;
mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; 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; flags = O_CREAT | O_RDWR;
else if (mode & OpenMode_ReadOnly) else if ((mode & OpenMode_ReadOnly) == OpenMode_ReadOnly)
flags = O_RDONLY; flags = O_RDONLY;
else if (mode & OpenMode_WriteOnly) else if ((mode & OpenMode_WriteOnly) == OpenMode_WriteOnly)
flags = O_CREAT | O_WRONLY; flags = O_CREAT | O_WRONLY;
else else
return false; return false;

View File

@ -3204,14 +3204,12 @@ namespace Nz
EnsureOwnership(true); EnsureOwnership(true);
m_sharedString->size = 1; m_sharedString->size = 1;
m_sharedString->string[0] = character;
m_sharedString->string[1] = '\0'; m_sharedString->string[1] = '\0';
} }
else else
{ m_sharedString = std::make_shared<SharedString>(1);
auto newString = std::make_shared<SharedString>(1);
newString->string[0] = character; m_sharedString->string[0] = character;
}
} }
else else
ReleaseString(); ReleaseString();

View File

@ -2,7 +2,7 @@
// This file is part of the "Nazara Engine - Utility module" // This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Network/RudpConnection.hpp> #include <Nazara/Network/RUdpConnection.hpp>
#include <Nazara/Core/CallOnExit.hpp> #include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Log.hpp> #include <Nazara/Core/Log.hpp>
#include <Nazara/Network/NetPacket.hpp> #include <Nazara/Network/NetPacket.hpp>
@ -474,7 +474,7 @@ namespace Nz
return true; return true;
} }
inline void RUdpConnection::Uninitialize() void RUdpConnection::Uninitialize()
{ {
} }

View File

@ -2078,7 +2078,6 @@ namespace Nz
}; };
static_assert(VertexComponent_Max + 1 == 16, "Attribute index array is incomplete"); static_assert(VertexComponent_Max + 1 == 16, "Attribute index array is incomplete");
}
PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr; PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr;
PFNGLATTACHSHADERPROC glAttachShader = nullptr; PFNGLATTACHSHADERPROC glAttachShader = nullptr;
@ -2260,3 +2259,5 @@ GLX::PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr;
GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA = nullptr; GLX::PFNGLXSWAPINTERVALMESAPROC NzglXSwapIntervalMESA = nullptr;
GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr; GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = nullptr;
#endif #endif
}

View File

@ -9,7 +9,7 @@ SCENARIO("File", "[CORE][FILE]")
{ {
Nz::File file("Test File.txt", Nz::OpenMode_ReadWrite); Nz::File file("Test File.txt", Nz::OpenMode_ReadWrite);
REQUIRE(file.GetDirectory() == Nz::Directory::GetCurrent() + NAZARA_DIRECTORY_SEPARATOR); 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'") 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);
}
}
}
} }

View File

@ -0,0 +1,261 @@
#include <Nazara/Core/Serialization.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/MemoryView.hpp>
#include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Ray.hpp>
#include <Catch/catch.hpp>
SCENARIO("Serialization", "[CORE][SERIALIZATION]")
{
GIVEN("A context of serialization")
{
std::array<char, 256> 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<Nz::BoxCorner>(i)) != copy.GetCorner(static_cast<Nz::BoxCorner>(i)));
context.stream->SetCursorPos(0);
REQUIRE(Unserialize(context, &frustum));
for (unsigned int i = 0; i <= Nz::BoxCorner_Max; ++i)
REQUIRE(frustum.GetCorner(static_cast<Nz::BoxCorner>(i)) == copy.GetCorner(static_cast<Nz::BoxCorner>(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);
}
}
}
}

View File

@ -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 /* TODO
GIVEN("One unicode string") GIVEN("One unicode string")
{ {

View File

@ -0,0 +1 @@
Test