@@ -1110,6 +1110,10 @@ func TestMerge_OutputParams_Method(t *testing.T) {
11101110 if ! op .IsHandle {
11111111 t .Error ("IsHandle = false, want true" )
11121112 }
1113+ // media_status_t is not bool, so ReturnsBool must be false.
1114+ if m .ReturnsBool {
1115+ t .Error ("ReturnsBool = true, want false" )
1116+ }
11131117 // The image param should be marked as "out" so it's filtered from visible params.
11141118 foundOut := false
11151119 for _ , p := range m .Params {
@@ -1266,6 +1270,138 @@ func TestMerge_OutputParams_ScalarTypes(t *testing.T) {
12661270 }
12671271}
12681272
1273+ func TestMerge_OutputParams_ReturnsBool_Method (t * testing.T ) {
1274+ spec := specmodel.Spec {
1275+ Module : "persistablebundle" ,
1276+ SourcePackage : "github.com/xaionaro-go/ndk/capi/persistablebundle" ,
1277+ Types : map [string ]specmodel.TypeDef {
1278+ "APersistableBundle" : {Kind : "opaque_ptr" , CType : "APersistableBundle" , GoType : "*C.APersistableBundle" },
1279+ },
1280+ Functions : map [string ]specmodel.FuncDef {
1281+ "APersistableBundle_getPersistableBundle" : {
1282+ CName : "APersistableBundle_getPersistableBundle" ,
1283+ Params : []specmodel.Param {
1284+ {Name : "pBundle" , Type : "*APersistableBundle" },
1285+ {Name : "key" , Type : "string" },
1286+ {Name : "val" , Type : "**APersistableBundle" , Direction : "out" },
1287+ },
1288+ Returns : "bool" ,
1289+ },
1290+ },
1291+ }
1292+ overlay := overlaymodel.Overlay {
1293+ Module : "persistablebundle" ,
1294+ Package : overlaymodel.PackageOverlay {
1295+ GoName : "persistablebundle" ,
1296+ GoImport : "github.com/xaionaro-go/ndk/persistablebundle" ,
1297+ },
1298+ Types : map [string ]overlaymodel.TypeOverlay {
1299+ "APersistableBundle" : {GoName : "PersistableBundle" },
1300+ },
1301+ Functions : map [string ]overlaymodel.FuncOverlay {
1302+ "APersistableBundle_getPersistableBundle" : {
1303+ Receiver : "PersistableBundle" ,
1304+ GoName : "PersistableBundle" ,
1305+ OutputParams : map [string ]string {
1306+ "val" : "*PersistableBundle" ,
1307+ },
1308+ },
1309+ },
1310+ }
1311+ merged := idiomgen .Merge (spec , overlay )
1312+ if len (merged .Methods ) != 1 {
1313+ t .Fatalf ("Methods count = %d, want 1" , len (merged .Methods ))
1314+ }
1315+ m := merged .Methods [0 ]
1316+ if m .GoName != "PersistableBundle" {
1317+ t .Errorf ("GoName = %q, want %q" , m .GoName , "PersistableBundle" )
1318+ }
1319+ // The C function returns bool, so ReturnsBool must be true.
1320+ if ! m .ReturnsBool {
1321+ t .Error ("ReturnsBool = false, want true" )
1322+ }
1323+ if len (m .OutputParams ) != 1 {
1324+ t .Fatalf ("OutputParams count = %d, want 1" , len (m .OutputParams ))
1325+ }
1326+ op := m .OutputParams [0 ]
1327+ if op .CParamName != "val" {
1328+ t .Errorf ("CParamName = %q, want %q" , op .CParamName , "val" )
1329+ }
1330+ if op .GoType != "*PersistableBundle" {
1331+ t .Errorf ("GoType = %q, want %q" , op .GoType , "*PersistableBundle" )
1332+ }
1333+ if op .CapiType != "*capi.APersistableBundle" {
1334+ t .Errorf ("CapiType = %q, want %q" , op .CapiType , "*capi.APersistableBundle" )
1335+ }
1336+ if ! op .IsHandle {
1337+ t .Error ("IsHandle = false, want true" )
1338+ }
1339+ }
1340+
1341+ func TestMerge_OutputParams_ReturnsBool_FreeFunction (t * testing.T ) {
1342+ spec := specmodel.Spec {
1343+ Module : "persistablebundle" ,
1344+ SourcePackage : "github.com/xaionaro-go/ndk/capi/persistablebundle" ,
1345+ Types : map [string ]specmodel.TypeDef {
1346+ "APersistableBundle" : {Kind : "opaque_ptr" , CType : "APersistableBundle" , GoType : "*C.APersistableBundle" },
1347+ },
1348+ Functions : map [string ]specmodel.FuncDef {
1349+ "APersistableBundle_createFromBytes" : {
1350+ CName : "APersistableBundle_createFromBytes" ,
1351+ Params : []specmodel.Param {
1352+ {Name : "data" , Type : "*uint8" },
1353+ {Name : "size" , Type : "int32" },
1354+ {Name : "outBundle" , Type : "**APersistableBundle" , Direction : "out" },
1355+ },
1356+ Returns : "bool" ,
1357+ },
1358+ },
1359+ }
1360+ overlay := overlaymodel.Overlay {
1361+ Module : "persistablebundle" ,
1362+ Package : overlaymodel.PackageOverlay {
1363+ GoName : "persistablebundle" ,
1364+ GoImport : "github.com/xaionaro-go/ndk/persistablebundle" ,
1365+ },
1366+ Types : map [string ]overlaymodel.TypeOverlay {
1367+ "APersistableBundle" : {GoName : "PersistableBundle" },
1368+ },
1369+ Functions : map [string ]overlaymodel.FuncOverlay {
1370+ "APersistableBundle_createFromBytes" : {
1371+ GoName : "CreateFromBytes" ,
1372+ OutputParams : map [string ]string {
1373+ "outBundle" : "*PersistableBundle" ,
1374+ },
1375+ },
1376+ },
1377+ }
1378+ merged := idiomgen .Merge (spec , overlay )
1379+ if len (merged .FreeFunctions ) != 1 {
1380+ t .Fatalf ("FreeFunctions count = %d, want 1" , len (merged .FreeFunctions ))
1381+ }
1382+ f := merged .FreeFunctions [0 ]
1383+ if f .GoName != "CreateFromBytes" {
1384+ t .Errorf ("GoName = %q, want %q" , f .GoName , "CreateFromBytes" )
1385+ }
1386+ // The C function returns bool, so ReturnsBool must be true.
1387+ if ! f .ReturnsBool {
1388+ t .Error ("ReturnsBool = false, want true" )
1389+ }
1390+ if len (f .OutputParams ) != 1 {
1391+ t .Fatalf ("OutputParams count = %d, want 1" , len (f .OutputParams ))
1392+ }
1393+ op := f .OutputParams [0 ]
1394+ if op .CParamName != "outBundle" {
1395+ t .Errorf ("CParamName = %q, want %q" , op .CParamName , "outBundle" )
1396+ }
1397+ if op .GoType != "*PersistableBundle" {
1398+ t .Errorf ("GoType = %q, want %q" , op .GoType , "*PersistableBundle" )
1399+ }
1400+ if ! op .IsHandle {
1401+ t .Error ("IsHandle = false, want true" )
1402+ }
1403+ }
1404+
12691405func TestMerge_AutoOpaqueType_NoOverlay (t * testing.T ) {
12701406 spec := specmodel.Spec {
12711407 Module : "test" ,
0 commit comments