Skip to content

Commit

Permalink
Merge pull request mikera#28 from vvvvalvalval/save-to-any-outputstream
Browse files Browse the repository at this point in the history
test for core/write
  • Loading branch information
mikera committed Feb 2, 2016
2 parents 0f94989 + 5a0144e commit 3613de5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/test/clojure/mikera/image/test_core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
javax.imageio.ImageIO
javax.imageio.ImageWriter
javax.imageio.ImageWriteParam
java.io.ByteArrayOutputStream
java.io.ByteArrayInputStream
java.awt.Color))

(set! *warn-on-reflection* true)
Expand Down Expand Up @@ -123,3 +125,23 @@
(is (= (.getProgressiveMode ^ImageWriteParam (progressive-fn param true)) ImageWriteParam/MODE_DEFAULT))
(is (= (.getProgressiveMode ^ImageWriteParam (progressive-fn param false)) ImageWriteParam/MODE_DISABLED))
(is (= (.getProgressiveMode ^ImageWriteParam (progressive-fn param nil)) ImageWriteParam/MODE_COPY_FROM_METADATA)))))

(deftest test-write
(are [path format quality progressive]
(let [img (load-image path)
baos (ByteArrayOutputStream.)
arr (do (write img baos format :quality quality :progressive progressive)
(.toByteArray baos))
bais (ByteArrayInputStream. arr)
img2 (load-image bais)]
(and
(instance? BufferedImage img2)
(= [(.getWidth img2) (.getHeight img2)] [(.getWidth img) (.getHeight img)])
))
"src/test/resources/mikera/image/samples/Clojure_300x300.png" "png" 0.9 true
"src/test/resources/mikera/image/samples/Clojure_300x300.png" "gif" 0.9 true
"src/test/resources/mikera/image/samples/Clojure_300x300.png" "png" 0.9 false
"src/test/resources/mikera/image/samples/Clojure_300x300.png" "gif" 0.9 false
"src/test/resources/mikera/image/samples/Ant.png" "png" 0.8 false
"src/test/resources/mikera/image/samples/Ant.png" "gif" 0.8 false
))

0 comments on commit 3613de5

Please sign in to comment.