Exemple #1
0
static void
test_errors (void)
{
    Cache cache;
    // Add a few path names
    cache.addPath("foo", "/bar/foo");
    cache.addPath("bar", "/foo/bar");

    if ((cache.findPath("foo") == "/bar/foo")
        && (cache.findPath("bar") == "/foo/bar")
        && (cache.findPath("foobar").size() == 0)) {
        runtest.pass("Cache::findPath()");
    } else {
        runtest.fail("Cache::findPath()");
    }

    std::string resp1 = "HTTP/1.1\r\n404 Object Not Found\r\nServer: Microsoft-IIS/4.0\r\n\r\nDate: Sat, 08 Dec 2007 20:32:20 GMT\r\nConnection: close\r\nContent-Length: 461\r\nContent-Type: text/html";
    cache.addResponse("foo", resp1);
    cache.addResponse("bar", resp1);
    if ((cache.findResponse("foo") == resp1)
        && (cache.findResponse("bar") == resp1)
        && (cache.findResponse("foobar").size() == 0)) {
        runtest.pass("Cache::findResponse()");
    } else {
        runtest.fail("Cache::findResponse()");
    }

    boost::shared_ptr<DiskStream> file1(new DiskStream);
//    create_file("outbuf1.raw", 100);   it's created aleady in test().
    file1->open("outbuf1.raw");

    cache.addFile("foo", file1);
    if ((cache.findFile("foo")->getFileSize() == file1->getFileSize())
         && (cache.findFile("bar") == 0)) {
        runtest.pass("Cache::addFile()/findFile()");
    } else {
        runtest.fail("Cache::addFile()/findFile()");
    }
    
    // see what happens if we try an uninitialized Cache.
    Cache c1;
    
    if (c1.findPath("foo").size() == 0) {
        runtest.pass("Cache::findPath(empty)");
    } else {
        runtest.fail("Cache::findPath(empty)");
    }

    if (c1.findResponse("foo").size() == 0) {
        runtest.pass("Cache::findResponse(empty)");
    } else {
        runtest.fail("Cache::findResponse(empty)");
    }

    if (c1.findFile("foo") == 0) {
        runtest.pass("Cache::findFile(empty)");
    } else {
        runtest.fail("Cache::findFile(empty)");
    }
    
//      if (dbglogfile.getVerbosity() > 0) {
//          cache.dump();
//      }
}
Exemple #2
0
static void
test_remove(void)
{
    Cache cache;

    // Add a few path names
    cache.addPath("foo", "/bar/foo");
    cache.addPath("bar", "/foo/bar");
    cache.addPath("barfoo", "/foo/bar/barfoo");
    cache.addPath("foobar", "/foo/bar/foobar");

     if (dump) {
         cache.dump();
     }
    // now remove one in the middle
    cache.removePath("barfoo");
    if ((cache.findPath("foo") == "/bar/foo")
        && (cache.findPath("bar") == "/foo/bar")
        && (cache.findPath("barfoo").empty())
        && (cache.findPath("foobar") == "/foo/bar/foobar")) {
        runtest.pass("Cache::removePath()");
    } else {
        runtest.fail("Cache::removePath()");
    }
    
    // FIXME: make these different, although it probably makes not difference.
    std::string resp1 = "HTTP/1.1\r\n404 Object Not Found\r\nServer: Microsoft-IIS/4.0\r\n\r\nDate: Sat, 08 Dec 2007 20:32:20 GMT\r\nConnection: close\r\nContent-Length: 461\r\nContent-Type: text/html";

    cache.addResponse("foo", resp1);
    cache.addResponse("bar", resp1);
    cache.addResponse("barfoo", resp1);
    cache.addResponse("foobar", resp1);
    cache.removeResponse("barfoo");
    if ((cache.findResponse("foo") == resp1)
        && (cache.findResponse("bar") == resp1)
        && (cache.findResponse("barfoo").empty())
        && (cache.findResponse("foobar") == resp1)) {
        runtest.pass("Cache::removeResponse()");
    } else {
        runtest.fail("Cache::removeResponse()");
    }

    boost::shared_ptr<DiskStream> file1(new DiskStream);
    create_file("outbuf1.raw", 100);
    file1->open("outbuf1.raw");

    boost::shared_ptr<DiskStream> file2(new DiskStream);
    create_file("outbuf2.raw", 200);
    file2->open("outbuf2.raw");

    boost::shared_ptr<DiskStream> file3(new DiskStream);
    create_file("outbuf3.raw", 300);
    file3->open("outbuf3.raw");

    boost::shared_ptr<DiskStream> file4(new DiskStream);
    create_file("outbuf4.raw", 400);
    file4->open("outbuf4.raw");

    cache.addFile("foo", file1);
    cache.addFile("bar", file2);
    cache.addFile("barfoo", file3);
    cache.addFile("foobar", file4);
    cache.removeFile("barfoo");

    boost::shared_ptr<DiskStream> ds1 = cache.findFile("foo");
    boost::shared_ptr<DiskStream> ds2 = cache.findFile("bar");
    if (ds1 && ds2) {
        if ((cache.findFile("foo")->getFileSize() == file1->getFileSize())
            && (cache.findFile("barfoo") == 0)
            && (cache.findFile("bar")->getFileSize() == file2->getFileSize())) {
            runtest.pass("Cache::removeFile()");
        } else {
            runtest.fail("Cache::removeFile()");
        }
    } else {
        runtest.unresolved("Cache::removeFile()");
    }
    
    if (dbglogfile.getVerbosity() > 0) {
         cache.dump();
     }
}