Back to index

glibc  2.9
tst_swscanf.c
Go to the documentation of this file.
00001 /*
00002   SWSCANF: int swscanf (const wchar_t *ws, const wchar_t *fmt, ...);
00003 */
00004 
00005 #define TST_FUNCTION swscanf
00006 
00007 #include "tsp_common.c"
00008 #include "dat_swscanf.c"
00009 
00010 int
00011 tst_swscanf (FILE * fp, int debug_flg)
00012 {
00013   TST_DECL_VARS (int);
00014   wchar_t *ws;
00015   wchar_t *fmt;
00016   int val_int1;
00017   unsigned val_int2;
00018   float val_flt;
00019   char val_c;
00020   char val_s[MBSSIZE * 3];
00021   wchar_t val_S[WCSSIZE * 3], *exp_S;
00022   int i;
00023 
00024   TST_DO_TEST (swscanf)
00025   {
00026     TST_HEAD_LOCALE (swscanf, S_SWSCANF);
00027     TST_DO_REC (swscanf)
00028     {
00029       TST_GET_ERRET (swscanf);
00030       ws = TST_INPUT (swscanf).ws;
00031       fmt = TST_INPUT (swscanf).fmt;
00032       val_int1 = val_int2 = val_flt = val_c = 0;
00033       memset (val_s, 0, sizeof (val_s));
00034       memset (val_S, 0, sizeof (val_S));
00035 
00036       TST_CLEAR_ERRNO;
00037 
00038       if (TST_INPUT (swscanf).wch)
00039        {
00040          ret = swscanf (ws, fmt, val_S);
00041        }
00042       else
00043        {
00044          ret =
00045            swscanf (ws, fmt, &val_int1, &val_int2, &val_flt, &val_c, val_s);
00046        }
00047 
00048       TST_SAVE_ERRNO;
00049 
00050       if (debug_flg)
00051        {                    /* seems fprintf doesn't update errno */
00052          fprintf (stdout, "swscanf() [ %s : %d ] ret = %d\n", locale,
00053                  rec + 1, ret);
00054          fprintf (stdout, "                   errno   = %d\n",
00055                  errno_save);
00056          fprintf (stdout, "                   collate = %s\n",
00057                  (setlocale (LC_COLLATE, NULL)) ? setlocale (LC_COLLATE,
00058                                                         NULL) : "");
00059 
00060          if (TST_INPUT (swscanf).wch)
00061            {
00062              fprintf (stdout, "                  val_S[ 0 ] = 0x%lx\n",
00063                      (unsigned long int) val_S[0]);
00064            }
00065          else
00066            {
00067              fprintf (stdout, "                  val_int1   = %d\n",
00068                      val_int1);
00069              fprintf (stdout, "                  val_int2   = %d\n",
00070                      val_int2);
00071              fprintf (stdout, "                  val_flt          = %f\n",
00072                      val_flt);
00073              fprintf (stdout, "                  val_c     = %c\n",
00074                      val_c);
00075              fprintf (stdout, "                  val_s     = %s\n",
00076                      val_s);
00077            }
00078        }
00079 
00080       TST_IF_RETURN (S_SWSCANF)
00081       {
00082       };
00083 
00084       if (errno == 0 && TST_INPUT (swscanf).wch)
00085        {
00086          for (exp_S = TST_EXPECT (swscanf).val_S, i = 0; i < WCSSIZE * 3;
00087               i++)
00088            {
00089              if (val_S[i] == L'\0' || exp_S[i] == L'\0')
00090               {
00091                 if (val_S[i] != exp_S[i] && TST_INPUT (swscanf).wch == 'C')
00092                   {
00093                     err_count++;
00094                     Result (C_FAILURE, S_SWSCANF, CASE_4,
00095                            "the converted wide-char string is different"
00096                            " from an expected value.");
00097                   }
00098                 break;
00099               }
00100 
00101              if (val_S[i] != exp_S[i])
00102               {
00103                 err_count++;
00104                 Result (C_FAILURE, S_SWSCANF, CASE_4,
00105                        "the converted wide-char string is different from"
00106                        " an expected value.");
00107                 break;
00108               }
00109              else
00110               {
00111                 Result (C_SUCCESS, S_SWSCANF, CASE_4, MS_PASSED);
00112               }
00113            }
00114        }
00115 
00116       if (errno == 0 && !TST_INPUT (swscanf).wch)
00117        {
00118          if (val_int1 != TST_EXPECT (swscanf).val_int ||
00119              val_int2 != TST_EXPECT (swscanf).val_uns ||
00120              val_flt != TST_EXPECT (swscanf).val_flt ||
00121              val_c != TST_EXPECT (swscanf).val_c ||
00122              strcmp (val_s, TST_EXPECT (swscanf).val_s))
00123            {
00124              err_count++;
00125              Result (C_FAILURE, S_SWSCANF, CASE_3,
00126                     "the converted values are different from expected values.");
00127            }
00128          else
00129            {
00130              Result (C_SUCCESS, S_SWSCANF, CASE_3, MS_PASSED);
00131            }
00132        }
00133     }
00134   }
00135 
00136   return err_count;
00137 }