aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua
diff options
context:
space:
mode:
authorHadriel Kaplan <hadrielk@yahoo.com>2014-03-23 00:30:21 -0400
committerAnders Broman <a.broman58@gmail.com>2014-03-23 07:05:30 +0000
commit21a61a8cb1bad305a2653aa14d2cdb53472f9f20 (patch)
tree5924db9a5af951ba6f4b63fd28d3ea22251beade /test/lua
parent99505109bbfb19cd6f7ca5f7ab0edc8e093376f2 (diff)
Add Lua Struct.values() function, and prevent coercion in all Struct functions
This adds a Struct.values() function to get the number of values needed/returned with Struct.pack/unpack. It also changes the existing Struct functions such that they don't coerce a non-string argument into a string. (not preventing it confused a user on ask.wireshark.org) Change-Id: I93d5846105e55b67680e1c276a7286535c77b039 Reviewed-on: https://code.wireshark.org/review/790 Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/struct.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/lua/struct.lua b/test/lua/struct.lua
index 384e12414e..7759c1e75e 100644
--- a/test/lua/struct.lua
+++ b/test/lua/struct.lua
@@ -71,6 +71,14 @@ test("basic_size2", lib.size(fmt1_le) == Struct.size(fmt1_be))
test("basic_size3", lib.size(fmt1_le) == Struct.size(fmt1_64le))
test("basic_size4", lib.size(fmt2_be) == Struct.size(fmt1_64le))
+testing("basic values")
+
+test("basic_values1", lib.values(fmt1_le) == 5)
+test("basic_values2", lib.values(fmt1_be) == lib.values(fmt1_le))
+test("basic_values3", lib.values(fmt1_64le) == 3)
+test("basic_values4", lib.values(fmt2_be) == lib.values(fmt1_64le))
+test("basic_values4", lib.values(" (I) s x i XxX c0") == 3)
+
testing("tohex")
local val1hex = "2A:00:00:00:00:00:00:01:00:00:00:02:00:00:00:03:00:00:00:04"
test("tohex1", Struct.tohex(val1) == tohex(val1):upper())
@@ -352,6 +360,17 @@ test("weird_unpack7",pcall(lib.unpack, "bc0", "\3alo"))
test("weird_unpack8",not pcall(lib.unpack, "b", "alo", 4))
test("weird_unpack9",lib.unpack("b", "alo\3", 4) == 3)
+test("weird_pack11",not pcall(lib.pack, "\250\22", "alo"))
+test("weird_pack12",not pcall(lib.pack, 1, "alo"))
+test("weird_pack13",not pcall(lib.pack, nil, "alo"))
+test("weird_pack14",not pcall(lib.pack, {}, "alo"))
+test("weird_pack15",not pcall(lib.pack, true, "alo"))
+test("weird_unpack10",not pcall(lib.unpack, "\250\22", "\3alo"))
+test("weird_unpack11",not pcall(lib.unpack, 1, "\3alo"))
+test("weird_unpack12",not pcall(lib.unpack, nil, "\3alo"))
+test("weird_unpack13",not pcall(lib.unpack, {}, "\3alo"))
+test("weird_unpack14",not pcall(lib.unpack, true, "\3alo"))
+
print("\n-----------------------------\n")