Tests: implement smtp test backend and use it.
diff --git a/README b/README
index 8187478..51753e0 100644
--- a/README
+++ b/README
@@ -3,10 +3,14 @@
 Use prove to run tests as one usually do for perl tests.  Individual tests
 may be run as well.
 
+Tests assume that nginx sources are in directory nginx at the same level
+as directory with tests, and nginx was already configured and built (i.e.
+nginx binary available as ../nginx/objs/nginx from test directory).
+
 Note: some tests may fail since they are for bugs not fixed in public code.
 
 Note: tests run nginx listening on localhost, and currently this includes
-following ports: 8080, 10025.
+following ports: 8025, 8026, 8080, 8081.
 
 Currently each test creates it's own temporary directory and uses it for
 logs etc.  One may instruct tests not to remove the temp directory (e.g.
diff --git a/lib/Test/Nginx/SMTP.pm b/lib/Test/Nginx/SMTP.pm
index 606f509..1898539 100644
--- a/lib/Test/Nginx/SMTP.pm
+++ b/lib/Test/Nginx/SMTP.pm
@@ -23,7 +23,7 @@
 	my $self = return $class->SUPER::new(
 		Proto => "tcp",
 		PeerAddr => "localhost",
-		PeerPort => 10025,
+		PeerPort => 8025,
 		@_
 	)
 		or die "Can't connect to nginx: $!\n";
@@ -70,6 +70,45 @@
 
 ###############################################################################
 
+sub smtp_test_daemon {
+	my $server = IO::Socket::INET->new(
+		Proto => 'tcp',
+		LocalPort => 8026,
+		Listen => 5,
+		Reuse => 1
+	)
+		or die "Can't create listening socket: $!\n";
+
+	while (my $client = $server->accept()) {
+		$client->autoflush(1);
+		print $client "220 fake esmtp server ready" . CRLF;
+
+		while (<$client>) {
+			if (/^quit/i) {
+				print $client '221 quit ok' . CRLF;
+			} elsif (/^(ehlo|helo)/i) {
+				print $client '250 hello ok' . CRLF;
+			} elsif (/^rset/i) {
+				print $client '250 rset ok' . CRLF;
+			} elsif (/^mail from:[^@]+$/i) {
+				print $client '500 mail from error' . CRLF;
+			} elsif (/^mail from:/i) {
+				print $client '250 mail from ok' . CRLF;
+			} elsif (/^rcpt to:[^@]+$/i) {
+				print $client '500 rcpt to error' . CRLF;
+			} elsif (/^rcpt to:/i) {
+				print $client '250 rcpt to ok' . CRLF;
+			} else {
+				print $client "500 unknown command" . CRLF;
+			}
+                }
+
+		close $client;
+	}
+}
+
+###############################################################################
+
 1;
 
 ###############################################################################
diff --git a/smtp-greeting-delay.t b/smtp-greeting-delay.t
index 06181e5..2c09401 100644
--- a/smtp-greeting-delay.t
+++ b/smtp-greeting-delay.t
@@ -38,7 +38,7 @@
     xclient    off;
 
     server {
-        listen     localhost:10025;
+        listen     localhost:8025;
         protocol   smtp;
         smtp_greeting_delay  100ms;
     }
diff --git a/smtp.t b/smtp.t
index 4e44cd8..ecccefe 100644
--- a/smtp.t
+++ b/smtp.t
@@ -25,7 +25,9 @@
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->write_file_expand('nginx.conf', <<'EOF')->run();
+my $t = Test::Nginx->new()
+	->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon)
+	->write_file_expand('nginx.conf', <<'EOF')->run();
 
 master_process off;
 daemon         off;
@@ -40,7 +42,7 @@
     xclient    off;
 
     server {
-        listen     localhost:10025;
+        listen     localhost:8025;
         protocol   smtp;
         smtp_auth  login plain none;
     }
@@ -65,7 +67,7 @@
 
             add_header Auth-Status $reply;
             add_header Auth-Server 127.0.0.1;
-            add_header Auth-Port 25;
+            add_header Auth-Port 8026;
             add_header Auth-Wait 1;
             return 204;
         }