#!/bin/sh

. unittest_init

entry=0
MOUNTPOINTS_FILE=`mktemp ./fake_mtab.XXXXXXXXXX`

mtab_mount_array=('Photo\040bébé'
                  'P&h&o&t&o&\040b&é&b&é'
                  'P\134h\134o\134t\134o\134\040b\134é\134b\134é')

string_mount_array=('Photo bébé'
                    'P&h&o&t&o& b&é&b&é'
                    'P\h\o\t\o\ b\é\b\é')

build_fake_mtab()
{
  count=0
  while [ -n "${mtab_mount_array[${count}]}" ]; do
    echo "/dev/sda6 /fake_dir/${mtab_mount_array[${count}]} " \
         "ext3 rw,errors=continue,data=ordered 0 0" >> ${MOUNTPOINTS_FILE}
    count=$((${count} + 1))
  done
}

check_mountpoint_string()
{
  DEV=$1
  MP=$2
  FST=$3
  OPTS=$4

  if [ "${MP}" != "/fake_dir/${string_mount_array[${entry}]}" ]; then
    assert "\"${MP}\" should be \"/fake_dir/${string_mount_array[${entry}]}\""
  fi
  entry=$((${entry} + 1))
}

trap "rm -f ${MOUNTPOINTS_FILE}" 0

build_fake_mtab
for_each_mountpoint check_mountpoint_string

#
# The for_each_mountpoint function use pipes '|' to iterate along the
# mtab file. That's why an exit call in the assert function will not
# terminate this shell.
#
exit $?

