test_zbar.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import os
  2. import infra.basetest
  3. class TestZbar(infra.basetest.BRTest):
  4. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  5. """
  6. BR2_PACKAGE_IMAGEMAGICK=y
  7. BR2_PACKAGE_LIBQRENCODE=y
  8. BR2_PACKAGE_LIBQRENCODE_TOOLS=y
  9. BR2_PACKAGE_ZBAR=y
  10. BR2_TARGET_ROOTFS_CPIO=y
  11. # BR2_TARGET_ROOTFS_TAR is not set
  12. """
  13. def test_run(self):
  14. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  15. self.emulator.boot(arch="armv5",
  16. kernel="builtin",
  17. options=["-initrd", cpio_file])
  18. self.emulator.login()
  19. txt_msg = "Hello Buildroot!"
  20. qr_img = "qr.png"
  21. # We check the program can execute.
  22. self.assertRunOk("zbarimg --version")
  23. # We generate a QR code image containing a message.
  24. self.assertRunOk(f"qrencode -o '{qr_img}' '{txt_msg}'")
  25. # We decode the QR code image and check the extracted message
  26. # is the expected one.
  27. out, ret = self.emulator.run(f"zbarimg -q --raw {qr_img}")
  28. self.assertEqual(ret, 0)
  29. self.assertEqual(out[0], txt_msg)