Fix. Progress function should return 1
to continue.
This commit is contained in:
parent
05147e5b30
commit
e30104bc44
@ -329,8 +329,11 @@ function setopt_readfunction() end
|
||||
-- the third is the number of bytes downloaded so far,
|
||||
-- the fourth is the total number of bytes expected to be uploaded
|
||||
-- in this transfer, and the fifth is the number of bytes uploaded so far.
|
||||
-- Function must return `true` or or nothing to continue operation.
|
||||
-- Otherwise the transfer will be aborted with an error.
|
||||
-- Function must return `true` or `1` or nothing to continue operation.
|
||||
-- Otherwise the transfer will be aborted with an error `ABORTED_BY_CALLBACK`.<br/>
|
||||
--
|
||||
-- !!! NOTE !!! This is differents form libcurl API. In libcurl returning a non-zero
|
||||
-- value from this callback will cause libcurl to abort the transfer and return.
|
||||
--
|
||||
-- @tparam function progress
|
||||
-- @param[opt] context progress context
|
||||
|
@ -785,7 +785,10 @@ static int lcurl_xferinfo_callback(void *arg, curl_off_t dltotal, curl_off_t dln
|
||||
}
|
||||
if(lua_isboolean(L, top + 1))
|
||||
ret = lua_toboolean(L, top + 1)?0:1;
|
||||
else ret = (size_t)lua_tonumber(L, top + 1);
|
||||
else{
|
||||
ret = (size_t)lua_tonumber(L, top + 1);
|
||||
if(ret == 0) ret = 1; else ret = 0;
|
||||
}
|
||||
}
|
||||
|
||||
lua_settop(L, top);
|
||||
|
@ -114,6 +114,115 @@ function test_write_pass_03()
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
local _ENV = TEST_CASE'progress_callback' do
|
||||
|
||||
local c
|
||||
|
||||
local function pass() end
|
||||
|
||||
function teardown()
|
||||
if f then f:close() end
|
||||
os.remove(fname)
|
||||
if c then c:close() end
|
||||
f, c = nil
|
||||
end
|
||||
|
||||
function test_abort_01()
|
||||
c = assert(scurl.easy{
|
||||
url = url,
|
||||
writefunction = pass,
|
||||
noprogress = false,
|
||||
progressfunction = function() return false end
|
||||
})
|
||||
|
||||
local _, e = assert_nil(c:perform())
|
||||
assert_equal(curl.error(curl.ERROR_EASY, curl.E_ABORTED_BY_CALLBACK), e)
|
||||
end
|
||||
|
||||
function test_abort_02()
|
||||
c = assert(scurl.easy{
|
||||
url = url,
|
||||
writefunction = pass,
|
||||
noprogress = false,
|
||||
progressfunction = function() return 0 end
|
||||
})
|
||||
|
||||
local _, e = assert_nil(c:perform())
|
||||
assert_equal(curl.error(curl.ERROR_EASY, curl.E_ABORTED_BY_CALLBACK), e)
|
||||
end
|
||||
|
||||
function test_abort_03()
|
||||
c = assert(scurl.easy{
|
||||
url = url,
|
||||
writefunction = pass,
|
||||
noprogress = false,
|
||||
progressfunction = function() return nil end
|
||||
})
|
||||
|
||||
local _, e = assert_nil(c:perform())
|
||||
assert_equal(curl.error(curl.ERROR_EASY, curl.E_ABORTED_BY_CALLBACK), e)
|
||||
end
|
||||
|
||||
function test_abort_04()
|
||||
c = assert(scurl.easy{
|
||||
url = url,
|
||||
writefunction = pass,
|
||||
noprogress = false,
|
||||
progressfunction = function() return nil, "PROGRESSERROR" end
|
||||
})
|
||||
|
||||
local _, e = assert_nil(c:perform())
|
||||
assert_equal("PROGRESSERROR", e)
|
||||
end
|
||||
|
||||
function test_abort_05()
|
||||
c = assert(scurl.easy{
|
||||
url = url,
|
||||
writefunction = pass,
|
||||
noprogress = false,
|
||||
progressfunction = function() error( "PROGRESSERROR" )end
|
||||
})
|
||||
|
||||
assert_error_match("PROGRESSERROR", function()
|
||||
c:perform()
|
||||
end)
|
||||
end
|
||||
|
||||
function test_pass_01()
|
||||
c = assert(scurl.easy{
|
||||
url = url,
|
||||
writefunction = pass,
|
||||
noprogress = false,
|
||||
progressfunction = function() end
|
||||
})
|
||||
|
||||
assert_equal(c, c:perform())
|
||||
end
|
||||
|
||||
function test_pass_02()
|
||||
c = assert(scurl.easy{
|
||||
url = url,
|
||||
writefunction = pass,
|
||||
noprogress = false,
|
||||
progressfunction = function() return true end
|
||||
})
|
||||
|
||||
assert_equal(c, c:perform())
|
||||
end
|
||||
|
||||
function test_pass_03()
|
||||
c = assert(scurl.easy{
|
||||
url = url,
|
||||
writefunction = pass,
|
||||
noprogress = false,
|
||||
progressfunction = function() return 1 end
|
||||
})
|
||||
|
||||
assert_equal(c, c:perform())
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local _ENV = TEST_CASE'escape' do
|
||||
|
Loading…
x
Reference in New Issue
Block a user