Test creating notifications
[gnucomo.git] / test / notifications
1 #!/bin/bash
2
3 #
4 #  Test the service and log check notifications.
5 #  Create a database with two objects and no services. After reading two
6 #  log file fragments for these two objects, gcm_daemon should create
7 #  several notifications, three for each object.
8 #
9 #  This tests problem report nr. 23
10
11 #LD_LIBRARY_PATH=/usr/local/pqxx/lib
12 #export LD_LIBRARY_PATH
13
14
15 rm -f gcm_input.log
16
17 createdb gnucomo_test
18
19 result=0
20
21 if psql gnucomo_test -q <../src/database/create.sql >/dev/null
22 then
23    #  Prepare the database
24
25    psql gnucomo_test -q -c "insert into object (objectname) values ('example1.gnucomo.test')"
26    psql gnucomo_test -q -c "insert into object (objectname) values ('example2.gnucomo.test')"
27    psql gnucomo_test -q -c "delete from service"
28
29    #  read logs for both objects
30
31    ../src/gcm_input/gcm_input -c gnucomo_test -h example1.gnucomo.test -d 'sep 5 2002 20:30:45' <messages.bad
32    ../src/gcm_input/gcm_input -c gnucomo_test -h example2.gnucomo.test -d 'sep 5 2002 20:30:45' <messages
33
34    # Make the notifications.
35    cd ../src/gcm_daemon; ./gcm_daemon.php -c gnucomo_test; cd ../../test
36
37    # Check the notifications, 3 for each object.
38
39    NR_NOTIF1=`psql gnucomo_test -q -t -c "select count(*) from notification where objectid=1"`
40    NR_NOTIF2=`psql gnucomo_test -q -t -c "select count(*) from notification where objectid=2"`
41
42    if [[ $NR_NOTIF1 -ne 3 ]]
43    then
44       echo "$NR_NOTIF1 notifications for object 1 (3 expected)."
45       result=2
46    fi
47
48    if [[ $NR_NOTIF2 -ne 3 ]]
49    then
50       echo "$NR_NOTIF2 notifications for object 2 (3 expected)."
51       result=3
52    fi
53
54    #  Clean up.
55
56    psql gnucomo_test -f ../src/database/destroy.sql -q
57    dropdb gnucomo_test
58
59    exit $result
60 else
61    echo Can not create test database
62    dropdb gnucomo_test
63    exit 1
64 fi