Bug 1204 - Can't Parse Time +100000000.0ns

This commit is contained in:
Mitch Watrous
2011-11-11 14:36:05 -08:00
parent f3f7ea2d1d
commit 2e030ed11d
2 changed files with 57 additions and 1 deletions

View File

@@ -33,7 +33,7 @@ namespace ns3 {
Time::Time (const std::string& s)
{
std::string::size_type n = s.find_first_not_of ("0123456789.");
std::string::size_type n = s.find_first_not_of ("+-0123456789.");
if (n != std::string::npos)
{ // Found non-numeric
std::istringstream iss;

View File

@@ -78,6 +78,61 @@ TimeSimpleTestCase::DoTeardown (void)
Time::SetResolution (m_originalResolution);
}
class TimesWithSignsTestCase : public TestCase
{
public:
TimesWithSignsTestCase ();
private:
virtual void DoSetup (void);
virtual void DoRun (void);
virtual void DoTeardown (void);
};
TimesWithSignsTestCase::TimesWithSignsTestCase ()
: TestCase ("Checks times that have plus or minus signs")
{
}
void
TimesWithSignsTestCase::DoSetup (void)
{
}
void
TimesWithSignsTestCase::DoRun (void)
{
Time timePositive ("+1000.0");
Time timePositiveWithUnits ("+1000.0ms");
Time timeNegative ("-1000.0");
Time timeNegativeWithUnits ("-1000.0ms");
NS_TEST_ASSERT_MSG_EQ_TOL (timePositive.GetSeconds (),
+1000.0,
1.0e-8,
"Positive time not parsed correctly.");
NS_TEST_ASSERT_MSG_EQ_TOL (timePositiveWithUnits.GetSeconds (),
+1.0,
1.0e-8,
"Positive time with units not parsed correctly.");
NS_TEST_ASSERT_MSG_EQ_TOL (timeNegative.GetSeconds (),
-1000.0,
1.0e-8,
"Negative time not parsed correctly.");
NS_TEST_ASSERT_MSG_EQ_TOL (timeNegativeWithUnits.GetSeconds (),
-1.0,
1.0e-8,
"Negative time with units not parsed correctly.");
}
void
TimesWithSignsTestCase::DoTeardown (void)
{
}
static class TimeTestSuite : public TestSuite
{
public:
@@ -85,6 +140,7 @@ public:
: TestSuite ("time", UNIT)
{
AddTestCase (new TimeSimpleTestCase (Time::US));
AddTestCase (new TimesWithSignsTestCase ());
}
} g_timeTestSuite;