]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/path_test.cxx
Fix #1783: repeated error message on console
[simgear.git] / simgear / misc / path_test.cxx
index 459f064cdd78a3464851863b5badecfda75db4c6..61a9fba94ea77100b9d2741c8bf90ea561c8f0af 100644 (file)
@@ -41,6 +41,44 @@ void test_dir()
     }
     
     cout << temp.path().modTime() << endl;
+
+    std::cout << "Standard Locations:"
+              << "\n - Home:      " << SGPath::standardLocation(SGPath::HOME)
+              << "\n - Desktop:   " << SGPath::standardLocation(SGPath::DESKTOP)
+              << "\n - Downloads: " << SGPath::standardLocation(SGPath::DOWNLOADS)
+              << "\n - Documents: " << SGPath::standardLocation(SGPath::DOCUMENTS)
+              << "\n - Pictures:  " << SGPath::standardLocation(SGPath::PICTURES)
+              << std::endl;
+
+    VERIFY( !SGPath::standardLocation(SGPath::HOME     ).isNull() );
+    VERIFY( !SGPath::standardLocation(SGPath::DESKTOP  ).isNull() );
+    VERIFY( !SGPath::standardLocation(SGPath::DOWNLOADS).isNull() );
+    VERIFY( !SGPath::standardLocation(SGPath::DOCUMENTS).isNull() );
+    VERIFY( !SGPath::standardLocation(SGPath::PICTURES ).isNull() );
+}
+
+SGPath::Permissions validateNone(const SGPath&)
+{
+  SGPath::Permissions p;
+  p.read = false;
+  p.write = false;
+  return p;
+}
+
+SGPath::Permissions validateRead(const SGPath&)
+{
+  SGPath::Permissions p;
+  p.read = true;
+  p.write = false;
+  return p;
+}
+
+SGPath::Permissions validateWrite(const SGPath&)
+{
+  SGPath::Permissions p;
+  p.read = false;
+  p.write = true;
+  return p;
 }
 
 int main(int argc, char* argv[])
@@ -103,8 +141,12 @@ int main(int argc, char* argv[])
     
 // add
     pc.add("/opt/local");
+#ifdef _WIN32
+    COMPARE(pc.str(), std::string("/usr/local/include/;/opt/local"));
+#else
     COMPARE(pc.str(), std::string("/usr/local/include/:/opt/local"));
-    
+#endif
+
 // concat
     SGPath pd = pb;
     pd.concat("-1");
@@ -143,7 +185,26 @@ int main(int argc, char* argv[])
     COMPARE(pf.dir(), "");
     COMPARE(pf.lower_extension(), "gz");
     COMPARE(pf.complete_lower_extension(), "txt.gz");
-    
+
+    COMPARE(pf.canRead(), true);
+    COMPARE(pf.canWrite(), true);
+
+    SGPath pp(&validateNone);
+    COMPARE(pp.canRead(), false);
+    COMPARE(pp.canWrite(), false);
+
+    pp.append("./test-dir/file.txt");
+    COMPARE(pp.create_dir(0700), -3);
+
+    pp.setPermissionChecker(&validateRead);
+    COMPARE(pp.canRead(), true);
+    COMPARE(pp.canWrite(), false);
+    COMPARE(pp.create_dir(0700), -3);
+
+    pp.setPermissionChecker(&validateWrite);
+    COMPARE(pp.canRead(), false);
+    COMPARE(pp.canWrite(), true);
+
     test_dir();
     
     cout << "all tests passed OK" << endl;