aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNardi Ivan <nardi.ivan@gmail.com>2021-07-15 14:04:06 +0200
committerAndersBroman <a.broman58@gmail.com>2023-01-04 14:32:23 +0000
commite6e3a916969eb68713fc7604f5215566813c5162 (patch)
treede57ffb9ecb480d0858bce7cf3ecc92f35336484 /test
parentd4cd1d9d1d78a4e5ce289616628aa7d0685922a0 (diff)
WSLUA: allow 64 bits bitmask for ProtoField objects
Mask might be specified using a (Lua) number, a string or a UInt64 object. It is useful to handle 64 bit bitfields.
Diffstat (limited to 'test')
-rw-r--r--test/lua/int64.lua5
-rw-r--r--test/lua/protofield.lua88
2 files changed, 92 insertions, 1 deletions
diff --git a/test/lua/int64.lua b/test/lua/int64.lua
index 8582485b31..bc405c099b 100644
--- a/test/lua/int64.lua
+++ b/test/lua/int64.lua
@@ -337,6 +337,11 @@ test("min3",z==Int64.min())
test("minmax",Int64.min()== - Int64.max() - 1)
+--Because of g_ascii_strtoll() usage without errno check, "invalid" strings are converted to 0
+testing("invalid string values")
+test("invalid",Int64.new("invalid")== Int64.new(0,0))
+test("invalid2",UInt64.new("invalid")== UInt64.new(0,0))
+
testing("error conditions")
local function divtest(f,s)
diff --git a/test/lua/protofield.lua b/test/lua/protofield.lua
index 2fcfafb2fd..a83538982b 100644
--- a/test/lua/protofield.lua
+++ b/test/lua/protofield.lua
@@ -30,7 +30,7 @@ local function setFailed(name)
end
-- expected number of runs
-local taptests = { [OTHER]=38 }
+local taptests = { [OTHER]=66 }
local function getResults()
print("\n-----------------------------\n")
for k,v in pairs(taptests) do
@@ -91,6 +91,92 @@ test("ProtoField-char-unit-string", not success)
success = pcall(ProtoField.new, "char base RANGE_STRING", "test.char5", ftypes.CHAR, {{1, 2, "Value"}}, base.RANGE_STRING)
test("ProtoField-char-range-string", success)
+-- Field type: BOOLEAN/UINT64 with (64 bit) mask
+success = pcall(ProtoField.new, "boolean", "test.boolean0", ftypes.BOOLEAN, nil, base.HEX, 0x1)
+test("ProtoField-new-bool-mask-trivial", success)
+
+success = pcall(ProtoField.new, "boolean", "test.boolean1", ftypes.BOOLEAN, nil, base.HEX, "1")
+test("ProtoField-new-bool-mask-string", success)
+
+success = pcall(ProtoField.new, "boolean", "test.boolean2", ftypes.BOOLEAN, nil, base.HEX, UInt64(0x00000001, 0x0))
+test("ProtoField-new-bool-mask-uint64", success)
+
+success = pcall(ProtoField.new, "boolean", "test.boolean3", ftypes.BOOLEAN, nil, base.NONE, "invalid") -- 0
+test("ProtoField-new-bool-mask-string-invalid", success)
+
+success = pcall(ProtoField.new, "boolean", "test.boolean4", ftypes.BOOLEAN, nil, base.HEX, "-1") -- 0xFFFFFFFFFFFFFFFF
+test("ProtoField-new-bool-mask-negative", success)
+
+success = pcall(ProtoField.new, "boolean", "test.boolean5", ftypes.BOOLEAN, nil, base.NONE)
+test("ProtoField-new-bool-mask-none", success)
+
+success = pcall(ProtoField.new, "boolean", "test.boolean6", ftypes.BOOLEAN, nil, base.NONE, nil)
+test("ProtoField-new-bool-mask-nil", success)
+
+success = pcall(ProtoField.bool, "test.boolean10", nil, 64, nil, 0x1)
+test("ProtoField-bool-mask-trivial", success)
+
+success = pcall(ProtoField.bool, "test.boolean11", nil, 64, nil, "1")
+test("ProtoField-bool-mask-string", success)
+
+success = pcall(ProtoField.bool, "test.boolean12", nil, 64, nil, UInt64(0x00000001, 0x0))
+test("ProtoField-bool-mask-uint64", success)
+
+success = pcall(ProtoField.bool, "test.boolean13", nil, base.NONE, nil, "invalid") -- 0
+test("ProtoField-bool-mask-string-invalid", success)
+
+success = pcall(ProtoField.bool, "test.boolean14", nil, 64, nil, "-1") -- 0xFFFFFFFFFFFFFFFF
+test("ProtoField-bool-mask-negative", success)
+
+success = pcall(ProtoField.bool, "test.boolean15", nil, base.NONE, nil)
+test("ProtoField-bool-mask-none", success)
+
+success = pcall(ProtoField.bool, "test.boolean16", nil, base.NONE, nil, nil)
+test("ProtoField-bool-mask-nil", success)
+
+success = pcall(ProtoField.new, "uint64", "test.uint64_0", ftypes.UINT64, nil, base.HEX, 0x1)
+test("ProtoField-new-uint64-mask-trivial", success)
+
+success = pcall(ProtoField.new, "uint64", "test.uint64_1", ftypes.UINT64, nil, base.HEX, "1")
+test("ProtoField-new-uint64-mask-string", success)
+
+success = pcall(ProtoField.new, "uint64", "test.uint64_2", ftypes.UINT64, nil, base.HEX, UInt64(0x00000001, 0x0))
+test("ProtoField-new-uint64-mask-uint64", success)
+
+success = pcall(ProtoField.new, "uint64", "test.uint64_3", ftypes.UINT64, nil, base.NONE, "invalid") -- 0
+test("ProtoField-new-uint64-mask-string-invalid", success)
+
+success = pcall(ProtoField.new, "uint64", "test.uint64_4", ftypes.UINT64, nil, base.HEX, "-1") -- 0xFFFFFFFFFFFFFFFF
+test("ProtoField-new-uint64-mask-negative", success)
+
+success = pcall(ProtoField.new, "uint64", "test.uint64_5", ftypes.UINT64, nil, base.NONE)
+test("ProtoField-new-uint64-mask-none", success)
+
+success = pcall(ProtoField.new, "uint64", "test.uint64_6", ftypes.UINT64, nil, base.NONE, nil)
+test("ProtoField-new-uint64-mask-nil", success)
+
+success = pcall(ProtoField.uint64, "test.uint64_10", nil, base.HEX, nil, 0x1)
+test("ProtoField-uint64-mask-trivial", success)
+
+success = pcall(ProtoField.uint64, "test.uint64_11", nil, base.HEX, nil, "1")
+test("ProtoField-uint64-mask-string", success)
+
+success = pcall(ProtoField.uint64, "test.uint64_12", nil, base.HEX, nil, UInt64(0x00000001, 0x0))
+test("ProtoField-uint64-mask-uint64", success)
+
+success = pcall(ProtoField.uint64, "test.uint64_13", nil, base.DEC, nil, "invalid") -- 0
+test("ProtoField-uint64-mask-string-invalid", success)
+
+success = pcall(ProtoField.uint64, "test.uint64_14", nil, base.DEC, nil, "-1") -- 0xFFFFFFFFFFFFFFFF
+test("ProtoField-uint64-mask-negative", success)
+
+success = pcall(ProtoField.uint64, "test.uint64_15", nil, base.DEC, nil)
+test("ProtoField-uint64-mask-none", success)
+
+success = pcall(ProtoField.uint64, "test.uint64_16", nil, base.DEC, nil, nil)
+test("ProtoField-uint64-mask-nil", success)
+
+
-- Field name: empty, illegal, incompatible
success = pcall(ProtoField.int8, nil, "empty field name 1")
test("ProtoField-empty-field-name-1", not success)