#!/bin/sh

lTest=1;
ret=0;

# Tests for v 0.1.2
# -----------------

cat << EOF > input
1151489802.66192#1#root#master.rebenweg:33299#NULL#Query#0#NULL#SHOW FULL PROCESSLIST
1151489802.71511#11#root#localhost#test#Sleep#0##NULL
1151489802.87177#1#root#master.rebenweg:33299#NULL#Query#0#NULL#SHOW FULL PROCESSLIST
1151489802.87177#11#root#localhost#test#Query#0#creating table#create table t1 (a int not null primary key, b int not null unique)
1151489802.92382#1#root#master.rebenweg:33299#NULL#Query#0#NULL#SHOW FULL PROCESSLIST
1151489802.92382#11#root#localhost#test#Query#0#NULL#create table t1 (a int not null primary key, b varchar(20) not null, unique (b(10)))
EOF

./profiler.pl --trace=input > output 2>&1

cat <<EOF > result

General infos
-------------
Slots         :        4
Time          :        0.262 s
Interval      :        0.065 s
Filters       : none
Lines total   :        6
Lines skipped :        0
Lines matched :        6

Commands
--------
Query                              5          0.327 s    83.3 %
Sleep                              1          0.065 s    16.7 %
-------------------------   --------   --------------   -------
Total                              6          0.393 s   100.0 %

State
-----
NULL                               4          0.262 s    66.7 %
Idling                             1          0.065 s    16.7 %
creating table                     1          0.065 s    16.7 %
-------------------------   --------   --------------   -------
Total                              6          0.393 s   100.0 %
EOF

diff output result
if test  $? -ne 0  ; then
  echo "Test $lTest failed"
  let ret=$ret+1
else
  echo "Test $lTest OK"
fi

let lTest=$lTest+1

# ----------------------------------------------------------------------

cat << EOF > input
152799999.9782#151876#ltread#10.49.250.79:50273#angebot#Sleep#1##NULL
1152799999.9782#151877#ltread#10.49.250.83:49707#angebot#Sleep#0##NULL
1152799999.9782#151878#ltread#10.49.250.76:56217#angebot#Query#0#Copying to tmp table#SELECT  *, zielort as SEA_destination_code  FROM angebot.hotel_B WHERE ...
1152799999.9782#151879#ltread#10.49.250.39:56299#angebot#Sleep#0##NULL
1152800000.05247#17407#ltread#10.49.135.70:10664#NULL#Query#0#NULL#SHOW FULL PROCESSLIST
1152800000.05247#50663#ltread#10.49.250.161:56473#angebot#Sleep#1007##NULL
1152800000.05247#132798#ltread#10.49.250.76:53769#angebot#Sleep#1732##NULL
EOF

./profiler.pl --trace=input > output 2>&1

cat <<EOF > result

General infos
-------------
Slots         :        2
Time          :        0.074 s
Interval      :        0.037 s
Filters       : none
Lines total   :        7
Lines skipped :        1
Lines matched :        6

Commands
--------
Sleep                              4          0.149 s    66.7 %
Query                              2          0.074 s    33.3 %
-------------------------   --------   --------------   -------
Total                              6          0.223 s   100.0 %

State
-----
Idling                             4          0.149 s    66.7 %
NULL                               1          0.037 s    16.7 %
Copying to tmp table               1          0.037 s    16.7 %
-------------------------   --------   --------------   -------
Total                              6          0.223 s   100.0 %
EOF

diff output result
if test  $? -ne 0  ; then
  echo "Test $lTest failed"
  let ret=$ret+1
else
  echo "Test $lTest OK"
fi

let lTest=$lTest+1

# ----------------------------------------------------------------------

rm input output result
echo "Failed tests: $ret"
exit $ret
