Lua: Add some ProtoField tests
authorStig Bjørlykke <stig@bjorlykke.org>
Thu, 16 Mar 2017 19:45:34 +0000 (20:45 +0100)
committerAnders Broman <a.broman58@gmail.com>
Sun, 19 Mar 2017 15:14:18 +0000 (15:14 +0000)
Add tests for abbrev and name validation.
Add tests for signed integer base values.

Change-Id: I0bd65c6633b44ae998880f528c22afc22c87529d
Reviewed-on: https://code.wireshark.org/review/20568
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
test/lua/protofield.lua

index 8f8e5d237b90aeeaeb4db2480ac7ec1bff0cfc3a..c4026e5cf85c03d1cac650c85f59b75382ccbe24 100644 (file)
@@ -30,7 +30,7 @@ local function setFailed(name)
 end
 
 -- expected number of runs
-local taptests = { [OTHER]=16 }
+local taptests = { [OTHER]=28 }
 local function getResults()
     print("\n-----------------------------\n")
     for k,v in pairs(taptests) do
@@ -71,6 +71,45 @@ local test_proto = Proto.new("test", "Test Proto")
 test_proto.fields.time_field = ProtoField.uint16("test.time", "Time", base.UNIT_STRING, {" sec", " secs"})
 test_proto.fields.dist_field = ProtoField.uint16("test.dist", "Distance", base.UNIT_STRING, {" km"})
 
+-- Field name: empty, illegal, incompatible
+success = pcall(ProtoField.int8, nil, "empty field name 1")
+test("ProtoField-empty-field-name-1", not success)
+
+success = pcall(ProtoField.int8, "", "empty field name 2")
+test("ProtoField-empty-field-name-2", not success)
+
+success = pcall(ProtoField.int8, "test.$", "illegal field name")
+test("ProtoField-illegal-field-name", not success)
+
+success = pcall(ProtoField.int8, "frame.time", "incompatible field name")
+test("ProtoField-incompatible-field-name", not success)
+
+-- Actual name: empty
+success = pcall(ProtoField.int8, "test.empty_name_1")
+test("ProtoField-empty-name-1", success)  -- will use abbrev
+
+success = pcall(ProtoField.int8, "test.empty_name_2", "")
+test("ProtoField-empty-name-2", not success)
+
+-- Signed integer base values, only base.DEC should work
+success = pcall(ProtoField.int8, "test.int.base_none", "int base NONE", base.NONE)
+test("ProtoField-int-base-none", not success)
+
+success = pcall(ProtoField.int8, "test.int.base_dec", "int base DEC", base.DEC)
+test("ProtoField-int-base-dec", success)
+
+success = pcall(ProtoField.int8, "test.int.base_hex", "int base HEX", base.HEX)
+test("ProtoField-int-base-hex", not success)
+
+success = pcall(ProtoField.int8, "test.int.base_oct", "int base OCT", base.OCT)
+test("ProtoField-int-base-oct", not success)
+
+success = pcall(ProtoField.int8, "test.int.base_dec_hex", "int base DEC_HEX", base.DEC_HEX)
+test("ProtoField-int-base-dec-hex", not success)
+
+success = pcall(ProtoField.int8, "test.int.base_hex_dec", "int base HEX_DEC", base.HEX_DEC)
+test("ProtoField-int-base-hex-dec", not success)
+
 -- Passing no table should not work
 success = pcall(ProtoField.uint16, "test.bad0", "Bad0", base.UNIT_STRING)
 test("ProtoField-unitstring-no-table", not success)