Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
0.locale.cpp
Go to the documentation of this file.
1
29#include <cstdio> // for remove()
30#include <cstdlib> // for getenv()
31
32#include <rw_environ.h> // for rw_putenv()
33#include <rw_file.h> // for rw_fwrite()
34#include <rw_driver.h> // for rw_test(), etc.
35#include <rw_locale.h> // for rw_localedef()
36#include <rw_printf.h> // for rw_fprintf()
37
38
40static int
41test_localedef ()
42{
43 // the root of the locale directory (RWSTD_LOCALE_ROOT)
44 static const char* const locale_root = rw_set_locale_root ();
45
46 static int inx;
47
48 const int id = inx++;
49
50 // create a temporary locale definition file
51 char srcfname [1024];
52 if (rw_snprintf (srcfname, sizeof srcfname, "%s%c%s.%d",
53 locale_root, _RWSTD_PATH_SEP, "locale", id) < 0)
54 return -1;
55
56 // create a temporary character map file
57 char cmfname [1024];
58 if (rw_snprintf (cmfname, sizeof cmfname, "%s%c%s.%d.src",
59 locale_root, _RWSTD_PATH_SEP, "charmap", id) < 0)
60 return -1;
61
62 rw_fwrite (srcfname, "LC_CTYPE\nEND LC_CTYPE\n");
63 rw_fwrite (cmfname, "CHARMAP\nEND CHARMAP\n");
64
65 const char opts[] = "-w";
66 char locname[40];
67 rw_snprintf (locname, sizeof locname, "%s.%d", "locale", id);
68
69 // try to create the locale
70 const char* const ret =
71 rw_localedef (opts, srcfname, cmfname, locname);
72
73 const char* const topdir = std::getenv ("TOPDIR");
74
75 rw_assert (0 != ret, 0, __LINE__,
76 "rw_localedef(%s, %#s, %#s, %#s) failed with TOPDIR=%#s",
77 opts, srcfname, cmfname, locname, topdir);
78
79 // remove temporary files
80 std::remove (cmfname);
81 std::remove (srcfname);
82
83 return 0;
84}
85
86
88static int
89run_test (int, char*[])
90{
91 // exercise with the default setting of TOPDIR
92 rw_error (0 == test_localedef (), 0, __LINE__, "");
93
94 // exercise with TOPDIR set but empty
95 rw_putenv ("TOPDIR=");
96 rw_error (0 == test_localedef (), 0, __LINE__, "");
97
98 // exercise with TOPDIR unset
99 rw_putenv ("TOPDIR");
100 rw_error (0 == test_localedef (), 0, __LINE__, "");
101
102 return 0;
103}
104
105
107int main (int argc, char *argv[])
108{
109 return rw_test (argc, argv, __FILE__,
110 0 /* no section */,
111 0 /* no comment */,
112 run_test,
113 "",
114 0);
115}
#define inx
Definition 17.names.cpp:484
const char * locale_root
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define main
#define _RWSTD_PATH_SEP
Definition _config.h:297
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
_TEST_EXPORT int rw_error(int, const char *, int, const char *,...)
Definition driver.cpp:1613
_TEST_EXPORT int rw_putenv(const char *, int=-1)
Definition environ.cpp:69
_TEST_EXPORT _RWSTD_SIZE_T rw_fwrite(const char *, const void *, _RWSTD_SIZE_T=~0, const char *="w")
_TEST_EXPORT const char * rw_set_locale_root()
Definition locale.cpp:324
_TEST_EXPORT const char * rw_localedef(const char *, const char *, const char *, const char *)
Definition locale.cpp:154
_TEST_EXPORT int rw_snprintf(char *, _RWSTD_SIZE_T, const char *,...)