122 lines
1.8 KiB
Bash
Executable File
122 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Copyright 2014 (c) Anna Schumaker
|
|
|
|
. $(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
|
|
#
|
|
|
|
function test_autosave
|
|
{
|
|
new_test "Database Test (n = $1, autosave = true)"
|
|
src/database.run -a $1
|
|
if [ ! -f $DATA_DIR/database.db ] && [ $1 != 0 ]; then
|
|
echo "ERROR: $DATA_DIR/database.db doesn't exist!"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
function test_noautosave
|
|
{
|
|
new_test "Database Test (n = $1, autosave = false)"
|
|
src/database.run $1
|
|
if [ -f $DATA_DIR/database.db ]; then
|
|
echo "ERROR: $DATA_DIR/database.db exists!"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
function run_test
|
|
{
|
|
rm $DATA_DIR/* 2>/dev/null || true
|
|
|
|
if [ $1 -le 1000 ]; then
|
|
test_autosave $1
|
|
else
|
|
test_noautosave $1
|
|
fi
|
|
}
|
|
|
|
run_test 0
|
|
echo
|
|
run_test 10
|
|
echo
|
|
run_test 100
|
|
echo
|
|
run_test 1000
|
|
echo
|
|
run_test 10000
|
|
echo
|
|
run_test 100000
|