2
// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
#include "gnashconfig.h"
24
#include <netinet/in.h>
26
#include <sys/types.h>
28
#include <sys/types.h>
38
bool gofast = false; // FIXME: this flag gets set based on
39
// an XML message written using
40
// SendCommand(""). This way a movie
41
// can optimize it's own performance
43
bool nodelay = false; // FIXME: this flag gets set based on
44
// an XML message written using
45
// SendCommand(""). This way a movie
46
// can optimize it's own performance
52
using namespace gnash;
55
static void usage (void);
61
void test_Number(void);
62
void test_Boolean(void);
63
void test_String(void);
65
void test_Header(void);
67
void test_Packet(void);
70
main(int argc, char *argv[])
76
memset(buffer, 0, 300);
78
while ((c = getopt (argc, argv, "hdvsm:")) != -1) {
94
// get the file name from the command line
96
string filespec = argv[optind];
97
cout << "Will use \"" << filespec << "\" for test " << endl;
114
amfnum_t num = 123456789;
116
// Write a number element
117
note("Test a Number element");
118
void *out = amf_obj.encodeElement(AMF::NUMBER, &num, 0);
119
if (amf_obj.extractElementHeader(out) == AMF::NUMBER) {
120
runtest.pass("Number header correct");
122
runtest.fail("Number header not correct");
124
if (amf_obj.extractElementLength(out) == 8) {
125
runtest.pass("Number length returned correct");
127
runtest.fail("Number length returned not correct");
130
char *numptr = (char *)#
131
char *outptr = (char *)out+1;
132
if ((numptr[0] == outptr[7]) && (numptr[1] == outptr[6])
133
&& (numptr[2] == outptr[5]) && (numptr[3] == outptr[4])
134
&& (numptr[4] == outptr[3]) && (numptr[5] == outptr[2])
135
&& (numptr[6] == outptr[1]) && (numptr[7] == outptr[0])
137
pass("Number swapped correct");
139
fail("Number swapped not correct");
143
char buf[AMF_NUMBER_SIZE+1];
144
amfnum_t value = 0xf03fL;
147
memset(buf, 0, AMF_NUMBER_SIZE+1);
148
fd = open("number.amf", O_RDONLY);
149
ret = read(fd, buf, 12);
152
num = amf_obj.extractNumber(buf);
154
// unsigned char hexint[32];
155
// hexify((unsigned char *)hexint, (unsigned char *)num, 8, false);
156
// cerr << "AMF number is: 0x" << hexint << endl;
157
// hexify((unsigned char *)hexint, (unsigned char *)&value, 8, false);
158
// cerr << "AMF value is: 0x" << hexint << endl;
160
if (((char *)num)[7] == 0x3f) {
161
// if (memcmp(num, &value, AMF_NUMBER_SIZE) == 0) {
162
runtest.pass("Extracted Number AMF object");
164
runtest.fail("Extracted Number AMF object");
167
void *out = amf_obj.encodeNumber(*num);
168
// hexify((unsigned char *)hexint, (unsigned char *)out, 9, false);
169
// cerr << "AMF encoded number is: 0x" << hexint << endl;
171
// hexify((unsigned char *)hexint, (unsigned char *)buf, 9, false);
172
// cerr << "AMF buff number is: 0x" << hexint << endl;
174
if (memcmp(out, buf, 9) == 0) {
175
runtest.pass("Encoded AMF Number");
177
runtest.fail("Encoded AMF Number");
189
// Write a number element
190
void *out = amf_obj.encodeElement(AMF::BOOLEAN, &bo, 0);
191
if (amf_obj.extractElementHeader(out) == AMF::BOOLEAN) {
192
runtest.pass("Boolean header correct");
194
runtest.fail("Boolean header not correct");
196
if (amf_obj.extractElementLength(out) == 1) {
197
runtest.pass("Boolean length returned correct");
199
runtest.fail("Boolean length returned not correct");
201
if (*((char *)out + 1) == 0) {
202
pass("Boolean false returned correct");
204
runtest.fail("Boolean false returned not correct");
207
out = amf_obj.encodeElement(AMF::BOOLEAN, &bo, 0);
208
if (*((char *)out + 1) == 1) {
209
runtest.pass("Boolean true returned correct");
211
runtest.fail("Boolean true returned not correct");
215
// Make sure we can read and write binary AMF strings
221
char buf[AMF_VIDEO_PACKET_SIZE+1];
223
// First see if we can read strings. This file is produced by
224
// using a network packet sniffer, and should be binary correct.
225
memset(buf, 0, AMF_VIDEO_PACKET_SIZE+1);
226
fd = open("string1.amf", O_RDONLY);
227
ret = read(fd, buf, AMF_VIDEO_PACKET_SIZE);
230
char *str = amf_obj.extractString(buf);
231
if (strcmp(str, "connect") == 0) {
232
runtest.pass("Extracted \"connect\" string");
234
runtest.fail("Extracted \"connect\" string");
237
// Now make sure we can also create strings. We'll create the same
238
// string we just read, and make sure they match.
239
char *connect = "connect";
240
void *out = amf_obj.encodeElement(AMF::STRING, connect, strlen(connect));
241
if (memcmp(out, buf, 10) == 0) {
242
runtest.pass("Encoded \"connect\" string");
244
runtest.fail("Encoded \"connect\" string");
251
// Each header consists of the following:
253
// * UTF string (including length bytes) - name
254
// * Boolean - specifies if understanding the header is `required'
255
// * Long - Length in bytes of header
256
// * Variable - Actual data (including a type code)
260
amfutf8_t name, headname;
265
note("Test the Header");
269
char *test = "NumberTest";
270
name.length = strlen(test);
273
element = amf_obj.encodeElement(AMF::NUMBER, &num, 0);
274
head = amf_obj.encodeHeader(&name, true, sizeof(amfnum_t), &num);
276
char *ptr = ((char *)head) + 2;
277
if ((strncmp(ptr, test, name.length) == 0) && (ntohs(*(short *)head) == name.length)) {
278
runtest.pass("Header name correct");
280
runtest.fail("Header name not correct");
283
ptr = ((char *)head) + 2 + name.length + 1;
284
if (*ptr == AMF::NUMBER) {
285
runtest.pass("Header Object type correct");
287
runtest.fail("Header Object type not correct");
291
if (*ptr == htonl(num)) {
292
runtest.pass("Header Object data correct");
294
runtest.fail("Header Object data not correct");
304
// Write a number element
305
note("Test the Body");
314
// Write a number element
315
note("Test the Packet");
322
cerr << "This program tests the AMF library." << endl;
323
cerr << "Usage: amftest [hv]" << endl;
324
cerr << "-h\tHelp" << endl;
325
cerr << "-v\tVerbose" << endl;