[or-cvs] r10890: started to reorganise test cases (topf/trunk/lib)

benedikt at seul.org benedikt at seul.org
Fri Jul 20 09:47:16 UTC 2007


Author: benedikt
Date: 2007-07-20 05:47:15 -0400 (Fri, 20 Jul 2007)
New Revision: 10890

Added:
   topf/trunk/lib/fuzz-test.rb
Modified:
   topf/trunk/lib/fuzz.rb
Log:
started to reorganise test cases

Added: topf/trunk/lib/fuzz-test.rb
===================================================================
--- topf/trunk/lib/fuzz-test.rb	                        (rev 0)
+++ topf/trunk/lib/fuzz-test.rb	2007-07-20 09:47:15 UTC (rev 10890)
@@ -0,0 +1,17 @@
+# This file includes a default test-case object
+#
+# test template
+# default_tests.register Fuzz::Test.new("") {|arg|    }
+
+default_tests = Tests.new
+# Tests for character fields aka strings
+default_tests.register Fuzz::Test.new("char") {|arg, size|  arg     } # Return string
+default_tests.register Fuzz::Test.new("char") {|arg, size|  ""      } # Return empty String 
+default_tests.register Fuzz::Test.new("char") {|arg, size|  "A"*Fuzz::MAX_RAND    } # LONG STRING
+default_tests.register Fuzz::Test.new("char") {|arg, size|  "%n"*Fuzz::MAX_RAND   } # FORMAT STRING
+
+# Tests for signed numbers
+default_tests.register Fuzz::Test.new("signed") {|arg, size|  rand(5) } # return a small number 
+default_tests.register Fuzz::Test.new("signed") {|arg, size|  -1      } # return -1 
+default_tests.register Fuzz::Test.new("signed") {|arg, size|  (2.power!(size)/2)-1      } # biggest  2s complement number 
+default_tests.register Fuzz::Test.new("signed") {|arg, size|  -(2.power!(size)/2)       } # smallest 2s complement number 

Modified: topf/trunk/lib/fuzz.rb
===================================================================
--- topf/trunk/lib/fuzz.rb	2007-07-20 03:30:38 UTC (rev 10889)
+++ topf/trunk/lib/fuzz.rb	2007-07-20 09:47:15 UTC (rev 10890)
@@ -2,6 +2,59 @@
     MAX_RAND = 1000
     MAX_STRING_PERMUTATIONS = 3 
 
+    # This Class holds all tests to related to a given field-type
+    class Tests
+        def initialize
+            @char_tests      = []
+            @unsigned_tests  = []
+            @signed_tests    = []
+            @octet_tests     = []
+        end
+        def register(test)
+            raise "argument must be a Fuzz::Test object" if !test.is_a?(Fuzz::Test)
+            case test.type
+                when "char"
+                    @char_tests.push test
+                when "unsigned"
+                    @unsigned_tests.push test
+                when "signed"
+                    @signed_tests.push test
+                when "octet"
+                    @octet_tests.push test
+            end
+        end
+        def test_struct(struct)
+            raise "argument must be a BitStruct object" if !struct.is_a?(BitStruct)
+             
+        end
+    end
+
+    # This Class holds our test which is a ruby-block that must be able to process one argument
+    # which is the default value of the Field to be tested. This argument can be ignored if wanted.
+    class Test
+        attr_reader :type
+        def initialize(type, &block)
+            case type.downcase
+                when "char"
+                    @type = "char"
+                when "unsigned"
+                    @type = "unsigned"
+                when "signed"
+                    @type = "signed"
+                when "octet"
+                    @type = "octet"
+                else
+                    raise "unknown type"
+                end
+            @test = block
+        end
+        def run(arg)
+                @test.call arg
+        end
+    end
+    # sample test-case
+    # Fuzz::Test.new("char") {|arg| arg.insert( rand(arg.size), "A"*rand(1024) ) } 
+
     def Fuzz.fuzzField(type, length, value)
         case type.to_s
             when "BitStruct::CharField"
@@ -94,6 +147,8 @@
         end
     end
 
+    # makes a Connection to a given target and sends our raw data to it
+    # see yourself what options are needed :>
     class Host
         def initialize(args)
             @type = args[:type]



More information about the tor-commits mailing list