~ubuntu-branches/ubuntu/karmic/gnash/karmic

« back to all changes in this revision

Viewing changes to libamf/amftest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2008-10-13 14:29:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081013142949-f6qdvnu4mn05ltdc
Tags: 0.8.4~~bzr9980-0ubuntu1
* new upstream release 0.8.4 (LP: #240325)
* ship new lib usr/lib/gnash/libmozsdk.so.* in mozilla-plugin-gnash
  - update debian/mozilla-plugin-gnash.install
* ship new lib usr/lib/gnash/libgnashnet.so.* in gnash-common
  - update debian/gnash-common.install
* add basic debian/build_head script to build latest CVS head packages.
  - add debian/build_head
* new sound architecture requires build depend on libsdl1.2-dev
  - update debian/control
* head build script now has been completely migrated to bzr (upstream +
  ubuntu)
  - update debian/build_head
* disable kde gui until klash/qt4 has been fixed; keep kde packages as empty
  packages for now.
  - update debian/rules
  - debian/klash.install
  - debian/klash.links
  - debian/klash.manpages
  - debian/konqueror-plugin-gnash.install
* drop libkonq5-dev build dependency accordingly
  - update debian/control
* don't install headers manually anymore. gnash doesnt provide a -dev
  package after all
  - update debian/rules
* update libs installed in gnash-common; libgnashserver-*.so is not available
  anymore (removed); in turn we add the new libgnashcore-*.so
  - update debian/gnash-common.install
* use -Os for optimization and properly pass CXXFLAGS=$(CFLAGS) to configure
  - update debian/rules
* touch firefox .autoreg in postinst of mozilla plugin
  - update debian/mozilla-plugin-gnash.postinst
* link gnash in ubufox plugins directory for the plugin alternative switcher
  - add debian/mozilla-plugin-gnash.links
* suggest ubufox accordingly
  - update debian/control
* add new required build-depends on libgif-dev
  - update debian/control
* add Xb-Npp-Description and Xb-Npp-File as new plugin database meta data
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
3
// 
 
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.
 
8
// 
 
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.
 
13
// 
 
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
 
17
 
 
18
#ifdef HAVE_CONFIG_H
 
19
#include "gnashconfig.h"
 
20
#endif
 
21
 
 
22
#ifdef HAVE_DEJAGNU_H
 
23
 
 
24
#include <netinet/in.h>
 
25
#include <string>
 
26
#include <sys/types.h>
 
27
#include <unistd.h>
 
28
#include <sys/types.h>
 
29
#include <sys/stat.h>
 
30
#include <fcntl.h>
 
31
#include <log.h>
 
32
#include <iostream>
 
33
#include <string>
 
34
 
 
35
#include "dejagnu.h"
 
36
 
 
37
 
 
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
 
42
                                // when needed,
 
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
 
47
                                // when needed,
 
48
 
 
49
#include "amf.h"
 
50
 
 
51
using namespace amf;
 
52
using namespace gnash;
 
53
using namespace std;
 
54
 
 
55
static void usage (void);
 
56
 
 
57
static int verbosity;
 
58
 
 
59
TestState runtest;
 
60
 
 
61
void test_Number(void);
 
62
void test_Boolean(void);
 
63
void test_String(void);
 
64
 
 
65
void test_Header(void);
 
66
void test_Body(void);
 
67
void test_Packet(void);
 
68
 
 
69
int
 
70
main(int argc, char *argv[])
 
71
{
 
72
    bool dump = false;
 
73
    char buffer[300];
 
74
    int c, retries = 3;
 
75
 
 
76
    memset(buffer, 0, 300);
 
77
    
 
78
    while ((c = getopt (argc, argv, "hdvsm:")) != -1) {
 
79
        switch (c) {
 
80
          case 'h':
 
81
            usage ();
 
82
            break;
 
83
            
 
84
          case 'v':
 
85
            verbosity++;
 
86
            break;
 
87
            
 
88
          default:
 
89
            usage ();
 
90
            break;
 
91
        }
 
92
    }
 
93
    
 
94
    // get the file name from the command line
 
95
    if (optind < argc) {
 
96
        string filespec = argv[optind];
 
97
        cout << "Will use \"" << filespec << "\" for test " << endl;
 
98
    }
 
99
 
 
100
    test_Number();
 
101
    test_Boolean();
 
102
    test_String();
 
103
 
 
104
//     test_Header();
 
105
//     test_Body();
 
106
//     test_Packet();
 
107
}
 
108
 
 
109
void
 
110
test_Number(void)
 
111
{
 
112
    AMF amf_obj;
 
113
#if 0
 
114
    amfnum_t num = 123456789;
 
115
 
 
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");
 
121
    } else {
 
122
        runtest.fail("Number header not correct");
 
123
    }
 
124
    if (amf_obj.extractElementLength(out) == 8) {
 
125
        runtest.pass("Number length returned correct");
 
126
    } else {
 
127
        runtest.fail("Number length returned not correct");
 
128
    }
 
129
    
 
130
    char *numptr = (char *)&num;
 
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])
 
136
        ) {
 
137
        pass("Number swapped correct");
 
138
    } else {
 
139
        fail("Number swapped not correct");
 
140
    }
 
141
#endif
 
142
    int fd, ret;
 
143
    char buf[AMF_NUMBER_SIZE+1];
 
144
    amfnum_t value = 0xf03fL;
 
145
    amfnum_t *num;
 
146
    
 
147
    memset(buf, 0, AMF_NUMBER_SIZE+1);
 
148
    fd = open("number.amf", O_RDONLY);
 
149
    ret = read(fd, buf, 12);
 
150
    close(fd);
 
151
 
 
152
    num = amf_obj.extractNumber(buf);
 
153
 
 
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;
 
159
 
 
160
    if (((char *)num)[7] == 0x3f) {
 
161
//    if (memcmp(num, &value, AMF_NUMBER_SIZE) == 0) {
 
162
        runtest.pass("Extracted Number AMF object");
 
163
    } else {
 
164
        runtest.fail("Extracted Number AMF object");
 
165
    }
 
166
 
 
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;
 
170
 
 
171
//     hexify((unsigned char *)hexint, (unsigned char *)buf, 9, false);
 
172
//     cerr << "AMF buff number is: 0x" << hexint << endl;
 
173
 
 
174
    if (memcmp(out, buf, 9) == 0) {
 
175
        runtest.pass("Encoded AMF Number");
 
176
    } else {
 
177
        runtest.fail("Encoded AMF Number");
 
178
    }
 
179
 
 
180
    delete num;
 
181
}
 
182
 
 
183
void
 
184
test_Boolean(void)
 
185
{
 
186
    AMF amf_obj;
 
187
    bool bo = false;
 
188
 
 
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");
 
193
    } else {
 
194
        runtest.fail("Boolean header not correct");
 
195
    }
 
196
    if (amf_obj.extractElementLength(out) == 1) {
 
197
        runtest.pass("Boolean length returned correct");
 
198
    } else {
 
199
        runtest.fail("Boolean length returned not correct");
 
200
    }
 
201
    if (*((char *)out + 1) == 0) {
 
202
        pass("Boolean false returned correct");
 
203
    } else {
 
204
        runtest.fail("Boolean false returned not correct");
 
205
    }
 
206
    bo = true;
 
207
    out = amf_obj.encodeElement(AMF::BOOLEAN, &bo, 0);
 
208
    if (*((char *)out + 1) == 1) {
 
209
        runtest.pass("Boolean true returned correct");
 
210
    } else {
 
211
        runtest.fail("Boolean true returned not correct");
 
212
    }
 
213
}
 
214
 
 
215
// Make sure we can read and write binary AMF strings
 
216
void
 
217
test_String(void)
 
218
{
 
219
    AMF amf_obj;
 
220
    int fd, ret;
 
221
    char buf[AMF_VIDEO_PACKET_SIZE+1];
 
222
 
 
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);
 
228
    close(fd);
 
229
 
 
230
    char *str = amf_obj.extractString(buf);
 
231
    if (strcmp(str, "connect") == 0) {
 
232
        runtest.pass("Extracted \"connect\" string");
 
233
    } else {
 
234
        runtest.fail("Extracted \"connect\" string");
 
235
    }
 
236
 
 
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");
 
243
    } else {
 
244
        runtest.fail("Encoded \"connect\" string");
 
245
    }
 
246
 
 
247
    delete str;
 
248
}
 
249
 
 
250
#if 0
 
251
// Each header consists of the following:
 
252
//
 
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)
 
257
void
 
258
test_Header(void){
 
259
    AMF amf_obj;
 
260
    amfutf8_t name, headname;
 
261
    amfnum_t num;
 
262
    void *element;
 
263
    amfhead_t *head;
 
264
 
 
265
    note("Test the Header");
 
266
 
 
267
    num = 123456789;
 
268
 
 
269
    char *test = "NumberTest";
 
270
    name.length = strlen(test);
 
271
    name.data = test;
 
272
    
 
273
    element = amf_obj.encodeElement(AMF::NUMBER, &num, 0);
 
274
    head = amf_obj.encodeHeader(&name, true, sizeof(amfnum_t), &num);
 
275
 
 
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");
 
279
    } else {
 
280
        runtest.fail("Header name not correct");
 
281
    }
 
282
 
 
283
    ptr = ((char *)head) + 2 + name.length + 1;
 
284
    if (*ptr == AMF::NUMBER) {
 
285
        runtest.pass("Header Object type correct");
 
286
    } else {
 
287
        runtest.fail("Header Object type not correct");
 
288
    }
 
289
    
 
290
    ptr++;
 
291
    if (*ptr == htonl(num)) {
 
292
        runtest.pass("Header Object data correct");
 
293
    } else {
 
294
        runtest.fail("Header Object data not correct");
 
295
    }    
 
296
}
 
297
 
 
298
void
 
299
test_Body(void)
 
300
{
 
301
    AMF amf_obj;
 
302
    void *out;
 
303
 
 
304
    // Write a number element
 
305
    note("Test the Body");
 
306
}
 
307
 
 
308
void
 
309
test_Packet(void)
 
310
{
 
311
    AMF amf_obj;
 
312
    void *out;
 
313
 
 
314
    // Write a number element
 
315
    note("Test the Packet");
 
316
}
 
317
#endif
 
318
 
 
319
static void
 
320
usage (void)
 
321
{
 
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;
 
326
    exit (-1);
 
327
}
 
328
 
 
329
#endif