+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;
+}
+