1#!/bin/sh 2# *************************************************************************** 3# * _ _ ____ _ 4# * Project ___| | | | _ \| | 5# * / __| | | | |_) | | 6# * | (__| |_| | _ <| |___ 7# * \___|\___/|_| \_\_____| 8# * 9# * Copyright (C) 2013 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. 10# * 11# * This software is licensed as described in the file COPYING, which 12# * you should have received as part of this distribution. The terms 13# * are also available at https://curl.haxx.se/docs/copyright.html. 14# * 15# * You may opt to use, copy, modify, merge, publish, distribute and/or sell 16# * copies of the Software, and permit persons to whom the Software is 17# * furnished to do so, under the terms of the COPYING file. 18# * 19# * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20# * KIND, either express or implied. 21# * 22# *************************************************************************** 23 24# 25# This Bourne shell script file is used by test case 1222 to do 26# unit testing of curl_8char_object_name() shell function which 27# is defined in file objnames.inc and sourced by this file and 28# any other shell script that may use it. 29# 30 31# 32# argument validation 33# 34 35if test $# -eq 1; then 36 : 37else 38 echo "Usage: ${0} srcdir" 39 exit 1 40fi 41 42if test -f "${1}/runtests.pl"; then 43 : 44else 45 echo "${0}: Wrong srcdir" 46 exit 1 47fi 48 49srcdir=${1} 50 51if test -f "$srcdir/objnames.inc"; then 52 : 53else 54 echo "$0: Missing objnames.inc" 55 exit 1 56fi 57 58# 59# Some variables 60# 61 62logdir=log 63tstnum=1222 64 65list_c=$logdir/${tstnum}_list_c 66list_obj=$logdir/${tstnum}_list_obj 67list_obj_c=$logdir/${tstnum}_list_obj_c 68list_obj_uniq=$logdir/${tstnum}_list_obj_uniq 69 70 71# 72# Source curl_8char_object_name() function definition 73# 74 75. $srcdir/objnames.inc 76 77# 78# Some curl_8char_object_name() unit tests 79# 80 81echo 'Testing curl_8char_object_name...' 82echo "" 83 84argstr=123__678__ABC__FGH__KLM__PQRSTUV 85expect=16AFKPQR 86outstr=`curl_8char_object_name $argstr` 87echo "result: $outstr expected: $expect input: $argstr" 88 89argstr=123__678__ABC__FGH__KLM__PQ.S.UV 90expect=16AFKPQ 91outstr=`curl_8char_object_name $argstr` 92echo "result: $outstr expected: $expect input: $argstr" 93 94argstr=123__678__ABC..FGH..KLM..PQRSTUV 95expect=16ABC 96outstr=`curl_8char_object_name $argstr` 97echo "result: $outstr expected: $expect input: $argstr" 98 99argstr=123__678_.ABC._FGH__KLM__PQRSTUV 100expect=16 101outstr=`curl_8char_object_name $argstr` 102echo "result: $outstr expected: $expect input: $argstr" 103 104argstr=123.567.90ABCDEFGHIJKLMNOPQRSTUV 105expect=123 106outstr=`curl_8char_object_name $argstr` 107echo "result: $outstr expected: $expect input: $argstr" 108 109argstr=1234567.90A.CDEFGHIJKLMNOPQRSTUV 110expect=1234567 111outstr=`curl_8char_object_name $argstr` 112echo "result: $outstr expected: $expect input: $argstr" 113 114argstr=1234567890.BCD.FGHIJKLMNOPQRSTUV 115expect=12345678 116outstr=`curl_8char_object_name $argstr` 117echo "result: $outstr expected: $expect input: $argstr" 118 119argstr=12=45-78+0AB.DE.GHIJKLMNOPQRSTUV 120expect=1470AB 121outstr=`curl_8char_object_name $argstr` 122echo "result: $outstr expected: $expect input: $argstr" 123 124argstr=1234567890ABCDEFGHIJKLMNOPQRSTUV 125expect=12345678 126outstr=`curl_8char_object_name $argstr` 127echo "result: $outstr expected: $expect input: $argstr" 128 129argstr=123_567_90A_CDE_GHIJKLMNOPQRSTUV 130expect=159CGHIJ 131outstr=`curl_8char_object_name $argstr` 132echo "result: $outstr expected: $expect input: $argstr" 133 134argstr=123_567_90A_CDEFGHIJKLMNOPQRSTUV 135expect=159CDEFG 136outstr=`curl_8char_object_name $argstr` 137echo "result: $outstr expected: $expect input: $argstr" 138 139argstr=123_567_90ABCDEFGHIJKLMNOPQRSTUV 140expect=1590ABCD 141outstr=`curl_8char_object_name $argstr` 142echo "result: $outstr expected: $expect input: $argstr" 143 144argstr=123_567890ABCDEFGHIJKLMNOPQRSTUV 145expect=1567890A 146outstr=`curl_8char_object_name $argstr` 147echo "result: $outstr expected: $expect input: $argstr" 148 149argstr=1234567890ABCDEFGHIJKLMNOPQRSTUV 150expect=12345678 151outstr=`curl_8char_object_name $argstr` 152echo "result: $outstr expected: $expect input: $argstr" 153 154# 155# Verify that generated object name is distinct for 156# all *.c source files in lib and src subdirectories. 157# 158 159ls $srcdir/../lib/*.c > $list_c 160ls $srcdir/../src/*.c >> $list_c 161 162rm -f $list_obj 163 164for c_fname in `cat $list_c`; do 165 obj_name=`curl_8char_object_name $c_fname` 166 echo "$obj_name" >> $list_obj 167done 168 169sort -u $list_obj > $list_obj_uniq 170 171cnt_c=`cat $list_c | wc -l` 172cnt_u=`cat $list_obj_uniq | wc -l` 173 174echo "" 175echo "" 176echo "" 177if test $cnt_c -eq $cnt_u; then 178 echo "8-characters-or-less generated object names are unique." 179 obj_name_clash="no" 180else 181 echo "8-characters-or-less generated object names are clashing..." 182 obj_name_clash="yes" 183fi 184 185if test $obj_name_clash = "yes"; then 186 # 187 # Show clashing object names and respective source file names 188 # 189 echo "" 190 paste $list_obj $list_c | sort > $list_obj_c 191 prev_match="no" 192 prev_line="unknown" 193 prev_obj_name="unknown" 194 while read this_line; do 195 obj_name=`echo "$this_line" | cut -f1` 196 if test "x$obj_name" = "x$prev_obj_name"; then 197 if test "x$prev_match" != "xyes"; then 198 echo "$prev_line" 199 echo "$this_line" 200 prev_match="yes" 201 else 202 echo "$this_line" 203 fi 204 else 205 prev_match="no" 206 fi 207 prev_line=$this_line 208 prev_obj_name=$obj_name 209 done < $list_obj_c 210fi 211 212rm -f $list_c 213rm -f $list_obj 214rm -f $list_obj_c 215rm -f $list_obj_uniq 216 217# end of objnames-test.sh 218