blob: 522256c6af304858e300e36e749d0efa724a5ec0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// **********************************************************************
//
// Copyright (c) 2003
// ZeroC, Inc.
// Billerica, MA, USA
//
// All Rights Reserved.
//
// Ice is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License version 2 as published by
// the Free Software Foundation.
//
// **********************************************************************
#include <IceUtil/Unicode.h>
#include <TestCommon.h>
#include <fstream>
using namespace IceUtil;
using namespace std;
int
main(int, char**)
{
cout << "testing string/wstring conversion... ";
string arabic = "لماذا لا يتكلمون اللّغة العربية فحسب؟";
wstring warabic = stringToWstring(arabic);
test(warabic.length() == 37);
string arabic2 = wstringToString(warabic);
test(arabic2.length() == arabic.length());
test(arabic2 == arabic);
string japanese = "なぜ、みんな日本語を話してくれないのか?";
wstring wjapanese = stringToWstring(japanese);
test(wjapanese.length() == 20);
string japanese2 = wstringToString(wjapanese);
test(japanese2.length() == japanese.length());
test(japanese2 == japanese);
cout << "ok" << endl;
cout << "ditto, but with random unicode text... ";
ifstream numeric("numeric.txt");
test(numeric.good());
wstring wrandom;
while(numeric)
{
int c;
numeric >> c;
if(numeric)
{
wrandom += static_cast<wchar_t>(c);
}
}
numeric.close();
ifstream utf8("utf8.txt");
test(utf8.good());
string random;
while(utf8)
{
char c;
utf8.get(c);
if(utf8)
{
random += c;
}
}
utf8.close();
string random2 = wstringToString(wrandom);
wstring wrandom2 = stringToWstring(random);
/*
unsigned int i;
ofstream numeric2("numeric2.txt");
for(i = 0; i < wrandom2.length(); ++i)
{
numeric2 << static_cast<int>(wrandom2[i]) << '\n';
}
numeric2.close();
ofstream utf82("utf82.txt");
for(i = 0; i < random2.length(); ++i)
{
utf82.put(random2[i]);
}
utf82.close();
*/
test (random2.length() == random.length());
test (wrandom2.length() == wrandom.length());
test (random2 == random);
test (wrandom2 == wrandom);
cout << "ok" << endl;
return EXIT_SUCCESS;
}
|