Commits

Sergey Astanin committed 027b45c

tests for new addFile/addDirectory with Unicode filenames, skip line b/w tests

  • Participants
  • Parent commits 8a29e34
  • Branches 0.11-bindings-libzip

Comments (0)

Files changed (1)

File LibZip/Tests/MonadicTests.hs

 import Test.HUnit
 import qualified Control.Exception as E
 import qualified Data.ByteString as BS
+import qualified Data.ByteString.UTF8 as UTF8
 
 monadicTests = TestList
   [ "read list of files" ~: do
       files <- withArchive [] testzip $ fileNames []
       files @?= testfiles
+
   , "read file size" ~: do
       sz <- withArchive [] testzip $ fileSize [] lastfile
       sz @?= lastfilesize
+
   , "case-insensitive file names" ~: do
       sz <- withArchive [] testzip $
               fileSize [FileNOCASE] (map2 toUpper toLower $ lastfile)
       sz @?= lastfilesize
+
   , "open error if exists (with ExclFlag)" ~: do
       err <- catchZipError
              (withArchive [ExclFlag] testzip $ lift $ E.throwIO ErrOK)
              (return . id)
       err @?= ErrEXISTS
+
   , "open error if archive does not exists" ~: do
       err <- catchZipError
              (withArchive [] "notexists.zip" $ return ErrOK)
              (return . id)
       err @?= ErrOPEN
+
   , "read file" ~: do
       txt <- withArchive [] testzip $ fileContents [] lastfile
       txt @?= world_txt
+
   , "read file by index" ~: do
       let i = toInteger (length testfiles - 1)
       txt <- withArchive [] testzip $ fileContentsIx [] i
       txt @?= world_txt
+
   , "skipBytes/readBytes" ~: do
       txt <- withArchive [] testzip $
                fromFile [] lastfile $ do
                   skipBytes 13
                   readBytes 10
       txt @?= (take 10 . drop 13 $ world_txt)
+
   , "create an archive/use sourceBuffer" ~: do
       tmpzip <- getTmpFileName "test_LibZip_sourceBuffer.zip"
       i <- withArchive [CreateFlag] tmpzip $ do
            txt <- withArchive [] f $ fileContents [] "hello/world.txt"
            removeFile f
            (txt, i) @?= (world_txt, 1)
+
+  , "create an archive with Unicode filenames" ~: do
+      tmpzip <- getTmpFileName "test_LibZip_unicode_filenames.zip"
+      let dir = "\x4e16\x754c"
+      let name1 = "\x4e16\x754c/привет.txt"
+      let name2 = "\x4e16\x754c/мир.txt"
+      i <- withArchive [CreateFlag] tmpzip $ do
+           addDirectory dir
+           addFile name1 =<< sourceBuffer world_txt
+           addFileWithFlags [FileENC_UTF_8] (UTF8.fromString name2) =<< sourceBuffer world_txt
+      tmpzip `doesExistAnd` \f -> do
+           names <- withArchive [] f $ fileNames []
+           removeFile f
+           names @?= [dir ++ "/", name1, name2]
+
   , "create an archive/use sourceFile" ~: do
       tmpzip <- getTmpFileName "test_LibZip_sourceFile.zip"
       tmpsrc <- getTmpFileName "test_LibZip_sourceFile.txt"
            removeFile tmpzip
            removeFile tmpsrc
            txt @?= world_txt
+
   , "create an archive/use sourceZip" ~: do
       tmpzip <- getTmpFileName "test_LibZip_sourceZip.zip"
       withArchive [] testzip $ do
            txt <- withArchive [] f $ fileContents [] "world.txt"
            removeFile tmpzip
            txt @?= world_txt
+
   , "create an archive/use sourcePure" ~: do
       tmpzip <- getTmpFileName "test_LibZip_sourcePure.zip"
       let src = PureSource
            txt <- withArchive [] f $ fileContents [] "world.txt"
            removeFile tmpzip
            txt @?= world_txt
+
   , "delete a file" ~: do
       let orig = [("one", "one"), ("two", "two")]
       let final = init orig
       fs_final <- withArchive [] tmpzip $ fileNames []
       removeFile tmpzip
       (fs_orig, fs_final) @?= (map fst orig, map fst final)
+
   , "attempt to delete a non-existing file" ~: do
       tmpzip <- getTmpFileName "test_LibZip_delete_ne.zip"
       mkArchive tmpzip [("world.txt", world_txt)]
             (return . id)
       removeFile tmpzip
       (r1, r2) @?= (ErrNOENT, ErrINVAL)
+
   , "rename a file" ~: do
       tmpzip <- getTmpFileName "test_LibZip_rename.zip"
       mkArchive tmpzip [("world.txt", world_txt)]
               fileNames []
       removeFile tmpzip
       fs @?= ["hello.txt"]
+
   , "attempt to rename a non-existing file" ~: do
       tmpzip <- getTmpFileName "test_LibZip_rename_ne.zip"
       mkArchive tmpzip [("world.txt", world_txt)]
             (return . id)
       removeFile tmpzip
       r @?= ErrNOENT
-  --
+
   -- -- libzip 0.11 renames an entry to an empty string without errors;
   -- the test is disabled.
   --
   --            (return . id)
   --     removeFile tmpzip
   --     r @?= ErrINVAL
+
   , "replace a file" ~: do
       tmpzip <- getTmpFileName "test_LibZip_replace.zip"
       mkArchive tmpzip [("hello/",""), ("hello/world.txt", "old contents")]
       txt <- withArchive [] tmpzip $ fileContents [] "hello/world.txt"
       txt @?= world_txt
       removeFile tmpzip
+
   , "set/get/remove archive comment" ~: do
       c1 <- withArchive [] testzip $ getComment []
       tmpzip <- getTmpFileName "test_LibZip_comment.zip"
       -- libzip-0.11 returns an empty string, instead of NULL pointer in 0.10.
       -- Haskell LibZip reflects it by returning Just "" rather than Nothing.
       (c1, c2, c2_added, c2_removed) @?= (Just "", Just "", Just com, Just "")
+
   , "set/get/remove file comment" ~: do
       tmpzip <- getTmpFileName "test_LibZip_file_comment.zip"
       let world_path = "hello/world.txt"
       -- libzip-0.11 returns an empty string, instead of NULL pointer in 0.10.
       -- Haskell LibZip reflects it by returning Just "" rather than Nothing.
       (c_off, c_on, c_off') @?= (Just "", Just world_comm, Just "")
+
   , "set/get Unicode file comment" ~: do
       tmpzip <- getTmpFileName "test_LibZip_file_comment.zip"
       let world_path = "hello/world.txt"
       c_on2 <- get_comm
       removeFile tmpzip
       (c_off, c_on, c_on2) @?= (Just "", Just "привет", Just "мир")
+
   , "unchange file" ~: do
       tmpzip <- getTmpFileName "test_LibZip_unchange_file.zip"
       mkArchive tmpzip [("world.txt",world_txt)]
       -- libzip-0.11 returns an empty string, instead of NULL pointer in 0.10.
       -- Haskell LibZip reflects it by returning Just "" rather than Nothing.
       c @?= Just ""
+
   , "unchange archive" ~: do
       tmpzip <- getTmpFileName "test_LibZip_unchange.zip"
       mkArchive tmpzip [("world.txt",world_txt)]
       -- libzip-0.11 returns an empty string, instead of NULL pointer in 0.10.
       -- Haskell LibZip reflects it by returning Just "" rather than Nothing.
       c @?= Just ""
+
   , "unchange all" ~: do
       tmpzip <- getTmpFileName "test_LibZip_unchange_all.zip"
       mkArchive tmpzip [("world.txt",world_txt)]
       -- libzip-0.11 returns an empty string, instead of NULL pointer in 0.10.
       -- Haskell LibZip reflects it by returning Just "" rather than Nothing.
       c @?= (Just "", Just "")
+
   , "read a file from an encrypted archive" ~: do
       txt <- withEncryptedArchive [] "purity" encryptedzip $ fileContents [] lastfile
       txt @?= world_txt