implemented new working destructor for tree
[feisty_meow.git] / nucleus / library / tests_filesystem / test_byte_filer.cpp
index 8261d39831055a08180dc8f9f1c6e17d7b0a5fa0..283ebb0529b63198ce9fd32d6b46bd437c3a31d2 100644 (file)
@@ -44,6 +44,9 @@ using namespace unit_test;
 
 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
 
+//#define DEBUG_BYTE_FILER
+  // uncomment for noisy test run.
+
 class test_byte_filer : virtual public unit_base, virtual public application_shell
 {
 public:
@@ -56,12 +59,17 @@ public:
 
 const astring &TEST_FILE()
 {
-  const char *TEST_FILE_BASE = "/zz_garbage.txt";
+  const char *TEST_FILE_BASE = "/zz_garbage";
+  const char *TEST_FILE_SUFFIX = ".txt";
   static astring __hidden_filename;
   if (!__hidden_filename) {
-    __hidden_filename = environment::get("TMP");
+    __hidden_filename = environment::TMP();
     if (!__hidden_filename) __hidden_filename = "/tmp";
-    __hidden_filename += astring(TEST_FILE_BASE);
+    // try to create it just in case it wasn't there already.
+    directory::make_directory(__hidden_filename);
+    __hidden_filename += TEST_FILE_BASE;
+    __hidden_filename += a_sprintf("%d", chaos().inclusive(0, 65535));
+    __hidden_filename += TEST_FILE_SUFFIX;
   }
   return __hidden_filename;
 }
@@ -69,7 +77,7 @@ const astring &TEST_FILE()
 int test_byte_filer::run_simple_test()
 {
   FUNCDEF("run_simple_test");
-#ifdef DEBUG
+#ifdef DEBUG_BYTE_FILER
   LOG("ahoy, beginning file test...");
   LOG(astring("test file is ") + TEST_FILE());
 #endif
@@ -90,7 +98,7 @@ int test_byte_filer::run_simple_test()
   test1.unlink();
 
   int block_size = randomizer.inclusive(3000, 30000);
-#ifdef DEBUG
+#ifdef DEBUG_BYTE_FILER
   LOG(a_sprintf("block size=%d", block_size));
 #endif
   abyte *original_block = new abyte[block_size];
@@ -99,7 +107,7 @@ int test_byte_filer::run_simple_test()
   unsigned int original_checksum
       = checksums::bizarre_checksum((abyte *)original_block, block_size);
   if (original_checksum) {} // compiler quieting.
-#ifdef DEBUG
+#ifdef DEBUG_BYTE_FILER
   LOG(a_sprintf("random block checksum=%d", original_checksum));
 #endif
   {
@@ -108,7 +116,7 @@ int test_byte_filer::run_simple_test()
     byte_filer fred(TEST_FILE(), "w+");
     fred.write(to_stuff_in_file);
   }
-#ifdef DEBUG
+#ifdef DEBUG_BYTE_FILER
   LOG(astring("about to compare file to checksum"));
 #endif
   {
@@ -116,17 +124,14 @@ int test_byte_filer::run_simple_test()
     byte_array to_fake_stuff(21309, temp_array);
     delete [] temp_array;
     byte_filer fred(TEST_FILE(), "r");
-#ifdef DEBUG
+#ifdef DEBUG_BYTE_FILER
     LOG(astring("about to try writing to file"));
 #endif
     int should_be_failure = fred.write(to_fake_stuff);
     ASSERT_EQUAL(should_be_failure, 0, "write on read only, should not succeed");
 
-///    int fredsize = int(fred.size());
-///    fred.chunk_factor(fredsize);
-
-#ifdef DEBUG
-    LOG(a_sprintf("about to try reading from file %d bytes", fredsize));
+#ifdef DEBUG_BYTE_FILER
+    LOG(a_sprintf("about to try reading from file %d bytes", block_size * 2));
 #endif
     byte_array file_contents;
     int bytes_read = fred.read(file_contents, block_size * 2);
@@ -169,9 +174,8 @@ int test_byte_filer::run_file_scan()
   files.zap(0, 0);  // toss the first element since that's our app filename.
 
   if (!files.length()) {
-    // pretend they gave us the list of files in the TMP directory.  some of
+    // pretend they gave us the list of files in the current directory.  some of
     // these might fail if they're locked up.
-//    astring tmpdir = environment::get("TMP");
     astring tmpdir = application_configuration::current_directory();
     directory dir(tmpdir);
     for (int i = 0; i < dir.files().length(); i++) {
@@ -222,7 +226,7 @@ int test_byte_filer::run_file_scan()
 
 int test_byte_filer::execute()
 {
-//  FUNCDEF("execute");
+  FUNCDEF("execute");
   int ret = run_simple_test();
   if (ret) return ret;  // failed.
   ret = run_file_scan();