test_directory.cpp

Go to the documentation of this file.
00001 /*
00002 *  Name   : test_directory
00003 *  Author : Chris Koeritz
00004 *  Purpose:
00005 *    Tests the directory object out to see if it scans properly.
00006 **
00007 * Copyright (c) 2001-$now By Author.  This program is free software; you can  *
00008 * redistribute it and/or modify it under the terms of the GNU General Public  *
00009 * License as published by the Free Software Foundation; either version 2 of   *
00010 * the License or (at your option) any later version.  This is online at:      *
00011 *     http://www.fsf.org/copyleft/gpl.html                                    *
00012 * Please send any updates to: fred@gruntose.com                               *
00013 */
00014 
00015 #include <basis/functions.h>
00016 #include <basis/guards.h>
00017 #include <structures/string_array.h>
00018 #include <application/hoople_main.h>
00019 #include <loggers/critical_events.h>
00020 #include <loggers/program_wide_logger.h>
00021 #include <filesystem/directory.h>
00022 #include <filesystem/filename.h>
00023 #include <structures/static_memory_gremlin.h>
00024 #include <textual/string_manipulation.h>
00025 #include <unit_test/unit_base.h>
00026 
00027 using namespace application;
00028 using namespace basis;
00029 using namespace mathematics;
00030 using namespace filesystem;
00031 using namespace loggers;
00032 using namespace structures;
00033 using namespace textual;
00034 using namespace timely;
00035 using namespace unit_test;
00036 
00038 
00039 class test_directory : public virtual unit_base, public virtual application_shell
00040 {
00041 public:
00042   test_directory() : application_shell() {}
00043   DEFINE_CLASS_NAME("test_directory");
00044   int execute();
00045 };
00046 
00048 
00049 int test_directory::execute()
00050 {
00051   FUNCDEF("execute");
00052   {
00053     astring path = "/tmp";  // default path.
00054 #ifdef __WIN32__
00055     path = "c:/";  // default path for windoze.
00056 #endif
00057     if (application::_global_argc >= 2)
00058       path = application::_global_argv[1];
00059 
00060     astring pattern = "*";
00061     if (application::_global_argc >= 3)
00062       pattern = application::_global_argv[2];
00063 
00064 //    log(astring("Scanning directory named \"") + path + "\"");
00065 //    log(astring("Using pattern-match \"") + pattern + "\"");
00066 
00067     directory dir(path, pattern.s());
00068     ASSERT_TRUE(dir.good(), "the current directory should be readable");
00069 //    log(path + " contained these files:");
00070     astring names;
00071     for (int i = 0; i < dir.files().length(); i++) {
00072       names += dir.files()[i] + " ";
00073     }
00074     astring split;
00075     string_manipulation::split_lines(names, split, 4);
00076 //    log(split);
00077 //    log(path + " contained these directories:");
00078     names = "";
00079     for (int i = 0; i < dir.directories().length(); i++) {
00080       names += dir.directories()[i] + " ";
00081     }
00082     string_manipulation::split_lines(names, split, 4);
00083 //    log(split);
00084   }
00085 //hmmm: the above test proves zilch.
00086 //      it needs to do this differently.
00087 //      instead of relying on someone else's folder, pick and make our own.
00088 //      then fill it with some known stuff.
00089 //      verify then that the read form is identical!
00090 
00091 
00092 
00093 //more tests!
00094 
00095   return final_report();
00096 }
00097 
00098 HOOPLE_MAIN(test_directory, )
00099 
Generated on Sat Jan 28 04:22:30 2012 for hoople2 project by  doxygen 1.6.3