]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/path_test.cxx
Fix VS2010 lack of fminf
[simgear.git] / simgear / misc / path_test.cxx
index d4a490c46fcaa068a6c68bde036a725f3c88a04d..94f9eaad296087a327e8669ecee9b157c45b9e9d 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <iostream>
 #include <cstdlib>
+#include <cstring>
 
 using std::cout;
 using std::cerr;
@@ -26,7 +27,7 @@ using std::endl;
 void test_dir()
 {
     simgear::Dir temp = simgear::Dir::tempDir("foo");
-    cout << "created:" << temp.path().str() << endl;
+    cout << "created:" << temp.path() << endl;
   
     VERIFY(temp.exists());
     VERIFY(temp.path().isDir());
@@ -40,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[])
@@ -81,7 +120,7 @@ int main(int argc, char* argv[])
     SGPath pj("/Foo/zot.dot/thing.tar.gz");
     COMPARE(pj.dir(), std::string("/Foo/zot.dot"));
     COMPARE(pj.file(), std::string("thing.tar.gz"));
-    COMPARE(pj.base(), std::string("/Foo/zot.dot/thing"));
+    COMPARE(pj.base(), std::string("/Foo/zot.dot/thing.tar"));
     COMPARE(pj.file_base(), std::string("thing"));
     COMPARE(pj.extension(), std::string("gz"));
     COMPARE(pj.complete_lower_extension(), std::string("tar.gz"));
@@ -123,7 +162,7 @@ int main(int argc, char* argv[])
     
     SGPath extB("BAH/FOO.HTML.GZ");
     COMPARE(extB.extension(), "GZ");
-    COMPARE(extB.base(), "BAH/FOO");
+    COMPARE(extB.base(), "BAH/FOO.HTML");
     COMPARE(extB.lower_extension(), "gz");
     COMPARE(extB.complete_lower_extension(), "html.gz");
 #ifdef _WIN32
@@ -134,7 +173,34 @@ int main(int argc, char* argv[])
 #else
     COMPARE(d1.str_native(), std::string("/usr/local"));
 #endif
-    
+  
+// paths with only the file components
+    SGPath pf("something.txt.gz");
+    COMPARE(pf.base(), "something.txt");
+    COMPARE(pf.file(), "something.txt.gz");
+    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;