test_laytext.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * This is a test for laytext in $package$
  3. */
  4. #include <string.h>
  5. #include "si_test.h"
  6. #include "laytext.h"
  7. static int callback(char * str, int bytes, void * extra, float * w, float * h) {
  8. (*w) = 1.0 * bytes;
  9. (*h) = 1.0 * bytes;
  10. return bytes;
  11. }
  12. TEST_FUNC(laytext) {
  13. int index;
  14. long start;
  15. Dynar * result;
  16. long value = 0;
  17. int length;
  18. char * text = "Milennia have passed since mankind first traveled to the moon. "
  19. "Civilizations rose as never before, yet to fall again. "
  20. "When all hope seemed lost, the 21 trees sprouted from the earth. "
  21. "They brought mysterious powers that protected and strengthened mankind. "
  22. "Hello µ world, this is me, 無 life should be\nfun for everyone!";
  23. result = laytext_layout(text, 28.0, callback, NULL);
  24. for(index = 0; index < dynar_size(result); index++) {
  25. dynar_get_long(result, index, &value);
  26. printf("Layout: %d, %ld/%zd\n", index, value, strlen(text));
  27. }
  28. length = strlen(text);
  29. start = 0;
  30. for(index = 0; index < dynar_size(result); index++) {
  31. dynar_get_long(result, index, &value);
  32. if (value > 0) {
  33. printf("|%.*s|%d, %ld, %ld|\n", (int)(value - start), text+start, (int)(value - start), value, start);
  34. }
  35. start = value + 1;
  36. }
  37. printf("|%s|EOS|\n", text+start);
  38. dynar_free(result);
  39. TEST_DONE();
  40. }
  41. int main(void) {
  42. TEST_INIT();
  43. TEST_RUN(laytext);
  44. TEST_REPORT();
  45. }