fix memory leak and unnecessary allocations
[oweals/gnunet.git] / src / namestore / test_namestore_delete.sh
1 #!/bin/bash
2 CONFIGURATION="test_namestore_api.conf"
3 trap "gnunet-arm -e -c $CONFIGURATION" SIGINT
4
5 LOCATION=$(which gnunet-config)
6 if [ -z $LOCATION ]
7 then
8   LOCATION="gnunet-config"
9 fi
10 $LOCATION --version 1> /dev/null
11 if test $? != 0
12 then
13         echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
14         exit 77
15 fi
16
17 rm -rf `$LOCATION -c $CONFIGURATION -s PATHS -o GNUNET_HOME`
18 TEST_DOMAIN_PLUS="www.gnu"
19 TEST_DOMAIN_DNS="www3.gnu"
20 TEST_IP_PLUS="127.0.0.1"
21 TEST_IP_DNS="131.159.74.67"
22 TEST_RECORD_CNAME_SERVER="server"
23 TEST_RECORD_CNAME_PLUS="server.+"
24 TEST_RECORD_CNAME_DNS="gnunet.org"
25 TEST_RECORD_NAME_SERVER="server"
26 TEST_RECORD_NAME_PLUS="www"
27 TEST_RECORD_NAME_DNS="www3"
28 which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
29
30 function start_peer
31 {
32         gnunet-arm -s -c $CONFIGURATION
33         gnunet-identity -C testego -c $CONFIGURATION
34 }
35
36 function stop_peer
37 {
38         gnunet-identity -D testego -c $CONFIGURATION
39         gnunet-arm -e -c $CONFIGURATION
40 }
41
42
43 start_peer
44 # Create a public record
45 gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME_DNS -t A -V $TEST_IP_PLUS -e never -c $CONFIGURATION
46 # Delete record
47 gnunet-namestore -p -z testego -d -n $TEST_RECORD_NAME_DNS -t A -V $TEST_IP_PLUS -e never -c $CONFIGURATION
48 # List all records
49 OUTPUT=`gnunet-namestore -p -z testego -D`
50 FOUND_IP=false
51 FOUND_NAME=false
52 for LINE in $OUTPUT ;
53  do
54         if echo "$LINE" | grep -q "$TEST_RECORD_NAME_DNS"; then
55                 FOUND_NAME=true;
56         fi
57         if echo "$LINE" | grep -q "$TEST_IP_PLUS"; then
58                 FOUND_IP=true;
59         fi
60  done
61 stop_peer
62
63
64 if [ $FOUND_NAME == false -a $FOUND_IP != false ]
65 then
66   echo "PASS: Delete name in namestore"
67   exit 0
68 elif [ $FOUND_NAME == true ]
69 then
70   echo "FAIL: Delete name in namestore: name returned"
71   exit 1
72 elif [ $FOUND_IP == true ]
73 then
74   echo "FAIL: Delete name in namestore: IP returned"
75   exit 1
76 fi