@@ -8,6 +8,9 @@ import Libdl
88
99# for cfunction_closure
1010include (" testenv.jl" )
11+ # for cfunction error
12+ isdefined (Main, :MacroCalls ) || @eval Main include (" testhelpers/MacroCalls.jl" )
13+ using Main. MacroCalls
1114
1215const libccalltest = " libccalltest"
1316
@@ -1677,6 +1680,10 @@ end
16771680 @test_throws ArgumentError (" interpolated function `PROGRAM_FILE` was not a Ptr{Cvoid}, but String" ) @ccall $ PROGRAM_FILE (" foo" :: Cstring ):: Cvoid
16781681end
16791682
1683+ @testset " check error path for @cfunction" begin
1684+ @test_throws ArgumentError (" @cfunction argument types must be a literal tuple" ) @macrocall (@cfunction (identity, Cstring, Cstring))
1685+ end
1686+
16801687# call some c functions
16811688@testset " run @ccall with C standard library functions" begin
16821689 @test @ccall (sqrt (4.0 :: Cdouble ):: Cdouble ) == 2.0
@@ -1733,3 +1740,14 @@ ccall_lazy_lib_name(x) = ccall((:testUcharX, compute_lib_name()), Int32, (UInt8,
17331740@test ccall_lazy_lib_name (3 ) == 1
17341741ccall_with_undefined_lib () = ccall ((:time , xx_nOt_DeFiNeD_xx), Cint, (Ptr{Cvoid},), C_NULL )
17351742@test_throws UndefVarError (:xx_nOt_DeFiNeD_xx ) ccall_with_undefined_lib ()
1743+
1744+ @testset " transcode for UInt8 and UInt16" begin
1745+ a = [UInt8 (1 ), UInt8 (2 ), UInt8 (3 )]
1746+ a16 = transcode (UInt16, a)
1747+ a8 = transcode (UInt8, a16)
1748+ @test a8 == a
1749+ b = [UInt16 (1 ), UInt16 (2 ), UInt16 (3 )]
1750+ b8 = transcode (UInt8, b)
1751+ b16 = transcode (UInt16, b8)
1752+ @test b16 == b
1753+ end
0 commit comments