]> git.saurik.com Git - wxWidgets.git/blob - tests/benchmarks/mbconv.cpp
Check wxListCtrl::GetItemRect() origin in the unit tests.
[wxWidgets.git] / tests / benchmarks / mbconv.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tests/benchmarks/mbconv.cpp
3 // Purpose: MB<->WC conversion benchmarks
4 // Author: Vadim Zeitlin
5 // Created: 2008-10-17
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/strconv.h"
12 #include "wx/string.h"
13
14 #include "bench.h"
15
16 namespace
17 {
18
19 const wchar_t *TEST_STRING =
20 L"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod"
21 L"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim"
22 L"veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea"
23 L"commodo consequat. Duis aute irure dolor in reprehenderit in voluptate"
24 L"velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint"
25 L"occaecat cupidatat non proident, sunt in culpa qui officia deserunt"
26 L"mollit anim id est laborum."
27 ;
28
29 // just compute the length of the resulting multibyte string
30 bool ComputeMBLength(const wxMBConv& conv)
31 {
32 // we suppose a fixed length encoding here (which happens to cover UTF-8
33 // too as long as the test string is ASCII)
34 return conv.FromWChar(NULL, 0, TEST_STRING)
35 == (wcslen(TEST_STRING) + 1)*conv.GetMBNulLen();
36 }
37
38 // perform the conversion
39 bool ConvertToMB(const wxMBConv& conv)
40 {
41 const size_t outlen = (wcslen(TEST_STRING) + 1)*conv.GetMBNulLen();
42 wxCharBuffer buf(outlen - 1); // it adds 1 internally
43 return conv.FromWChar(buf.data(), outlen, TEST_STRING) == outlen;
44 }
45
46 } // anonymous namespace
47
48 BENCHMARK_FUNC(UTF16InitWX)
49 {
50 wxMBConvUTF16 conv;
51 return true;
52 }
53
54 BENCHMARK_FUNC(UTF16InitSys)
55 {
56 wxCSConv conv("UTF-16LE");
57 return conv.IsOk();
58 }
59
60 BENCHMARK_FUNC(UTF16LenWX)
61 {
62 return ComputeMBLength(wxMBConvUTF16());
63 }
64
65 BENCHMARK_FUNC(UTF16LenSys)
66 {
67 return ComputeMBLength(wxCSConv("UTF-16LE"));
68 }
69
70 BENCHMARK_FUNC(UTF16WX)
71 {
72 return ConvertToMB(wxMBConvUTF16());
73 }
74
75 BENCHMARK_FUNC(UTF16Sys)
76 {
77 return ConvertToMB(wxCSConv("UTF-16LE"));
78 }
79