| 472 | } |
| 473 | |
| 474 | func TestObjectImageNotExistTempFile(t *testing.T) { |
| 475 | imgbuf := bytes.NewBuffer([]byte{}) |
| 476 | img := image.NewRGBA(image.Rect(0, 0, 55, 55)) |
| 477 | err := png.Encode(imgbuf, img) |
| 478 | if err != nil { |
| 479 | t.Errorf("Unable to encode png from image") |
| 480 | } |
| 481 | |
| 482 | dir, err := ioutil.TempDir(".", "testing") |
| 483 | if err != nil { |
| 484 | t.Errorf("failed to create temp directory for testing, error: %v", err) |
| 485 | } |
| 486 | defer os.RemoveAll(dir) |
| 487 | |
| 488 | engo.Files.SetRoot(dir) |
| 489 | |
| 490 | tmpfn := filepath.Join(dir, "objimgtest.png") |
| 491 | if err = ioutil.WriteFile(tmpfn, imgbuf.Bytes(), 0666); err != nil { |
| 492 | t.Errorf("failed to create temp file for testing, file: %v, error: %v", tmpfn, err) |
| 493 | } |
| 494 | |
| 495 | buf := bytes.NewBuffer([]byte{}) |
| 496 | tmpl, err := template.New("test").Parse(testTMXtmpl) |
| 497 | if err != nil { |
| 498 | t.Error("Error parsing tmx template") |
| 499 | } |
| 500 | err = tmpl.Execute(buf, tmxData{ |
| 501 | Orientation: "orthogonal", |
| 502 | RenderOrder: "right-up", |
| 503 | ObjectImageTest: true, |
| 504 | ChunkData: true, |
| 505 | }) |
| 506 | if err != nil { |
| 507 | t.Error("Error executing tmx template") |
| 508 | } |
| 509 | |
| 510 | engo.Files.Unload("objimgtest.png") |
| 511 | err = engo.Files.LoadReaderData("test.tmx", buf) |
| 512 | if err != nil { |
| 513 | t.Errorf("Unable to load test image from file while loading object image. Error: %v", err) |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | func TestTMXBadObjectImageNotExist(t *testing.T) { |
| 518 | buf := bytes.NewBuffer([]byte{}) |