STLdoc
STLdocumentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Macros | Typedefs | Functions
xtest File Reference
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <cvt/wbuffer>
#include <cvt/wstring>

Macros

#define _CVT_XTEST_
 
#define CHECK(x)
 
#define CHECK_INT(x, y)
 
#define CHECK_MSG(msg, ok)
 
#define NCHARS   0x100
 
#define MYWCHAR   wchar_t
 
#define Mywchar   MYWCHAR
 
#define MYWCMAX   0xffff
 

Typedefs

typedef basic_istream< MYWCHARMyistream
 
typedef basic_ostream< MYWCHARMyostream
 
typedef basic_string< MYWCHARMystring
 
typedef stdext::cvt::wstring_convert< MYNAME, MYWCHARMysconvert
 
typedef basic_filebuf< charMybfilebuf
 

Functions

int leave_chk (const char *fname)
 
bool test_write (const char *fname, const Mystring &mystring)
 
bool test_read (const char *fname, const Mystring &mystring)
 
void test_other ()
 
int main ()
 

Macro Definition Documentation

#define _CVT_XTEST_
#define CHECK (   x)
#define CHECK_INT (   x,
 
)
#define CHECK_MSG (   msg,
  ok 
)
#define MYWCHAR   wchar_t
#define Mywchar   MYWCHAR
#define MYWCMAX   0xffff
#define NCHARS   0x100

Typedef Documentation

Function Documentation

int leave_chk ( const char fname)
33  { // display message and quit
34  cout << "#PASSED: " << fname << endl;
35  return (0);
36  }
basic_ostream< _Elem, _Traits > &__CLRCALL_OR_CDECL endl(basic_ostream< _Elem, _Traits > &_Ostr)
Definition: ostream:982
__PURE_APPDOMAIN_GLOBAL _CRTDATA2 ostream cout
int main ( )
156  { // write a file and read it back
157  const char *fname = "testfile.txt";
158  Mystring mystring;
159 
160  #if defined(MYMAKE)
161  mystring = MYMAKE();
162 
163  #else /* defined(MYMAKE) */
164  Mysconvert myconv(""); // don't throw on bad codes
165 
166  for (unsigned long ch = 0;
167  ch <= MYWC_MAX && mystring.size() < NCHARS; ++ch)
168  { // add a wide character if valid
169  string buf = myconv.to_bytes((MYWCHAR)ch);
170  if (0 < buf.size() && ch != (unsigned long)WEOF)
171  mystring.insert(mystring.end(), (MYWCHAR)ch);
172  }
173  #endif /* defined(MYMAKE) */
174 
175  if (test_write(fname, mystring))
176  test_read(fname, mystring);
177  remove(fname);
178 
179  test_other();
180 
181  cout << "FINISHED testing \"cvt/"
182  << MYFILE << "\"" << endl;
183  return (leave_chk(MYFILE ".cpp"));
184  }
basic_string< MYWCHAR > Mystring
Definition: xtest:54
_In_ long
Definition: corecrt_wstdlib.h:88
basic_ostream< _Elem, _Traits > &__CLRCALL_OR_CDECL endl(basic_ostream< _Elem, _Traits > &_Ostr)
Definition: ostream:982
#define NCHARS
Definition: xtest:40
bool test_read(const char *fname, const Mystring &mystring)
Definition: xtest:94
void test_other()
Definition: xtest:138
Definition: wstring:23
__PURE_APPDOMAIN_GLOBAL _CRTDATA2 ostream cout
#define MYWCHAR
Definition: xtest:44
bool test_write(const char *fname, const Mystring &mystring)
Definition: xtest:59
#define WEOF
Definition: corecrt_wconio.h:18
int leave_chk(const char *fname)
Definition: xtest:32
void test_other ( )
139  { // test other codecvt member functions
140  MYNAME *p = new MYNAME;
141 
142  CHECK(!p->always_noconv());
143  CHECK(0 < p->max_length());
144  CHECK(-1 <= p->encoding() && p->encoding() <= p->max_length());
145 
146  const char arr[] = "ab";
147  static mbstate_t state0;
148  mbstate_t state = state0;
149  int len = p->length(state, &arr[0], &arr[2], 2 * p->max_length());
150  CHECK(0 <= len && len <= 2 * p->max_length());
151 
152  delete p;
153  }
_Mbstatet mbstate_t
Definition: corecrt.h:503
#define CHECK(x)
Definition: xtest:28
bool test_read ( const char fname,
const Mystring mystring 
)
95  { // read sequences of wide chars from file
96  Mybfilebuf mybbuf;
97 
98  mybbuf.open(fname, ios_base::binary | ios_base::in);
99  if (!mybbuf.is_open())
100  { // open failed, give up
101  #ifndef TERSE
102  cout << "can't read from " << fname << endl;
103  #endif /* TERSE */
104 
105  CHECK_MSG("can't open file for reading", 0);
106  return (false);
107  }
108 
110  Myistream mystr(&mybuf);
111 
112  MYWCHAR ch;
113  for (size_t idx = 0; idx < mystring.size(); ++idx)
114  { // read a wide char and test for expected value
115  ch = (MYWCHAR)(-1);
116  if (mystr.read(&ch, 1) && ch == mystring[idx])
117  CHECK(1);
118  else
119  { // read failed, quit
120  #ifndef TERSE
121  cout << hex
122  << "read failed for " << (unsigned long)mystring[idx]
123  << ", got " << (unsigned long)ch << endl;
124  #endif /* TERSE */
125 
126  CHECK_INT((int)idx, -1);
127  return (false);
128  }
129  }
130  if (mystr.read(&ch, 1))
131  { // read too much, complain
132  CHECK_MSG("end of file not reached", 0);
133  return (false);
134  }
135  return (true);
136  }
ios_base &__CLRCALL_OR_CDECL hex(ios_base &_Iosbase)
Definition: ios:236
_In_ long
Definition: corecrt_wstdlib.h:88
#define CHECK_MSG(msg, ok)
Definition: xtest:30
basic_istream< MYWCHAR > Myistream
Definition: xtest:52
static constexpr _Openmode binary
Definition: xiosbase:102
basic_ostream< _Elem, _Traits > &__CLRCALL_OR_CDECL endl(basic_ostream< _Elem, _Traits > &_Ostr)
Definition: ostream:982
#define CHECK_INT(x, y)
Definition: xtest:29
_Myt * open(const char *_Filename, ios_base::openmode _Mode, int _Prot=(int) ios_base::_Openprot)
Definition: fstream:262
#define CHECK(x)
Definition: xtest:28
__PURE_APPDOMAIN_GLOBAL _CRTDATA2 ostream cout
bool is_open() const
Definition: fstream:257
#define MYWCHAR
Definition: xtest:44
Definition: fstream:135
static constexpr _Openmode in
Definition: xiosbase:95
Definition: wbuffer:29
bool test_write ( const char fname,
const Mystring mystring 
)
60  { // write sequences of wide chars to file
61  Mybfilebuf mybbuf;
62 
63  mybbuf.open(fname, ios_base::binary | ios_base::out);
64  if (!mybbuf.is_open())
65  { // open failed, give up
66  #ifndef TERSE
67  cout << "can't write to " << fname << endl;
68  #endif /* TERSE */
69 
70  CHECK_MSG("can't open file for writing", 0);
71  return (false);
72  }
73 
75  Myostream mystr(&mybuf);
76 
77  for (size_t idx = 0; idx < mystring.size(); ++idx)
78  if (mystr.write(&mystring[idx], 1))
79  CHECK(1);
80  else
81  { // write failed, quit
82  #ifndef TERSE
83  cout << hex
84  << "write failed for " << (unsigned long)mystring[idx]
85  << endl;
86  #endif /* TERSE */
87 
88  CHECK_INT((int)idx, -1);
89  return (false);
90  }
91  return (true);
92  }
static constexpr _Openmode out
Definition: xiosbase:96
ios_base &__CLRCALL_OR_CDECL hex(ios_base &_Iosbase)
Definition: ios:236
basic_ostream< MYWCHAR > Myostream
Definition: xtest:53
_In_ long
Definition: corecrt_wstdlib.h:88
#define CHECK_MSG(msg, ok)
Definition: xtest:30
static constexpr _Openmode binary
Definition: xiosbase:102
basic_ostream< _Elem, _Traits > &__CLRCALL_OR_CDECL endl(basic_ostream< _Elem, _Traits > &_Ostr)
Definition: ostream:982
#define CHECK_INT(x, y)
Definition: xtest:29
_Myt * open(const char *_Filename, ios_base::openmode _Mode, int _Prot=(int) ios_base::_Openprot)
Definition: fstream:262
#define CHECK(x)
Definition: xtest:28
__PURE_APPDOMAIN_GLOBAL _CRTDATA2 ostream cout
bool is_open() const
Definition: fstream:257
Definition: fstream:135
Definition: wbuffer:29