t_directory.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : test_directory                                                    *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *  Purpose:                                                                   *
00007 *                                                                             *
00008 *    Tests the directory object out to see if it scans properly.              *
00009 *                                                                             *
00010 *******************************************************************************
00011 * Copyright (c) 2001-$now By Author.  This program is free software; you can  *
00012 * redistribute it and/or modify it under the terms of the GNU General Public  *
00013 * License as published by the Free Software Foundation; either version 2 of   *
00014 * the License or (at your option) any later version.  This is online at:      *
00015 *     http://www.fsf.org/copyleft/gpl.html                                    *
00016 * Please send any updates to: fred@gruntose.com                               *
00017 \*****************************************************************************/
00018 
00019 #include <basis/function.h>
00020 #include <basis/guards.h>
00021 #include <basis/string_array.h>
00022 #include <opsystem/application_shell.h>
00023 #include <loggers/console_logger.h>
00024 #include <opsystem/directory.h>
00025 #include <opsystem/filename.h>
00026 #include <data_struct/static_memory_gremlin.h>
00027 #include <textual/string_manipulation.h>
00028 
00029 class test_directory : public application_shell
00030 {
00031 public:
00032   test_directory() : application_shell("test_directory") {}
00033   IMPLEMENT_CLASS_NAME("test_directory");
00034   int execute();
00035 };
00036 
00037 int test_directory::execute()
00038 {
00039   {
00040     istring path = "/tmp";  // default path.
00041 #ifdef __WIN32__
00042     path = "c:/";  // default path for windoze.
00043 #endif
00044     if (__argc >= 2)
00045       path = __argv[1];
00046 
00047     istring pattern = "*";
00048     if (__argc >= 3)
00049       pattern = __argv[2];
00050 
00051     log(istring("Scanning directory named \"") + path + "\"");
00052     log(istring("Using pattern-match \"") + pattern + "\"");
00053 
00054     directory dir(path, pattern.s());
00055     if (!dir.good())
00056       deadly_error(class_name(), "current directory test",
00057           "the current directory cannot be read");
00058     log(path + " contained these files:");
00059     istring names;
00060     for (int i = 0; i < dir.files().length(); i++) {
00061       names += dir.files()[i] + " ";
00062     }
00063     istring split;
00064     string_manipulation::split_lines(names, split, 4);
00065     log(split);
00066     log(path + " contained these directories:");
00067     names = "";
00068     for (int i = 0; i < dir.directories().length(); i++) {
00069       names += dir.directories()[i] + " ";
00070     }
00071     string_manipulation::split_lines(names, split, 4);
00072     log(split);
00073   }
00074 //more tests!
00075 
00076   guards::alert_message("command_line:: works for those functions tested.");
00077   return 0;
00078 }
00079 
00080 HOOPLE_MAIN(test_directory, )
00081 

Generated on Fri Nov 28 04:29:39 2008 for HOOPLE Libraries by  doxygen 1.5.1