From e6c2ffce5c02455763856c87adafab3f783ef2dd Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Mon, 15 Sep 2014 10:57:33 +0500 Subject: [PATCH] Add. test to set/unset postfields --- test/test_easy.lua | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/test_easy.lua b/test/test_easy.lua index 0f38c18..27dd6ef 100644 --- a/test/test_easy.lua +++ b/test/test_easy.lua @@ -700,6 +700,61 @@ function test_reset() assert(not pfrom.value) end +end + +local _ENV = TEST_CASE'setopt_postfields' if ENABLE then + +local c + +function teardown() + if c then c:close() end + c = nil +end + +function test() + + do local fields = {} + for i = 1, 100 do fields[#fields + 1] = "key" .. i .. "=value"..i end + fields = table.concat(fields, '&') + c = assert(curl.easy{ + url = "http://httpbin.org/post", + postfields = fields, + writefunction = function()end, + }) + end + + -- call gc to try clear `fields` string + for i = 1, 4 do collectgarbage"collect" end + + c:perform() +end + +function test_unset() + local pfields + + do local fields = {} + for i = 1, 100 do fields[#fields + 1] = "key" .. i .. "=value"..i end + fields = table.concat(fields, '&') + c = assert(curl.easy{ + url = "http://httpbin.org/post", + postfields = fields, + writefunction = function()end, + }) + pfields = weak_ptr(fields) + end + + -- call gc to try clear `fields` string + for i = 1, 4 do collectgarbage"collect" end + assert_string(pfields.value) + + assert_equal(c, c:unsetopt_postfields()) + + -- @todo check internal storage because gc really do not clear `weak` string + -- for i = 1, 4 do collectgarbage"collect" end + -- assert_nil(pfields.value) + + -- c:perform() +end end