12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/usr/bin/env ruby
- require 'optparse'
- require 'json'
- require File.join(File.dirname(__FILE__), '../Spec/vectors', 'vectorparser')
- @test_files = ["kdf_short"]
- @options = {}
- # Returns the text for a JS hash from a hash
- def NSDictionaryForHash(hash)
- "@{\n" + hash.collect { |key, value| %Q( @"#{key}": @"#{value}") }.join(",\n") + "}"
- end
- # Output the file header to output stream
- def outputHeader(output)
- output << <<-HEADER
- // Automatically Generated by GenVectorTests
- HEADER
- end
- # Output the tests for a given filename to the output stream
- def outputTestsForFile(output, name)
- VectorParser.new(@options[:v3_directory] + "/" + name).vectors.each do |vector|
- output << <<-TEST_CASE
- test("#{vector["title"]}", function() {
- verify_#{name}(#{JSON.dump vector});
- });
- TEST_CASE
- end
- end
- # Output the footer to the output stream
- def outputFooter(output)
- output<< <<-FOOTER
- FOOTER
- end
- ###################
- ### MAIN
- ###################
- opt_parser = OptionParser.new do |opt|
- opt.banner = "Usage: GenVectorTest -o VectorTests.m -3 v3_directory"
- opt.separator ""
- opt.on("-o","--output PATH","path to output code") do |output_path|
- @options[:output_path] = output_path
- end
- opt.on("-3", "-3 PATH", "path to v3 directory") do |v3_directory|
- @options[:v3_directory] = v3_directory
- end
- end
- opt_parser.parse!
- raise OptionParser::MissingArgument if @options[:output_path].nil?
- raise OptionParser::MissingArgument if @options[:v3_directory].nil?
- File.open(@options[:output_path], "w") do |output|
- outputHeader(output)
- @test_files.each do |file|
- outputTestsForFile(output, file)
- end
- outputFooter(output)
- end
|