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

Function TestTMXTileImagesNotLoadedTempFile

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

Source from the content-addressed store, hash-verified

363}
364
365func TestTMXTileImagesNotLoadedTempFile(t *testing.T) {
366 imgbuf := bytes.NewBuffer([]byte{})
367 img := image.NewRGBA(image.Rect(0, 0, 132, 99))
368 err := png.Encode(imgbuf, img)
369 if err != nil {
370 t.Errorf("Unable to encode png from image")
371 }
372
373 dir, err := ioutil.TempDir(".", "testing")
374 if err != nil {
375 t.Errorf("failed to create temp directory for testing, error: %v", err)
376 }
377 defer os.RemoveAll(dir)
378
379 engo.Files.SetRoot(dir)
380
381 tmpfn := filepath.Join(dir, "test.png")
382 if err = ioutil.WriteFile(tmpfn, imgbuf.Bytes(), 0666); err != nil {
383 t.Errorf("failed to create temp file for testing, file: %v, error: %v", tmpfn, err)
384 }
385
386 buf := bytes.NewBuffer([]byte{})
387 tmpl, err := template.New("test").Parse(testTMXtmpl)
388 if err != nil {
389 t.Error("Error parsing tmx template")
390 }
391 err = tmpl.Execute(buf, tmxData{
392 Orientation: "orthogonal",
393 RenderOrder: "right-down",
394 Tiles: true,
395 })
396 if err != nil {
397 t.Error("Error executing tmx template")
398 }
399
400 engo.Files.Unload("test.png")
401 err = engo.Files.LoadReaderData("test.tmx", buf)
402 if err != nil {
403 t.Errorf("Unable to load test image from file while loading tmx. Error: %v", err)
404 }
405}
406
407func TestTMXTileImageWrongFileType(t *testing.T) {
408 buf := bytes.NewBuffer([]byte{})

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