]> granicus.if.org Git - taglib/commitdiff
Add a test for File::truncate().
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Thu, 27 Oct 2016 06:15:22 +0000 (15:15 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Thu, 27 Oct 2016 06:15:22 +0000 (15:15 +0900)
tests/test_file.cpp

index f00a31156c867245b65f8577a0da41966fd70932..9aae07fe2db016f17dbf3e82e4220363288980b4 100644 (file)
@@ -45,6 +45,7 @@ class TestFile : public CppUnit::TestFixture
   CPPUNIT_TEST(testFindInSmallFile);
   CPPUNIT_TEST(testRFindInSmallFile);
   CPPUNIT_TEST(testSeek);
+  CPPUNIT_TEST(testTruncate);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -129,6 +130,24 @@ public:
     CPPUNIT_ASSERT_EQUAL((long)4428, f.tell());
   }
 
+  void testTruncate()
+  {
+    ScopedFileCopy copy("empty", ".ogg");
+    std::string name = copy.fileName();
+
+    {
+      PlainFile f(name.c_str());
+      CPPUNIT_ASSERT_EQUAL(4328L, f.length());
+
+      f.truncate(2000);
+      CPPUNIT_ASSERT_EQUAL(2000L, f.length());
+    }
+    {
+      PlainFile f(name.c_str());
+      CPPUNIT_ASSERT_EQUAL(2000L, f.length());
+    }
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestFile);