]> granicus.if.org Git - taglib/commitdiff
Add tests for newline handling in String (#125)
authorLukáš Lalinský <lalinsky@gmail.com>
Mon, 15 Apr 2013 08:45:33 +0000 (10:45 +0200)
committerLukáš Lalinský <lalinsky@gmail.com>
Mon, 15 Apr 2013 08:47:43 +0000 (10:47 +0200)
tests/test_string.cpp

index 1e37d7a2fdc71bf334e6a8c76707d1bc717ee0f7..4a58c277573d2a87124741b0ce0fca8259c7bef5 100644 (file)
@@ -42,6 +42,7 @@ class TestString : public CppUnit::TestFixture
   CPPUNIT_TEST(testAppendStringDetach);
   CPPUNIT_TEST(testToInt);
   CPPUNIT_TEST(testSubstr);
+  CPPUNIT_TEST(testNewline);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -201,6 +202,22 @@ public:
     CPPUNIT_ASSERT_EQUAL(String("123456"), String("0123456").substr(1, 200));
   }
 
+  void testNewline()
+  {
+    ByteVector cr("abc\x0dxyz", 7);
+    ByteVector lf("abc\x0axyz", 7);
+    ByteVector crlf("abc\x0d\x0axyz", 8);
+
+    CPPUNIT_ASSERT_EQUAL(uint(7), String(cr).size());
+    CPPUNIT_ASSERT_EQUAL(uint(7), String(lf).size());
+    CPPUNIT_ASSERT_EQUAL(uint(8), String(crlf).size());
+
+    CPPUNIT_ASSERT_EQUAL(L'\x0d', String(cr)[3]);
+    CPPUNIT_ASSERT_EQUAL(L'\x0a', String(lf)[3]);
+    CPPUNIT_ASSERT_EQUAL(L'\x0d', String(crlf)[3]);
+    CPPUNIT_ASSERT_EQUAL(L'\x0a', String(crlf)[4]);
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestString);