Remove redundant wxUSE_WXVSNPRINTF checks from the unit test.
[wxWidgets.git] / tests / strings / vsnprintf.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/strings/vsnprintf.cpp
3 // Purpose: wxVsnprintf unit test
4 // Author: Francesco Montorsi
5 // (part of this file was taken from CMP.c of TRIO package
6 // written by Bjorn Reese and Daniel Stenberg)
7 // Created: 2006-04-01
8 // RCS-ID: $Id$
9 // Copyright: (c) 2006 Francesco Montorsi, Bjorn Reese and Daniel Stenberg
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ----------------------------------------------------------------------------
13 // headers
14 // ----------------------------------------------------------------------------
15
16 #include "testprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #include "wx/crt.h"
23
24 #if wxUSE_WXVSNPRINTF
25
26 #ifndef WX_PRECOMP
27 #include "wx/wx.h"
28 #include "wx/wxchar.h"
29 #endif // WX_PRECOMP
30
31
32 // NOTE: for more info about the specification of wxVsnprintf() behaviour you can
33 // refer to the following page of the GNU libc manual:
34 // http://www.gnu.org/software/libc/manual/html_node/Formatted-Output.html
35
36
37
38 // ----------------------------------------------------------------------------
39 // global utilities for testing
40 // ----------------------------------------------------------------------------
41
42 #define MAX_TEST_LEN 1024
43
44 // temporary buffers
45 static wxChar buf[MAX_TEST_LEN];
46 int r;
47
48 // these macros makes it possible to write all tests without repeating a lot
49 // of times the wxT() macro
50 // NOTE: you should use expected strings with these macros which do not exceed
51 // MAX_TEST_LEN as these macro do check if the return value is == (int)wxStrlen(buf)
52
53 #define ASSERT_STR_EQUAL( a, b ) \
54 CPPUNIT_ASSERT_EQUAL( wxString(a), wxString(b) );
55
56 #define CMP6(expected, fmt, y, z, w, t) \
57 r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y, z, w, t); \
58 CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
59 ASSERT_STR_EQUAL( wxT(expected), buf );
60
61 #define CMP5(expected, fmt, y, z, w) \
62 r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y, z, w); \
63 CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
64 ASSERT_STR_EQUAL( wxT(expected), buf );
65
66 #define CMP4(expected, fmt, y, z) \
67 r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y, z); \
68 CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
69 ASSERT_STR_EQUAL( wxT(expected), buf );
70
71 #define CMP3(expected, fmt, y) \
72 r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y); \
73 CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
74 ASSERT_STR_EQUAL( wxT(expected), buf );
75
76 #define CMP2(expected, fmt) \
77 r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt)); \
78 CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
79 ASSERT_STR_EQUAL( wxT(expected), buf );
80
81 // NOTE: this macro is used also with too-small buffers (see Miscellaneous())
82 // test function, thus the return value can be > size and thus we
83 // cannot check if r == (int)wxStrlen(buf)
84 #define CMPTOSIZE(buffer, size, failuremsg, expected, fmt, x, y, z, w) \
85 r=wxSnprintf(buffer, size, wxT(fmt), x, y, z, w); \
86 CPPUNIT_ASSERT( r > 0 ); \
87 CPPUNIT_ASSERT_EQUAL_MESSAGE( \
88 failuremsg, \
89 wxString(wxT(expected)).Left(size - 1), \
90 wxString(buffer))
91
92 // this is the same as wxSnprintf() but it passes the format string to
93 // wxVsnprintf() without using WX_ATTRIBUTE_PRINTF and thus suppresses the gcc
94 // checks (and resulting warnings) for the format string
95 //
96 // use with extreme care and only when you're really sure the warnings must be
97 // suppressed!
98 template<typename T>
99 static int
100 wxUnsafeSnprintf(T *buf, size_t len, const wxChar *fmt, ...)
101 {
102 va_list args;
103 va_start(args, fmt);
104
105 int rc = wxVsnprintf(buf, len, fmt, args);
106
107 va_end(args);
108
109 return rc;
110 }
111
112 // ----------------------------------------------------------------------------
113 // test class
114 // ----------------------------------------------------------------------------
115
116 class VsnprintfTestCase : public CppUnit::TestCase
117 {
118 public:
119 VsnprintfTestCase() {}
120
121 virtual void setUp();
122
123 private:
124 CPPUNIT_TEST_SUITE( VsnprintfTestCase );
125 CPPUNIT_TEST( C );
126 CPPUNIT_TEST( D );
127 CPPUNIT_TEST( X );
128 CPPUNIT_TEST( O );
129 CPPUNIT_TEST( P );
130 CPPUNIT_TEST( N );
131 CPPUNIT_TEST( E );
132 CPPUNIT_TEST( F );
133 CPPUNIT_TEST( G );
134 CPPUNIT_TEST( S );
135 CPPUNIT_TEST( Asterisk );
136 CPPUNIT_TEST( Percent );
137 #ifdef wxLongLong_t
138 CPPUNIT_TEST( LongLong );
139 #endif
140
141 CPPUNIT_TEST( BigToSmallBuffer );
142 CPPUNIT_TEST( WrongFormatStrings );
143 CPPUNIT_TEST( Miscellaneous );
144 CPPUNIT_TEST( GlibcMisc1 );
145 CPPUNIT_TEST( GlibcMisc2 );
146 CPPUNIT_TEST_SUITE_END();
147
148 void C();
149 void D();
150 void X();
151 void O();
152 void P();
153 void N();
154 void E();
155 void F();
156 void G();
157 void S();
158 void Asterisk();
159 void Percent();
160 #ifdef wxLongLong_t
161 void LongLong();
162 #endif
163 void Unicode();
164
165 template<typename T>
166 void DoBigToSmallBuffer(T *buffer, int size);
167 void BigToSmallBuffer();
168
169 void WrongFormatStrings();
170
171 // compares the expectedString and the result of wxVsnprintf() char by char
172 // for all its lenght (not only for first expectedLen chars) and also
173 // checks the return value
174 void DoMisc(int expectedLen, const wxString& expectedString,
175 size_t max, const wxChar *format, ...);
176 void Miscellaneous();
177
178 void GlibcMisc1();
179 void GlibcMisc2();
180
181 DECLARE_NO_COPY_CLASS(VsnprintfTestCase)
182 };
183
184 // register in the unnamed registry so that these tests are run by default
185 CPPUNIT_TEST_SUITE_REGISTRATION( VsnprintfTestCase );
186
187 // also include in it's own registry so that these tests can be run alone
188 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VsnprintfTestCase, "VsnprintfTestCase" );
189
190 void VsnprintfTestCase::setUp()
191 {
192 // this call is required to avoid check failures when running on machines
193 // with a locale where the decimal point is not '.'
194 wxSetlocale(LC_ALL, "C");
195 }
196
197 void VsnprintfTestCase::C()
198 {
199 CMP5("hi!", "%c%c%c", wxT('h'), wxT('i'), wxT('!'));
200
201 // NOTE:
202 // the NULL characters _can_ be passed to %c to e.g. create strings
203 // with embedded NULs (because strings are not always supposed to be
204 // NUL-terminated).
205
206 DoMisc(14, wxT("Hello \0 World!"), 16, wxT("Hello %c World!"), wxT('\0'));
207 }
208
209 void VsnprintfTestCase::D()
210 {
211 CMP3("+123456", "%+d", 123456);
212 CMP3("-123456", "%d", -123456);
213 CMP3(" 123456", "% d", 123456);
214 CMP3(" 123456", "%10d", 123456);
215 CMP3("0000123456", "%010d", 123456);
216 CMP3("-123456 ", "%-10d", -123456);
217 }
218
219 void VsnprintfTestCase::X()
220 {
221 CMP3("ABCD", "%X", 0xABCD);
222 CMP3("0XABCD", "%#X", 0xABCD);
223 CMP3("0xabcd", "%#x", 0xABCD);
224 }
225
226 void VsnprintfTestCase::O()
227 {
228 CMP3("1234567", "%o", 01234567);
229 CMP3("01234567", "%#o", 01234567);
230 }
231
232 void VsnprintfTestCase::P()
233 {
234 // WARNING: printing of pointers is not fully standard.
235 // GNU prints them as %#x except for NULL pointers which are
236 // printed as '(nil)'.
237 // MSVC always print them as %8X on 32 bit systems and as %16X
238 // on 64 bit systems
239 // mingw32 uses MSVC CRT by default so uses the same rules
240 #if defined(__VISUALC__) || (defined(__MINGW32__) && !__USE_MINGW_ANSI_STDIO)
241 #if SIZEOF_VOID_P == 4
242 CMP3("00ABCDEF", "%p", (void*)0xABCDEF);
243 CMP3("00000000", "%p", (void*)NULL);
244 #elif SIZEOF_VOID_P == 8
245 CMP3("0000ABCDEFABCDEF", "%p", (void*)0xABCDEFABCDEF);
246 CMP3("0000000000000000", "%p", (void*)NULL);
247 #endif
248 #elif defined(__MINGW32__)
249 CMP3("0xabcdef", "%p", (void*)0xABCDEF);
250 CMP3("0", "%p", (void*)NULL);
251 #elif defined(__GNUG__)
252 CMP3("0xabcdef", "%p", (void*)0xABCDEF);
253 CMP3("(nil)", "%p", (void*)NULL);
254 #endif
255 }
256
257 void VsnprintfTestCase::N()
258 {
259 int nchar;
260
261 wxSnprintf(buf, MAX_TEST_LEN, wxT("%d %s%n\n"), 3, wxT("bears"), &nchar);
262 CPPUNIT_ASSERT_EQUAL( 7, nchar );
263 }
264
265 void VsnprintfTestCase::E()
266 {
267 // NB: there are no standards about the minimum exponent width
268 // (and the width of the %e conversion specifier refers to the
269 // mantissa, not to the exponent).
270 // Since newer MSVC versions use 3 digits as minimum exponent
271 // width while GNU libc uses 2 digits as minimum width, here we
272 // workaround this problem using for the exponent values with at
273 // least three digits.
274 // Some examples:
275 // printf("%e",2.342E+02);
276 // -> under MSVC7.1 prints: 2.342000e+002
277 // -> under GNU libc 2.4 prints: 2.342000e+02
278 CMP3("2.342000e+112", "%e",2.342E+112);
279 CMP3("-2.3420e-112", "%10.4e",-2.342E-112);
280 CMP3("-2.3420e-112", "%11.4e",-2.342E-112);
281 CMP3(" -2.3420e-112", "%15.4e",-2.342E-112);
282
283 CMP3("-0.02342", "%G",-2.342E-02);
284 CMP3("3.1415E-116", "%G",3.1415e-116);
285 CMP3("0003.141500e+103", "%016e", 3141.5e100);
286 CMP3(" 3.141500e+103", "%16e", 3141.5e100);
287 CMP3("3.141500e+103 ", "%-16e", 3141.5e100);
288 CMP3("3.142e+103", "%010.3e", 3141.5e100);
289 }
290
291 void VsnprintfTestCase::F()
292 {
293 CMP3("3.300000", "%5f", 3.3);
294 CMP3("3.000000", "%5f", 3.0);
295 CMP3("0.000100", "%5f", .999999E-4);
296 CMP3("0.000990", "%5f", .99E-3);
297 CMP3("3333.000000", "%5f", 3333.0);
298 }
299
300 void VsnprintfTestCase::G()
301 {
302 // NOTE: the same about E() testcase applies here...
303
304 CMP3(" 3.3", "%5g", 3.3);
305 CMP3(" 3", "%5g", 3.0);
306 CMP3("9.99999e-115", "%5g", .999999E-114);
307 CMP3("0.00099", "%5g", .99E-3);
308 CMP3(" 3333", "%5g", 3333.0);
309 CMP3(" 0.01", "%5g", 0.01);
310
311 CMP3(" 3", "%5.g", 3.3);
312 CMP3(" 3", "%5.g", 3.0);
313 CMP3("1e-114", "%5.g", .999999E-114);
314 CMP3("0.0001", "%5.g", 1.0E-4);
315 CMP3("0.001", "%5.g", .99E-3);
316 CMP3("3e+103", "%5.g", 3333.0E100);
317 CMP3(" 0.01", "%5.g", 0.01);
318
319 CMP3(" 3.3", "%5.2g", 3.3);
320 CMP3(" 3", "%5.2g", 3.0);
321 CMP3("1e-114", "%5.2g", .999999E-114);
322 CMP3("0.00099", "%5.2g", .99E-3);
323 CMP3("3.3e+103", "%5.2g", 3333.0E100);
324 CMP3(" 0.01", "%5.2g", 0.01);
325 }
326
327 void VsnprintfTestCase::S()
328 {
329 CMP3(" abc", "%5s", wxT("abc"));
330 CMP3(" a", "%5s", wxT("a"));
331 CMP3("abcdefghi", "%5s", wxT("abcdefghi"));
332 CMP3("abc ", "%-5s", wxT("abc"));
333 CMP3("abcdefghi", "%-5s", wxT("abcdefghi"));
334
335 CMP3("abcde", "%.5s", wxT("abcdefghi"));
336
337 // do the same tests but with Unicode characters:
338 #if wxUSE_UNICODE
339
340 // Unicode code points from U+03B1 to U+03B9 are the greek letters alpha-iota;
341 // UTF8 encoding of such code points is 0xCEB1 to 0xCEB9
342
343 #define ALPHA "\xCE\xB1"
344 // alpha
345 #define ABC "\xCE\xB1\xCE\xB2\xCE\xB3"
346 // alpha+beta+gamma
347 #define ABCDE "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5"
348 // alpha+beta+gamma+delta+epsilon
349 #define ABCDEFGHI "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5\xCE\xB6\xCE\xB7\xCE\xB8\xCE\xB9"
350 // alpha+beta+gamma+delta+epsilon+zeta+eta+theta+iota
351
352 // the 'expected' and 'arg' parameters of this macro are supposed to be
353 // UTF-8 strings
354 #define CMP3_UTF8(expected, fmt, arg) \
355 CPPUNIT_ASSERT_EQUAL \
356 ( \
357 wxString::FromUTF8(expected).length(), \
358 wxSnprintf(buf, MAX_TEST_LEN, fmt, wxString::FromUTF8(arg)) \
359 ); \
360 CPPUNIT_ASSERT_EQUAL \
361 ( \
362 wxString::FromUTF8(expected), \
363 buf \
364 )
365
366 CMP3_UTF8(" " ABC, "%5s", ABC);
367 CMP3_UTF8(" " ALPHA, "%5s", ALPHA);
368 CMP3_UTF8(ABCDEFGHI, "%5s", ABCDEFGHI);
369 CMP3_UTF8(ABC " ", "%-5s", ABC);
370 CMP3_UTF8(ABCDEFGHI, "%-5s", ABCDEFGHI);
371 CMP3_UTF8(ABCDE, "%.5s", ABCDEFGHI);
372 #endif // wxUSE_UNICODE
373
374 // test a string which has a NULL character after "ab";
375 // obviously it should be handled exactly like just as "ab"
376 CMP3(" ab", "%5s", wxT("ab\0cdefghi"));
377 }
378
379 void VsnprintfTestCase::Asterisk()
380 {
381 CMP5(" 0.1", "%*.*f", 10, 1, 0.123);
382 CMP5(" 0.1230", "%*.*f", 10, 4, 0.123);
383 CMP5("0.1", "%*.*f", 3, 1, 0.123);
384
385 CMP4("%0.002", "%%%.*f", 3, 0.0023456789);
386
387 CMP4(" a", "%*c", 8, 'a');
388 CMP4(" four", "%*s", 8, "four");
389 CMP6(" four four", "%*s %*s", 8, "four", 6, "four");
390 }
391
392 void VsnprintfTestCase::Percent()
393 {
394 // some tests without any argument passed through ...
395 CMP2("%", "%%");
396 CMP2("%%%", "%%%%%%");
397
398 CMP3("% abc", "%%%5s", wxT("abc"));
399 CMP3("% abc%", "%%%5s%%", wxT("abc"));
400
401 // do not test odd number of '%' symbols as different implementations
402 // of snprintf() give different outputs as this situation is not considered
403 // by any standard (in fact, GCC will also warn you about a spurious % if
404 // you write %%% as argument of some *printf function !)
405 // Compare(wxT("%"), wxT("%%%"));
406 }
407
408 #ifdef wxLongLong_t
409 void VsnprintfTestCase::LongLong()
410 {
411 CMP3("123456789", "%lld", (wxLongLong_t)123456789);
412 CMP3("-123456789", "%lld", (wxLongLong_t)-123456789);
413
414 CMP3("123456789", "%llu", (wxULongLong_t)123456789);
415
416 #ifdef __WXMSW__
417 CMP3("123456789", "%I64d", (wxLongLong_t)123456789);
418 CMP3("123456789abcdef", "%I64x", wxLL(0x123456789abcdef));
419 #endif
420 }
421 #endif
422
423 void VsnprintfTestCase::WrongFormatStrings()
424 {
425 // test how wxVsnprintf() behaves with wrong format string:
426
427 #if 0
428 // NB: the next 2 tests currently return an error but it would be nice
429 // if they didn't (see ticket #9367)
430
431 // two positionals with the same index:
432 r = wxSnprintf(buf, MAX_TEST_LEN, wxT("%1$s %1$s"), "hello");
433 CPPUNIT_ASSERT(r != -1);
434
435 // three positionals with the same index mixed with other pos args:
436 r = wxSnprintf(buf, MAX_TEST_LEN, wxT("%4$d %2$f %1$s %2$s %3$d"), "hello", "world", 3, 4);
437 CPPUNIT_ASSERT(r != -1);
438 #endif
439
440 // a missing positional arg should result in an assert
441 WX_ASSERT_FAILS_WITH_ASSERT(
442 wxSnprintf(buf, MAX_TEST_LEN, wxT("%1$d %3$d"), 1, 2, 3) );
443
444 // positional and non-positionals in the same format string:
445 r = wxSnprintf(buf, MAX_TEST_LEN, wxT("%1$d %d %3$d"), 1, 2, 3);
446 CPPUNIT_ASSERT_EQUAL(-1, r);
447 }
448
449 // BigToSmallBuffer() test case helper:
450 template<typename T>
451 void VsnprintfTestCase::DoBigToSmallBuffer(T *buffer, int size)
452 {
453 // Remember that wx*printf could be mapped either to system
454 // implementation or to wx implementation.
455 // In the first case, when the output buffer is too small, the returned
456 // value can be the number of characters required for the output buffer
457 // (conforming to ISO C99; implemented in e.g. GNU libc >= 2.1), or
458 // just a negative number, usually -1; (this is how e.g. MSVC's
459 // *printf() behaves). Luckily, in all implementations, when the
460 // output buffer is too small, it's nonetheless filled up to its max size.
461 //
462 // Note that in the second case (i.e. when we're using our own implementation),
463 // wxVsnprintf() will return the number of characters written in the standard
464 // output or
465 // -1 if there was an error in the format string
466 // maxSize+1 if the output buffer is too small
467
468 wxString errStr;
469 errStr << "The size of the buffer was " << size;
470 std::string errMsg(errStr.mb_str());
471
472 // test without positionals
473 CMPTOSIZE(buffer, size, errMsg,
474 "123456789012 - test - 123 -4.567",
475 "%i%li - test - %d %.3f",
476 123, (long int)456789012, 123, -4.567);
477
478 #if wxUSE_PRINTF_POS_PARAMS
479 // test with positional
480 CMPTOSIZE(buffer, size, errMsg,
481 "-4.567 123 - test - 456789012 123",
482 "%4$.3f %1$i - test - %2$li %3$d",
483 123, (long int)456789012, 123, -4.567);
484 #endif
485
486 // test unicode/ansi conversion specifiers
487 //
488 // NB: we use wxUnsafeSnprintf() as %hs and %hc are invalid in printf
489 // format and gcc would warn about this otherwise
490
491 r = wxUnsafeSnprintf(buffer, size,
492 wxT("unicode string/char: %ls/%lc -- ansi string/char: %hs/%hc"),
493 L"unicode", L'U', "ansi", 'A');
494 wxString expected =
495 wxString(wxT("unicode string/char: unicode/U -- ansi string/char: ansi/A")).Left(size - 1);
496
497 CPPUNIT_ASSERT( r != -1 );
498 CPPUNIT_ASSERT_EQUAL(
499 expected,
500 wxString(buffer)
501 );
502 }
503
504 void VsnprintfTestCase::BigToSmallBuffer()
505 {
506 // VC6 can't compile this code
507 #if !defined(__VISUALC__) || (__VISUALC__ >= 1310)
508 #if wxUSE_UNICODE
509 wchar_t bufw[1024], bufw2[16], bufw3[4], bufw4;
510 DoBigToSmallBuffer(bufw, 1024);
511 DoBigToSmallBuffer(bufw2, 16);
512 DoBigToSmallBuffer(bufw3, 4);
513 DoBigToSmallBuffer(&bufw4, 1);
514 #endif // wxUSE_UNICODE
515
516 char bufa[1024], bufa2[16], bufa3[4], bufa4;
517 DoBigToSmallBuffer(bufa, 1024);
518 DoBigToSmallBuffer(bufa2, 16);
519 DoBigToSmallBuffer(bufa3, 4);
520 DoBigToSmallBuffer(&bufa4, 1);
521 #endif // !VC6
522 }
523
524 // Miscellaneous() test case helper:
525 void VsnprintfTestCase::DoMisc(
526 int expectedLen,
527 const wxString& expectedString,
528 size_t max,
529 const wxChar *format, ...)
530 {
531 const size_t BUFSIZE = MAX_TEST_LEN - 1;
532 size_t i;
533 static int count = 0;
534
535 wxASSERT(max <= BUFSIZE);
536
537 for (i = 0; i < BUFSIZE; i++)
538 buf[i] = '*';
539 buf[BUFSIZE] = 0;
540
541 va_list ap;
542 va_start(ap, format);
543
544 int n = wxVsnprintf(buf, max, format, ap);
545
546 va_end(ap);
547
548 // Prepare messages so that it is possible to see from the error which
549 // test was running.
550 wxString errStr, overflowStr;
551 errStr << wxT("No.: ") << ++count << wxT(", expected: ") << expectedLen
552 << wxT(" '") << expectedString << wxT("', result: ");
553 overflowStr << errStr << wxT("buffer overflow");
554 errStr << n << wxT(" '") << buf << wxT("'");
555
556 // turn them into std::strings
557 std::string errMsg(errStr.mb_str());
558 std::string overflowMsg(overflowStr.mb_str());
559
560 CPPUNIT_ASSERT_MESSAGE(errMsg,
561 (expectedLen == -1 && size_t(n) >= max) || expectedLen == n);
562
563 CPPUNIT_ASSERT_MESSAGE(errMsg, expectedString == buf);
564
565 for (i = max; i < BUFSIZE; i++)
566 CPPUNIT_ASSERT_MESSAGE(overflowMsg, buf[i] == '*');
567 }
568
569 void VsnprintfTestCase::Miscellaneous()
570 {
571 // expectedLen, expectedString, max, format, ...
572 DoMisc(5, wxT("-1234"), 8, wxT("%d"), -1234);
573 DoMisc(7, wxT("1234567"), 8, wxT("%d"), 1234567);
574 DoMisc(-1, wxT("1234567"), 8, wxT("%d"), 12345678);
575 DoMisc(-1, wxT("-123456"), 8, wxT("%d"), -1234567890);
576
577 DoMisc(6, wxT("123456"), 8, wxT("123456"));
578 DoMisc(7, wxT("1234567"), 8, wxT("1234567"));
579 DoMisc(-1, wxT("1234567"), 8, wxT("12345678"));
580
581 DoMisc(6, wxT("123450"), 8, wxT("12345%d"), 0);
582 DoMisc(7, wxT("1234560"), 8, wxT("123456%d"), 0);
583 DoMisc(-1, wxT("1234567"), 8, wxT("1234567%d"), 0);
584 DoMisc(-1, wxT("1234567"), 8, wxT("12345678%d"), 0);
585
586 DoMisc(6, wxT("12%45%"), 8, wxT("12%%45%%"));
587 DoMisc(7, wxT("12%45%7"), 8, wxT("12%%45%%7"));
588 DoMisc(-1, wxT("12%45%7"), 8, wxT("12%%45%%78"));
589
590 DoMisc(5, wxT("%%%%%"), 6, wxT("%%%%%%%%%%"));
591 DoMisc(6, wxT("%%%%12"), 7, wxT("%%%%%%%%%d"), 12);
592 }
593
594
595 /* (C) Copyright C E Chew
596 *
597 * Feel free to copy, use and distribute this software provided:
598 *
599 * 1. you do not pretend that you wrote it
600 * 2. you leave this copyright notice intact.
601 */
602
603 void VsnprintfTestCase::GlibcMisc1()
604 {
605 CMP3(" ", "%5.s", "xyz");
606 CMP3(" 33", "%5.f", 33.3);
607 #if defined(__VISUALC__)
608 // see the previous notes about the minimum width of mantissa:
609 CMP3(" 3e+008", "%8.e", 33.3e7);
610 CMP3(" 3E+008", "%8.E", 33.3e7);
611 CMP3("3e+001", "%.g", 33.3);
612 CMP3("3E+001", "%.G", 33.3);
613 #else
614 CMP3(" 3e+08", "%8.e", 33.3e7);
615 CMP3(" 3E+08", "%8.E", 33.3e7);
616 CMP3("3e+01", "%.g", 33.3);
617 CMP3("3E+01", "%.G", 33.3);
618 #endif
619 }
620
621 void VsnprintfTestCase::GlibcMisc2()
622 {
623 int prec;
624 wxString test_format;
625
626 prec = 0;
627 CMP4("3", "%.*g", prec, 3.3);
628
629 prec = 0;
630 CMP4("3", "%.*G", prec, 3.3);
631
632 prec = 0;
633 CMP4(" 3", "%7.*G", prec, 3.33);
634
635 prec = 3;
636 CMP4(" 041", "%04.*o", prec, 33);
637
638 prec = 7;
639 CMP4(" 0000033", "%09.*u", prec, 33);
640
641 prec = 3;
642 CMP4(" 021", "%04.*x", prec, 33);
643
644 prec = 3;
645 CMP4(" 021", "%04.*X", prec, 33);
646 }
647
648 #endif // wxUSE_WXVSNPRINTF
649