remove POCO_WIN32_UTF8

This commit is contained in:
Günter Obiltschnig 2020-01-10 15:55:30 +01:00
parent c7c6871c4a
commit 7872c35324
5 changed files with 99 additions and 118 deletions

View File

@ -33,7 +33,7 @@
#include <sqlucode.h> #include <sqlucode.h>
#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8) #if defined(POCO_OS_FAMILY_WINDOWS)
#define POCO_ODBC_UNICODE #define POCO_ODBC_UNICODE
#define POCO_ODBC_UNICODE_WINDOWS #define POCO_ODBC_UNICODE_WINDOWS
#elif defined(POCO_OS_FAMILY_UNIX) && defined(UNICODE) #elif defined(POCO_OS_FAMILY_UNIX) && defined(UNICODE)

View File

@ -29,11 +29,7 @@ FileStreamTest::~FileStreamTest()
void FileStreamTest::testRead() void FileStreamTest::testRead()
{ {
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8) #if defined(POCO_OS_FAMILY_WINDOWS)
char tmp[]={'\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
std::string file(tmp);
file.append(".txt");
#elif defined(POCO_OS_FAMILY_WINDOWS)
char tmp[]={'\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'}; char tmp[]={'\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
std::string file(tmp); std::string file(tmp);
file.append(".txt"); file.append(".txt");
@ -57,11 +53,7 @@ void FileStreamTest::testRead()
void FileStreamTest::testWrite() void FileStreamTest::testWrite()
{ {
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8) #if defined(POCO_OS_FAMILY_WINDOWS)
char tmp[]={'\xdf', '\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
std::string file(tmp);
file = "dummy_" + file + (".txt");
#elif defined(POCO_OS_FAMILY_WINDOWS)
char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'}; char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
std::string file(tmp); std::string file(tmp);
file = "dummy_" + file + ".txt"; file = "dummy_" + file + ".txt";
@ -86,15 +78,9 @@ void FileStreamTest::testWrite()
void FileStreamTest::testReadWrite() void FileStreamTest::testReadWrite()
{ {
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
char tmp[]={'\xdf', '\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
std::string file(tmp);
file = "dummy_" + file + (".txt");
#else
char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'}; char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
std::string file(tmp); std::string file(tmp);
file = "dummy_" + file + ".txt"; file = "dummy_" + file + ".txt";
#endif
Poco::TemporaryFile::registerForDeletion(file); Poco::TemporaryFile::registerForDeletion(file);
@ -122,9 +108,9 @@ void FileStreamTest::testOpenModeIn()
Poco::File f("nonexistent.txt"); Poco::File f("nonexistent.txt");
if (f.exists()) if (f.exists())
f.remove(); f.remove();
try try
{ {
Poco::FileInputStream istr("nonexistent.txt"); Poco::FileInputStream istr("nonexistent.txt");
fail("nonexistent file - must throw"); fail("nonexistent file - must throw");
} }
@ -143,20 +129,20 @@ void FileStreamTest::testOpenModeOut()
Poco::File f("test.txt"); Poco::File f("test.txt");
if (f.exists()) if (f.exists())
f.remove(); f.remove();
Poco::FileOutputStream ostr1("test.txt"); Poco::FileOutputStream ostr1("test.txt");
ostr1 << "Hello, world!"; ostr1 << "Hello, world!";
ostr1.close(); ostr1.close();
assertTrue (f.exists()); assertTrue (f.exists());
assertTrue (f.getSize() != 0); assertTrue (f.getSize() != 0);
Poco::FileStream str1("test.txt"); Poco::FileStream str1("test.txt");
str1.close(); str1.close();
assertTrue (f.exists()); assertTrue (f.exists());
assertTrue (f.getSize() != 0); assertTrue (f.getSize() != 0);
Poco::FileOutputStream ostr2("test.txt"); Poco::FileOutputStream ostr2("test.txt");
ostr2.close(); ostr2.close();
@ -172,14 +158,14 @@ void FileStreamTest::testOpenModeTrunc()
Poco::File f("test.txt"); Poco::File f("test.txt");
if (f.exists()) if (f.exists())
f.remove(); f.remove();
Poco::FileOutputStream ostr1("test.txt"); Poco::FileOutputStream ostr1("test.txt");
ostr1 << "Hello, world!"; ostr1 << "Hello, world!";
ostr1.close(); ostr1.close();
assertTrue (f.exists()); assertTrue (f.exists());
assertTrue (f.getSize() != 0); assertTrue (f.getSize() != 0);
Poco::FileStream str1("test.txt", std::ios::trunc); Poco::FileStream str1("test.txt", std::ios::trunc);
str1.close(); str1.close();
@ -195,16 +181,16 @@ void FileStreamTest::testOpenModeAte()
Poco::FileOutputStream ostr("test.txt"); Poco::FileOutputStream ostr("test.txt");
ostr << "0123456789"; ostr << "0123456789";
ostr.close(); ostr.close();
Poco::FileStream str1("test.txt", std::ios::ate); Poco::FileStream str1("test.txt", std::ios::ate);
int c = str1.get(); int c = str1.get();
assertTrue (str1.eof()); assertTrue (str1.eof());
str1.clear(); str1.clear();
str1.seekg(0); str1.seekg(0);
c = str1.get(); c = str1.get();
assertTrue (c == '0'); assertTrue (c == '0');
str1.close(); str1.close();
Poco::FileStream str2("test.txt", std::ios::ate); Poco::FileStream str2("test.txt", std::ios::ate);
@ -222,15 +208,15 @@ void FileStreamTest::testOpenModeApp()
Poco::FileOutputStream ostr("test.txt"); Poco::FileOutputStream ostr("test.txt");
ostr << "0123456789"; ostr << "0123456789";
ostr.close(); ostr.close();
Poco::FileStream str1("test.txt", std::ios::app); Poco::FileStream str1("test.txt", std::ios::app);
str1 << "abc"; str1 << "abc";
str1.seekp(0); str1.seekp(0);
str1 << "def"; str1 << "def";
str1.close(); str1.close();
Poco::FileInputStream istr("test.txt"); Poco::FileInputStream istr("test.txt");
@ -245,35 +231,35 @@ void FileStreamTest::testSeek()
{ {
Poco::FileStream str("test.txt", std::ios::trunc); Poco::FileStream str("test.txt", std::ios::trunc);
str << "0123456789abcdef"; str << "0123456789abcdef";
str.seekg(0); str.seekg(0);
int c = str.get(); int c = str.get();
assertTrue (c == '0'); assertTrue (c == '0');
str.seekg(10); str.seekg(10);
assertTrue (str.tellg() == std::streampos(10)); assertTrue (str.tellg() == std::streampos(10));
c = str.get(); c = str.get();
assertTrue (c == 'a'); assertTrue (c == 'a');
assertTrue (str.tellg() == std::streampos(11)); assertTrue (str.tellg() == std::streampos(11));
str.seekg(-1, std::ios::end); str.seekg(-1, std::ios::end);
assertTrue (str.tellg() == std::streampos(15)); assertTrue (str.tellg() == std::streampos(15));
c = str.get(); c = str.get();
assertTrue (c == 'f'); assertTrue (c == 'f');
assertTrue (str.tellg() == std::streampos(16)); assertTrue (str.tellg() == std::streampos(16));
str.seekg(-1, std::ios::cur); str.seekg(-1, std::ios::cur);
assertTrue (str.tellg() == std::streampos(15)); assertTrue (str.tellg() == std::streampos(15));
c = str.get(); c = str.get();
assertTrue (c == 'f'); assertTrue (c == 'f');
assertTrue (str.tellg() == std::streampos(16)); assertTrue (str.tellg() == std::streampos(16));
str.seekg(-4, std::ios::cur); str.seekg(-4, std::ios::cur);
assertTrue (str.tellg() == std::streampos(12)); assertTrue (str.tellg() == std::streampos(12));
c = str.get(); c = str.get();
assertTrue (c == 'c'); assertTrue (c == 'c');
assertTrue (str.tellg() == std::streampos(13)); assertTrue (str.tellg() == std::streampos(13));
str.seekg(1, std::ios::cur); str.seekg(1, std::ios::cur);
assertTrue (str.tellg() == std::streampos(14)); assertTrue (str.tellg() == std::streampos(14));
c = str.get(); c = str.get();
@ -289,7 +275,7 @@ void FileStreamTest::testMultiOpen()
str << "abcdefghij\n"; str << "abcdefghij\n";
str << "klmnopqrst\n"; str << "klmnopqrst\n";
str.close(); str.close();
std::string s; std::string s;
str.open("test.txt", std::ios::in); str.open("test.txt", std::ios::in);
std::getline(str, s); std::getline(str, s);
@ -299,7 +285,7 @@ void FileStreamTest::testMultiOpen()
str.open("test.txt", std::ios::in); str.open("test.txt", std::ios::in);
std::getline(str, s); std::getline(str, s);
assertTrue (s == "0123456789"); assertTrue (s == "0123456789");
str.close(); str.close();
} }

View File

@ -380,7 +380,7 @@ void FileTest::testCopy()
f1.setWriteable().remove(); f1.setWriteable().remove();
} }
void FileTest::testCopyFailIfDestinationFileExists() void FileTest::testCopyFailIfDestinationFileExists()
{ {
std::ofstream ostr("testfile.dat"); std::ofstream ostr("testfile.dat");
ostr << "Hello, world!" << std::endl; ostr << "Hello, world!" << std::endl;
@ -499,7 +499,7 @@ void FileTest::testCopyDirectory()
fd3.remove(true); fd3.remove(true);
} }
void FileTest::testCopyDirectoryFailIfExists() void FileTest::testCopyDirectoryFailIfExists()
{ {
Path pd1("testdir"); Path pd1("testdir");
File fd1(pd1); File fd1(pd1);
@ -516,7 +516,7 @@ void FileTest::testCopyDirectoryFailIfExists()
std::ofstream ostr2(pf2.toString().c_str()); std::ofstream ostr2(pf2.toString().c_str());
ostr2 << "Hello, world!" << std::endl; ostr2 << "Hello, world!" << std::endl;
ostr2.close(); ostr2.close();
Path pd2("destination"); Path pd2("destination");
File fd2(pd2); File fd2(pd2);
try { try {
@ -584,7 +584,7 @@ void FileTest::testRenameFailIfExists() {
void FileTest::testLongPath() void FileTest::testLongPath()
{ {
#if defined(_WIN32) && defined(POCO_WIN32_UTF8) && !defined(_WIN32_WCE) #if defined(_WIN32) && !defined(_WIN32_WCE)
Poco::Path p("longpathtest"); Poco::Path p("longpathtest");
p.makeAbsolute(); p.makeAbsolute();
std::string longpath(p.toString()); std::string longpath(p.toString());
@ -601,7 +601,7 @@ void FileTest::testLongPath()
assertTrue (d.isDirectory()); assertTrue (d.isDirectory());
Poco::File f(p.toString()); Poco::File f(p.toString());
f.remove(true); f.remove(true);
#endif #endif
} }

View File

@ -17,16 +17,16 @@
#include "Poco/Environment.h" #include "Poco/Environment.h"
#include <iostream> #include <iostream>
#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
#if defined(POCO_OS_FAMILY_WINDOWS)
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
#include "Poco/Path_WINCE.h" #include "Poco/Path_WINCE.h"
#else #else
#include "Poco/Path_WIN32U.h" #include "Poco/Path_WIN32U.h"
#endif #endif
#elif defined(POCO_OS_FAMILY_WINDOWS)
#include "Poco/Path_WIN32.h"
#endif #endif
using Poco::Path; using Poco::Path;
using Poco::PathSyntaxException; using Poco::PathSyntaxException;
using Poco::Environment; using Poco::Environment;
@ -98,7 +98,7 @@ void PathTest::testParseUnix1()
assertTrue (!p.isDirectory()); assertTrue (!p.isDirectory());
assertTrue (p.isFile()); assertTrue (p.isFile());
assertTrue (p.toString(Path::PATH_UNIX) == "usr"); assertTrue (p.toString(Path::PATH_UNIX) == "usr");
p.parse("/usr/local", Path::PATH_UNIX); p.parse("/usr/local", Path::PATH_UNIX);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
assertTrue (p.isAbsolute()); assertTrue (p.isAbsolute());
@ -214,7 +214,7 @@ void PathTest::testParseUnix3()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin/"); assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin/");
p.parse("/usr/local/./bin/", Path::PATH_UNIX); p.parse("/usr/local/./bin/", Path::PATH_UNIX);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
assertTrue (p.isAbsolute()); assertTrue (p.isAbsolute());
@ -345,7 +345,7 @@ void PathTest::testParseUnix4()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_UNIX) == "../lib/"); assertTrue (p.toString(Path::PATH_UNIX) == "../lib/");
p.parse("a/b/c/d", Path::PATH_UNIX); p.parse("a/b/c/d", Path::PATH_UNIX);
assertTrue (p.isRelative()); assertTrue (p.isRelative());
assertTrue (!p.isAbsolute()); assertTrue (!p.isAbsolute());
@ -371,7 +371,7 @@ void PathTest::testParseUnix5()
assertTrue (p[1] == "system32"); assertTrue (p[1] == "system32");
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_UNIX) == "/c:/windows/system32/"); assertTrue (p.toString(Path::PATH_UNIX) == "/c:/windows/system32/");
} }
@ -467,7 +467,7 @@ void PathTest::testParseWindows2()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_WINDOWS) == "usr\\"); assertTrue (p.toString(Path::PATH_WINDOWS) == "usr\\");
p.parse("/usr/local", Path::PATH_WINDOWS); p.parse("/usr/local", Path::PATH_WINDOWS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
assertTrue (p.isAbsolute()); assertTrue (p.isAbsolute());
@ -574,7 +574,7 @@ void PathTest::testParseWindows2()
assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\bin\\"); assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\bin\\");
} }
void PathTest::testParseWindows3() void PathTest::testParseWindows3()
{ {
Path p; Path p;
@ -739,7 +739,7 @@ void PathTest::testParseWindows4()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\files\\"); assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\files\\");
p.parse("\\\\server\\files\\file", Path::PATH_WINDOWS); p.parse("\\\\server\\files\\file", Path::PATH_WINDOWS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
assertTrue (p.isAbsolute()); assertTrue (p.isAbsolute());
@ -770,7 +770,7 @@ void PathTest::testParseWindows4()
assertTrue (p.getNode() == "server"); assertTrue (p.getNode() == "server");
assertTrue (!p.isDirectory()); assertTrue (!p.isDirectory());
assertTrue (p.isFile()); assertTrue (p.isFile());
assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\files\\dir\\file"); assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\files\\dir\\file");
p.parse("\\\\server", Path::PATH_WINDOWS); p.parse("\\\\server", Path::PATH_WINDOWS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
@ -780,7 +780,7 @@ void PathTest::testParseWindows4()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\"); assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\");
p.parse("c:\\", Path::PATH_WINDOWS); p.parse("c:\\", Path::PATH_WINDOWS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
assertTrue (p.isAbsolute()); assertTrue (p.isAbsolute());
@ -788,7 +788,7 @@ void PathTest::testParseWindows4()
assertTrue (p.getDevice() == "c"); assertTrue (p.getDevice() == "c");
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\"); assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\");
p.parse("c:\\WinNT", Path::PATH_WINDOWS); p.parse("c:\\WinNT", Path::PATH_WINDOWS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
@ -797,7 +797,7 @@ void PathTest::testParseWindows4()
assertTrue (p.getDevice() == "c"); assertTrue (p.getDevice() == "c");
assertTrue (!p.isDirectory()); assertTrue (!p.isDirectory());
assertTrue (p.isFile()); assertTrue (p.isFile());
assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\WinNT"); assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\WinNT");
p.parse("c:\\WinNT\\", Path::PATH_WINDOWS); p.parse("c:\\WinNT\\", Path::PATH_WINDOWS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
@ -808,7 +808,7 @@ void PathTest::testParseWindows4()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\WinNT\\"); assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\WinNT\\");
try try
{ {
p.parse("~:\\", Path::PATH_WINDOWS); p.parse("~:\\", Path::PATH_WINDOWS);
@ -817,7 +817,7 @@ void PathTest::testParseWindows4()
catch (PathSyntaxException&) catch (PathSyntaxException&)
{ {
} }
try try
{ {
p.parse("c:file.txt", Path::PATH_WINDOWS); p.parse("c:file.txt", Path::PATH_WINDOWS);
@ -826,7 +826,7 @@ void PathTest::testParseWindows4()
catch (PathSyntaxException&) catch (PathSyntaxException&)
{ {
} }
p.parse("a\\b\\c\\d", Path::PATH_WINDOWS); p.parse("a\\b\\c\\d", Path::PATH_WINDOWS);
assertTrue (p.isRelative()); assertTrue (p.isRelative());
assertTrue (!p.isAbsolute()); assertTrue (!p.isAbsolute());
@ -850,7 +850,7 @@ void PathTest::testParseVMS1()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_VMS) == ""); assertTrue (p.toString(Path::PATH_VMS) == "");
p.parse("[]", Path::PATH_VMS); p.parse("[]", Path::PATH_VMS);
assertTrue (p.isRelative()); assertTrue (p.isRelative());
assertTrue (!p.isAbsolute()); assertTrue (!p.isAbsolute());
@ -858,7 +858,7 @@ void PathTest::testParseVMS1()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_VMS) == ""); assertTrue (p.toString(Path::PATH_VMS) == "");
p.parse("[foo]", Path::PATH_VMS); p.parse("[foo]", Path::PATH_VMS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
assertTrue (p.isAbsolute()); assertTrue (p.isAbsolute());
@ -896,7 +896,7 @@ void PathTest::testParseVMS1()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_VMS) == "[.foo.bar]"); assertTrue (p.toString(Path::PATH_VMS) == "[.foo.bar]");
p.parse("[foo.bar.foobar]", Path::PATH_VMS); p.parse("[foo.bar.foobar]", Path::PATH_VMS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
assertTrue (p.isAbsolute()); assertTrue (p.isAbsolute());
@ -933,7 +933,7 @@ void PathTest::testParseVMS2()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar]"); assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar]");
p.parse("[foo.][bar]", Path::PATH_VMS); p.parse("[foo.][bar]", Path::PATH_VMS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
assertTrue (p.isAbsolute()); assertTrue (p.isAbsolute());
@ -943,7 +943,7 @@ void PathTest::testParseVMS2()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar]"); assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar]");
p.parse("[foo.bar][foo]", Path::PATH_VMS); p.parse("[foo.bar][foo]", Path::PATH_VMS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
assertTrue (p.isAbsolute()); assertTrue (p.isAbsolute());
@ -954,7 +954,7 @@ void PathTest::testParseVMS2()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar.foo]"); assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar.foo]");
try try
{ {
p.parse("[foo.bar][.foo]", Path::PATH_VMS); p.parse("[foo.bar][.foo]", Path::PATH_VMS);
@ -972,7 +972,7 @@ void PathTest::testParseVMS2()
catch (PathSyntaxException&) catch (PathSyntaxException&)
{ {
} }
p.parse("[-]", Path::PATH_VMS); p.parse("[-]", Path::PATH_VMS);
assertTrue (p.isRelative()); assertTrue (p.isRelative());
assertTrue (!p.isAbsolute()); assertTrue (!p.isAbsolute());
@ -1192,7 +1192,7 @@ void PathTest::testParseVMS4()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_VMS) == "node::device:[foo.bar]"); assertTrue (p.toString(Path::PATH_VMS) == "node::device:[foo.bar]");
p.parse("node::device:[foo.bar.][goo]", Path::PATH_VMS); p.parse("node::device:[foo.bar.][goo]", Path::PATH_VMS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
assertTrue (p.isAbsolute()); assertTrue (p.isAbsolute());
@ -1205,7 +1205,7 @@ void PathTest::testParseVMS4()
assertTrue (p.isDirectory()); assertTrue (p.isDirectory());
assertTrue (!p.isFile()); assertTrue (!p.isFile());
assertTrue (p.toString(Path::PATH_VMS) == "node::device:[foo.bar.goo]"); assertTrue (p.toString(Path::PATH_VMS) == "node::device:[foo.bar.goo]");
p.parse("[]foo.txt", Path::PATH_VMS); p.parse("[]foo.txt", Path::PATH_VMS);
assertTrue (p.isRelative()); assertTrue (p.isRelative());
assertTrue (!p.isAbsolute()); assertTrue (!p.isAbsolute());
@ -1333,7 +1333,7 @@ void PathTest::testParseGuess()
assertTrue (p.getDevice() == "c"); assertTrue (p.getDevice() == "c");
assertTrue (!p.isDirectory()); assertTrue (!p.isDirectory());
assertTrue (p.isFile()); assertTrue (p.isFile());
assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\WinNT"); assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\WinNT");
p.parse("foo:bar.txt;5", Path::PATH_GUESS); p.parse("foo:bar.txt;5", Path::PATH_GUESS);
assertTrue (!p.isRelative()); assertTrue (!p.isRelative());
@ -1382,12 +1382,12 @@ void PathTest::testStatics()
assertTrue (!s.empty()); assertTrue (!s.empty());
Path p(s); Path p(s);
assertTrue (p.isDirectory() && p.isAbsolute()); assertTrue (p.isDirectory() && p.isAbsolute());
s = Path::home(); s = Path::home();
assertTrue (!s.empty()); assertTrue (!s.empty());
p = s; p = s;
assertTrue (p.isDirectory() && p.isAbsolute()); assertTrue (p.isDirectory() && p.isAbsolute());
s = Path::temp(); s = Path::temp();
assertTrue (!s.empty()); assertTrue (!s.empty());
p = s; p = s;
@ -1405,17 +1405,17 @@ void PathTest::testBaseNameExt()
assertTrue (p.getFileName() == "foo.bar"); assertTrue (p.getFileName() == "foo.bar");
assertTrue (p.getBaseName() == "foo"); assertTrue (p.getBaseName() == "foo");
assertTrue (p.getExtension() == "bar"); assertTrue (p.getExtension() == "bar");
p.setBaseName("readme"); p.setBaseName("readme");
assertTrue (p.getFileName() == "readme.bar"); assertTrue (p.getFileName() == "readme.bar");
assertTrue (p.getBaseName() == "readme"); assertTrue (p.getBaseName() == "readme");
assertTrue (p.getExtension() == "bar"); assertTrue (p.getExtension() == "bar");
p.setExtension("txt"); p.setExtension("txt");
assertTrue (p.getFileName() == "readme.txt"); assertTrue (p.getFileName() == "readme.txt");
assertTrue (p.getBaseName() == "readme"); assertTrue (p.getBaseName() == "readme");
assertTrue (p.getExtension() == "txt"); assertTrue (p.getExtension() == "txt");
p.setExtension("html"); p.setExtension("html");
assertTrue (p.getFileName() == "readme.html"); assertTrue (p.getFileName() == "readme.html");
assertTrue (p.getBaseName() == "readme"); assertTrue (p.getBaseName() == "readme");
@ -1434,7 +1434,7 @@ void PathTest::testAbsolute()
Path rel("Poco"); Path rel("Poco");
Path abs = rel.absolute(base); Path abs = rel.absolute(base);
assertTrue (abs.toString(Path::PATH_WINDOWS) == "C:\\Program Files\\Poco"); assertTrue (abs.toString(Path::PATH_WINDOWS) == "C:\\Program Files\\Poco");
base.parse("/usr/local", Path::PATH_UNIX); base.parse("/usr/local", Path::PATH_UNIX);
rel.parse("Poco/include", Path::PATH_UNIX); rel.parse("Poco/include", Path::PATH_UNIX);
abs = rel.absolute(base); abs = rel.absolute(base);
@ -1516,7 +1516,7 @@ void PathTest::testExpand()
#if defined(POCO_OS_FAMILY_UNIX) #if defined(POCO_OS_FAMILY_UNIX)
std::string s = Path::expand("~/.bashrc"); std::string s = Path::expand("~/.bashrc");
assertTrue (s == Path::expand("$HOME/.bashrc")); assertTrue (s == Path::expand("$HOME/.bashrc"));
assertTrue (s == Environment::get("HOME") + "/.bashrc" || assertTrue (s == Environment::get("HOME") + "/.bashrc" ||
s == Environment::get("HOME") + "//.bashrc"); s == Environment::get("HOME") + "//.bashrc");
Path p(s); Path p(s);
s = Path::expand("$HOME/.bashrc"); s = Path::expand("$HOME/.bashrc");
@ -1565,7 +1565,7 @@ void PathTest::testFind()
#endif #endif
assertTrue (found); assertTrue (found);
assertTrue (!notfound); assertTrue (!notfound);
std::string fn = p.toString(); std::string fn = p.toString();
assertTrue (fn.size() > 0); assertTrue (fn.size() > 0);
} }
@ -1586,15 +1586,15 @@ void PathTest::testResolve()
Path p("c:\\foo\\", Path::PATH_WINDOWS); Path p("c:\\foo\\", Path::PATH_WINDOWS);
p.resolve("test.dat"); p.resolve("test.dat");
assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\foo\\test.dat"); assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\foo\\test.dat");
p.assign("c:\\foo\\", Path::PATH_WINDOWS); p.assign("c:\\foo\\", Path::PATH_WINDOWS);
p.resolve(Path("d:\\bar.txt", Path::PATH_WINDOWS)); p.resolve(Path("d:\\bar.txt", Path::PATH_WINDOWS));
assertTrue (p.toString(Path::PATH_WINDOWS) == "d:\\bar.txt"); assertTrue (p.toString(Path::PATH_WINDOWS) == "d:\\bar.txt");
p.assign("c:\\foo\\bar.txt", Path::PATH_WINDOWS); p.assign("c:\\foo\\bar.txt", Path::PATH_WINDOWS);
p.resolve("foo.txt"); p.resolve("foo.txt");
assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\foo\\foo.txt"); assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\foo\\foo.txt");
p.assign("c:\\foo\\bar\\", Path::PATH_WINDOWS); p.assign("c:\\foo\\bar\\", Path::PATH_WINDOWS);
p.resolve(Path("..\\baz\\test.dat", Path::PATH_WINDOWS)); p.resolve(Path("..\\baz\\test.dat", Path::PATH_WINDOWS));
assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\foo\\baz\\test.dat"); assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\foo\\baz\\test.dat");

View File

@ -42,7 +42,7 @@ public:
initialize(); initialize();
open(); open();
} }
~ArchiveImpl() ~ArchiveImpl()
{ {
try try
@ -54,27 +54,27 @@ public:
poco_unexpected(); poco_unexpected();
} }
} }
const std::string& path() const const std::string& path() const
{ {
return _path; return _path;
} }
std::size_t size() const std::size_t size() const
{ {
return _entries.size(); return _entries.size();
} }
Archive::ConstIterator begin() const Archive::ConstIterator begin() const
{ {
return _entries.begin(); return _entries.begin();
} }
Archive::ConstIterator end() const Archive::ConstIterator end() const
{ {
return _entries.end(); return _entries.end();
} }
std::string extract(const ArchiveEntry& entry, const std::string& destPath) std::string extract(const ArchiveEntry& entry, const std::string& destPath)
{ {
Poco::Path basePath; Poco::Path basePath;
@ -91,19 +91,19 @@ public:
Poco::Path extractedPath(basePath); Poco::Path extractedPath(basePath);
extractedPath.append(entryPath); extractedPath.append(entryPath);
extractedPath.makeAbsolute(); extractedPath.makeAbsolute();
if (entry.isFile()) if (entry.isFile())
{ {
Poco::UInt32 blockIndex = 0; Poco::UInt32 blockIndex = 0;
Byte* pOutBuffer = 0; Byte* pOutBuffer = 0;
std::size_t outBufferSize = 0; std::size_t outBufferSize = 0;
std::size_t offset = 0; std::size_t offset = 0;
std::size_t extractedSize = 0; std::size_t extractedSize = 0;
int err = SzArEx_Extract( int err = SzArEx_Extract(
&_db, &_db,
&_lookStream.s, &_lookStream.s,
entry.index(), entry.index(),
&blockIndex, &blockIndex,
&pOutBuffer, &pOutBuffer,
&outBufferSize, &outBufferSize,
&offset, &offset,
@ -115,7 +115,7 @@ public:
try try
{ {
poco_assert (extractedSize == entry.size()); poco_assert (extractedSize == entry.size());
Poco::Path parent = extractedPath.parent(); Poco::Path parent = extractedPath.parent();
Poco::File dir(parent.toString()); Poco::File dir(parent.toString());
dir.createDirectories(); dir.createDirectories();
@ -140,10 +140,10 @@ public:
Poco::File dir(extractedPath.toString()); Poco::File dir(extractedPath.toString());
dir.createDirectories(); dir.createDirectories();
} }
return extractedPath.toString(); return extractedPath.toString();
} }
protected: protected:
void initialize() void initialize()
{ {
@ -162,20 +162,15 @@ protected:
{ {
checkFile(); checkFile();
#if defined(_WIN32) && defined(POCO_WIN32_UTF8) #if defined(_WIN32)
std::wstring wpath; std::wstring wpath;
Poco::UnicodeConverter::toUTF16(_path, wpath); Poco::UnicodeConverter::toUTF16(_path, wpath);
if (InFile_OpenW(&_archiveStream.file, wpath.c_str()) != SZ_OK) if (InFile_OpenW(&_archiveStream.file, wpath.c_str()) != SZ_OK)
{ {
throw Poco::OpenFileException(_path); throw Poco::OpenFileException(_path);
} }
#else
if (InFile_Open(&_archiveStream.file, _path.c_str()) != SZ_OK)
{
throw Poco::OpenFileException(_path);
}
#endif #endif
_lookStream.realStream = &_archiveStream.s; _lookStream.realStream = &_archiveStream.s;
LookToRead_Init(&_lookStream); LookToRead_Init(&_lookStream);
@ -185,29 +180,29 @@ protected:
{ {
loadEntries(); loadEntries();
} }
else else
{ {
handleError(err); handleError(err);
} }
} }
void close() void close()
{ {
SzArEx_Free(&_db, &_szAlloc); SzArEx_Free(&_db, &_szAlloc);
File_Close(&_archiveStream.file); File_Close(&_archiveStream.file);
} }
void loadEntries() void loadEntries()
{ {
_entries.reserve(_db.db.NumFiles); _entries.reserve(_db.db.NumFiles);
for (Poco::UInt32 i = 0; i < _db.db.NumFiles; i++) for (Poco::UInt32 i = 0; i < _db.db.NumFiles; i++)
{ {
const CSzFileItem *f = _db.db.Files + i; const CSzFileItem *f = _db.db.Files + i;
ArchiveEntry::EntryType type = f->IsDir ? ArchiveEntry::ENTRY_DIRECTORY : ArchiveEntry::ENTRY_FILE; ArchiveEntry::EntryType type = f->IsDir ? ArchiveEntry::ENTRY_DIRECTORY : ArchiveEntry::ENTRY_FILE;
Poco::UInt32 attributes = f->AttribDefined ? f->Attrib : 0; Poco::UInt32 attributes = f->AttribDefined ? f->Attrib : 0;
Poco::UInt64 size = f->Size; Poco::UInt64 size = f->Size;
std::vector<Poco::UInt16> utf16Path; std::vector<Poco::UInt16> utf16Path;
std::size_t utf16PathLen = SzArEx_GetFileNameUtf16(&_db, i, 0); std::size_t utf16PathLen = SzArEx_GetFileNameUtf16(&_db, i, 0);
utf16Path.resize(utf16PathLen, 0); utf16Path.resize(utf16PathLen, 0);
@ -218,7 +213,7 @@ protected:
Poco::TextConverter converter(utf16Encoding, utf8Encoding); Poco::TextConverter converter(utf16Encoding, utf8Encoding);
std::string utf8Path; std::string utf8Path;
converter.convert(&utf16Path[0], (int) utf16PathLen*sizeof(Poco::UInt16), utf8Path); converter.convert(&utf16Path[0], (int) utf16PathLen*sizeof(Poco::UInt16), utf8Path);
Poco::Timestamp lastModified(0); Poco::Timestamp lastModified(0);
if (f->MTimeDefined) if (f->MTimeDefined)
{ {
@ -228,12 +223,12 @@ protected:
tv /= 10; tv /= 10;
lastModified = tv; lastModified = tv;
} }
ArchiveEntry entry(type, utf8Path, size, lastModified, attributes, i); ArchiveEntry entry(type, utf8Path, size, lastModified, attributes, i);
_entries.push_back(entry); _entries.push_back(entry);
} }
} }
void checkFile() void checkFile()
{ {
Poco::File f(_path); Poco::File f(_path);
@ -250,13 +245,13 @@ protected:
throw Poco::FileAccessDeniedException(_path); throw Poco::FileAccessDeniedException(_path);
} }
} }
void handleError(int err) void handleError(int err)
{ {
std::string arg; std::string arg;
handleError(err, arg); handleError(err, arg);
} }
void handleError(int err, const std::string& arg) void handleError(int err, const std::string& arg)
{ {
switch (err) switch (err)
@ -308,7 +303,7 @@ Archive::Archive(const std::string& path):
{ {
} }
Archive::~Archive() Archive::~Archive()
{ {
delete _pImpl; delete _pImpl;
@ -320,7 +315,7 @@ const std::string& Archive::path() const
return _pImpl->path(); return _pImpl->path();
} }
std::size_t Archive::size() const std::size_t Archive::size() const
{ {
return _pImpl->size(); return _pImpl->size();
@ -332,7 +327,7 @@ Archive::ConstIterator Archive::begin() const
return _pImpl->begin(); return _pImpl->begin();
} }
Archive::ConstIterator Archive::end() const Archive::ConstIterator Archive::end() const
{ {
return _pImpl->end(); return _pImpl->end();
@ -365,7 +360,7 @@ void Archive::extract(const std::string& destPath)
} }
} }
std::string Archive::extract(const ArchiveEntry& entry, const std::string& destPath) std::string Archive::extract(const ArchiveEntry& entry, const std::string& destPath)
{ {
return _pImpl->extract(entry, destPath); return _pImpl->extract(entry, destPath);