CVSROOT: /sources/gnash Module name: gnash Changes by: Rob Savoye <rsavoye> 07/12/15 07:00:28
Added files: testsuite/libamf.all: test_sol.cpp Log message: * testsuite/libamf.all/test_sol.cpp: Test case for SOL support. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libamf.all/test_sol.cpp?cvsroot=gnash&rev=1.1 Patches: Index: test_sol.cpp =================================================================== RCS file: test_sol.cpp diff -N test_sol.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ test_sol.cpp 15 Dec 2007 07:00:27 -0000 1.1 @@ -0,0 +1,191 @@ +// +// Copyright (C) 2005, 2006, 2007 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 "config.h" +#endif + +#ifdef HAVE_DEJAGNU_H + +//#include <netinet/in.h> +#include <string> +#include <sys/types.h> +#include <sys/stat.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> +#include <log.h> +#include <iostream> +#include <string> + +#include "dejagnu.h" + +#include "amf.h" +#include "sol.h" + +using namespace amf; +using namespace gnash; +using namespace std; + +static void usage (void); + +static TestState runtest; + +bool test_read(); +bool test_write(); +bool test_sol(); + +LogFile& dbglogfile = LogFile::getDefaultInstance(); + +int +main(int argc, char *argv[]) +{ + int c; + + while ((c = getopt (argc, argv, "hdvsm:")) != -1) { + switch (c) { + case 'h': + usage (); + break; + + case 'v': + dbglogfile.setVerbosity(); + break; + + default: + usage (); + break; + } + } + + test_read(); + test_write(); +// test_sol(); +} + +bool +test_read() +{ + struct stat st; + + string filespec = SRCDIR; + filespec += "/settings.sol"; + + if (stat(filespec.c_str(), &st) == 0) { + SOL sol; + int fd, ret; + char *buf; + amfnum_t *num; + + buf = new char[st.st_size + 1]; + + sol.readFile(filespec); + string name = "TestString"; + char *data = "testing, 1-2-3, testing"; + AMF::amf_element_t el = sol.getElement(0); + if ((name == el.name) && (memcmp(data, el.data, el.length) == 0)) { + runtest.pass("Read SOL File"); + } else { + runtest.fail("Read SOL file"); + } + sol.dump(); + } +} + +bool +test_write() +{ + +} + +// Test SOL files. These are shared Objects which are basically an AMF object with +// a header. These .sol files are used for transferring data, so we want to make +// sure they actually work. All numeric data is stored in big endian format. +bool +test_sol() +{ + struct stat st; + + string filespec = SRCDIR; + filespec += "/settings.sol"; + + if (stat(filespec.c_str(), &st) == 0) { + AMF amf_obj; + int fd, ret; + uint8_t *buf; + amfnum_t *num; + + buf = new uint8_t[st.st_size + 1]; + + memset(buf, 0, st.st_size+1); + fd = open(filespec.c_str(), O_RDONLY); + ret = read(fd, buf, st.st_size); + close(fd); + + num = amf_obj.extractNumber(buf); + + if ((((char *)num)[6] == -16) && (((char *)num)[7] == 0x3f)) { + runtest.pass("Extracted Number SOL object"); + } else { + runtest.fail("Extracted Number SOL object"); + } + + void *out = amf_obj.encodeNumber(*num); + + if (memcmp(out, buf, 9) == 0) { + runtest.pass("Encoded SOL Number"); + } else { + runtest.fail("Encoded SOL Number"); + } + delete num; + return true; + } + + runtest.untested("testfile not found"); + return false; +} + +static void +usage (void) +{ + cerr << "This program tests SOL support in the AMF library." << endl; + cerr << "Usage: test_sol [hv]" << endl; + cerr << "-h\tHelp" << endl; + cerr << "-v\tVerbose" << endl; + exit (-1); +} + +#else + +int +main(int /*argc*/, char /* *argv[]*/) +{ + // nop + return 0; +} + +#endif _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit