Skip to content

Commit

Permalink
Added a unit test to check Quat::FromString works independent of the …
Browse files Browse the repository at this point in the history
…locale that is used.
  • Loading branch information
juj committed Dec 14, 2012
1 parent dbaf202 commit 06a3d00
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/SerializationTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>

#include "MathGeoLib.h"
#include "myassert.h"
#include "TestRunner.h"

extern LCG rng;

void TestQuat4FromString()
{
const char *locales[] = { "C", "en", "fi" }; // From http://www.loc.gov/standards/iso639-2/php/code_list.php

for(int i = 0; i < sizeof(locales)/sizeof(locales[0]); ++i)
{
setlocale(LC_ALL, locales[i]);
assert(Quat::FromString("1, +2, 3.1, -4").Equals(Quat(1,2,3.1f,-4)));
assert(Quat::FromString("(1, +2, 3.1, -4").Equals(Quat(1,2,3.1f,-4)));
assert(Quat::FromString("(1, +2, 3.1, -4)").Equals(Quat(1,2,3.1f,-4)));

assert(Quat::FromString("1,+2,3.1, -4").Equals(Quat(1,2,3.1f,-4)));
assert(Quat::FromString("(1,+2,3.1, -4").Equals(Quat(1,2,3.1f,-4)));
assert(Quat::FromString("(1,+2,3.1, -4)").Equals(Quat(1,2,3.1f,-4)));

assert(Quat::FromString("1 +2 3.1 -4").Equals(Quat(1,2,3.1f,-4)));
assert(Quat::FromString("(1 +2 3.1 -4").Equals(Quat(1,2,3.1f,-4)));
assert(Quat::FromString("(1 +2 3.1 -4)").Equals(Quat(1,2,3.1f,-4)));
}
}

void AddSerializationTests()
{
AddTest("Quat4::FromString", TestQuat4FromString);
}
2 changes: 2 additions & 0 deletions tests/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ void AddPositiveIntersectionTests();
void AddNegativeIntersectionTests();
void AddMatrixTests();
void AddVectorTests();
void AddSerializationTests();

int main()
{
AddPositiveIntersectionTests();
AddNegativeIntersectionTests();
AddMatrixTests();
AddVectorTests();
AddSerializationTests();

int numFailures = RunTests(10000);
LOGI("%d\n", globalPokedData);
Expand Down

0 comments on commit 06a3d00

Please sign in to comment.