--- a/src/core/model/time.cc Thu Nov 10 10:21:12 2011 +0100
+++ b/src/core/model/time.cc Fri Nov 11 14:36:05 2011 -0800
@@ -33,7 +33,7 @@
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;
--- a/src/core/test/time-test-suite.cc Thu Nov 10 10:21:12 2011 +0100
+++ b/src/core/test/time-test-suite.cc Fri Nov 11 14:36:05 2011 -0800
@@ -78,6 +78,61 @@
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 @@
: TestSuite ("time", UNIT)
{
AddTestCase (new TimeSimpleTestCase (Time::US));
+ AddTestCase (new TimesWithSignsTestCase ());
}
} g_timeTestSuite;