2
0

fwide.c 848 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <wchar.h>
  4. int test_initial_orientation(void) {
  5. FILE *f = tmpfile();
  6. assert(fwide(f, 0) == 0);
  7. return 0;
  8. }
  9. int test_manual_byte_orientation(void) {
  10. FILE *f = tmpfile();
  11. // set manually to byte orientation
  12. assert(fwide(f, -483) == -1);
  13. // Cannot change to wchar orientation
  14. assert(fwide(f, 1) == -1);
  15. fclose(f);
  16. return 0;
  17. }
  18. int test_manual_wchar_orientation(void) {
  19. FILE *f = tmpfile();
  20. // set manually to wchar orientation
  21. assert(fwide(f, 483) == 1);
  22. // Cannot change to byte orientation
  23. assert(fwide(f, -1) == 1);
  24. fclose(f);
  25. return 0;
  26. }
  27. int main() {
  28. int(*tests[])(void) = {
  29. &test_initial_orientation,
  30. &test_manual_byte_orientation,
  31. &test_manual_wchar_orientation,
  32. };
  33. for(int i=0; i<sizeof(tests)/sizeof(int(*)(void)); i++) {
  34. printf("%d\n", (*tests[i])());
  35. }
  36. }