mirror of
https://github.com/vidarh/ruby-x11
synced 2024-12-26 09:59:02 +01:00
start adding tests
This commit is contained in:
parent
e94a3450fa
commit
93a15e6afa
3 changed files with 61 additions and 12 deletions
6
Rakefile
6
Rakefile
|
@ -1 +1,7 @@
|
||||||
require "bundler/gem_tasks"
|
require "bundler/gem_tasks"
|
||||||
|
require "rake/testtask"
|
||||||
|
|
||||||
|
Rake::TestTask.new do |t|
|
||||||
|
t.test_files = FileList['test/*_test.rb']
|
||||||
|
t.verbose = true
|
||||||
|
end
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'bundler'
|
require 'bundler'
|
||||||
begin
|
Bundler.setup(:default, :development)
|
||||||
Bundler.setup(:default, :development)
|
|
||||||
rescue Bundler::BundlerError => e
|
require 'minitest/spec'
|
||||||
$stderr.puts e.message
|
require 'minitest/autorun'
|
||||||
$stderr.puts "Run `bundle install` to install missing gems"
|
|
||||||
exit e.status_code
|
|
||||||
end
|
|
||||||
require 'test/unit'
|
|
||||||
require 'shoulda'
|
|
||||||
|
|
||||||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||||
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
||||||
require 'X11'
|
|
||||||
|
|
||||||
class Test::Unit::TestCase
|
require 'X11'
|
||||||
end
|
|
||||||
|
|
50
test/packet_test.rb
Normal file
50
test/packet_test.rb
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
require File.expand_path('../helper', __FILE__)
|
||||||
|
|
||||||
|
class MockSocket
|
||||||
|
def initialize(packet)
|
||||||
|
@packet = packet
|
||||||
|
end
|
||||||
|
|
||||||
|
def read(amount)
|
||||||
|
@packet.slice!(0..amount-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Child < X11::Packet::BasePacket
|
||||||
|
field :name, Uint16, :length
|
||||||
|
field :name, String8, :string
|
||||||
|
end
|
||||||
|
|
||||||
|
class Parent < X11::Packet::BasePacket
|
||||||
|
field :a, Uint8
|
||||||
|
field :b, Uint16
|
||||||
|
field :c, Uint32
|
||||||
|
|
||||||
|
field :d, Uint16, :length
|
||||||
|
field :d, String8, :string
|
||||||
|
|
||||||
|
field :children, Uint16, :length
|
||||||
|
field :children, Child, :list
|
||||||
|
end
|
||||||
|
|
||||||
|
describe X11::Packet::BasePacket do
|
||||||
|
it "should create and read a packet" do
|
||||||
|
children = []
|
||||||
|
children << Child.create("#1")
|
||||||
|
children << Child.create("#2")
|
||||||
|
children << Child.create("#3")
|
||||||
|
|
||||||
|
packet = Parent.create(1,2,3,"Hello World", children)
|
||||||
|
socket = MockSocket.new(packet)
|
||||||
|
reader = Parent.read(socket)
|
||||||
|
|
||||||
|
reader.a.must_equal 1
|
||||||
|
reader.b.must_equal 2
|
||||||
|
reader.c.must_equal 3
|
||||||
|
reader.d.must_equal "Hello World"
|
||||||
|
|
||||||
|
reader.children.shift.name.must_equal("#1")
|
||||||
|
reader.children.shift.name.must_equal("#2")
|
||||||
|
reader.children.shift.name.must_equal("#3")
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue