Print this page
4964 nl_langinfo(CRNCYSTR) returns wrong alignment character
4999 libc test suite enhancements
Reviewed by: Jason King <jason.brian.king@gmail.com>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Approved by: TBD

Split Close
Expand all
Collapse all
          --- old/usr/src/test/libc-tests/tests/newlocale/newlocale_test.c
          +++ new/usr/src/test/libc-tests/tests/newlocale/newlocale_test.c
↓ open down ↓ 50 lines elided ↑ open up ↑
  51   51  
  52   52  #define NUM_LDATA       5
  53   53  #define NUMTHR  20
  54   54  #define NUMITR  200
  55   55  
  56   56  static void
  57   57  test_start(const char *testName, const char *format, ...)
  58   58  {
  59   59          va_list args;
  60   60  
  61      -        (void) printf("TEST STARTING %s: ", testName);
       61 +        (void) printf("TEST STARTING %s (%s): ", testName, ARCH);
  62   62  
  63   63          va_start(args, format);
  64   64          (void) vprintf(format, args);
  65   65          va_end(args);
  66   66          (void) fflush(stdout);
  67   67  }
  68   68  
  69   69  static void
  70   70  test_failed(const char *testName, const char *format, ...)
  71   71  {
  72   72          va_list args;
  73   73  
  74      -        (void) printf("TEST FAILED %s: ", testName);
       74 +        (void) printf("TEST FAILED %s (%s): ", testName, ARCH);
  75   75  
  76   76          va_start(args, format);
  77   77          (void) vprintf(format, args);
  78   78          va_end(args);
       79 +        (void) printf("\n");
  79   80  
  80   81          (void) exit(-1);
  81   82  }
  82   83  
  83   84  static void
  84   85  test_passed(const char *testName)
  85   86  {
  86      -        (void) printf("TEST PASS: %s\n", testName);
       87 +        (void) printf("TEST PASS: %s (%s)\n", testName, ARCH);
  87   88          (void) fflush(stdout);
  88   89  }
  89   90  
  90   91  void *
  91      -testlocale_thr(void *ptr)
       92 +testlocale_thr_one(void *ptr)
  92   93  {
  93   94          locale_t        cloc, loc;
  94   95          struct lconv    *lc;
  95   96          char            *day;
  96   97          char            *tname = ptr;
  97   98  
  98   99          for (int i = 0; i < NUMITR; i++) {
  99  100                  struct ldata *l = &ldata[i % NUM_LDATA];
 100  101                  cloc = uselocale(NULL);
 101  102  
↓ open down ↓ 47 lines elided ↑ open up ↑
 149  150                  freelocale(loc);
 150  151                  if (uselocale(LC_GLOBAL_LOCALE) != cloc) {
 151  152                          test_failed(tname, "revert GLOBAL_LOCALE mismatch");
 152  153                  }
 153  154          }
 154  155          return (NULL);
 155  156  }
 156  157  
 157  158  
 158  159  void
 159      -testlocale(void)
      160 +test_newlocale_threaded(void)
 160  161  {
 161      -        char            *tname = "newlocale/uselocale";
      162 +        char            *tname = "newlocale_threaded";
 162  163          pthread_t       tid[NUMTHR];
 163  164  
 164  165          test_start(tname, "running %d threads %d iterations\n", NUMTHR, NUMITR);
 165  166  
 166  167          for (int i = 0; i < NUMTHR; i++) {
 167      -                (void) pthread_create(&tid[i], NULL, testlocale_thr, tname);
      168 +                (void) pthread_create(&tid[i], NULL, testlocale_thr_one, tname);
 168  169          }
 169  170  
 170  171          for (int i = 0; i < NUMTHR; i++) {
 171  172                  (void) pthread_join(tid[i], NULL);
 172  173          }
 173  174          test_passed(tname);
 174  175  }
 175  176  
      177 +void
      178 +test_newlocale_negative(void)
      179 +{
      180 +        
      181 +        locale_t loc, bad;
      182 +        char *day;
      183 +        char *tname = "newlocale_negative";
      184 +
      185 +        test_start(tname, "verify proper failure handling\n");
      186 +        loc = newlocale(LC_ALL_MASK, "de_DE.UTF-8", NULL);
      187 +        if (loc == NULL) {
      188 +                test_failed(tname, "cannot set de_DE.UTF-8");
      189 +        }
      190 +        day = nl_langinfo_l(DAY_1, loc);
      191 +        if (strcmp(day, "Sonntag") != 0) {
      192 +                test_failed(tname, "incorrect Sonntag != %s", day);
      193 +        }
      194 +
      195 +        bad = newlocale(LC_ALL_MASK, "cn_US.BIZRRE", loc);
      196 +        if (bad != NULL) {
      197 +                test_failed(tname, "passed setting bogus locale");
      198 +        }
      199 +        day = nl_langinfo_l(DAY_1, loc);
      200 +        if (strcmp(day, "Sonntag") != 0) {
      201 +                test_failed(tname, "incorrect Sonntag != %s", day);
      202 +        }
      203 +        test_passed(tname);
      204 +}
      205 +
      206 +void
      207 +test_newlocale_categories(void)
      208 +{
      209 +        locale_t loc;
      210 +        char *day, *cur, *yes;
      211 +        char *tname = "newlocale_categories";
      212 +
      213 +        test_start(tname, "verify different category behavior\n");
      214 +
      215 +        loc = NULL;
      216 +        loc = newlocale(LC_TIME_MASK, "de_DE.UTF-8", loc);
      217 +        loc = newlocale(LC_MESSAGES_MASK, "ru_RU.UTF-8", loc);
      218 +        loc = newlocale(LC_MONETARY_MASK, "en_US.UTF-8", loc);
      219 +
      220 +        if (loc == NULL) {
      221 +                test_failed(tname, "failed to set locale");
      222 +        }
      223 +
      224 +        day = nl_langinfo_l(DAY_1, loc);
      225 +        if ((day == NULL) || (strcmp(day, "Sonntag") != 0)) {
      226 +                test_failed(tname, "day1 mismatch %s != %s", day, "Sonntag");
      227 +        }
      228 +        yes = nl_langinfo_l(YESSTR, loc);
      229 +        if ((yes == NULL) || (strcmp(yes, "да") != 0)) {
      230 +                test_failed(tname, "currency mismatch");
      231 +        }
      232 +        cur = nl_langinfo_l(CRNCYSTR, loc);
      233 +        if ((cur == NULL) || (strcmp(cur, "-$") != 0)) {
      234 +                test_failed(tname, "currency mismatch [%s] != [%s]", cur, "-$");
      235 +        }
      236 +
      237 +        test_passed(tname);
      238 +}
      239 +
      240 +void
      241 +test_newlocale_composite(void)
      242 +{
      243 +        locale_t loc;
      244 +        char *day, *cur, *yes;
      245 +        char *tname = "newlocale_composite";
      246 +
      247 +        test_start(tname, "verify composite locale behavior\n");
      248 +
      249 +        /* order: CTYPE/NUMERIC/TIME/COLLATE/MONETARY/MESSAGES */
      250 +        loc = newlocale(LC_ALL_MASK,
      251 +            "C/C/de_DE.UTF-8/C/en_US.UTF-8/ru_RU.UTF-8", NULL);
      252 +
      253 +        if (loc == NULL) {
      254 +                test_failed(tname, "failed to set composite locale");
      255 +        }
      256 +
      257 +        day = nl_langinfo_l(DAY_1, loc);
      258 +        if ((day == NULL) || (strcmp(day, "Sonntag") != 0)) {
      259 +                test_failed(tname, "day1 mismatch %s != %s", day, "Sonntag");
      260 +        }
      261 +        yes = nl_langinfo_l(YESSTR, loc);
      262 +        if ((yes == NULL) || (strcmp(yes, "да") != 0)) {
      263 +                test_failed(tname, "currency mismatch");
      264 +        }
      265 +        cur = nl_langinfo_l(CRNCYSTR, loc);
      266 +        if ((cur == NULL) || (strcmp(cur, "-$") != 0)) {
      267 +                test_failed(tname, "currency mismatch [%s] != [%s]", cur, "-$");
      268 +        }
      269 +
      270 +        test_passed(tname);
      271 +}
      272 +
 176  273  int
 177  274  main(int argc, char **argv)
 178  275  {
 179  276          int optc;
 180  277  
 181  278          while ((optc = getopt(argc, argv, "d")) != EOF) {
 182  279                  switch (optc) {
 183  280                  case 'd':
 184  281                          debug++;
 185  282                          break;
 186  283                  default:
 187  284                          (void) fprintf(stderr, "Usage: %s [-d]\n", argv[0]);
 188  285                          exit(1);
 189  286                  }
 190  287          }
 191  288  
 192      -        testlocale();
      289 +        test_newlocale_threaded();
      290 +        test_newlocale_negative();
      291 +        test_newlocale_categories();
      292 +        test_newlocale_composite();
 193  293  
 194  294          exit(0);
 195  295  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX