--- /dev/null
+#!/bin/bash
+
+#
+# Create an object 'kithira.andromeda.nl' in the database and
+# parse a piece of a XML file.
+
+rm -f gcm_input.log
+
+createdb gnucomo_test
+result=1
+
+if psql gnucomo_test -q <../src/database/create.sql >/dev/null
+then
+ psql gnucomo_test -q -c "insert into object (objectname) values ('kithira.andromeda.nl')"
+
+ # read logs from an XML file. 2 log entries are expected
+ echo "Read a good XML file"
+ ../src/gcm_input/gcm_input -v -c gnucomo_test <log.xml
+ NR_LOGS=`psql gnucomo_test -q -t -c "select count(*) from log"`
+ echo $NR_LOGS log entries in the datebase
+
+ # read a bad XML file, resulting in a parse error
+ psql gnucomo_test -q -t -c "delete from log"
+ echo "Read a bad XML file"
+ ../src/gcm_input/gcm_input -v -c gnucomo_test <log_bad.xml
+ result=$?
+ echo "gcm_input returned $result"
+
+ if [[ $result -eq 1 ]]
+ then
+ # check if nothing was stored in the (existing) database
+ NR_LOGS=`psql gnucomo_test -q -t -c "select count(*) from log"`
+ if [[ $NR_LOGS -eq 0 ]]
+ then
+ echo "No log entries in database"
+ result=0
+ fi
+ # check if the saved XML file exists
+ SAVEDFILE=`grep 'XML content stored' gcm_input.log |cut -d ' ' -f 12`
+ echo "Saved file is $SAVEDFILE"
+ if [[ ! -e $SAVEDFILE ]]
+ then
+ echo $SAVEDFILE does not exist.
+ result=2
+ fi
+ rm $SAVEDFILE # cleanup
+ else
+ echo "gcm_input did not return an error"
+ result=1
+ fi
+
+ psql gnucomo_test -f ../src/database/destroy.sql -q
+else
+ echo Can not create test database
+ result=1
+fi
+
+dropdb gnucomo_test
+exit $result