aboutsummaryrefslogtreecommitdiff
path: root/lib/objnames-test10.sh
blob: 62184b8640a3dc3b8b0e8de7a19f76636493208e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/sh
# ***************************************************************************
# *                                  _   _ ____  _
# *  Project                     ___| | | |  _ \| |
# *                             / __| | | | |_) | |
# *                            | (__| |_| |  _ <| |___
# *                             \___|\___/|_| \_\_____|
# *
# * Copyright (C) 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
# *
# * This software is licensed as described in the file COPYING, which
# * you should have received as part of this distribution. The terms
# * are also available at https://curl.haxx.se/docs/copyright.html.
# *
# * You may opt to use, copy, modify, merge, publish, distribute and/or sell
# * copies of the Software, and permit persons to whom the Software is
# * furnished to do so, under the terms of the COPYING file.
# *
# * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# * KIND, either express or implied.
# *
# ***************************************************************************

#
# This Bourne shell script file is used by test case 1221 to do
# unit testing of curl_10char_object_name() shell function which
# is defined in file objnames.inc and sourced by this file and
# any other shell script that may use it.
#

#
# argument validation
#

if test $# -eq 1; then
  :
else
  echo "Usage: ${0} srcdir"
  exit 1
fi

if test -f "${1}/runtests.pl"; then
  :
else
  echo "${0}: Wrong srcdir"
  exit 1
fi

srcdir=${1}

if test -f "$srcdir/../lib/objnames.inc"; then
  :
else
  echo "$0: Missing objnames.inc"
  exit 1
fi

#
# Some variables
#

logdir=log
tstnum=1221

list_c=$logdir/${tstnum}_list_c
list_obj=$logdir/${tstnum}_list_obj
list_obj_c=$logdir/${tstnum}_list_obj_c
list_obj_uniq=$logdir/${tstnum}_list_obj_uniq


#
# Source curl_10char_object_name() function definition
#

. $srcdir/../lib/objnames.inc

#
# Some curl_10char_object_name() unit tests
#

echo 'Testing curl_10char_object_name...'
echo ""

argstr=123__678__ABC__FGH__KLM__PQRSTUV
expect=16AFKPQRST
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=123__678__ABC__FGH__KLM__PQ.S.UV
expect=16AFKPQ
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=123__678__ABC..FGH..KLM..PQRSTUV
expect=16ABC
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=123__678_.ABC._FGH__KLM__PQRSTUV
expect=16
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=123.567.90ABCDEFGHIJKLMNOPQRSTUV
expect=123
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=1234567.90A.CDEFGHIJKLMNOPQRSTUV
expect=1234567
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=1234567890.BCD.FGHIJKLMNOPQRSTUV
expect=1234567890
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=12=45-78+0AB.DE.GHIJKLMNOPQRSTUV
expect=1470AB
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=1234567890ABCDEFGHIJKLMNOPQRSTUV
expect=1234567890
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=123_567_90A_CDE_GHIJKLMNOPQRSTUV
expect=159CGHIJKL
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=123_567_90A_CDEFGHIJKLMNOPQRSTUV
expect=159CDEFGHI
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=123_567_90ABCDEFGHIJKLMNOPQRSTUV
expect=1590ABCDEF
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=123_567890ABCDEFGHIJKLMNOPQRSTUV
expect=1567890ABC
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

argstr=1234567890ABCDEFGHIJKLMNOPQRSTUV
expect=1234567890
outstr=`curl_10char_object_name $argstr`
echo "result: $outstr expected: $expect input: $argstr"

#
# Verify that generated object name is distinct for
# all *.c source files in lib and src subdirectories.
#

ls $srcdir/../lib/*.c > $list_c
ls $srcdir/../src/*.c >> $list_c

rm -f $list_obj

for c_fname in `cat $list_c`; do
  obj_name=`curl_10char_object_name $c_fname`
  echo "$obj_name" >> $list_obj
done

sort -u $list_obj > $list_obj_uniq

cnt_c=`cat $list_c | wc -l`
cnt_u=`cat $list_obj_uniq | wc -l`

echo ""
echo ""
echo ""
if test $cnt_c -eq $cnt_u; then
  echo "10-characters-or-less generated object names are unique."
  obj_name_clash="no"
else
  echo "10-characters-or-less generated object names are clashing..."
  obj_name_clash="yes"
fi

if test $obj_name_clash = "yes"; then
  #
  # Show clashing object names and respective source file names
  #
  echo ""
  paste $list_obj $list_c | sort > $list_obj_c
  prev_match="no"
  prev_line="unknown"
  prev_obj_name="unknown"
  while read this_line; do
    obj_name=`echo "$this_line" | cut -f1`
    if test "x$obj_name" = "x$prev_obj_name"; then
      if test "x$prev_match" != "xyes"; then
        echo "$prev_line"
        echo "$this_line"
        prev_match="yes"
      else
        echo "$this_line"
      fi
    else
      prev_match="no"
    fi
    prev_line=$this_line
    prev_obj_name=$obj_name
  done < $list_obj_c
fi

rm -f $list_c
rm -f $list_obj
rm -f $list_obj_c
rm -f $list_obj_uniq

# end of objnames-test10.sh