[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libamf/buffer.cpp libamf/buffer...
From: |
Rob Savoye |
Subject: |
[Gnash-commit] gnash ChangeLog libamf/buffer.cpp libamf/buffer... |
Date: |
Sat, 12 Apr 2008 03:59:33 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Rob Savoye <rsavoye> 08/04/12 03:59:33
Modified files:
. : ChangeLog
libamf : buffer.cpp buffer.h element.cpp element.h
testsuite/libamf.all: test_buffer.cpp test_el.cpp
Log message:
* libamf/buffer.cpp: Redesign the ::resize() method. Add more
::copy() methods for bool and doubles.
* libamf/element.cpp: When invoking one of the make* methods for
initializing an object, all allocate memory if none has been
done so
yet. Implement a few more object creation types.
* libamf/element.h: Add a few more object creation methods.
* testsuite/libamf.all/test_buffer.cpp: Test new ::copy()
methods. Default to a nop if DejaGnu isn't installed.
* testsuite/libamf.all/test_el.cpp: Use arg_parser instead of
getopt. Default to a nop if DejaGnu isn't installed. Add more
tests for construction, and the making of Elements.`
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6262&r2=1.6263
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/buffer.cpp?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/buffer.h?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.cpp?cvsroot=gnash&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.h?cvsroot=gnash&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libamf.all/test_buffer.cpp?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libamf.all/test_el.cpp?cvsroot=gnash&r1=1.5&r2=1.6
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6262
retrieving revision 1.6263
diff -u -b -r1.6262 -r1.6263
--- ChangeLog 11 Apr 2008 21:04:33 -0000 1.6262
+++ ChangeLog 12 Apr 2008 03:59:32 -0000 1.6263
@@ -1,5 +1,19 @@
2008-04-11 Rob Savoye <address@hidden>
+ * libamf/buffer.cpp: Redesign the ::resize() method. Add more
+ ::copy() methods for bool and doubles.
+ * libamf/element.cpp: When invoking one of the make* methods for
+ initializing an object, all allocate memory if none has been done so
+ yet. Implement a few more object creation types.
+ * libamf/element.h: Add a few more object creation methods.
+ * testsuite/libamf.all/test_buffer.cpp: Test new ::copy()
+ methods. Default to a nop if DejaGnu isn't installed.
+ * testsuite/libamf.all/test_el.cpp: Use arg_parser instead of
+ getopt. Default to a nop if DejaGnu isn't installed. Add more
+ tests for construction, and the making of Elements.
+
+2008-04-11 Rob Savoye <address@hidden>
+
* libamf/buffer.h: Check _seekptr, not nbytes to determine if a
buffer is ::empty().
* libamf/buffer.cpp: Fix bugs in ::remove() method.
Index: libamf/buffer.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/buffer.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- libamf/buffer.cpp 11 Apr 2008 21:13:49 -0000 1.5
+++ libamf/buffer.cpp 12 Apr 2008 03:59:32 -0000 1.6
@@ -33,11 +33,12 @@
{
// GNASH_REPORT_FUNCTION;
if (_ptr == 0) {
- _seekptr = _ptr = new Network::byte_t[nbytes];
+ _ptr = new Network::byte_t[nbytes];
+ _seekptr = _ptr;
+ if (_ptr == 0) {
+ return _ptr;
+ }
_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,
-// clear();
}
#ifdef USE_STATS_BUFFERS
@@ -78,7 +79,7 @@
(float)((now.tv_sec - _stamp.tv_sec) + ((now.tv_nsec -
_stamp.tv_nsec)/1e9)));
#endif
delete[] _ptr;
- _ptr = 0;
+ _seekptr = _ptr = 0;
_nbytes = 0;
}
}
@@ -95,7 +96,7 @@
void
Buffer::copy(const string &str)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
std::copy(str.begin(), str.end(), _ptr);
_seekptr = _ptr + str.size();
}
@@ -103,11 +104,38 @@
void
Buffer::copy(boost::uint16_t length)
{
+ GNASH_REPORT_FUNCTION;
Network::byte_t *data = reinterpret_cast<Network::byte_t *>(&length);
std::copy(data, data + sizeof(boost::uint16_t), _ptr);
_seekptr = _ptr + sizeof(boost::uint16_t);
}
+void
+Buffer::copy(double num)
+{
+ GNASH_REPORT_FUNCTION;
+ Network::byte_t *ptr = reinterpret_cast<Network::byte_t *>(&num);
+ std::copy(ptr, ptr + amf::AMF_NUMBER_SIZE, _ptr);
+ _seekptr = _ptr + amf::AMF_NUMBER_SIZE;
+}
+
+void
+Buffer::copy(Network::byte_t val)
+{
+ GNASH_REPORT_FUNCTION;
+ *_ptr = val;
+ _seekptr = _ptr + sizeof(bool);
+}
+
+#if 0
+void
+Buffer::copy(bool val)
+{
+ GNASH_REPORT_FUNCTION;
+ return copy(static_cast<Network::byte_t>(val));
+}
+#endif
+
Network::byte_t *
Buffer::append(boost::uint16_t length)
{
@@ -410,35 +438,41 @@
_seekptr = _ptr;
}
-// Resize the buffer that holds the data
+// Resize the buffer that holds the data.
void *
-Buffer::resize(size_t nbytes)
+Buffer::resize(size_t size)
{
// GNASH_REPORT_FUNCTION;
// Allocate a new memory block
- size_t diff = _seekptr - _ptr;
- Network::byte_t *tmp = new Network::byte_t[nbytes];
+ if (_nbytes == 0) {
+ init(size);
+ } else {
+ size_t diff =_seekptr - _ptr;
+ Network::byte_t *tmp = new Network::byte_t[size];
// And copy ourselves into it
- if (nbytes > _nbytes) {
+ if (size > _nbytes) {
std::copy(_ptr, _ptr + _nbytes, tmp);
+ // Delete the old block, it's unused now
+ delete[] _ptr;
+ // Make the memory block use the new space
+ _ptr = tmp;
+ // Make the seekptr point into the new space with the correct offset
+ _seekptr = tmp + diff;
}
-
- if (nbytes < _nbytes) {
- std::copy(_ptr, _ptr + nbytes, tmp);
- }
-
- _nbytes = nbytes;
-
+ if (size < _nbytes) {
+ std::copy(_ptr, _ptr + size, tmp);
// Delete the old block, it's unused now
delete[] _ptr;
-
- // Make the memeory block use the new space
+ // Make the memory block use the new space
_ptr = tmp;
+ // Make the seekptr point into the new space with the correct offset
+ _seekptr = _ptr + size;
+ }
+ }
+ // Adjust the size
+ _nbytes = size;
- // reset the seek pointer to point into this block
- _seekptr = _ptr + diff;
-
- return tmp;
+ return _ptr;
}
void
Index: libamf/buffer.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/buffer.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libamf/buffer.h 11 Apr 2008 21:04:34 -0000 1.4
+++ libamf/buffer.h 12 Apr 2008 03:59:32 -0000 1.5
@@ -51,10 +51,11 @@
void copy(gnash::Network::byte_t *data, size_t nbytes);
void copy(gnash::Network::byte_t *data) { copy(data, _nbytes); };
void copy(const std::string &str);
+ void copy(double num);
void copy(boost::uint16_t length);
-// void copy(boost::uint32_t val);
+ void copy(gnash::Network::byte_t byte);
// void copy(bool);
-// void copy(double num);
+// void copy(boost::uint32_t val);
// void copy(Element::amf_type_e type);
// Append data to the existing data in the buffer. This assume the
Index: libamf/element.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- libamf/element.cpp 11 Apr 2008 19:02:35 -0000 1.18
+++ libamf/element.cpp 12 Apr 2008 03:59:32 -0000 1.19
@@ -75,10 +75,8 @@
{
// GNASH_REPORT_FUNCTION;
if (_buffer) {
- if (_buffer->size() > 0) {
delete _buffer;
}
- }
for (size_t i=0; i< _children.size(); i++) {
delete _children[i];
}
@@ -200,11 +198,13 @@
if (name.size()) {
setName(name);
}
+ if (_buffer == 0) {
_buffer = new Buffer(AMF_NUMBER_SIZE);
-// _data = reinterpret_cast<Network::byte_t *>(new char[sizeof(double)]);
-// Network::byte_t *ptr = reinterpret_cast<Network::byte_t *>(&indata);
+ } else {
+ _buffer->resize(AMF_NUMBER_SIZE);
+ }
+ _buffer->copy(num);
- _buffer->append(num);
return *this;
}
@@ -223,8 +223,12 @@
if (name.size()) {
setName(name);
}
+ if (_buffer == 0) {
_buffer = new Buffer(str.size());
- _buffer->append(str);
+ } else {
+ _buffer->resize(str.size());
+ }
+ _buffer->copy(str);
return *this;
}
@@ -244,7 +248,11 @@
if (name.size()) {
setName(name);
}
+ if (_buffer == 0) {
_buffer = new Buffer(sizeof(bool));
+ } else {
+ _buffer->resize(sizeof(bool));
+ }
_buffer->append(flag);
return *this;
@@ -366,14 +374,22 @@
{
// GNASH_REPORT_FUNCTION;
_type = Element::STRING;
+ if (_buffer == 0) {
// Make room for an additional NULL terminator
_buffer = new Buffer(size+1);
+ } else {
+ if (_buffer->size() != size+1) {
+ _buffer->resize(size+1);
+ }
+ }
_buffer->copy(data, size);
+
// Unlike other buffers, people like to print strings, so we must add
// a NULL terminator to the string. When encoding, we are careful to
// to adjust the byte count down by one, as the NULL terminator doesn't
// get written.
*(_buffer->end() - 1) = 0;
+
return *this;
}
@@ -384,7 +400,13 @@
{
// GNASH_REPORT_FUNCTION;
_type = Element::STRING;
+ if (_buffer == 0) {
_buffer = new Buffer(sizeof(Network::byte_t));
+ } else {
+ if (_buffer->size() != sizeof(Network::byte_t)) {
+ _buffer->resize(sizeof(Network::byte_t));
+ }
+ }
*(_buffer->reference()) = 0;
return *this;
}
@@ -421,8 +443,15 @@
GNASH_REPORT_FUNCTION;
double num = *reinterpret_cast<const double*>(data);
_type = Element::NUMBER;
+ if (_buffer == 0) {
_buffer = new Buffer(AMF_NUMBER_SIZE);
- _buffer->append(num);
+ } else {
+ if (_buffer->size() != AMF_NUMBER_SIZE) {
+ _buffer->resize(AMF_NUMBER_SIZE);
+ }
+ }
+ _buffer->copy(num);
+
return *this;
}
@@ -431,8 +460,15 @@
{
// GNASH_REPORT_FUNCTION;
_type = Element::NUMBER;
- _buffer = new Buffer(AMF_NUMBER_SIZE);
- _buffer->append(num);
+ size_t size = AMF_NUMBER_SIZE;
+ if (_buffer == 0) {
+ _buffer = new Buffer(size);
+ } else {
+ if (_buffer->size() != size) {
+ _buffer->resize(size);
+ }
+ }
+ _buffer->copy(num);
return *this;
}
@@ -452,7 +488,14 @@
{
// GNASH_REPORT_FUNCTION;
_type = Element::BOOLEAN;
+ if (_buffer == 0) {
_buffer = new Buffer(sizeof(bool));
+ } else {
+ if (_buffer->size() != sizeof(bool)) {
+ _buffer->resize(sizeof(bool));
+ }
+ }
+
_buffer->append(flag);
return *this;
}
@@ -498,9 +541,15 @@
{
// GNASH_REPORT_FUNCTION;
_type = Element::NULL_VALUE;
- Network::byte_t val = 0;
+ if (_buffer == 0) {
_buffer = new Buffer(sizeof(Network::byte_t));
- _buffer->append(val);
+ } else {
+ if (_buffer->size() != sizeof(Network::byte_t)) {
+ _buffer->resize(sizeof(Network::byte_t));
+ }
+ }
+
+ *(_buffer->reference()) = 0;
return *this;
}
@@ -517,8 +566,10 @@
Element &
Element::makeObject(const std::string &name)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
+ if (name.size()) {
setName(name);
+ }
_type = OBJECT;
return *this;
}
@@ -526,9 +577,16 @@
Element &
Element::makeObject(Network::byte_t *indata, size_t size)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
_type = Element::OBJECT;
+ if (_buffer == 0) {
_buffer = new Buffer(size);
+ } else {
+ if (_buffer->size() != size) {
+ _buffer->resize(size);
+ }
+ }
+
_buffer->copy(indata, size);
return *this;
}
@@ -536,37 +594,86 @@
Element &
Element::makeObjectEnd()
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
_type = Element::OBJECT_END;
return *this;
}
Element &
+Element::makeXMLObject(const std::string &name)
+{
+// GNASH_REPORT_FUNCTION;
+ _type = Element::XML_OBJECT;
+ if (name.size()) {
+ setName(name);
+ }
+ return *this;
+}
+
+Element &
Element::makeXMLObject(Network::byte_t *indata, size_t size)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
_type = Element::XML_OBJECT;
+ if (_buffer == 0) {
_buffer = new Buffer(size);
+ } else {
+ if (_buffer->size() != size) {
+ _buffer->resize(size);
+ }
+ }
_buffer->copy(indata, size);
+
+ return *this;
+}
+
+Element &
+Element::makeTypedObject(const std::string &name)
+{
+// GNASH_REPORT_FUNCTION;
+ _type = Element::TYPED_OBJECT;
+ if (name.size()) {
+ setName(name);
+ }
return *this;
}
Element &
Element::makeTypedObject(Network::byte_t *indata, size_t size)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
_type = Element::TYPED_OBJECT;
+ if (_buffer == 0) {
_buffer = new Buffer(size);
+ } else {
+ if (_buffer->size() != size) {
+ _buffer->resize(size);
+ }
+ }
_buffer->copy(indata, size);
return *this;
}
Element &
+Element::makeReference()
+{
+// GNASH_REPORT_FUNCTION;
+ _type = Element::REFERENCE;
+ return *this;
+}
+
+Element &
Element::makeReference(Network::byte_t *indata, size_t size)
{
// GNASH_REPORT_FUNCTION;
_type = Element::REFERENCE;
+ if (_buffer == 0) {
_buffer = new Buffer(size);
+ } else {
+ if (_buffer->size() != size) {
+ _buffer->resize(size);
+ }
+ }
_buffer->copy(indata, size);
return *this;
}
@@ -576,7 +683,13 @@
{
GNASH_REPORT_FUNCTION;
_type = Element::MOVIECLIP;
+ if (_buffer == 0) {
_buffer = new Buffer(size);
+ } else {
+ if (_buffer->size() != size) {
+ _buffer->resize(size);
+ }
+ }
_buffer->copy(indata, size);
return *this;
}
@@ -586,7 +699,13 @@
{
GNASH_REPORT_FUNCTION;
_type = Element::ECMA_ARRAY;
+ if (_buffer == 0) {
_buffer = new Buffer(size);
+ } else {
+ if (_buffer->size() != size) {
+ _buffer->resize(size);
+ }
+ }
_buffer->copy(indata, size);
return *this;
}
@@ -596,7 +715,13 @@
{
GNASH_REPORT_FUNCTION;
_type = Element::LONG_STRING;
+ if (_buffer == 0) {
_buffer = new Buffer(size);
+ } else {
+ if (_buffer->size() != size) {
+ _buffer->resize(size);
+ }
+ }
_buffer->copy(indata, size);
return *this;
}
@@ -606,7 +731,13 @@
{
GNASH_REPORT_FUNCTION;
_type = Element::RECORD_SET;
+ if (_buffer == 0) {
_buffer = new Buffer(size);
+ } else {
+ if (_buffer->size() != size) {
+ _buffer->resize(size);
+ }
+ }
_buffer->copy(indata, size);
return *this;
}
@@ -616,6 +747,15 @@
{
GNASH_REPORT_FUNCTION;
_type = Element::DATE;
+ size_t size = sizeof(long);
+ if (_buffer == 0) {
+ _buffer = new Buffer(size);
+ } else {
+ if (_buffer->size() != size) {
+ _buffer->resize(size);
+ }
+ }
+ _buffer->copy(date, sizeof(long));
return makeNumber(date);
}
@@ -623,9 +763,14 @@
Element::makeStrictArray(Network::byte_t *indata, size_t size)
{
GNASH_REPORT_FUNCTION;
-
_type = Element::STRICT_ARRAY;
+ if (_buffer == 0) {
_buffer = new Buffer(size);
+ } else {
+ if (_buffer->size() != size) {
+ _buffer->resize(size);
+ }
+ }
_buffer->copy(indata, size);
return *this;
}
Index: libamf/element.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- libamf/element.h 11 Apr 2008 19:02:35 -0000 1.15
+++ libamf/element.h 12 Apr 2008 03:59:32 -0000 1.16
@@ -97,21 +97,40 @@
Element &makeUndefined();
Element &makeUndefined(const std::string &name);
+
Element &makeNull();
Element &makeNull(const std::string &name);
Element &makeObjectEnd();
+
Element &makeObject(const std::string &name);
Element &makeObject(gnash::Network::byte_t *data, size_t size);
+ Element &makeXMLObject(const std::string &name);
Element &makeXMLObject(gnash::Network::byte_t *data, size_t size);
+
+ Element &makeTypedObject(const std::string &name);
Element &makeTypedObject(gnash::Network::byte_t *data, size_t size);
+
+ Element &makeReference();
Element &makeReference(gnash::Network::byte_t *data, size_t size);
+
+ Element &makeMovieClip();
Element &makeMovieClip(gnash::Network::byte_t *data, size_t size);
+
+ Element &makeECMAArray();
Element &makeECMAArray(gnash::Network::byte_t *data, size_t size);
+
+ Element &makeLongString();
Element &makeLongString(gnash::Network::byte_t *data, size_t size);
+
+ Element &makeRecordSet();
Element &makeRecordSet(gnash::Network::byte_t *data, size_t size);
+
+ Element &makeDate();
Element &makeDate(gnash::Network::byte_t *data);
+
+ Element &makeStrictArray();
Element &makeStrictArray(gnash::Network::byte_t *data, size_t size);
// Element &makeArray();
Index: testsuite/libamf.all/test_buffer.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libamf.all/test_buffer.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- testsuite/libamf.all/test_buffer.cpp 11 Apr 2008 21:13:49 -0000
1.4
+++ testsuite/libamf.all/test_buffer.cpp 12 Apr 2008 03:59:33 -0000
1.5
@@ -20,6 +20,8 @@
#include "gnashconfig.h"
#endif
+#ifdef HAVE_DEJAGNU_H
+
#include <regex.h>
#include <cstdio>
#include <cerrno>
@@ -211,7 +213,7 @@
if (memcmp(ptr2, str, 9) == 0) {
runtest.pass ("Buffer::copy(const char *)");
} else {
- runtest.fail ("Buffer::copy(const char)");
+ runtest.fail ("Buffer::copy(const char *)");
}
boost::uint16_t length = 12;
@@ -224,6 +226,32 @@
} else {
runtest.fail ("Buffer::copy(boost::uint16_t)");
}
+
+#if 0
+ double num = 1.2345;
+ Buffer buf4;
+ buf4.clear();
+ buf4.copy(num);
+ memcpy(data, &num, amf::AMF_NUMBER_SIZE);
+
+ if (memcmp(data, buf4.reference(), amf::AMF_NUMBER_SIZE) == 0) {
+ runtest.pass ("Buffer::copy(double)");
+ } else {
+ runtest.fail ("Buffer::copy(double)");
+ }
+#endif
+
+#if 0
+ bool flag = true;
+ Buffer buf5;
+ buf5.clear();
+ buf5.copy(flag);
+ if (*(buf5.reference()) == 1) {
+ runtest.pass ("Buffer::copy(bool)");
+ } else {
+ runtest.fail ("Buffer::copy(bool)");
+ }
+#endif
}
void
@@ -249,8 +277,8 @@
runtest.fail ("Buffer::find(Network::byte_t)");
}
- char *sub = "fgh";
- Network::byte_t *ptr2 = reinterpret_cast<Network::byte_t *>(sub);
+ const char *sub = "fgh";
+ Network::byte_t *ptr2 = const_cast<Network::byte_t
*>(reinterpret_cast<const Network::byte_t *>(sub));
fptr = buf1.find(ptr2, 3);
if (fptr == (ptr1 + 5)) {
runtest.pass ("Buffer::find(Network::byte_t *, size_t)");
@@ -266,7 +294,7 @@
{
Buffer buf1;
buf1.clear();
- Network::byte_t *ptr1 = buf1.reference();
+// Network::byte_t *ptr1 = buf1.reference();
Network::byte_t *data1 = new Network::byte_t[10];
memset(data1, 0, 10);
@@ -306,6 +334,7 @@
runtest.fail ("Buffer::append(Network::byte_t)");
}
+ // Append a number
double num = 1.2345;
Buffer buf3;
buf3.clear();
@@ -518,6 +547,7 @@
}
Buffer buf5(10);
+ buf5.clear();
boost::uint8_t *ptr3 = buf5.reference();
buf5 += 'a';
buf5 += 'b';
@@ -529,6 +559,7 @@
}
Buffer buf6(10);
+ buf6.clear();
buf6 += 'D';
buf6 += 'E';
buf6 += 'F';
@@ -556,3 +587,13 @@
<< endl;
}
+#else
+
+int
+main(int /*argc*/, char /* *argv[]*/)
+{
+ // nop
+ return 0;
+}
+
+#endif
Index: testsuite/libamf.all/test_el.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libamf.all/test_el.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- testsuite/libamf.all/test_el.cpp 11 Apr 2008 19:02:35 -0000 1.5
+++ testsuite/libamf.all/test_el.cpp 12 Apr 2008 03:59:33 -0000 1.6
@@ -1,5 +1,5 @@
//
-// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+// 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
@@ -21,22 +21,10 @@
#ifdef HAVE_DEJAGNU_H
-//#include <netinet/in.h>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
-#include "as_object.h"
-
-extern "C"{
-#include <unistd.h>
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
-#ifndef __GNUC__
-extern int optind, getopt(int, char *const *, const char *);
-#endif
-}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -45,7 +33,8 @@
#include <string>
#include "dejagnu.h"
-
+#include "as_object.h"
+#include "arg_parser.h"
#include "buffer.h"
#include "network.h"
#include "amf.h"
@@ -57,174 +46,369 @@
static void usage (void);
-static TestState runtest;
-
bool test_read(std::string &filespec);
bool test_write(std::string &filespec);
bool test_sol(std::string &filespec);
+// Prototypes for test cases
+static void test_construct();
+static void test_destruct();
+static void test_make();
+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[])
-{
- int c;
+{ 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);
+ }
- while ((c = getopt (argc, argv, "hdvsm:")) != -1) {
- switch (c) {
+ for( int i = 0; i < parser.arguments(); ++i ) {
+ const int code = parser.code(i);
+ try {
+ switch( code ) {
case 'h':
usage ();
- break;
-
+ exit(EXIT_SUCCESS);
case 'v':
dbglogfile.setVerbosity();
+ // This happens once per 'v' flag
+ log_debug(_("Verbose output turned on"));
break;
-
- default:
- usage ();
+ 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;
+
}
}
- Element el;
- if (el.getType() == Element::NOTYPE) {
+ catch (Arg_parser::ArgParserException &e) {
+ cerr << _("Error parsing command line options: ") << e.what() <<
endl;
+ cerr << _("This is a Gnash bug.") << endl;
+ }
+ }
+
+ // run the tests
+ test_construct();
+ test_make();
+ test_operators();
+ test_destruct();
+}
+
+void
+test_construct()
+{
+ // First test the init method, which is all the constructor does anyway..
First
+ // we test just making regular elements instead of named elements, ie...
+ // AMF "variables".
+ Element el1;
+ if (el1.getType() == Element::NOTYPE) {
runtest.pass("Created empty element");
} else {
runtest.fail("Created empty element");
}
+ Element el2;
double dub = 54.3;
- el.init(dub);
- if ((el.getType() == Element::NUMBER) &&
- (el.to_number() == dub)) {
- runtest.pass("Created double element");
+ el2.init(dub);
+ if ((el2.getType() == Element::NUMBER) &&
+ (el2.to_number() == dub)) {
+ runtest.pass("Initialized as double element");
} else {
- runtest.fail("Created double element");
+ runtest.fail("Initialized as double element");
}
-// el.dump();
- el.clear();
+ Element el3;
+ bool flag = true;
+ el3.init(flag);
+ if ((el3.getType() == Element::BOOLEAN) &&
+ (el3.to_bool() == true)) {
+ runtest.pass("Initialized as bool element");
+ } else {
+ runtest.fail("Initialized as bool element");
+ }
- string str = "Hello World!";
- el.makeString("Hello World!");
- if ((el.getType() == Element::STRING) &&
- (el.to_string() == str)) {
- runtest.pass("Created string element");
+ Element el4;
+ string str = "Hello World";
+ el4.init(str);
+ if ((el4.getType() == Element::STRING) &&
+ (el4.getLength() == str.size())) {
+ runtest.pass("Initialized as string element");
} else {
- runtest.fail("Created string element");
+ runtest.fail("Initialized as string element");
}
- el.clear();
- bool sheet = true;
- el.makeBoolean(sheet);
- if ((el.getType() == Element::BOOLEAN) &&
- (el.to_bool() == sheet)) {
- runtest.pass("Created bool element");
+ // Now test init with the variable name
+ Element el5;
+ dub = 2.456;
+ el5.init("test1", dub);
+ if ((el5.getType() == Element::NUMBER) &&
+ (strcmp(el5.getName(), "test1") == 0) &&
+ (el5.to_number() == dub)) {
+ runtest.pass("Initialized as double element with name");
} else {
- runtest.fail("Created bool element");
+ runtest.fail("Initialized as double element with name");
}
- el.clear();
- el.makeNull();
- if (el.getType() == Element::NULL_VALUE) {
- runtest.pass("Created NULL Value element");
+ Element el6;
+ flag = true;
+ el6.init("test2", flag);
+ if ((el6.getType() == Element::BOOLEAN) &&
+ (strcmp(el6.getName(), "test2") == 0) &&
+ (el6.to_bool() == true)) {
+ runtest.pass("Initialized as bool element with name");
} else {
- runtest.fail("Created NULL Value element");
+ runtest.fail("Initialized as bool element with name");
}
- el.clear();
- el.makeUndefined();
- if (el.getType() == Element::UNDEFINED) {
- runtest.pass("Created Undefined element");
+
+ Element el7;
+ str = "Hello World";
+ el7.init("test3", str);
+ if ((el7.getType() == Element::STRING) &&
+ (strcmp(el7.getName(), "test3") == 0) &&
+ (el7.getLength() == str.size())) {
+ runtest.pass("Initialized as string element with name");
} else {
- runtest.fail("Created Undefined element");
+ runtest.fail("Initialized as string element with name");
}
-}
-static void
-usage (void)
-{
- cerr << "This program tests AMF Element support in the AMF library." <<
endl;
- cerr << "Usage: test_el [hv]" << endl;
- cerr << "-h\tHelp" << endl;
- cerr << "-v\tVerbose" << endl;
- exit (-1);
-}
+ // Now test the actual constructor
+ dub = 23.45;
+ Element elnum1(dub);
+ if ((elnum1.getType() == Element::NUMBER) &&
+ (elnum1.to_number() == dub)) {
+ runtest.pass("Constructed as double element");
+ } else {
+ runtest.fail("Constructed as double element");
+ }
-#else
+ flag = true;
+ Element elbool1(flag);
+ if ((elbool1.getType() == Element::BOOLEAN) &&
+ (elbool1.to_bool() == true)) {
+ runtest.pass("Constructed as bool element");
+ } else {
+ runtest.fail("Constructed as bool element");
+ }
-int
-main(int /*argc*/, char /* *argv[]*/)
-{
- // nop
- return 0;
-}
+ str = "Guten Tag";
+ Element elstr1(str);
+ if ((elstr1.getType() == Element::STRING) &&
+ (elstr1.getLength() == str.size())) {
+ runtest.pass("Constructed as string element");
+ } else {
+ runtest.fail("Constructed as string element");
+ }
-#endif
+ // And now test constrcutors with variable names
+
+ dub = 23.45;
+ Element elnum2(dub);
+ if ((elnum2.getType() == Element::NUMBER) &&
+ (elnum2.to_number() == dub)) {
+ runtest.pass("Constructed as double element with name");
+ } else {
+ runtest.fail("Constructed as double element with name");
+ }
+
+ flag = true;
+ Element elbool2(flag);
+ if ((elbool2.getType() == Element::BOOLEAN) &&
+ (elbool2.to_bool() == true)) {
+ runtest.pass("Constructed as bool element with name");
+ } else {
+ runtest.fail("Constructed as bool element with name");
+ }
+ str = "Aloha";
+ Element elstr2(str);
+ if ((elstr2.getType() == Element::STRING) &&
+ (elstr2.getLength() == str.size())) {
+ runtest.pass("Constructed as string element with name");
+ } else {
+ runtest.fail("Constructed as string element with name");
+ }
+}
+
+void
+test_destruct()
+{
+}
// 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()
+void
+test_make()
+{
+ Element el1;
+ string str = "Hello World!";
+ el1.makeString("Hello World!");
+ if ((el1.getType() == Element::STRING) &&
+ (el1.to_string() == str)) {
+ runtest.pass("Made string element");
+ } else {
+ runtest.fail("Made string element");
+ }
+
+ Element el2;
+ bool sheet = true;
+ el2.makeBoolean(sheet);
+ if ((el2.getType() == Element::BOOLEAN) &&
+ (el2.to_bool() == sheet)) {
+ runtest.pass("Made bool element");
+ } else {
+ runtest.fail("Made bool element");
+ }
+
+ Element el3;
+ el3.clear();
+ el3.makeNull();
+ if (el3.getType() == Element::NULL_VALUE) {
+ runtest.pass("Made NULL Value element");
+ } else {
+ runtest.fail("Made NULL Value element");
+ }
+
+ Element el4;
+ el4.makeUndefined();
+ if (el4.getType() == Element::UNDEFINED) {
+ runtest.pass("Made Undefined element");
+ } else {
+ runtest.fail("Made Undefined element");
+ }
+
+ Element el5;
+ el5.clear();
+ el5.makeObjectEnd();
+ if (el5.getType() == Element::OBJECT_END) {
+ runtest.pass("Made Object End element");
+ } else {
+ runtest.fail("Made Object End element");
+ }
+
+ Element el6;
+ el6.clear();
+ el6.makeNullString();
+ if ((el6.getType() == Element::STRING) &&
+ (el6.getLength() == 1)) {
+ runtest.pass("Made NULL String element");
+ } else {
+ runtest.fail("Made NULL String element");
+ }
+
+ double num = 123.456;
+ Element el7;
+ el7.clear();
+ el7.makeNumber(num);
+ if ((el7.getType() == Element::NUMBER) &&
+ (el7.to_number() == num)) {
+ runtest.pass("Made double element");
+ } else {
+ runtest.fail("Made double element");
+ }
+
+ Element el8;
+ el8.clear();
+ el8.makeObject("app");
+ if (el8.getType() == Element::OBJECT) {
+ runtest.pass("Made Object element");
+ } else {
+ runtest.fail("Made Object element");
+ }
+
+ Element el9;
+ el9.clear();
+ el9.makeTypedObject("foobar");
+ if (el9.getType() == Element::TYPED_OBJECT) {
+ runtest.pass("Made Object element");
+ } else {
+ runtest.fail("Made Object element");
+ }
+
+ // Test recreating an element as a large size data type.
+ Element rel1;
+ rel1.clear();
+ rel1.makeBoolean(true);
+ rel1.makeNumber(num);
+ if ((rel1.getType() == Element::NUMBER) &&
+ (rel1.getLength() == amf::AMF_NUMBER_SIZE) &&
+ (rel1.to_number() == num)) {
+ runtest.pass("Remade boolean as a double element");
+ } else {
+ runtest.fail("Remade boolean as a double element");
+ }
+}
+
// amf::Element::operator=(amf::Element&)
// amf::Element::operator==(bool)
// amf::Element::operator[](int)
+void
+test_operators()
+{
+}
+
+static void
+usage (void)
+{
+ cerr << "This program tests AMF Element support in the AMF library." <<
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;
+}
+
+#else
+
+int
+main(int /*argc*/, char /* *argv[]*/)
+{
+ // nop
+ return 0;
+}
+
+#endif
+