feisty meow concerns codebase  2.140
test_directory.cpp
Go to the documentation of this file.
1 /*
2 * Name : test_directory
3 * Author : Chris Koeritz
4 * Purpose:
5 * Tests the directory object out to see if it scans properly.
6 **
7 * Copyright (c) 2001-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 */
14 
15 #include <basis/functions.h>
16 #include <basis/guards.h>
21 #include <filesystem/directory.h>
22 #include <filesystem/filename.h>
25 #include <unit_test/unit_base.h>
26 
27 using namespace application;
28 using namespace basis;
29 using namespace mathematics;
30 using namespace filesystem;
31 using namespace loggers;
32 using namespace structures;
33 using namespace textual;
34 using namespace timely;
35 using namespace unit_test;
36 
38 
39 class test_directory : public virtual unit_base, public virtual application_shell
40 {
41 public:
42  test_directory() : application_shell() {}
43  DEFINE_CLASS_NAME("test_directory");
44  int execute();
45 };
46 
48 
49 int test_directory::execute()
50 {
51  FUNCDEF("execute");
52  {
53  astring path = "/tmp"; // default path.
54 #ifdef __WIN32__
55  path = "c:/"; // default path for windoze.
56 #endif
59 
60  astring pattern = "*";
62  pattern = application::_global_argv[2];
63 
64 // log(astring("Scanning directory named \"") + path + "\"");
65 // log(astring("Using pattern-match \"") + pattern + "\"");
66 
67  directory dir(path, pattern.s());
68  ASSERT_TRUE(dir.good(), "the current directory should be readable");
69 // log(path + " contained these files:");
70  astring names;
71  for (int i = 0; i < dir.files().length(); i++) {
72  names += dir.files()[i] + " ";
73  }
74  astring split;
75  string_manipulation::split_lines(names, split, 4);
76 // log(split);
77 // log(path + " contained these directories:");
78  names = "";
79  for (int i = 0; i < dir.directories().length(); i++) {
80  names += dir.directories()[i] + " ";
81  }
82  string_manipulation::split_lines(names, split, 4);
83 // log(split);
84  }
85 //hmmm: the above test proves zilch.
86 // it needs to do this differently.
87 // instead of relying on someone else's folder, pick and make our own.
88 // then fill it with some known stuff.
89 // verify then that the read form is identical!
90 
91 
92 
93 //more tests!
94 
95  return final_report();
96 }
97 
98 HOOPLE_MAIN(test_directory, )
99 
The application_shell is a base object for console programs.
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
Definition: astring.h:113
Implements a scanner that finds all filenames in the directory specified.
Definition: directory.h:27
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition: enhance_cpp.h:45
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition: enhance_cpp.h:57
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition: hoople_main.h:61
Implements an application lock to ensure only one is running at once.
char ** _global_argv
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
string path
Definition: eml_to_txt.py:139
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Definition: averager.h:21
None split_lines(str unsplit_line)
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55
#include <time.h>
Definition: earth_time.cpp:37
Useful support functions for unit testing, especially within hoople.
Definition: unit_base.cpp:35
#define ASSERT_TRUE(a, test_name)
Definition: unit_base.h:46