Skip to content

Commit e6c2ffc

Browse files
committed
Add. test to set/unset postfields
1 parent 47fa936 commit e6c2ffc

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

test/test_easy.lua

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,61 @@ function test_reset()
700700
assert(not pfrom.value)
701701
end
702702

703+
end
704+
705+
local _ENV = TEST_CASE'setopt_postfields' if ENABLE then
706+
707+
local c
708+
709+
function teardown()
710+
if c then c:close() end
711+
c = nil
712+
end
713+
714+
function test()
715+
716+
do local fields = {}
717+
for i = 1, 100 do fields[#fields + 1] = "key" .. i .. "=value"..i end
718+
fields = table.concat(fields, '&')
719+
c = assert(curl.easy{
720+
url = "http://httpbin.org/post",
721+
postfields = fields,
722+
writefunction = function()end,
723+
})
724+
end
725+
726+
-- call gc to try clear `fields` string
727+
for i = 1, 4 do collectgarbage"collect" end
728+
729+
c:perform()
730+
end
731+
732+
function test_unset()
733+
local pfields
734+
735+
do local fields = {}
736+
for i = 1, 100 do fields[#fields + 1] = "key" .. i .. "=value"..i end
737+
fields = table.concat(fields, '&')
738+
c = assert(curl.easy{
739+
url = "http://httpbin.org/post",
740+
postfields = fields,
741+
writefunction = function()end,
742+
})
743+
pfields = weak_ptr(fields)
744+
end
745+
746+
-- call gc to try clear `fields` string
747+
for i = 1, 4 do collectgarbage"collect" end
748+
assert_string(pfields.value)
749+
750+
assert_equal(c, c:unsetopt_postfields())
751+
752+
-- @todo check internal storage because gc really do not clear `weak` string
753+
-- for i = 1, 4 do collectgarbage"collect" end
754+
-- assert_nil(pfields.value)
755+
756+
-- c:perform()
757+
end
703758

704759
end
705760

0 commit comments

Comments
 (0)