Not logged in

Artifact 8ef24cd0f344ba0dac847173c56d770c79098930:


#!/bin/sh
# system_tests.test --- Run system tests on the zeptodb executables

# Copyright (C) 2013, 2016 Brandon Invergo <brandon@invergo.net>

# Author: Brandon Invergo <brandon@invergo.net>

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

BINDIR="@srcdir@/src"
ZDBC="${BINDIR}/zdbc"
ZDBF="${BINDIR}/zdbf"
ZDBR="${BINDIR}/zdbr"
ZDBS="${BINDIR}/zdbs"

if [ @WITH_KYOTOCABINET@ ]; then
    TESTDB=test.kch
else
    TESTDB=test.db
fi

msg () {
    printf "%s\n" "$1"
}

fail () {
    msg "not ok $1 - $2"
}

pass () {
    msg "ok $1 - $2"
}

xfail () {
    msg "ok $1 - $2"
}

test_create_db () {
    "${ZDBC}" ${TESTDB} || fail $1 "database creation failed"
    if [ -f ${TESTDB} ]; then
        pass $1 "database created"
    else
        fail $1 "database creation process succeeded but file does not exist"
    fi
    rm ${TESTDB}
}

test_large_args () {
    "${ZDBC}" --cache-size=1000000000000000000 \
        --mmap-size=1000000000000000000 ${TESTDB} || \
        fail $1 "large argument usage failed"
    if [ -f ${TESTDB} ]; then
        pass $1 "large argument usage succeeded"
    else
        fail $1 "large argument usage failed"
    fi
    rm ${TESTDB}
    return $?
}

test_neg_args () {
    "${ZDBC}" --cache-size=-5 \
        --mmap-size=-5 ${TESTDB} || \
        fail $1 "negative argument usage failed"
    if [ -f ${TESTDB} ]; then
        pass $1 "negative argument usage succeeded"
    else
        fail $1 "negative argument usage failed"
    fi
    rm ${TESTDB}
    return $?
}

create_test_db () {
    "${ZDBC}" ${TESTDB}
}

remove_test_db () {
    rm ${TESTDB}
}

test_store_records () {
    "${ZDBS}" ${TESTDB} <<EOF
foo|bar
baz|quux
blah|bleh
another|record
EOF
    [ $? ] || fail $1 "store records failed"
    pass $1 "store records succeeded"
    return $?
}

test_store_records_with_alt_delim () {
    "${ZDBS}" -d'~' ${TESTDB} <<EOF
1~2
3~4
5~6
EOF
    [ $? ] || fail $1 "store records with alternate delimiter failed"
    pass $1 "store records with alternate delimiter succeeded"
    return $?
}

test_fetch_records () {
    vals=`"${ZDBF}" ${TESTDB} <<EOF
foo
baz
EOF
` || fail $1 "fetch records failed"
    if [[ "$vals" != `printf "bar\nquux"` ]]; then
        fail $1 "fetch records returned the wrong results"
    else
        pass $1 "fetch records succeeded"
    fi
    return $?
}

test_fetch_records_with_delim () {
    vals=`"${ZDBF}" -d'~' ${TESTDB} <<EOF
foo
baz
EOF
` || fail $1 "fetch records with a delimiter failed"
    if [[ "$vals" != `printf "foo~bar\nbaz~quux"` ]]; then
        fail $1 "fetch records with a delimiter returned the wrong results"
    else
        pass $1 "fetch records with delimiter succeeded"
    fi
    return $?
}

test_fetch_all_records () {
    numrecs=`"${ZDBF}" -a ${TESTDB} | wc -l` || fail $1 "fetch all records failed"
    if [[ "$numrecs" != "7" ]]; then
        fail $1 "fetch all records returned the wrong results"
    else
        pass $1 "fetch all records succeeded"
    fi
    return $?
}

test_remove_records () {
    "${ZDBR}" ${TESTDB} <<EOF
foo
baz
blah
another
1
3
5
EOF
    [ $? ] || fail $1 "remove records failed"
    if [[ "x`"${ZDBF}" -a ${TESTDB}`" != "x" ]]; then
        fail $1 "remove records - some records remain"
    else
        pass $1 "remove records succeeded"
    fi
    return $?
}

echo 1..9
test_create_db 1
test_large_args 2
test_neg_args 3
create_test_db
test_store_records 4
test_store_records_with_alt_delim 5
test_fetch_records 6
test_fetch_records_with_delim 7
test_fetch_all_records 8
test_remove_records 9
remove_test_db