File: stream-nomem.c

package info (click to toggle)
netsurf 3.11-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 87,296 kB
  • sloc: ansic: 403,115; xml: 81,988; cpp: 6,246; perl: 4,605; makefile: 2,907; yacc: 2,246; python: 2,057; sh: 1,500; jsp: 1,156; lex: 623; javascript: 551; ruby: 329; asm: 326; lisp: 151; php: 6
file content (79 lines) | stat: -rw-r--r-- 2,067 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <string.h>

#include <parserutils/parserutils.h>
#include <parserutils/input/inputstream.h>

#include "utils/utils.h"

#include "testutils.h"

int main(int argc, char **argv)
{
	parserutils_inputstream *stream;

	/* This is specially calculated so that the inputstream is forced to 
	 * reallocate (it assumes that the inputstream's buffer chunk size 
	 * is 4k) */
#define BUFFER_SIZE (4096 + 4)
	uint8_t input_buffer[BUFFER_SIZE];
//	uint8_t *buffer;
//	size_t buflen;
	const uint8_t *c;
	size_t clen;

	UNUSED(argc);
	UNUSED(argv);

	/* Populate the buffer with something sane */
	memset(input_buffer, 'a', BUFFER_SIZE);
	/* Now, set up our test data */
	input_buffer[BUFFER_SIZE - 1] = '5';
	input_buffer[BUFFER_SIZE - 2] = '4';
	input_buffer[BUFFER_SIZE - 3] = '\xbd';
	input_buffer[BUFFER_SIZE - 4] = '\xbf';
	/* This byte will occupy the 4095th byte in the buffer and
	 * thus cause the entirety of U+FFFD to be buffered until after
	 * the buffer has been enlarged */
	input_buffer[BUFFER_SIZE - 5] = '\xef';
	input_buffer[BUFFER_SIZE - 6] = '3';
	input_buffer[BUFFER_SIZE - 7] = '2';
	input_buffer[BUFFER_SIZE - 8] = '1';

	assert(parserutils_inputstream_create("UTF-8", 0, 
			NULL, &stream) == PARSERUTILS_OK);

	assert(parserutils_inputstream_append(stream, 
			input_buffer, BUFFER_SIZE) == PARSERUTILS_OK);

	assert(parserutils_inputstream_append(stream, NULL, 0) == 
			PARSERUTILS_OK);

	while (parserutils_inputstream_peek(stream, 0, &c, &clen) != 
			PARSERUTILS_EOF)
		parserutils_inputstream_advance(stream, clen);

/*
	assert(css_inputstream_claim_buffer(stream, &buffer, &buflen) == 
			CSS_OK);

	assert(buflen == BUFFER_SIZE);

	printf("Buffer: '%.*s'\n", 8, buffer + (BUFFER_SIZE - 8));

	assert( buffer[BUFFER_SIZE - 6] == '3' && 
		buffer[BUFFER_SIZE - 5] == (uint8_t) '\xef' && 
		buffer[BUFFER_SIZE - 4] == (uint8_t) '\xbf' && 
		buffer[BUFFER_SIZE - 3] == (uint8_t) '\xbd' && 
		buffer[BUFFER_SIZE - 2] == '4');

	free(buffer);
*/

	parserutils_inputstream_destroy(stream);

	printf("PASS\n");

	return 0;
}