coap 0.0.16 → 0.1.0
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +13 -2
- data/Gemfile +0 -1
- data/LICENSE +2 -2
- data/README.md +37 -33
- data/Rakefile +12 -3
- data/bin/coap +111 -0
- data/coap.gemspec +34 -29
- data/lib/coap.rb +3 -34
- data/lib/core.rb +11 -0
- data/lib/core/coap.rb +42 -0
- data/lib/core/coap/block.rb +98 -0
- data/lib/core/coap/client.rb +314 -0
- data/lib/core/coap/coap.rb +26 -0
- data/lib/core/coap/coding.rb +146 -0
- data/lib/core/coap/fsm.rb +82 -0
- data/lib/core/coap/message.rb +203 -0
- data/lib/core/coap/observer.rb +40 -0
- data/lib/core/coap/options.rb +44 -0
- data/lib/core/coap/registry.rb +32 -0
- data/lib/core/coap/registry/content_formats.yml +7 -0
- data/lib/core/coap/resolver.rb +17 -0
- data/lib/core/coap/transmission.rb +165 -0
- data/lib/core/coap/types.rb +69 -0
- data/lib/core/coap/utility.rb +34 -0
- data/lib/core/coap/version.rb +5 -0
- data/lib/core/core_ext/socket.rb +19 -0
- data/lib/core/hexdump.rb +18 -0
- data/lib/core/link.rb +97 -0
- data/lib/core/os.rb +15 -0
- data/spec/block_spec.rb +160 -0
- data/spec/client_spec.rb +86 -0
- data/spec/fixtures/coap.me.link +1 -0
- data/spec/link_spec.rb +98 -0
- data/spec/registry_spec.rb +39 -0
- data/spec/resolver_spec.rb +19 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/transmission_spec.rb +70 -0
- data/test/helper.rb +15 -0
- data/test/test_client.rb +99 -228
- data/test/test_message.rb +99 -71
- metadata +140 -37
- data/bin/client +0 -42
- data/lib/coap/block.rb +0 -45
- data/lib/coap/client.rb +0 -364
- data/lib/coap/coap.rb +0 -273
- data/lib/coap/message.rb +0 -187
- data/lib/coap/mysocket.rb +0 -81
- data/lib/coap/observer.rb +0 -41
- data/lib/coap/version.rb +0 -3
- data/lib/misc/hexdump.rb +0 -17
- data/test/coap_test_helper.rb +0 -2
- data/test/disabled_econotag_blck.rb +0 -33
@@ -0,0 +1 @@
|
|
1
|
+
</test>;rt="test";ct=0,</validate>;rt="validate";ct=0,</hello>;rt="Type1";ct=0;if="If1",</bl%C3%A5b%C3%A6rsyltet%C3%B8y>;rt="blåbærsyltetøy";ct=0,</sink>;rt="sink";ct=0,</separate>;rt="separate";ct=0,</large>;rt="Type1 Type2";ct=0;sz=1700;if="If2",</secret>;rt="secret";ct=0,</broken>;rt="Type2 Type1";ct=0;if="If2 If1",</weird33>;rt="weird33";ct=0,</weird44>;rt="weird44";ct=0,</weird55>;rt="weird55";ct=0,</weird333>;rt="weird333";ct=0,</weird3333>;rt="weird3333";ct=0,</weird33333>;rt="weird33333";ct=0,</123412341234123412341234>;rt="123412341234123412341234";ct=0,</location-query>;rt="location-query";ct=0,</create1>;rt="create1";ct=0,</large-update>;rt="large-update";ct=0,</large-create>;rt="large-create";ct=0,</query>;rt="query";ct=0,</seg1>;rt="seg1";ct=40,</path>;rt="path";ct=40,</location1>;rt="location1";ct=40,</multi-format>;rt="multi-format";ct=0,</3>;rt="3";ct=50,</4>;rt="4";ct=50,</5>;rt="5";ct=50
|
data/spec/link_spec.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CoRE::Link do
|
4
|
+
describe '#initialize' do
|
5
|
+
context 'with valid parameters' do
|
6
|
+
context 'without attributes' do
|
7
|
+
subject { CoRE::Link.new('test') }
|
8
|
+
|
9
|
+
it 'should instantialize' do
|
10
|
+
expect { subject }.not_to raise_error
|
11
|
+
expect(subject.uri).to eq('test')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with attributes' do
|
16
|
+
subject { CoRE::Link.new('test', if: 'test') }
|
17
|
+
|
18
|
+
it 'should instantialize' do
|
19
|
+
expect { subject }.not_to raise_error
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with invalid parameters' do
|
25
|
+
subject { CoRE::Link.new('test', foo: 'bar') }
|
26
|
+
|
27
|
+
it 'should raise error' do
|
28
|
+
expect { subject }.to raise_error(ArgumentError)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'modification' do
|
34
|
+
subject { CoRE::Link.new('test') }
|
35
|
+
|
36
|
+
context 'with valid attributes' do
|
37
|
+
it 'should work' do
|
38
|
+
expect { subject.rel = 'hosts' }.not_to raise_error
|
39
|
+
expect(subject.rel).to eq('hosts')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with invalid attributes' do
|
44
|
+
it 'should fail' do
|
45
|
+
expect { subject.foo }.to raise_error(ArgumentError)
|
46
|
+
expect { subject.foo = 'bar' }.to raise_error(ArgumentError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#to_s' do
|
52
|
+
subject { CoRE::Link.new('test', if: 'test', rel: 'hosts') }
|
53
|
+
let(:text) { '<test>;if="test";rel="hosts"' }
|
54
|
+
|
55
|
+
it 'should equal example' do
|
56
|
+
expect(subject.to_s).to eq(text)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '.parse' do
|
61
|
+
let(:text) { '<test>;if="test";rel="hosts"' }
|
62
|
+
subject { CoRE::Link.parse(text) }
|
63
|
+
|
64
|
+
it 'should build object correctly' do
|
65
|
+
expect(subject.to_s).to eq(text)
|
66
|
+
expect(subject.if).to eq('test')
|
67
|
+
expect(subject.rel).to eq('hosts')
|
68
|
+
expect(subject.uri).to eq('test')
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with misformed input' do
|
72
|
+
let(:text) { '<test>;if=""test;' }
|
73
|
+
subject { CoRE::Link.parse(text) }
|
74
|
+
|
75
|
+
it 'should work' do
|
76
|
+
expect { subject }.not_to raise_error
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'of multiple links' do
|
81
|
+
let(:text) { '<test>;if="test",<test>;if="test"' }
|
82
|
+
subject { CoRE::Link.parse_multiple(text) }
|
83
|
+
|
84
|
+
it 'should work' do
|
85
|
+
expect(subject).to be_a(Array)
|
86
|
+
expect(subject.size).to eq(2)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'coap.me/.well-known/core' do
|
91
|
+
subject { CoRE::Link.parse(fixture('coap.me.link')) }
|
92
|
+
|
93
|
+
it 'should be parsed' do
|
94
|
+
expect { subject }.not_to raise_error
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Registry do
|
4
|
+
context '.load_yaml' do
|
5
|
+
it 'should have already loaded content formats YAML' do
|
6
|
+
[
|
7
|
+
Registry::CONTENT_FORMATS,
|
8
|
+
Registry::CONTENT_FORMATS_INVERTED
|
9
|
+
].each do |o|
|
10
|
+
expect(o).to be_a(Hash)
|
11
|
+
expect(o.empty?).to be(false)
|
12
|
+
expect(o.frozen?).to be(true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.convert_content_format' do
|
18
|
+
context 'Integer' do
|
19
|
+
it 'should convert' do
|
20
|
+
Registry::CONTENT_FORMATS.each do |k, v|
|
21
|
+
expect(Registry.convert_content_format(k)).to eq(v)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'String' do
|
27
|
+
it 'should convert' do
|
28
|
+
Registry::CONTENT_FORMATS.each do |k, v|
|
29
|
+
expect(Registry.convert_content_format(v)).to eq(k)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should convert without charset' do
|
34
|
+
expect(Registry.convert_content_format('text/plain')).to eq(0)
|
35
|
+
expect(Registry.convert_content_format('application/json; charset=utf-8')).to eq(50)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Resolver do
|
4
|
+
if ENV['IPv4'].nil?
|
5
|
+
context 'ipv6' do
|
6
|
+
subject { IPAddr.new(Resolver.address('orgizm.net')) }
|
7
|
+
|
8
|
+
it { expect { subject }.not_to raise_error }
|
9
|
+
it { expect(subject.ipv6?).to be(true) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'ipv4' do
|
14
|
+
subject { IPAddr.new(Resolver.address('ipv4.orgizm.net')) }
|
15
|
+
|
16
|
+
it { expect { subject }.not_to raise_error }
|
17
|
+
it { expect(subject.ipv4?).to be(true) }
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear_merged!
|
3
|
+
|
4
|
+
#$:.unshift File.expand_path('../lib', File.dirname(__FILE__))
|
5
|
+
require 'core'
|
6
|
+
|
7
|
+
require 'faker'
|
8
|
+
|
9
|
+
def fixture_path
|
10
|
+
File.join(File.dirname(__FILE__), 'fixtures')
|
11
|
+
end
|
12
|
+
|
13
|
+
def fixture(name)
|
14
|
+
File.read(File.join(fixture_path, name))
|
15
|
+
end
|
16
|
+
|
17
|
+
include CoRE::CoAP
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Transmission do
|
4
|
+
describe '#initialize' do
|
5
|
+
context 'without arguments' do
|
6
|
+
subject { Transmission.new }
|
7
|
+
|
8
|
+
it 'should set socket correctly' do
|
9
|
+
expect(subject.socket.class).to eq(Celluloid::IO::UDPSocket)
|
10
|
+
expect(subject.socket.class).not_to eq(::UDPSocket)
|
11
|
+
expect(subject.address_family).to eq(Socket::AF_INET6)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with ordinary UDPSocket' do
|
16
|
+
subject { Transmission.new(socket_class: ::UDPSocket) }
|
17
|
+
|
18
|
+
it 'should set socket correctly' do
|
19
|
+
expect(subject.socket.class).to eq(::UDPSocket)
|
20
|
+
expect(subject.socket.class).not_to eq(Celluloid::IO::UDPSocket)
|
21
|
+
expect(subject.address_family).to eq(Socket::AF_INET6)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#from_host' do
|
27
|
+
context 'ipv6' do
|
28
|
+
subject { Transmission.from_host('::1') }
|
29
|
+
|
30
|
+
it 'should set address family correctly' do
|
31
|
+
expect(subject.address_family).to eq(Socket::AF_INET6)
|
32
|
+
expect(subject.address_family).not_to eq(Socket::AF_INET)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'ipv4' do
|
37
|
+
subject { Transmission.from_host('127.0.0.1') }
|
38
|
+
|
39
|
+
it 'should set address family correctly' do
|
40
|
+
expect(subject.address_family).to eq(Socket::AF_INET)
|
41
|
+
expect(subject.address_family).not_to eq(Socket::AF_INET6)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '.send' do
|
47
|
+
context 'resolve' do
|
48
|
+
it 'no error for IP addresses' do
|
49
|
+
expect { Transmission.send('hello', '127.0.0.1') }.not_to raise_error
|
50
|
+
expect { Transmission.send('hello', '::1') }.not_to raise_error
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'error for invalid host' do
|
54
|
+
expect { Transmission.send('hello', '.') }.to raise_error(Resolv::ResolvError)
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'hostnames' do
|
58
|
+
it 'ipv4' do
|
59
|
+
expect(Transmission.from_host('ipv4.orgizm.net').ipv6?).to be(false)
|
60
|
+
end
|
61
|
+
|
62
|
+
if ENV['IPv4'].nil?
|
63
|
+
it 'ipv6' do
|
64
|
+
expect(Transmission.from_host('orgizm.net').ipv6?).to be(true)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear_merged!
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
$:.unshift File.expand_path('../lib', File.dirname(__FILE__))
|
8
|
+
require 'core'
|
9
|
+
|
10
|
+
d = ENV['DEBUG']
|
11
|
+
Log = Logger.new(d && IO.new(d.to_i))
|
12
|
+
|
13
|
+
Log.formatter = proc do |sev, time, prog, msg|
|
14
|
+
"#{time.strftime('%Y%m%d%H%M%S')}(#{sev.downcase}) #{msg}\n"
|
15
|
+
end
|
data/test/test_client.rb
CHANGED
@@ -1,311 +1,182 @@
|
|
1
|
-
#
|
2
|
-
require_relative 'coap_test_helper'
|
1
|
+
# encoding: utf-8
|
3
2
|
|
4
|
-
|
5
|
-
# TODO: rewrite tests with local coap server
|
6
|
-
# test
|
7
|
-
$observe_count = 0
|
8
|
-
PAYLOAD = Random.rand(999).to_s + 'TESTLorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nuncLorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nuncTEST'
|
3
|
+
require 'helper'
|
9
4
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
class TestMessage < Test::Unit::TestCase
|
14
|
-
def observe_tester(data, socket)
|
15
|
-
$observe_count += 1
|
16
|
-
end
|
5
|
+
# TODO Rewrite tests with local coap server!
|
17
6
|
|
7
|
+
class TestClient < Minitest::Test
|
18
8
|
def test_client_get_v4_v6_hostname
|
19
|
-
# client = CoAP::Client.new
|
20
|
-
# answer = client.get('2001:638:708:30da:219:d1ff:fea4:abc5'
|
21
|
-
# assert_equal(2,answer.mcode
|
22
|
-
# assert_equal(5,answer.mcode[1])
|
9
|
+
# client = CoRE::CoAP::Client.new
|
10
|
+
# answer = client.get('/hello', '2001:638:708:30da:219:d1ff:fea4:abc5')
|
11
|
+
# assert_equal([2, 5],answer.mcode)
|
23
12
|
# assert_equal('world',answer.payload)
|
24
13
|
|
25
|
-
client = CoAP::Client.new
|
26
|
-
answer = client.get('
|
27
|
-
assert_equal(2, answer.mcode
|
28
|
-
assert_equal(5, answer.mcode[1])
|
14
|
+
client = CoRE::CoAP::Client.new
|
15
|
+
answer = client.get('/hello', 'coap.me')
|
16
|
+
assert_equal([2, 5], answer.mcode)
|
29
17
|
assert_equal('world', answer.payload)
|
30
18
|
|
31
|
-
client = CoAP::Client.new
|
32
|
-
answer = client.get('134.102.218.16'
|
33
|
-
assert_equal(2, answer.mcode
|
34
|
-
assert_equal(5, answer.mcode[1])
|
19
|
+
client = CoRE::CoAP::Client.new
|
20
|
+
answer = client.get('/hello', '134.102.218.16')
|
21
|
+
assert_equal([2, 5], answer.mcode)
|
35
22
|
assert_equal('world', answer.payload)
|
36
23
|
end
|
37
24
|
|
38
25
|
def test_client_404
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
assert_equal(4, answer.mcode
|
43
|
-
assert_equal(4, answer.mcode[1])
|
26
|
+
client = CoRE::CoAP::Client.new
|
27
|
+
answer = client.get('/hello-this-does-not-exist', 'coap.me')
|
28
|
+
|
29
|
+
assert_equal([4, 4], answer.mcode)
|
44
30
|
assert_equal('Not found', answer.payload)
|
45
31
|
end
|
46
32
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
client = CoAP::Client.new
|
51
|
-
assert_raise RuntimeError do
|
52
|
-
answer = client.get('192.0.2.1', 5683, '/hello')
|
33
|
+
def test_invalid_hostname
|
34
|
+
assert_raises Resolv::ResolvError do
|
35
|
+
CoRE::CoAP::Client.new.get('/', 'unknown.tld')
|
53
36
|
end
|
54
|
-
|
55
|
-
x = Time.now
|
56
|
-
assert_raise RuntimeError do
|
57
|
-
answer = client.get('192.0.2.1', 5683, '/hello')
|
58
|
-
end
|
59
|
-
duration = Time.now - x
|
60
|
-
#assert_operator duration, :>, 0
|
61
|
-
#assert_operator duration, :<, 5
|
62
|
-
|
63
37
|
end
|
64
38
|
|
65
|
-
def
|
39
|
+
def test_recv_timeout
|
40
|
+
client = CoRE::CoAP::Client.new(max_retransmit: 0, recv_timeout: 0.1)
|
66
41
|
|
67
|
-
|
68
|
-
|
69
|
-
assert_raise Resolv::ResolvError do
|
70
|
-
client.get('coapunknown.mexyz', 5683, '/hello')
|
42
|
+
assert_raises RuntimeError do
|
43
|
+
client.get('/hello', '192.0.2.1')
|
71
44
|
end
|
72
|
-
|
73
45
|
end
|
74
46
|
|
75
|
-
def
|
76
|
-
|
77
|
-
client = CoAP::Client.new(256, 0, 30)
|
78
|
-
duration = 0
|
79
|
-
x = Time.now
|
80
|
-
assert_raise RuntimeError do
|
81
|
-
answer = client.get('bongo.xmorpheus.de', 1194, '/hello')
|
82
|
-
end
|
83
|
-
duration = Time.now - x
|
84
|
-
assert_operator duration, :>, 25
|
85
|
-
assert_operator duration, :<, 35
|
86
|
-
|
87
|
-
client = CoAP::Client.new(256, 1, 30)
|
88
|
-
duration = 0
|
89
|
-
x = Time.now
|
90
|
-
assert_raise RuntimeError do
|
91
|
-
answer = client.get('bongo.xmorpheus.de', 1194, '/hello')
|
92
|
-
end
|
93
|
-
duration = Time.now - x
|
94
|
-
assert_operator duration, :>, 55
|
95
|
-
assert_operator duration, :<, 110
|
47
|
+
def test_recv_timeout_retransmit
|
48
|
+
client = CoRE::CoAP::Client.new(max_retransmit: 1, recv_timeout: 1)
|
96
49
|
|
50
|
+
assert_raises RuntimeError do
|
51
|
+
client.get('/hello', 'eternium.orgizm.net', 1195)
|
52
|
+
end
|
97
53
|
end
|
98
54
|
|
99
55
|
def test_client_arguments
|
100
|
-
|
101
|
-
client = CoAP::Client.new
|
102
|
-
assert_raise Errno::ECONNREFUSED do
|
103
|
-
client.get('coap.me', 15_683, '/hello')
|
104
|
-
end
|
56
|
+
client = CoRE::CoAP::Client.new
|
105
57
|
|
106
|
-
#
|
107
|
-
|
108
|
-
|
109
|
-
answer = client.get('coap.me', 5683, '')
|
58
|
+
# Wrong port
|
59
|
+
assert_raises RuntimeError do
|
60
|
+
client.get('/hello', 'coap.me', 15_683)
|
110
61
|
end
|
111
62
|
|
112
|
-
#
|
113
|
-
|
114
|
-
|
115
|
-
answer = client.get('', 15_683, '/hello')
|
63
|
+
# Empty path
|
64
|
+
assert_raises ArgumentError do
|
65
|
+
answer = client.get('', 'coap.me')
|
116
66
|
end
|
117
67
|
|
118
|
-
#
|
119
|
-
|
120
|
-
|
121
|
-
answer = client.get('coap.me', nil, '/hello')
|
68
|
+
# Empty host
|
69
|
+
assert_raises ArgumentError do
|
70
|
+
answer = client.get('/', '')
|
122
71
|
end
|
123
72
|
|
124
|
-
#
|
125
|
-
|
126
|
-
|
127
|
-
answer = client.get('coap.me', 'i m a sring', '/hello')
|
73
|
+
# String port
|
74
|
+
assert_raises ArgumentError do
|
75
|
+
answer = client.get('/', '192.0.2.1', 'string')
|
128
76
|
end
|
129
77
|
|
130
|
-
#
|
131
|
-
|
132
|
-
|
133
|
-
assert_raise ArgumentError do
|
134
|
-
answer = client.post('coap.me', 5683, '/large-create', @suchEmpty)
|
78
|
+
# Empty payload
|
79
|
+
assert_raises ArgumentError do
|
80
|
+
answer = client.post('/large-create', 'coap.me', nil, '')
|
135
81
|
end
|
136
|
-
|
137
82
|
end
|
138
83
|
|
139
|
-
def
|
140
|
-
client = CoAP::Client.new
|
141
|
-
|
84
|
+
def test_client_get_by_uri
|
85
|
+
client = CoRE::CoAP::Client.new
|
86
|
+
|
87
|
+
answer = client.get_by_uri('coap://coap.me/hello')
|
88
|
+
assert_equal('world', answer.payload)
|
89
|
+
|
90
|
+
answer = client.get_by_uri('coap://coap.me:5683/hello')
|
142
91
|
assert_equal('world', answer.payload)
|
143
92
|
|
144
|
-
#
|
145
|
-
|
146
|
-
|
147
|
-
answer = client.get_by_url('coap:/#/coap.me:5683/hello')
|
93
|
+
# Broken URI
|
94
|
+
assert_raises ArgumentError do
|
95
|
+
answer = client.get_by_uri('coap:/#/coap.me/hello')
|
148
96
|
end
|
149
97
|
end
|
150
98
|
|
151
|
-
#
|
99
|
+
# TODO test payload
|
152
100
|
|
101
|
+
# Basic POST test
|
153
102
|
def test_client_post
|
154
|
-
client = CoAP::Client.new
|
155
|
-
answer = client.post('coap.me',
|
156
|
-
|
157
|
-
assert_equal(1, answer.mcode
|
103
|
+
client = CoRE::CoAP::Client.new
|
104
|
+
answer = client.post('/test', 'coap.me', nil, 'TD_COAP_CORE_04')
|
105
|
+
|
106
|
+
assert_equal([2, 1], answer.mcode)
|
158
107
|
assert_equal('POST OK', answer.payload)
|
159
108
|
end
|
160
109
|
|
161
|
-
|
110
|
+
# Basic PUT test
|
162
111
|
def test_client_put
|
163
|
-
client = CoAP::Client.new
|
164
|
-
answer = client.put('coap.me',
|
165
|
-
|
166
|
-
assert_equal(4, answer.mcode
|
112
|
+
client = CoRE::CoAP::Client.new
|
113
|
+
answer = client.put('/test', 'coap.me', nil, 'TD_COAP_CORE_03')
|
114
|
+
|
115
|
+
assert_equal([2, 4], answer.mcode)
|
167
116
|
assert_equal('PUT OK', answer.payload)
|
168
117
|
end
|
169
118
|
|
170
119
|
def test_client_delete
|
171
|
-
client = CoAP::Client.new
|
172
|
-
answer = client.delete('
|
173
|
-
|
174
|
-
assert_equal(2, answer.mcode
|
120
|
+
client = CoRE::CoAP::Client.new
|
121
|
+
answer = client.delete('/test', 'coap.me')
|
122
|
+
|
123
|
+
assert_equal([2, 2], answer.mcode)
|
175
124
|
assert_equal('DELETE OK', answer.payload)
|
176
125
|
end
|
177
126
|
|
178
127
|
def test_client_sönderzeichen
|
179
|
-
client = CoAP::Client.new
|
180
|
-
answer = client.
|
181
|
-
assert_equal(2, answer.mcode[0])
|
182
|
-
assert_equal(5, answer.mcode[1])
|
183
|
-
assert_equal('Übergrößenträger = 特大の人 = 超大航母', answer.payload.force_encoding('utf-8'))
|
184
|
-
end
|
128
|
+
client = CoRE::CoAP::Client.new
|
129
|
+
answer = client.get_by_uri('coap://coap.me/bl%C3%A5b%C3%A6rsyltet%C3%B8y')
|
185
130
|
|
186
|
-
|
187
|
-
client = CoAP::Client.new
|
188
|
-
answer = client.custom('coap://coap.me/bl%C3%A5b%C3%A6rsyltet%C3%B8y', 'get')
|
189
|
-
assert_equal(2, answer.mcode[0])
|
190
|
-
assert_equal(5, answer.mcode[1])
|
131
|
+
assert_equal([2, 5], answer.mcode)
|
191
132
|
assert_equal('Übergrößenträger = 特大の人 = 超大航母', answer.payload.force_encoding('utf-8'))
|
192
133
|
end
|
193
134
|
|
194
135
|
def test_multi_request_without_hostname_port
|
195
|
-
|
196
|
-
client =
|
197
|
-
client.hostname = 'coap.me'
|
136
|
+
client = CoRE::CoAP::Client.new
|
137
|
+
client.host = 'coap.me'
|
198
138
|
client.port = 5683
|
199
|
-
|
200
|
-
|
201
|
-
|
139
|
+
|
140
|
+
# Are host and port set?
|
141
|
+
answer = client.get('/hello')
|
142
|
+
assert_equal([2, 5], answer.mcode)
|
202
143
|
assert_equal('world', answer.payload)
|
203
144
|
|
204
|
-
|
205
|
-
|
206
|
-
assert_equal(5, answer.mcode
|
145
|
+
# Do they keep to be set after a request?
|
146
|
+
answer = client.get('/hello')
|
147
|
+
assert_equal([2, 5], answer.mcode)
|
207
148
|
assert_equal('world', answer.payload)
|
208
149
|
|
209
|
-
|
210
|
-
assert_equal(2, answer.mcode[0])
|
211
|
-
assert_equal(5, answer.mcode[1])
|
212
|
-
assert_equal('world', answer.payload)
|
150
|
+
client = CoRE::CoAP::Client.new
|
213
151
|
|
214
|
-
|
215
|
-
answer = client.get('
|
216
|
-
assert_equal(2, answer.mcode
|
217
|
-
assert_equal(5, answer.mcode[1])
|
152
|
+
# Ordinary request.
|
153
|
+
answer = client.get('/hello', 'coap.me')
|
154
|
+
assert_equal([2, 5], answer.mcode)
|
218
155
|
assert_equal('world', answer.payload)
|
219
156
|
|
220
|
-
|
221
|
-
|
222
|
-
assert_equal(5, answer.mcode
|
157
|
+
# Did previous request set host?
|
158
|
+
answer = client.get('/hello')
|
159
|
+
assert_equal([2, 5], answer.mcode)
|
223
160
|
assert_equal('world', answer.payload)
|
224
161
|
|
225
|
-
|
226
|
-
|
227
|
-
assert_equal(5, answer.mcode
|
228
|
-
assert_equal('world', answer.payload)
|
229
|
-
|
162
|
+
# Is it kept?
|
163
|
+
answer = client.get('/hello')
|
164
|
+
assert_equal([2, 5], answer.mcode)
|
165
|
+
assert_equal('world', answer.payload)
|
230
166
|
end
|
231
167
|
|
232
168
|
def test_initialize
|
233
|
-
client = CoAP::Client.new(
|
234
|
-
answer = client.get(
|
235
|
-
assert_equal(2, answer.mcode
|
236
|
-
assert_equal(5, answer.mcode[1])
|
169
|
+
client = CoRE::CoAP::Client.new(host: 'coap.me', max_payload: 16)
|
170
|
+
answer = client.get('/large')
|
171
|
+
assert_equal([2, 5], answer.mcode)
|
237
172
|
assert_equal(%Q'\n 0 1 2 3\n 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\n +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n |Ver| T | TKL | Code | Message ID |\n +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n | Token (if any, TKL bytes) ...\n +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n | Options (if any) ...\n +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n |1 1 1 1 1 1 1 1| Payload (if any) ...\n +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n[...]\n\n Token Length (TKL): 4-bit unsigned integer. Indicates the length of\n the variable-length Token field (0-8 bytes). Lengths 9-15 are\n reserved, MUST NOT be sent, and MUST be processed as a message\n format error.\n\n Code: 8-bit unsigned integer, split into a 3-bit class (most\n significant bits) and a 5-bit detail (least significant bits),\n documented as c.dd where c is a digit from 0 to 7 for the 3-bit\n subfield and dd are two digits from 00 to 31 for the 5-bit\n subfield. The class can indicate a request (0), a success\n response (2), a client error response (4), or a server error\n response (5). (All other class values are reserved.) As a\n special case, Code 0.00 indicates an Empty message. In case of a\n request, the Code field indicates the Request Method; in case of a\n response a Response Code. Possible values are maintained in the\n CoAP Code Registries (Section 12.1). The semantics of requests\n and responses are defined in Section 5.\n\n', answer.payload)
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_client_separate
|
241
|
-
client = CoAP::Client.new
|
242
|
-
answer = client.get('coap.me', 5683, '/separate')
|
243
|
-
assert_equal(2, answer.mcode[0])
|
244
|
-
assert_equal(5, answer.mcode[1])
|
245
|
-
assert_equal('That took a long time', answer.payload)
|
246
|
-
end
|
247
|
-
|
248
|
-
def test_client_observe
|
249
|
-
# basic observe test
|
250
|
-
client = CoAP::Client.new
|
251
|
-
|
252
|
-
t1 = Thread.new do
|
253
|
-
answer = client.observe('vs0.inf.ethz.ch', 5683, '/obs', method(:observe_tester))
|
254
|
-
end
|
255
|
-
sleep(10)
|
256
|
-
t1.kill
|
257
|
-
|
258
|
-
assert_operator $observe_count, :>, 2
|
259
173
|
end
|
260
174
|
|
261
175
|
def test_client_block2
|
262
|
-
|
263
|
-
client = CoAP::Client.new
|
176
|
+
client = CoRE::CoAP::Client.new
|
264
177
|
client.max_payload = 512
|
265
|
-
answer = client.get('
|
266
|
-
assert_equal(2, answer.mcode
|
267
|
-
assert_equal(5, answer.mcode[1])
|
178
|
+
answer = client.get('/large', 'coap.me')
|
179
|
+
assert_equal([2, 5], answer.mcode)
|
268
180
|
assert_equal(%Q'\n 0 1 2 3\n 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\n +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n |Ver| T | TKL | Code | Message ID |\n +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n | Token (if any, TKL bytes) ...\n +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n | Options (if any) ...\n +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n |1 1 1 1 1 1 1 1| Payload (if any) ...\n +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n[...]\n\n Token Length (TKL): 4-bit unsigned integer. Indicates the length of\n the variable-length Token field (0-8 bytes). Lengths 9-15 are\n reserved, MUST NOT be sent, and MUST be processed as a message\n format error.\n\n Code: 8-bit unsigned integer, split into a 3-bit class (most\n significant bits) and a 5-bit detail (least significant bits),\n documented as c.dd where c is a digit from 0 to 7 for the 3-bit\n subfield and dd are two digits from 00 to 31 for the 5-bit\n subfield. The class can indicate a request (0), a success\n response (2), a client error response (4), or a server error\n response (5). (All other class values are reserved.) As a\n special case, Code 0.00 indicates an Empty message. In case of a\n request, the Code field indicates the Request Method; in case of a\n response a Response Code. Possible values are maintained in the\n CoAP Code Registries (Section 12.1). The semantics of requests\n and responses are defined in Section 5.\n\n', answer.payload)
|
269
181
|
end
|
270
|
-
|
271
|
-
def test_client_block1
|
272
|
-
client = CoAP::Client.new
|
273
|
-
client.max_payload = 512
|
274
|
-
answer = client.post('coap.me', 5683, '/large-create', PAYLOAD)
|
275
|
-
assert_equal(2, answer.mcode[0])
|
276
|
-
assert_equal(1, answer.mcode[1])
|
277
|
-
|
278
|
-
client = CoAP::Client.new
|
279
|
-
client.max_payload = 512
|
280
|
-
answer = client.get('coap.me', 5683, '/large-create')
|
281
|
-
assert_equal(2, answer.mcode[0])
|
282
|
-
assert_equal(5, answer.mcode[1])
|
283
|
-
assert_equal(PAYLOAD, answer.payload)
|
284
|
-
|
285
|
-
client = CoAP::Client.new
|
286
|
-
client.max_payload = 512
|
287
|
-
answer = client.post('coap.me', 5683, '/large-create', PAYLOAD_SONDERZEICHEN)
|
288
|
-
assert_equal(2, answer.mcode[0])
|
289
|
-
assert_equal(1, answer.mcode[1])
|
290
|
-
|
291
|
-
client = CoAP::Client.new
|
292
|
-
client.max_payload = 512
|
293
|
-
answer = client.get('coap.me', 5683, '/large-create')
|
294
|
-
assert_equal(2, answer.mcode[0])
|
295
|
-
assert_equal(5, answer.mcode[1])
|
296
|
-
assert_equal(PAYLOAD_SONDERZEICHEN, answer.payload.force_encoding('utf-8'))
|
297
|
-
|
298
|
-
client = CoAP::Client.new
|
299
|
-
client.max_payload = 512
|
300
|
-
answer = client.put('coap.me', 5683, '/large-update', PAYLOAD)
|
301
|
-
assert_equal(2, answer.mcode[0])
|
302
|
-
assert_equal(4, answer.mcode[1])
|
303
|
-
|
304
|
-
client = CoAP::Client.new
|
305
|
-
client.max_payload = 512
|
306
|
-
answer = client.get('coap.me', 5683, '/large-update')
|
307
|
-
assert_equal(2, answer.mcode[0])
|
308
|
-
assert_equal(5, answer.mcode[1])
|
309
|
-
assert_equal(PAYLOAD, answer.payload)
|
310
|
-
end
|
311
182
|
end
|