From: Fred T. Hamster Date: Sat, 7 Feb 2026 15:14:01 +0000 (-0500) Subject: breaking change - adding test for dirtree fcopy X-Git-Tag: 2.140.190^2~33 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=8c4f2e4933f9cf47220d68ab36ec8fc47b93f7c4;p=feisty_meow.git breaking change - adding test for dirtree fcopy getting this older test up to speed. --- diff --git a/nucleus/library/tests_application/test_dirtree_fcopy.cpp b/nucleus/library/tests_application/test_dirtree_fcopy.cpp deleted file mode 100644 index 4e5e40a5..00000000 --- a/nucleus/library/tests_application/test_dirtree_fcopy.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/*****************************************************************************\ -* * -* Name : test_fcopy_file_transfer * -* Author : Chris Koeritz * -* * -* Purpose: * -* * -* Tests the directory_tree object as a file copy prompter. * -* * -******************************************************************************* -* Copyright (c) 2005-$now By Author. This program is free software; you can * -* redistribute it and/or modify it under the terms of the GNU General Public * -* License as published by the Free Software Foundation; either version 2 of * -* the License or (at your option) any later version. This is online at: * -* http://www.fsf.org/copyleft/gpl.html * -* Please send any updates to: fred@gruntose.com * -\*****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s) - -class test_fcopy : public application_shell -{ -public: - test_fcopy() : application_shell(static_class_name()) {} - IMPLEMENT_CLASS_NAME("test_dirtree_fcopy"); - int execute(); -}; - -int test_fcopy::execute() -{ - FUNCDEF("execute"); - - if (__argc < 3) - non_continuable_error(class_name(), "command line", "this program needs two " - "parameters:\na directory for the source and one for the target."); - - istring source_dir = __argv[1]; - istring target_dir = __argv[2]; - - // read the source location. - log(istring("Scanning source tree at \"") + source_dir + "\""); - directory_tree source(source_dir, "*"); - if (!source.good()) - non_continuable_error(class_name(), "directory_tree construction", - "the source directory could not be read"); - - // read the stuff that exists at the target. - log(istring("Scanning target tree at \"") + target_dir + "\""); - directory_tree target(target_dir, "*"); - if (!target.good()) - non_continuable_error(class_name(), "directory_tree construction", - "the target directory could not be read"); - - LOG("calculating checksums for source."); - if (!source.calculate()) - non_continuable_error(class_name(), "directory_tree calculation", - "the source tree could not be calculated"); - - LOG("calculating checksums for target."); - if (!target.calculate()) - non_continuable_error(class_name(), "directory_tree calculation", - "the target tree could not be calculated"); - - istring source_start; - istring target_start; - if (__argc > 3) - source_start = __argv[3]; - if (__argc > 4) - target_start = __argv[4]; - - LOG("comparing the two trees."); - filename_list diffs; - directory_tree::compare_trees(source, source_start, target, target_start, - diffs); -//LOG("missing files:"); -//LOG(diffs.text_form()); - - byte_array packed_form; - diffs.pack(packed_form); - filename_list regen; - if (!regen.unpack(packed_form)) - non_continuable_error(class_name(), "filename_list packing", - "could not unpack the list of differences"); - -//LOG("after packing and restoring:"); -//LOG(regen.text_form()); - - if (regen.elements() != diffs.elements()) - non_continuable_error(class_name(), "filename_list packing", - "there were a different number of elements in unpacked form"); - for (int i = 0; i < diffs.elements(); i++) { - if (!regen.member(*diffs[i])) { - istring name = diffs[i]->raw(); - non_continuable_error(class_name(), "filename_list packing", - istring("name from original set was missing in regenerated: ") - + name); - } - } - - for (int i = 0; i < diffs.elements(); i++) { - file_info *curr = diffs[i]; - filename source_file = source.path() + filename::default_separator() - + curr->raw(); - filename target_file = target.path() + filename::default_separator() - + curr->secondary(); -//LOG(istring("cp source: ") + source_file.raw()); -//LOG(istring("-> target: ") + target_file.raw()); - filename targ_dir = target_file.dirname(); - if (!targ_dir.is_directory()) { - bool worked = directory::recursive_create(targ_dir); - if (!worked) - non_continuable_error(class_name(), "recursive mkdir", - istring("failed to create the target directory ") + targ_dir); - } - - outcome ret = heavy_file_operations::copy_file(source_file, target_file); - if (ret != heavy_file_operations::OKAY) - non_continuable_error(class_name(), "copying file", istring("there was an error ") - + heavy_file_operations::outcome_name(ret) - + " when copying the file."); - } - -//do the copy by going across the entire set of files and making sure -//they get copied to target. -// -//reread the target location. -// -//compare with source tree read before. - - guards::alert_message("directory_tree file transfer:: works for those functions tested."); - return 0; -} - -HOOPLE_MAIN(test_fcopy, ) - diff --git a/nucleus/library/tests_filesystem/makefile b/nucleus/library/tests_filesystem/makefile index fb163a75..73aa27cb 100644 --- a/nucleus/library/tests_filesystem/makefile +++ b/nucleus/library/tests_filesystem/makefile @@ -2,12 +2,12 @@ include cpp/variables.def PROJECT = tests_filesystem TYPE = test -TARGETS = test_byte_filer.exe test_directory.exe test_directory_tree.exe test_file_info.exe \ - test_file_time.exe test_filename.exe test_huge_file.exe +TARGETS = test_byte_filer.exe test_directory.exe test_directory_tree.exe \ + test_dirtree_fcopy.exe test_file_info.exe test_file_time.exe \ + test_filename.exe test_huge_file.exe DEFINITIONS += USE_FEISTY_MEOW_DLLS LOCAL_LIBS_USED = unit_test application configuration filesystem loggers \ - mathematics nodes processes structures textual timely structures basis \ -loggers + mathematics nodes processes structures textual timely structures basis RUN_TARGETS = $(ACTUAL_TARGETS) include cpp/rules.def diff --git a/nucleus/library/tests_filesystem/test_dirtree_fcopy.cpp b/nucleus/library/tests_filesystem/test_dirtree_fcopy.cpp new file mode 100644 index 00000000..4e5e40a5 --- /dev/null +++ b/nucleus/library/tests_filesystem/test_dirtree_fcopy.cpp @@ -0,0 +1,147 @@ +/*****************************************************************************\ +* * +* Name : test_fcopy_file_transfer * +* Author : Chris Koeritz * +* * +* Purpose: * +* * +* Tests the directory_tree object as a file copy prompter. * +* * +******************************************************************************* +* Copyright (c) 2005-$now By Author. This program is free software; you can * +* redistribute it and/or modify it under the terms of the GNU General Public * +* License as published by the Free Software Foundation; either version 2 of * +* the License or (at your option) any later version. This is online at: * +* http://www.fsf.org/copyleft/gpl.html * +* Please send any updates to: fred@gruntose.com * +\*****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s) + +class test_fcopy : public application_shell +{ +public: + test_fcopy() : application_shell(static_class_name()) {} + IMPLEMENT_CLASS_NAME("test_dirtree_fcopy"); + int execute(); +}; + +int test_fcopy::execute() +{ + FUNCDEF("execute"); + + if (__argc < 3) + non_continuable_error(class_name(), "command line", "this program needs two " + "parameters:\na directory for the source and one for the target."); + + istring source_dir = __argv[1]; + istring target_dir = __argv[2]; + + // read the source location. + log(istring("Scanning source tree at \"") + source_dir + "\""); + directory_tree source(source_dir, "*"); + if (!source.good()) + non_continuable_error(class_name(), "directory_tree construction", + "the source directory could not be read"); + + // read the stuff that exists at the target. + log(istring("Scanning target tree at \"") + target_dir + "\""); + directory_tree target(target_dir, "*"); + if (!target.good()) + non_continuable_error(class_name(), "directory_tree construction", + "the target directory could not be read"); + + LOG("calculating checksums for source."); + if (!source.calculate()) + non_continuable_error(class_name(), "directory_tree calculation", + "the source tree could not be calculated"); + + LOG("calculating checksums for target."); + if (!target.calculate()) + non_continuable_error(class_name(), "directory_tree calculation", + "the target tree could not be calculated"); + + istring source_start; + istring target_start; + if (__argc > 3) + source_start = __argv[3]; + if (__argc > 4) + target_start = __argv[4]; + + LOG("comparing the two trees."); + filename_list diffs; + directory_tree::compare_trees(source, source_start, target, target_start, + diffs); +//LOG("missing files:"); +//LOG(diffs.text_form()); + + byte_array packed_form; + diffs.pack(packed_form); + filename_list regen; + if (!regen.unpack(packed_form)) + non_continuable_error(class_name(), "filename_list packing", + "could not unpack the list of differences"); + +//LOG("after packing and restoring:"); +//LOG(regen.text_form()); + + if (regen.elements() != diffs.elements()) + non_continuable_error(class_name(), "filename_list packing", + "there were a different number of elements in unpacked form"); + for (int i = 0; i < diffs.elements(); i++) { + if (!regen.member(*diffs[i])) { + istring name = diffs[i]->raw(); + non_continuable_error(class_name(), "filename_list packing", + istring("name from original set was missing in regenerated: ") + + name); + } + } + + for (int i = 0; i < diffs.elements(); i++) { + file_info *curr = diffs[i]; + filename source_file = source.path() + filename::default_separator() + + curr->raw(); + filename target_file = target.path() + filename::default_separator() + + curr->secondary(); +//LOG(istring("cp source: ") + source_file.raw()); +//LOG(istring("-> target: ") + target_file.raw()); + filename targ_dir = target_file.dirname(); + if (!targ_dir.is_directory()) { + bool worked = directory::recursive_create(targ_dir); + if (!worked) + non_continuable_error(class_name(), "recursive mkdir", + istring("failed to create the target directory ") + targ_dir); + } + + outcome ret = heavy_file_operations::copy_file(source_file, target_file); + if (ret != heavy_file_operations::OKAY) + non_continuable_error(class_name(), "copying file", istring("there was an error ") + + heavy_file_operations::outcome_name(ret) + + " when copying the file."); + } + +//do the copy by going across the entire set of files and making sure +//they get copied to target. +// +//reread the target location. +// +//compare with source tree read before. + + guards::alert_message("directory_tree file transfer:: works for those functions tested."); + return 0; +} + +HOOPLE_MAIN(test_fcopy, ) +