test_sprite.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * This is a test for sprite in $package$
  3. */
  4. #include "si_test.h"
  5. #include "eruta.h"
  6. #include "sprite.h"
  7. TEST_FUNC(sprite) {
  8. SpriteList * list;
  9. Sprite * sprite;
  10. SpriteAction * act;
  11. SpriteFrame * frame;
  12. SpriteLayer * layer;
  13. Point offset = bevec(1.0, 2.0);
  14. sprite = sprite_new(1);
  15. list = spritelist_new();
  16. TEST_NOTNULL(list);
  17. TEST_NOTNULL(spritelist_getornew(list, 123));
  18. TEST_NOTNULL(sprite);
  19. TEST_NULL(sprite_action(sprite, 0));
  20. TEST_NULL(sprite_action(sprite, 1));
  21. TEST_NULL(sprite_frame(sprite, 1, 2));
  22. TEST_NULL(sprite_layer(sprite, 1, 2, 3));
  23. act = sprite_newaction(sprite, 0, SPRITE_NORTH, SPRITE_ACTIVE);
  24. TEST_NOTNULL(act);
  25. TEST_PTREQ(act, sprite_action(sprite, 0));
  26. act = sprite_newaction(sprite, 0, SPRITE_NORTH,SPRITE_ACTIVE);
  27. TEST_NOTNULL(act);
  28. TEST_PTREQ(act, sprite_action(sprite, 0));
  29. frame = sprite_newframe(sprite, 0, 1, SPRITE_ACTIVE, 0.25);
  30. TEST_NOTNULL(frame);
  31. TEST_PTREQ(frame, sprite_frame(sprite, 0, 1));
  32. layer = sprite_newlayer(sprite, 0, 1, 2, NULL, offset);
  33. TEST_NOTNULL(layer);
  34. TEST_PTREQ(layer, sprite_layer(sprite, 0, 1, 2));
  35. /* Check if out of bounds new works and doesn't leak. */
  36. act = sprite_newaction(sprite, 100, SPRITE_NORTH, SPRITE_ACTIVE);
  37. TEST_NULL(act);
  38. layer = sprite_newlayer(sprite, 0, 1, 22, NULL, offset);
  39. TEST_NULL(layer);
  40. TEST_PTREQ(layer, sprite_layer(sprite, 0, 1, 22));
  41. frame = sprite_newframe(sprite, 0, 111, SPRITE_ACTIVE, 0.25);
  42. TEST_NULL(frame);
  43. layer = sprite_newlayer(sprite, 0, 1, 222, NULL, offset);
  44. TEST_NULL(layer);
  45. TEST_NOTNULL(sprite_maxactions_(sprite, 77));
  46. TEST_INTEQ(77, sprite_maxactions(sprite));
  47. act = sprite_newaction(sprite, 60, SPRITE_NORTH, SPRITE_ACTIVE);
  48. TEST_NOTNULL(sprite_action(sprite, 60));
  49. TEST_NOTNULL(sprite_maxactions_(sprite, 1));
  50. TEST_NULL(sprite_action(sprite, 60));
  51. TEST_INTEQ(1, sprite_maxactions(sprite));
  52. TEST_NOTNULL(sprite_action(sprite, 0));
  53. act = sprite_action(sprite, 0);
  54. if (act) {
  55. TEST_NOTNULL(spriteaction_maxframes_(act, 3));
  56. }
  57. spritelist_free(list);
  58. sprite_free(sprite);
  59. TEST_DONE();
  60. }
  61. int main(void) {
  62. TEST_INIT();
  63. TEST_RUN(sprite);
  64. TEST_REPORT();
  65. }