2 * Name : test_huge_file
3 * Author : Chris Koeritz
5 * Copyright (c) 1991-$now By Author. This program is free software; you can *
6 * redistribute it and/or modify it under the terms of the GNU General Public *
7 * License as published by the Free Software Foundation; either version 2 of *
8 * the License or (at your option) any later version. This is online at: *
9 * http://www.fsf.org/copyleft/gpl.html *
10 * Please send any updates to: fred@gruntose.com *
13 #include <application/hoople_main.h>
14 #include <basis/byte_array.h>
15 #include <basis/functions.h>
16 #include <basis/guards.h>
17 #include <basis/astring.h>
18 #include <configuration/application_configuration.h>
19 #include <filesystem/directory.h>
20 #include <filesystem/filename.h>
21 #include <filesystem/huge_file.h>
22 #include <loggers/critical_events.h>
23 #include <loggers/program_wide_logger.h>
24 #include <mathematics/chaos.h>
25 #include <structures/static_memory_gremlin.h>
26 #include <structures/string_array.h>
27 #include <unit_test/unit_base.h>
29 using namespace application;
30 using namespace basis;
31 using namespace configuration;
32 using namespace mathematics;
33 using namespace filesystem;
34 using namespace loggers;
35 using namespace structures;
36 using namespace textual;
37 using namespace timely;
38 using namespace unit_test;
40 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
42 class test_huge_file : public virtual unit_base, virtual public application_shell
45 test_huge_file() : application_shell() {}
46 DEFINE_CLASS_NAME("test_huge_file");
48 virtual int execute();
51 void test_huge_file::run_file_scan()
53 FUNCDEF("run_file_scan");
56 string_array files(application::_global_argc, (const char **)application::_global_argv);
57 files.zap(0, 0); // toss the first element since that's our app filename.
59 if (!files.length()) {
60 // pretend they gave us the list of files in the current directory. some of
61 // these might fail if they're locked up.
62 astring tmpdir = application_configuration::current_directory();
63 directory dir(tmpdir);
64 for (int i = 0; i < dir.files().length(); i++) {
65 // skip text files since we use those right here.
66 if (dir.files()[i].ends(".txt"))
68 astring chewed_string = tmpdir + "/" + dir.files()[i];
69 files += chewed_string;
71 //LOG(astring("added files since no cmd args: ") + files.text_form());
74 byte_array data_found;
75 for (int i = 0; i < files.length(); i++) {
76 astring curr = files[i];
77 // LOG(a_sprintf("file %d: ", i) + curr);
78 huge_file test(curr, "rb");
79 ASSERT_TRUE(test.good(), "good check should say yes, it's good.");
80 double len = test.length();
81 //log(a_sprintf("file len is %.0f", len));
83 while ( (posn < len) && !test.eof() ) {
84 int readlen = randomizer.inclusive(1, 256 * KILOBYTE);
85 //log(a_sprintf("read %.0f bytes, posn now %.0f bytes", double(readlen), posn));
87 outcome ret = test.read(data_found, readlen, bytes_read);
88 ASSERT_EQUAL(ret.value(), huge_file::OKAY, "should be able to read file");
89 if (ret == huge_file::OKAY) {
93 ASSERT_TRUE(test.eof(), "eof check should be at eof.");
95 log(a_sprintf("failed check, want %.0f, got %.0f", double(len), double(posn)));
96 ASSERT_EQUAL(posn, len, "eof check should be at right position: ");
97 // log(astring("successfully read ") + curr);
101 int test_huge_file::execute()
105 return final_report();
108 HOOPLE_MAIN(test_huge_file, )