[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash/cygnal ChangeLog buffer.h buffer.cpp hand...
From: |
Rob Savoye |
Subject: |
[Gnash-commit] gnash/cygnal ChangeLog buffer.h buffer.cpp hand... |
Date: |
Sun, 16 Mar 2008 01:26:18 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Rob Savoye <rsavoye> 08/03/16 01:26:18
Modified files:
cygnal : ChangeLog
Added files:
cygnal : buffer.h buffer.cpp handler.h handler.cpp
cygnal/testsuite/cygnal.all: test_buffer.cpp test_handler.cpp
Log message:
* buffer.{h,cpp}: Low level class to hold blocks of memory for
message queues.
* testsuite/cygnal.all/test_buffer.cpp: Test case for the
Buffer class.
* handler.{h,cpp}: Higher level handler for all incoming network
connections.
* testsuite/cygnal.all/test_handler.cpp: Test case for the
Handler class.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/ChangeLog?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/buffer.h?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/buffer.cpp?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/handler.h?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/handler.cpp?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/testsuite/cygnal.all/test_buffer.cpp?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/testsuite/cygnal.all/test_handler.cpp?cvsroot=gnash&rev=1.1
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/cygnal/ChangeLog,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ChangeLog 3 Oct 2007 15:29:16 -0000 1.3
+++ ChangeLog 16 Mar 2008 01:26:17 -0000 1.4
@@ -1,3 +1,20 @@
+2008-03-15 Rob Savoye <address@hidden>
+
+ * buffer.{h,cpp}: Low level class to hold blocks of memory for
+ message queues.
+ * testsuite/cygnal.all/test_buffer.cpp: Test case for the Buffer class.
+ * handler.{h,cpp}: Higher level handler for all incoming network
+ connections.
+ * testsuite/cygnal.all/test_handler.cpp: Test case for the Handler
class.
+
+2008-03-14 Rob Savoye <address@hidden>
+
+ * buffer.{h, cpp}: New class for low-level buffer allocation.
+ * testsuite/cygnal.all/test_buffer.cpp: Test case for low level
+ buffer class.
+ * handler.{h, cpp}: New class for handling network connections.
+ * testsuite/cygnal.all/test_buffer.cpp: Test case for handler class.
+
2009-09-05 Markus Gothe
* cygnal.cpp: Added a #ifdef ENABLE_NLS.
Index: buffer.h
===================================================================
RCS file: buffer.h
diff -N buffer.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ buffer.h 16 Mar 2008 01:26:17 -0000 1.1
@@ -0,0 +1,76 @@
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#ifndef __BUFFER_H__
+#define __BUFFER_H__ 1
+
+#include <boost/cstdint.hpp>
+
+// _definst_ is the default instance name
+namespace cygnal
+{
+
+class Buffer
+{
+public:
+ Buffer();
+ // Create with a size other than the default
+ Buffer(size_t nbytes);
+
+ // Delete the allocate memory
+ ~Buffer();
+ void empty();
+
+ // Resize the buffer that holds the data
+ void *resize(size_t nbytes);
+
+ // Put data into the buffer
+ void copy(boost::uint8_t *data, int nbytes);
+
+ // Accessors
+ boost::uint8_t *reference() { return _ptr; }
+ size_t size() { return _nbytes; }
+ void setSize(size_t nbytes) { _nbytes = nbytes; };
+
+ // make ourselves be able to be copied.
+ Buffer &operator=(Buffer *buf);
+ Buffer &operator=(Buffer &buf);
+
+ // Test against other buffers
+ bool operator==(Buffer *buf);
+ bool operator==(Buffer &buf);
+
+ boost::uint8_t operator[](int x) { return _ptr[x]; };
+
+ // debug stuff, not need for running Cygnal
+ void dump();
+private:
+ void *init(size_t nbytes);
+ boost::uint8_t *_ptr;
+ int _nbytes;
+};
+
+
+} // end of cygnal namespace
+
+#endif // end of __BUFFER_H__
+
+// local Variables:
+// mode: C++
+// indent-tabs-mode: t
+// End:
Index: buffer.cpp
===================================================================
RCS file: buffer.cpp
diff -N buffer.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ buffer.cpp 16 Mar 2008 01:26:17 -0000 1.1
@@ -0,0 +1,180 @@
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#include <boost/cstdint.hpp>
+#include "buffer.h"
+#include "log.h"
+
+using namespace std;
+
+namespace cygnal
+{
+
+// Adjust for the constant size
+const size_t BUFFERSIZE = 128;
+
+void *
+Buffer::init(size_t nbytes)
+{
+// GNASH_REPORT_FUNCTION;
+ if (_ptr == 0) {
+ _ptr = new boost::uint8_t[nbytes];
+ _nbytes = nbytes;
+ // this could be a performance hit, but for debugging we leave it in
so we get
+ // easier to ready hex dumps in GDB,
+ empty();
+ }
+
+ return _ptr;
+}
+
+Buffer::Buffer()
+{
+// GNASH_REPORT_FUNCTION;
+ _ptr = 0;
+ _nbytes = BUFFERSIZE;
+ init(BUFFERSIZE);
+}
+
+// Create with a size other than the default
+Buffer::Buffer(size_t nbytes)
+{
+// GNASH_REPORT_FUNCTION;
+ _ptr = 0;
+ _nbytes = nbytes;
+ init(nbytes);
+}
+
+// Delete the allocate memory
+Buffer::~Buffer()
+{
+// GNASH_REPORT_FUNCTION;
+ if (_ptr) {
+ delete[] _ptr;
+ _ptr = 0;
+ _nbytes = 0;
+ }
+}
+
+// Put data into the buffer
+void
+Buffer::copy(boost::uint8_t *data, int nbytes)
+{
+// GNASH_REPORT_FUNCTION;
+ std::copy(data, data + nbytes, _ptr);
+}
+
+// make ourselves be able to be copied.
+Buffer &
+Buffer::operator=(Buffer *buf)
+{
+// GNASH_REPORT_FUNCTION;
+ if (buf->size() != _nbytes) {
+ resize(buf->size());
+ }
+
+ std::copy(buf->reference(), buf->reference() + _nbytes, _ptr);
+
+ return *this;
+}
+
+Buffer &
+Buffer::operator=(Buffer &buf)
+{
+// GNASH_REPORT_FUNCTION;
+ if (buf.size() != _nbytes) {
+ resize(buf.size());
+ }
+
+ std::copy(buf.reference(), buf.reference() + _nbytes, _ptr);
+
+ return *this;
+}
+
+// Check to see if two Buffer objects are identical
+bool
+Buffer::operator==(Buffer *buf)
+{
+ if (buf->size() == _nbytes) {
+ if (memcmp(buf->reference(), _ptr, _nbytes) == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+Buffer::operator==(Buffer &buf)
+{
+ if (buf.size() == _nbytes){
+ if (memcmp(buf.reference(), _ptr, _nbytes) == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+// Just reset to having no data, but still having storage
+void
+Buffer::empty()
+{
+// GNASH_REPORT_FUNCTION;
+ if (_ptr) {
+ memset(_ptr, 0, _nbytes);
+ }
+}
+
+// Resize the buffer that holds the data
+void *
+Buffer::resize(size_t nbytes)
+{
+ // Allocate a new memory block
+ boost::uint8_t *tmp = new boost::uint8_t[nbytes];
+ // And copy ourselves into it
+ if (nbytes > _nbytes) {
+ std::copy(_ptr, _ptr + _nbytes, tmp);
+ }
+
+ if (nbytes < _nbytes) {
+ std::copy(_ptr, _ptr + nbytes, tmp);
+ }
+
+ _nbytes = nbytes;
+
+ // Delete the old block, it's unused now
+ delete[] _ptr;
+
+ // Make the memeory block use the new space
+ _ptr = tmp;
+
+ return tmp;
+}
+
+void
+Buffer::dump()
+{
+ cerr << "Buffer is " << _nbytes << " bytes at " << (void *)_ptr << endl;
+}
+
+} // end of cygnal namespace
+
+
+// local Variables:
+// mode: C++
+// indent-tabs-mode: t
+// End:
Index: handler.h
===================================================================
RCS file: handler.h
diff -N handler.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ handler.h 16 Mar 2008 01:26:17 -0000 1.1
@@ -0,0 +1,125 @@
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#ifndef __HANDLER_H__
+#define __HANDLER_H__ 1
+
+#include <boost/cstdint.hpp>
+#include <boost/thread/condition.hpp>
+#include <string>
+#include <deque>
+
+#include "log.h"
+#include "buffer.h"
+
+// _definst_ is the default instance name
+namespace cygnal
+{
+
+class Handler
+{
+public:
+ Handler();
+ ~Handler();
+
+ // This is used to pass parameters to a thread using boost::bind
+ typedef struct {
+ int netfd;
+ int port;
+ std::string filespec;
+ } thread_params_t ;
+
+ // Specify which queue should be used
+ typedef enum { INCOMING, OUTGOING } fifo_e;
+
+ // Push bytes on the incoming FIFO, which is the default
+ bool push(boost::uint8_t *data, int nbytes, fifo_e direction);
+ bool push(Buffer *data, fifo_e direction);
+ bool push(Buffer *data)
+ { return push(data, INCOMING); };
+ bool push(boost::uint8_t *data, int nbytes)
+ { return push(data, nbytes, INCOMING); };
+ bool pushin(boost::uint8_t *data, int nbytes)
+ { return push(data, nbytes, INCOMING); };
+ bool pushin(Buffer *data)
+ { return push(data, INCOMING); };
+
+ // Push bytes on the incoming FIFO, which must be specified
+ bool pushout(boost::uint8_t *data, int nbytes)
+ { return push(data, nbytes, OUTGOING); };
+ bool pushout(Buffer *data)
+ { return push(data, OUTGOING); };
+
+ // Pop the first date element off the incoming FIFO
+ Buffer *pop(fifo_e direction);
+ Buffer *pop()
+ { return pop(INCOMING); };
+ Buffer *popin()
+ { return pop(INCOMING); };
+ // Pop the first date element off the outgoing FIFO
+ Buffer *popout()
+ { return pop(OUTGOING); };
+
+ // Peek at the first data element without removing it
+ Buffer *peek(fifo_e direction);
+ Buffer *peek()
+ { return peek(INCOMING); };
+ Buffer *peekin()
+ { return peek(INCOMING); };
+ // Pop the first date element off the outgoing FIFO
+ Buffer *peekout()
+ { return peek(OUTGOING); };
+
+ // Removes all the buffers from the queues
+ void clear() { _incoming.clear(); };
+ void clear(fifo_e direction);
+ void clearin() { _incoming.clear(); };
+ void clearout() { _outgoing.clear(); };
+ void clearall() { _outgoing.clear(); _incoming.clear(); };
+
+ // Return the size of the queues, default to the incoming queue
+ size_t size(fifo_e direction);
+ size_t size() { return size(INCOMING); };
+ size_t insize() { return _incoming.size(); };
+ size_t outsize() { return _outgoing.size(); };
+
+ // Dump internal data.
+ void dump();
+private:
+ int _netfd;
+ boost::condition _inmutex;
+ std::deque<Buffer *> _incoming;
+
+ std::deque<Buffer *> _outgoing;
+ boost::condition _outmutex;
+};
+
+// This is the thread for all incoming network connections, which
+// has to be in C.
+extern "C" {
+ void nethandler(Handler::thread_params_t *args);
+}
+
+} // end of cygnal namespace
+
+#endif // end of __HANDLER_H__
+
+// local Variables:
+// mode: C++
+// indent-tabs-mode: t
+// End:
Index: handler.cpp
===================================================================
RCS file: handler.cpp
diff -N handler.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ handler.cpp 16 Mar 2008 01:26:17 -0000 1.1
@@ -0,0 +1,180 @@
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#ifdef HAVE_CONFIG_H
+#include "gnashconfig.h"
+#endif
+
+#include <boost/thread/mutex.hpp>
+#include <boost/date_time/gregorian/gregorian.hpp>
+//#include <boost/date_time/local_time/local_time.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+//#include <boost/date_time/time_zone_base.hpp>
+#include <string>
+#include <deque>
+
+#include "log.h"
+#include "buffer.h"
+#include "handler.h"
+
+using namespace gnash;
+using namespace std;
+using namespace boost;
+
+namespace cygnal
+{
+
+Handler::Handler()
+{
+// GNASH_REPORT_FUNCTION;
+}
+
+Handler::~Handler()
+{
+// GNASH_REPORT_FUNCTION;
+#if 0
+ deque<Buffer *>::iterator it;
+ for (it = _incoming.begin(); it != _incoming.end(); it++) {
+ Buffer *ptr = *(it);
+// delete ptr;
+ }
+ for (it = _outgoing.begin(); it != _outgoing.end(); it++) {
+ Buffer *ptr = *(it);
+ delete ptr;
+ }
+#endif
+}
+
+bool
+Handler::push(Buffer *data, fifo_e direction)
+{
+// GNASH_REPORT_FUNCTION;
+ if (direction == Handler::OUTGOING) {
+ _outgoing.push_back(data);
+ return true;
+ }
+ if (direction == Handler::INCOMING) {
+ _incoming.push_back(data);
+ return true;
+ }
+
+ return false;
+}
+
+// Push bytes on the outgoing FIFO
+bool
+Handler::push(uint8_t *data, int nbytes, fifo_e direction)
+{
+// GNASH_REPORT_FUNCTION;
+ Buffer *ptr = new Buffer;
+ return push(ptr, direction);
+}
+
+// Pop the first date element off the FIFO
+Buffer *
+Handler::pop(fifo_e direction)
+{
+// GNASH_REPORT_FUNCTION;
+ Buffer *buf;
+
+ if (direction == Handler::OUTGOING) {
+ if (_outgoing.size()) {
+ buf = _outgoing.front();
+ _outgoing.pop_front();
+ }
+ }
+ if (direction == Handler::INCOMING) {
+ if (_incoming.size()) {
+ buf = _incoming.front();
+ _incoming.pop_front();
+ }
+ }
+
+ return buf;
+}
+
+// Peek at the first data element without removing it
+Buffer *
+Handler::peek(fifo_e direction)
+{
+// GNASH_REPORT_FUNCTION;
+ if (direction == Handler::OUTGOING) {
+ if (_outgoing.size()) {
+ return _outgoing.front();
+ }
+ }
+ if (direction == Handler::INCOMING) {
+ if (_incoming.size()) {
+ return _incoming.front();
+ }
+ }
+}
+
+// Return the size of the queues
+size_t
+Handler::size(fifo_e direction)
+{
+// GNASH_REPORT_FUNCTION;
+ if (direction == Handler::OUTGOING) {
+ return _outgoing.size();
+ }
+ if (direction == Handler::INCOMING) {
+ return _incoming.size();
+ }
+
+ return 0; // we should never actually get to here
+}
+
+// Return the size of the queues
+void
+Handler::clear(fifo_e direction)
+{
+// GNASH_REPORT_FUNCTION;
+ if (direction == Handler::OUTGOING) {
+ _outgoing.clear();
+ }
+ if (direction == Handler::INCOMING) {
+ _incoming.clear();
+ }
+}
+
+// Dump internal data.
+void
+Handler::dump()
+{
+// GNASH_REPORT_FUNCTION;
+ deque<Buffer *>::iterator it;
+ cerr << "Incoming queue has "<< _incoming.size() << " buffers." << endl;
+ for (it = _incoming.begin(); it != _incoming.end(); it++) {
+ Buffer *ptr = *(it);
+ ptr->dump();
+ }
+ cerr << endl << "Outgoing queue has "<< _outgoing.size() << " buffers." <<
endl;
+ for (it = _outgoing.begin(); it != _outgoing.end(); it++) {
+ Buffer *ptr = *(it);
+ ptr->dump();
+ }
+}
+
+} // end of cygnal namespace
+
+
+// local Variables:
+// mode: C++
+// indent-tabs-mode: t
+// End:
Index: testsuite/cygnal.all/test_buffer.cpp
===================================================================
RCS file: testsuite/cygnal.all/test_buffer.cpp
diff -N testsuite/cygnal.all/test_buffer.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/cygnal.all/test_buffer.cpp 16 Mar 2008 01:26:17 -0000
1.1
@@ -0,0 +1,114 @@
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#ifdef HAVE_CONFIG_H
+#include "gnashconfig.h"
+#endif
+
+#include <regex.h>
+#include <cstdio>
+#include <cerrno>
+#include <iostream>
+#include <fstream>
+#include <cstring>
+#include <vector>
+#include <boost/cstdint.hpp>
+
+#ifdef HAVE_DEJAGNU_H
+#include "dejagnu.h"
+#else
+#include "check.h"
+#endif
+
+#include "log.h"
+#include "gmemory.h"
+#include "buffer.h"
+
+using namespace std;
+using namespace gnash;
+using namespace cygnal;
+using namespace boost;
+
+TestState runtest;
+LogFile& dbglogfile = LogFile::getDefaultInstance();
+
+// This must match the value in buffer.h
+const size_t BUFFERSIZE = 128;
+
+int
+main (int /*argc*/, char** /*argv*/) {
+ gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
+ dbglogfile.setVerbosity();
+ // We use the Memory profiling class to check the malloc buffers
+ // in the kernel to make sure the allocations and frees happen
+ // the way we expect them too. There is no real other way to tell.
+ Memory mem;
+ mem.startStats();
+
+ Buffer buf;
+ mem.addStats(__LINE__); // take a sample
+
+ if (buf.size() == BUFFERSIZE) {
+ runtest.pass ("Buffer::size()");
+ } else {
+ runtest.fail ("Buffer::size()");
+ }
+
+ mem.addStats(__LINE__); // take a sample
+ buf.resize(112);
+ mem.addStats(__LINE__); // take a sample
+
+ if ((buf.size() == 112) && (mem.diffStats() == -16)) {
+ runtest.pass ("Buffer::resize()");
+ } else {
+ runtest.fail ("Buffer::resize()");
+ }
+ mem.addStats(__LINE__); // take a sample
+
+// buf.dump();
+ mem.addStats(__LINE__); // take a sample
+ buf.empty(); //empty just nukes the contents
+ if ((buf.size() == 112) && (mem.diffStats() == 0)) {
+ runtest.pass ("Buffer::empty()");
+ } else {
+ runtest.fail ("Buffer::empty()");
+ }
+
+ // populate the buffer
+ boost::uint8_t *ptr = buf.reference();
+ for (size_t i=1; i< buf.size(); i++) {
+ ptr[i] = i;
+ }
+
+ Buffer buf2;
+ if (buf2 == buf) {
+ runtest.fail ("Buffer::operator==");
+ } else {
+ runtest.pass ("Buffer::operator==");
+ }
+
+ buf2 = buf;
+ if (buf2 == buf) {
+ runtest.pass ("Buffer::operator=");
+ } else {
+ runtest.fail ("Buffer::operator=");
+ }
+
+// mem.analyze();
+}
+
Index: testsuite/cygnal.all/test_handler.cpp
===================================================================
RCS file: testsuite/cygnal.all/test_handler.cpp
diff -N testsuite/cygnal.all/test_handler.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/cygnal.all/test_handler.cpp 16 Mar 2008 01:26:18 -0000
1.1
@@ -0,0 +1,130 @@
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#ifdef HAVE_CONFIG_H
+#include "gnashconfig.h"
+#endif
+
+#ifdef HAVE_STDARG_H
+#include <cstdarg>
+#endif
+
+#include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <regex.h>
+#include <cstdio>
+#include <cerrno>
+#include <iostream>
+#include <fstream>
+#include <cstring>
+#include <vector>
+#include <boost/cstdint.hpp>
+
+#ifdef HAVE_DEJAGNU_H
+#include "dejagnu.h"
+#else
+#include "check.h"
+#endif
+
+#include "log.h"
+#include "handler.h"
+
+using namespace std;
+using namespace gnash;
+using namespace cygnal;
+using namespace boost;
+
+TestState runtest;
+LogFile& dbglogfile = LogFile::getDefaultInstance();
+
+int
+main (int /*argc*/, char** /*argv*/) {
+ gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
+ dbglogfile.setVerbosity();
+
+ Handler que;
+
+ Buffer buf;
+ boost::uint8_t *test = new uint8_t[6];
+ memcpy(test, "hell", 4);
+
+ // Push one buffer on the fifo. The default is the incoming fifo,
+ // which is the one where data flows from the network to the queue.
+ que.push(&buf);
+ if ((que.size() == 1) && (que.outsize() == 0)) {
+ runtest.pass ("Handler::push(Buffer *)");
+ } else {
+ runtest.fail ("Handler::push(Buffer *)");
+ }
+
+ // Push one buffer on the outgoing fifo. The default is the incoming fifo,
+ // The outgoing fifo is where data flows from the queu to the network. As
+ // we can explicitly specufy which queue we write to, we test that here.
+ que.pushout(&buf);
+ if ((que.size() == 1) && (que.outsize() == 1)) {
+ runtest.pass ("Handler::pushout(Buffer *)");
+ } else {
+ runtest.fail ("Handler::pushout(Buffer *)");
+ }
+
+ // Test pushin. When dumpimg, the second address should be different than
the first,
+ // as well as the size. The outgoing queue should be uneffected.
+ Buffer buf1;
+ buf1.resize(112);
+ que.pushin(&buf1);
+ if ((que.size() == 2) && (que.outsize() == 1)) {
+ runtest.pass ("Handler::pushin(Buffer *)");
+ } else {
+ runtest.fail ("Handler::pushin(Buffer *)");
+ }
+
+ // Nuke the array
+ que.clearall();
+ if ((que.size() == 0) && (que.outsize() == 0)) {
+ runtest.pass ("Handler::clearall()");
+ } else {
+ runtest.fail ("Handler::clearall()");
+ }
+
+ // populate the buffer
+ boost::uint8_t *ptr = buf.reference();
+ for (size_t i=1; i< buf.size(); i++) {
+ ptr[i] = i;
+ }
+
+ que.push(&buf);
+ Buffer *buf2 = que.peek();
+ if ((buf2 == &buf) && (que.size() == 1)) {
+ runtest.pass ("Handler::peek()");
+ } else {
+ runtest.fail ("Handler::peek()");
+ }
+
+ Buffer *buf3 = que.peek();
+ if ((buf3 == &buf) && (que.size() == 1)) {
+ runtest.pass ("Handler::pop()");
+ } else {
+ runtest.fail ("Handler::pop()");
+ }
+
+// que.dump();
+}
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash/cygnal ChangeLog buffer.h buffer.cpp hand...,
Rob Savoye <=