Skip to content
Extraits de code Groupes Projets
Valider c242064d rédigé par Rodrigo Braz Monteiro's avatar Rodrigo Braz Monteiro
Parcourir les fichiers

Fixed athenatime's parse and updated test cases.

Originally committed to SVN as r2446.
parent c029e5aa
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -132,11 +132,13 @@ void Time::ParseString(const String &data)
{
// Break into an array of values
array<size_t,4> values;
size_t last = 0;
//size_t last = 0;
size_t len = data.Length();
size_t curIndex = 0;
char cur = 0;
bool gotDecimal = false;
int curValue = 0;
int nDigits = 0;
for (size_t i=0;i<len;i++) {
cur = data[i];
......@@ -147,26 +149,36 @@ void Time::ParseString(const String &data)
if (gotDecimal) break;
gotDecimal = true;
}
values.at(curIndex++) = data.SubToInteger(last,i);
last = i+1;
//values.at(curIndex++) = data.SubToInteger(last,i);
//last = i+1;
values.at(curIndex++) = curValue;
curValue = 0;
nDigits = 0;
}
// Got a digit
else {
curValue = curValue * 10 + (int)(cur-'0');
nDigits++;
// Check if we're already done
if (gotDecimal && nDigits >= 3) {
values.at(curIndex++) = curValue;
break;
}
}
// Reached end of string
if (i == len-1) {
int value = data.SubToInteger(last,len);
size_t digits = len - last;
//int value = data.SubToInteger(last,len);
//size_t digits = len - last;
// Ended in decimal, so we gotta normalize it to 3 digits
if (gotDecimal) {
if (digits != 3) {
if (digits == 2) value *= 10;
else if (digits == 1) value *= 100;
else if (digits > 3) {
}
}
if (nDigits == 2) curValue *= 10;
else if (nDigits == 1) curValue *= 100;
}
values.at(curIndex++) = value;
values.at(curIndex++) = curValue;
}
}
......
......@@ -36,6 +36,7 @@
#include "../suites.h"
#if ATHENASUB_TEST == 1
#include <iostream>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include "../../../athenasub/include/athenasub/athenasub.h"
......@@ -48,6 +49,7 @@ class AthenasubTimeTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testComparison);
CPPUNIT_TEST(testOperators);
CPPUNIT_TEST(testSetGet);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST_SUITE_END();
private:
......@@ -104,6 +106,49 @@ public:
CPPUNIT_ASSERT(a - 300 == Time(200));
CPPUNIT_ASSERT(a - 600 == Time(0));
}
void testParse()
{
Time a;
a.ParseString("0");
CPPUNIT_ASSERT(a.GetMS() == 0);
a.ParseString("5");
CPPUNIT_ASSERT(a.GetMS() == 5000);
a.ParseString("5.0");
CPPUNIT_ASSERT(a.GetMS() == 5000);
a.ParseString("5,0");
CPPUNIT_ASSERT(a.GetMS() == 5000);
a.ParseString("5.00");
CPPUNIT_ASSERT(a.GetMS() == 5000);
a.ParseString("5.000");
CPPUNIT_ASSERT(a.GetMS() == 5000);
a.ParseString("5.1");
CPPUNIT_ASSERT(a.GetMS() == 5100);
a.ParseString("5.12");
CPPUNIT_ASSERT(a.GetMS() == 5120);
a.ParseString("5.123");
CPPUNIT_ASSERT(a.GetMS() == 5123);
a.ParseString("5,123");
CPPUNIT_ASSERT(a.GetMS() == 5123);
a.ParseString("5,1234");
CPPUNIT_ASSERT(a.GetMS() == 5123);
a.ParseString("5,");
CPPUNIT_ASSERT(a.GetMS() == 5000);
a.ParseString("05.12");
CPPUNIT_ASSERT(a.GetMS() == 5120);
a.ParseString("0:05.12");
CPPUNIT_ASSERT(a.GetMS() == 5120);
a.ParseString("0:15.12");
CPPUNIT_ASSERT(a.GetMS() == 15120);
a.ParseString("1:15.12");
CPPUNIT_ASSERT(a.GetMS() == 75120);
a.ParseString("11:15.12");
CPPUNIT_ASSERT(a.GetMS() == 675120);
a.ParseString("2:11:15.12");
CPPUNIT_ASSERT(a.GetMS() == 675120+7200000);
a.ParseString("10:11:15.12");
CPPUNIT_ASSERT(a.GetMS() == 675120+36000000);
}
};
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AthenasubTimeTest,AegisubSuites::athenasub());
......
......@@ -40,8 +40,12 @@
#ifdef _MSC_VER
#ifdef _DEBUG
#pragma comment(lib,"cppunitd.lib")
#else
#pragma comment(lib,"cppunit.lib")
#endif
#endif
int main()
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter