From d1103a077284a7014a172b898b5fa367a9f9c690 Mon Sep 17 00:00:00 2001 From: Guillaume DOTT Date: Mon, 9 Sep 2013 17:29:35 +0200 Subject: [PATCH] Add spec for new PDU classes --- spec/biju/pdu/data_coding_scheme_spec.rb | 29 ++++++++++++++++++++++++ spec/biju/pdu/phone_number_spec.rb | 21 +++++++++++++++++ spec/biju/pdu/type_of_address_spec.rb | 9 ++++++++ spec/biju/pdu/user_data_spec.rb | 12 ++++++++++ spec/biju/sms_spec.rb | 13 +++++++++++ 5 files changed, 84 insertions(+) create mode 100644 spec/biju/pdu/data_coding_scheme_spec.rb create mode 100644 spec/biju/pdu/phone_number_spec.rb create mode 100644 spec/biju/pdu/type_of_address_spec.rb create mode 100644 spec/biju/pdu/user_data_spec.rb diff --git a/spec/biju/pdu/data_coding_scheme_spec.rb b/spec/biju/pdu/data_coding_scheme_spec.rb new file mode 100644 index 0000000..184a23a --- /dev/null +++ b/spec/biju/pdu/data_coding_scheme_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' +require 'biju/pdu' + +describe Biju::PDU::DataCodingScheme do + describe '::autodetect' do + it "autodetects gsm7bit encoding" do + [ + "Test", + "Ç$", + "[teßt}", + ].each do |string| + expect(Biju::PDU::DataCodingScheme.autodetect(string)).to eq(:gsm7bit) + end + end + + it "autodetects ucs2 encoding" do + [ + "ç", + "âmazing", + ].each do |string| + expect(Biju::PDU::DataCodingScheme.autodetect(string)).to eq(:ucs2) + end + end + end + + subject { Biju::PDU::DataCodingScheme.new(:gsm7bit) } + its(:to_sym) { should eq(:gsm7bit) } + its(:hex) { should eq(0) } +end diff --git a/spec/biju/pdu/phone_number_spec.rb b/spec/biju/pdu/phone_number_spec.rb new file mode 100644 index 0000000..3943fe1 --- /dev/null +++ b/spec/biju/pdu/phone_number_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' +require 'biju/pdu' + +describe Biju::PDU::PhoneNumber do + describe '::encode' do + subject { Biju::PDU::PhoneNumber.encode('33123456789') } + its(:number) { should eq('3321436587F9') } + end + + context "odd length" do + subject { Biju::PDU::PhoneNumber.new('3321436587F9') } + its(:decode) { should eq('33123456789') } + its(:length) { should eq(11) } + end + + context "even length" do + subject { Biju::PDU::PhoneNumber.new('3321436587') } + its(:decode) { should eq('3312345678') } + its(:length) { should eq(10) } + end +end diff --git a/spec/biju/pdu/type_of_address_spec.rb b/spec/biju/pdu/type_of_address_spec.rb new file mode 100644 index 0000000..6312dcd --- /dev/null +++ b/spec/biju/pdu/type_of_address_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' +require 'biju/pdu' + +describe Biju::PDU::TypeOfAddress do + subject { Biju::PDU::TypeOfAddress.new(:international) } + + its(:to_sym) { should eq(:international) } + its(:hex) { should eq(145) } +end diff --git a/spec/biju/pdu/user_data_spec.rb b/spec/biju/pdu/user_data_spec.rb new file mode 100644 index 0000000..9d7bc52 --- /dev/null +++ b/spec/biju/pdu/user_data_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' +require 'biju/pdu' + +describe Biju::PDU::UserData do + subject(:message) { 'Test' } + subject(:encoded) { Biju::PDU::Encoding::GSM7Bit.encode(message) } + subject { Biju::PDU::UserData.encode(message, encoding: :gsm7bit) } + + its(:message) { should eq(encoded[0]) } + its(:length) { should eq(encoded[1][:length]) } + its(:decode) { should eq(message) } +end diff --git a/spec/biju/sms_spec.rb b/spec/biju/sms_spec.rb index f3ade4a..a2f262e 100644 --- a/spec/biju/sms_spec.rb +++ b/spec/biju/sms_spec.rb @@ -23,5 +23,18 @@ describe Biju::Sms do its(:datetime) { should eq(DateTime.new(2013, 9, 5, 9, 59, 29, '+08')) } its(:message) { should eq('Test') } + its(:phone_number) { should eq('33666666666') } + its(:type_of_address) { should eq(:international) } + end + + describe '#to_pdu' do + subject do + Biju::Sms.new( + phone_number: '33666666666', + type_of_address: :international, + message: 'Test').to_pdu.upcase + end + + it { should eq('0001000B913366666666F6000004D4F29C0E') } end end