1 //
2 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 //   Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 
19 #ifdef HAVE_CONFIG_H
20 #include "gnashconfig.h"
21 #endif
22 
23 #include "CodeStream.h"
24 #include "log.h"
25 
26 #include <iostream>
27 #include <sstream>
28 #include <cassert>
29 #include <cmath>
30 #include <string>
31 
32 #include "check.h"
33 
34 #include "utility.h"
35 
36 using namespace gnash;
37 using std::cout;
38 using std::endl;
39 
40 int
main(int,char **)41 main(int /*argc*/, char** /*argv*/)
42 {
43 	char data[10] = {0x4,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9};
44 
45 	CodeStream* stream = new CodeStream(std::string(data,10));
46 
47 	//Test read_as30p()
48 	std::uint8_t opcode;
49 	int i = 0;
50 	while(opcode = stream->read_as3op()){
51 		check_equals(opcode,data[i]);
52 		i++;
53 	}
54 
55 	//Make sure we stopped at the right spot.
56 	check_equals(i,10);
57 
58 	//Reset stream.
59 	stream->seekTo(0);
60 	stream->clear();
61 
62 	//Test seekTo
63 	stream->seekTo(5);
64 
65 	opcode = stream->read_as3op();
66 	check_equals(opcode,data[5]);
67 
68 	//Reset stream.
69 	stream->seekTo(0);
70 	stream->clear();
71 
72 	//Test read_u8.
73 	i=0;
74 	while(i<10){
75 		opcode = stream->read_u8();
76 		check_equals(opcode,data[i]);
77 		i++;
78 	}
79 
80 	char newData[6] = {0x5,0xC5,0x0,0x0,0x1,0x2};
81 	CodeStream* streamA = new CodeStream(std::string(newData,6));
82 
83 	std::uint8_t byteA = streamA->read_u8();
84 	check_equals(byteA,newData[0]);
85 
86 	//Test read_S24.
87 	std::int32_t byteB = streamA->read_S24();
88 	check_equals(byteB,197);
89 
90 
91 
92 	return 0;
93 }
94