#!/bin/bash

# Copyright 2015 Neha Maggu <maggu.neha@gmail.com>

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"



#Valid size
testing "File size : 1024 bytes" "fallocate -l 1024 file; ls -l file | awk '{print \$5}'  " "1024\n" "" ""

#Allocating any Random size
testing "Random size" "fallocate -l 2321313 file; ls -l file | awk '{print \$5}'  " "2321313\n" "" ""

#To reduce already allocated size
testing "Reduce allocated Size" "fallocate -l 23 file; ls -l file | awk '{print \$5}'  " "2321313\n" "" ""

#Allocating zero size to above created file 
testing "Allocating zero size" "fallocate -l 0 file 2> error; cat error" "fallocate: Not enough space\n" "" ""

#To increase allocated size
testing "Increase allocated size" " ls -l file | awk '{print \$5}'; fallocate -l 2400000 file; ls -l file | awk '{print \$5}' " "2321313\n2400000\n" "" ""

#Missing argument
testing "Missing argument" "fallocate -l 1024 2> error; cat error" "fallocate: (null): Bad address\n" "" ""

#Large Size
testing "Large size" "fallocate -l 10241024102410241041024 file 2> error; cat error" "fallocate: 10241024102410241041024: Numerical result out of range\n" "" "" 	
rm -rf file

#Directory as argument
mkdir dir
testing "Allocating directory" "fallocate -l 1024 dir 2> error; cat error" "fallocate: dir: Is a directory\n" "" ""
rm -rf error dir
