summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-23 15:20:47 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-23 15:20:47 +0000
commit4676ede3d1338ca78c58496a3ce11e78df188215 (patch)
tree68009796d910c03a8daa06ecd967ae33359b2e08 /test
parentf984a4d8476c8e1349caed98379843d1268bb069 (diff)
* lib/net/imap.rb (resp_text_code): accepts response codes without
text. [ruby-core:24194] * lib/net/imap.rb (idle, idle_done): new methods for the IMAP4 IDLE command (RFC 2177). Thanks, Eric Hodel. * lib/net/imap.rb (format_date, format_datetime): new method to format IMAP-style date/datetime. Thanks, Eric Hodel. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/net/imap/test_imap.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/net/imap/test_imap.rb b/test/net/imap/test_imap.rb
index cff09d3cbc..e4e1c25ca0 100644
--- a/test/net/imap/test_imap.rb
+++ b/test/net/imap/test_imap.rb
@@ -18,6 +18,18 @@ class IMAPTest < Test::Unit::TestCase
assert_equal(utf8, s)
end
+ def test_format_date
+ time = Time.mktime(2009, 7, 24)
+ s = Net::IMAP.format_date(time)
+ assert_equal("24-Jul-2009", s)
+ end
+
+ def test_format_datetime
+ time = Time.mktime(2009, 7, 24, 1, 23, 45)
+ s = Net::IMAP.format_datetime(time)
+ assert_match(/\A24-Jul-2009 01:23 [+\-]\d{4}\z/, s)
+ end
+
def test_imaps_unknown_ca
if defined?(OpenSSL)
assert_raise(OpenSSL::SSL::SSLError) do
@@ -112,6 +124,58 @@ class IMAPTest < Test::Unit::TestCase
end
end
+ def test_idle
+ server = TCPServer.new(0)
+ port = server.addr[1]
+ requests = []
+ Thread.start do
+ begin
+ sock = server.accept
+ begin
+ sock.print("* OK test server\r\n")
+ requests.push(sock.gets)
+ sock.print("+ idling\r\n")
+ sock.print("* 3 EXISTS\r\n")
+ sock.print("* 2 EXPUNGE\r\n")
+ requests.push(sock.gets)
+ sock.print("RUBY0001 OK IDLE terminated\r\n")
+ sock.gets
+ sock.print("* BYE terminating connection\r\n")
+ sock.print("RUBY0002 OK LOGOUT completed\r\n")
+ ensure
+ sock.close
+ end
+ rescue
+ end
+ end
+ begin
+ begin
+ imap = Net::IMAP.new("localhost", :port => port)
+ responses = []
+ imap.idle do |res|
+ responses.push(res)
+ if res.name == "EXPUNGE"
+ imap.idle_done
+ end
+ end
+ assert_equal(3, responses.length)
+ assert_instance_of(Net::IMAP::ContinuationRequest, responses[0])
+ assert_equal("EXISTS", responses[1].name)
+ assert_equal(3, responses[1].data)
+ assert_equal("EXPUNGE", responses[2].name)
+ assert_equal(2, responses[2].data)
+ assert_equal(2, requests.length)
+ assert_equal("RUBY0001 IDLE\r\n", requests[0])
+ assert_equal("DONE\r\n", requests[1])
+ imap.logout
+ ensure
+ imap.disconnect if imap
+ end
+ ensure
+ server.close
+ end
+ end
+
private
def imaps_test