The original raylib C library's ExportImage function returns a boolean to indicate the success or failure of the export operation. This behavior was missing in the raylib-go implementation, which provided no return value, thereby limiting error handling capabilities. This commit updates the ExportImage function in raylib-go to return a boolean or an error, aligning it with its C counterpart and enabling idiomatic Go error handling. The change includes updates to the function and tests to reflect the new return type. This enhancement increases robustness and clarity in error handling for Go developers using raylib-go. The test suite has been updated and run to ensure the correct functioning of the modified ExportImage function, with results confirming the expected behavior in both successful and unsuccessful scenarios. - Daniel "ShellFu" Kendrick
48 lines
939 B
Go
48 lines
939 B
Go
package rl_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"image/color"
|
|
|
|
rl "github.com/gen2brain/raylib-go/raylib"
|
|
)
|
|
|
|
func TestExportImage(t *testing.T) {
|
|
var tests = []struct {
|
|
name string
|
|
image rl.Image
|
|
fileName string
|
|
want bool
|
|
}{
|
|
{
|
|
name: "ValidImageExport",
|
|
image: *rl.GenImageColor(100, 100, color.RGBA{255, 0, 0, 255}),
|
|
fileName: "test_image.png",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "InvalidImageExport",
|
|
image: rl.Image{},
|
|
fileName: "",
|
|
want: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
success := rl.ExportImage(tt.image, tt.fileName)
|
|
defer os.Remove(tt.fileName)
|
|
|
|
if success != tt.want {
|
|
t.Errorf("ExportImage() result = %v, wantResult %v", success, tt.want)
|
|
return
|
|
}
|
|
|
|
if _, err := os.Stat(tt.fileName); os.IsNotExist(err) && tt.want {
|
|
t.Errorf("ExportImage() failed to create file %s", tt.fileName)
|
|
}
|
|
})
|
|
}
|
|
}
|