Commits

Sergey Astanin committed 84e8b08

tests for unicode file comments

Comments (0)

Files changed (1)

LibZip/Tests/MonadicTests.hs

 import System.FilePath ((</>))
 import Test.HUnit
 import qualified Control.Exception as E
+import qualified Data.ByteString as BS
 
 monadicTests = TestList
   [ "read list of files" ~: do
       -- 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"
+      let world_comm = "\1087\1088\1080\1074\1077\1090"
+      let world_comm2 = [208,188,208,184,209,128]
+      mkArchive tmpzip [("hello/",undefined), (world_path,world_txt)]
+      let get_comm = withArchive [] tmpzip $ getFileComment [] world_path
+      c_off <- get_comm
+      withArchive [] tmpzip $ setFileComment [] world_path world_comm
+      c_on <- get_comm
+      withArchive [] tmpzip $ setFileCommentIx 1 (BS.pack world_comm2) [FileENC_UTF_8]
+      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)]