13 #define DEBUG_FILENAME_TEST
30 using namespace basis;
40 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
47 virtual int execute();
48 void clean_sequel(
astring &sequel);
52 bool prepare_string_arrays_for_filenames(
const astring &common_bit,
const astring &group,
53 bool &exemplar_rooted,
string_array &exemplar_pieces,
bool &acolyte_rooted,
57 void test_filename::clean_sequel(
astring &sequel)
60 astring test_filename::virtual_root()
62 astring virt_root = application_configuration::virtual_unix_root();
63 if (!!virt_root && !filename::separator(virt_root[virt_root.
length() - 1])) {
75 for (
int i = 0; i < to_dump.
length(); i++) {
92 FUNCDEF(
"verify_equal_string_array");
95 dump_string_array(
"exemplar", exemplar);
96 dump_string_array(
"acolyte", acolyte);
100 if (exemplar.
length() != acolyte.
length()) {
return false; }
102 for (
int indy = 0; indy < exemplar.
length(); indy++) {
103 bool success = acolyte[indy].
equal_to(exemplar[indy]);
105 + acolyte[indy] +
"' vs expected '" + exemplar[indy] +
"'");
106 if (!success) {
return false; }
117 bool test_filename::prepare_string_arrays_for_filenames(
const astring &common_bit,
const astring &group,
121 FUNCDEF(
"prepare_string_arrays_for_filenames")
122 bool to_return = true;
126 filename acolyte_fn(virtual_root() + common_bit);
127 acolyte_fn.separate(acolyte_rooted, acolyte_pieces);
132 filename(virtual_root()).separate(exemplar_rooted, exemplar_pieces);
137 ASSERT_FALSE(common_rooted, group +
"the common_rooted value is erreonous");
138 if (common_rooted) { to_return =
false; }
140 exemplar_pieces += common_pieces;
146 int test_filename::execute()
152 ASSERT_FALSE(gorgeola.exists(),
"an empty filename should not exist");
159 astring GROUP =
"testing separate() ";
160 astring common_bit =
"omega/ralph/turkey/buzzard.txt";
164 bool exemplar_rooted;
165 bool worked = test_filename::prepare_string_arrays_for_filenames(common_bit, GROUP,
166 exemplar_rooted, exemplar_pieces, turkey_rooted, turkey_pieces);
168 ASSERT_EQUAL(turkey_rooted, exemplar_rooted, GROUP +
"the turkey_rooted value is erreonous.");
169 ASSERT_TRUE(verify_equal_string_array(GROUP, exemplar_pieces, turkey_pieces),
"the turkey array differs from exemplar");
174 astring GROUP =
"third: test compare_prefix ";
175 filename turkey(virtual_root() +
"omega/ralph/turkey/buzzard.txt");
176 filename murpin1(virtual_root() +
"omega");
177 filename murpin2(virtual_root() +
"omega/ralph");
178 filename murpin3(virtual_root() +
"omega/ralph/turkey");
179 filename murpin4(virtual_root() +
"omega/ralph/turkey/buzzard.txt");
180 filename murpin_x1(
"ralph/turkey/buzzard.txt");
181 filename murpin_x2(virtual_root() +
"omega/ralph/turkey/buzzard.txt2");
182 filename murpin_x3(virtual_root() +
"omega/turkey/buzzard.txt");
183 filename murpin_x4(virtual_root() +
"omega/ralph/turkey/b0/buzzard.txt");
184 filename murpin_x5(
"moomega/ralph/turkey");
187 ASSERT_TRUE(murpin1.compare_prefix(turkey, sequel), GROUP +
"first should match but didn't");
188 clean_sequel(sequel);
189 ASSERT_TRUE(sequel.
equal_to(
"ralph/turkey/buzzard.txt"), GROUP +
"first sequel was wrong");
190 ASSERT_TRUE(murpin2.compare_prefix(turkey, sequel), GROUP +
"second should match but didn't");
191 clean_sequel(sequel);
193 ASSERT_TRUE(murpin3.compare_prefix(turkey, sequel), GROUP +
"third should match but didn't");
194 clean_sequel(sequel);
196 ASSERT_TRUE(murpin4.compare_prefix(turkey, sequel), GROUP +
"fourth should match but didn't");
197 ASSERT_FALSE(sequel.
t(), GROUP +
"fourth had a sequel but shouldn't");
200 GROUP +
"x-first should not match but did");
202 GROUP +
"x-first had a sequel but shouldn't");
204 GROUP +
"x-second should not match but did");
206 GROUP +
"x-second had a sequel but shouldn't");
208 GROUP +
"x-third should not match but did");
210 GROUP +
"x-third had a sequel but shouldn't");
212 GROUP +
"x-fourth should not match but did");
214 GROUP +
"x-fourth had a sequel but shouldn't");
216 GROUP +
"x-fifth should not match but did");
218 GROUP +
"x-fifth had a sequel but shouldn't");
221 ASSERT_TRUE(murpin1.compare_prefix(turkey), GROUP +
"the two versions differed!");
222 ASSERT_FALSE(murpin_x1.compare_prefix(turkey), GROUP +
"x-the two versions differed!");
227 astring GROUP =
"fourth: test compare_suffix ";
228 filename turkey(virtual_root() +
"omega/ralph/turkey/buzzard.txt");
229 filename murpin1(
"turkey\\buzzard.txt");
230 filename murpin2(
"turkey/buzzard.txt");
231 filename murpin3(
"ralph/turkey/buzzard.txt");
232 filename murpin4(
"omega/ralph/turkey/buzzard.txt");
233 filename murpin5(virtual_root() +
"omega/ralph/turkey/buzzard.txt");
235 ASSERT_TRUE(murpin1.compare_suffix(turkey), GROUP +
"compare 1 failed");
236 ASSERT_TRUE(murpin2.compare_suffix(turkey), GROUP +
"compare 2 failed");
237 ASSERT_TRUE(murpin3.compare_suffix(turkey), GROUP +
"compare 3 failed");
238 ASSERT_TRUE(murpin4.compare_suffix(turkey), GROUP +
"compare 4 failed");
239 ASSERT_TRUE(murpin5.compare_suffix(turkey), GROUP +
"compare 5 failed");
241 ASSERT_FALSE(turkey.compare_suffix(murpin1), GROUP +
"compare x.1 failed");
248 astring GROUP =
"fifth: canonicalize command-line paths ";
264 astring GROUP =
"sixth: testing pop and push ";
266 filename test1(
"c:/flug/blumen/klemper/smooden");
271 GROUP +
"d-dirname 1 failed");
280 popped = test2.
pop();
286 test2.
push(
"blumen");
287 test2.
push(
"klemper");
290 filename test3(virtual_root() +
"flug/blumen/klemper/smooden");
293 GROUP +
"u-dirname 1 failed");
295 popped = test4.
pop();
301 popped = test4.
pop();
306 special_popped.
pop();
307 ASSERT_EQUAL(test4, special_popped, GROUP +
"upop 4 failed");
310 test4.
push(
"blumen");
311 test4.
push(
"klemper");
312 ASSERT_EQUAL(test4,
filename(virtual_root() +
"flug/blumen/klemper"), GROUP +
"upush 1 failed");
316 astring GROUP =
"seventh: testing pack and unpack ";
317 filename test1(virtual_root() +
"usr/local/athabasca");
319 int size_guess = test1.packed_size();
324 ASSERT_EQUAL(test2, test1, GROUP +
"packed contents differ, 1 failed");
329 astring GROUP =
"eighth: cygwin and msys paths ";
330 filename test1(
"/cygdrive/q/marbles");
338 ASSERT_EQUAL(test4, virtual_root() +
"cygdrive", GROUP +
"test 4 failed");
341 ASSERT_EQUAL(test5, virtual_root() +
"cygdrive", GROUP +
"test 5 failed");
344 ASSERT_EQUAL(test6, virtual_root() +
"cygdrive", GROUP +
"test 6 failed");
345 filename test7(virtual_root() +
"klaunspendle");
363 bool ex_rooted, ac_rooted;
366 ex_rooted, exemplar, ac_rooted, acolyte), GROUP +
"test 16 failed prep");
367 ASSERT_TRUE(verify_equal_string_array(GROUP, exemplar, acolyte), GROUP +
"test 16 failed compare");
371 filename test18(virtual_root() +
"kr/soop");
376 return final_report();
The application_shell is a base object for console programs.
a_sprintf is a specialization of astring that provides printf style support.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
bool t() const
t() is a shortcut for the string being "true", as in non-empty.
bool equal_to(const char *that) const
returns true if "that" is equal to this.
bool replace_all(char to_replace, char new_char)
changes all occurrences of "to_replace" with "new_char".
int length() const
Returns the current length of the string.
A very common template for a dynamic array of bytes.
Provides operations commonly needed on file names.
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
void separate(bool &rooted, structures::string_array &pieces) const
breaks the filename into its component parts.
void push(const basis::astring &to_push)
pushes a new filename onto the current pathname.
basis::astring pop()
removes the deepest component of the pathname.
An array of strings with some additional helpful methods.
bool equal_to(const equalizable &to_compare) const
Compares this string array for equality with "to_compare".
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
A dynamic container class that holds any kind of object via pointers.
Useful support functions for unit testing, especially within hoople.
#define ASSERT_EQUAL(a, b, test_name)
#define ASSERT_TRUE(a, test_name)
#define ASSERT_FALSE(a, test_name)