gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash libbase/shm.cpp libbase/gmemory.h libbase...


From: Rob Savoye
Subject: [Gnash-commit] gnash libbase/shm.cpp libbase/gmemory.h libbase...
Date: Fri, 11 Apr 2008 19:02:36 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Rob Savoye <rsavoye>    08/04/11 19:02:36

Modified files:
        libbase        : shm.cpp gmemory.h memory.cpp 
        .              : ChangeLog 
        libamf         : amf.cpp amf.h buffer.cpp buffer.h element.cpp 
                         element.h lcshm.cpp 
        testsuite/libamf.all: test_buffer.cpp test_el.cpp test_lc.cpp 
                              test_sol.cpp 

Log message:
                * libamf/buffer.{h,cpp}: Cleanup minor bugs found by newly
                expanded test case. Rename empty() to clear().
                * libamf/amf.cpp: Don't take 1 off the end of the string. 
Comment
                out some stuff that will be deleted later, it's been moved to 
the
                Element class.
                * libamf/element.cpp: Add makeNumber that takes a variable name.
                * testsuite/libamf.all/test_buffer.cpp: Add many new tests for 
all
                methods. This makes it much easier to more thoroughly test for
                memory problems.
                * testsuite/libamf.all/test_lc.cpp: Clean up error handling.
                * libbase/shm.cpp: Handle permission errors better.
                * libbase/gmemory.h, memory.cpp: Use size_t instead of int.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/shm.cpp?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/gmemory.h?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/memory.cpp?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6260&r2=1.6261
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/amf.cpp?cvsroot=gnash&r1=1.69&r2=1.70
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/amf.h?cvsroot=gnash&r1=1.37&r2=1.38
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/buffer.cpp?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/buffer.h?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.cpp?cvsroot=gnash&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.h?cvsroot=gnash&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/lcshm.cpp?cvsroot=gnash&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libamf.all/test_buffer.cpp?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libamf.all/test_el.cpp?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libamf.all/test_lc.cpp?cvsroot=gnash&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libamf.all/test_sol.cpp?cvsroot=gnash&r1=1.11&r2=1.12

Patches:
Index: libbase/shm.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/shm.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- libbase/shm.cpp     22 Mar 2008 02:33:38 -0000      1.7
+++ libbase/shm.cpp     11 Apr 2008 19:02:33 -0000      1.8
@@ -214,7 +214,11 @@
     
     filespec = "default";      // this is unused for sysv memory segments
     _shmfd = shmget(_shmkey, _size, shmflg);
-    if (_shmfd < 0 && errno == EEXIST)
+    if (_shmfd <= 0 && errno == EACCES) {
+       log_error("You don't have the proper permisisons to access shared 
memory");
+       return false;
+    }
+    if (_shmfd <= 0 && errno == EEXIST)
 # else
 #  ifdef __riscos__
     if (0)

Index: libbase/gmemory.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/gmemory.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- libbase/gmemory.h   28 Mar 2008 21:30:18 -0000      1.7
+++ libbase/gmemory.h   11 Apr 2008 19:02:33 -0000      1.8
@@ -48,7 +48,7 @@
         int fordblks; // total free space
     };
     Memory();
-    Memory(int size);
+    Memory(size_t size);
     ~Memory();
 
     // Start collecting statistics. This can effect performance

Index: libbase/memory.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/memory.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- libbase/memory.cpp  28 Mar 2008 21:30:19 -0000      1.5
+++ libbase/memory.cpp  11 Apr 2008 19:02:33 -0000      1.6
@@ -45,19 +45,19 @@
 Memory::Memory() 
     : _collecting(false),
       _info(0),
-      _size(0),
+      _size(DATALOG_SIZE),
       _index(0)
 {
 //    GNASH_REPORT_FUNCTION;
 }
 
 
-Memory::Memory(int size) 
+Memory::Memory(size_t size) 
     : _collecting(false)
 {
 //    GNASH_REPORT_FUNCTION;
     _size = size;
-    _info = new struct small_mallinfo[DATALOG_SIZE];
+    _info = new struct small_mallinfo[_size];
     reset();
 }
 
@@ -89,8 +89,8 @@
 //    GNASH_REPORT_FUNCTION;
     _collecting = true;
     if (_info == 0) {
-        log_debug("Allocating buffer for %d data samples", DATALOG_SIZE);
-        _info = new struct small_mallinfo[DATALOG_SIZE];
+        log_debug("Allocating buffer for %d data samples", _size);
+        _info = new struct small_mallinfo[_size];
         reset();
     }
 }
@@ -132,9 +132,10 @@
 {
 //    GNASH_REPORT_FUNCTION;
     struct mallinfo mal = mallinfo();
+    int yy = static_cast<int>(_size);
 
 //    dump(&mal);
-    if ((ptr) && (_index < DATALOG_SIZE)) {
+    if ((ptr) && (_index < yy)) {
        ptr->line = line;
        clock_gettime (CLOCK_REALTIME, &ptr->stamp);
         ptr->arena = mal.arena;
@@ -171,7 +172,8 @@
 Memory::diffStats(int x, int y)
 {
 //    GNASH_REPORT_FUNCTION;
-    if ((_info) && (x < DATALOG_SIZE) && (y < DATALOG_SIZE)) {
+    int yy = static_cast<int>(_size);
+    if ((_info) && (x < DATALOG_SIZE) && (y < yy)) {
         return (_info[x].uordblks - _info[y].uordblks);
     }
     return -1;
@@ -189,7 +191,8 @@
 Memory::diffStamp(int x, int y)
 {
 //    GNASH_REPORT_FUNCTION;
-    if ((_info) && (x < DATALOG_SIZE) && (y < DATALOG_SIZE)) {
+    int yy = static_cast<int>(_size);
+    if ((_info) && (x < DATALOG_SIZE) && (y < yy)) {
         return (_info[x].stamp.tv_nsec - _info[y].stamp.tv_nsec);
     }
     return -1;
@@ -220,7 +223,7 @@
         for (int i=1; i<_index; i++) {
             struct small_mallinfo *ptr = _info + i;
 
-           // Get the time stamp
+//         // Get the time stamp
             int diff_stamp_sec = (ptr->stamp.tv_sec) - (ptr - 1)->stamp.tv_sec;
             int diff_stamp_nsec = (ptr->stamp.tv_nsec) - (ptr - 
1)->stamp.tv_nsec;
 //             if ((diff_stamp_sec > 0) || (diff_stamp_nsec > 0)) {

Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6260
retrieving revision 1.6261
diff -u -b -r1.6260 -r1.6261
--- ChangeLog   11 Apr 2008 18:30:46 -0000      1.6260
+++ ChangeLog   11 Apr 2008 19:02:33 -0000      1.6261
@@ -1,3 +1,18 @@
+2008-04-11  Rob Savoye  <address@hidden>
+
+       * libamf/buffer.{h,cpp}: Cleanup minor bugs found by newly
+       expanded test case. Rename empty() to clear().
+       * libamf/amf.cpp: Don't take 1 off the end of the string. Comment
+       out some stuff that will be deleted later, it's been moved to the
+       Element class.
+       * libamf/element.cpp: Add makeNumber that takes a variable name.
+       * testsuite/libamf.all/test_buffer.cpp: Add many new tests for all
+       methods. This makes it much easier to more thoroughly test for
+       memory problems.
+       * testsuite/libamf.all/test_lc.cpp: Clean up error handling.
+       * libbase/shm.cpp: Handle permission errors better.
+       * libbase/gmemory.h, memory.cpp: Use size_t instead of int.
+
 2008-04-11 Sandro Santilli <address@hidden>
 
        * server/button_character_instance.cpp (add_invalidated_bounds):
@@ -355,7 +370,7 @@
        singular interators. Not this fixes the abort, but leaks memory as
        the original buffers aren't removed from the que like they need to
        be. This at least get make check working for libnet.all.
-       * testsuite/libamf.all/test_sol.cpp: Don't ehck the bogus data for
+       * testsuite/libamf.all/test_sol.cpp: Don't check the bogus data for
        default camera.
 
 2008-04-07 Sandro Santilli <address@hidden>

Index: libamf/amf.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/amf.cpp,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -b -r1.69 -r1.70
--- libamf/amf.cpp      6 Apr 2008 18:11:33 -0000       1.69
+++ libamf/amf.cpp      11 Apr 2008 19:02:34 -0000      1.70
@@ -530,7 +530,7 @@
     // it can be printed by to_string() efficiently. The NULL terminator
     // doesn't get written when encoding a string as it has a byte count
     // instead.
-    length = str.size() - 1;
+    length = str.size();
     log_debug("Encoded data size is going to be %d", length);
     swapBytes(&length, 2);
     buf->append(length);
@@ -711,145 +711,170 @@
 }
 #endif
 
-#if 0
-AMF::astype_e
-AMF::extractElementHeader(void *in)
-{
-//    GNASH_REPORT_FUNCTION;
+// #if 0
+// AMF::astype_e
+// AMF::extractElementHeader(void *in)
+// {
+// //    GNASH_REPORT_FUNCTION;
 
-    return (AMF::astype_e)*(char *)in;
-}
+//     return (AMF::astype_e)*(char *)in;
+// }
 
-int
-AMF::extractElementLength(void *in)
-{
-//    GNASH_REPORT_FUNCTION;
+// int
+// AMF::extractElementLength(void *in)
+// {
+// //    GNASH_REPORT_FUNCTION;
 
-    char *x = (char *)in;
-    Element::astype_e type = (Element::astype_e)*x;
-    x++;                        // skip the header byte
+//     char *x = (char *)in;
+//     Element::astype_e type = (Element::astype_e)*x;
+//     x++;                        // skip the header byte
+    
+//     switch (type) {
+//       case Element::NUMBER:              // a 64 bit numeric value
+//           return AMF_NUMBER_SIZE;
+//           break;
+//       case Element::BOOLEAN:             // a single byte
+//           return sizeof(bool);
+//           break;
+//       case Element::STRING:              // the length is a 2 byte value
+//             //FIXME, there are all kinds of byte order problems in this 
code.
+//           return (short)*(short *)x;
+//           break;
+//       case Element::OBJECT:
+//           return x - strchr(x, TERMINATOR);
+//           break;
+//       case Element::MOVIECLIP:
+//           return -1;
+//           log_unimpl("MovieClip AMF extractor");
+//           break;
+//       case Element::NULL_VALUE: 
+//           return -1;
+//           log_unimpl("Null AMF extractor");
+//           break;
+//       case Element::UNDEFINED:
+//           return 0;
+//           break;
+//       case Element::REFERENCE:
+//           return -1;
+//           log_unimpl("Reference AMF extractor");
+//           break;
+//       case Element::ECMA_ARRAY:
+//           return x - strchr(x, TERMINATOR);
+//           break;
+//       case Element::OBJECT_END:
+//           return -1;
+//           log_unimpl("ObjectEnd AMF extractor");
+//           break;
+//       case Element::STRICT_ARRAY:         // the length is a 4 byte value
+// //          return (int *)x;
+//           break;
+//       case Element::DATE:              // a 64 bit numeric value
+//           return 8;
+//           break;
+//       case Element::LONG_STRING:
+//           return -1;
+//           log_unimpl("LongString AMF extractor");
+//           break;
+//       case Element::UNSUPPORTED:
+//           return -1;
+//           log_unimpl("Unsupported AMF extractor");
+//           break;
+//       case Element::RECORD_SET:
+//           return -1;
+//           log_unimpl("Recordset AMF extractor");
+//           break;
+//       case Element::XML_OBJECT:           // the length is a 4 byte value
+// //          return (int)*(int *)x;
+//           break;
+//       case Element::TYPED_OBJECT:
+//           return x - strchr(x, TERMINATOR);
+//           break;
+//     };
     
-    switch (type) {
-      case Element::NUMBER:              // a 64 bit numeric value
-          return AMF_NUMBER_SIZE;
-          break;
-      case Element::BOOLEAN:             // a single byte
-          return sizeof(bool);
-          break;
-      case Element::STRING:              // the length is a 2 byte value
-               //FIXME, there are all kinds of byte order problems in this 
code.
-          return (short)*(short *)x;
-          break;
-      case Element::OBJECT:
-          return x - strchr(x, TERMINATOR);
-          break;
-      case Element::MOVIECLIP:
-          return -1;
-          log_unimpl("MovieClip AMF extractor");
-          break;
-      case Element::NULL_VALUE: 
-          return -1;
-          log_unimpl("Null AMF extractor");
-          break;
-      case Element::UNDEFINED:
-          return 0;
-          break;
-      case Element::REFERENCE:
-          return -1;
-          log_unimpl("Reference AMF extractor");
-          break;
-      case Element::ECMA_ARRAY:
-          return x - strchr(x, TERMINATOR);
-          break;
-      case Element::OBJECT_END:
-          return -1;
-          log_unimpl("ObjectEnd AMF extractor");
-          break;
-      case Element::STRICT_ARRAY:         // the length is a 4 byte value
-//          return (int *)x;
-          break;
-      case Element::DATE:              // a 64 bit numeric value
-          return 8;
-          break;
-      case Element::LONG_STRING:
-          return -1;
-          log_unimpl("LongString AMF extractor");
-          break;
-      case Element::UNSUPPORTED:
-          return -1;
-          log_unimpl("Unsupported AMF extractor");
-          break;
-      case Element::RECORD_SET:
-          return -1;
-          log_unimpl("Recordset AMF extractor");
-          break;
-      case Element::XML_OBJECT:           // the length is a 4 byte value
-//          return (int)*(int *)x;
-          break;
-      case Element::TYPED_OBJECT:
-          return x - strchr(x, TERMINATOR);
-          break;
-    };
+//     return 0;
+// }
     
-    return 0;
-}
+// char *
+// AMF::extractString(const Network::byte_t *in)
+// {
+// //    GNASH_REPORT_FUNCTION;
+//     boost::int8_t *buf = NULL;
+//     Network::byte_t *x = const_cast<Network::byte_t *>(in);
 
-char *
-AMF::extractString(const Network::byte_t *in)
-{
-//    GNASH_REPORT_FUNCTION;
-    boost::int8_t *buf = NULL;
-    Network::byte_t *x = const_cast<Network::byte_t *>(in);
+//     if (*x == Element::STRING) {
+//         x++;
+//         short length = *(reinterpret_cast<const short *>(x));
+//         swapBytes(&length, 2);
+//     log_debug("Encoded length of string: %hd", length);
+//         x += sizeof(short);
+//         buf = new int8_t[length+1];
+//         memset(buf, 0, length+1);
+//         memcpy(buf, x, length); /* x is not long enough */
+//     } else {
+//         log_error("Tried to extract AMF string from non String object!");
+//     }
     
-    if (*x == Element::STRING) {
-        x++;
-        short length = *(reinterpret_cast<const short *>(x));
-        swapBytes(&length, 2);
-       log_debug("Encoded length of string: %hd", length);
-        x += sizeof(short);
-        buf = new int8_t[length+1];
-        memset(buf, 0, length+1);
-        memcpy(buf, x, length); /* x is not long enough */
-    } else {
-        log_error("Tried to extract AMF string from non String object!");
-    }
+//     return reinterpret_cast<char *>(buf);
+// }
     
-    return reinterpret_cast<char *>(buf);
-}
+// double
+// AMF::extractNumber(const Network::byte_t *in)
+// {
+// //    GNASH_REPORT_FUNCTION;    
+//     Network::byte_t *x = const_cast<uint8_t *>(in);
+// //    double *num = new double;
+//     double num = 0.0;
+// //    memset(num, 0, AMF_NUMBER_SIZE);
+    
+//     if (*x == Element::NUMBER) {
+//         x++;
+//         memcpy(&num, x, AMF_NUMBER_SIZE);
+//         swapBytes(&num, AMF_NUMBER_SIZE);
+//     } else {
+//         log_error("Tried to extract AMF Number from non Number object!");
+//     }
 
-double
-AMF::extractNumber(const Network::byte_t *in)
-{
-//    GNASH_REPORT_FUNCTION;    
-    Network::byte_t *x = const_cast<uint8_t *>(in);
-//    double *num = new double;
-    double num = 0.0;
-//    memset(num, 0, AMF_NUMBER_SIZE);
-    
-    if (*x == Element::NUMBER) {
-        x++;
-        memcpy(&num, x, AMF_NUMBER_SIZE);
-        swapBytes(&num, AMF_NUMBER_SIZE);
-    } else {
-        log_error("Tried to extract AMF Number from non Number object!");
-    }
+//     return num;
+// }
 
-    return num;
-}
+// Element &
+// AMF::createElement(amf_element_t *el, astype_e type,
+//               const std::string &name, Network::byte_t *data, int nbytes)
+// {
+// //    GNASH_REPORT_FUNCTION;
+//     log_debug("Creating element %s", name.c_str());
 
-Element &
-AMF::createElement(amf_element_t *el, astype_e type,
-                 const std::string &name, Network::byte_t *data, int nbytes)
-{
-//    GNASH_REPORT_FUNCTION;
-    log_debug("Creating element %s", name.c_str());
+//     el->type = type;
+//     el->name = name;
+//     el->length = nbytes;
+//     el->data = data;
+//     return el;
+// }
     
-    el->type = type;
-    el->name = name;
-    el->length = nbytes;
-    el->data = data;
-    return el;
-}
+// // AMF::amf_element_t *
+// // AMF::createElement(amf_element_t *el, const char *name, double data)
+// // {
+// // //    GNASH_REPORT_FUNCTION;
+// //     string str = name;
+// //     return createElement(el, str, data);
+// // }
+
+// // AMF::amf_element_t *
+// // AMF::createElement(amf_element_t *el, const std::string &name, double 
data)
+// // {
+// // //    GNASH_REPORT_FUNCTION;
+// //     log_debug("Creating element %s", name.c_str());
+
+// //     el->type = AMF::NUMBER;
+// //     el->name = name;
+// //     el->length = AMF_NUMBER_SIZE;
+// // //    char *numptr = (char *)&data;
+// //     el->data = new Network::byte_t[AMF_NUMBER_SIZE + 1];
+// //     memset(el->data, 0, AMF_NUMBER_SIZE + 1);
+// //     memcpy(el->data, &data, AMF_NUMBER_SIZE);
+
+// //     return el;
+// // }
 
 // AMF::amf_element_t *
 // AMF::createElement(amf_element_t *el, const char *name, double data)
@@ -876,83 +901,58 @@
 //     return el;
 // }
 
-AMF::amf_element_t *
-AMF::createElement(amf_element_t *el, const char *name, double data)
-{
-//    GNASH_REPORT_FUNCTION;
-    string str = name;
-    return createElement(el, str, data);
-}
-
-AMF::amf_element_t *
-AMF::createElement(amf_element_t *el, const std::string &name, double data)
-{
-//    GNASH_REPORT_FUNCTION;
-    log_debug("Creating element %s", name.c_str());
-
-    el->type = AMF::NUMBER;
-    el->name = name;
-    el->length = AMF_NUMBER_SIZE;
-//    char *numptr = (char *)&data;
-    el->data = new Network::byte_t[AMF_NUMBER_SIZE + 1];
-    memset(el->data, 0, AMF_NUMBER_SIZE + 1);
-    memcpy(el->data, &data, AMF_NUMBER_SIZE);
-
-    return el;
-}
-
-AMF::amf_element_t *
-AMF::createElement(amf_element_t *el, const char *name, const char *data)
-{
-//    GNASH_REPORT_FUNCTION;
-    log_debug("Creating element %s", name);
+// AMF::amf_element_t *
+// AMF::createElement(amf_element_t *el, const char *name, const char *data)
+// {
+// //    GNASH_REPORT_FUNCTION;
+//     log_debug("Creating element %s", name);
 
-    el->type = AMF::STRING;
-    el->name = name;
-    el->length = strlen(data);
-    char *str = const_cast<char *>(data);
-    el->data = reinterpret_cast<Network::byte_t *>(str);
-    return el;
-}
+//     el->type = AMF::STRING;
+//     el->name = name;
+//     el->length = strlen(data);
+//     char *str = const_cast<char *>(data);
+//     el->data = reinterpret_cast<Network::byte_t *>(str);
+//     return el;
+// }
 
-AMF::amf_element_t *
-AMF::createElement(amf_element_t *el, const std::string &name, std::string 
&data)
-{
-//    GNASH_REPORT_FUNCTION;
-    log_debug("Creating element %s", name.c_str());
+// AMF::amf_element_t *
+// AMF::createElement(amf_element_t *el, const std::string &name, std::string 
&data)
+// {
+// //    GNASH_REPORT_FUNCTION;
+//     log_debug("Creating element %s", name.c_str());
 
-    el->type = AMF::STRING;
-    el->name = name;
-    el->length = data.size();
-    char *str = const_cast<char *>(data.c_str());
-    el->data = reinterpret_cast<Network::byte_t *>(str);
-    return el;
-}
+//     el->type = AMF::STRING;
+//     el->name = name;
+//     el->length = data.size();
+//     char *str = const_cast<char *>(data.c_str());
+//     el->data = reinterpret_cast<Network::byte_t *>(str);
+//     return el;
+// }
 
-AMF::amf_element_t *
-AMF::createElement(amf_element_t *el, const char *name, bool data)
-{
-//    GNASH_REPORT_FUNCTION;
-    string str = name;
-    return createElement(el, str, data);
-}
+// AMF::amf_element_t *
+// AMF::createElement(amf_element_t *el, const char *name, bool data)
+// {
+// //    GNASH_REPORT_FUNCTION;
+//     string str = name;
+//     return createElement(el, str, data);
+// }
 
-AMF::amf_element_t *
-AMF::createElement(AMF::amf_element_t *el, const std::string &name, bool data)
-{
-//    GNASH_REPORT_FUNCTION;
-    log_debug("Creating element %s", name.c_str());
+// AMF::amf_element_t *
+// AMF::createElement(AMF::amf_element_t *el, const std::string &name, bool 
data)
+// {
+// //    GNASH_REPORT_FUNCTION;
+//     log_debug("Creating element %s", name.c_str());
 
-    el->type = AMF::BOOLEAN;
-    el->name = name;
-    el->length = 1;
-    el->data = new Network::byte_t[sizeof(uint16_t)];
-    memset(el->data, 0, sizeof(uint16_t));
-    *el->data = data;
-    return el;
-}
+//     el->type = AMF::BOOLEAN;
+//     el->name = name;
+//     el->length = 1;
+//     el->data = new Network::byte_t[sizeof(uint16_t)];
+//     memset(el->data, 0, sizeof(uint16_t));
+//     *el->data = data;
+//     return el;
+// }
 
-#endif
+// #endif
 
 Buffer *
 AMF::encodeVariable(amf::Element *el)
@@ -962,6 +962,7 @@
     size_t outsize = el->getNameSize() + el->getLength() + AMF_VAR_HEADER_SIZE;
 
     Buffer *buf = new Buffer(outsize);
+    _totalsize += outsize;
 //     Network::byte_t *out = new Network::byte_t[outsize + 4]; // why +4 here 
?
 //     Network::byte_t *end = out + outsize+4; // why +4 ?
 
@@ -974,7 +975,10 @@
     swapBytes(&enclength, 2);
     buf->copy(enclength);
 
-    buf->append(el->getName());
+    string xxx = el->getName();        // FIXME: stupid name
+    if (xxx.size() > 0) {
+       buf->append(xxx);
+    }
     // Add the type of the variable's data
     buf->append(el->getType());
     // Booleans appear to be encoded weird. Just a short after

Index: libamf/amf.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/amf.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- libamf/amf.h        5 Apr 2008 20:39:39 -0000       1.37
+++ libamf/amf.h        11 Apr 2008 19:02:34 -0000      1.38
@@ -244,7 +244,7 @@
     ///         in form of a newly allocated byte array.
     ///         to be deleted by caller using delete [] operator, or NULL
     ///
-    static Buffer *encodeVariable(amf::Element *el);
+    Buffer *encodeVariable(amf::Element *el);
     
     //
     // Methods for extracting data from big endian formatted raw AMF data.

Index: libamf/buffer.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/buffer.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- libamf/buffer.cpp   5 Apr 2008 20:39:39 -0000       1.2
+++ libamf/buffer.cpp   11 Apr 2008 19:02:35 -0000      1.3
@@ -37,7 +37,7 @@
         _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();
+//        clear();
     }
 
 #ifdef USE_STATS_BUFFERS
@@ -93,7 +93,7 @@
 }
 
 void
-Buffer::copy(string &str)
+Buffer::copy(const string &str)
 {    
 //    GNASH_REPORT_FUNCTION;
     std::copy(str.begin(), str.end(), _ptr);
@@ -112,8 +112,10 @@
 Buffer::append(boost::uint16_t length)
 {
 //    GNASH_REPORT_FUNCTION;
-    if ((_seekptr + length) <= (_ptr + _nbytes)) {
-       std::copy(&length, &length + sizeof(boost::uint16_t), _seekptr);
+    
+    if ((_seekptr + sizeof(boost::uint16_t)) <= (_ptr + _nbytes)) {
+       Network::byte_t *data = reinterpret_cast<Network::byte_t *>(&length);
+       std::copy(data, data + sizeof(boost::uint16_t), _seekptr);
        _seekptr += sizeof(boost::uint16_t);
        return _seekptr;
     }
@@ -199,16 +201,94 @@
     return append(static_cast<Network::byte_t>(type));
 }
 
+Network::byte_t *
+Buffer::append(Buffer &buf)
+{
+//    GNASH_REPORT_FUNCTION;
+    if (buf.size() > _nbytes) {
+         resize(buf.size());
+    }
+    
+    if ((_seekptr + buf.size()) <= (_ptr + _nbytes)) {
+       std::copy(buf.begin(), buf.end(), _seekptr);
+       _seekptr += buf.size();
+    }
+    return _seekptr;
+}
+
+Network::byte_t *
+Buffer::append(Buffer *buf)
+{
+//    GNASH_REPORT_FUNCTION;
+    if (buf->size() >= _nbytes) {
+         resize(buf->size());
+    }
+    
+    if ((_seekptr + buf->size()) <= (_ptr + _nbytes)) {
+       std::copy(buf->begin(), buf->end(), _seekptr);
+       _seekptr += buf->size();
+    }
+    return _seekptr;
+}
+
+// make ourselves be able to appended too. If the source
+// buffer is larger than the current buffer has room for,
+// resize ourselves (which copies the data too) to make
+// enough room.
+// note that using this may have a performance hit due to
+// the resize operation, which has to copy data.
+Buffer &
+Buffer::operator+=(Buffer &buf)
+{
+    return operator+=(&buf);
+}
+
+Buffer &
+Buffer::operator+=(Buffer *buf)
+{
+//    GNASH_REPORT_FUNCTION;
+    size_t diff = 0;
+    if (buf->size() >= _nbytes) {
+       diff = _seekptr - _ptr;
+       resize(buf->size() + diff);
+    }
+    
+    if ((_seekptr + buf->size()) <= (_ptr + _nbytes)) {
+       std::copy(buf->begin(), buf->end(), _seekptr);
+       _seekptr += buf->size();
+    }
+    return *this;
+}
+
+Buffer &
+Buffer::operator+=(char byte)
+{
+//    GNASH_REPORT_FUNCTION;
+    return operator+=(static_cast<Network::byte_t>(byte));
+}
+
+Buffer &
+Buffer::operator+=(Network::byte_t byte)
+{
+//    GNASH_REPORT_FUNCTION;
+    if ((_seekptr + 1) <= (_ptr + _nbytes)) {
+       *_seekptr = byte;
+       _seekptr += sizeof(char);
+    }
+    return *this;
+}
+
 // make ourselves be able to be copied.
 Buffer &
 Buffer::operator=(Buffer *buf)
 {
 //    GNASH_REPORT_FUNCTION;
-    if (buf->size() != _nbytes) {
+    if (buf->size() > _nbytes) {
          resize(buf->size());
     }
     
-    std::copy(buf->reference(), buf->reference() + _nbytes, _ptr);
+    std::copy(buf->begin(), buf->end(), _ptr);
+    _seekptr += buf->size();
 
     return *this;
 }
@@ -221,7 +301,7 @@
          resize(buf.size());
     }
     
-    std::copy(buf.reference(), buf.reference() + _nbytes, _ptr);
+    std::copy(buf.begin(), buf.end(), _ptr);
 
     return *this;
 }
@@ -231,8 +311,9 @@
 Buffer::operator==(Buffer *buf)
 { 
 //    GNASH_REPORT_FUNCTION;
+    Network::byte_t *bufptr = buf->reference();
    if (buf->size() == _nbytes) {
-        if (memcmp(buf->reference(), _ptr, _nbytes) == 0)  {
+        if (memcmp(bufptr, _ptr, _nbytes) == 0)  {
             return true;
         }
     }
@@ -243,54 +324,47 @@
 Buffer::operator==(Buffer &buf)
 {
 //    GNASH_REPORT_FUNCTION;
-    if (buf.size() == _nbytes){
-        if (memcmp(buf.reference(), _ptr, _nbytes) == 0)  {
-            return true;
-        }
-    }
-    return false;
+//     Network::byte_t *bufptr = buf.reference();
+//     size_t max = 0;
+    
+//     if (buf.size() == _nbytes){
+//         if (memcmp(bufptr, _ptr, _nbytes) == 0) {
+//             return true;
+//         }
+//     }
+//     return false;
+    return operator==(&buf);
 }
 
 Network::byte_t *
-Buffer::find(Network::byte_t b, size_t start)
+Buffer::find(Network::byte_t *b, size_t size)
 {
-    GNASH_REPORT_FUNCTION;
-    for (size_t i=start; i< _nbytes; i++) {
-       if ( *(_ptr + i) == b) {
+//    GNASH_REPORT_FUNCTION;
+    for (size_t i=0; i< _nbytes; i++) {
+       if (memcmp((_ptr + i), b, size) == 0) {
            return _ptr + i;
        }
     }
     return 0;
 }
 
-// Find a byte in the buffer
-// Network::byte_t *
-// Buffer::find(char c)
-// {
-// //    GNASH_REPORT_FUNCTION;
-//     return find(static_cast<Network::byte_t>(c), 0);
-// }
-
 Network::byte_t *
 Buffer::find(Network::byte_t c)
 {
 //    GNASH_REPORT_FUNCTION;
-    return find(static_cast<Network::byte_t>(c), 0);
+    for (size_t i=0; i< _nbytes; i++) {
+       if (*(_ptr + i) == c) {
+           return _ptr + i;
+       }
+    }
+    return 0;
 }   
 
-// // Drop a character or range of characters without resizing
-// Network::byte_t
-// Buffer::remove(char c)
-// {
-// //    GNASH_REPORT_FUNCTION;
-//     return remove(reinterpret_cast<Network::byte_t>(c));
-// }
-
 Network::byte_t *
 Buffer::remove(Network::byte_t c)
 {
-    GNASH_REPORT_FUNCTION;
-    Network::byte_t *start = find(c, 0);
+//    GNASH_REPORT_FUNCTION;
+    Network::byte_t *start = find(c);
     log_debug("FRAME MARK is at %x", (void *)start);
     if (start == 0) {
        return 0;
@@ -325,12 +399,13 @@
 
 // Just reset to having no data, but still having storage
 void
-Buffer::empty()
+Buffer::clear()
 {
 //    GNASH_REPORT_FUNCTION;
     if (_ptr) {
         memset(_ptr, 0, _nbytes);
     }
+    _seekptr = _ptr;
 }
 
 // Resize the buffer that holds the data
@@ -339,6 +414,7 @@
 {
 //    GNASH_REPORT_FUNCTION;
     // Allocate a new memory block
+    size_t diff = _seekptr - _ptr;
     Network::byte_t *tmp = new Network::byte_t[nbytes];
     // And copy ourselves into it
     if (nbytes > _nbytes) {
@@ -357,6 +433,9 @@
     // Make the memeory block use the new space
     _ptr = tmp;
 
+    // reset the seek pointer to point into this block
+    _seekptr = _ptr + diff;
+
     return tmp;
 }
 

Index: libamf/buffer.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/buffer.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- libamf/buffer.h     3 Apr 2008 11:05:01 -0000       1.2
+++ libamf/buffer.h     11 Apr 2008 19:02:35 -0000      1.3
@@ -41,7 +41,8 @@
     
     // Delete the allocate memory
     ~Buffer();
-    void empty();
+    void clear();
+    bool empty() { return (_nbytes)?true:false; };
 
     // Resize the buffer that holds the data
     void *resize(size_t nbytes);
@@ -49,7 +50,7 @@
     // Put data into the buffer. This overwrites all data, and resets the seek 
ptr.
     void copy(gnash::Network::byte_t *data, size_t nbytes);
     void copy(gnash::Network::byte_t *data) { copy(data, _nbytes); };
-    void copy(std::string &str);
+    void copy(const std::string &str);
     void copy(boost::uint16_t length);
 //     void copy(boost::uint32_t val);
 //     void copy(bool);
@@ -58,6 +59,8 @@
 
     // Append data to the existing data in the buffer. This assume the
     // buffer has been sized to hold the data as it is appended.
+    gnash::Network::byte_t *append(Buffer *buf);
+    gnash::Network::byte_t *append(Buffer &buf);
     gnash::Network::byte_t *append(boost::uint32_t val);
     gnash::Network::byte_t *append(bool);
     gnash::Network::byte_t *append(double num);
@@ -70,7 +73,7 @@
     // Find a byte in the buffer
 //    Network::byte_t *find(char c);
     gnash::Network::byte_t *find(gnash::Network::byte_t b);
-    gnash::Network::byte_t *find(gnash::Network::byte_t b, size_t start);
+    gnash::Network::byte_t *find(gnash::Network::byte_t *b, size_t size);
     
     // Drop a byte or range of characters without resizing
 //    Network::byte_t *remove(char c);
@@ -92,6 +95,10 @@
     // Test against other buffers
     bool operator==(Buffer *buf);
     bool operator==(Buffer &buf);
+    Buffer &operator+=(Buffer *buf);
+    Buffer &operator+=(gnash::Network::byte_t byte);
+    Buffer &operator+=(char byte);
+    Buffer &operator+=(Buffer &buf);
     gnash::Network::byte_t operator[](int x) { return *(_ptr + x); };
     gnash::Network::byte_t *at(int x) { return _ptr + x; };
 

Index: libamf/element.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- libamf/element.cpp  7 Apr 2008 19:35:11 -0000       1.17
+++ libamf/element.cpp  11 Apr 2008 19:02:35 -0000      1.18
@@ -429,6 +429,7 @@
 Element &
 Element::makeNumber(double num)
 {
+//    GNASH_REPORT_FUNCTION;
     _type = Element::NUMBER;
     _buffer = new Buffer(AMF_NUMBER_SIZE);
     _buffer->append(num);
@@ -437,6 +438,16 @@
 }
 
 Element &
+Element::makeNumber(const string &name, double num)
+{
+//    GNASH_REPORT_FUNCTION;
+    if (name.size()) {
+        setName(name);
+    }
+    return makeNumber(num);
+}
+
+Element &
 Element::makeBoolean(bool flag)
 {
 //    GNASH_REPORT_FUNCTION;

Index: libamf/element.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- libamf/element.h    5 Apr 2008 20:39:39 -0000       1.14
+++ libamf/element.h    11 Apr 2008 19:02:35 -0000      1.15
@@ -75,7 +75,7 @@
     Element &init(std::vector<double> &data);
     Element &init(const std::string &name, const std::string &data);
     Element &init(const std::string &data);
-    Element & init(const std::string &name, bool data);
+    Element &init(const std::string &name, bool data);
     Element &init(bool data);
     // Create a function block for AMF
     Element &init(bool, double, double, const std::string &str);
@@ -139,15 +139,17 @@
     void setName(const std::string &name);
     void setName(gnash::Network::byte_t *name, size_t x);
 
+    // Manipulate the children Elements of an object
     void addChild(Element *el) { _children.push_back(el); };
     Element *popChild() { return _children.front(); };
-    void dump();
+    size_t childrenSize() { return _children.size(); };
     
+    void dump();
 private:
     char               *_name;
     Buffer             *_buffer;
-    std::vector<Element        *> _children;
     amf_type_e         _type;
+    std::vector<Element        *> _children;
 };                              // end of class definition
 
 

Index: libamf/lcshm.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/lcshm.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- libamf/lcshm.cpp    1 Apr 2008 22:20:41 -0000       1.11
+++ libamf/lcshm.cpp    11 Apr 2008 19:02:35 -0000      1.12
@@ -295,6 +295,11 @@
 //    GNASH_REPORT_FUNCTION;
     Network::byte_t *ptr = data;
     
+    if (data == 0) {
+        log_debug("No data pointer to parse!");
+        return 0;
+    }
+    
     memcpy(&_header, ptr, LC_HEADER_SIZE);
 //     memcpy(&_object, data + LC_HEADER_SIZE, _header.length);
 //    log_debug("Timestamp: %d", _header.timestamp);

Index: testsuite/libamf.all/test_buffer.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libamf.all/test_buffer.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- testsuite/libamf.all/test_buffer.cpp        1 Apr 2008 22:18:46 -0000       
1.1
+++ testsuite/libamf.all/test_buffer.cpp        11 Apr 2008 19:02:35 -0000      
1.2
@@ -36,30 +36,97 @@
 #endif
 
 #include "log.h"
+#include "rc.h"
 #include "network.h"
 #include "gmemory.h"
 #include "buffer.h"
+#include "arg_parser.h"
 
 using namespace std;
 using namespace amf;
 using namespace gnash;
 using namespace boost;
 
+static void usage();
+
+// Prototypes for test cases
+static void test_construct();
+static void test_copy();
+static void test_find();
+static void test_append();
+static void test_remove();
+static void test_destruct();
+static void test_operators();
+
+// Enable the display of memory allocation and timing data
+static bool memdebug = false;
+
 TestState runtest;
 LogFile& dbglogfile = LogFile::getDefaultInstance();
+RcInitFile& rcfile = RcInitFile::getDefaultInstance();
 
 int
-main (int /*argc*/, char** /*argv*/) {
-    gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
+main (int argc, char** argv)
+{
+    const Arg_parser::Option opts[] =
+        {
+            { 'h', "help",          Arg_parser::no  },
+            { 'v', "verbose",       Arg_parser::no  },
+            { 'w', "write",         Arg_parser::no  },
+            { 'm', "memstats",      Arg_parser::no  },
+            { 'd', "dump",          Arg_parser::no  },
+        };
+    
+    Arg_parser parser(argc, argv, opts);
+    if( ! parser.error().empty() ) {
+        cout << parser.error() << endl;
+        exit(EXIT_FAILURE);
+    }
+    
+    for( int i = 0; i < parser.arguments(); ++i ) {
+        const int code = parser.code(i);
+        try {
+            switch( code ) {
+              case 'h':
+                  usage ();
+                  exit(EXIT_SUCCESS);
+              case 'v':
     dbglogfile.setVerbosity();
+                    // This happens once per 'v' flag 
+                    log_debug(_("Verbose output turned on"));
+                    break;
+              case 'm':
+                    // This happens once per 'v' flag 
+                    log_debug(_("Enabling memory statistics"));
+                    memdebug = true;
+                    break;
+              case 'w':
+                  rcfile.useWriteLog(true); // dbglogfile.setWriteDisk(true);
+                  log_debug(_("Logging to disk enabled"));
+                  break;
+                  
+           }
+        }
+        
+        catch (Arg_parser::ArgParserException &e) {
+            cerr << _("Error parsing command line options: ") << e.what() << 
endl;
+            cerr << _("This is a Gnash bug.") << endl;
+        }
+    }
+    
     // 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();
+    Memory *mem = 0;
+    if (memdebug) {
+        mem = new Memory;
+        mem->startStats();
+    }
 
     Buffer buf;
-    mem.addStats(__LINE__);             // take a sample
+    if (memdebug) {
+        mem->addStats(__LINE__);             // take a sample
+    }
     
     if (buf.size() == gnash::NETBUFSIZE) {
          runtest.pass ("Buffer::size()");
@@ -67,46 +134,379 @@
          runtest.fail ("Buffer::size()");
     }
 
-    mem.addStats(__LINE__);             // take a sample
+    if (memdebug) {
+        mem->addStats(__LINE__);             // take a sample
+    }
     buf.resize(112);
-    mem.addStats(__LINE__);             // take a sample
+    if (memdebug) {
+        mem->addStats(__LINE__);             // take a sample
+    }
 
     if (buf.size() == 112) {
          runtest.pass ("Buffer::resize()");
      } else {
          runtest.fail ("Buffer::resize()");
     }
+    if (memdebug) {
+        mem->addStats(__LINE__);             // take a sample
+    }
+
+// amf::Buffer::empty()
+
+    // test creating Buffers
+    test_construct();
+    // test destroying Buffers
+    test_destruct();
+
+    test_copy();
+    test_find();
+    test_append();
+    test_remove();
+    test_operators();
+
+// amf::Buffer::resize(unsigned int)
+    
+    if (memdebug) {
+        mem->analyze();
+    }
+
+    // cleanup
+    if (mem) {
+        delete mem;
+    }
+}
+
+void
+test_copy()
+{
+    // Make some data for the buffers
+    Network::byte_t *data = 0;
+    data = new Network::byte_t[10];
+    memset(data, 0, 10);
+    for (size_t i=1; i<10; i++) {
+        *(data + i) = i + '0';
+    }
+
+    Buffer buf1;
+    Network::byte_t *ptr1 = 0;
+    ptr1 = buf1.reference();
+
+    buf1.copy(data, 10);
+    if (memcmp(ptr1, data, 10) == 0) {
+         runtest.pass ("Buffer::copy(Network::byte_t *, size_t)");
+    } else {
+         runtest.fail ("Buffer::copy(Network::byte_t *, size_t)");
+    }
+
+    const char *str = "I'm bored";
+    string str1 = str;
+    buf1.copy(str1);
+    if (memcmp(ptr1, str, 9) == 0) {
+         runtest.pass ("Buffer::copy(std::string &)");
+    } else {
+         runtest.fail ("Buffer::copy(std::string &)");
+    }
+
+    Buffer buf2;
+    buf2.copy(str);
+    Network::byte_t *ptr2 = buf2.reference();
+    if (memcmp(ptr2, str, 9) == 0) {
+         runtest.pass ("Buffer::copy(const char *)");
+    } else {
+         runtest.fail ("Buffer::copy(const char)");
+    }
+
+    boost::uint16_t length = 12;
+    Buffer buf3;
+    buf3.copy(length);
+    Network::byte_t *ptr3 = buf3.reference();
+    boost::uint16_t newlen = *(reinterpret_cast<boost::uint16_t *>(ptr3));
+    if (length == newlen) {
+         runtest.pass ("Buffer::copy(boost::uint16_t)");
+    } else {
+         runtest.fail ("Buffer::copy(boost::uint16_t)");
+    }
+}
+
+void
+test_find()
+{
+    // Make some data for the buffers
+    Network::byte_t *data = new Network::byte_t[10];
+    for (size_t i=0; i<10; i++) {
+        data[i] = i + 'a';
+    }
+
+    Buffer buf1, buf2, buf3;
+    Network::byte_t *ptr1 = buf1.reference();
+
+    // populate the buffer
+    buf1.copy(data, 10);
+
+    // See if we can find a character
+    Network::byte_t *fptr = buf1.find('c');
+    if (fptr == (ptr1 + 2)) {
+         runtest.pass ("Buffer::find(Network::byte_t)");
+    } else {
+         runtest.fail ("Buffer::find(Network::byte_t)");
+    }
+
+    char *sub = "fgh";
+    Network::byte_t *ptr2 = reinterpret_cast<Network::byte_t *>(sub);
+    fptr = buf1.find(ptr2, 3);
+    if (fptr == (ptr1 + 5)) {
+         runtest.pass ("Buffer::find(Network::byte_t *, size_t)");
+    } else {
+         runtest.fail ("Buffer::find(Network::byte_t *, size_t)");
+    }
+
+// amf::Buffer::init(unsigned int)
+}
+
+void
+test_append()
+{
+    Buffer buf1;
+    buf1.clear();
+    Network::byte_t *ptr1 = buf1.reference();
+
+    Network::byte_t *data1 = new Network::byte_t[10];
+    memset(data1, 0, 10);
+    for (size_t i=0; i< 10; i++) {
+        data1[i] = i + 'a';
+    }
+    Network::byte_t *data2 = new Network::byte_t[10];
+    memset(data2, 0, 10);
+    for (size_t i=0; i< 10; i++) {
+        data2[i] = i + 'A';
+    }
+
+    // append a string of bytes
+    Network::byte_t *data3 = new Network::byte_t[20];
+    memcpy(data3, data1, 10);
+    memcpy(data3+10, data2, 10);
+    buf1.copy(data1, 10);
+    buf1.append(data2, 10);
+    if (memcmp(data3, buf1.reference(), 20) == 0) {
+         runtest.pass ("Buffer::append(Network::byte_t *, size_t)");
+    } else {
+         runtest.fail ("Buffer::append(Network::byte_t *, size_t)");
+    }
+
+    // append an unsigned byte
+    Buffer buf2(30);
+    buf2.clear();
+    buf2.copy(data1, 10);
+    Network::byte_t byte = '@';
+    buf2.append(byte);
+    memset(data3, 0, 20);
+    memcpy(data3, data1, 10);
+    *(data3 + 10) = '@';
+    if (memcmp(data3, buf2.reference(), 11) == 0) {
+         runtest.pass ("Buffer::append(Network::byte_t)");
+    } else {
+         runtest.fail ("Buffer::append(Network::byte_t)");
+    }
+
+    double num = 1.2345;
+    Buffer buf3;
+    buf3.clear();
+    buf3.copy(data1, 10);
+    buf3.append(num);
+    
+    memset(data3, 0, 20);
+    memcpy(data3, data1, 10);
+    memcpy(data3 + 10, &num, sizeof(double));
+    if (memcmp(data3, buf3.reference(), 10+sizeof(double)) == 0) {
+         runtest.pass ("Buffer::append(double)");
+    } else {
+         runtest.fail ("Buffer::append(double)");
+    }
+    
+// amf::Buffer::append(amf::Element::amf_type_e)
+// amf::Buffer::append(amf::Buffer*)
+// amf::Buffer::append(std::string const&)
+// amf::Buffer::append(amf::Buffer&)
+// amf::Buffer::append(bool)
+// amf::Buffer::append(unsigned int)
+// amf::Buffer::append(unsigned short)
+}
+
+void
+test_remove()
+{
+// amf::Buffer::remove(unsigned char)
+// amf::Buffer::remove(int)
+// amf::Buffer::remove(int, int)
+}
+
+void
+test_construct()
+{
+    bool valgrind = false;
+    
+    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 - (sizeof(long *) 
* 4)) && diff <= (NETBUFSIZE + sizeof(long *)*4))) {
+        runtest.pass ("Buffer::Buffer()");
+    } else {
+        if (valgrind) {
+            runtest.unresolved("Buffer::Buffer()) under valgrind");
+        } else {
+            runtest.fail("Buffer::Buffer()");
+        }
+    }
 
-//    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()");
+    Buffer buf2(124);
+    mem.addStats(__LINE__);             // take a sample
+    diff = mem.diffStats() - sizeof(long *);
+    if ((buf2.size() == 124) && (124 - (sizeof(long *) * 4)) && diff <= (124 + 
sizeof(long *)*4)) {
+        runtest.pass ("Buffer::Buffer(size_t)");
      } else {
-         runtest.fail ("Buffer::empty()");
+        if (valgrind) {
+            runtest.unresolved("Buffer::Buffer(size_t) under valgrind");
+        } else {
+            runtest.fail("Buffer::Buffer(size_t)");
+        }
     }
+}
 
-    // populate the buffer
-    boost::uint8_t *ptr = buf.reference();
-    for (size_t i=1; i< buf.size(); i++) {
-        ptr[i] = i;
+// make sure when we delete a Buffer, *all* the allocated
+// memory goes away. As the only way to do this is to examine
+// the malloc buffers in the kernel, this will only work on
+// POSIX conforming systems, and probabably only Linux & BSD.
+void
+test_destruct()
+{
+    Memory mem(5);
+    mem.addStats(__LINE__);             // take a sample
+    Buffer *buf1, *buf2;
+
+    mem.startCheckpoint();
+    buf1 = new Buffer(NETBUFSIZE);
+    delete buf1;
+    
+    if (mem.endCheckpoint()) {
+        runtest.pass ("Buffer::~Buffer()");
+    } else {
+        runtest.fail ("Buffer::~Buffer()");
     }
 
-    Buffer buf2;
-    if (buf2 == buf) {
-         runtest.fail ("Buffer::operator==");
+    mem.startCheckpoint();
+    buf2 = new Buffer(124);
+    delete buf2;
+    
+    if (mem.endCheckpoint()) {
+        runtest.pass ("Buffer::~Buffer(size_t)");
+    } else {
+        runtest.fail ("Buffer::~Buffer(size_t)");
+    }
+    
+}
+
+void
+test_operators()
+{
+    // Make some data for the buffers
+    Buffer buf1, buf2;
+    // valgrind gets pissed unless we zero the memory. Constructing
+    // a buffer doesn't clear the memory to save speed, and it's
+    // also unnecessary normally, but makes debugging easier.
+    buf1.clear();
+    buf2.clear();
+
+    boost::uint8_t *ptr1 = buf1.reference();
+    for (size_t i=1; i< buf1.size(); i++) {
+        ptr1[i] = i;
+    }
+
+    // buf1 has data, but buf2 doesn't, so if the
+    // equivalance test fails, then this passed.
+    buf2.clear();
+    if (buf2 == buf1) {
+         runtest.fail ("Buffer::operator==(Buffer &)");
      } else {
-         runtest.pass ("Buffer::operator==");
+         runtest.pass ("Buffer::operator==(Buffer &)");
     }
 
-    buf2 = buf;
-    if (buf2 == buf) {
-         runtest.pass ("Buffer::operator=");
+    // This makes the new buffer be identical to the
+    // the source buffer, including copying all the data.
+    buf2 = buf1;
+    if (buf1 == buf2) {
+         runtest.pass ("Buffer::operator=(Buffer &)");
      } else {
-         runtest.fail ("Buffer::operator=");
+         runtest.fail ("Buffer::operator=(Buffer &)");
     }
 
-//    mem.analyze();
+    Buffer *buf3, *buf4;
+    buf3 = new Buffer;
+    buf4 = new Buffer;
+    boost::uint8_t *ptr2 = buf3->reference();
+    for (size_t i=1; i< buf3->size(); i++) {
+        ptr2[i] = i + 'a';
+    }
+    if (buf3 == buf4) {
+         runtest.fail ("Buffer::operator==(Buffer *)");
+     } else {
+         runtest.pass ("Buffer::operator==(Buffer *)");
+    }
+
+    // This makes the new buffer be identical to the
+    // the source buffer, including copying all the data.
+    buf4 = buf3;
+    if (buf3 == buf4) {
+         runtest.pass ("Buffer::operator=(Buffer *)");
+    } else {
+         runtest.fail ("Buffer::operator=(Buffer *)");
+    }
+
+    Buffer buf5(10);
+    boost::uint8_t *ptr3 = buf5.reference();
+    buf5 += 'a';
+    buf5 += 'b';
+    buf5 += 'c';
+    if (memcmp(ptr3, "abc", 3) == 0) {
+         runtest.pass ("Buffer::operator+=(char)");
+    } else {
+         runtest.fail ("Buffer::operator+=(char)");
+    }
+
+    Buffer buf6(10);
+    buf6 += 'D';
+    buf6 += 'E';
+    buf6 += 'F';
+    buf5 += buf6;
+    ptr3 = buf5.reference();    // refresh the pointer, as it changes
+                                // on a resize()
+    // The size should now be the default 10, plus the 3 characters
+    // already added.
+    if ((memcmp(ptr3, "abcDEF", 6) == 0) && (buf5.size() == 13)) {
+         runtest.pass ("Buffer::operator+=(Buffer &)");
+    } else {
+         runtest.fail ("Buffer::operator+=(Buffer &)");
+    }
+}
+
+static void
+usage()
+{
+    cout << _("test_buffer - test Buffer class") << endl
+         << endl
+         << _("Usage: cygnal [options...]") << endl
+         << _("  -h,  --help          Print this help and exit") << endl
+         << _("  -v,  --verbose       Output verbose debug info") << endl
+         << _("  -m,  --memdebug      Output memory statistics") << endl
+         << endl;
 }
 

Index: testsuite/libamf.all/test_el.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libamf.all/test_el.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- testsuite/libamf.all/test_el.cpp    6 Apr 2008 18:11:33 -0000       1.4
+++ testsuite/libamf.all/test_el.cpp    11 Apr 2008 19:02:35 -0000      1.5
@@ -160,3 +160,71 @@
 }
 
 #endif
+
+
+// amf::Element::makeNumber(unsigned char*)
+// amf::Element::makeNumber(std::string const&, double)
+// amf::Element::makeNumber(double)
+// amf::Element::makeObject(unsigned char*, unsigned int)
+// amf::Element::makeObject(std::string const&)
+// amf::Element::makeString(char const*, unsigned int)
+// amf::Element::makeString(unsigned char*, unsigned int)
+// amf::Element::makeString(std::string const&)
+// amf::Element::makeString(std::string const&, std::string const&)
+// amf::Element::getNameSize()
+// amf::Element::makeBoolean(unsigned char*)
+// amf::Element::makeBoolean(std::string const&, bool)
+// amf::Element::makeBoolean(bool)
+// amf::Element::to_reference()
+// amf::Element::makeECMAArray(unsigned char*, unsigned int)
+// amf::Element::makeMovieClip(unsigned char*, unsigned int)
+// amf::Element::makeObjectEnd()
+// amf::Element::makeRecordSet(unsigned char*, unsigned int)
+// amf::Element::makeReference(unsigned char*, unsigned int)
+// amf::Element::makeUndefined(std::string const&)
+// amf::Element::makeUndefined()
+// amf::Element::makeXMLObject(unsigned char*, unsigned int)
+// amf::Element::makeLongString(unsigned char*, unsigned int)
+// amf::Element::makeNullString()
+// amf::Element::makeStrictArray(unsigned char*, unsigned int)
+// amf::Element::makeTypedObject(unsigned char*, unsigned int)
+// amf::Element::dump()
+// amf::Element::init(std::string const&)
+// amf::Element::init(std::string const&, std::string const&)
+// amf::Element::init(std::string const&, bool)
+// amf::Element::init(std::string const&, double)
+// amf::Element::init(bool)
+// amf::Element::init(bool, double, double, std::string const&)
+// amf::Element::init(double)
+// amf::Element::clear()
+// amf::Element::getData()
+// amf::Element::setName(unsigned char*, unsigned int)
+// amf::Element::setName(std::string const&)
+// amf::Element::to_bool()
+// amf::Element::makeDate(unsigned char*)
+// amf::Element::makeNull(std::string const&)
+// amf::Element::makeNull()
+// amf::Element::getLength()
+// amf::Element::to_number()
+// amf::Element::to_string()
+// amf::Element::Element(unsigned char*)
+// amf::Element::Element(std::string const&)
+// amf::Element::Element(std::string const&, std::string const&)
+// amf::Element::Element(std::string const&, bool)
+// amf::Element::Element(bool)
+// amf::Element::Element(bool, double, double, std::string const&)
+// amf::Element::Element(double)
+// amf::Element::Element()
+// amf::Element::Element(unsigned char*)
+// amf::Element::Element(std::string const&)
+// amf::Element::Element(std::string const&, std::string const&)
+// amf::Element::Element(std::string const&, bool)
+// amf::Element::Element(bool)
+// amf::Element::Element(bool, double, double, std::string const&)
+// amf::Element::Element(double)
+// amf::Element::Element()
+// amf::Element::~Element()
+// amf::Element::~Element()
+// amf::Element::operator=(amf::Element&)
+// amf::Element::operator==(bool)
+// amf::Element::operator[](int)

Index: testsuite/libamf.all/test_lc.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libamf.all/test_lc.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- testsuite/libamf.all/test_lc.cpp    25 Feb 2008 08:39:00 -0000      1.8
+++ testsuite/libamf.all/test_lc.cpp    11 Apr 2008 19:02:36 -0000      1.9
@@ -23,6 +23,7 @@
 
 //#include <netinet/in.h>
 #include <string>
+#include <cerrno>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -129,6 +130,13 @@
     
     //
     shmaddr = lc.getAddr();
+    if (shmaddr == 0) {
+        runtest.unresolved("LcShm::getAddr()");
+        return;
+    } else {
+        runtest.pass("LcShm::getAddr()");
+    }
+    
     char *addr = shmaddr + LC_LISTENERS_START;
     memset(addr, 0, 1024);
     
@@ -209,7 +217,7 @@
     vector<amf::Element *> els;
 
     el = new Element(true, 123.456, 987.654, "IAmReplyingNow");
-    el->dump();
+//    el->dump();
     els.push_back(el);
 
 #if 0
@@ -244,10 +252,13 @@
     char *shmaddr;
 
     string con1 = "lc_reply";
-    if (lc.connect(con1)) {
-        runtest.pass("LcShm::connect()");
+    if (!lc.connect(con1)) {
+        if (errno == EACCES) {
+            runtest.untested("Couldn't map input file, permission problems!!");
     } else {
-        runtest.fail("LcShm::connect()");
+            runtest.unresolved("LcShm::connect()");
+        }
+        exit(0);
     }
 
     shmaddr = lc.getAddr();
@@ -261,7 +272,13 @@
     if (dataptr != (void*)-1) {
         memcpy(shmaddr, dataptr, 64528);
     } else {
-        cerr << "ERROR: couldn't map input file!" << endl;
+        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);
@@ -525,7 +542,7 @@
         runtest.fail("localSecPathTime set");
     }
 
-    sol.dump();
+//    sol.dump();
     // now write the data to disk
     sol.writeFile(filespec, "settings");
 #endif
@@ -586,3 +603,31 @@
     
 #endif // }
 
+// FIXME: more tests! Here's all the methods:
+//
+// gnash::LcShm::parseHeader(unsigned char*)
+// gnash::LcShm::formatHeader(std::string const&, std::string const&, bool)
+// gnash::LcShm::dump()
+// gnash::LcShm::send(std::string const&, std::string const&, 
std::vector<amf::Element*, std::allocator<amf::Element*> >&)
+// gnash::LcShm::close()
+// gnash::LcShm::connect(std::string const&)
+// gnash::LcShm::connect(int)
+// gnash::LcShm::parseBody(unsigned char*)
+// gnash::LcShm::LcShm(unsigned char*)
+// gnash::LcShm::LcShm(int)
+// gnash::LcShm::LcShm()
+// gnash::LcShm::LcShm(unsigned char*)
+// gnash::LcShm::LcShm(int)
+// gnash::LcShm::LcShm()
+// gnash::LcShm::~LcShm()
+// gnash::LcShm::~LcShm()
+// gnash::Listener::addListener(std::string const&)
+// gnash::Listener::findListener(std::string const&)
+// gnash::Listener::listListeners()
+// gnash::Listener::removeListener(std::string const&)
+// gnash::Listener::Listener(unsigned char*)
+// gnash::Listener::Listener()
+// gnash::Listener::Listener(unsigned char*)
+// gnash::Listener::Listener()
+// gnash::Listener::~Listener()
+// gnash::Listener::~Listener()

Index: testsuite/libamf.all/test_sol.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libamf.all/test_sol.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- testsuite/libamf.all/test_sol.cpp   7 Apr 2008 20:44:31 -0000       1.11
+++ testsuite/libamf.all/test_sol.cpp   11 Apr 2008 19:02:36 -0000      1.12
@@ -40,12 +40,11 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <log.h>
 #include <iostream>
 #include <string>
 
 #include "dejagnu.h"
-
+#include "log.h"
 #include "amf.h"
 #include "buffer.h"
 #include "network.h"
@@ -400,3 +399,17 @@
 }
 
 #endif
+
+// amf::SOL::formatHeader(std::string const&)
+// amf::SOL::formatHeader(std::string const&, int)
+// amf::SOL::formatHeader(std::vector<unsigned char, std::allocator<unsigned 
char> > const&)
+// amf::SOL::extractHeader(std::string const&)
+// amf::SOL::extractHeader(std::vector<unsigned char, std::allocator<unsigned 
char> > const&)
+// amf::SOL::dump()
+// amf::SOL::addObj(amf::Element*)
+// amf::SOL::readFile(std::string&)
+// amf::SOL::writeFile(std::string const&, std::string const&)
+// amf::SOL::SOL()
+// amf::SOL::SOL()
+// amf::SOL::~SOL()
+// amf::SOL::~SOL()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]