# Common definitions for rhizome test suites. # Copyright 2012 The Serval Project, Inc. # # 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 2 # 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, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Some useful regular expressions. These must work for grep(1) (as basic # expressions) and also in sed(1). rexp_service='[A-Za-z0-9_]\+' rexp_manifestid='[0-9a-fA-F]\{64\}' rexp_bundlekey='[0-9a-fA-F]\{64\}' rexp_bundlesecret="$rexp_bundlekey" rexp_filehash='[0-9a-fA-F]\{128\}' rexp_filesize='[0-9]\{1,\}' rexp_version='[0-9]\{1,\}' rexp_crypt='[0-9]\{1,\}' rexp_date='[0-9]\{1,\}' rexp_rowid='[0-9]\{1,\}' assert_manifest_complete() { local manifest="$1" tfw_cat -v "$manifest" assertGrep "$manifest" "^service=$rexp_service\$" assertGrep "$manifest" "^id=$rexp_manifestid\$" assertGrep "$manifest" "^BK=$rexp_bundlekey\$" assertGrep "$manifest" "^date=$rexp_date\$" assertGrep "$manifest" "^version=$rexp_version\$" assertGrep "$manifest" "^filesize=$rexp_filesize\$" if $GREP -q '^filesize=0$' "$manifest"; then assertGrep --matches=0 "$manifest" "^filehash=" else assertGrep "$manifest" "^filehash=$rexp_filehash\$" fi if $GREP -q '^service=file$' "$manifest"; then assertGrep "$manifest" "^name=" fi } # Assertion function: # - assert that the output of a "servald rhizome list" command exactly describes the given files assert_rhizome_list() { assertStdoutIs --stderr --line=1 -e '13\n' assertStdoutIs --stderr --line=2 -e '_id:service:id:version:date:.inserttime:.author:.fromhere:filesize:filehash:sender:recipient:name\n' local exactly=true local re__inserttime="$rexp_date" local re__fromhere='[01]' local re__author="\($rexp_sid\)\{0,1\}" local files=0 local manifestname= local arg for arg; do case "$arg" in --fromhere=*) re__fromhere="${arg#*=}";; --author=*) re__author="${arg#*=}";; --manifest=*) manifestname="${arg#*=}";; --and-others) exactly=false;; --*) error "unsupported option: $arg";; *) unpack_manifest_for_grep "$arg" "$manifestname" assertStdoutGrep --stderr --matches=1 "^$rexp_rowid:$re_service:$re_manifestid:$re_version:$re_date:$re__inserttime:$re__author:$re__fromhere:$re_filesize:$re_filehash:$re_sender:$re_recipient:$re_name\$" let files+=1 manifestname= ;; esac done $exactly && assertStdoutLineCount --stderr '==' $(($files + 2)) rhizome_list_file_count=$(( $(replayStdout | wc -l) - 2 )) } # Parse the standard output produced by the immediately preceding "rhizome list" # command into the following shell variables: # NCOLS the number of columns # NROWS the number of data rows (not counting headers) # HEADER[c] the C-th header label, 0 <= C <= NCOLS-1 #