@@ -153,9 +153,16 @@ function test_reset_write_callback()
153153 assert_equal (c , c :setopt_writefunction (f ))
154154 assert_equal (c , c :setopt_writefunction (f .write , f ))
155155 assert_equal (c , c :setopt_writefunction (print ))
156+ assert_equal (c , c :setopt_writefunction (print , null ))
157+ assert_equal (c , c :setopt_writefunction (null ))
158+ assert_equal (c , c :setopt_writefunction (null , nil ))
159+ assert_equal (c , c :setopt_writefunction (null , null ))
156160 assert_error (function ()c :setopt_writefunction ()end )
157161 assert_error (function ()c :setopt_writefunction (nil )end )
158162 assert_error (function ()c :setopt_writefunction (nil , f )end )
163+ assert_error (function ()c :setopt_writefunction (null , {})end )
164+ assert_error (function ()c :setopt_writefunction (print , {}, nil )end )
165+ assert_error (function ()c :setopt_writefunction (print , {}, null )end )
159166end
160167
161168function test_write_pass_01 ()
@@ -210,6 +217,38 @@ function test_write_coro()
210217 assert_equal (co2 , called )
211218end
212219
220+ function test_write_pass_null_context ()
221+ c = assert (curl .easy {
222+ url = GET_URL ;
223+ })
224+
225+ local context
226+ assert_equal (c , c :setopt_writefunction (function (ctx )
227+ context = ctx
228+ return true
229+ end , null ))
230+
231+ assert_equal (c , c :perform ())
232+ assert_equal (null , context )
233+ end
234+
235+ function test_write_pass_nil_context ()
236+ c = assert (curl .easy {
237+ url = GET_URL ;
238+ })
239+
240+ local context , called
241+ assert_equal (c , c :setopt_writefunction (function (ctx )
242+ context = ctx
243+ called = true
244+ return true
245+ end , nil ))
246+
247+ assert_equal (c , c :perform ())
248+ assert_true (called )
249+ assert_nil (context )
250+ end
251+
213252end
214253
215254local _ENV = TEST_CASE ' progress_callback' if ENABLE then
@@ -381,9 +420,14 @@ function test_reset_header_callback()
381420 assert_equal (c , c :setopt_headerfunction (f ))
382421 assert_equal (c , c :setopt_headerfunction (f .header , f ))
383422 assert_equal (c , c :setopt_headerfunction (print ))
423+ assert_equal (c , c :setopt_headerfunction (null ))
424+ assert_equal (c , c :setopt_headerfunction (null , nil ))
425+ assert_equal (c , c :setopt_headerfunction (null , null ))
384426 assert_error (function ()c :setopt_headerfunction ()end )
385427 assert_error (function ()c :setopt_headerfunction (nil )end )
386428 assert_error (function ()c :setopt_headerfunction (nil , f )end )
429+ assert_error (function ()c :setopt_headerfunction (null , {})end )
430+ assert_error (function ()c :setopt_headerfunction (print , {}, nil )end )
387431end
388432
389433function test_header_pass_01 ()
0 commit comments