od.tests 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #!/bin/sh
  2. # Copyright 2008 by Denys Vlasenko
  3. # Licensed under GPLv2, see file LICENSE in this source tree.
  4. . ./testing.sh
  5. # testing "test name" "commands" "expected result" "file input" "stdin"
  6. input="$(printf '\001\002\003\nABC\xfe')"
  7. little_endian=false
  8. { printf '\0\1' | od -s | grep -q 256; } && little_endian=true
  9. readonly little_endian
  10. $little_endian || SKIP=1
  11. testing "od (little-endian)" \
  12. "od" \
  13. "\
  14. 0000000 001001 005003 041101 177103
  15. 0000010
  16. " \
  17. "" "$input"
  18. SKIP=
  19. optional !DESKTOP
  20. testing "od -a (!DESKTOP)" \
  21. "od -a" \
  22. "\
  23. 0000000 nul soh stx etx eot enq ack bel bs ht lf vt ff cr so si
  24. 0000020 dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us
  25. 0000040 p q r s t u v w x y z { | } ~ del
  26. 0000060 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f
  27. 0000100 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff
  28. 0000120
  29. " \
  30. "" \
  31. "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\
  32. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"\
  33. "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"\
  34. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\
  35. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
  36. SKIP=
  37. # ^^^ a bit incorrect handling of ctrl ("lf" should be "nl") and high bytes.
  38. # vvv this output is correct.
  39. optional DESKTOP
  40. testing "od -a (DESKTOP)" \
  41. "od -a" \
  42. "\
  43. 0000000 nul soh stx etx eot enq ack bel bs ht nl vt ff cr so si
  44. 0000020 dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us
  45. 0000040 p q r s t u v w x y z { | } ~ del
  46. 0000060 nul soh stx etx eot enq ack bel bs ht nl vt ff cr so si
  47. 0000100 p q r s t u v w x y z { | } ~ del
  48. 0000120
  49. " \
  50. "" \
  51. "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"\
  52. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"\
  53. "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"\
  54. "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"\
  55. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
  56. SKIP=
  57. testing "od -B" \
  58. "od -B" \
  59. "\
  60. 0000000 001001 005003 041101 177103
  61. 0000010
  62. " \
  63. "" "$input"
  64. SKIP=
  65. $little_endian || SKIP=1
  66. testing "od -o (little-endian)" \
  67. "od -o" \
  68. "\
  69. 0000000 001001 005003 041101 177103
  70. 0000010
  71. " \
  72. "" "$input"
  73. SKIP=
  74. testing "od -b" \
  75. "od -b" \
  76. "\
  77. 0000000 001 002 003 012 101 102 103 376
  78. 0000010
  79. " \
  80. "" "$input"
  81. SKIP=
  82. testing "od -c" \
  83. "od -c" \
  84. "\
  85. 0000000 001 002 003 \\\\n A B C 376
  86. 0000010
  87. " \
  88. "" "$input"
  89. SKIP=
  90. $little_endian || SKIP=1
  91. testing "od -d (little-endian)" \
  92. "od -d" \
  93. "\
  94. 0000000 513 2563 16961 65091
  95. 0000010
  96. " \
  97. "" "$input"
  98. SKIP=
  99. $little_endian || SKIP=1
  100. testing "od -D (little-endian)" \
  101. "od -D" \
  102. "\
  103. 0000000 167969281 4265820737
  104. 0000010
  105. " \
  106. "" "$input"
  107. SKIP=
  108. optional !DESKTOP #DESKTOP: unrecognized option: e
  109. $little_endian || SKIP=1
  110. testing "od -e (!DESKTOP little-endian)" \
  111. "od -e" \
  112. "\
  113. 0000000 -1.61218556514036e+300
  114. 0000010
  115. " \
  116. "" "$input"
  117. SKIP=
  118. optional !DESKTOP #DESKTOP: unrecognized option: F
  119. $little_endian || SKIP=1
  120. testing "od -F (!DESKTOP little-endian)" \
  121. "od -F" \
  122. "\
  123. 0000000 -1.61218556514036e+300
  124. 0000010
  125. " \
  126. "" "$input"
  127. SKIP=
  128. $little_endian || SKIP=1
  129. testing "od -f (little-endian)" \
  130. "od -f" \
  131. "\
  132. 0000000 6.3077975e-33 -6.4885867e+37
  133. 0000010
  134. " \
  135. "" "$input"
  136. SKIP=
  137. $little_endian || SKIP=1
  138. testing "od -H (little-endian)" \
  139. "od -H" \
  140. "\
  141. 0000000 0a030201 fe434241
  142. 0000010
  143. " \
  144. "" "$input"
  145. SKIP=
  146. $little_endian || SKIP=1
  147. testing "od -X (little-endian)" \
  148. "od -X" \
  149. "\
  150. 0000000 0a030201 fe434241
  151. 0000010
  152. " \
  153. "" "$input"
  154. SKIP=
  155. $little_endian || SKIP=1
  156. testing "od -h (little-endian)" \
  157. "od -h" \
  158. "\
  159. 0000000 0201 0a03 4241 fe43
  160. 0000010
  161. " \
  162. "" "$input"
  163. SKIP=
  164. $little_endian || SKIP=1
  165. testing "od -x (little-endian)" \
  166. "od -x" \
  167. "\
  168. 0000000 0201 0a03 4241 fe43
  169. 0000010
  170. " \
  171. "" "$input"
  172. SKIP=
  173. $little_endian || SKIP=1
  174. testing "od -i (little-endian)" \
  175. "od -i" \
  176. "\
  177. 0000000 167969281 -29146559
  178. 0000010
  179. " \
  180. "" "$input"
  181. SKIP=
  182. $little_endian || SKIP=1
  183. testing "od -O (little-endian)" \
  184. "od -O" \
  185. "\
  186. 0000000 01200601001 37620641101
  187. 0000010
  188. " \
  189. "" "$input"
  190. SKIP=
  191. # 32-bit?
  192. printf '00000000' | od -l | grep -q '808464432 *808464432' && SKIP=1 #yes, skip
  193. $little_endian || SKIP=1
  194. testing "od -I (little-endian)" \
  195. "od -I" \
  196. "\
  197. 0000000 -125183517527965183
  198. 0000010
  199. " \
  200. "" "$input"
  201. testing "od -L (little-endian)" \
  202. "od -L" \
  203. "\
  204. 0000000 -125183517527965183
  205. 0000010
  206. " \
  207. "" "$input"
  208. testing "od -l (little-endian)" \
  209. "od -l" \
  210. "\
  211. 0000000 -125183517527965183
  212. 0000010
  213. " \
  214. "" "$input"
  215. SKIP=
  216. optional DESKTOP
  217. testing "od -b" \
  218. "od -b" \
  219. "\
  220. 0000000 110 105 114 114 117
  221. 0000005
  222. " \
  223. "" "HELLO"
  224. SKIP=
  225. optional DESKTOP
  226. testing "od -f" \
  227. "od -f" \
  228. "\
  229. 0000000 0.0000000e+00 0.0000000e+00
  230. 0000010
  231. " \
  232. "" "\x00\x00\x00\x00\x00\x00\x00\x00"
  233. SKIP=
  234. optional DESKTOP LONG_OPTS
  235. testing "od -b --traditional" \
  236. "od -b --traditional" \
  237. "\
  238. 0000000 110 105 114 114 117
  239. 0000005
  240. " \
  241. "" "HELLO"
  242. SKIP=
  243. optional DESKTOP LONG_OPTS
  244. testing "od -b --traditional FILE" \
  245. "od -b --traditional input" \
  246. "\
  247. 0000000 110 105 114 114 117
  248. 0000005
  249. " \
  250. "HELLO" ""
  251. SKIP=
  252. exit $FAILCOUNT