diff options
author | Roberto C. Sanchez <roberto@connexer.com> | 2014-03-29 10:53:59 -0400 |
---|---|---|
committer | Roberto C. Sanchez <roberto@connexer.com> | 2014-03-29 10:53:59 -0400 |
commit | 03134fa5f6f25d92724ce4c183f9bbe12a9e37dc (patch) | |
tree | 847326a4de82f0241ac87cbbc427a1b92a696a02 /tests/testblocks.cpp | |
parent | d7469385b05b9510338407fa123e9ad090f80af6 (diff) |
Imported Upstream version 1.5.11
Diffstat (limited to 'tests/testblocks.cpp')
-rw-r--r-- | tests/testblocks.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/testblocks.cpp b/tests/testblocks.cpp new file mode 100644 index 0000000..f386118 --- /dev/null +++ b/tests/testblocks.cpp @@ -0,0 +1,89 @@ +#include <entriesblk.h> +#include <iostream> +#include <string> +#include <stdio.h> +#include <stdlib.h> + +using namespace std; +#ifndef NO_SWORD_NAMESPACE +using namespace sword; +#endif + +void addEntry(EntriesBlock *eb) { + string input; + string body; + char line[1024]; + std::cout << "\nEnter new Entry's text. '.' on an empty line to finish:\n"; + do { + std::cout << "> "; + fgets(line, 1000, stdin); + input = line; + if (input.compare(".")) + body.append(input); + } + while (input.compare(".")); + std::cout << "Adding new entry. Index is: " << eb->addEntry(body.c_str()) << "\n\n"; +} + + +void printEntry(EntriesBlock *eb, int index) { + if (index < eb->getCount()) { + std::cout << "Contents of entry [" << index << "]:\n"; + std::cout << eb->getEntry(index) << "\n"; + } + else std::cout << "Invalid entry number\n\n"; +} + + +void printSize(EntriesBlock *eb) { + unsigned long size; + eb->getRawData(&size); + std::cout << "Size of raw data: " << size << "\n\n"; +} + + +void removeEntry(EntriesBlock *eb, int index) { + if (index < eb->getCount()) { + std::cout << "Removing entry [" << index << "]\n"; + eb->removeEntry(index); + } + else std::cout << "Invalid entry number\n\n"; +} + + +int main(int argc, char **argv) { + + EntriesBlock *eb = new EntriesBlock(); + string input; + char line[1024]; + + std::cout << "Initial entry count should be 0: " << eb->getCount() << "\n"; + + do { + std::cout << "[" << eb->getCount() << "] > "; + fgets(line, 1000, stdin); + 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: + std::cout << "\n a - add a new entry\n"; + std::cout << " p <entry_index> - print entry\n"; + std::cout << " r <entry_index> - remove entry\n"; + std::cout << " s - print size of raw data\n"; + std::cout << " q - quit\n\n"; + break; + } + } + } + while (input.compare("q")); + + delete eb; + + return 0; +} |