Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / ACEXML / tests / Transcoder_Test.cpp
blob5f3bf7c675fa5ba43ca8db71a28ca57a1f55a3a6
1 // -*- C++ -*-
3 #include "ACEXML/common/Transcode.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_NS_string.h"
6 #include "ace/OS_main.h"
8 void dump_utf16 (const ACEXML_UTF16 *data, size_t len)
10 size_t ptr = 0;
12 while (1)
14 ACE_DEBUG ((LM_DEBUG, "%04x", data[ptr]));
16 if (++ptr >= len)
17 break;
19 if (ptr % 4 == 0)
20 ACE_DEBUG ((LM_DEBUG, "\n"));
21 else
22 ACE_DEBUG ((LM_DEBUG, " "));
24 ACE_DEBUG ((LM_DEBUG, "\n"));
25 return;
28 int
29 ACE_TMAIN (int, ACE_TCHAR*[])
31 ACEXML_UTF16 org [18];
32 // = { 1, 2, 4, 8, 0x10, 0x20, 0x40,
33 // 0x80,
34 // 0x100, 0x200, 0x400,
35 // 0x800, 0x801, 0x802, 0x804, 0x808, 0x810, 0x820,
36 // 0x840, 0x880, 0x900, 0xa00, 0xc00,
37 // 0x1000, 0x2000, 0x4000, 0x8000, 0 }
38 ACEXML_UCS4 temp = 1;
40 ACE_OS::memset (org, 0, sizeof org);
41 size_t x;
43 for (x = 0; temp < 0x10000; x++, temp <<= 1)
45 org[x] = static_cast<ACEXML_UTF16> (temp);
48 ACE_DEBUG ((LM_DEBUG, "Original UTF16 string:\n"));
49 dump_utf16 (org, x);
50 ACE_DEBUG ((LM_DEBUG, "\n\n"));
52 ACEXML_UTF8 decoded [MAXPATHLEN];
53 ACE_OS::memset (decoded, 0, sizeof decoded);
55 ACEXML_Transcoder::utf16s2utf8s (org, decoded, MAXPATHLEN);
57 ACE_DEBUG ((LM_DEBUG, "Transcoded UTF8 string:\n"));
58 ACE_HEX_DUMP ((LM_DEBUG, decoded, ACE_OS::strlen (decoded) + 1));
59 ACE_DEBUG ((LM_DEBUG, "\n\n"));
61 ACEXML_UTF16 after [18];
62 ACE_OS::memset (after, 0, sizeof after);
63 ACEXML_Transcoder::utf8s2utf16s (decoded, after, 18);
65 ACE_DEBUG ((LM_DEBUG, "Restored UTF16 string:\n"));
66 dump_utf16 (after, x);
67 ACE_DEBUG ((LM_DEBUG, "\n\n"));
69 return 0;