1# Licensed to the Apache Software Foundation (ASF) under one 2# or more contributor license agreements. See the NOTICE file 3# distributed with this work for additional information 4# regarding copyright ownership. The ASF licenses this file 5# to you under the Apache License, Version 2.0 (the 6# "License"); you may not use this file except in compliance 7# with the License. You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, 12# software distributed under the License is distributed on an 13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14# KIND, either express or implied. See the License for the 15# specific language governing permissions and limitations 16# under the License. 17 18test_that("codec_is_available", { 19 expect_true(codec_is_available("uncompressed")) # Always true 20 expect_match_arg_error(codec_is_available("sdfasdf")) 21 skip_if_not_available("gzip") 22 expect_true(codec_is_available("gzip")) 23 expect_true(codec_is_available("GZIP")) 24}) 25 26if (identical(Sys.getenv("APPVEYOR"), "True")) { 27 test_that("Compression codecs are included in the Windows build", { 28 expect_true(codec_is_available("lz4")) 29 expect_true(codec_is_available("zstd")) 30 }) 31} 32 33test_that("Codec attributes", { 34 skip_if_not_available("gzip") 35 cod <- Codec$create("gzip") 36 expect_equal(cod$name, "gzip") 37 # TODO: implement $level 38 expect_error(cod$level) 39}) 40 41test_that("can write Buffer to CompressedOutputStream and read back in CompressedInputStream", { 42 skip_if_not_available("gzip") 43 buf <- buffer(as.raw(sample(0:255, size = 1024, replace = TRUE))) 44 45 tf1 <- tempfile() 46 stream1 <- CompressedOutputStream$create(tf1) 47 expect_equal(stream1$tell(), 0) 48 stream1$write(buf) 49 expect_equal(stream1$tell(), buf$size) 50 stream1$close() 51 52 tf2 <- tempfile() 53 sink2 <- FileOutputStream$create(tf2) 54 stream2 <- CompressedOutputStream$create(sink2) 55 expect_equal(stream2$tell(), 0) 56 stream2$write(buf) 57 expect_equal(stream2$tell(), buf$size) 58 stream2$close() 59 sink2$close() 60 61 input1 <- CompressedInputStream$create(tf1) 62 buf1 <- input1$Read(1024L) 63 64 file2 <- ReadableFile$create(tf2) 65 input2 <- CompressedInputStream$create(file2) 66 buf2 <- input2$Read(1024L) 67 68 expect_equal(buf, buf1) 69 expect_equal(buf, buf2) 70 71 unlink(tf1) 72 unlink(tf2) 73}) 74