Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

------------------------------------------------------------------------

tests/fixtures/amen.mp3 is in the public domain (https://sampleswap.org)
Binary file added tests/fixtures/amen-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen-15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/amen.mp3
Binary file not shown.
25 changes: 20 additions & 5 deletions tests/test_read_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,43 @@ def test_one_qr_code(self):
image = get_image('one_qr_code')

self.assertEqual(read_codes(image, barcode_type=BarcodeType.QR_CODE), [
'zxinglight test qr code'
b'zxinglight test qr code'
])

self.assertEqual(read_codes(image, barcode_type=BarcodeType.CODE_39), [])

def test_two_qr_code(self):
self.assertEqual(sorted(read_codes(get_image('two_qr_codes'))), [
'first zxinglight test qr code', 'second zxinglight test qr code'
b'first zxinglight test qr code', b'second zxinglight test qr code'
])

def test_finding_one_of_two_qr_code(self):
self.assertEqual(
read_codes(get_image('two_qr_codes'), multi=False), ['first zxinglight test qr code'],
read_codes(get_image('two_qr_codes'), multi=False), [b'first zxinglight test qr code'],
)

def test_small_rotated_qr_code(self):
self.assertEqual(
read_codes(get_image('small_rotated_qr_code'), try_harder=True), ['217EXP0112'],
read_codes(get_image('small_rotated_qr_code'), try_harder=True), [b'217EXP0112'],
)

def test_small_rotated_qr_code_single(self):
self.assertEqual(
read_codes(get_image('small_rotated_qr_code'), try_harder=True, multi=False),
['217EXP0112'],
[b'217EXP0112'],
)

def test_embedded_nuls(self):
"""
amen-*.png contain a music sample -- binary dara with anything goes including embedded nuls.

They were created with
cat amen.mp3 | qrencode -S -v 16 -8 -o amen.png # -8 = bytes = binary
"""

codes = read_codes(get_image('amen-02'), barcode_type=BarcodeType.QR_CODE,
try_harder=True, multi=False)
self.assertTrue(len(codes) > 0)
mp3_chunk = codes[0]
print(mp3_chunk)
self.assertTrue(b"\x00" in mp3_chunk)
2 changes: 1 addition & 1 deletion zxinglight/_zxinglight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static PyObject* zxing_read_codes(PyObject *self, PyObject *args) {

if (results != NULL) {
for (const string &code : *results) {
PyList_Append(codes, PyUnicode_FromString(code.c_str()));
PyList_Append(codes, PyBytes_FromStringAndSize(code.data(), code.size()));
}

delete results;
Expand Down