tst-sscanf.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <stdio.h>
  2. #include <locale.h>
  3. #include <assert.h>
  4. #define P0 "\xDB\xB0"
  5. #define P1 "\xDB\xB1"
  6. #define P2 "\xDB\xB2"
  7. #define P3 "\xDB\xB3"
  8. #define P4 "\xDB\xB4"
  9. #define P5 "\xDB\xB5"
  10. #define P6 "\xDB\xB6"
  11. #define P7 "\xDB\xB7"
  12. #define P8 "\xDB\xB8"
  13. #define P9 "\xDB\xB9"
  14. #define PD "\xd9\xab"
  15. #define PT "\xd9\xac"
  16. static int
  17. check_sscanf (const char *s, const char *format, const float n)
  18. {
  19. float f;
  20. if (sscanf (s, format, &f) != 1)
  21. {
  22. printf ("nothing found for \"%s\"\n", s);
  23. return 1;
  24. }
  25. if (f != n)
  26. {
  27. printf ("got %f expected %f from \"%s\"\n", f, n, s);
  28. return 1;
  29. }
  30. return 0;
  31. }
  32. static int
  33. do_test (void)
  34. {
  35. if (setlocale (LC_ALL, "fa_IR.UTF-8") == NULL)
  36. {
  37. puts ("cannot set fa_IR locale");
  38. return 1;
  39. }
  40. int r = check_sscanf (P3 PD P1 P4, "%I8f", 3.14);
  41. r |= check_sscanf (P3 PT P1 P4 P5, "%I'f", 3145);
  42. r |= check_sscanf (P3 PD P1 P4 P1 P5 P9, "%If", 3.14159);
  43. r |= check_sscanf ("-" P3 PD P1 P4 P1 P5, "%If", -3.1415);
  44. r |= check_sscanf ("+" PD P1 P4 P1 P5, "%If", +.1415);
  45. r |= check_sscanf (P3 PD P1 P4 P1 P5 "e+" P2, "%Ie", 3.1415e+2);
  46. return r;
  47. }
  48. #define TEST_FUNCTION do_test ()
  49. #include "../test-skeleton.c"