objnames-test10.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. # This Bourne shell script file is used by test case 1221 to do
  25. # unit testing of curl_10char_object_name() shell function which
  26. # is defined in file objnames.inc and sourced by this file and
  27. # any other shell script that may use it.
  28. #
  29. #
  30. # argument validation
  31. #
  32. if test $# -eq 1; then
  33. :
  34. else
  35. echo "Usage: ${0} srcdir"
  36. exit 1
  37. fi
  38. if test -f "${1}/runtests.pl"; then
  39. :
  40. else
  41. echo "${0}: Wrong srcdir"
  42. exit 1
  43. fi
  44. srcdir=${1}
  45. if test -f "$srcdir/objnames.inc"; then
  46. :
  47. else
  48. echo "$0: Missing objnames.inc"
  49. exit 1
  50. fi
  51. #
  52. # Some variables
  53. #
  54. logdir=log
  55. tstnum=1221
  56. list_c=$logdir/${tstnum}_list_c
  57. list_obj=$logdir/${tstnum}_list_obj
  58. list_obj_c=$logdir/${tstnum}_list_obj_c
  59. list_obj_uniq=$logdir/${tstnum}_list_obj_uniq
  60. #
  61. # Source curl_10char_object_name() function definition
  62. #
  63. . $srcdir/objnames.inc
  64. #
  65. # Some curl_10char_object_name() unit tests
  66. #
  67. echo 'Testing curl_10char_object_name...'
  68. echo ""
  69. argstr=123__678__ABC__FGH__KLM__PQRSTUV
  70. expect=16AFKPQRST
  71. outstr=`curl_10char_object_name $argstr`
  72. echo "result: $outstr expected: $expect input: $argstr"
  73. argstr=123__678__ABC__FGH__KLM__PQ.S.UV
  74. expect=16AFKPQ
  75. outstr=`curl_10char_object_name $argstr`
  76. echo "result: $outstr expected: $expect input: $argstr"
  77. argstr=123__678__ABC..FGH..KLM..PQRSTUV
  78. expect=16ABC
  79. outstr=`curl_10char_object_name $argstr`
  80. echo "result: $outstr expected: $expect input: $argstr"
  81. argstr=123__678_.ABC._FGH__KLM__PQRSTUV
  82. expect=16
  83. outstr=`curl_10char_object_name $argstr`
  84. echo "result: $outstr expected: $expect input: $argstr"
  85. argstr=123.567.90ABCDEFGHIJKLMNOPQRSTUV
  86. expect=123
  87. outstr=`curl_10char_object_name $argstr`
  88. echo "result: $outstr expected: $expect input: $argstr"
  89. argstr=1234567.90A.CDEFGHIJKLMNOPQRSTUV
  90. expect=1234567
  91. outstr=`curl_10char_object_name $argstr`
  92. echo "result: $outstr expected: $expect input: $argstr"
  93. argstr=1234567890.BCD.FGHIJKLMNOPQRSTUV
  94. expect=1234567890
  95. outstr=`curl_10char_object_name $argstr`
  96. echo "result: $outstr expected: $expect input: $argstr"
  97. argstr=12=45-78+0AB.DE.GHIJKLMNOPQRSTUV
  98. expect=1470AB
  99. outstr=`curl_10char_object_name $argstr`
  100. echo "result: $outstr expected: $expect input: $argstr"
  101. argstr=1234567890ABCDEFGHIJKLMNOPQRSTUV
  102. expect=1234567890
  103. outstr=`curl_10char_object_name $argstr`
  104. echo "result: $outstr expected: $expect input: $argstr"
  105. argstr=123_567_90A_CDE_GHIJKLMNOPQRSTUV
  106. expect=159CGHIJKL
  107. outstr=`curl_10char_object_name $argstr`
  108. echo "result: $outstr expected: $expect input: $argstr"
  109. argstr=123_567_90A_CDEFGHIJKLMNOPQRSTUV
  110. expect=159CDEFGHI
  111. outstr=`curl_10char_object_name $argstr`
  112. echo "result: $outstr expected: $expect input: $argstr"
  113. argstr=123_567_90ABCDEFGHIJKLMNOPQRSTUV
  114. expect=1590ABCDEF
  115. outstr=`curl_10char_object_name $argstr`
  116. echo "result: $outstr expected: $expect input: $argstr"
  117. argstr=123_567890ABCDEFGHIJKLMNOPQRSTUV
  118. expect=1567890ABC
  119. outstr=`curl_10char_object_name $argstr`
  120. echo "result: $outstr expected: $expect input: $argstr"
  121. argstr=1234567890ABCDEFGHIJKLMNOPQRSTUV
  122. expect=1234567890
  123. outstr=`curl_10char_object_name $argstr`
  124. echo "result: $outstr expected: $expect input: $argstr"
  125. #
  126. # Verify that generated object name is distinct for
  127. # all *.c source files in lib and src subdirectories.
  128. #
  129. ls $srcdir/../lib/*.c > $list_c
  130. ls $srcdir/../src/*.c >> $list_c
  131. rm -f $list_obj
  132. for c_fname in `cat $list_c`; do
  133. obj_name=`curl_10char_object_name $c_fname`
  134. echo "$obj_name" >> $list_obj
  135. done
  136. sort -u $list_obj > $list_obj_uniq
  137. cnt_c=`cat $list_c | wc -l`
  138. cnt_u=`cat $list_obj_uniq | wc -l`
  139. echo ""
  140. echo ""
  141. echo ""
  142. if test $cnt_c -eq $cnt_u; then
  143. echo "10-characters-or-less generated object names are unique."
  144. obj_name_clash="no"
  145. else
  146. echo "10-characters-or-less generated object names are clashing..."
  147. obj_name_clash="yes"
  148. fi
  149. if test $obj_name_clash = "yes"; then
  150. #
  151. # Show clashing object names and respective source file names
  152. #
  153. echo ""
  154. paste $list_obj $list_c | sort > $list_obj_c
  155. prev_match="no"
  156. prev_line="unknown"
  157. prev_obj_name="unknown"
  158. while read this_line; do
  159. obj_name=`echo "$this_line" | cut -f1`
  160. if test "x$obj_name" = "x$prev_obj_name"; then
  161. if test "x$prev_match" != "xyes"; then
  162. echo "$prev_line"
  163. echo "$this_line"
  164. prev_match="yes"
  165. else
  166. echo "$this_line"
  167. fi
  168. else
  169. prev_match="no"
  170. fi
  171. prev_line=$this_line
  172. prev_obj_name=$obj_name
  173. done < $list_obj_c
  174. fi
  175. rm -f $list_c
  176. rm -f $list_obj
  177. rm -f $list_obj_c
  178. rm -f $list_obj_uniq
  179. # end of objnames-test10.sh