]> gitweb.factorcode.org Git - factor.git/blob - extra/pop3/pop3-tests.factor
10c5024d588c766b8c5a3a47647e0ce1441524d9
[factor.git] / extra / pop3 / pop3-tests.factor
1 ! Copyright (C) 2009 Elie Chaftari.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: concurrency.promises namespaces kernel pop3 pop3.server
4 sequences tools.test accessors calendar ;
5 IN: pop3.tests
6
7 FROM: pop3 => count delete ;
8
9 <promise> "p1" set
10
11 [ ] [ "p1" get mock-pop3-server ] unit-test
12 [ ] [
13         <pop3-account>
14             "127.0.0.1" >>host
15             "p1" get 5 seconds ?promise-timeout >>port
16         connect
17 ] unit-test
18 [ ] [ "username@host.com" >user ] unit-test
19 [ ] [ "password" >pwd ] unit-test
20 [ { "CAPA" "TOP" "UIDL" } ] [ capa ] unit-test
21 [ 2 ] [ count ] unit-test
22 [ H{ { 1 "1006" } { 2 "747" } } ] [ list ] unit-test
23 [
24     H{
25         { "From:" "from.first@mail.com" }
26         { "Subject:" "First test with mock POP3 server" }
27         { "To:" "username@host.com" }
28     }
29 ] [ 1 0 top drop headers ] unit-test
30 [
31     {
32         T{ message
33             { # 1 }
34             { uidl "000000d547ac2fc2" }
35             { from "from.first@mail.com" }
36             { to "username@host.com" }
37             { subject "First test with mock POP3 server" }
38             { size "1006" }
39         }
40         T{ message
41             { # 2 }
42             { uidl "000000d647ac2fc2" }
43             { from "from.second@mail.com" }
44             { to "username@host.com" }
45             { subject "Second test with mock POP3 server" }
46             { size "747" }
47         }
48     }
49 ] [ consolidate ] unit-test
50 [ "000000d547ac2fc2" ] [ 1 uidl ] unit-test
51 [ ] [ 1 delete ] unit-test
52 [ ] [ reset ] unit-test
53 [ ] [ close ] unit-test
54
55
56 <promise> "p2" set
57
58 [ ] [ "p2" get mock-pop3-server ] unit-test
59 [ ] [
60         <pop3-account>
61             "127.0.0.1" >>host
62             "p2" get 5 seconds ?promise-timeout >>port
63             "username@host.com" >>user
64             "password" >>pwd
65         connect
66 ] unit-test
67 [ f ] [ 1 retrieve empty? ] unit-test
68 [ ] [ close ] unit-test