mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 17:25:03 +02:00
Use POCO_BASE for looking for test data directory.
Signed-off-by: FrancisANDRE <zosrothko@orange.fr>
This commit is contained in:
parent
5d08905f02
commit
3c2a83d2ee
@ -17,6 +17,9 @@
|
|||||||
#include "Poco/Path.h"
|
#include "Poco/Path.h"
|
||||||
#include "Poco/File.h"
|
#include "Poco/File.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
#include "Poco/Environment.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
using Poco::SharedMemory;
|
using Poco::SharedMemory;
|
||||||
@ -43,7 +46,7 @@ void SharedMemoryTest::testCreate()
|
|||||||
|
|
||||||
void SharedMemoryTest::testCreateFromFile()
|
void SharedMemoryTest::testCreateFromFile()
|
||||||
{
|
{
|
||||||
Poco::Path p = findDataFile("testdata.txt");
|
Poco::Path p = findDataFile("data", "testdata.txt");
|
||||||
Poco::File f(p);
|
Poco::File f(p);
|
||||||
assert (f.exists() && f.isFile());
|
assert (f.exists() && f.isFile());
|
||||||
SharedMemory mem(f, SharedMemory::AM_READ);
|
SharedMemory mem(f, SharedMemory::AM_READ);
|
||||||
@ -54,24 +57,28 @@ void SharedMemoryTest::testCreateFromFile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Poco::Path SharedMemoryTest::findDataFile(const std::string& afile)
|
Poco::Path SharedMemoryTest::findDataFile(const std::string& directory, const std::string& file)
|
||||||
{
|
{
|
||||||
Poco::Path root;
|
std::ostringstream ostr;
|
||||||
root.makeAbsolute();
|
ostr << directory << '/' << file;
|
||||||
Poco::Path result;
|
std::string validDir(ostr.str());
|
||||||
while (!Poco::Path::find(root.toString(), "data", result))
|
Poco::Path pathPattern(validDir);
|
||||||
|
if (Poco::File(pathPattern).exists())
|
||||||
{
|
{
|
||||||
root.makeParent();
|
return pathPattern;
|
||||||
if (root.toString().empty() || root.toString() == "/" || root.toString() == "\\")
|
|
||||||
throw Poco::FileNotFoundException("Didn't find data subdir");
|
|
||||||
}
|
}
|
||||||
result.makeDirectory();
|
|
||||||
result.setFileName(afile);
|
ostr.str("");
|
||||||
Poco::File aFile(result.toString());
|
ostr << "/Foundation/testsuite/" << directory << '/' << file;
|
||||||
if (!aFile.exists() || (aFile.exists() && !aFile.isFile()))
|
validDir = Poco::Environment::get("POCO_BASE") + ostr.str();
|
||||||
throw Poco::FileNotFoundException("Didn't find file " + afile);
|
pathPattern = validDir;
|
||||||
|
|
||||||
return result;
|
if (!Poco::File(pathPattern).exists())
|
||||||
|
{
|
||||||
|
std::cout << "Can't find " << validDir << std::endl;
|
||||||
|
throw Poco::NotFoundException("cannot locate directory containing valid Zip test files");
|
||||||
|
}
|
||||||
|
return pathPattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
static Poco::Path findDataFile(const std::string& afile);
|
static Poco::Path findDataFile(const std::string& directory, const std::string& file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user