database: Remove old db_entry test

This might have made more sense for an earlier version of the
DatabaseEntry class, but as far as I can tell this test only checks code
that exists inside this file.  This means I can removed it without
reducing code coverage.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-04-27 09:07:04 -04:00
parent 7b358259bd
commit 968ca30484
2 changed files with 0 additions and 176 deletions

View File

@ -4,74 +4,6 @@
. $(dirname $0)/_functions
###
#
# First, verify everything for a DatabaseEntry
#
function test_entry
{
test_equal "./src/db_entry.run $1 $2" "$3"
}
function test_print
{
test_entry $1 $2 "Value: $1 Key: $2 Id: 0"
}
function test_primary_key
{
test_entry "-p $1" $2 "Primary key: $2"
}
function test_write
{
rm $DATA_DIR/db_entry.txt 2>/dev/null || true
./src/db_entry.run -w $1 $2
test_equal "tail -1 $DATA_DIR/db_entry.txt" "$1 $2"
}
function test_read
{
rm $DATA_DIR/db_entry.txt 2>/dev/null || true
echo 0 > $DATA_DIR/db_entry.txt
echo $1 $2 >> $DATA_DIR/db_entry.txt
test_entry "-r $1" $2 "Value: $1 Key: $2 Id: 0"
}
new_test "Database Entry Print Test"
test_print 1 1
test_print 1 2
test_print 2 1
test_print 2 2
echo
new_test "Database Entry Primary Key Test"
test_primary_key 1 1
test_primary_key 1 2
test_primary_key 2 1
test_primary_key 2 2
echo
new_test "Database Entry Write Test"
test_write 1 1
test_write 1 2
test_write 2 1
test_write 2 2
echo
new_test "Database Entry Read Test"
test_read 1 1
test_read 1 2
test_read 2 1
test_read 2 2
echo
###
#
# Now, test the actual database

View File

@ -1,108 +0,0 @@
/*
* Copyright 2014 (c) Anna Schumaker.
* Test a DatabaseEntry
*/
#include <database.h>
#include <file.h>
#include <print.h>
#include <string>
#include <stdlib.h>
#include <unistd.h>
enum action_t { PRIMARY_KEY, PRINT, READ, WRITE };
class IntEntry : public DatabaseEntry {
public:
unsigned int val;
std::string key;
IntEntry(unsigned int, const std::string &);
const std::string primary_key() const;
void write(File &);
void read(File &);
void print();
};
IntEntry :: IntEntry(unsigned int i, const std::string &s)
{
val = i;
key = s;
}
const std::string IntEntry :: primary_key() const
{
return key;
}
void IntEntry :: write(File &f)
{
f << val << " " << key;
}
void IntEntry :: read(File &f)
{
f >> val >> key;
}
void IntEntry :: print()
{
:: print("Value: %u Key: %s Id: %u\n", val, key.c_str(), id);
}
int main(int argc, char **argv)
{
action_t action = PRINT;
char c;
while ((c = getopt(argc, argv, "prw")) != -1) {
switch (c) {
case 'p':
action = PRIMARY_KEY;
break;
case 'r':
action = READ;
break;
case 'w':
action = WRITE;
break;
}
}
if (optind >= argc) {
print("ERROR: Not enough arguments\n");
return 1;
}
unsigned int i = atoi(argv[optind++]);
std::string key = argv[optind];
File f("db_entry.txt");
IntEntry ient(i, key);
switch (action) {
case PRIMARY_KEY:
print("Primary key: %s\n", ient.primary_key().c_str());
break;
case PRINT:
ient.print();
break;
case READ:
f.open(OPEN_READ);
ient.read(f);
ient.print();
f.close();
break;
case WRITE:
f.open(OPEN_WRITE);
ient.write(f);
f.close();
break;
}
return 0;
}