1 #ifndef _T_DIRECTORY_H_
2 #define _T_DIRECTORY_H_
7 #include <mimetic/os/directory.h>
8 #include <mimetic/os/fileop.h>
9 #include <mimetic/utils.h>
15 class TEST_CLASS( test_directory )
18 #define TESTDIR "__t_directory_h_testdir"
21 TEST_ASSERT( Directory::create(TESTDIR) );
25 TEST_ASSERT( Directory::remove(TESTDIR) );
27 void TEST_FUNCTION( exists )
29 TEST_ASSERT( Directory::exists(TESTDIR) );
30 TEST_ASSERT( ! Directory::exists("__ThisDirShouldNotExist__") );
32 void TEST_FUNCTION( emptyDir )
34 // only . and .. should exist in TESTDIR
36 Directory::iterator bit = d.begin(), eit = d.end();
37 for(; bit != eit; ++bit)
39 TEST_ASSERT( bit->name == "." || bit->name == ".." );
42 void TEST_FUNCTION( withFiles )
46 ofstream of(TESTDIR "/file1");
50 Directory::iterator bit = d.begin(), eit = d.end();
51 for(int count = 2; bit != eit; ++bit, --count)
58 TEST_ASSERT( count >= 0); // max 2 items
60 FileOp::remove( TESTDIR "/file1" );
62 void TEST_FUNCTION( moreFiles )
65 unsigned long tot = 0;
67 for(n = 1; n < 100; ++n)
69 string fqn = TESTDIR "/";
70 fqn += utils::int2str(n);
71 ofstream of(fqn.c_str());
76 Directory::iterator bit = d.begin(), eit = d.end();
77 for(; bit != eit; ++bit)
79 if( bit->name == "." || bit->name == ".." )
81 n = utils::str2int(bit->name);
84 TEST_ASSERT( tot == 0);
86 for(n = 1; n < 100; ++n)
88 string fqn = TESTDIR "/";
89 fqn += utils::int2str(n);
90 FileOp::remove( fqn );