test_utf8.c 821 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/**
* This is a test for utf8 in $package$
*/
#include "si_test.h"
#include "utf8.h"


TEST_FUNC(utf8) {
  char * strlist[] = { "", "u", "µ", "無"};
  long correct[] = { 0, 117, 181, 28961 };
  int index;
  long result;
  char * aid = NULL;
  for (index = 0; index < 4; index ++) { 
    TEST_INTEQ(index, utf8_decode_length(strlist[index]));
    TEST_INTEQ(index, utf8_decode_one(strlist[index], &result));
    TEST_INTEQ(result, correct[index]);
    TEST_INTEQ(index, utf8_next(strlist[index], &aid, &result));
    if (index > 0) { 
      TEST_INTEQ(result, correct[index]);
      TEST_PTREQ((void *)aid, (void *)(strlist[index] + index));
    } else {
      TEST_INTEQ(result, 0);
      TEST_NULL((void *)aid);      
   }
  }
  TEST_DONE();
}


int main(void) {
  TEST_INIT();
  TEST_RUN(utf8);
  TEST_REPORT();
}