Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zxing-cpp/wrappers/kn/src/nativeTest/kotlin/Test.kt @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* | |
| 2 * Copyright 2024 ISNing | |
| 3 */ | |
| 4 // SPDX-License-Identifier: Apache-2.0 | |
| 5 | |
| 6 import zxingcpp.* | |
| 7 import kotlin.experimental.ExperimentalNativeApi | |
| 8 import kotlin.test.Test | |
| 9 import kotlin.test.assertContentEquals | |
| 10 import kotlin.test.assertEquals | |
| 11 import kotlin.test.assertNotNull | |
| 12 | |
| 13 class BarcodeReaderTest { | |
| 14 | |
| 15 @Test | |
| 16 @OptIn(ExperimentalNativeApi::class) | |
| 17 fun `read barcode`() { | |
| 18 val data = "0000101000101101011110111101011011101010100111011100101000100101110010100000".map { | |
| 19 if (it == '0') 255.toByte() else 0.toByte() | |
| 20 } | |
| 21 | |
| 22 val iv = ImageView(data.toByteArray(), data.size, 1, ImageFormat.Lum) | |
| 23 val br = BarcodeReader().apply { | |
| 24 binarizer = Binarizer.BoolCast | |
| 25 } | |
| 26 val res = br.read(iv).firstOrNull() | |
| 27 | |
| 28 val expected = "96385074" | |
| 29 | |
| 30 assertNotNull(res) | |
| 31 assert(res.isValid) | |
| 32 assertEquals(BarcodeFormat.EAN8, res.format) | |
| 33 assertEquals(expected, res.text) | |
| 34 assertContentEquals(expected.encodeToByteArray(), res.bytes) | |
| 35 assert(!res.hasECI) | |
| 36 assertEquals(ContentType.Text, res.contentType) | |
| 37 assertEquals(0, res.orientation) | |
| 38 assertEquals(PointI(4, 0), res.position.topLeft) | |
| 39 assertEquals(1, res.lineCount) | |
| 40 } | |
| 41 | |
| 42 @Test | |
| 43 @OptIn(ExperimentalNativeApi::class, ExperimentalWriterApi::class) | |
| 44 fun `create write and read barcode with text`() { | |
| 45 val text = "I have the best words." | |
| 46 val barcode = Barcode(text, BarcodeFormat.DataMatrix) | |
| 47 val image = barcode.toImage() | |
| 48 | |
| 49 val res = BarcodeReader.read(image.toImageView()).firstOrNull() | |
| 50 | |
| 51 assertNotNull(res) | |
| 52 assert(res.isValid) | |
| 53 assertEquals(BarcodeFormat.DataMatrix, res.format) | |
| 54 assertEquals(text, res.text) | |
| 55 assertContentEquals(text.encodeToByteArray(), res.bytes) | |
| 56 assert(!res.hasECI) | |
| 57 assertEquals(ContentType.Text, res.contentType) | |
| 58 assertEquals(0, res.orientation) | |
| 59 assertEquals(PointI(1, 1), res.position.topLeft) | |
| 60 assertEquals(0, res.lineCount) | |
| 61 } | |
| 62 | |
| 63 @Test | |
| 64 @OptIn(ExperimentalNativeApi::class, ExperimentalWriterApi::class) | |
| 65 fun `create write and read barcode with bytes`() { | |
| 66 val text = "I have the best words." | |
| 67 val barcode = Barcode(text.encodeToByteArray(), BarcodeFormat.DataMatrix) | |
| 68 val image = barcode.toImage() | |
| 69 | |
| 70 val res = BarcodeReader.read(image.toImageView()).firstOrNull() | |
| 71 | |
| 72 assertNotNull(res) | |
| 73 assert(res.isValid) | |
| 74 assertEquals(BarcodeFormat.DataMatrix, res.format) | |
| 75 assertEquals(text, res.text) | |
| 76 assertContentEquals(text.encodeToByteArray(), res.bytes) | |
| 77 assert(res.hasECI) | |
| 78 assertEquals(ContentType.Binary, res.contentType) | |
| 79 assertEquals(0, res.orientation) | |
| 80 assertEquals(PointI(1, 1), res.position.topLeft) | |
| 81 assertEquals(0, res.lineCount) | |
| 82 } | |
| 83 } |
