#!/bin/bash

RASQL="rasql --user rasadmin --passwd rasadmin --quiet"
COLL=test_large
TYPE=GreySet

f=rasql_1.unknown

function check()
{
  if [ -f $f ]; then
    output=`file $f`
    if [ "$output" == "rasql_1.unknown: data" ]; then
      echo failed.
    else
      echo ok.
    fi
  else
    echo failed, file not found.
  fi
  rm -f $f
}

function test()
{
  fn="$1"
  echo -n * function $fn...
  $RASQL -q "select $fn from $COLL as c" --out file > /dev/null
  check
}

# vary size in MB
for sz in `seq 20`; do
  $RASQL -q "drop collection $COLL" > /dev/null
  $RASQL -q "create collection $COLL $TYPE" > /dev/null

  X=3
  Y=$(($sz * 262144))

  echo -------------------------------------------------------------------
  echo " Testing with $sz MB ($(($X*$Y)) B)"
  echo -------------------------------------------------------------------


  # insert data
  $RASQL -q "insert into $COLL values marray i in [0:$X,0:$Y] values 2c" > /dev/null

  # test
  test "tiff(c)"
  test "png(c)"
  test "jpeg(c)"
  test 'encode(c, "GTiff")'
  test 'encode(c, "PNG")'
done
