mirror of https://github.com/KLayout/klayout.git
Made tl::parent_path require existing parent - otherwise the previous implementation returned true always.
This commit is contained in:
parent
7504293c28
commit
ce951b29ec
|
|
@ -34,13 +34,18 @@ bool
|
||||||
is_parent_path (const QString &parent, const QString &path)
|
is_parent_path (const QString &parent, const QString &path)
|
||||||
{
|
{
|
||||||
QFileInfo parent_info (parent);
|
QFileInfo parent_info (parent);
|
||||||
|
if (! parent_info.exists ()) {
|
||||||
|
// If the parent path does not exist, we always return false. This cannot be a parent.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QFileInfo path_info (path);
|
QFileInfo path_info (path);
|
||||||
|
|
||||||
while (parent_info != path_info) {
|
while (parent_info != path_info) {
|
||||||
path_info = path_info.path ();
|
|
||||||
if (path_info.isRoot ()) {
|
if (path_info.isRoot ()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
path_info = path_info.path ();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,19 @@
|
||||||
|
|
||||||
TEST (1)
|
TEST (1)
|
||||||
{
|
{
|
||||||
EXPECT_EQ (tl::is_parent_path (std::string ("/home"), "/home/matthias"), true);
|
EXPECT_EQ (tl::is_parent_path (std::string ("."), "./doesnotexist"), true);
|
||||||
EXPECT_EQ (tl::is_parent_path (std::string ("/home"), "/home"), true);
|
EXPECT_EQ (tl::is_parent_path (std::string ("./doesnotexist"), "./alsodoesnotexist"), false);
|
||||||
EXPECT_EQ (tl::is_parent_path (std::string (""), ""), true);
|
EXPECT_EQ (tl::is_parent_path (std::string ("."), "."), true);
|
||||||
EXPECT_EQ (tl::is_parent_path (std::string ("/opt/klayout"), "/home/matthias"), false);
|
|
||||||
EXPECT_EQ (tl::is_parent_path (std::string ("/home/klayout"), "/home/matthias"), false);
|
QString p = QFileInfo (tl::to_qstring (tmp_file ())).path ();
|
||||||
|
QDir (p).mkdir (QString::fromUtf8 ("x"));
|
||||||
|
QDir (p).mkdir (QString::fromUtf8 ("y"));
|
||||||
|
EXPECT_EQ (tl::is_parent_path (tl::to_string (p), tl::to_string (p)), true);
|
||||||
|
EXPECT_EQ (tl::is_parent_path (tl::to_string (p), tl::to_string (p) + "/x"), true);
|
||||||
|
EXPECT_EQ (tl::is_parent_path (tl::to_string (p) + "/x", tl::to_string (p) + "/x"), true);
|
||||||
|
EXPECT_EQ (tl::is_parent_path (tl::to_string (p) + "/x", tl::to_string (p) + "/y"), false);
|
||||||
|
EXPECT_EQ (tl::is_parent_path (tl::to_string (QDir::root ().absolutePath ()), tl::to_string (p) + "/y"), true);
|
||||||
|
EXPECT_EQ (tl::is_parent_path (tl::to_string (QDir::root ().absolutePath ()), tl::to_string (p)), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST (2)
|
TEST (2)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue