test_utf8.c 821 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * This is a test for utf8 in $package$
  3. */
  4. #include "si_test.h"
  5. #include "utf8.h"
  6. TEST_FUNC(utf8) {
  7. char * strlist[] = { "", "u", "µ", "無"};
  8. long correct[] = { 0, 117, 181, 28961 };
  9. int index;
  10. long result;
  11. char * aid = NULL;
  12. for (index = 0; index < 4; index ++) {
  13. TEST_INTEQ(index, utf8_decode_length(strlist[index]));
  14. TEST_INTEQ(index, utf8_decode_one(strlist[index], &result));
  15. TEST_INTEQ(result, correct[index]);
  16. TEST_INTEQ(index, utf8_next(strlist[index], &aid, &result));
  17. if (index > 0) {
  18. TEST_INTEQ(result, correct[index]);
  19. TEST_PTREQ((void *)aid, (void *)(strlist[index] + index));
  20. } else {
  21. TEST_INTEQ(result, 0);
  22. TEST_NULL((void *)aid);
  23. }
  24. }
  25. TEST_DONE();
  26. }
  27. int main(void) {
  28. TEST_INIT();
  29. TEST_RUN(utf8);
  30. TEST_REPORT();
  31. }