Randomized test.

This commit is contained in:
Michael Jumper
2010-09-05 14:47:42 -07:00
parent be395f197b
commit 82cf348d95
3 changed files with 51 additions and 16 deletions

View File

@@ -26,6 +26,26 @@ void guac_close(GUACIO* io) {
free(io); free(io);
} }
ssize_t guac_write_int(GUACIO* io, unsigned int i) {
char buffer[128];
char* ptr = &(buffer[127]);
*ptr = 0;
do {
ptr--;
*ptr = '0' + (i % 10);
i /= 10;
} while (i > 0 && ptr >= buffer);
return guac_write_string(io, ptr);
}
ssize_t guac_write_string(GUACIO* io, const char* str) { ssize_t guac_write_string(GUACIO* io, const char* str) {
int fd = io->fd; int fd = io->fd;

View File

@@ -17,6 +17,7 @@ typedef struct GUACIO {
} GUACIO; } GUACIO;
GUACIO* guac_open(int fd); GUACIO* guac_open(int fd);
ssize_t guac_write_int(GUACIO* io, unsigned int i);
ssize_t guac_write_string(GUACIO* io, const char* str); ssize_t guac_write_string(GUACIO* io, const char* str);
ssize_t guac_write_base64(GUACIO* io, const void* buf, size_t count); ssize_t guac_write_base64(GUACIO* io, const void* buf, size_t count);
ssize_t guac_flush_base64(GUACIO* io); ssize_t guac_flush_base64(GUACIO* io);

View File

@@ -28,6 +28,8 @@ void proxy(int client_fd) {
int x, y; int x, y;
int test_index;
GUACIO* io = guac_open(client_fd); GUACIO* io = guac_open(client_fd);
/*** INIT ***/ /*** INIT ***/
@@ -35,6 +37,10 @@ void proxy(int client_fd) {
/* Allocate rows for PNG */ /* Allocate rows for PNG */
png_rows = (png_byte**) malloc(100 /* height */ * sizeof(png_byte*)); png_rows = (png_byte**) malloc(100 /* height */ * sizeof(png_byte*));
guac_write_string(io, "name:hello;size:1024,768;");
for (test_index=0; test_index<200; test_index++) {
/* For now, generate test white image */ /* For now, generate test white image */
for (y=0; y<100 /* height */; y++) { for (y=0; y<100 /* height */; y++) {
@@ -42,17 +48,21 @@ void proxy(int client_fd) {
png_rows[y] = row; png_rows[y] = row;
for (x=0; x<100 /* width */; x++) { for (x=0; x<100 /* width */; x++) {
*row++ = 0xFF; *row++ = random() % 0xFF;
*row++ = 0xFF;
*row++ = 0xFF; if (test_index % 2 == 0)
*row++ = random() % 0xFF;
else
*row++ = 0x00;
if (test_index % 3 == 0)
*row++ = random() % 0xFF;
else
*row++ = 0x00;
} }
} }
guac_write_string(io, "name:hello;size:1024,768;");
for (y=0; y<200; y++) {
/* Write image */ /* Write image */
/* Set up PNG writer */ /* Set up PNG writer */
@@ -91,7 +101,11 @@ void proxy(int client_fd) {
PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_DEFAULT
); );
guac_write_string(io, "png:0,0,"); guac_write_string(io, "png:");
guac_write_int(io, random()%1024);
guac_write_string(io, ",");
guac_write_int(io, random()%768);
guac_write_string(io, ",");
png_set_rows(png, png_info, png_rows); png_set_rows(png, png_info, png_rows);
png_write_png(png, png_info, PNG_TRANSFORM_IDENTITY, NULL); png_write_png(png, png_info, PNG_TRANSFORM_IDENTITY, NULL);