From 82cf348d951f13d27178c32010d05a14d626e70f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 5 Sep 2010 14:47:42 -0700 Subject: [PATCH] Randomized test. --- guacamole/proxy/guacio.c | 20 +++++++++++++++++ guacamole/proxy/guacio.h | 1 + guacamole/proxy/proxy.c | 46 ++++++++++++++++++++++++++-------------- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/guacamole/proxy/guacio.c b/guacamole/proxy/guacio.c index accf41034..f04dffc6d 100644 --- a/guacamole/proxy/guacio.c +++ b/guacamole/proxy/guacio.c @@ -26,6 +26,26 @@ void guac_close(GUACIO* 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) { int fd = io->fd; diff --git a/guacamole/proxy/guacio.h b/guacamole/proxy/guacio.h index 7d0343061..680492849 100644 --- a/guacamole/proxy/guacio.h +++ b/guacamole/proxy/guacio.h @@ -17,6 +17,7 @@ typedef struct GUACIO { } GUACIO; 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_base64(GUACIO* io, const void* buf, size_t count); ssize_t guac_flush_base64(GUACIO* io); diff --git a/guacamole/proxy/proxy.c b/guacamole/proxy/proxy.c index 0cd03c43d..7464b6c57 100644 --- a/guacamole/proxy/proxy.c +++ b/guacamole/proxy/proxy.c @@ -28,6 +28,8 @@ void proxy(int client_fd) { int x, y; + int test_index; + GUACIO* io = guac_open(client_fd); /*** INIT ***/ @@ -35,23 +37,31 @@ void proxy(int client_fd) { /* Allocate rows for PNG */ png_rows = (png_byte**) malloc(100 /* height */ * sizeof(png_byte*)); - /* For now, generate test white image */ - for (y=0; y<100 /* height */; y++) { - - row = (png_byte*) malloc(sizeof(png_byte) * 3 * 100 /* width */); - png_rows[y] = row; - - for (x=0; x<100 /* width */; x++) { - *row++ = 0xFF; - *row++ = 0xFF; - *row++ = 0xFF; - } - } - - guac_write_string(io, "name:hello;size:1024,768;"); - for (y=0; y<200; y++) { + for (test_index=0; test_index<200; test_index++) { + + /* For now, generate test white image */ + for (y=0; y<100 /* height */; y++) { + + row = (png_byte*) malloc(sizeof(png_byte) * 3 * 100 /* width */); + png_rows[y] = row; + + for (x=0; x<100 /* width */; x++) { + *row++ = random() % 0xFF; + + if (test_index % 2 == 0) + *row++ = random() % 0xFF; + else + *row++ = 0x00; + + if (test_index % 3 == 0) + *row++ = random() % 0xFF; + else + *row++ = 0x00; + + } + } /* Write image */ @@ -91,7 +101,11 @@ void proxy(int client_fd) { 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_write_png(png, png_info, PNG_TRANSFORM_IDENTITY, NULL);