const bool JUST_SIZES = false;
// determines if we'll only compare file size and time.
-#define DEBUG_TEST_DIRECTORY_TREE
+//#define DEBUG_TEST_DIRECTORY_TREE
// uncomment if you want noisy logging.
-#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
+#ifdef DEBUG_TEST_DIRECTORY_TREE
+ #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
+#else
+ #define LOG(s) {}
+#endif
class test_directory_tree : public virtual unit_base, virtual public application_shell
{
{
FUNCDEF("execute");
-/* old approach.
- astring path = "/usr/lib";
-#ifdef __WIN32__
- // default path for windoze uses an area that should always exist.
- path = environment::get("COMMONPROGRAMFILES");
-#endif
-*/
-
/*
hmmm: this test shows that our algorithms are poor; the tree traversal on feisty meow apex
should not take as long as it does.
get some timing around this, comparing it with other linux tools, like ls -R and find.
see if we have some ugly bottlenecks, or where they are, and fix them.
+
+a bit of watching, and it seems like the comparison is the super slow thing.
+
*/
// new approach for where to look is at feisty meow itself.
// some type of introspection to be sure.
- astring path = environment::get("FEISTY_MEOW_APEX");
+ astring path = environment::get("FEISTY_MEOW_SCRIPTS");
// process the command line parameters, which are optionally a directory name and
// a pattern to use when scanning.
pattern = _global_argv[2];
{
-#ifdef DEBUG_TEST_DIRECTORY_TREE
- log(astring("Scanning directory tree at \"") + path + "\"");
- log(astring("Using pattern-match \"") + pattern + "\"");
-#endif
+ LOG(astring("Scanning directory tree at \"") + path + "\"");
+ LOG(astring("Using pattern-match \"") + pattern + "\"");
directory_tree dir(path, pattern.s());
ASSERT_TRUE(dir.good(), "directory_tree construction should succeed and be readable.");
while (directory_tree::current(*ted, curr, files)) {
// we have a good directory to show.
directory_tree::depth(*ted, depth);
-#ifdef DEBUG_TEST_DIRECTORY_TREE
- log(string_manipulation::indentation(depth * 2) + astring("[") + curr.raw() + "]");
-#endif
+ LOG(string_manipulation::indentation(depth * 2) + astring("[") + curr.raw() + "]");
astring names;
for (int i = 0; i < files.length(); i++) names += files[i] + " ";
if (names.length()) {
astring split;
string_manipulation::split_lines(names, split, depth * 2 + 2);
-#ifdef DEBUG_TEST_DIRECTORY_TREE
- log(split);
-#endif
+ LOG(split);
}
// go to the next place.
}
directory_tree::throw_out(ted);
+
+ LOG(astring("Finished scan on directory tree at \"") + path + "\"");
}
{
{
// third test group. tree comparison operation.
-// log(astring("Self-comparing directory tree at \"") + path + "\"");
-// log(astring("Using pattern-match \"") + pattern + "\"");
+ LOG(astring("Self-comparing directory tree at \"") + path + "\"");
+ LOG(astring("Using pattern-match \"") + pattern + "\"");
-// LOG("reading tree 1.");
+ LOG("reading tree 1.");
directory_tree dir(path, pattern.s());
ASSERT_TRUE(dir.good(), "the directory should be readable for self-compare");
+ LOG("done reading tree 1.");
// now read a copy of the tree also.
-// LOG("reading tree 2.");
+ LOG("reading tree 2.");
directory_tree dir2(path, pattern.s());
ASSERT_TRUE(dir2.good(), "the directory should read the second time fine too");
+ LOG("done reading tree 2.");
- LOG("comparing the two trees.");
+ LOG("started comparing the two trees.");
filename_list diffs;
directory_tree::compare_trees(dir, dir2, diffs, file_info::EQUAL_CHECKSUM_TIMESTAMP_FILESIZE);
+ LOG("finished comparing the two trees.");
+
+LOG("#### diffs found...");
LOG(diffs.text_form());
+LOG("####");
ASSERT_FALSE(diffs.elements(), "there should be no differences comparing identical dirs");
}
{
// fourth test: see if the calculate function works.
-// log(astring("Calculating sums for tree at \"") + path + "\"");
-// log(astring("Using pattern-match \"") + pattern + "\"");
+ LOG(astring("Calculating sums for tree at \"") + path + "\"");
+ LOG(astring("Using pattern-match \"") + pattern + "\"");
-// LOG("reading tree 1.");
+ LOG("reading tree 1.");
directory_tree dir(path, pattern.s());
ASSERT_TRUE(dir.good(), "the directory should be readable for checksums");
// now read a copy of the tree also.
-// LOG("reading tree 2.");
+ LOG("reading tree 2.");
directory_tree dir2(path, pattern.s());
ASSERT_TRUE(dir2.good(), "checksummer should be able to read second time also");
-// LOG("calculating checksums for tree 1.");
+ LOG("calculating checksums for tree 1.");
ASSERT_TRUE(dir.calculate(JUST_SIZES), "the first checksummer tree can be calculated");
-// LOG("calculating checksums for tree 2.");
+ LOG("calculating checksums for tree 2.");
ASSERT_TRUE(dir2.calculate(JUST_SIZES), "the second checksummer tree can be calculated");
-// LOG("comparing the two trees.");
+ LOG("comparing the two trees.");
filename_list diffs;
directory_tree::compare_trees(dir, dir2, diffs, file_info::EQUAL_CHECKSUM_TIMESTAMP_FILESIZE);
-//LOG(diffs.text_form());
+
+LOG(astring("#### diffs found..."));
+LOG(diffs.text_form());
+LOG("####");
ASSERT_FALSE(diffs.elements(), "no checksummer differences should be seen for identical directories");
}
{
// fifth test: see if the packing works.
-// log(astring("Reading tree for packing at \"") + path + "\"");
-// log(astring("Using pattern-match \"") + pattern + "\"");
+ LOG(astring("Reading tree for packing at \"") + path + "\"");
+ LOG(astring("Using pattern-match \"") + pattern + "\"");
-// LOG("reading tree.");
+ LOG("reading tree.");
directory_tree dir(path, pattern.s());
ASSERT_TRUE(dir.good(), "packer directory should be read");
-// LOG("calculating checksums for tree.");
+ LOG("calculating checksums for tree.");
ASSERT_TRUE(dir.calculate(JUST_SIZES), "the first packer tree can be calculated");
+ LOG("done calculating checksums for tree.");
+ LOG("packing the tree.");
byte_array packed_form;
int size_packed = dir.packed_size();
dir.pack(packed_form);
//LOG(a_sprintf("tree became %d abyte array", packed_form.length()));
ASSERT_EQUAL(size_packed, packed_form.length(), "packed size should be right");
+ LOG("unpacking the tree.");
directory_tree dir2;
ASSERT_TRUE(dir2.unpack(packed_form), "second tree can be unpacked from the first");
-// LOG("comparing the two trees.");
+ LOG("comparing the two trees.");
filename_list diffs;
directory_tree::compare_trees(dir, dir2, diffs, file_info::EQUAL_CHECKSUM_TIMESTAMP_FILESIZE);
//LOG(diffs.text_form());
+ LOG("finished comparing the two trees.");
ASSERT_FALSE(diffs.elements(), "identical directories should stay same after packing");
{
// sixth test: see if the make_directories function works.
-LOG("reading tree to recreate");
+LOG("reading tree to test making directories");
directory_tree dir(path, pattern.s());
ASSERT_TRUE(dir.good(), "makedirs test directory reading");
filename tmpdir(environment::get("FEISTY_MEOW_GENERATED_STORE") + "/zz_balfazzaral");