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