first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / tests_filesystem / test_directory.cpp
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>
17 #include <structures/string_array.h>
18 #include <application/hoople_main.h>
19 #include <loggers/critical_events.h>
20 #include <loggers/program_wide_logger.h>
21 #include <filesystem/directory.h>
22 #include <filesystem/filename.h>
23 #include <structures/static_memory_gremlin.h>
24 #include <textual/string_manipulation.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
37 //////////////
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
47 //////////////
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
57     if (application::_global_argc >= 2)
58       path = application::_global_argv[1];
59
60     astring pattern = "*";
61     if (application::_global_argc >= 3)
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