From a1e5a157802428cee7c01ada4def7c818ebfea82 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 24 May 2018 13:57:37 +0200 Subject: wslua: fix NSTime:__tostring for negative values "nstime_t{A, B}" is defined as "A + B * 10^9" rather than an integer part A and fractional part B. Bug: 14720 Change-Id: I5321db7d5ecea8f976291d2a22667b02162194e2 Reviewed-on: https://code.wireshark.org/review/27775 Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- test/lua/nstime.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/lua/nstime.lua b/test/lua/nstime.lua index c8ecdd2d29..00daa3e40e 100644 --- a/test/lua/nstime.lua +++ b/test/lua/nstime.lua @@ -31,7 +31,7 @@ end -- note ip only runs 3 times because it gets removed -- and bootp only runs twice because the filter makes it run -- once and then it gets replaced with a different one for the second time -local taptests = { [FRAME]=4, [OTHER]=40 } +local taptests = { [FRAME]=4, [OTHER]=44 } local function getResults() print("\n-----------------------------\n") for k,v in pairs(taptests) do @@ -143,6 +143,13 @@ test("NSTime.set-38", first == NSTime(123,100)) test("NSTime.get-39", first.secs == 123) test("NSTime.get-40", first.nsecs == 100) +local minus0_4 = NSTime() - NSTime(0,400000000) +test("NSTime.negative_tonumber-41", minus0_4:tonumber() == -0.4) +test("NSTime.negative_tostring-42", tostring(minus0_4) == "-0.400000000") +local minus0_4 = NSTime() - NSTime(1,400000000) +test("NSTime.negative_tonumber-43", minus0_4:tonumber() == -1.4) +test("NSTime.negative_tostring-44", tostring(minus0_4) == "-1.400000000") + ---------------------------------- -- revert to original test function, kinda sorta -- cgit v1.2.3