From: Fred T. Hamster Date: Tue, 31 May 2022 12:21:10 +0000 (-0400) Subject: last minor changes to get filename test working X-Git-Tag: 2.140.136^2~50 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=e7cb32011d5b8d577904e0e9a19454021d825337;p=feisty_meow.git last minor changes to get filename test working perhaps this is the last thing that wasn't right on windoze yet, except the bundler? --- diff --git a/nucleus/library/configuration/application_configuration.cpp b/nucleus/library/configuration/application_configuration.cpp index 05259f12..b3927849 100644 --- a/nucleus/library/configuration/application_configuration.cpp +++ b/nucleus/library/configuration/application_configuration.cpp @@ -304,23 +304,22 @@ const astring &application_configuration::DEFAULT_VIRTUAL_UNIX_ROOT() // so we cache it once we retrieve it. SAFE_STATIC(astring, static_root_holder, ) -astring application_configuration::get_virtual_unix_root() +const astring &application_configuration::virtual_unix_root() { -#ifdef __UNIX__ - // simple implementation for unix/linux; just tell the truth about the real root. - return "/"; -#endif -#ifdef __WIN32__ // see if we already cached the root. it shouldn't change during runtime. if (static_root_holder().length()) { return static_root_holder(); } - +#ifdef __UNIX__ + // simple implementation for unix/linux; just tell the truth about the real root. + static_root_holder() = astring("/"); + return static_root_holder(); +#endif +#ifdef __WIN32__ /* use the path in our system helpers header, which should have been set during the build process if this is really windows. */ -/// astring virtual_root = read_item(WINDOZE_VIRTUAL_ROOT_NAME()); astring virtual_root = FEISTY_MEOW_VIRTUAL_UNIX_ROOT; if (!virtual_root) { // if it has no length, we didn't get our setting! we'll limp along with a guess. diff --git a/nucleus/library/configuration/application_configuration.h b/nucleus/library/configuration/application_configuration.h index 5633beae..293f0fdb 100644 --- a/nucleus/library/configuration/application_configuration.h +++ b/nucleus/library/configuration/application_configuration.h @@ -79,7 +79,7 @@ public: unless there are special purposes for those log files. but logs from general operation of feisty meow should be written in this directory. */ - static basis::astring get_virtual_unix_root(); + static const basis::astring &virtual_unix_root(); //!< returns the path to the unix root, which may be simulated. /*!< on unix, this will just return '/'. on win32 with cygwin installed, this will return the cygwin path for '/' that was detected at build time. @@ -97,16 +97,9 @@ public: to particular programs or subsystems should be contained in their own section. */ -/// static const basis::astring &LOCAL_FOLDER_NAME(); - //!< entry name in the config file that points at the installation root. - /*!< this is where all files for this product are stored on "this" machine. */ - static const basis::astring &LOGGING_FOLDER_NAME(); //!< the tag used for finding our logging path in the paths config file. -// static const basis::astring &WINDOZE_VIRTUAL_ROOT_NAME(); - //!< the tag used for looking up the virtual windows path in the paths config file. - static const basis::astring &DEFAULT_VIRTUAL_UNIX_ROOT(); //!< default value if we don't find our setting for virtual root. /*!< this is bound to fail on many occasions if it's actually used on diff --git a/nucleus/library/tests_filesystem/test_filename.cpp b/nucleus/library/tests_filesystem/test_filename.cpp index c72e9790..92cf1eb4 100644 --- a/nucleus/library/tests_filesystem/test_filename.cpp +++ b/nucleus/library/tests_filesystem/test_filename.cpp @@ -16,15 +16,19 @@ #include #include #include +#include #include +#include #include #include #include #include +#include #include using namespace application; using namespace basis; +using namespace configuration; using namespace mathematics; using namespace filesystem; using namespace loggers; @@ -33,6 +37,8 @@ using namespace textual; using namespace timely; using namespace unit_test; +#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s) + class test_filename : virtual public unit_base, public virtual application_shell { public: @@ -40,11 +46,103 @@ public: DEFINE_CLASS_NAME("test_filename"); virtual int execute(); void clean_sequel(astring &sequel); + astring virtual_root(); + void dump_string_array(const astring &title, const string_array &to_dump); + bool verify_equal_string_array(const astring &group, const string_array &exemplar, const string_array &acolyte); + bool prepare_string_arrays_for_filenames(const astring &common_bit, const astring &group, + bool &exemplar_rooted, string_array &exemplar_pieces, bool &acolyte_rooted, + string_array &acolyte_pieces); }; void test_filename::clean_sequel(astring &sequel) { sequel.replace_all('\\', '/'); } +astring test_filename::virtual_root() +{ + astring virt_root = application_configuration::virtual_unix_root(); + if (!!virt_root && !filename::separator(virt_root[virt_root.length() - 1])) { + // this is not terminated with a slash, which is possible for dosdows. + // we'll make it a reliable directory component by adding a slash. + virt_root += astring("/"); + } + return virt_root; +} + +void test_filename::dump_string_array(const astring &title, const string_array &to_dump) +{ + FUNCDEF("dump_string_array"); + LOG(title); + for (int i = 0; i < to_dump.length(); i++) { + LOG(a_sprintf("%d: '", i) + to_dump[i] + "'"); + } +} + +/* + due to some difference in behavior between the platforms, we need to turn + rooted paths that work perfectly find on unix systems into a bizarre messed + up c drive version for windows (based on the virtual unix system in place, + although only cygwin is currently supported). this assumes the virtual root + is available... we accomplish our testing a platform invariant way by by + simulating the same operations filename does, but using our exemplar paths + as the starting point. +*/ + +bool test_filename::verify_equal_string_array(const astring &group, const string_array &exemplar, const string_array &acolyte) +{ + FUNCDEF("verify_equal_string_array"); + +//temp debug +dump_string_array("exemplar", exemplar); +dump_string_array("acolyte", acolyte); + + // doing some extra assertions in here, to complain about what went wrong, but then we still need to return a success value. + ASSERT_EQUAL(exemplar.length(), acolyte.length(), group + "the list was the wrong length"); + if (exemplar.length() != acolyte.length()) { return false; } + + for (int indy = 0; indy < exemplar.length(); indy++) { + bool success = acolyte[indy].equal_to(exemplar[indy]); + ASSERT_TRUE(success, group + a_sprintf("piece %d did not match: ", indy) + "'" + + acolyte[indy] + "' vs expected '" + exemplar[indy] + "'"); + if (!success) { return false; } // fail fast. + } + return true; +} + +/* + helper method constructs string arrays for the filename with common_bit as + the portion after the root ('/'). the exemplar array is generated + independently from the acolyte string array to ensure that it is correctly + constructed (with a virtual root and then a non-rooted chunk). +*/ +bool test_filename::prepare_string_arrays_for_filenames(const astring &common_bit, const astring &group, + bool &exemplar_rooted, string_array &exemplar_pieces, + bool &acolyte_rooted, string_array &acolyte_pieces) +{ + FUNCDEF("prepare_string_arrays_for_filenames") + bool to_return = true; // success until we learn otherwise. + + // generate the acolyte, which will be tested again, very straightforwardly. + // it is a non-rooted string, so we just slap the virtual root in front. + filename acolyte_fn(virtual_root() + common_bit); + acolyte_fn.separate(acolyte_rooted, acolyte_pieces); + + // generate the exemplar without allowing filename to operate on the whole + // string. we get the virtual root first and operate on it as a filename, + // then we slap on the unrooted portion to get the unmanipulated form. + filename(virtual_root()).separate(exemplar_rooted, exemplar_pieces); + { + string_array common_pieces; + bool common_rooted; + filename(common_bit).separate(common_rooted, common_pieces); + ASSERT_FALSE(common_rooted, group + "the common_rooted value is erreonous"); + if (common_rooted) { to_return = false; } + // conjoin the rooty pieces with the common bits, hopefully hitting both platforms' sweet spots. + exemplar_pieces += common_pieces; + } + + return to_return; +} + int test_filename::execute() { FUNCDEF("execute") @@ -55,40 +153,34 @@ int test_filename::execute() } -//hmmm: totally hosed here due to differences on win32. -// we need to start in a proper state: -// the test strings should all be constructed using the virtual unix root! then the results will match. -// -// until we can fix this, gotta bail on running these. -/* - { // second test group. - astring GROUP = "separate-- "; - filename turkey("/omega/ralph/turkey/buzzard.txt"); - string_array pieces; - bool rooted; - turkey.separate(rooted, pieces); - ASSERT_TRUE(rooted, GROUP + "the rooted value is erreonous."); - ASSERT_TRUE(pieces[0].equal_to("omega"), GROUP + "the first piece didn't match."); - ASSERT_TRUE(pieces[1].equal_to("ralph"), GROUP + "the second piece didn't match."); - ASSERT_TRUE(pieces[2].equal_to("turkey"), GROUP + "the third piece didn't match."); - ASSERT_TRUE(pieces[3].equal_to("buzzard.txt"), GROUP + "the fourth piece didn't match."); - ASSERT_EQUAL(pieces.length(), 4, GROUP + "the list was the wrong length"); + + astring GROUP = "testing separate() "; + astring common_bit = "omega/ralph/turkey/buzzard.txt"; + string_array turkey_pieces; + bool turkey_rooted; + string_array exemplar_pieces; + bool exemplar_rooted; + bool worked = test_filename::prepare_string_arrays_for_filenames(common_bit, GROUP, + exemplar_rooted, exemplar_pieces, turkey_rooted, turkey_pieces); + + ASSERT_EQUAL(turkey_rooted, exemplar_rooted, GROUP + "the turkey_rooted value is erreonous."); + ASSERT_TRUE(verify_equal_string_array(GROUP, exemplar_pieces, turkey_pieces), "the turkey array differs from exemplar"); } { // third test group. astring GROUP = "third: test compare_prefix "; - filename turkey("/omega/ralph/turkey/buzzard.txt"); - filename murpin1("/omega"); - filename murpin2("/omega/ralph"); - filename murpin3("/omega/ralph/turkey"); - filename murpin4("/omega/ralph/turkey/buzzard.txt"); + filename turkey(virtual_root() + "omega/ralph/turkey/buzzard.txt"); + filename murpin1(virtual_root() + "omega"); + filename murpin2(virtual_root() + "omega/ralph"); + filename murpin3(virtual_root() + "omega/ralph/turkey"); + filename murpin4(virtual_root() + "omega/ralph/turkey/buzzard.txt"); filename murpin_x1("ralph/turkey/buzzard.txt"); - filename murpin_x2("/omega/ralph/turkey/buzzard.txt2"); - filename murpin_x3("/omega/turkey/buzzard.txt"); - filename murpin_x4("/omega/ralph/turkey/b0/buzzard.txt"); + filename murpin_x2(virtual_root() + "omega/ralph/turkey/buzzard.txt2"); + filename murpin_x3(virtual_root() + "omega/turkey/buzzard.txt"); + filename murpin_x4(virtual_root() + "omega/ralph/turkey/b0/buzzard.txt"); filename murpin_x5("moomega/ralph/turkey"); astring sequel; @@ -133,12 +225,12 @@ int test_filename::execute() { // fourth test group. astring GROUP = "fourth: test compare_suffix "; - filename turkey("/omega/ralph/turkey/buzzard.txt"); + filename turkey(virtual_root() + "omega/ralph/turkey/buzzard.txt"); filename murpin1("turkey\\buzzard.txt"); filename murpin2("turkey/buzzard.txt"); filename murpin3("ralph/turkey/buzzard.txt"); filename murpin4("omega/ralph/turkey/buzzard.txt"); - filename murpin5("/omega/ralph/turkey/buzzard.txt"); + filename murpin5(virtual_root() + "omega/ralph/turkey/buzzard.txt"); ASSERT_TRUE(murpin1.compare_suffix(turkey), GROUP + "compare 1 failed"); ASSERT_TRUE(murpin2.compare_suffix(turkey), GROUP + "compare 2 failed"); @@ -195,31 +287,34 @@ int test_filename::execute() test2.push("klemper"); ASSERT_EQUAL(test2, filename("c:/flug/blumen/klemper"), GROUP + "dpush 1 failed"); // test unix paths. - filename test3("/flug/blumen/klemper/smooden"); + filename test3(virtual_root() + "flug/blumen/klemper/smooden"); ASSERT_EQUAL(test3.basename(), astring("smooden"), GROUP + "basename 1 failed"); - ASSERT_EQUAL(test3.dirname(), filename("/flug/blumen/klemper"), + ASSERT_EQUAL(test3.dirname(), filename(virtual_root() + "flug/blumen/klemper"), GROUP + "u-dirname 1 failed"); filename test4 = test3; popped = test4.pop(); ASSERT_EQUAL(popped, astring("smooden"), GROUP + "upop 1 return failed"); - ASSERT_EQUAL(test4, filename("/flug/blumen/klemper"), GROUP + "upop 1 failed"); + ASSERT_EQUAL(test4, filename(virtual_root() + "flug/blumen/klemper"), GROUP + "upop 1 failed"); test4.pop(); test4.pop(); - ASSERT_EQUAL(test4, filename("/flug"), GROUP + "upop 2 failed"); + ASSERT_EQUAL(test4, filename(virtual_root() + "flug"), GROUP + "upop 2 failed"); popped = test4.pop(); - ASSERT_EQUAL(popped, astring("flug"), GROUP + "upop 1 return failed"); - ASSERT_EQUAL(test4, filename("/"), GROUP + "upop 3 failed"); + ASSERT_EQUAL(popped, astring("flug"), GROUP + "upop 2 return failed"); + ASSERT_EQUAL(test4, filename(virtual_root()), GROUP + "upop 3 failed"); test4.pop(); - ASSERT_EQUAL(test4, filename("/"), GROUP + "upop 3 failed"); + filename special_popped = filename(virtual_root()); + special_popped.pop(); + ASSERT_EQUAL(test4, special_popped, GROUP + "upop 4 failed"); + test4 = filename(virtual_root()); test4.push("flug"); test4.push("blumen"); test4.push("klemper"); - ASSERT_EQUAL(test4, filename("/flug/blumen/klemper"), GROUP + "upush 1 failed"); + ASSERT_EQUAL(test4, filename(virtual_root() + "flug/blumen/klemper"), GROUP + "upush 1 failed"); } { // seventh test group. astring GROUP = "seventh: testing pack and unpack "; - filename test1("/usr/local/athabasca"); + filename test1(virtual_root() + "usr/local/athabasca"); byte_array packed; int size_guess = test1.packed_size(); test1.pack(packed); @@ -238,14 +333,17 @@ int test_filename::execute() ASSERT_EQUAL(test2, astring("r:/"), GROUP + "test 2 failed"); filename test3("/cygdrive/r/"); ASSERT_EQUAL(test3, astring("r:/"), GROUP + "test 3 failed"); + // this is a broken pattern, which we don't expect to resolve to a drive. filename test4("/cygdrive//"); - ASSERT_EQUAL(test4, astring("/cygdrive"), GROUP + "test 4 failed"); + ASSERT_EQUAL(test4, virtual_root() + "cygdrive", GROUP + "test 4 failed"); + // another broken pattern. filename test5("/cygdrive/"); - ASSERT_EQUAL(test5, astring("/cygdrive"), GROUP + "test 5 failed"); + ASSERT_EQUAL(test5, virtual_root() + "cygdrive", GROUP + "test 5 failed"); + // and one more. not great tests, but whatever. filename test6("/cygdrive"); - ASSERT_EQUAL(test6, astring("/cygdrive"), GROUP + "test 6 failed"); - filename test7("/klaunspendle"); - ASSERT_EQUAL(test7, astring("/klaunspendle"), GROUP + "test 7 failed"); + ASSERT_EQUAL(test6, virtual_root() + "cygdrive", GROUP + "test 6 failed"); + filename test7(virtual_root() + "klaunspendle"); + ASSERT_EQUAL(test7, astring(virtual_root() + "klaunspendle"), GROUP + "test 7 failed"); filename test8("z:/klaunspendle"); ASSERT_EQUAL(test8, astring("z:/klaunspendle"), GROUP + "test 8 failed"); @@ -261,17 +359,20 @@ int test_filename::execute() ASSERT_EQUAL(test14, astring("r:/"), GROUP + "test 14 failed"); filename test15("/r"); ASSERT_EQUAL(test15, astring("r:/"), GROUP + "test 15 failed"); - filename test16("/"); - ASSERT_EQUAL(test16, astring("/"), GROUP + "test 16 failed"); + + bool ex_rooted, ac_rooted; + string_array exemplar, acolyte; + ASSERT_TRUE(prepare_string_arrays_for_filenames(astring(""), GROUP, + ex_rooted, exemplar, ac_rooted, acolyte), GROUP + "test 16 failed prep"); + ASSERT_TRUE(verify_equal_string_array(GROUP, exemplar, acolyte), GROUP + "test 16 failed compare"); + filename test17("r/"); ASSERT_EQUAL(test17, astring("r/"), GROUP + "test 17 failed"); - filename test18("/kr/soop"); - ASSERT_EQUAL(test18, astring("/kr/soop"), GROUP + "test 18 failed"); + filename test18(virtual_root() + "kr/soop"); + ASSERT_EQUAL(test18, astring(virtual_root() + "kr/soop"), GROUP + "test 18 failed"); } #endif - */ - return final_report(); }