openenvutils/commandshell/shell/test/scripts/greptest1.sh
changeset 0 2e3d3ce01487
child 1 0fdb7f6b0309
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of the License "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 #
       
    15 
       
    16 init()
       
    17 {
       
    18     let total=0;
       
    19     let pass=0;
       
    20     let fail=0;
       
    21 
       
    22     if [ ! -d c:\\greptest ]
       
    23     then
       
    24 		mkdir c:\\greptest	
       
    25     fi
       
    26 	cd c:\\greptest
       
    27 	cat "Hello.
       
    28 		hi his
       
    29 		hi
       
    30 		Testing for the grep command." > test1.txt
       
    31 	cat "fddsfsduf  dsofdsfsdf  dfds
       
    32 	          dfsd isdf ndsljfs d" > test2.txt
       
    33 	cat "fddsfsduf " > test3.txt
       
    34 	if [ ! -d .\\test4 ] 
       
    35 	then 
       
    36 		mkdir .\\test4
       
    37 	fi
       
    38 	cd .\\test4
       
    39 	cat "Hello.
       
    40 		hi his
       
    41 		hi
       
    42 		Testing for the grep command." > test41.txt
       
    43 	cat "fddsfsduf  dsofdsfsdf  dfds
       
    44 	          dfsd isdf ndsljfs d" > test42.txt
       
    45 	cat "fddsfsduf " > test43.txt
       
    46 	cd 
       
    47 	
       
    48 }
       
    49 report()
       
    50 {
       
    51     echo "Changing the directory back";
       
    52     echo "--------------------Grep test results------------------------"
       
    53     echo " TOTAL TESTS : $total"
       
    54     echo " TOTAL PASS  : $pass"
       
    55     echo " TOTAL FAIL  : $fail"
       
    56     echo "------------------------------------------------------------"
       
    57 }
       
    58 
       
    59 test_grep1()
       
    60 {
       
    61 	echo " test_grep1 : grep with no options; grep";
       
    62 	let total+=1;
       
    63 	grep
       
    64 	ret=$?
       
    65 	if [ $ret -ne 0 ]
       
    66 	then
       
    67 		echo "PASS";
       
    68 		let pass+=1;
       
    69 	else
       
    70 		echo "FAIL"
       
    71 		echo "Expected 1 Returned $ret"
       
    72 		let fail+=1;
       
    73 	fi
       
    74 }
       
    75 test_grep2()
       
    76 {
       
    77 	echo " test_grep2: grep with invalid options; grep -q";
       
    78 	let total+=1;
       
    79 	grep -q
       
    80 	ret=$?
       
    81 	if [ $ret -ne 0 ]
       
    82 	then
       
    83 		echo "PASS";
       
    84 		let pass+=1;
       
    85 	else
       
    86 		echo "FAIL"
       
    87 		echo "Expected 1 Returned $ret"
       
    88 		let fail+=1;
       
    89 	fi
       
    90 }
       
    91 test_grep3()
       
    92 {
       
    93 	echo " test_grep3 : grep with valid args; grep \"hi\" test1.txt ";
       
    94 	let total+=1;
       
    95 	grep "hi" c:\\greptest\\test1.txt
       
    96 	ret=$?
       
    97 	if [ $ret -eq 0 ]
       
    98 	then
       
    99 		echo "PASS";
       
   100 		let pass+=1;
       
   101 	else
       
   102 		echo "FAIL"
       
   103 		echo "Expected 1 Returned $ret"
       
   104 		let fail+=1;
       
   105 	fi
       
   106 }
       
   107 test_grep4()
       
   108 {
       
   109 	echo " test_grep4 : grep with valid args; grep -c \"hi\" test1.txt ";
       
   110 	let total+=1;
       
   111 	grep -c "hi" c:\\greptest\\test1.txt
       
   112 	ret=$?
       
   113 	if [ $ret -eq 0 ]
       
   114 	then
       
   115 		echo "PASS";
       
   116 		let pass+=1;
       
   117 	else
       
   118 		echo "FAIL"
       
   119 		echo "Expected 1 Returned $ret"
       
   120 		let fail+=1;
       
   121 	fi
       
   122 }
       
   123 test_grep5()
       
   124 {
       
   125 	echo " test_grep5 : grep with valid args; grep -A 2 \"hi\" test1.txt ";
       
   126 	let total+=1;
       
   127 	grep -A 2 "hi" c:\\greptest\\test1.txt
       
   128 	ret=$?
       
   129 	if [ $ret -eq 0 ]
       
   130 	then
       
   131 		echo "PASS";
       
   132 		let pass+=1;
       
   133 	else
       
   134 		echo "FAIL"
       
   135 		echo "Expected 1 Returned $ret"
       
   136 		let fail+=1;
       
   137 	fi
       
   138 }
       
   139 test_grep6()
       
   140 {
       
   141 	echo " test_grep6 : grep with valid args; grep -B 2 \"hi\" test1.txt ";
       
   142 	let total+=1;
       
   143 	grep -B 2 "hi" c:\\greptest\\test1.txt
       
   144 	ret=$?
       
   145 	if [ $ret -eq 0 ]
       
   146 	then
       
   147 		echo "PASS";
       
   148 		let pass+=1;
       
   149 	else
       
   150 		echo "FAIL"
       
   151 		echo "Expected 1 Returned $ret"
       
   152 		let fail+=1;
       
   153 	fi
       
   154 }
       
   155 test_grep7()
       
   156 {
       
   157 	echo " test_grep7 : grep with valid args; grep -C 2 \"hi\" test1.txt ";
       
   158 	let total+=1;
       
   159 	grep -C 2 "hi" c:\\greptest\\test1.txt
       
   160 	ret=$?
       
   161 	if [ $ret -eq 0 ]
       
   162 	then
       
   163 		echo "PASS";
       
   164 		let pass+=1;
       
   165 	else
       
   166 		echo "FAIL"
       
   167 		echo "Expected 1 Returned $ret"
       
   168 		let fail+=1;
       
   169 	fi
       
   170 }
       
   171 test_grep17()
       
   172 {
       
   173 	echo " test_grep17 : grep with valid args; grep -d recurse \"hi\"  ./test4 ";
       
   174 	let total+=1;
       
   175 	grep -d recurse "hi" c:\\greptest\\test4
       
   176 	ret=$?
       
   177 	if [ $ret -eq 0 ]
       
   178 	then
       
   179 		echo "PASS";
       
   180 		let pass+=1;
       
   181 	else
       
   182 		echo "FAIL"
       
   183 		echo "Expected 1 Returned $ret"
       
   184 		let fail+=1;
       
   185 	fi
       
   186 }
       
   187 test_grep8()
       
   188 {
       
   189 	echo " test_grep8 : grep with valid args; grep -E \"h*\" test1.txt ";
       
   190 	let total+=1;
       
   191 	grep -E "h*" c:\\greptest\\test1.txt
       
   192 	ret=$?
       
   193 	if [ $ret -eq 0 ]
       
   194 	then
       
   195 		echo "PASS";
       
   196 		let pass+=1;
       
   197 	else
       
   198 		echo "FAIL"
       
   199 		echo "Expected 1 Returned $ret"
       
   200 		let fail+=1;
       
   201 	fi
       
   202 }
       
   203 test_grep9()
       
   204 {
       
   205 	echo " test_grep9 : grep with valid args; grep -e \"hi\" -e  \"grep\" test1.txt ";
       
   206 	let total+=1;
       
   207 	grep -e "hi" -e "grep" c:\\greptest\\test1.txt
       
   208 	ret=$?
       
   209 	if [ $ret -eq 0 ]
       
   210 	then
       
   211 		echo "PASS";
       
   212 		let pass+=1;
       
   213 	else
       
   214 		echo "FAIL"
       
   215 		echo "Expected 1 Returned $ret"
       
   216 		let fail+=1;
       
   217 	fi
       
   218 }
       
   219 test_grep10()
       
   220 {
       
   221 	echo " test_grep10 : grep with valid args; grep -F \"hi\" test1.txt ";
       
   222 	let total+=1;
       
   223 	grep -F "hi" c:\\greptest\\test1.txt
       
   224 	ret=$?
       
   225 	if [ $ret -eq 0 ]
       
   226 	then
       
   227 		echo "PASS";
       
   228 		let pass+=1;
       
   229 	else
       
   230 		echo "FAIL"
       
   231 		echo "Expected 1 Returned $ret"
       
   232 		let fail+=1;
       
   233 	fi
       
   234 }
       
   235 test_grep11()
       
   236 {
       
   237 	echo " test_grep11 : grep with valid args; grep -d recurse -H \"hi\" ./test4 ";
       
   238 	let total+=1;
       
   239 	grep -d recurse -H "hi" c:\\greptest\\test4
       
   240 	ret=$?
       
   241 	if [ $ret -eq 0 ]
       
   242 	then
       
   243 		echo "PASS";
       
   244 		let pass+=1;
       
   245 	else
       
   246 		echo "FAIL"
       
   247 		echo "Expected 1 Returned $ret"
       
   248 		let fail+=1;
       
   249 	fi
       
   250 }
       
   251 test_grep12()
       
   252 {
       
   253 	echo " test_grep12 : grep with valid args; grep -d recurse -h \"hi\" ./test4 ";
       
   254 	let total+=1;
       
   255 	grep -d recurse -h "hi" c:\\greptest\\test4
       
   256 	ret=$?
       
   257 	if [ $ret -eq 0 ]
       
   258 	then
       
   259 		echo "PASS";
       
   260 		let pass+=1;
       
   261 	else
       
   262 		echo "FAIL"
       
   263 		echo "Expected 1 Returned $ret"
       
   264 		let fail+=1;
       
   265 	fi
       
   266 }
       
   267 test_grep13()
       
   268 {
       
   269 	echo " test_grep13 : grep with valid args; grep -i \"Hi\" test1.txt ";
       
   270 	let total+=1;
       
   271 	grep -i "Hi" c:\\greptest\\test1.txt
       
   272 	ret=$?
       
   273 	if [ $ret -eq 0 ]
       
   274 	then
       
   275 		echo "PASS";
       
   276 		let pass+=1;
       
   277 	else
       
   278 		echo "FAIL"
       
   279 		echo "Expected 1 Returned $ret"
       
   280 		let fail+=1;
       
   281 	fi
       
   282 }
       
   283 test_grep14()
       
   284 {
       
   285 	echo " test_grep14 : grep with valid args; grep -L \"hi\" test1.txt test2.txt ";
       
   286 	let total+=1;
       
   287 	grep -L "hi" c:\\greptest\\test1.txt c:\\greptest\\test2.txt
       
   288 	ret=$?
       
   289 	if [ $ret -eq 0 ]
       
   290 	then
       
   291 		echo "PASS";
       
   292 		let pass+=1;
       
   293 	else
       
   294 		echo "FAIL"
       
   295 		echo "Expected 1 Returned $ret"
       
   296 		let fail+=1;
       
   297 	fi
       
   298 }
       
   299 test_grep15()
       
   300 {
       
   301 	echo " test_grep15 : grep with valid args; grep -l \"hi\" test1.txt test2.txt ";
       
   302 	let total+=1;
       
   303 	grep -l "hi" c:\\greptest\\test1.txt c:\\greptest\\test2.txt
       
   304 	ret=$?
       
   305 	if [ $ret -eq 0 ]
       
   306 	then
       
   307 		echo "PASS";
       
   308 		let pass+=1;
       
   309 	else
       
   310 		echo "FAIL"
       
   311 		echo "Expected 1 Returned $ret"
       
   312 		let fail+=1;
       
   313 	fi
       
   314 }
       
   315 test_grep16()
       
   316 {
       
   317 	echo " test_grep16 : grep with valid args; grep -m 2 \"hi\" test1.txt ";
       
   318 	let total+=1;
       
   319 	grep -m 2 "hi" c:\\greptest\\test1.txt 
       
   320 	ret=$?
       
   321 	if [ $ret -eq 0 ]
       
   322 	then
       
   323 		echo "PASS";
       
   324 		let pass+=1;
       
   325 	else
       
   326 		echo "FAIL"
       
   327 		echo "Expected 1 Returned $ret"
       
   328 		let fail+=1;
       
   329 	fi
       
   330 }
       
   331 
       
   332 #begin making calls
       
   333 
       
   334 init
       
   335 test_grep1
       
   336 test_grep2
       
   337 test_grep3
       
   338 test_grep4
       
   339 test_grep5
       
   340 test_grep6
       
   341 test_grep7
       
   342 test_grep8
       
   343 test_grep9
       
   344 test_grep10
       
   345 test_grep11
       
   346 test_grep12
       
   347 test_grep13
       
   348 test_grep14
       
   349 test_grep15
       
   350 test_grep16
       
   351 test_grep17
       
   352 report