1/*
2 * "$Id: testlang.c 11093 2013-07-03 20:48:42Z msweet $"
3 *
4 *   Localization test program for CUPS.
5 *
6 *   Copyright 2007-2010 by Apple Inc.
7 *   Copyright 1997-2006 by Easy Software Products.
8 *
9 *   These coded instructions, statements, and computer programs are the
10 *   property of Apple Inc. and are protected by Federal copyright
11 *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
12 *   which should have been included with this file.  If this file is
13 *   file is missing or damaged, see the license at "http://www.cups.org/".
14 *
15 *   This file is subject to the Apple OS-Developed Software exception.
16 *
17 * Contents:
18 *
19 *   main() - Load the specified language and show the strings for yes and no.
20 */
21
22/*
23 * Include necessary headers...
24 */
25
26#include "cups-private.h"
27
28
29/*
30 * 'main()' - Load the specified language and show the strings for yes and no.
31 */
32
33int					/* O - Exit status */
34main(int  argc,				/* I - Number of command-line arguments */
35     char *argv[])			/* I - Command-line arguments */
36{
37  int			i;		/* Looping var */
38  int			errors = 0;	/* Number of errors */
39  cups_lang_t		*language;	/* Message catalog */
40  cups_lang_t		*language2;	/* Message catalog */
41  struct lconv		*loc;		/* Locale data */
42  char			buffer[1024];	/* String buffer */
43  double		number;		/* Number */
44  static const char * const tests[] =	/* Test strings */
45  {
46    "1",
47    "-1",
48    "3",
49    "5.125"
50  };
51
52
53  _cupsSetLocale(argv);
54
55  if (argc == 1)
56  {
57    language  = cupsLangDefault();
58    language2 = cupsLangDefault();
59  }
60  else
61  {
62    language  = cupsLangGet(argv[1]);
63    language2 = cupsLangGet(argv[1]);
64  }
65
66  if (language != language2)
67  {
68    errors ++;
69
70    puts("**** ERROR: Language cache did not work! ****");
71    puts("First result from cupsLangGet:");
72  }
73
74  printf("Language = \"%s\"\n", language->language);
75  printf("Encoding = \"%s\"\n", _cupsEncodingName(language->encoding));
76  printf("No       = \"%s\"\n", _cupsLangString(language, "No"));
77  printf("Yes      = \"%s\"\n", _cupsLangString(language, "Yes"));
78
79  if (language != language2)
80  {
81    puts("Second result from cupsLangGet:");
82
83    printf("Language = \"%s\"\n", language2->language);
84    printf("Encoding = \"%s\"\n", _cupsEncodingName(language2->encoding));
85    printf("No       = \"%s\"\n", _cupsLangString(language2, "No"));
86    printf("Yes      = \"%s\"\n", _cupsLangString(language2, "Yes"));
87  }
88
89  loc = localeconv();
90
91  for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i ++)
92  {
93    number = _cupsStrScand(tests[i], NULL, loc);
94
95    printf("_cupsStrScand(\"%s\") number=%f\n", tests[i], number);
96
97    _cupsStrFormatd(buffer, buffer + sizeof(buffer), number, loc);
98
99    printf("_cupsStrFormatd(%f) buffer=\"%s\"\n", number, buffer);
100
101    if (strcmp(buffer, tests[i]))
102    {
103      errors ++;
104      puts("**** ERROR: Bad formatted number! ****");
105    }
106  }
107
108  return (errors > 0);
109}
110
111
112/*
113 * End of "$Id: testlang.c 11093 2013-07-03 20:48:42Z msweet $".
114 */
115