From 16f88edb3bca8afbaba5de13b74ab74fcb5abf57 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Wed, 30 Jul 2014 22:31:38 -0400 Subject: Docx tests: Added media test comparison function. Also tell pandoc.cabal that we'll be needing base64, since we want to compare strings here. --- pandoc.cabal | 1 + tests/Tests/Readers/Docx.hs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pandoc.cabal b/pandoc.cabal index 9249723ff..377a3b6c4 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -385,6 +385,7 @@ Test-Suite test-pandoc syb >= 0.1 && < 0.5, pandoc, pandoc-types >= 1.12.3.3 && < 1.13, + base64-bytestring >= 0.1 && < 1.1, bytestring >= 0.9 && < 0.11, text >= 0.11 && < 1.2, directory >= 1 && < 1.3, diff --git a/tests/Tests/Readers/Docx.hs b/tests/Tests/Readers/Docx.hs index e8dd6b72e..e57376063 100644 --- a/tests/Tests/Readers/Docx.hs +++ b/tests/Tests/Readers/Docx.hs @@ -5,7 +5,10 @@ import Text.Pandoc.Readers.Native import Text.Pandoc.Definition import Tests.Helpers import Test.Framework +import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as B +import qualified Data.ByteString.Char8 as B8 +import qualified Data.ByteString.Base64 as B64 import Text.Pandoc.Readers.Docx import Text.Pandoc.Writers.Native (writeNative) import qualified Data.Map as M @@ -52,6 +55,22 @@ testCompareWithOpts opts name docxFile nativeFile = testCompare :: String -> FilePath -> FilePath -> Test testCompare = testCompareWithOpts def +testCompareMediaIO :: String -> FilePath -> FilePath -> FilePath -> IO Test +testCompareMediaIO name docxFile mediaPath mediaFile = do + df <- B.readFile docxFile + mf <- B.readFile mediaFile + let (_, mb) = readDocx def df + dBytes = case M.lookup mediaPath mb of + Just bs -> bs + Nothing -> error "Media file not found" + d64 = B8.unpack $ B64.encode $ BS.concat $ B.toChunks dBytes + m64 = B8.unpack $ B64.encode $ BS.concat $ B.toChunks mf + return $ test id name (d64, m64) + +testCompareMedia :: String -> FilePath -> FilePath -> FilePath -> Test +testCompareMedia name docxFile mediaPath mediaFile = + buildTest $ testCompareMediaIO name docxFile mediaPath mediaFile + tests :: [Test] tests = [ testGroup "inlines" -- cgit v1.2.3 From b24b3289064d4f4294b3d4ec87032fcd54af7e8a Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Wed, 30 Jul 2014 22:32:27 -0400 Subject: Docx tests: Add test image. This is the cow image extracted from `docx.image.docx`. --- tests/docx.image1.jpeg | Bin 0 -> 46626 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/docx.image1.jpeg diff --git a/tests/docx.image1.jpeg b/tests/docx.image1.jpeg new file mode 100644 index 000000000..423dff48b Binary files /dev/null and b/tests/docx.image1.jpeg differ -- cgit v1.2.3 From 4d1d8a4b6ff6ca957c63233e344f2de4cd9e87bb Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Wed, 30 Jul 2014 22:32:55 -0400 Subject: Docx test: Test image from media bag. --- tests/Tests/Readers/Docx.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Tests/Readers/Docx.hs b/tests/Tests/Readers/Docx.hs index e57376063..494669fd5 100644 --- a/tests/Tests/Readers/Docx.hs +++ b/tests/Tests/Readers/Docx.hs @@ -184,6 +184,13 @@ tests = [ testGroup "inlines" "docx.track_changes_deletion.docx" "docx.track_changes_deletion_all.native" ] + , testGroup "media" + [ testCompareMedia + "image extraction" + "docx.image.docx" + "media/image1.jpeg" + "docx.image1.jpeg" + ] , testGroup "metadata" [ testCompareWithOpts def{readerStandalone=True} "metadata fields" -- cgit v1.2.3