diff options
author | Roberto C. Sanchez <roberto@connexer.com> | 2014-03-29 10:53:33 -0400 |
---|---|---|
committer | Roberto C. Sanchez <roberto@connexer.com> | 2014-03-29 10:53:33 -0400 |
commit | 8d3fc864d094eeadc721f8e93436b37a5fab173e (patch) | |
tree | 05e201c67dca55b4ccdf90ad479a25d95e3b1e63 /tests/testblocks.cpp |
Imported Upstream version 1.5.3
Diffstat (limited to 'tests/testblocks.cpp')
-rw-r--r-- | tests/testblocks.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/testblocks.cpp b/tests/testblocks.cpp new file mode 100644 index 0000000..49a44c0 --- /dev/null +++ b/tests/testblocks.cpp @@ -0,0 +1,85 @@ +#include <entriesblk.h> +#include <iostream.h> +#include <string> +#include <stdio.h> + +using namespace std; + +void addEntry(EntriesBlock *eb) { + string input; + string body; + char line[1024]; + cout << "\nEnter new Entry's text. '.' on an empty line to finish:\n"; + do { + cout << "> "; + gets(line); + input = line; + if (input.compare(".")) + body.append(input); + } + while (input.compare(".")); + cout << "Adding new entry. Index is: " << eb->addEntry(body.c_str()) << "\n\n"; +} + + +void printEntry(EntriesBlock *eb, int index) { + if (index < eb->getCount()) { + cout << "Contents of entry [" << index << "]:\n"; + cout << eb->getEntry(index) << "\n"; + } + else cout << "Invalid entry number\n\n"; +} + + +void printSize(EntriesBlock *eb) { + unsigned long size; + eb->getRawData(&size); + cout << "Size of raw data: " << size << "\n\n"; +} + + +void removeEntry(EntriesBlock *eb, int index) { + if (index < eb->getCount()) { + cout << "Removing entry [" << index << "]\n"; + eb->removeEntry(index); + } + else cout << "Invalid entry number\n\n"; +} + + +int main(int argc, char **argv) { + + EntriesBlock *eb = new EntriesBlock(); + string input; + char line[1024]; + + cout << "Initial entry count should be 0: " << eb->getCount() << "\n"; + + do { + cout << "[" << eb->getCount() << "] > "; + gets(line); + input = line; + if (input.length() > 0) { + switch (input[0]) { + case 'a': addEntry(eb); break; + case 'p': printEntry(eb, atoi(input.c_str()+1)); break; + case 'r': removeEntry(eb, atoi(input.c_str()+1)); break; + case 's': printSize(eb); break; + case 'q': break; + case '?': + default: + cout << "\n a - add a new entry\n"; + cout << " p <entry_index> - print entry\n"; + cout << " r <entry_index> - remove entry\n"; + cout << " s - print size of raw data\n"; + cout << " q - quit\n\n"; + break; + } + } + } + while (input.compare("q")); + + delete eb; + + return 0; +} |