rbkb 0.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. data/History.txt +74 -0
  2. data/README.rdoc +149 -0
  3. data/Rakefile +47 -0
  4. data/bin/b64 +5 -0
  5. data/bin/bgrep +5 -0
  6. data/bin/blit +5 -0
  7. data/bin/c +5 -0
  8. data/bin/crc32 +5 -0
  9. data/bin/d64 +5 -0
  10. data/bin/dedump +5 -0
  11. data/bin/feed +5 -0
  12. data/bin/hexify +5 -0
  13. data/bin/len +5 -0
  14. data/bin/plugsrv +271 -0
  15. data/bin/rex +10 -0
  16. data/bin/rstrings +5 -0
  17. data/bin/slice +5 -0
  18. data/bin/telson +5 -0
  19. data/bin/unhexify +5 -0
  20. data/bin/urldec +5 -0
  21. data/bin/urlenc +5 -0
  22. data/bin/xor +5 -0
  23. data/cli_usage.rdoc +285 -0
  24. data/doctor-bag.jpg +0 -0
  25. data/lib/rbkb.rb +51 -0
  26. data/lib/rbkb/cli.rb +219 -0
  27. data/lib/rbkb/cli/b64.rb +35 -0
  28. data/lib/rbkb/cli/bgrep.rb +86 -0
  29. data/lib/rbkb/cli/blit.rb +89 -0
  30. data/lib/rbkb/cli/chars.rb +24 -0
  31. data/lib/rbkb/cli/crc32.rb +35 -0
  32. data/lib/rbkb/cli/d64.rb +28 -0
  33. data/lib/rbkb/cli/dedump.rb +52 -0
  34. data/lib/rbkb/cli/feed.rb +229 -0
  35. data/lib/rbkb/cli/hexify.rb +65 -0
  36. data/lib/rbkb/cli/len.rb +76 -0
  37. data/lib/rbkb/cli/rstrings.rb +108 -0
  38. data/lib/rbkb/cli/slice.rb +47 -0
  39. data/lib/rbkb/cli/telson.rb +87 -0
  40. data/lib/rbkb/cli/unhexify.rb +50 -0
  41. data/lib/rbkb/cli/urldec.rb +35 -0
  42. data/lib/rbkb/cli/urlenc.rb +35 -0
  43. data/lib/rbkb/cli/xor.rb +43 -0
  44. data/lib/rbkb/extends.rb +725 -0
  45. data/lib/rbkb/http.rb +21 -0
  46. data/lib/rbkb/http/base.rb +172 -0
  47. data/lib/rbkb/http/body.rb +214 -0
  48. data/lib/rbkb/http/common.rb +74 -0
  49. data/lib/rbkb/http/headers.rb +370 -0
  50. data/lib/rbkb/http/parameters.rb +104 -0
  51. data/lib/rbkb/http/request.rb +58 -0
  52. data/lib/rbkb/http/response.rb +86 -0
  53. data/lib/rbkb/plug.rb +9 -0
  54. data/lib/rbkb/plug/blit.rb +222 -0
  55. data/lib/rbkb/plug/cli.rb +83 -0
  56. data/lib/rbkb/plug/feed_import.rb +74 -0
  57. data/lib/rbkb/plug/peer.rb +67 -0
  58. data/lib/rbkb/plug/plug.rb +215 -0
  59. data/lib/rbkb/plug/proxy.rb +26 -0
  60. data/lib/rbkb/plug/unix_domain.rb +75 -0
  61. data/lib_usage.rdoc +176 -0
  62. data/rbkb.gemspec +38 -0
  63. data/spec/rbkb_spec.rb +7 -0
  64. data/spec/spec_helper.rb +16 -0
  65. data/tasks/ann.rake +80 -0
  66. data/tasks/bones.rake +20 -0
  67. data/tasks/gem.rake +201 -0
  68. data/tasks/git.rake +40 -0
  69. data/tasks/notes.rake +27 -0
  70. data/tasks/post_load.rake +34 -0
  71. data/tasks/rdoc.rake +51 -0
  72. data/tasks/rubyforge.rake +55 -0
  73. data/tasks/setup.rb +292 -0
  74. data/tasks/spec.rake +54 -0
  75. data/tasks/svn.rake +47 -0
  76. data/tasks/test.rake +40 -0
  77. data/test/test_cli_b64.rb +35 -0
  78. data/test/test_cli_bgrep.rb +137 -0
  79. data/test/test_cli_blit.rb +11 -0
  80. data/test/test_cli_chars.rb +21 -0
  81. data/test/test_cli_crc32.rb +108 -0
  82. data/test/test_cli_d64.rb +22 -0
  83. data/test/test_cli_dedump.rb +118 -0
  84. data/test/test_cli_feed.rb +11 -0
  85. data/test/test_cli_helper.rb +96 -0
  86. data/test/test_cli_hexify.rb +63 -0
  87. data/test/test_cli_len.rb +96 -0
  88. data/test/test_cli_rstrings.rb +15 -0
  89. data/test/test_cli_slice.rb +73 -0
  90. data/test/test_cli_telson.rb +11 -0
  91. data/test/test_cli_unhexify.rb +43 -0
  92. data/test/test_cli_urldec.rb +50 -0
  93. data/test/test_cli_urlenc.rb +44 -0
  94. data/test/test_cli_xor.rb +71 -0
  95. data/test/test_helper.rb +5 -0
  96. data/test/test_http.rb +27 -0
  97. data/test/test_http_helper.rb +60 -0
  98. data/test/test_http_request.rb +136 -0
  99. data/test/test_http_response.rb +222 -0
  100. data/test/test_rbkb.rb +19 -0
  101. metadata +238 -0
@@ -0,0 +1,22 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+ require 'rbkb/cli/d64'
3
+
4
+ class TestCliD64 < Test::Unit::TestCase
5
+ include CliTest
6
+
7
+ def setup
8
+ @cli_class = Rbkb::Cli::D64
9
+ super()
10
+ end
11
+
12
+ def test_basic_string_arg
13
+ assert_equal 0, run_with_args(%w(Zm9vYnk=))
14
+ assert_equal "fooby", @stdout_io.string
15
+ end
16
+
17
+ def test_stdin
18
+ @stdin_io.write "Zm9vYnk=" ; @stdin_io.rewind
19
+ assert_equal 0, run_with_args()
20
+ assert_equal "fooby", @stdout_io.string
21
+ end
22
+ end
@@ -0,0 +1,118 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+ require 'rbkb/cli/dedump'
3
+
4
+ class TestCliDedump < Test::Unit::TestCase
5
+ include CliTest
6
+
7
+ def setup
8
+ @cli_class = Rbkb::Cli::Dedump
9
+ super()
10
+ @tst_string = "this is a \x00\n\n\ntest\x01\x02\xff\x00"
11
+ @tst_dump = <<_EOF_
12
+ 00000000 74 68 69 73 20 69 73 20 61 20 00 0a 0a 0a 74 65 |this is a ....te|
13
+ 00000010 73 74 01 02 ff 00 |st....|
14
+ 00000016
15
+ _EOF_
16
+
17
+ @bigtst_string = "\000\001\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\e\034\035\036\037 !\"\#.$.%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377" * 3
18
+ @bigtst_dump = <<_EOF_
19
+ 00000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |................|
20
+ 00000010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f |................|
21
+ 00000020 20 21 22 23 2e 24 2e 25 26 27 28 29 2a 2b 2c 2d | !"#.$.%&'()*+,-|
22
+ 00000030 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d |./0123456789:;<=|
23
+ 00000040 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d |>?@ABCDEFGHIJKLM|
24
+ 00000050 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d |NOPQRSTUVWXYZ[\]|
25
+ 00000060 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d |^_`abcdefghijklm|
26
+ 00000070 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d |nopqrstuvwxyz{|}|
27
+ 00000080 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d |~...............|
28
+ 00000090 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d |................|
29
+ 000000a0 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad |................|
30
+ 000000b0 ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd |................|
31
+ 000000c0 be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd |................|
32
+ 000000d0 ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd |................|
33
+ 000000e0 de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed |................|
34
+ 000000f0 ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd |................|
35
+ 00000100 fe ff 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d |................|
36
+ 00000110 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d |................|
37
+ 00000120 1e 1f 20 21 22 23 2e 24 2e 25 26 27 28 29 2a 2b |.. !"#.$.%&'()*+|
38
+ 00000130 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b |,-./0123456789:;|
39
+ 00000140 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b |<=>?@ABCDEFGHIJK|
40
+ 00000150 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b |LMNOPQRSTUVWXYZ[|
41
+ 00000160 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b |\]^_`abcdefghijk|
42
+ 00000170 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b |lmnopqrstuvwxyz{|
43
+ 00000180 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b ||}~.............|
44
+ 00000190 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b |................|
45
+ 000001a0 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab |................|
46
+ 000001b0 ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb |................|
47
+ 000001c0 bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb |................|
48
+ 000001d0 cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db |................|
49
+ 000001e0 dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb |................|
50
+ 000001f0 ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb |................|
51
+ 00000200 fc fd fe ff 00 01 02 03 04 05 06 07 08 09 0a 0b |................|
52
+ 00000210 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b |................|
53
+ 00000220 1c 1d 1e 1f 20 21 22 23 2e 24 2e 25 26 27 28 29 |.... !"#.$.%&'()|
54
+ 00000230 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 |*+,-./0123456789|
55
+ 00000240 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 |:;<=>?@ABCDEFGHI|
56
+ 00000250 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 |JKLMNOPQRSTUVWXY|
57
+ 00000260 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 |Z[\]^_`abcdefghi|
58
+ 00000270 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 |jklmnopqrstuvwxy|
59
+ 00000280 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 |z{|}~...........|
60
+ 00000290 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 |................|
61
+ 000002a0 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 |................|
62
+ 000002b0 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 |................|
63
+ 000002c0 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 |................|
64
+ 000002d0 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 |................|
65
+ 000002e0 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 |................|
66
+ 000002f0 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 |................|
67
+ 00000300 fa fb fc fd fe ff |......|
68
+ 00000306
69
+ _EOF_
70
+
71
+ end # setup
72
+
73
+ def test_file_input_arg
74
+ with_testfile do |fname, tf|
75
+ tf.write @tst_dump; tf.close
76
+ assert_equal 0, go_with_args([fname])
77
+ assert_equal(@tst_string, @stdout_io.string)
78
+ end
79
+ end
80
+
81
+ def test_stdin
82
+ @stdin_io.write(@tst_dump) ; @stdin_io.rewind
83
+ assert_equal 0, go_with_args
84
+ assert_equal(@tst_string, @stdout_io.string)
85
+ end
86
+
87
+
88
+ def test_stdin_big
89
+ @stdin_io.write(@bigtst_dump) ; @stdin_io.rewind
90
+ assert_equal 0, go_with_args
91
+ assert_equal(@bigtst_string, @stdout_io.string)
92
+ end
93
+
94
+ def test_bad_len
95
+ len_dump = <<_EOF_
96
+ 00000000 68 65 6c 75 |helu|
97
+ 00000004 20 66 6f 6f | foo|
98
+ 00000008
99
+ _EOF_
100
+
101
+ @stdin_io.write(len_dump) ; @stdin_io.rewind
102
+ assert_equal 1, go_with_args(["-l", "2"])
103
+ assert_equal("helu foo", @stdout_io.string)
104
+ end
105
+
106
+ def test_bad_len
107
+ @stdin_io.write(@bigtst_dump) ; @stdin_io.rewind
108
+ assert_equal 1, go_with_args(["-l", "-4"])
109
+ assert_match(/length must be greater than zero/i, @stderr_io.string)
110
+ end
111
+
112
+ def test_bad_input
113
+ @stdin_io.write("bad monkey") ; @stdin_io.rewind
114
+ assert_equal 1, go_with_args([])
115
+ assert_match(/parse error/i, @stderr_io.string)
116
+ end
117
+
118
+ end
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+
3
+ class TestCliFeed < Test::Unit::TestCase
4
+ include CliTest
5
+
6
+ def setup
7
+ @cli_class = Rbkb::Cli::Feed
8
+ super()
9
+ end
10
+
11
+ end
@@ -0,0 +1,96 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+ require 'rbkb/cli.rb'
3
+
4
+ Rbkb.require_all_libs_relative_to(File.dirname(__FILE__) + "/../lib/rbkb/cli.rb")
5
+
6
+ Rbkb::Cli::TESTING = true unless defined? Rbkb::Cli::TESTING
7
+
8
+ module CliTest
9
+ def setup
10
+ @stdout_io = StringIO.new
11
+ @stderr_io = StringIO.new
12
+ @stdin_io = StringIO.new
13
+ @cli_obj = @cli_class.new(
14
+ :stdout => @stdout_io,
15
+ :stderr => @stderr_io,
16
+ :stdin => @stdin_io
17
+ )
18
+ end
19
+
20
+ ## several variations on running a cli command, shouldn't matter which
21
+ ## is used, but we want to test all of them out
22
+ def go_with_args(argv=[])
23
+ catch(:exit_err) { catch(:exit_zero) { @cli_obj.go(argv) } }
24
+ end
25
+
26
+ def go_set_args(argv=[])
27
+ @cli_obj.argv = argv
28
+ catch(:exit_err) { catch(:exit_zero) { @cli_obj.go } }
29
+ end
30
+
31
+ def run_with_args(argv=[])
32
+ param = {
33
+ :stdout => @stdout_io,
34
+ :stderr => @stderr_io,
35
+ :stdin => @stdin_io,
36
+ :argv => argv
37
+ }
38
+ catch(:exit_err){ catch(:exit_zero) { @cli_class.run(param) } }
39
+ end
40
+
41
+
42
+ def with_testfile
43
+ fname = ".cli_tst_#{rand(0xffffffffffffffff).to_s(16).rjust(16,'0')}.tmp"
44
+ f=File.open(fname,"w")
45
+ begin
46
+ yield(fname.dup, f)
47
+ ensure
48
+ f.close unless f.closed?
49
+ File.delete(fname)
50
+ end
51
+ end
52
+
53
+ ### These are all basic CLI tests which every derived class should be able
54
+ ### to pass.
55
+ ### They'll be imported into individual TestCli.... suites
56
+ ### along with the standard set up convenience methods above
57
+
58
+ # Every command should print usage when -h supplied
59
+ def test_usage
60
+ assert_equal 1, go_with_args(%w(-h))
61
+ assert_match(/^Usage: /, @stderr_io.string )
62
+ end
63
+
64
+ # Every command should exit cleanly when bad arguments are specified
65
+ def test_bad_argument
66
+ assert_equal 1, go_with_args(%w(--this_is_really_redonculouslywrong))
67
+ assert_match(/Error: bad arguments/, @stderr_io.string )
68
+ end
69
+
70
+ # Every command should display version information with -v
71
+ def test_version_arg
72
+ assert_equal 0, go_with_args(%w(-v))
73
+ assert_match(/Ruby BlackBag version #{Rbkb::VERSION}/, @stdout_io.string)
74
+ end
75
+
76
+ # Every command should exit cleanly with a numeric 0/non-zero exit code
77
+ # when called without arguments.
78
+ # (and nothing on STDIN for cases when it is expected)
79
+ def test_clean_exit_with_no_arguments
80
+ @stdin_io = StringIO.new
81
+ assert( Numeric === go_with_args() )
82
+ end
83
+
84
+ # Every cli object should support the go() method with obj.argv = [...]
85
+ def test_vers_go_set_variant
86
+ assert_equal 0, go_set_args(%w(-v))
87
+ assert_match(/Ruby BlackBag version #{Rbkb::VERSION}/, @stdout_io.string)
88
+ end
89
+
90
+ # Every cli class should support the 'run([...])' method
91
+ def test_vers_class_run_variant
92
+ assert_equal 0, run_with_args(%w(-v))
93
+ assert_match(/Ruby BlackBag version #{Rbkb::VERSION}/, @stdout_io.string)
94
+ end
95
+
96
+ end
@@ -0,0 +1,63 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+ require 'rbkb/cli/hexify'
3
+
4
+ class TestCliHexify < Test::Unit::TestCase
5
+ include CliTest
6
+
7
+ def setup
8
+ @cli_class = Rbkb::Cli::Hexify
9
+ super()
10
+ end
11
+
12
+ def test_string_arg
13
+ assert_equal 0, go_with_args(%w(foo))
14
+ assert_equal("666f6f\n", @stdout_io.string)
15
+ end
16
+
17
+ def test_length_argument
18
+ assert_equal 0, go_with_args(%w(-l 1 foo))
19
+ assert_equal("66\n6f\n6f\n", @stdout_io.string)
20
+ end
21
+
22
+ def test_bad_length_arguments
23
+ assert_equal 1, go_with_args(%w(-l 0 foo))
24
+ assert_match(/must be greater than zero/, @stderr_io.string)
25
+ assert_equal 1, go_with_args(%w(-l -1 foo))
26
+ assert_match(/must be greater than zero/, @stderr_io.string)
27
+ end
28
+
29
+ def test_string_arg_with_plus
30
+ assert_equal 0, go_with_args(%w(+ foo))
31
+ assert_equal("66 6f 6f\n", @stdout_io.string)
32
+ end
33
+
34
+ def test_string_arg_with_delim
35
+ assert_equal 0, go_with_args(%w(-d : foo))
36
+ assert_equal("66:6f:6f\n", @stdout_io.string)
37
+ end
38
+
39
+ def test_string_arg_with_prefix
40
+ assert_equal 0, go_with_args(%w(-p : foo))
41
+ assert_equal(":66:6f:6f\n", @stdout_io.string)
42
+ end
43
+
44
+ def test_string_arg_with_suffix
45
+ assert_equal 0, go_with_args(%w(-s : foo))
46
+ assert_equal("66:6f:6f:\n", @stdout_io.string)
47
+ end
48
+
49
+ def test_stdin
50
+ @stdin_io.write("foo") ; @stdin_io.rewind
51
+ assert_equal 0, go_with_args
52
+ assert_equal("666f6f\n", @stdout_io.string)
53
+ end
54
+
55
+ def test_file_input
56
+ with_testfile do |fname, tf|
57
+ tf.write "hex_test_foo"; tf.close
58
+ assert_equal 0, go_with_args(["-f", fname])
59
+ assert_equal("6865785f746573745f666f6f\n", @stdout_io.string)
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,96 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+ require 'rbkb/cli/len'
3
+
4
+ class TestCliLen < Test::Unit::TestCase
5
+ include CliTest
6
+
7
+ def setup
8
+ @cli_class = Rbkb::Cli::Len
9
+ super()
10
+
11
+ @tst_in = "helu world"
12
+ @bigtst_in = "A"*65536
13
+ end
14
+
15
+ def test_string_arg
16
+ assert_equal 0, go_with_args([@tst_in])
17
+ assert_equal("\x00\x00\x00\x0a" + @tst_in, @stdout_io.string)
18
+ end
19
+
20
+ def test_big_string_arg
21
+ assert_equal 0, go_with_args([@bigtst_in])
22
+ assert_equal("\x00\x01\x00\x00" + @bigtst_in, @stdout_io.string)
23
+ end
24
+
25
+ def test_stdin
26
+ @stdin_io.write(@tst_in) ; @stdin_io.rewind
27
+ assert_equal 0, go_with_args()
28
+ assert_equal("\x00\x00\x00\x0a" + @tst_in, @stdout_io.string)
29
+ end
30
+
31
+ def test_file_input_flag
32
+ with_testfile do |fname, tf|
33
+ tf.write @tst_in; tf.close
34
+ assert_equal 0, go_with_args(["-f", fname])
35
+ assert_equal("\x00\x00\x00\x0a" + @tst_in, @stdout_io.string)
36
+ end
37
+ end
38
+
39
+ def test_string_arg_swap
40
+ assert_equal 0, go_with_args(["-x", @tst_in])
41
+ assert_equal("\x0a\x00\x00\x00" + @tst_in, @stdout_io.string)
42
+ end
43
+
44
+
45
+ def test_big_string_arg_swap
46
+ assert_equal 0, go_with_args(["-x", @bigtst_in])
47
+ assert_equal("\x00\x00\x01\x00" + @bigtst_in, @stdout_io.string)
48
+ end
49
+
50
+ def test_big_string_arg_total
51
+ assert_equal 0, go_with_args(["-t", @bigtst_in])
52
+ assert_equal("\x00\x01\x00\x04" + @bigtst_in, @stdout_io.string)
53
+ end
54
+
55
+ def test_big_string_arg_static_len
56
+ assert_equal 0, go_with_args(["-l3", @bigtst_in])
57
+ assert_equal("\x00\x00\x00\x03" + @bigtst_in, @stdout_io.string)
58
+ end
59
+
60
+ def test_big_string_arg_static_len_negative
61
+ assert_equal 0, go_with_args(["-l", "-3", @bigtst_in])
62
+ assert_equal("\xff\xff\xff\xfd" + @bigtst_in, @stdout_io.string)
63
+ end
64
+
65
+ def test_big_string_arg_static_len_negative_short
66
+ assert_equal 0, go_with_args(["-l", "-3", "-s2", @bigtst_in])
67
+ assert_equal("\xff\xfd" + @bigtst_in, @stdout_io.string)
68
+ end
69
+
70
+ def test_big_string_arg_nudge
71
+ assert_equal 0, go_with_args(["-n5", @bigtst_in])
72
+ assert_equal("\x00\x01\x00\x05" + @bigtst_in, @stdout_io.string)
73
+ end
74
+
75
+ def test_big_string_arg_byte
76
+ assert_equal 0, go_with_args(["-s1", @tst_in])
77
+ assert_equal("\x0a" + @tst_in, @stdout_io.string)
78
+ end
79
+
80
+ def test_big_string_arg_byte_wrap
81
+ assert_equal 0, go_with_args(["-s1", @bigtst_in])
82
+ assert_equal("\x00" + @bigtst_in, @stdout_io.string)
83
+ end
84
+
85
+
86
+ def test_big_string_arg_short
87
+ assert_equal 0, go_with_args(["-s2", @tst_in])
88
+ assert_equal("\x00\x0a" + @tst_in, @stdout_io.string)
89
+ end
90
+
91
+ def test_big_string_arg_short_wrap
92
+ assert_equal 0, go_with_args(["-s2", @bigtst_in])
93
+ assert_equal("\x00\x00" + @bigtst_in, @stdout_io.string)
94
+ end
95
+
96
+ end
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+
3
+ # FIXME Finish test cases for rstrings cli
4
+
5
+ class TestCliRstrings < Test::Unit::TestCase
6
+ include CliTest
7
+
8
+ def setup
9
+ @cli_class = Rbkb::Cli::Rstrings
10
+ super()
11
+
12
+ @test_dat = "a\000bc\001def\002gehi\003jklmn\004string 1\005string 2\020\370\f string 3\314string4\221string 5\n\000string 6\r\n\000\000\000\000string 7\000\000w\000i\000d\000e\000s\000t\000r\000i\000n\000g\000\000\000last string\000"
13
+ end
14
+
15
+ end
@@ -0,0 +1,73 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+ require 'rbkb/cli/slice'
3
+
4
+ class TestCliSlice < Test::Unit::TestCase
5
+ include CliTest
6
+
7
+ def setup
8
+ @cli_class = Rbkb::Cli::Slice
9
+ super()
10
+ @rawdat = (0..255).map {|x| x.chr}.join
11
+ @stdin_io.write(@rawdat) ; @stdin_io.rewind
12
+ end
13
+
14
+ def test_stdin
15
+ assert_equal 0, go_with_args(%w{0})
16
+ assert_equal @rawdat, @stdout_io.string
17
+ end
18
+
19
+ def test_start_from_end_negative_size
20
+ assert_equal 0, go_with_args(%w(-- -10))
21
+ assert_equal(@rawdat[-10..-1], @stdout_io.string)
22
+ end
23
+
24
+ def test_file_input_opt
25
+ with_testfile do |fname, tf|
26
+ tf.write @rawdat; tf.close
27
+ assert_equal 0, go_with_args(["-f", fname, "0"])
28
+ assert_equal(@rawdat, @stdout_io.string)
29
+ end
30
+ end
31
+
32
+ def test_bad_start
33
+ assert_equal 1, go_with_args(%w{foo})
34
+ assert_match(/invalid start length/i, @stderr_io.string)
35
+ end
36
+
37
+ def test_start_from_end_zero
38
+ assert_equal 0, go_with_args(%w(-r 256))
39
+ assert_equal("", @stdout_io.string)
40
+ end
41
+
42
+ def test_start_from_end_one
43
+ assert_equal 0, go_with_args(%w(-r 255))
44
+ assert_equal("\xff", @stdout_io.string)
45
+ end
46
+
47
+ def test_start_from_overflow
48
+ assert_equal 0, go_with_args(%w(-r 2000))
49
+ assert_equal("", @stdout_io.string)
50
+ end
51
+
52
+ def test_range_start_end
53
+ assert_equal 0, go_with_args(%w(-r 10:20))
54
+ assert_equal(@rawdat[10..20], @stdout_io.string)
55
+ end
56
+
57
+ def test_range_start_and_end
58
+ assert_equal 0, go_with_args(%w(-r 10:20))
59
+ assert_equal(@rawdat[10..20], @stdout_io.string)
60
+ end
61
+
62
+ def test_range_start_and_end_with_negative_end
63
+ assert_equal 0, go_with_args(%w(-r 0:-20))
64
+ assert_equal(@rawdat[0..-20], @stdout_io.string)
65
+ end
66
+
67
+
68
+ def test_range_start_and_end_hex
69
+ assert_equal 0, go_with_args(%w(-x 0a:14))
70
+ assert_equal(@rawdat[10..20], @stdout_io.string)
71
+ end
72
+
73
+ end