Ejemplo n.º 1
0
//
// Machinery for delayed images rendering (e.g. Xv with YV12 or VAAPI)
//
void
test_iterators(Renderer *renderer, const std::string &type)
{
    cout << "\t"<< type << " iterator tests" << endl;
    
    if (!renderer) {
        runtest.unresolved("No renderer to test!");
        return;
    }

    Renderer::RenderImages::iterator fit = renderer->getFirstRenderImage();
    Renderer::RenderImages::iterator lit = renderer->getLastRenderImage();
    // When there are no images, the first and last are the same obviously
    if (fit == lit) {
         runtest.pass("getFirstRenderImage()");
    } else {
        runtest.fail("getFirstRenderImage()");
    }

#if 0    
    geometry::Point2d a(1, 2);
    geometry::Point2d c(3, 4);
    Renderer::RenderImage image;
    image::GnashImage *frame = new image::ImageRGBA(10, 10);
    // gnash::GnashVaapiImage *foo = static_cast<gnash::GnashVaapiImage *>(frame);
    // gnash::GnashVaapiImageProxy *bar = new gnash::GnashVaapiImageProxy(foo, a.x, a.y, c.x - a.x, c.y - a.y);
    std::auto_ptr<image::GnashImage> rgba(frame);
//    image.reset(new gnash::GnashVaapiImageProxy(foo, a.x, a.y, c.x - a.x, c.y - a.y));

    renderer->addRenderImage(image);
//    image.reset(new gnash::GnashVaapiImageProxy(foo, a.x, a.y, c.x - a.x, c.y - a.y));
    renderer->addRenderImage(image);
#endif
    
    fit = renderer->getFirstRenderImage();
    lit = renderer->getLastRenderImage();
    // When there are no images, the first and last are the same obviously
    if (fit != lit) {
         runtest.pass("addRenderImage()");
    } else {
        runtest.fail("addRenderImage()");
    }
    
#if 0
    typedef boost::shared_ptr<GnashVaapiImageProxy> RenderImage;
    typedef std::vector<RenderImage> RenderImages;

    // Get first render image
    virtual RenderImages::iterator getFirstRenderImage()
            { return _render_images.begin(); }
    virtual RenderImages::const_iterator getFirstRenderImage() const
            { return _render_images.begin(); }

    // Get last render image
    virtual RenderImages::iterator getLastRenderImage()
            { return _render_images.end(); }
    virtual RenderImages::const_iterator getLastRenderImage() const
            { return _render_images.end(); }
#endif
}
Ejemplo n.º 2
0
void
test_construct()
{
// these tests are bogus unless you have both mallinfo()
// and also have memory statistics gathering turned on.
#if defined(HAVE_MALLINFO) && defined(USE_STATS_MEMORY)
    bool valgrind = false;
    
    size_t fudge = sizeof(long *)*5;
    
    Memory mem(5);
    mem.addStats(__LINE__);             // take a sample
    Buffer buf1;
    mem.addStats(__LINE__);             // take a sample
    size_t diff = mem.diffStats() - sizeof(buf1);    
    if (diff > NETBUFSIZE) {
        valgrind = true;
        log_debug("Running this test case under valgrind screws up mallinfo(), so the results get skewed");
    }
    // Different systems allocate memory slightly differently, so about all we can do to see
    // if it worked is check to make sure it's within a tight range of possible values.
     if ((buf1.size() == NETBUFSIZE) && (diff >= (NETBUFSIZE - fudge)) && diff <= (NETBUFSIZE + fudge)) {
        runtest.pass ("Buffer::Buffer()");
    } else {
        if (valgrind) {
            runtest.unresolved("Buffer::Buffer()) under valgrind");
        } else {
            runtest.fail("Buffer::Buffer()");
        }
    }
    
    mem.addStats(__LINE__);             // take a sample
    Buffer buf2(124);
    mem.addStats(__LINE__);             // take a sample
    diff = mem.diffStats() - sizeof(long *);
    if ((buf2.size() == 124) && (124 - fudge) && diff <= (124 + fudge)) {
        runtest.pass ("Buffer::Buffer(size_t)");
    } else {
        if (valgrind) {
            runtest.unresolved("Buffer::Buffer(size_t) under valgrind");
        } else {
            runtest.fail("Buffer::Buffer(size_t)");
        }
    }
#endif
}
Ejemplo n.º 3
0
void
load_data()
{

    LcShm lc;
    char *shmaddr;

    string con1 = "lc_reply";
    if (!lc.connect(con1)) {
        if (errno == EACCES) {
            runtest.untested("Couldn't map input file, permission problems!!");
        } else {
            runtest.unresolved("LcShm::connect()");
        }
        exit(0);
    }

    shmaddr = reinterpret_cast<char*>(lc.begin());
//    if (memcmp(shmaddr, con1.c_str():
    // Since this is a test case, populate the memory with known good data
    string srcdir = SRCDIR;
    srcdir += "/segment.raw";
    int fd = ::open(srcdir.c_str(), O_RDONLY);
    void *dataptr = mmap(0, 64528, PROT_READ, MAP_SHARED, fd, 0);

    if (dataptr != (void*)-1) {
        memcpy(shmaddr, dataptr, 64528);
    } else {
        if (errno == EACCES) {
            runtest.unresolved("Couldn't map input file, permission problems!!");
        } else {
            runtest.unresolved("Couldn't map input file!");
            log_debug("Error was: %s", strerror(errno));
        }
        exit(0);
    }

    ::close(fd);
}
Ejemplo n.º 4
0
void
test_listen()
{

    LcShm lc;
    char *shmaddr;
    
    string con1 = "localhost:lc_reply";
    if (lc.connect("lc_reply")) {
        runtest.pass("LcShm::connect()");
    } else {
        runtest.fail("LcShm::connect()");
    }
    
    //
    shmaddr = reinterpret_cast<char*>(lc.begin());
    if (shmaddr == 0) {
        runtest.unresolved("LcShm::begin()");
        return;
    } else {
        runtest.pass("LcShm::begin()");
    }
    
    char *addr = shmaddr + LC_LISTENERS_START;
    memset(addr, 0, 1024);
    
    lc.close();

    // Now reconnect to the memory segment, and see if our name
    // is set.
    if (lc.connect(con1)) {
        runtest.pass("LcShm::connect()");
    } else {
        runtest.fail("LcShm::connect()");
    }
    
    if (strcmp(addr, "localhost:lc_reply") == 0) {
        runtest.pass("LcShm::addListener(lc_reply)");
    } else {
        runtest.fail("LcShm::addListener(lc_reply)");
    }
    
    string con2 = "localhost:lc_name1";
    if (lc.connect(con2)) {
        runtest.pass("LcShm::connect(lc_name1)");
    } else {
        runtest.fail("LcShm::connect(lc_name1)");
    }

    if (strcmp(addr, "localhost:lc_reply") == 0) {
        runtest.pass("LcShm::addListener(lc_reply)");
    } else {
        runtest.fail("LcShm::addListener(lc_reply)");
    }

    // Aftyer removing a listener, everything gets moved up
    // in the table. The last element gets zero'd out, so
    // we don't have duplicate entries.
    lc.removeListener(con1);
    if ((strcmp(addr, "localhost:lc_name1") == 0)
    && (addr[con1.size() + 1] == 0)
    && (addr[con1.size() + 2] == 0)
    && (addr[con1.size() + 3] == 0)) {
        runtest.pass("LcShm::removeListener(lc_reply)");
    } else {
        runtest.fail("LcShm::removeListener(lc_reply)");
    }
    
    Listener list(reinterpret_cast<uint8_t *>(shmaddr));
    vector<string>::const_iterator it;
    auto_ptr< vector<string> > listeners ( list.listListeners() );
    if (listeners->size() == 0) {
        cout << "Nobody is listening" << endl;
    } else {
        for (it=listeners->begin(); it!=listeners->end(); it++) {
            string str = *it;
	    if ((str[0] != ':') || (dbglogfile.getVerbosity() > 0)) {
		cout << " Listeners: " << str << endl;
	    }
        }
    }
    
}
Ejemplo n.º 5
0
void
test_geometry(Renderer *renderer, const std::string &type)
{
    cout << "\t" << type << " geometry tests" << endl;
    
    if (!renderer) {
        runtest.unresolved("No renderer to test!");
        return;
    }
    
    int x = 10;
    int y = 10;
    geometry::Point2d nz(200, 0);
    geometry::Point2d z(x, y);
    geometry::Range2d<int> pixelbounds;
    geometry::Range2d<int> worldbounds;
    Timer tpixtow("pixel_to_world(int, int)");
    z = renderer->pixel_to_world(x, y);
    tpixtow.stop();
    
    if ((z.x >= 199) || (z.y >= 199)) {
        runtest.pass(std::string("pixel_to_world(int, int) ") + tpixtow.elapsed());
    } else {
        runtest.fail(std::string("pixel_to_world(int, int) ") + tpixtow.elapsed());
    }
    
#if 0
    Timer tpixtow2("pixel_to_world(pixelbounds)");
    worldbounds = renderer->pixel_to_world(pixelbounds);
    tpixtow2.stop();
    if (worldbounds.isNull()) {
        runtest.pass(std::string("pixel_to_world(geometry::Range2d<int>) ") + tpixtow2.elapsed());
    } else {
        runtest.fail(std::string("pixel_to_world(geometry::Range2d<int>) ") + tpixtow2.elapsed());
    }
#else
    runtest.untested("pixel_to_world(geometry::Range2d<int>)");
#endif
    
    Timer twtop("world_to_pixel(geometry::Range2d<int>)");
    pixelbounds = renderer->world_to_pixel(worldbounds);
    twtop.stop();
    if (pixelbounds.isNull()) {
        runtest.pass(std::string("world_to_pixel(geometry::Range2d<int>) ") + twtop.elapsed());
    } else {
        runtest.fail(std::string("world_to_pixel(geometry::Range2d<int>) ") + twtop.elapsed());
    }
    
    SWFRect bounds;
    Timer tbounds1("bounds_in_clipping_area(SWFRect)");
    bool ret = renderer->bounds_in_clipping_area(bounds);
    tbounds1.stop();
    if (ret) {
        runtest.pass(std::string("bounds_in_clipping_area(SWFRect) ") + tbounds1.elapsed());
    } else {
        runtest.fail(std::string("bounds_in_clipping_area(SWFRect) ") + tbounds1.elapsed());
    }
    
    InvalidatedRanges ranges;
    Timer tbounds2("bounds_in_clipping_area(InvalidatedRanges)");
    ret = renderer->bounds_in_clipping_area(ranges);
    tbounds2.stop();
    if (!ret) {
        runtest.pass(std::string("bounds_in_clipping_area(InvalidatedRanges) ") + tbounds2.elapsed());
    } else {
        runtest.fail(std::string("bounds_in_clipping_area(InvalidatedRanges) ") + tbounds2.elapsed());
    }

    Timer tbounds3("bounds_in_clipping_area(geometry::Range2d<int>)");
    ret = renderer->bounds_in_clipping_area(pixelbounds);
    tbounds3.stop();
    if (!ret) {
        runtest.pass(std::string("bounds_in_clipping_area(geometry::Range2d<int>) ") + tbounds3.elapsed());
    } else {
        runtest.fail(std::string("bounds_in_clipping_area(geometry::Range2d<int>) ") + tbounds3.elapsed());
    }
}
Ejemplo n.º 6
0
void
test_renderer(Renderer *renderer, const std::string &type)
{
    cout << "Testing " << type << " Renderer" << endl;
//    Timer trend("Renderer Tests", true);
    
    if (!renderer) {
        runtest.unresolved("No renderer to test!");
        return;
    }
    
    if (renderer > 0) {
        runtest.pass("Got Renderer");
    } else {
        runtest.fail("Couldn't get Renderer");
    }

    if (!renderer->description().empty()) {
        if (renderer->description() == type) {
            runtest.pass("description is correct");
        } else {
            runtest.fail("description is wrong");
        }
    } else {
        runtest.fail("Couldn't get description!");
    }

#if 0
    if (renderer->getBitsPerPixel()) {
        runtest.pass("getBitsPerPixel()");
    } else {
        runtest.fail("getBitsPerPixel()");
    }
#endif
    
    image::GnashImage *frame1 = new image::ImageRGBA(10, 12);
    std::auto_ptr<image::GnashImage> im1(frame1);
    CachedBitmap *cb = renderer->createCachedBitmap(im1);
    if (cb) {
        image::GnashImage &gi = cb->image();
        if ((gi.width() == 10) && (gi.height() == 12)) {
            runtest.pass("createCachedBitmap()");
        } else {
            runtest.fail("createCachedBitmap()");
        }
    } else {
        runtest.unresolved("createCachedBitmap()");
    }

#if 0
    // FIXME: initTestBuffer() is going away, replaced by the fake
    // framebuffer code.
    // Initializes the renderer for off-screen rendering used by the testsuite.
    if (renderer->initTestBuffer(10, 10)) {
        runtest.pass("initTestBuffer()");
    } else {
        runtest.fail("initTestBuffer()");
    }
#endif
    
    /// @coords an array of 16-bit signed integer coordinates. Even indices
    ///         (and 0) are x coordinates, while uneven ones are y coordinates.
    /// @vertex_count the number of x-y coordinates (vertices).
    /// @color the color to be used to draw the line strip.
    /// @mat the SWFMatrix to be used to transform the vertices.
    boost::uint16_t x = 10;
    boost::uint16_t y = 10;
    boost::uint16_t h = 10;
    std::vector<point> box = boost::assign::list_of
        (point(x, y))
        (point(x, y + h));

    rgba color(0, 0, 0, 255);
    SWFMatrix mat;
    mat.set_scale_rotation(1, 3, 0);

    Timer tdrawline("drawline");
    renderer->drawLine(box, color, mat);
    tdrawline.stop();
    
    // if (1) {
    //     runtest.pass("drawLine()");
    // } else {
    //     runtest.fail("drawLine()");
    // }
    runtest.unresolved(std::string("drawLine() ") + tdrawline.elapsed());

    //drawVideoFrame(image::GnashImage* frame, const Transform& xform, const SWFRect* bounds, bool smooth);
#if 0
    image::GnashImage *frame;
    const Transform xform;
    const SWFRect bounds;
    bool smooth;
    Timer tdrawvideo("drawVideoFrame");
    renderer->drawVideoFrame(frame, xform, bounds, smooth);
    tdrawvideo.stop();
#endif
    runtest.untested("drawVideoFrame()");

    point *corners = 0;
    size_t corner_count = 0;
    rgba fill(0, 0, 0, 255);;
    rgba outline(0, 0, 0, 255);;
    bool masked = true;
    Timer tdrawpoly("drawPoly");
    renderer->draw_poly(corners, corner_count, fill, outline, mat, masked);
    tdrawpoly.stop();
    runtest.unresolved(std::string("drawPoly() ") + tdrawpoly.elapsed());
    
//    SWF::ShapeRecord shape;
    SWFMatrix mat2(0x10000, 0x0, 0x0, 0x10000, 0x0, 0x0);
    SWFCxForm cxform;
    //(0x100, 0x100, 0x100, 0x100, 0x0, 0x0, 0x0, 0x0);
    Transform xform(mat2, cxform);
    SWF::ShapeRecord shape;
    // _bounds = {0x80000000, 0x7fffffff,
    //            0x80000000, 0x80000000,
    //            0x80000000, 0x80000000}}
    Timer drawshape("drawShape");
    renderer->drawShape(shape, xform);
    runtest.unresolved("drawShape()");
    drawshape.stop();
    
//    SWF::ShapeRecord rec;
    // rgba color;
    // SWFMatrix mat;
//    Timer drawGlyph("drawGlyph");
//    renderer->drawGlyph(rec, color, mat);
    runtest.untested("drawGlyph()");
//   drawglyph.stop();

#if 0
    boost::shared_ptr<IOChannel> io;
    FileType ftype;
    Timer renderi("renderToImage");
    renderer->renderToImage(io, ftype);
    renderi.stop();
#endif
    runtest.untested("renderToImage()");

    CachedBitmap *bitmap = 0;
    image::GnashImage *frame2 = new image::ImageRGBA(10, 10);
    std::auto_ptr<image::GnashImage> im(frame2);
    Timer cbit("createCachedBitmap");
    bitmap = renderer->createCachedBitmap(im);
    cbit.stop();
    if (bitmap) {
        runtest.pass(std::string("createCachedBitmap() ") + cbit.elapsed());
    } else {
        runtest.fail(std::string("createCachedBitmap() ") + cbit.elapsed());
    }
    
}
Ejemplo n.º 7
0
void
test()
{
    DiskStream ds1;

    // Create an array of printable ASCII characters
    int range = '~' - '!';
    char *buf = new char[range];
    for (int j=0; j<range; j++) {
        buf[j] = '!' + j;
    }

    create_file("outbuf.raw", 500);    
    ds1.open("outbuf.raw");

    // ptr should be the base address of the memory plus the offset
    boost::uint8_t *ptr = ds1.loadToMem(48);
//    boost::uint8_t *dsptr = ds1.get(); // cache the initial base address
    
    if ((ds1.get() == MAP_FAILED) || (ds1.get() == 0)) {
        runtest.unresolved("loadToMem(48)");
    } else {
        if ((memcmp(ds1.get(), buf, 48) == 0)
            && (memcmp(ptr, buf+48, range-48) == 0)) {
            runtest.pass("loadToMem(48)");
        } else {
            runtest.fail("loadToMem(48)");
        }
    }

    // as the offset is less than the memory pagesize, the pointer
    // should be the same as before, as it points to data in the
    // current segment. The temporary pointer should point to the
    // appropriate place in memory page.
    ptr = ds1.loadToMem(128);
    if ((ds1.get() == MAP_FAILED) || (ds1.get() == 0)) {
        runtest.unresolved("loadToMem(128)");
    } else {
        if ((memcmp(ds1.get(), buf, range) == 0)
            && (memcmp(ptr, buf+(128-range), 128-range) == 0)) {
            runtest.pass("loadToMem(128)");
        } else {
            runtest.fail("loadToMem(128)");
        }
    }

    // close the currently opened file
    ds1.close();
    if (ds1.getState() == DiskStream::CLOSED) {
        runtest.pass("close()");
    } else {
        runtest.fail("close()");
    }

    
    DiskStream ds2;
    // Create a bigger file that's larger than the page size
    create_file("outbuf2.raw", 12000);
    ds2.open("outbuf2.raw");
    ptr = ds2.loadToMem(6789);
    if ((ds2.get() == MAP_FAILED) || (ds2.get() == 0)) {
        runtest.unresolved("loadToMem(6789)");
    } else {
        if ((memcmp(ds2.get(), buf, range-4) == 0)
            && (memcmp(ptr, buf, range-4) == 0)) {
            runtest.pass("loadToMem(6789)");
        } else {
            runtest.fail("loadToMem(6789)");
        }
    }

    // test seeking in data files.
    ptr = ds2.seek(5100);
    if ((ds2.get() == MAP_FAILED) || (ds2.get() == 0)) {
        runtest.unresolved("seek(5100)");
    } else {
        if ((memcmp(ds2.get(), buf, range-4) == 0)
            && (memcmp(ptr, buf+78, range-78) == 0)) {
            runtest.pass("seek(5100)");
        } else {
            runtest.fail("seek(5100)");
        }
    }
    
//     if (dump) {
//         ds2.dump();
//     }

    delete[] buf;
    unlink("outbuf.raw");
    unlink("outbuf2.raw");
}
Ejemplo n.º 8
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();
     }
}