@@ -5,7 +5,10 @@ import Text.Pandoc.Readers.Native
55import Text.Pandoc.Definition
66import Tests.Helpers
77import Test.Framework
8+import qualified Data.ByteString as BS
89import qualified Data.ByteString.Lazy as B
10+import qualified Data.ByteString.Char8 as B8
11+import qualified Data.ByteString.Base64 as B64
912import Text.Pandoc.Readers.Docx
1013import Text.Pandoc.Writers.Native (writeNative)
1114import qualified Data.Map as M
@@ -52,6 +55,22 @@ testCompareWithOpts opts name docxFile nativeFile =
5255testCompare :: String -> FilePath -> FilePath -> Test
5356testCompare = testCompareWithOpts def
5457
58+testCompareMediaIO :: String -> FilePath -> FilePath -> FilePath -> IO Test
59+testCompareMediaIO name docxFile mediaPath mediaFile = do
60+ df <- B.readFile docxFile
61+ mf <- B.readFile mediaFile
62+ let (_, mb) = readDocx def df
63+ dBytes = case M.lookup mediaPath mb of
64+ Just bs -> bs
65+ Nothing -> error "Media file not found"
66+ d64 = B8.unpack $ B64.encode $ BS.concat $ B.toChunks dBytes
67+ m64 = B8.unpack $ B64.encode $ BS.concat $ B.toChunks mf
68+ return $ test id name (d64, m64)
69+
70+testCompareMedia :: String -> FilePath -> FilePath -> FilePath -> Test
71+testCompareMedia name docxFile mediaPath mediaFile =
72+ buildTest $ testCompareMediaIO name docxFile mediaPath mediaFile
73+
5574
5675tests :: [Test]
5776tests = [ testGroup "inlines"