require 'mock' class MockSocket < Test::Unit::MockObject( TCPSocket ) def initialize(host, port) super @io = ["200 Welcome\r\n"] @authenticated = false @group_selected = nil @last_article = nil end def alive? super true end def recv(len) return readline end def read( len ) super # Call the mocked method to record the call rval = @io[0,len] @io[0,len] = '' return %w{ you should never reach this } end def puts(stuff) super stuff += "\r\n" write stuff end def write( str ) super # Call the mocked method to record the call @io = [] case str.downcase when /^body(.*)/ body = [ "222 1392 <5d6be$4625ae23$51df8a12$32566@news.inode.at> article retrieved - body follows\r\n", "Hi,\r\n", "\r\n", "kennt ihr eine Moeglichkeit den maximalen Speicherbedarf eines Programms \r\n", "ueber dessen gesamte Laufzeit zu ermitteln? Also keine Momentaufnahme \r\n", "wie mit ps, top & Co?\r\n", "\r\n", "Danke & vG\r\n", "Franz Hollerer\r\n", ".\r\n" ] case $1 when /^\s+1392/, /^\s*$/ if @group_selected @io = body else @io = ["412 No Group selected"] end when /^\s*<5d6be\$4625ae23\$51df8a12\$32566@news\.inode\.at>/ @io = body else @io = ["No such article"] end when /^article(.*)/ article = [ "220 1392 <5d6be$4625ae23$51df8a12$32566@news.inode.at> article retrieved - text follows\r\n", "Path: vietwist00.chello.at!newsfeed02.chello.at!news.inode.at.POSTED!not-for-mail\r\n", "Message-ID: <5d6be$4625ae23$51df8a12$32566@news.inode.at>\r\n", "From: Franz Hollerer \r\n", "Newsgroups: at.linux\r\n", "Subject: Q: maximalen Speicherbedarfs eines Programms ueber dessen gesamte\r\n", " Laufzeit\r\n", "Date: Wed, 18 Apr 2007 07:34:56 +0200\r\n", "Lines: 8\r\n", "User-Agent: Thunderbird 1.5.0.10 (Windows/20070221)\r\n", "MIME-Version: 1.0\r\n", "Content-Type: text/plain; charset=ISO-8859-15; format=flowed\r\n", "Content-Transfer-Encoding: 7bit\r\n", "X-Complaints-To: abuse@inode.at\r\n", "NNTP-Posting-Host: 81.223.138.18 (81.223.138.18)\r\n", "NNTP-Posting-Date: Wed, 18 Apr 2007 07:35:31 +0200\r\n", "X-Trace: 5d6be4625ae23f47a2fb732566\r\n", "Xref: sensor.twincode.net at.linux:1392\r\n", "\r\n", "Hi,\r\n", "\r\n", "kennt ihr eine Moeglichkeit den maximalen Speicherbedarf eines Programms \r\n", "ueber dessen gesamte Laufzeit zu ermitteln? Also keine Momentaufnahme \r\n", "wie mit ps, top & Co?\r\n", "\r\n", "Danke & vG\r\n", "Franz Hollerer\r\n", ".\r\n" ] case $1 when /\s*1392/ if @group_selected @io = article else @io = ["412 No Group selected"] end when /^\s*<5d6be\$4625ae23\$51df8a12\$32566@news\.inode\.at>/ @io = article else @io = ["430 No such article"] end when /^list\b\s*(.*)\r\n$/ case $1 when /overview.fmt/i @io = ["215 Order of fields in overview database.\r\n", "Subject:\r\n", "From:\r\n", "Date:\r\n", "Message-ID:\r\n", "References:\r\n", "Bytes:\r\n", "Lines:\r\n", "Xref:full\r\n", ".\r\n" ] when /active\s*(.*)/ @io = ["215 Newsgroups in form \"group high low flags\".", "at.test 200 100 y\r\n", "at.linux 100 90 n\r\n", ".\r\n"] when /^\s*$/ @io = ["215 Newsgroups in form \"group high low flags\".", "at.test 200 100 y\r\n", "at.linux 100 90 n\r\n", ".\r\n"] else @io = ["501 Bad Command Usage"] end when "help\r\n" then @io = [ "100 Legal commands on THIS server:\r\n", "ARTICLE [|]\r\n", "BODY [|]\r\n", "DATE\r\n", "GROUP \r\n", "HDR
|\r\n", "HEAD [|]\r\n", "HELP\r\n", "LAST\r\n", "LIST [ACTIVE|NEWSGROUPS] []]\r\n", "LIST [ACTIVE.TIMES|EXTENSIONS|OVERVIEW.FMT]\r\n", "LISTGROUP \r\n", "MODE READER\r\n", "NEWGROUPS [GMT]\r\n", "NEXT\r\n", "POST\r\n", "OVER \r\n", "SLAVE\r\n", "STAT [|]\r\n", "XHDR
|\r\n", "XOVER \r\n", ".\r\n"] when /^next/i if @group_selected if @last_article if @last_article < 1375 @last_article += 1 else @last_article = nil end else @last_article = 1363 end @io = @last_article ? ["223 #{@last_article} retrieved"] : ['421 No next article in group'] else @io = ['412 No Group selected'] end when /^last/i if @group_selected if @last_article if @last_article > 1363 @last_article -= 1 else @last_article = nil end end @io = @last_article ? ["223 #{@last_article} retrieved"] : ['421 No next article in group'] else @io = ['412 No Group selected'] end when /^mode reader/i @io = ["200 Welcome"] when /^listgroup\s*(.*)\s*/i case $1 when 'at.linux' @io = [ "211 Article list for at.linux follows\r\n", "1363\r\n", "1364\r\n", "1365\r\n", "1366\r\n", "1367\r\n", "1368\r\n", "1369\r\n", "1370\r\n", "1371\r\n", "1372\r\n", "1373\r\n", "1374\r\n", "1375\r\n", ".\r\n" ] else if @group_selected @io = [ "211 Article list for at.linux follows\r\n", "1363\r\n", "1364\r\n", "1365\r\n", "1366\r\n", "1367\r\n", "1368\r\n", "1369\r\n", "1370\r\n", "1371\r\n", "1372\r\n", "1373\r\n", "1374\r\n", "1375\r\n", ".\r\n" ] else @io = ['412 No Group selected'] end end when "quit\r\n" then @io = ["200 Good bye"] when "authinfo user dummy\r\n" @io = ["381 More authentication details needed"] when "authinfo pass test\r\n" @io = ["281 Welcome to dummytest"] when /^group\s+(.+)\s*\r\n$/ case $1 when 'at.linux' @io = ["211 12 1363 1375 at.linux"] @group_selected = 'at.linux' else @io = ["411 No such group"] end when "xhdr subject \r\n" @io = ["1375 Re: Bitte um Meinungen ==> Virtualisierung\r\n"] when "xhdr subject 1363-1375\r\n" if @group_selected @io = [ "221 Subject header (from overview) for postings 1363-1375\r\n", "1363 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1364 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1365 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1366 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1367 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1368 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1369 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1370 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1371 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1372 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1373 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1374 Re: Bitte um Meinungen ==> Virtualisierung\r\n", "1375 Re: Bitte um Meinungen ==> Virtualisierung\r\n", ".\r\n" ] else @io = ['412 No group selected'] end when "xover 1363-1375\r\n" if @group_selected @io = [ "224 Overview information for postings 1363-1375:\r\n", "1363 Re: Bitte um Meinungen ==> Virtualisierung \"Igo Besser\" Sun, 15 Apr 2007 14:09:46 +0200 <46221541$0$2299$91cee783@newsreader01.highway.telekom.at> <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621ff58$0$2307$91cee783@newsreader01.highway.telekom.at> 1165 9 Xref: sensor.twincode.net at.linux:1363\r\n", "1364 Re: Bitte um Meinungen ==> Virtualisierung \"Igo Besser\" Sun, 15 Apr 2007 14:14:12 +0200 <4622164b$0$25611$91cee783@newsreader02.highway.telekom.at> <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621fc17$0$2315$91cee783@newsreader01.highway.telekom.at> 1229 13 Xref: sensor.twincode.net at.linux:1364\r\n", "1365 Re: Bitte um Meinungen ==> Virtualisierung \"Peter J. Holzer\" Sun, 15 Apr 2007 16:39:56 +0200 <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621ff58$0$2307$91cee783@newsreader01.highway.telekom.at> 2643 42 Xref: sensor.twincode.net at.linux:1365\r\n", "1366 Re: Bitte um Meinungen ==> Virtualisierung \"Igo Besser\" Sun, 15 Apr 2007 19:14:08 +0200 <46225c97$0$25626$91cee783@newsreader02.highway.telekom.at> <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621ff58$0$2307$91cee783@newsreader01.highway.telekom.at> 1344 13 Xref: sensor.twincode.net at.linux:1366\r\n", "1367 Re: Bitte um Meinungen ==> Virtualisierung \"Peter J. Holzer\" Sun, 15 Apr 2007 21:35:27 +0200 <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621ff58$0$2307$91cee783@newsreader01.highway.telekom.at> <46225c97$0$25626$91cee783@newsreader02.highway.telekom.at> 1851 24 Xref: sensor.twincode.net at.linux:1367\r\n", "1368 Re: Bitte um Meinungen ==> Virtualisierung Wolfgang Steger Sun, 15 Apr 2007 21:48:48 +0200 <16caf4-581.ln1@swws1.dyndns.org> <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621ff58$0$2307$91cee783@newsreader01.highway.telekom.at> <46225c97$0$25626$91cee783@newsreader02.highway.telekom.at> 2248 20 Xref: sensor.twincode.net at.linux:1368\r\n", "1369 Re: Bitte um Meinungen ==> Virtualisierung Michael Prokop Sun, 15 Apr 2007 22:22:46 +0200 <2007-04-15T22-19-44@devnull.michael-prokop.at> <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621ff58$0$2307$91cee783@newsreader01.highway.telekom.at> <46225c97$0$25626$91cee783@newsreader02.highway.telekom.at> 2022 23 Xref: sensor.twincode.net at.linux:1369\r\n", "1370 Re: Bitte um Meinungen ==> Virtualisierung Robert Annessi Sun, 15 Apr 2007 22:52:36 +0200 <46229089$0$10578$3b214f66@tunews.univie.ac.at> <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621ff58$0$2307$91cee783@newsreader01.highway.telekom.at> <46225c97$0$25626$91cee783@newsreader02.highway.telekom.at> <16caf4-581.ln1@swws1.dyndns.org> 1807 27 Xref: sensor.twincode.net at.linux:1370\r\n", "1371 Re: Bitte um Meinungen ==> Virtualisierung \"Thomas Spachinger\" Sun, 15 Apr 2007 22:58:17 +0200 <58fi18F2gdp4eU1@mid.individual.net> <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621fc17$0$2315$91cee783@newsreader01.highway.telekom.at> <4622164b$0$25611$91cee783@newsreader02.highway.telekom.at> 1427 18 Xref: sensor.twincode.net at.linux:1371\r\n", "1372 Re: Bitte um Meinungen ==> Virtualisierung Bernd Haug Sun, 15 Apr 2007 23:54:05 +0200 <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621ff58$0$2307$91cee783@newsreader01.highway.telekom.at> <46225c97$0$25626$91cee783@newsreader02.highway.telekom.at> 1721 10 Xref: sensor.twincode.net at.linux:1372\r\n", "1373 Re: Bitte um Meinungen ==> Virtualisierung Wolfgang Fuschlberger Sun, 15 Apr 2007 23:58:07 +0200 <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621ff58$0$2307$91cee783@newsreader01.highway.telekom.at> <46225c97$0$25626$91cee783@newsreader02.highway.telekom.at> <16caf4-581.ln1@swws1.dyndns.org> <46229089$0$10578$3b214f66@tunews.univie.ac.at> 1800 17 Xref: sensor.twincode.net at.linux:1373\r\n", "1374 Re: Bitte um Meinungen ==> Virtualisierung Andreas Labres Mon, 16 Apr 2007 08:57:43 +0200 <1tnru1ccirb05.dlg@al.lab.at> <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621ff58$0$2307$91cee783@newsreader01.highway.telekom.at> 1702 19 Xref: sensor.twincode.net at.linux:1374\r\n", "1375 Re: Bitte um Meinungen ==> Virtualisierung \"Peter J. Holzer\" Mon, 16 Apr 2007 09:49:46 +0200 <4621dbb8$0$2310$91cee783@newsreader01.highway.telekom.at> <4621ff58$0$2307$91cee783@newsreader01.highway.telekom.at> <1tnru1ccirb05.dlg@al.lab.at> 2127 33 Xref: sensor.twincode.net at.linux:1375\r\n", ".\r\n" ] else @io = ["412 No Group selected"] end when /xover \<.+\>/ @io = ["502 Usage: OVER first[-[last]]"] when /^xhdr\s*$/ @io = ["502 Usage: HDR header [first[-last]]|[message-id]"] when /^head(.*)$/ case $1 when /^\s+(1430|<462dfa6f$0$23135$9b4e6d93@newsspool1.arcor-online.net>)/ @io = [ "221 1430 <462dfa6f$0$23135$9b4e6d93@newsspool1.arcor-online.net> article retrieved - head follows\r\n", "Path: vietwist00.chello.at!newsfeed02.chello.at!newsfeed01.chello.at!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail\r\n", "Message-ID: <462dfa6f$0$23135$9b4e6d93@newsspool1.arcor-online.net>\r\n", "From: Gerhard Engler \r\n", "Newsgroups: at.linux\r\n", "Subject: Re: udev_node_mknod: /dev/capi Operation not permitted\r\n", "Date: Tue, 24 Apr 2007 14:39:11 +0200\r\n", "References: <4629ee10$0$10187$9b4e6d93@newsspool4.arcor-online.net> \r\n", "Lines: 26\r\n", "User-Agent: Thunderbird 1.5.0.10 (Windows/20070221)\r\n", "MIME-Version: 1.0\r\n", "In-Reply-To: \r\n", "Content-Type: text/plain; charset=ISO-8859-15; format=flowed\r\n", "Content-Transfer-Encoding: 7bit\r\n", "Organization: Arcor\r\n", "NNTP-Posting-Date: 24 Apr 2007 14:39:11 CEST\r\n", "NNTP-Posting-Host: 6cf11d8c.newsspool1.arcor-online.net\r\n", "X-Trace: DXC=Cd=D_AR>:`a^Y=RbYBPl4`ic==]BZ:afn4Fo<]lROoRaFl8W>\BH3Yb7K@fQgPi`FgUTEAfnAR\Ta@JWJ8E:^d article retrieved - head follows\r\n", "Path: vietwist00.chello.at!newsfeed02.chello.at!newsfeed01.chello.at!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail\r\n", "Message-ID: <462dfa6f$0$23135$9b4e6d93@newsspool1.arcor-online.net>\r\n", "From: Gerhard Engler \r\n", "Newsgroups: at.linux\r\n", "Subject: Re: udev_node_mknod: /dev/capi Operation not permitted\r\n", "Date: Tue, 24 Apr 2007 14:39:11 +0200\r\n", "References: <4629ee10$0$10187$9b4e6d93@newsspool4.arcor-online.net> \r\n", "Lines: 26\r\n", "User-Agent: Thunderbird 1.5.0.10 (Windows/20070221)\r\n", "MIME-Version: 1.0\r\n", "In-Reply-To: \r\n", "Content-Type: text/plain; charset=ISO-8859-15; format=flowed\r\n", "Content-Transfer-Encoding: 7bit\r\n", "Organization: Arcor\r\n", "NNTP-Posting-Date: 24 Apr 2007 14:39:11 CEST\r\n", "NNTP-Posting-Host: 6cf11d8c.newsspool1.arcor-online.net\r\n", "X-Trace: DXC=Cd=D_AR>:`a^Y=RbYBPl4`ic==]BZ:afn4Fo<]lROoRaFl8W>\BH3Yb7K@fQgPi`FgUTEAfnAR\Ta@JWJ8E:^d