瀏覽代碼

2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Added test cases for util::parseUIntNoThrow() and
	util::parseLLIntNoThrow().
	* test/UtilTest.cc
Tatsuhiro Tsujikawa 15 年之前
父節點
當前提交
788679f0df
共有 2 個文件被更改,包括 30 次插入0 次删除
  1. 6 0
      ChangeLog
  2. 24 0
      test/UtilTest.cc

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2010-10-10  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Added test cases for util::parseUIntNoThrow() and
+	util::parseLLIntNoThrow().
+	* test/UtilTest.cc
+
 2010-10-10  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Use util::strip() instead of util::trim()

+ 24 - 0
test/UtilTest.cc

@@ -46,6 +46,8 @@ class UtilTest:public CppUnit::TestFixture {
   CPPUNIT_TEST(testParseUInt);
   CPPUNIT_TEST(testParseLLInt);
   CPPUNIT_TEST(testParseULLInt);
+  CPPUNIT_TEST(testParseUIntNoThrow);
+  CPPUNIT_TEST(testParseLLIntNoThrow);
   CPPUNIT_TEST(testToString_binaryStream);
   CPPUNIT_TEST(testItos);
   CPPUNIT_TEST(testUitos);
@@ -100,6 +102,8 @@ public:
   void testParseUInt();
   void testParseLLInt();
   void testParseULLInt();
+  void testParseUIntNoThrow();
+  void testParseLLIntNoThrow();
   void testToString_binaryStream();
   void testItos();
   void testUitos();
@@ -753,6 +757,26 @@ void UtilTest::testParseULLInt()
   }
 }
 
+void UtilTest::testParseUIntNoThrow()
+{
+  uint32_t n;
+  CPPUNIT_ASSERT(util::parseUIntNoThrow(n, " 4294967295 "));
+  CPPUNIT_ASSERT_EQUAL((uint32_t)UINT32_MAX, n);
+  CPPUNIT_ASSERT(!util::parseUIntNoThrow(n, "4294967296"));
+  CPPUNIT_ASSERT(!util::parseUIntNoThrow(n, "-1"));
+}
+
+void UtilTest::testParseLLIntNoThrow()
+{
+  int64_t n;
+  CPPUNIT_ASSERT(util::parseLLIntNoThrow(n, " 9223372036854775807 "));
+  CPPUNIT_ASSERT_EQUAL((int64_t)INT64_MAX, n);
+  CPPUNIT_ASSERT(!util::parseLLIntNoThrow(n, "9223372036854775808"));
+  CPPUNIT_ASSERT(util::parseLLIntNoThrow(n, "-9223372036854775808"));
+  CPPUNIT_ASSERT_EQUAL((int64_t)INT64_MIN, n);
+  CPPUNIT_ASSERT(!util::parseLLIntNoThrow(n, "-9223372036854775809"));
+}
+
 void UtilTest::testToString_binaryStream()
 {
   SharedHandle<DiskWriter> dw(new ByteArrayDiskWriter());