Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
22.locale.codecvt.cpp File Reference
#include <locale>
#include <cassert>
#include <climits>
#include <clocale>
#include <csetjmp>
#include <csignal>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cwchar>
#include <sys/types.h>
#include <sys/stat.h>
#include <iconv.h>
#include <langinfo.h>
#include <unistd.h>
#include <rw_driver.h>
#include <rw_file.h>
#include <rw_locale.h>
Include dependency graph for 22.locale.codecvt.cpp:

Go to the source code of this file.

Data Structures

struct  TypeName< T >
 
struct  CodecvtDerived< Base >
 

Macros

#define DEFINE_REPLACEMENT_NEW_AND_DELETE
 
#define PATH_MAX   1024
 
#define min(a, b)   ((a) < (b) ? (a) : (b))
 
#define CCVT_MAX_LOCALE   5
 
#define CCVT_MB_CUR_MIN   1
 
#define CCVT_MB_CUR_MAX   6
 
#define TEST(resultT, result, fname, args)
 
#define TEST(resultT, result, fname, args)
 
#define DO_TEST(io, src, ext_len, ext_num, dst, int_len, int_num, res)
 
#define TEST_IN(src, ext_len, ext_num, dst, int_len, int_num, res)    DO_TEST ('I', src, ext_len, ext_num, dst, int_len, int_num, res)
 
#define TEST_OUT(src, ext_len, ext_num, dst, int_len, int_num, res)    DO_TEST ('O', src, ext_len, ext_num, dst, int_len, int_num, res)
 
#define TEST_IN_OUT(src, ext_len, ext_num, dst, int_len, int_num, res)    DO_TEST ('i', src, ext_len, ext_num, dst, int_len, int_num, res)
 
#define TEST_OUT_IN(src, ext_len, ext_num, dst, int_len, int_num, res)    DO_TEST ('o', src, ext_len, ext_num, dst, int_len, int_num, res)
 
#define TEST_UCS_MODIFIER(T, mod, enc, locname, f, i, is)
 
#define TEST_LIBSTD(L, T, C, c, f, s, i, is, o, os, ur, ar, er, lr, mr)
 
#define TEST_CONVERSION(T, L, C, f, s, i, is, o, os, ur, er, ar, lr, mr)
 
#define TESTS_ETC_PATH   "tests" SLASH "etc"
 

Typedefs

typedef std::codecvt_base::result CodecvtResult
 
typedef std::codecvt< char, char, std::mbstate_t > Codecvt
 
typedef std::codecvt_byname< char, char, std::mbstate_t > CodecvtBn
 
typedef std::codecvt< wchar_t, char, std::mbstate_t > CodecvtW
 
typedef std::codecvt_byname< wchar_t, char, std::mbstate_t > CodecvtBnW
 

Enumerations

enum  {
  dtor = 1 << 0 , do_out = 1 << 1 , do_in = 1 << 2 , do_unshift = 1 << 3 ,
  do_encoding = 1 << 4 , do_always_noconv = 1 << 5 , do_length = 1 << 6 , do_max_length = 1 << 7
}
 
enum  InternalEncoding { use_libc , use_UCS4 , use_UCS2 }
 

Functions

template<class T >
std::size_t rwtest_mbstowcs (std::mbstate_t &state, T *pi, const char *pe, std::size_t srclen)
 
_RWSTD_SPECIALIZED_FUNCTION std::size_t rwtest_mbstowcs< char > (std::mbstate_t &, char *, const char *, std::size_t)
 
template<class charT >
std::size_t rwtest_wcstombs (std::mbstate_t &state, const charT *pi, char *pe, std::size_t srclen)
 
_RWSTD_SPECIALIZED_FUNCTION std::size_t rwtest_wcstombs< char > (std::mbstate_t &, const char *, char *, std::size_t)
 
const Codecvt & create_Codecvt (const std::locale &)
 
const CodecvtBn & create_CodecvtBn (const std::locale &loc)
 
const CodecvtW & create_CodecvtW (const std::locale &)
 
const CodecvtBnW & create_CodecvtBnW (const std::locale &loc)
 
void SIGABRT_handler (int)
 
int main (int argc, char *argv[])
 

Variables

int call = 0
 
std::jmp_buf jmp_env
 
const char * locale_root
 
const char ext_ascii []
 

Macro Definition Documentation

◆ CCVT_MAX_LOCALE

#define CCVT_MAX_LOCALE   5

Definition at line 511 of file 22.locale.codecvt.cpp.

◆ CCVT_MB_CUR_MAX

#define CCVT_MB_CUR_MAX   6

Definition at line 513 of file 22.locale.codecvt.cpp.

◆ CCVT_MB_CUR_MIN

#define CCVT_MB_CUR_MIN   1

Definition at line 512 of file 22.locale.codecvt.cpp.

◆ DEFINE_REPLACEMENT_NEW_AND_DELETE

#define DEFINE_REPLACEMENT_NEW_AND_DELETE

22.locale.codecvt.cpp - test exercising the std::codecvt<> facets

$Id$

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 1994-2008 Rogue Wave Software.

Definition at line 57 of file 22.locale.codecvt.cpp.

◆ DO_TEST

#define DO_TEST (   io,
  src,
  ext_len,
  ext_num,
  dst,
  int_len,
  int_num,
  res 
)
Value:
test_inout (io, __LINE__, locname, src, ext_len, ext_num, \
dst, int_len, int_num, res)
#define res
Definition 17.names.cpp:531

◆ min

#define min (   a,
  b 
)    ((a) < (b) ? (a) : (b))

Definition at line 68 of file 22.locale.codecvt.cpp.

◆ PATH_MAX

#define PATH_MAX   1024

Definition at line 63 of file 22.locale.codecvt.cpp.

◆ TEST [1/2]

#define TEST (   resultT,
  result,
  fname,
  args 
)
Value:
if (0 == setjmp (jmp_env)) { \
std::signal (SIGABRT, SIGABRT_handler); \
const resultT res = cvt.fname args; \
rw_assert (!expect_abort && result == res, __FILE__, __LINE__, \
"%s::%s (state_type&, ...) failed to " \
"detect an invalid state argument", \
} else \
rw_assert (expect_abort, __FILE__, __LINE__, \
"%s::%s (state_type&, ...) called abort() instead " \
"of gracefully indicating an invalid state argument", \
int expect_abort
volatile int result
std::jmp_buf jmp_env
void SIGABRT_handler(int)
#define setjmp
Definition _csetjmp.h:52
#define SIGABRT

◆ TEST [2/2]

#define TEST (   resultT,
  result,
  fname,
  args 
)
Value:
if (0 == setjmp (jmp_env)) { \
std::signal (SIGABRT, SIGABRT_handler); \
const resultT res = cvt.fname args; \
rw_assert (result == res, __FILE__, __LINE__, \
"%s::%s (state_type&, (char_type*)0, ...) == %s, " \
"got %s (NULL pointer test)", \
rwtest_codecvt_result (result), \
rwtest_codecvt_result (res)); \
} else \
rw_assert (expect_abort, __FILE__, __LINE__, \
"%s::%s (state_type&, (char_type*)0, ...) " \
"unexpectedly called abort() (NULL pointer test)", \

◆ TEST_CONVERSION

#define TEST_CONVERSION (   T,
  L,
  C,
  f,
  s,
  i,
  is,
  o,
  os,
  ur,
  er,
  ar,
  lr,
  mr 
)
Value:
do { \
std::locale loc; \
_TRY { \
loc = std::locale (L); \
} _CATCH (...) { \
rw_assert (false, __FILE__, __LINE__, \
"locale(\"%s\") unexpectedly threw an " \
"exception; " LOCALE_ROOT_ENVAR " = %s", L, \
break; \
} \
_TRY { \
const T &cc = create_##T (loc); \
\
cc._C_opts |= cc._C_use_libstd; \
cc._C_opts &= ~cc._C_use_libc; \
TEST_LIBSTD (L,T,C,cc,f,s,i,is,o,os,ur,ar,er,lr,mr); \
\
if (C == true && rwtest_is_C_locale (f)) { \
cc._C_opts &= ~cc._C_use_libstd; \
cc._C_opts |= cc._C_use_libc; \
TEST_LIBSTD(L,T,C,cc,f,s,i,is,o,os,ur,ar,er,lr,mr); \
} \
} _CATCH (...) { \
rw_assert (false, __FILE__, __LINE__, \
"unexpected exception in locale test %s", L); \
} \
} while (0)
#define i
Definition 17.names.cpp:126
#define T
Definition 17.names.cpp:163
#define os
Definition 17.names.cpp:511
#define loc
Definition 17.names.cpp:492
#define f
Definition 17.names.cpp:119
#define s
#define o
Definition 17.names.cpp:131
const char * locale_root
#define _TRY
Definition _defs.h:850
#define _CATCH(ex)
Definition _defs.h:851
#define LOCALE_ROOT_ENVAR
Definition rw_locale.h:57

◆ TEST_IN

#define TEST_IN (   src,
  ext_len,
  ext_num,
  dst,
  int_len,
  int_num,
  res 
)     DO_TEST ('I', src, ext_len, ext_num, dst, int_len, int_num, res)

◆ TEST_IN_OUT

#define TEST_IN_OUT (   src,
  ext_len,
  ext_num,
  dst,
  int_len,
  int_num,
  res 
)     DO_TEST ('i', src, ext_len, ext_num, dst, int_len, int_num, res)

◆ TEST_LIBSTD

#define TEST_LIBSTD (   L,
  T,
  C,
  c,
  f,
  s,
  i,
  is,
  o,
  os,
  ur,
  ar,
  er,
  lr,
  mr 
)
Value:
_TRY { \
test_libstd_codecvt<T>(L,c,f,s,i,is,o,os,ur,ar,er,lr,mr); \
} _CATCH (...) { \
rw_assert (false, __FILE__, __LINE__, \
"unexpected exception in conversion using %s " \
"(locale %s)", C ? "C library" : "std library", L); \
}
#define c
Definition 17.names.cpp:111

◆ TEST_OUT

#define TEST_OUT (   src,
  ext_len,
  ext_num,
  dst,
  int_len,
  int_num,
  res 
)     DO_TEST ('O', src, ext_len, ext_num, dst, int_len, int_num, res)

◆ TEST_OUT_IN

#define TEST_OUT_IN (   src,
  ext_len,
  ext_num,
  dst,
  int_len,
  int_num,
  res 
)     DO_TEST ('o', src, ext_len, ext_num, dst, int_len, int_num, res)

◆ TEST_UCS_MODIFIER

#define TEST_UCS_MODIFIER (   T,
  mod,
  enc,
  locname,
  f,
  i,
  is 
)
Value:
do { \
char locname_mod [256]; /* <locale-name>@<modifier>*/ \
if (*(mod)) \
std::sprintf (locname_mod, "%s@%s", locname, (mod)); \
else \
std::sprintf (locname_mod, "%s", locname); \
\
_TRY { \
const CodecvtBnW cc (locname_mod, 1); \
std::locale loc = std::locale (std::locale::classic (), &cc); \
\
cc._C_opts |= cc._C_use_libstd; \
cc._C_opts &= ~cc._C_use_libc; \
test_ucs_modifier (locname_mod, enc, s, cc, f, i, is); \
\
} _CATCH (...) { \
rw_assert (false, __FILE__, __LINE__, \
"unexpected exception in locale test %s", \
locname_mod); \
} \
} while (0)
std::codecvt_byname< wchar_t, char, std::mbstate_t > CodecvtBnW

◆ TESTS_ETC_PATH

#define TESTS_ETC_PATH   "tests" SLASH "etc"

Typedef Documentation

◆ Codecvt

typedef std::codecvt<char,char,std::mbstate_t> Codecvt

Definition at line 165 of file 22.locale.codecvt.cpp.

◆ CodecvtBn

typedef std::codecvt_byname<char,char,std::mbstate_t> CodecvtBn

Definition at line 166 of file 22.locale.codecvt.cpp.

◆ CodecvtBnW

typedef std::codecvt_byname<wchar_t,char,std::mbstate_t> CodecvtBnW

Definition at line 170 of file 22.locale.codecvt.cpp.

◆ CodecvtResult

Definition at line 164 of file 22.locale.codecvt.cpp.

◆ CodecvtW

typedef std::codecvt<wchar_t,char,std::mbstate_t> CodecvtW

Definition at line 169 of file 22.locale.codecvt.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
dtor 
do_out 
do_in 
do_unshift 
do_encoding 
do_always_noconv 
do_length 
do_max_length 

Definition at line 207 of file 22.locale.codecvt.cpp.

◆ InternalEncoding

Enumerator
use_libc 
use_UCS4 
use_UCS2 

Definition at line 914 of file 22.locale.codecvt.cpp.

Function Documentation

◆ create_Codecvt()

const Codecvt & create_Codecvt ( const std::locale &  )

Definition at line 361 of file 22.locale.codecvt.cpp.

◆ create_CodecvtBn()

const CodecvtBn & create_CodecvtBn ( const std::locale &  loc)

Definition at line 367 of file 22.locale.codecvt.cpp.

◆ create_CodecvtBnW()

const CodecvtBnW & create_CodecvtBnW ( const std::locale &  loc)

Definition at line 380 of file 22.locale.codecvt.cpp.

◆ create_CodecvtW()

const CodecvtW & create_CodecvtW ( const std::locale &  )

Definition at line 374 of file 22.locale.codecvt.cpp.

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 2603 of file 22.locale.codecvt.cpp.

◆ rwtest_mbstowcs()

template<class T >
std::size_t rwtest_mbstowcs ( std::mbstate_t &  state,
T *  pi,
const char *  pe,
std::size_t  srclen 
)

Definition at line 77 of file 22.locale.codecvt.cpp.

◆ rwtest_mbstowcs< char >()

_RWSTD_SPECIALIZED_FUNCTION std::size_t rwtest_mbstowcs< char > ( std::mbstate_t &  ,
char *  ,
const char *  ,
std::size_t   
)

Definition at line 94 of file 22.locale.codecvt.cpp.

◆ rwtest_wcstombs()

template<class charT >
std::size_t rwtest_wcstombs ( std::mbstate_t &  state,
const charT *  pi,
char *  pe,
std::size_t  srclen 
)
inline

Definition at line 103 of file 22.locale.codecvt.cpp.

◆ rwtest_wcstombs< char >()

_RWSTD_SPECIALIZED_FUNCTION std::size_t rwtest_wcstombs< char > ( std::mbstate_t &  ,
const char *  ,
char *  ,
std::size_t   
)
inline

Definition at line 119 of file 22.locale.codecvt.cpp.

◆ SIGABRT_handler()

void SIGABRT_handler ( int  )

Definition at line 1161 of file 22.locale.codecvt.cpp.

Variable Documentation

◆ call

int call = 0

Definition at line 219 of file 22.locale.codecvt.cpp.

◆ ext_ascii

const char ext_ascii[]
Initial value:
= {
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f"
"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f"
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f"
"\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f"
"\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f"
"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
"\x90\x91\x92\x93\x94\x95\x96\x97\x89\x99\x9a\x9b\x9c\x9d\x9e\x9f"
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"
"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
}

Definition at line 1849 of file 22.locale.codecvt.cpp.

◆ jmp_env

std::jmp_buf jmp_env

Definition at line 1157 of file 22.locale.codecvt.cpp.

◆ locale_root

const char* locale_root

Definition at line 1648 of file 22.locale.codecvt.cpp.