tests/testthat/test_f_opencv.R

# use opencv to test QR codes
test_that("test generated codes", {
  skip_if_not_installed("opencv")
  requireNamespace("opencv")
  skip_if(
    identical(Sys.info()[["sysname"]], "Linux") &&
      opencv::ocv_version() < "4.5.2"
  )

  test_read_qr <- function(input) {
    requireNamespace("opencv")
    test_file <- tempfile("qrcode", fileext = ".png")
    png(test_file)
    plot(qr_code(input))
    dev.off()
    opencv::ocv_read(test_file) |>
      opencv::ocv_qr_detect() -> z
    Encoding(z) <- "latin1"
    expect_equal(input, z)
    rm(test_file)
  }
  test_read_qr("ABCD")
  test_read_qr("123 abc ABC_")
  input <- "fa\xE7ile"
  Encoding(input) <- "latin1"
  test_read_qr(input)
  test_read_qr("\u00E6")
})

Try the qrcode package in your browser

Any scripts or data that you put into this service are public.

qrcode documentation built on Nov. 11, 2023, 5:07 p.m.