int main() { // auto tests int init_size = 3; Queue q; int input [] = {1, 2, 3}; q.enqueue(init_size, input); test(to_char(init_size) + " in queue", init_size, q.count()); q.dequeue(); test(to_char(init_size-1) + " in queue", init_size-1, q.count()); // manual input d7(); system("pause"); return 0; }
void dpps::Pattern_random::generate () { // We have do declare them all. We cannot do a switch of if, // because distributions would get out of scope. // The only other possibility would be to place the switch inside // the loop, but it would be very inefficient to call the constructor // everytime. // So we have to pay for overhead and initialize them all in te beginning. // It's probably a negligible amount of time and memory as compared to the // loop. // signification of parametres depends on the engine. Some engines // need only one parametre. // For all user-changeable values (p1 and p2), 1.0 would have been the // default if we had not specified it, so it is an acceptable value for the // user as well. const double p1 {pattern_settings. p1} ; const double p2 {pattern_settings. p2} ; std::uniform_real_distribution<double> d0 (-p1, p1) ; // min, max // Normal-type std::normal_distribution<double> d1 (0.0, p1) ; // average = 0, sigma std::lognormal_distribution<double> d2 (0.0, p1) ; // average = 0, m std::chi_squared_distribution<double> d3 (p1) ; // n std::cauchy_distribution<double> d4 (p1, p2) ; // a, b std::fisher_f_distribution<double> d5 (p1, p2) ; // m, n std::student_t_distribution<double> d6 (p1) ; // n // Poisson-type std::exponential_distribution<double> d7 (p1) ; // lambda std::gamma_distribution<double> d8 (p1, p2) ; // alpha, beta std::weibull_distribution<double> d9 (p1, p2) ; // a, b Polyline p ; p. closed = true ; double x {0.0}, y {0.0} ; long_unsigned_int i {0}, attempts {0} ; //const double s {pattern_settings. side / 2.0} ; if (pattern_settings. max_attempts < pattern_settings. number) pattern_settings. max_attempts = std::numeric_limits<long_unsigned_int>::max () ; //std::cout << "hello" << i << " " << pattern_settings. number << " " << attempts << " " << pattern_settings. max_attempts << std::endl ; while ((i < pattern_settings. number) && (attempts < pattern_settings. max_attempts)) { bool overlap = false ; switch (pattern_settings. type) { case type_uniform_real_distribution: // 0 x = d0 (pseudorandom_generator) ; y = d0 (pseudorandom_generator) ; //std::cout << "alea 0 : " << x << " " << y << std::endl ; break ; case type_normal_distribution: // 1 x = d1 (pseudorandom_generator) ; y = d1 (pseudorandom_generator) ; break ; case type_lognormal_distribution: // 2 x = d2 (pseudorandom_generator) ; y = d2 (pseudorandom_generator) ; break ; case type_chi_squared_distribution: // 3 x = d3 (pseudorandom_generator) ; y = d3 (pseudorandom_generator) ; break ; case type_cauchy_distribution: // 4 x = d4 (pseudorandom_generator) ; y = d4 (pseudorandom_generator) ; break ; case type_fisher_f_distribution: // 5 x = d5 (pseudorandom_generator) ; y = d5 (pseudorandom_generator) ; break ; case type_student_t_distribution: // 6 x = d6 (pseudorandom_generator) ; y = d6 (pseudorandom_generator) ; break ; case type_exponential_distribution: // 7 x = d7 (pseudorandom_generator) ; y = d7 (pseudorandom_generator) ; break ; case type_gamma_distribution: // 8 x = d8 (pseudorandom_generator) ; y = d8 (pseudorandom_generator) ; break ; case type_weibull_distribution: // 9 x = d9 (pseudorandom_generator) ; y = d9 (pseudorandom_generator) ; break ; default: break ; } if (pattern_settings. avoid_overlap) { for (long_unsigned_int j = 0 ; j < polylines. size () ; j++) { if ((polylines[j]. vertices[0] - Vertex(x, y)).norm2_square() < pattern_settings. diametre*pattern_settings. diametre) { overlap = true ; break ; } } } bool within_limits = (((fabs (x - pattern_settings. x0) < pattern_settings. lx / 2.0) || (pattern_settings. lx <= 0)) && ((fabs (y - pattern_settings. y0) < pattern_settings. ly / 2.0) || (pattern_settings. ly <= 0))) ; // Either we are inside lx, or user set it to negative to disable it. if (within_limits && !overlap) { p. push_back (Vertex (x, y)) ; p. dose = pattern_settings. diametre ; polylines. push_back (p) ; p. vertices. clear () ; // does not change that p. closed == true ; i++ ; } attempts++ ; } }
static void OidTest() { Oid d1; ACE_ASSERT(d1.valid() == 0); ACE_ASSERT(d1.length() == 0); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Oid:d1(\"\") [%s]\n", d1.to_string())); Oid d2("1.2.3"); ACE_ASSERT(d2.valid() == 1); ACE_ASSERT(d2.length() == 3); ACE_ASSERT(d2[0] == (unsigned long) 1); ACE_ASSERT(d2[1] == (unsigned long) 2); ACE_ASSERT(d2[2] == (unsigned long) 3); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Oid:d2(\"1.2.3\") [%s]\n", d2.to_string())); Oid d3(d2); ACE_ASSERT(d3.valid() == 1); ACE_ASSERT(d3.length() == 3); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Oid:d3(\"d2\") [%s]\n", d3.to_string())); unsigned long t[3] = {2,3,4}; Oid d4((unsigned long *)&t, sizeof(t)/sizeof(long)); ACE_ASSERT(d4.valid() == 1); ACE_ASSERT(d4.length() == 3); ACE_ASSERT(d4[0] == (unsigned long) 2); ACE_ASSERT(d4[1] == (unsigned long) 3); ACE_ASSERT(d4[2] == (unsigned long) 4); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Oid:d4(\"long(2.3.4)\") [%s]\n", d4.to_string())); // suboid Oid d5; ACE_ASSERT(d4.suboid(d5, 1,1) == 0); // 2,3,4, 1,1 == 3 ACE_ASSERT(d5.length() == 1); ACE_ASSERT(d5.valid() == 1); ACE_ASSERT(d5[0] == 3); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Oid:d6::suboid(d5,1,1) [%s]\n", d5.to_string())); // trim Oid d7(d4); ACE_ASSERT(d7.valid() == 1); d7.trim(); ACE_ASSERT(d7.length() == d4.length() -1); // compare methods ACE_ASSERT(d7.left_comparison( d7.length(), d7) == 0); ACE_ASSERT(d4.right_comparison( d4.length(), d4) == 0); // assignment d1 = d4; ACE_ASSERT(d1.valid() == 1); ACE_ASSERT(d1 == d4); d2 = "5.6.7"; ACE_ASSERT(d2.valid() == 1); ACE_ASSERT(d2[2] == (unsigned long) 7); d1 = "8.9.10"; ACE_ASSERT(d1.valid() == 1); // concat unsigned long ll = ULONG_MAX; d1 = ""; d1 += (unsigned long)0; d1 += ll; d1 += ll; d1 += "0"; ACE_ASSERT(d1.valid() == 1); ACE_ASSERT(d1.length() == 4); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Oid:d1(0,max,max,0) [%s]\n", d1.to_string())); ACE_ASSERT(d1[0] == (unsigned long)0); ACE_ASSERT(d1[1] == ll); ACE_ASSERT(d1[2] == ll); ACE_ASSERT(d1[3] == (unsigned long)0); d2 += d1; ACE_ASSERT(d2.valid() == 1); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Oid:(5.6.7.8.9.10) [%s]\n", d2.to_string())); // test out max Oid string... // relational operators oid,oid ACE_ASSERT(d2 == d2); ACE_ASSERT(!(d2 != d2)); ACE_ASSERT(!(d2 < d2)); ACE_ASSERT(!(d2 > d2)); ACE_ASSERT(d2 >= d2); ACE_ASSERT(d2 <= d2); }
main(int argc, char* argv) { config(); bool do_socks = false; if( argc > 1 ) { do_socks = true; } dprintf( dflag, "\nExternal interface (local daemon)\n\n" ); testAPI( NULL, do_socks ); dprintf( dflag, "\nExternal interface (bad hostname)\n\n" ); testAPI( "bazzle", do_socks ); dprintf( dflag, "\nLocal daemons\n\n" ); makeAndDisplayCM( NULL, NULL ); makeAndDisplayRegular( NULL, NULL ); dprintf( dflag, "\nRemote daemons we should find\n\n" ); makeAndDisplayCM( "condor", "condor" ); makeAndDisplayRegular( "puck.cs.wisc.edu", "condor" ); dprintf( dflag, "\nWe should find the startd, but not the others\n\n" ); makeAndDisplayRegular( "*****@*****.**", NULL ); dprintf( dflag, "\nUsing a bogus sinful string\n\n" ); Daemon d( DT_NEGOTIATOR, "<128.105.232.240:23232>" ); if( d.locate() ) { dprintf( dflag, "Found %s\n", d.idStr() ); d.display( dflag ); } else { dprintf( dflag, "%s\n", d.error() ); } dprintf( dflag, "\nMake a local STARTD w/ explicit name\n\n" ); Daemon d2( DT_STARTD, get_local_fqdn().Value() ); if( d2.locate() ) { d2.display( dflag ); } else { dprintf( dflag, "%s\n", d2.error() ); } dprintf( dflag, "\nMake a local COLLECTOR w/ explicit name\n\n" ); Daemon d3( DT_COLLECTOR, "turkey.cs.wisc.edu" ); if( d3.locate() ) { d3.display( dflag ); } else { dprintf( dflag, "%s\n", d3.error() ); } dprintf( dflag, "\nUse idStr for a remote STARTD\n\n" ); Daemon d4( DT_STARTD, "puck.cs.wisc.edu" ); if( d4.locate() ) { dprintf( dflag, "Found %s\n", d4.idStr() ); } else { dprintf( dflag, "%s\n", d4.error() ); } dprintf( dflag, "\nTest socks on a valid Daemon that isn't up\n\n" ); Daemon d5( DT_SCHEDD, "cabernet.cs.wisc.edu" ); testSocks( &d5 ); dprintf( dflag, "\nCM where you specify pool and not name\n\n" ); Daemon d6( DT_COLLECTOR, NULL, "condor" ); if( d6.locate() ) { d6.display( dflag ); } else { dprintf( dflag, "%s\n", d6.error() ); } dprintf( dflag, "\nUsing sinful string for the collector\n\n" ); Daemon d7( DT_COLLECTOR, "<128.105.143.16:9618>" ); if( d7.locate() ) { dprintf( dflag, "Found %s\n", d7.idStr() ); d7.display( dflag ); } else { dprintf( dflag, "%s\n", d7.error() ); } dprintf( dflag, "\nRemote daemons we should NOT find\n\n" ); makeAndDisplayRegular( "bazzle.cs.wisc.edu", "condor" ); makeAndDisplayCM( "bazzle", "bazzle" ); }
int main (int, char**) { UnitTest t (110); // Ensure environment has no influence. unsetenv ("TASKDATA"); unsetenv ("TASKRC"); // Path (); Path p0; t.is (p0._data, "", "Path::Path"); // Path (const Path&); Path p1 = Path ("foo"); t.is (p1._data, Directory::cwd () + "/foo", "Path::operator="); // Path (const std::string&); Path p2 ("~"); t.ok (p2._data != "~", "~ expanded to " + p2._data); Path p3 ("/tmp"); t.ok (p3._data == "/tmp", "/tmp -> /tmp"); // operator== t.notok (p2 == p3, "p2 != p3"); // Path& operator= (const Path&); Path p3_copy (p3); t.is (p3._data, p3_copy._data, "Path::Path (Path&)"); // operator (std::string) const; t.is ((std::string) p3, "/tmp", "Path::operator (std::string) const"); // std::string name () const; Path p4 ("/a/b/c/file.ext"); t.is (p4.name (), "file.ext", "/a/b/c/file.ext name is file.ext"); // std::string parent () const; t.is (p4.parent (), "/a/b/c", "/a/b/c/file.ext parent is /a/b/c"); // std::string extension () const; t.is (p4.extension (), "ext", "/a/b/c/file.ext extension is ext"); // bool exists () const; t.ok (p2.exists (), "~ exists"); t.ok (p3.exists (), "/tmp exists"); // bool is_directory () const; t.ok (p2.is_directory (), "~ is_directory"); t.ok (p3.is_directory (), "/tmp is_directory"); // bool is_link () const; t.notok (p2.is_link (), "~ !is_link"); // bool readable () const; t.ok (p2.readable (), "~ readable"); t.ok (p3.readable (), "/tmp readable"); // bool writable () const; t.ok (p2.writable (), "~ writable"); t.ok (p3.writable (), "/tmp writable"); // bool executable () const; t.ok (p2.executable (), "~ executable"); t.ok (p3.executable (), "/tmp executable"); // static std::string expand (const std::string&); t.ok (Path::expand ("~") != "~", "Path::expand ~ != ~"); t.ok (Path::expand ("~/") != "~/", "Path::expand ~/ != ~/"); // static std::vector <std::string> glob (const std::string&); std::vector <std::string> out = Path::glob ("/tmp"); t.ok (out.size () == 1, "/tmp -> 1 result"); t.is (out[0], "/tmp", "/tmp -> /tmp"); out = Path::glob ("/t?p"); t.ok (out.size () == 1, "/t?p -> 1 result"); t.is (out[0], "/tmp", "/t?p -> /tmp"); out = Path::glob ("/[s-u]mp"); t.ok (out.size () == 1, "/[s-u]mp -> 1 result"); t.is (out[0], "/tmp", "/[s-u]mp -> /tmp"); // bool is_absolute () const; t.notok (p0.is_absolute (), "'' !is_absolute"); t.ok (p1.is_absolute (), "foo is_absolute"); t.ok (p2.is_absolute (), "~ is_absolute (after expansion)"); t.ok (p3.is_absolute (), "/tmp is_absolute"); t.ok (p4.is_absolute (), "/a/b/c/file.ext is_absolute"); Directory tmp ("tmp"); tmp.create (); t.ok (tmp.exists (), "tmp dir created."); File::write ("tmp/file.t.txt", "This is a test\n"); File f6 ("tmp/file.t.txt"); t.ok (f6.size () == 15, "File::size tmp/file.t.txt good"); t.ok (f6.mode () & S_IRUSR, "File::mode tmp/file.t.txt good"); t.ok (File::remove ("tmp/file.t.txt"), "File::remove tmp/file.t.txt good"); // operator (std::string) const; t.is ((std::string) f6, Directory::cwd () + "/tmp/file.t.txt", "File::operator (std::string) const"); t.ok (File::create ("tmp/file.t.create"), "File::create tmp/file.t.create good"); t.ok (File::remove ("tmp/file.t.create"), "File::remove tmp/file.t.create good"); // basename (std::string) const; t.is (f6.name (), "file.t.txt", "File::basename tmp/file.t.txt --> file.t.txt"); // dirname (std::string) const; t.is (f6.parent (), Directory::cwd () + "/tmp", "File::dirname tmp/file.t.txt --> tmp"); // bool rename (const std::string&); File f7 ("tmp/file.t.2.txt"); f7.append ("something\n"); f7.close (); t.ok (f7.rename ("tmp/file.t.3.txt"), "File::rename did not fail"); t.is (f7._data, Directory::cwd () + "/tmp/file.t.3.txt", "File::rename stored new name"); t.ok (f7.exists (), "File::rename new file exists"); t.ok (f7.remove (), "File::remove tmp/file.t.3.txt good"); t.notok (f7.exists (), "File::remove new file no longer exists"); // Test permissions. File f8 ("tmp/file.t.perm.txt"); f8.create (0744); t.ok (f8.exists (), "File::create perm file exists"); mode_t m = f8.mode (); t.ok (m & S_IFREG, "File::mode tmp/file.t.perm.txt S_IFREG good"); t.ok (m & S_IRUSR, "File::mode tmp/file.t.perm.txt r-------- good"); t.ok (m & S_IWUSR, "File::mode tmp/file.t.perm.txt -w------- good"); t.ok (m & S_IXUSR, "File::mode tmp/file.t.perm.txt --x------ good"); t.ok (m & S_IRGRP, "File::mode tmp/file.t.perm.txt ---r----- good"); t.notok (m & S_IWGRP, "File::mode tmp/file.t.perm.txt ----w---- good"); t.notok (m & S_IXGRP, "File::mode tmp/file.t.perm.txt -----x--- good"); t.ok (m & S_IROTH, "File::mode tmp/file.t.perm.txt ------r-- good"); t.notok (m & S_IWOTH, "File::mode tmp/file.t.perm.txt -------w- good"); t.notok (m & S_IXOTH, "File::mode tmp/file.t.perm.txt --------x good"); f8.remove (); t.notok (f8.exists (), "File::remove perm file no longer exists"); tmp.remove (); t.notok (tmp.exists (), "tmp dir removed."); tmp.create (); t.ok (tmp.exists (), "tmp dir created."); // Directory (const File&); // Directory (const Path&); Directory d0 (Path ("tmp")); Directory d1 (File ("tmp")); Directory d2 (File (Path ("tmp"))); t.is (d0._data, d1._data, "Directory(std::string) == Directory (File&)"); t.is (d0._data, d2._data, "Directory(std::string) == Directory (File (Path &))"); t.is (d1._data, d2._data, "Directory(File&)) == Directory (File (Path &))"); // Directory (const Directory&); Directory d3 (d2); t.is (d3._data, Directory::cwd () + "/tmp", "Directory (Directory&)"); // Directory (const std::string&); Directory d4 ("tmp/test_directory"); // Directory& operator= (const Directory&); Directory d5 = d4; t.is (d5._data, Directory::cwd () + "/tmp/test_directory", "Directory::operator="); // operator (std::string) const; t.is ((std::string) d3, Directory::cwd () + "/tmp", "Directory::operator (std::string) const"); // virtual bool create (); t.ok (d5.create (), "Directory::create tmp/test_directory"); t.ok (d5.exists (), "Directory::exists tmp/test_directory"); Directory d6 (d5._data + "/dir"); t.ok (d6.create (), "Directory::create tmp/test_directory/dir"); File::create (d5._data + "/f0"); File::create (d6._data + "/f1"); // std::vector <std::string> list (); std::vector <std::string> files = d5.list (); std::sort (files.begin (), files.end ()); t.is ((int)files.size (), 2, "Directory::list 1 file"); t.is (files[0], Directory::cwd () + "/tmp/test_directory/dir", "file[0] is tmp/test_directory/dir"); t.is (files[1], Directory::cwd () + "/tmp/test_directory/f0", "file[1] is tmp/test_directory/f0"); // std::vector <std::string> listRecursive (); files = d5.listRecursive (); std::sort (files.begin (), files.end ()); t.is ((int)files.size (), 2, "Directory::list 1 file"); t.is (files[0], Directory::cwd () + "/tmp/test_directory/dir/f1", "file is tmp/test_directory/dir/f1"); t.is (files[1], Directory::cwd () + "/tmp/test_directory/f0", "file is tmp/test_directory/f0"); // virtual bool remove (); t.ok (File::remove (d5._data + "/f0"), "File::remove tmp/test_directory/f0"); t.ok (File::remove (d6._data + "/f1"), "File::remove tmp/test_directory/dir/f1"); t.ok (d6.remove (), "Directory::remove tmp/test_directory/dir"); t.notok (d6.exists (), "Directory::exists tmp/test_directory/dir - no"); t.ok (d5.remove (), "Directory::remove tmp/test_directory"); t.notok (d5.exists (), "Directory::exists tmp/test_directory - no"); // bool remove (const std::string&); Directory d7 ("tmp/to_be_removed"); t.ok (d7.create (), "Directory::create tmp/to_be_removed"); File::create (d7._data + "/f0"); Directory d8 (d7._data + "/another"); t.ok (d8.create (), "Directory::create tmp/to_be_removed/another"); File::create (d8._data + "/f1"); t.ok (d7.remove (), "Directory::remove tmp/to_be_removed"); t.notok (d7.exists (), "Directory tmp/to_be_removed gone"); // static std::string cwd (); std::string cwd = Directory::cwd (); t.ok (cwd.length () > 0, "Directory::cwd returned a value"); // bool parent (std::string&) const; Directory d9 ("/one/two/three/four.txt"); t.ok (d9.up (), "parent /one/two/three/four.txt --> true"); t.is (d9._data, "/one/two/three", "parent /one/two/three/four.txt --> /one/two/three"); t.ok (d9.up (), "parent /one/two/three --> true"); t.is (d9._data, "/one/two", "parent /one/two/three --> /one/two"); t.ok (d9.up (), "parent /one/two --> true"); t.is (d9._data, "/one", "parent /one/two --> /one"); t.ok (d9.up (), "parent /one --> true"); t.is (d9._data, "/", "parent /one --> /"); t.notok (d9.up (), "parent / --> false"); // Test permissions. umask (0022); Directory d10 ("tmp/dir.perm"); d10.create (0750); t.ok (d10.exists (), "Directory::create perm file exists"); m = d10.mode (); t.ok (m & S_IFDIR, "Directory::mode tmp/dir.perm S_IFDIR good"); t.ok (m & S_IRUSR, "Directory::mode tmp/dir.perm r-------- good"); t.ok (m & S_IWUSR, "Directory::mode tmp/dir.perm -w------- good"); t.ok (m & S_IXUSR, "Directory::mode tmp/dir.perm --x------ good"); t.ok (m & S_IRGRP, "Directory::mode tmp/dir.perm ---r----- good"); t.notok (m & S_IWGRP, "Directory::mode tmp/dir.perm ----w---- good"); t.ok (m & S_IXGRP, "Directory::mode tmp/dir.perm -----x--- good"); t.notok (m & S_IROTH, "Directory::mode tmp/dir.perm ------r-- good"); t.notok (m & S_IWOTH, "Directory::mode tmp/dir.perm -------w- good"); t.notok (m & S_IXOTH, "Directory::mode tmp/dir.perm --------x good"); d10.remove (); t.notok (d10.exists (), "Directory::remove temp/dir.perm file no longer exists"); tmp.remove (); t.notok (tmp.exists (), "tmp dir removed."); return 0; }
int main (int argc, char** argv) { UnitTest t (49); // Ensure environment has no influence. unsetenv ("TASKDATA"); unsetenv ("TASKRC"); Directory tmp ("tmp"); tmp.create (); t.ok (tmp.exists (), "tmp dir created."); // Directory (const File&); // Directory (const Path&); Directory d0 (Path ("tmp")); Directory d1 (File ("tmp")); Directory d2 (File (Path ("tmp"))); t.is (d0._data, d1._data, "Directory(std::string) == Directory (File&)"); t.is (d0._data, d2._data, "Directory(std::string) == Directory (File (Path &))"); t.is (d1._data, d2._data, "Directory(File&)) == Directory (File (Path &))"); // Directory (const Directory&); Directory d3 (d2); t.is (d3._data, Directory::cwd () + "/tmp", "Directory (Directory&)"); // Directory (const std::string&); Directory d4 ("tmp/test_directory"); // Directory& operator= (const Directory&); Directory d5 = d4; t.is (d5._data, Directory::cwd () + "/tmp/test_directory", "Directory::operator="); // operator (std::string) const; t.is ((std::string) d3, Directory::cwd () + "/tmp", "Directory::operator (std::string) const"); // virtual bool create (); t.ok (d5.create (), "Directory::create tmp/test_directory"); t.ok (d5.exists (), "Directory::exists tmp/test_directory"); Directory d6 (d5._data + "/dir"); t.ok (d6.create (), "Directory::create tmp/test_directory/dir"); File::create (d5._data + "/f0"); File::create (d6._data + "/f1"); // std::vector <std::string> list (); std::vector <std::string> files = d5.list (); std::sort (files.begin (), files.end ()); t.is ((int)files.size (), 2, "Directory::list 1 file"); t.is (files[0], Directory::cwd () + "/tmp/test_directory/dir", "file[0] is tmp/test_directory/dir"); t.is (files[1], Directory::cwd () + "/tmp/test_directory/f0", "file[1] is tmp/test_directory/f0"); // std::vector <std::string> listRecursive (); files = d5.listRecursive (); std::sort (files.begin (), files.end ()); t.is ((int)files.size (), 2, "Directory::list 1 file"); t.is (files[0], Directory::cwd () + "/tmp/test_directory/dir/f1", "file is tmp/test_directory/dir/f1"); t.is (files[1], Directory::cwd () + "/tmp/test_directory/f0", "file is tmp/test_directory/f0"); // virtual bool remove (); t.ok (File::remove (d5._data + "/f0"), "File::remove tmp/test_directory/f0"); t.ok (File::remove (d6._data + "/f1"), "File::remove tmp/test_directory/dir/f1"); t.ok (d6.remove (), "Directory::remove tmp/test_directory/dir"); t.notok (d6.exists (), "Directory::exists tmp/test_directory/dir - no"); t.ok (d5.remove (), "Directory::remove tmp/test_directory"); t.notok (d5.exists (), "Directory::exists tmp/test_directory - no"); // bool remove (const std::string&); Directory d7 ("tmp/to_be_removed"); t.ok (d7.create (), "Directory::create tmp/to_be_removed"); File::create (d7._data + "/f0"); Directory d8 (d7._data + "/another"); t.ok (d8.create (), "Directory::create tmp/to_be_removed/another"); File::create (d8._data + "/f1"); t.ok (d7.remove (), "Directory::remove tmp/to_be_removed"); t.notok (d7.exists (), "Directory tmp/to_be_removed gone"); // static std::string cwd (); std::string cwd = Directory::cwd (); t.ok (cwd.length () > 0, "Directory::cwd returned a value"); // bool parent (std::string&) const; Directory d9 ("/one/two/three/four.txt"); t.ok (d9.up (), "parent /one/two/three/four.txt --> true"); t.is (d9._data, "/one/two/three", "parent /one/two/three/four.txt --> /one/two/three"); t.ok (d9.up (), "parent /one/two/three --> true"); t.is (d9._data, "/one/two", "parent /one/two/three --> /one/two"); t.ok (d9.up (), "parent /one/two --> true"); t.is (d9._data, "/one", "parent /one/two --> /one"); t.ok (d9.up (), "parent /one --> true"); t.is (d9._data, "/", "parent /one --> /"); t.notok (d9.up (), "parent / --> false"); // Test permissions. umask (0022); Directory d10 ("tmp/dir.perm"); d10.create (0750); t.ok (d10.exists (), "Directory::create perm file exists"); mode_t m = d10.mode (); t.ok (m & S_IFDIR, "Directory::mode tmp/dir.perm S_IFDIR good"); t.ok (m & S_IRUSR, "Directory::mode tmp/dir.perm r-------- good"); t.ok (m & S_IWUSR, "Directory::mode tmp/dir.perm -w------- good"); t.ok (m & S_IXUSR, "Directory::mode tmp/dir.perm --x------ good"); t.ok (m & S_IRGRP, "Directory::mode tmp/dir.perm ---r----- good"); t.notok (m & S_IWGRP, "Directory::mode tmp/dir.perm ----w---- good"); t.ok (m & S_IXGRP, "Directory::mode tmp/dir.perm -----x--- good"); t.notok (m & S_IROTH, "Directory::mode tmp/dir.perm ------r-- good"); t.notok (m & S_IWOTH, "Directory::mode tmp/dir.perm -------w- good"); t.notok (m & S_IXOTH, "Directory::mode tmp/dir.perm --------x good"); d10.remove (); t.notok (d10.exists (), "Directory::remove temp/dir.perm file no longer exists"); tmp.remove (); t.notok (tmp.exists (), "tmp dir removed."); return 0; }