45#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
55 int run_simple_test();
62 const char *TEST_FILE_BASE =
"/zz_garbage";
63 const char *TEST_FILE_SUFFIX =
".txt";
64 static astring __hidden_filename;
65 if (!__hidden_filename) {
67 if (!__hidden_filename) __hidden_filename =
"/tmp";
70 __hidden_filename += TEST_FILE_BASE;
72 __hidden_filename += TEST_FILE_SUFFIX;
74 return __hidden_filename;
77int test_byte_filer::run_simple_test()
80#ifdef DEBUG_BYTE_FILER
81 LOG(
"ahoy, beginning file test...");
90 garbage.write(
"oy.\n");
93 ASSERT_TRUE(test1.exists(),
"exists test file should exist");
94 filename test2(
"c:\\this_file_shouldNt_exist_ever.txt");
95 ASSERT_FALSE(test2.exists(),
"weird file should not existed");
97 ASSERT_FALSE(test2.exists(),
"weird file should still not exist");
100 int block_size =
randomizer.inclusive(3000, 30000);
101#ifdef DEBUG_BYTE_FILER
104 abyte *original_block =
new abyte[block_size];
105 for (
int i = 0; i < block_size; i++)
107 unsigned int original_checksum
109 if (original_checksum) {}
110#ifdef DEBUG_BYTE_FILER
111 LOG(
a_sprintf(
"random block checksum=%d", original_checksum));
114 byte_array to_stuff_in_file(block_size, original_block);
115 delete [] original_block;
117 fred.write(to_stuff_in_file);
119#ifdef DEBUG_BYTE_FILER
120 LOG(
astring(
"about to compare file to checksum"));
125 delete [] temp_array;
127#ifdef DEBUG_BYTE_FILER
130 int should_be_failure = fred.write(to_fake_stuff);
131 ASSERT_EQUAL(should_be_failure, 0,
"write on read only, should not succeed");
133#ifdef DEBUG_BYTE_FILER
134 LOG(
a_sprintf(
"about to try reading from file %d bytes", block_size * 2));
137 int bytes_read = fred.read(file_contents, block_size * 2);
138 ASSERT_EQUAL(bytes_read, block_size,
"reading entire file should get proper size");
140 ASSERT_EQUAL((
int)check_2, (
int)original_checksum,
"should read correct contents for checksum");
151 for (
int i = 0; i < numpacs; i++) {
153 int bytes_in = fred.read(blob_i,
FACTOR);
154 ASSERT_FALSE(bytes_in >
FACTOR,
"we should never somehow read in more than we asked for");
155 whole_size += blob_i.
length();
157 ASSERT_EQUAL(whole_size, fred.length(),
"chunking comparison should see sizes as same");
168int test_byte_filer::run_file_scan()
176 if (!
files.length()) {
181 for (
int i = 0; i < dir.files().length(); i++) {
183 if ( (dir.files()[i].ends(
".txt")) || (dir.files()[i].ends(
".txt")) )
185 astring chewed_string = tmpdir +
"/" + dir.files()[i];
186 files += chewed_string;
192 for (
int i = 0; i <
files.length(); i++) {
197 LOG(
astring(
"good check: ") + curr +
" cannot be opened. is this bad?");
207 size_t len =
test.length();
210 while ( (posn < len) && !
test.eof() ) {
213 int bytes_read = int(
test.read(data_found,
int(readlen)));
214 ASSERT_TRUE(bytes_read >= 0,
"reading should not fail to read some bytes");
215 if (bytes_read > 0) {
220 ASSERT_EQUAL((
int)posn, (
int)len,
"eof check should be at right position");
227int test_byte_filer::execute()
230 int ret = run_simple_test();
232 ret = run_file_scan();
235 return final_report();
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
application_shell()
constructs an application_shell to serve as the root of the program.
a_sprintf is a specialization of astring that provides printf style support.
contents * access()
A non-constant access of the underlying C-array. BE REALLY CAREFUL.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
A very common template for a dynamic array of bytes.
static astring TMP()
provides a single place to get the temporary directory.
static basis::astring current_directory()
returns the current directory as reported by the operating system.
Provides file managment services using the standard I/O support.
@ FROM_START
offset is from the beginning of the file.
@ FROM_END
offset is from the end of the file.
Implements a scanner that finds all filenames in the directory specified.
static bool make_directory(const basis::astring &path)
returns true if the directory "path" could be created.
Provides operations commonly needed on file names.
a platform-independent way to acquire random numbers in a specific range.
static unsigned int bizarre_checksum(const basis::abyte *data, int length)
A different type of checksum with somewhat unknown properties.
An array of strings with some additional helpful methods.
#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.
type number_of_packets(type message_size, type packet_size)
Reports number of packets needed given a total size and the packet size.
unsigned char abyte
A fairly important unit which is seldom defined...
unsigned int un_int
Abbreviated name for unsigned integers.
const int KILOBYTE
Number of bytes in a kilobyte.
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.
const astring & TEST_FILE()
#define ASSERT_EQUAL(a, b, test_name)
#define ASSERT_TRUE(a, test_name)
#define ASSERT_FALSE(a, test_name)