From c242064d3685b52e97295e768e3a225c06daf776 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Mon, 10 Nov 2008 02:02:43 +0000 Subject: [PATCH] Fixed athenatime's parse and updated test cases. Originally committed to SVN as r2446. --- athenasub/src/athenatime.cpp | 38 ++++++++++++++-------- unit_test/src/athenasub/test_time.cpp | 45 +++++++++++++++++++++++++++ unit_test/src/main.cpp | 4 +++ 3 files changed, 74 insertions(+), 13 deletions(-) diff --git a/athenasub/src/athenatime.cpp b/athenasub/src/athenatime.cpp index 642c4cf48..432efc83a 100644 --- a/athenasub/src/athenatime.cpp +++ b/athenasub/src/athenatime.cpp @@ -132,11 +132,13 @@ void Time::ParseString(const String &data) { // Break into an array of values array 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= 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; } } diff --git a/unit_test/src/athenasub/test_time.cpp b/unit_test/src/athenasub/test_time.cpp index e6c1b2f1e..f63070d19 100644 --- a/unit_test/src/athenasub/test_time.cpp +++ b/unit_test/src/athenasub/test_time.cpp @@ -36,6 +36,7 @@ #include "../suites.h" #if ATHENASUB_TEST == 1 +#include #include #include #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()); diff --git a/unit_test/src/main.cpp b/unit_test/src/main.cpp index 9150e3881..45b422d47 100644 --- a/unit_test/src/main.cpp +++ b/unit_test/src/main.cpp @@ -40,8 +40,12 @@ #ifdef _MSC_VER +#ifdef _DEBUG +#pragma comment(lib,"cppunitd.lib") +#else #pragma comment(lib,"cppunit.lib") #endif +#endif int main()