diff options
author | Jose <jose@zeroc.com> | 2009-11-10 05:30:26 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2009-11-10 05:30:26 +0100 |
commit | 4247c9e2c2612394a5f4d63a65ba538f975906d4 (patch) | |
tree | 96d3308681d9b0684ce5dd763f5a5d415eaf09d7 /cpp/test/IceUtil/unicode/Client.cpp | |
parent | Win32 64 bits compilation error (diff) | |
download | ice-4247c9e2c2612394a5f4d63a65ba538f975906d4.tar.bz2 ice-4247c9e2c2612394a5f4d63a65ba538f975906d4.tar.xz ice-4247c9e2c2612394a5f4d63a65ba538f975906d4.zip |
Fixed 3962 - Berkeley DB, problems with unicode paths.
Diffstat (limited to 'cpp/test/IceUtil/unicode/Client.cpp')
-rw-r--r-- | cpp/test/IceUtil/unicode/Client.cpp | 112 |
1 files changed, 102 insertions, 10 deletions
diff --git a/cpp/test/IceUtil/unicode/Client.cpp b/cpp/test/IceUtil/unicode/Client.cpp index a8b99a4d02b..622bbe79818 100644 --- a/cpp/test/IceUtil/unicode/Client.cpp +++ b/cpp/test/IceUtil/unicode/Client.cpp @@ -8,8 +8,12 @@ // ********************************************************************** #include <IceUtil/Unicode.h> +#include <IceUtil/FileUtil.h> #include <TestCommon.h> -#include <fstream> + +#ifdef _WIN32 +# include <io.h> +#endif using namespace IceUtil; using namespace std; @@ -18,17 +22,34 @@ using namespace std; // Note that each file starts with a BOM; stringToWstring and wstringToString // converts these BOMs back and forth. // + +//COMPILERFIX: Borland C++ 2010 doesn't support wmain for console applications. +#if defined(_WIN32) && !defined(__BCPLUSPLUS__) + int -main(int argc, char** argv) +wmain(int argc, wchar_t* argv[]) + +#else + +int +main(int argc, char* argv[]) + +#endif { string dir = ""; if(argc > 1) { +#ifdef _WIN32 + +#ifndef __BCPLUSPLUS__ dir = argv[1]; -#ifdef _WIN32 +#else + dir = IceUtil::wstringToString(argv[1]); +#endif dir += "\\"; #else + dir = argv[1]; dir += "/"; #endif } @@ -45,11 +66,10 @@ main(int argc, char** argv) string wcoeurFile = string("coeur.") + wstringEncoding; { - cout << "testing UTF-8 to wstring (" << wstringEncoding << ") conversion..."; - - ifstream is((dir + "coeur.utf8").c_str()); + cout << "testing UTF-8 to wstring (" << wstringEncoding << ") conversion... "; + IceUtilInternal::ifstream is((dir + "coeur.utf8")); test(is.good()); - ifstream bis((dir + wcoeurFile).c_str(), ios_base::binary); + IceUtilInternal::ifstream bis((dir + wcoeurFile), ios_base::binary); test(bis.good()); int lineNumber = 0; @@ -105,9 +125,9 @@ main(int argc, char** argv) } { - cout << "wstring (" << wstringEncoding << ") to UTF-8 conversion..."; + cout << "wstring (" << wstringEncoding << ") to UTF-8 conversion... "; - ifstream bis((dir + wcoeurFile).c_str(), ios_base::binary); + IceUtilInternal::ifstream bis((dir + wcoeurFile), ios_base::binary); test(bis.good()); wstring ws; @@ -136,7 +156,7 @@ main(int argc, char** argv) string s = wstringToString(ws); - ifstream nbis((dir + "coeur.utf8").c_str(), ios_base::binary); + IceUtilInternal::ifstream nbis((dir + "coeur.utf8"), ios_base::binary); test(nbis.good()); for(size_t i = 0; i < s.size(); ++i) @@ -160,5 +180,77 @@ main(int argc, char** argv) cout << "ok" << endl; } + { + cout << "testing UTF-8 filename... "; + IceUtilInternal::ifstream fn(dir + "filename.txt"); + string filename; + getline(fn, filename); + fn.close(); + + string filepath = dir + filename; + + { + IceUtilInternal::ofstream os(filepath); + test(os.is_open()); + os << "dummy"; + os.close(); + } + + IceUtilInternal::isAbsolutePath(filepath); + IceUtilInternal::structstat st; + test(IceUtilInternal::stat(filepath, &st) == 0); + + test(IceUtilInternal::mkdir(filepath + ".directory", 0777) == 0); + test(IceUtilInternal::directoryExists(filepath + ".directory")); + test(IceUtilInternal::rmdir(filepath + ".directory") == 0); + + int fd = IceUtilInternal::open(filepath, O_RDONLY); + test(fd > 0); +#if defined(_MSC_VER) && (_MSC_VER >= 1400) + test(_close(fd) == 0); +#else + test(close(fd) == 0); +#endif + + FILE* f = IceUtilInternal::fopen(filepath, "r"); + test(f != 0); + test(::fclose(f) == 0); + + IceUtilInternal::ifstream is(filepath); + string str; + getline(is, str); + test(str == "dummy"); + is.close(); + + IceUtilInternal::ifstream is2; + is2.open(filepath); + getline(is2, str); + test(str == "dummy"); + is2.close(); + + IceUtilInternal::ofstream os(filepath + ".out"); + os << "dummy" << endl; + os.close(); + + IceUtilInternal::ofstream os2; + os2.open(filepath + ".out", ios_base::app); + os2 << "dummy2" << endl; + os2.close(); + + IceUtilInternal::ifstream is3; + is3.open(filepath + ".out"); + getline(is3, str); + test(str == "dummy"); + getline(is3, str); + test(str == "dummy2"); + is3.close(); + + test(IceUtilInternal::unlink(filepath + ".out") == 0); + + IceUtilInternal::unlink(filepath); + + cout << "ok" << endl; + } + return EXIT_SUCCESS; } |