240E48152E50689CBB454D0
  
   355Ǿ c    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
  $   laeJi@pe1h&ÿ '    #include <TestSupport.h>
#include <Utils/CachedFileStat.hpp>
#include <SystemTools/SystemTime.h>
#include <sys/types.h>
#include <utime.h>

using namespace std;
using namespace Passenger;

namespace tut {
	struct CachedFileStatTest: public TestBase {
		struct stat buf;

		~CachedFileStatTest() {
			SystemTime::release();
			unlink("test.txt");
			unlink("test2.txt");
			unlink("test3.txt");
			unlink("test4.txt");
		}
	};

	DEFINE_TEST_GROUP(CachedFileStatTest);

	static void touch(const char *filename, time_t timestamp = 0) {
		FILE *f = fopen(filename, "w");
		fprintf(f, "hi");
		fclose(f);
		if (timestamp != 0) {
			struct utimbuf buf;
			buf.actime = timestamp;
			buf.modtime = timestamp;
			utime(filename, &buf);
		}
	}

	/************ Tests involving a single file ************/

	TEST_METHOD(1) {
		// Statting a new file works.
		touch("test.txt");
		CachedFileStat stat(1);
		ensure_equals(stat.stat("test.txt", &buf, 1), 0);
		ensure_equals((long) buf.st_size, (long) 2);
	}

	TEST_METHOD(2) {
		// It does not re-stat an existing file until the cache has expired.
		CachedFileStat stat(1);

		SystemTime::force(5);
		touch("test.txt", 1);
		ensure_equals("1st stat succceeded",
			stat.stat("test.txt", &buf, 1),
			0);

		touch("test.txt", 1000);
		ensure_equals("2nd stat succceeded",
			stat.stat("test.txt", &buf, 1),
			0);
		ensure_equals("Cached value was used",
			buf.st_mtime,
			(time_t) 1);

		SystemTime::force(6);
		ensure_equals("3rd stat succceeded",
			stat.stat("test.txt", &buf, 1),
			0);
		ensure_equals("Cache has been invalidated",
			buf.st_mtime,
			(time_t) 1000);
	}

	TEST_METHOD(3) {
		// Statting a nonexistant file returns an error.
		CachedFileStat stat(1);
		ensure_equals(stat.stat("test.txt", &buf, 1), -1);
		ensure_equals("It sets errno appropriately", errno, ENOENT);
	}

	TEST_METHOD(4) {
		// It does not re-stat a previously nonexistant file until
		// the cache has expired.
		SystemTime::force(5);
		CachedFileStat stat(1);
		ensure_equals("1st stat failed",
			stat.stat("test.txt", &buf, 1),
			-1);
		ensure_equals("It sets errno appropriately", errno, ENOENT);

		errno = EEXIST;
		touch("test.txt", 1000);
		ensure_equals("2nd stat failed",
			stat.stat("test.txt", &buf, 1),
			-1);
		ensure_equals("It sets errno appropriately", errno, ENOENT);
		ensure_equals("Cached value was used",
			buf.st_mtime,
			(time_t) 0);

		SystemTime::force(6);
		ensure_equals("3rd stat succeeded",
			stat.stat("test.txt", &buf, 1),
			0);
		ensure_equals("Cache has been invalidated",
			buf.st_mtime,
			(time_t) 1000);

		unlink("test.txt");
		ensure_equals("4th stat succeeded even though file was unlinked",
			stat.stat("test.txt", &buf, 1),
			0);
		ensure_equals("Cached value was used",
			buf.st_mtime,
			(time_t) 1000);
	}

	TEST_METHOD(5) {
		// If the throttling rate is 0 then the cache will be bypassed.
		SystemTime::force(5);
		CachedFileStat stat(2);
		ensure_equals("1st stat returns -1",
			stat.stat("test.txt", &buf, 0),
			-1);
		touch("test.txt");
		ensure_equals("2nd stat did not go through the cache",
			stat.stat("test.txt", &buf, 0),
			0);
	}


	/************ Tests involving multiple files ************/

	TEST_METHOD(10) {
		// Throttling in combination with multiple files works.
		CachedFileStat stat(2);
		SystemTime::force(5);

		// Touch and stat test.txt. The next stat should return
		// the old info.

		touch("test.txt", 10);
		ensure_equals(
			stat.stat("test.txt", &buf, 1),
			0);
		ensure_equals(buf.st_mtime, (time_t) 10);

		touch("test.txt", 20);
		ensure_equals(
			stat.stat("test.txt", &buf, 1),
			0);
		ensure_equals(buf.st_