File: masking_spec.rb

package info (click to toggle)
ruby-em-websocket 0.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 416 kB
  • sloc: ruby: 3,137; makefile: 5
file content (29 lines) | stat: -rw-r--r-- 862 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# encoding: BINARY

require 'helper'

describe EM::WebSocket::MaskedString do
  it "should allow reading 4 byte mask and unmasking byte / bytes" do
    t = EM::WebSocket::MaskedString.new("\x00\x00\x00\x01\x00\x01\x00\x01")
    t.read_mask
    t.getbyte(3).should == 0x00
    t.getbytes(4, 4).should == "\x00\x01\x00\x00"
    t.getbytes(5, 3).should ==     "\x01\x00\x00"
  end

  it "should return nil from getbyte if index requested is out of range" do
    t = EM::WebSocket::MaskedString.new("\x00\x00\x00\x00\x53")
    t.read_mask
    t.getbyte(4).should == 0x53
    t.getbyte(5).should == nil
  end
  
  it "should allow switching masking on and off" do
    t = EM::WebSocket::MaskedString.new("\x02\x00\x00\x00\x03")
    t.getbyte(4).should == 0x03
    t.read_mask
    t.getbyte(4).should == 0x01
    t.unset_mask
    t.getbyte(4).should == 0x03
  end
end