MCPcopy
hub / github.com/EngoEngine/engo / TestTMXTileNotLoadedTempFileBadExtensions

Function TestTMXTileNotLoadedTempFileBadExtensions

common/tmx_test.go:223–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

221}
222
223func TestTMXTileNotLoadedTempFileBadExtensions(t *testing.T) {
224 imgbuf := bytes.NewBuffer([]byte{})
225 img := image.NewRGBA(image.Rect(0, 0, 132, 99))
226 err := png.Encode(imgbuf, img)
227 if err != nil {
228 t.Errorf("Unable to encode png from image")
229 }
230
231 dir, err := ioutil.TempDir(".", "testing")
232 if err != nil {
233 t.Errorf("failed to create temp directory for testing, error: %v", err)
234 }
235 defer os.RemoveAll(dir)
236
237 engo.Files.SetRoot(dir)
238
239 tmpfn := filepath.Join(dir, "test.test")
240 if err = ioutil.WriteFile(tmpfn, imgbuf.Bytes(), 0666); err != nil {
241 t.Errorf("failed to create temp file for testing, file: %v, error: %v", tmpfn, err)
242 }
243
244 buf := bytes.NewBuffer([]byte{})
245 tmpl, err := template.New("test").Parse(testTMXtmpl)
246 if err != nil {
247 t.Error("Error parsing tmx template")
248 }
249 err = tmpl.Execute(buf, tmxData{
250 Orientation: "orthogonal",
251 RenderOrder: "right-down",
252 BadExtensions: ".test",
253 })
254 if err != nil {
255 t.Error("Error executing tmx template")
256 }
257
258 engo.Files.Unload("test.test")
259 err = engo.Files.LoadReaderData("test.tmx", buf)
260 if err == nil {
261 t.Errorf("Able to load test image with bad extension from file while loading tmx.")
262 }
263}
264
265func TestTMXBadFile(t *testing.T) {
266 err := engo.Files.LoadReaderData("bad.tmx", bytes.NewBufferString(badTMX))

Callers

nothing calls this directly

Calls 6

BytesMethod · 0.80
LoadReaderDataMethod · 0.80
SetRootMethod · 0.65
UnloadMethod · 0.65
NewMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected