<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">% !TeX program = LuaTeX
% Copyright (C) 2019-2022 Roberto Giacomelli

\newbox\mybox
\nopagenumbers

\directlua{
barracuda = require "barracuda"
local barcode = barracuda:barcode()
barcode:set_param("debug_bbox", "symb")
}

Interleaved 2 of 5 encoder test.

Test 1: one simple barcode with default parameters:

\directlua{
local barcode = barracuda:barcode()
local enc, err = barcode:new_encoder("i2of5"); assert(not err, err)
local symbo, err = enc:from_uint(54654681); assert(not err, err)
local canvas = barracuda:new_canvas(); symbo:draw(canvas)
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}%
input code 54654681: \vrule A\vrule\box\mybox \vrule A\vrule

\bigskip
Test 2: one simple barcode with default parameter:

\directlua{
local barcode = barracuda:barcode()
local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
local symbo, err = enc:from_uint(1234567895); assert(not err, err)
local canvas = barracuda:new_canvas(); symbo:draw(canvas)
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}%
input code 1234567895: \vrule A\vrule\box\mybox \vrule A\vrule

% check digit tests

\directlua{% verify check digits, the last one
local code = {
    7352621,
    9624764,
    7592881,
    5344147,
    742238,
    199766,
    4544739,
    2774794,
    8509895,
    8285157,
    5387564,
    5534371,
    2155678,
    4529545,
    4689164,
    1674910,
    5317837,
    4117698,
}
local barcode = barracuda:barcode()
local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
for _, n in ipairs(code) do
    local smbl, err = enc:from_uint(n, {check_digit_policy="verify"})
    assert(not err, err)
end
}

\directlua{% check digits evaluation
local code = {
    ["735262"] = 1,
    ["962476"] = 4,
    ["759288"] = 1,
    ["534414"] = 7,
    ["74223"] = 8,
    ["19976"] = 6,
    ["454473"] = 9,
    ["277479"] = 4,
    ["850989"] = 5,
    ["828515"] = 7,
    ["538756"] = 4,
    ["553437"] = 1,
    ["215567"] = 8,
    ["452954"] = 5,
    ["468916"] = 4,
    ["167491"] = 0,
    ["531783"] = 7,
    ["411769"] = 8,
}
local barcode = barracuda:barcode()
local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
for sc, ck in pairs(code) do
    local n = tonumber(sc)
    local c, err = enc:get_checkdigit(n)
    assert(not err, err)
    assert(c == ck, "Wrong check digit "..c.." vs "..ck .." for "..sc)
end
}

\bigskip
Test 3: one simple barcode with check digit automatically added:

\directlua{
local barcode = barracuda:barcode()
local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
local symbo, err = enc:from_uint(454473, {check_digit_policy="add"})
assert(not err, err)
local canvas = barracuda:new_canvas(); symbo:draw(canvas)
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}%
input code 454473: \vrule A\vrule\box\mybox \vrule A\vrule

\bigskip
Test 4: a second simple barcode with check digit automatically added:

\directlua{
local barcode = barracuda:barcode()
local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
local symbo, err = enc:from_uint(74223, {check_digit_policy="add"})
assert(not err, err)
local canvas = barracuda:new_canvas(); symbo:draw(canvas)
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}%
input code 74223: \vrule A\vrule\box\mybox \vrule A\vrule

\bigskip
Test 5: a symbol with native check digits:

\directlua{
local barcode = barracuda:barcode()
local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
local symbo, err = enc:from_uint(121891259, {check_digit_policy="verify"})
assert(not err, err)
local canvas = barracuda:new_canvas(); symbo:draw(canvas)
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}%
input code 121891259: \vrule A\vrule\box\mybox \vrule A\vrule

\bigskip
Test 6: bearer bars please:

\directlua{
local barcode = barracuda:barcode()
local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
local symbo, err = enc:from_string("747867239", {bearer_bars_enabled = true})
assert(not err, err)
local canvas = barracuda:new_canvas(); symbo:draw(canvas)
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}%
input string "747867239": \vrule A\vrule\box\mybox \vrule A\vrule

\bigskip
Test 7: bearer bars all around the symbol:

\directlua{
local barcode = barracuda:barcode()
local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
local symbo, err = enc:from_uint(986790868, {bearer_bars_enabled = true, bearer_bars_layout="frame"})
assert(not err, err)
local canvas = barracuda:new_canvas(); symbo:draw(canvas)
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}%
input code 986790868: \vrule A\vrule\box\mybox \vrule A\vrule

\bigskip
Test 8: bearer bars all around the symbol (with string costructor):

\directlua{
local barcode = barracuda:barcode()
local enc, err = barcode:enc_by_name("i2of5"); assert(not err, err)
local symbo, err = enc:from_string("986790868", {bearer_bars_enabled = true, bearer_bars_layout="frame"})
assert(not err, err)
local canvas = barracuda:new_canvas(); symbo:draw(canvas)
local drv = barracuda:get_driver()
drv:ga_to_hbox(canvas, "mybox")
}%
input string "986790868": \vrule A\vrule\box\mybox \vrule A\vrule

That's all folks!

\bye


</pre></body></html>