Skip to content

Commit bcc8719

Browse files
authored
test: add cases for options passing, memory management, and type safety (#44)
* test: add tests for parameter passing, memory management, and type safety * test: add tests for parameter passing, memory management, and type safety * test: add tests for parameter passing, memory management, and type safety * test: add tests for parameter passing, memory management, and type safety * build: update generated vips package
1 parent da38d95 commit bcc8719

File tree

4 files changed

+1090
-6
lines changed

4 files changed

+1090
-6
lines changed

internal/generator/templatefunc.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,16 @@ func generateCreatorMethodBody(op introspection.Operation) string {
12061206
// Add startup line
12071207
body = "Startup(nil)\n\t"
12081208

1209+
// Add buffer validation for operations with buffer input
1210+
if op.HasBufferInput {
1211+
if bufParam := getBufferParameter(op.RequiredInputs); bufParam != nil {
1212+
body += fmt.Sprintf(`if len(%s) == 0 {
1213+
return nil, fmt.Errorf("%s: buffer is empty")
1214+
}
1215+
`, bufParam.GoName, op.Name)
1216+
}
1217+
}
1218+
12091219
imageTypeString := op.ImageTypeString
12101220
if strings.Contains(op.Name, "thumbnail") {
12111221
imageTypeString = "vipsDetermineImageType(vipsImage)"

internal/generator/util.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,12 @@ func getArrayType(goType string) string {
7676
return "unknown"
7777
}
7878
}
79+
80+
func getBufferParameter(args []introspection.Argument) *introspection.Argument {
81+
for _, arg := range args {
82+
if arg.IsBuffer && arg.IsInput && arg.GoType == "[]byte" {
83+
return &arg
84+
}
85+
}
86+
return nil
87+
}

vips/image.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)