summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorTimo Dritschler <timo.dritschler@kit.edu>2014-08-29 14:06:44 +0200
committerTimo Dritschler <timo.dritschler@kit.edu>2014-08-29 14:06:44 +0200
commit4dff7a9ffb8355100482c9955bbb6889fe237bb4 (patch)
tree8f3dd0838b9485daa0037c3e3227363f276b489f /test
parentfc283a62d93fb5705cc955919ee109b2e915f912 (diff)
downloadkiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.tar.gz
kiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.tar.bz2
kiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.tar.xz
kiro-4dff7a9ffb8355100482c9955bbb6889fe237bb4.zip
Fix #6: Changed coding style to match UFO Project
Diffstat (limited to 'test')
-rw-r--r--test/test-client.c109
-rw-r--r--test/test-server.c179
-rw-r--r--test/test.c44
3 files changed, 176 insertions, 156 deletions
diff --git a/test/test-client.c b/test/test-client.c
index cdac3ee..45ce722 100644
--- a/test/test-client.c
+++ b/test/test-client.c
@@ -7,84 +7,85 @@
#include <assert.h>
-static _Bool init_app(const char * name, SDL_Surface * icon, uint32_t flags)
+static _Bool
+init_app (const char *name, SDL_Surface *icon, uint32_t flags)
{
- atexit(SDL_Quit);
- if(SDL_Init(flags) < 0)
- return 0;
+ atexit (SDL_Quit);
- SDL_WM_SetCaption(name, name);
- SDL_WM_SetIcon(icon, NULL);
+ if (SDL_Init (flags) < 0)
+ return 0;
+ SDL_WM_SetCaption (name, name);
+ SDL_WM_SetIcon (icon, NULL);
return 1;
}
-static void render(SDL_Surface * sf)
+static void
+render (SDL_Surface *sf)
{
- SDL_Surface * screen = SDL_GetVideoSurface();
- if(SDL_BlitSurface(sf, NULL, screen, NULL) == 0)
- SDL_UpdateRect(screen, 0, 0, 0, 0);
+ SDL_Surface *screen = SDL_GetVideoSurface();
+
+ if (SDL_BlitSurface (sf, NULL, screen, NULL) == 0)
+ SDL_UpdateRect (screen, 0, 0, 0, 0);
}
-static int filter(const SDL_Event * event)
-{ return event->type == SDL_QUIT; }
+static int
+filter (const SDL_Event *event)
+{
+ return event->type == SDL_QUIT;
+}
-int main ( int argc, char *argv[] )
+int
+main ( int argc, char *argv[] )
{
- if (argc < 3)
- {
- printf("Not enough aruments. Usage: ./client <address> <port>\n");
+ if (argc < 3) {
+ printf ("Not enough aruments. Usage: ./client <address> <port>\n");
return -1;
}
+
KiroClient *client = kiro_client_new ();
- if(-1 == kiro_client_connect(client, argv[1], argv[2]))
- {
- g_object_unref(client);
+
+ if (-1 == kiro_client_connect (client, argv[1], argv[2])) {
+ g_object_unref (client);
return -1;
}
-
- kiro_client_sync(client);
+
+ kiro_client_sync (client);
KiroTrb *trb = kiro_trb_new ();
- kiro_trb_adopt(trb, kiro_client_get_memory(client));
-
+ kiro_trb_adopt (trb, kiro_client_get_memory (client));
_Bool ok =
- init_app("UCA Images", NULL, SDL_INIT_VIDEO) &&
- SDL_SetVideoMode(512, 512, 8, SDL_HWSURFACE);
-
- assert(ok);
-
+ init_app ("UCA Images", NULL, SDL_INIT_VIDEO) &&
+ SDL_SetVideoMode (512, 512, 8, SDL_HWSURFACE);
+ assert (ok);
uint32_t mask = 0xffffffff;
- SDL_Surface * data_sf = SDL_CreateRGBSurfaceFrom(
- kiro_trb_get_element(trb, 0), 512, 512, 8, 512,
- mask, mask, mask, 0);
-
+ SDL_Surface *data_sf = SDL_CreateRGBSurfaceFrom (
+ kiro_trb_get_element (trb, 0), 512, 512, 8, 512,
+ mask, mask, mask, 0);
SDL_Color colors[256];
- for(int i=0;i<256;i++){
- colors[i].r=i;
- colors[i].g=i;
- colors[i].b=i;
- }
- SDL_SetPalette(data_sf, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256);
-
- SDL_SetEventFilter(filter);
-
+
+ for (int i = 0; i < 256; i++) {
+ colors[i].r = i;
+ colors[i].g = i;
+ colors[i].b = i;
+ }
+
+ SDL_SetPalette (data_sf, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256);
+ SDL_SetEventFilter (filter);
int cont = 1;
-
+
//struct KiroTrbInfo *header = (struct KiroTrbInfo *)kiro_trb_get_raw_buffer(trb);
-
- while(cont)
- {
- for(SDL_Event event; SDL_PollEvent(&event);)
- if(event.type == SDL_QUIT) cont=0;
-
- kiro_client_sync(client);
- SDL_Delay(10);
- render(data_sf);
+
+ while (cont) {
+ for (SDL_Event event; SDL_PollEvent (&event);)
+ if (event.type == SDL_QUIT) cont = 0;
+
+ kiro_client_sync (client);
+ SDL_Delay (10);
+ render (data_sf);
}
-
-
- g_object_unref(client);
+
+ g_object_unref (client);
return 0;
}
diff --git a/test/test-server.c b/test/test-server.c
index 9161122..2ed895b 100644
--- a/test/test-server.c
+++ b/test/test-server.c
@@ -12,65 +12,85 @@
static const char g_digits[10][20] = {
/* 0 */
- { 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0x00 },
+ {
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0xff, 0x00, 0x00, 0xff,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0x00
+ },
/* 1 */
- { 0x00, 0x00, 0xff, 0x00,
- 0x00, 0xff, 0xff, 0x00,
- 0x00, 0x00, 0xff, 0x00,
- 0x00, 0x00, 0xff, 0x00,
- 0x00, 0x00, 0xff, 0x00 },
+ {
+ 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0xff, 0xff, 0x00,
+ 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0x00, 0xff, 0x00
+ },
/* 2 */
- { 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0x00, 0xff, 0x00,
- 0x00, 0xff, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff },
+ {
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0xff, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0xff
+ },
/* 3 */
- { 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0x00, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0x00 },
+ {
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0x00
+ },
/* 4 */
- { 0xff, 0x00, 0x00, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0xff,
- 0x00, 0x00, 0x00, 0xff },
+ {
+ 0xff, 0x00, 0x00, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0xff, 0xff, 0xff, 0xff,
+ 0x00, 0x00, 0x00, 0xff,
+ 0x00, 0x00, 0x00, 0xff
+ },
/* 5 */
- { 0xff, 0xff, 0xff, 0xff,
- 0xff, 0x00, 0x00, 0x00,
- 0x00, 0xff, 0xff, 0x00,
- 0x00, 0x00, 0x00, 0xff,
- 0xff, 0xff, 0xff, 0x00 },
+ {
+ 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0x00, 0x00, 0x00,
+ 0x00, 0xff, 0xff, 0x00,
+ 0x00, 0x00, 0x00, 0xff,
+ 0xff, 0xff, 0xff, 0x00
+ },
/* 6 */
- { 0x00, 0xff, 0xff, 0xff,
- 0xff, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0x00 },
+ {
+ 0x00, 0xff, 0xff, 0xff,
+ 0xff, 0x00, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0x00
+ },
/* 7 */
- { 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0xff,
- 0x00, 0x00, 0xff, 0x00,
- 0x00, 0xff, 0x00, 0x00,
- 0xff, 0x00, 0x00, 0x00 },
+ {
+ 0xff, 0xff, 0xff, 0xff,
+ 0x00, 0x00, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0xff, 0x00, 0x00,
+ 0xff, 0x00, 0x00, 0x00
+ },
/* 8 */
- { 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0x00 },
+ {
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0x00
+ },
/* 9 */
- { 0x00, 0xff, 0xff, 0x00,
- 0xff, 0x00, 0x00, 0xff,
- 0x00, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0xff,
- 0xff, 0xff, 0xff, 0x00 }
+ {
+ 0x00, 0xff, 0xff, 0x00,
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0xff, 0xff,
+ 0x00, 0x00, 0x00, 0xff,
+ 0xff, 0xff, 0xff, 0x00
+ }
};
static const guint DIGIT_WIDTH = 4;
@@ -81,12 +101,14 @@ print_number (gchar *buffer, guint number, guint x, guint y, guint width)
{
for (int i = 0; i < DIGIT_WIDTH; i++) {
for (int j = 0; j < DIGIT_HEIGHT; j++) {
- char val = (char) g_digits[number][j*DIGIT_WIDTH+i];
- if(val != 0x00) {
+ char val = (char) g_digits[number][j * DIGIT_WIDTH + i];
+
+ if (val != 0x00) {
//This should make the frame counter appear in a bright yellow
val = 0xBE;
}
- buffer[(y+j)*width + (x+i)] = (guint8) val;
+
+ buffer[ (y + j)*width + (x + i)] = (guint8) val;
}
}
}
@@ -98,27 +120,26 @@ print_current_frame (gchar *buffer, guint number, guint width, guint height, GRa
int x = 1;
while (divisor > 0) {
- print_number(buffer, number / divisor, x, 1, width);
+ print_number (buffer, number / divisor, x, 1, width);
number = number % divisor;
divisor = divisor / 10;
x += DIGIT_WIDTH + 1;
}
-
//Rainbow pattern is the same for every row. Just calculate one single
//Scanline, so we can reuse it and dont have to do the whole calculation
//for every row again.
char default_line[width];
+
for (int p = 0; p < width; p++) {
- default_line[p] = (char) ((p*256) / (width));
+ default_line[p] = (char) ((p * 256) / (width));
}
-
//Use memcpy to quickly fill every row with the precalculated rainbow
//pattern
for (guint y = 16; y < height; y++) {
guint index = y * width;
- memcpy(buffer+index, &default_line[0], width);
+ memcpy (buffer + index, &default_line[0], width);
}
//This block will fill a square at the center of the image with normal
@@ -126,45 +147,45 @@ print_current_frame (gchar *buffer, guint number, guint width, guint height, GRa
const double mean = 128.0;
const double std = 32.0;
- for (guint y = (height/3); y < ((height*2)/3); y++) {
+ for (guint y = (height / 3); y < ((height * 2) / 3); y++) {
guint row_start = y * width;
- for (guint i = (width/3); i < ((width*2)/3); i++) {
+
+ for (guint i = (width / 3); i < ((width * 2) / 3); i++) {
int index = row_start + i;
- double u1 = g_rand_double(rand);
- double u2 = g_rand_double(rand);
- double r = sqrt(-2 * log(u1)) * cos(2 * G_PI * u2);
+ double u1 = g_rand_double (rand);
+ double u2 = g_rand_double (rand);
+ double r = sqrt (-2 * log (u1)) * cos (2 * G_PI * u2);
buffer[index] = (guint8) (r * std + mean);
}
}
}
-int main(void)
+int
+main (void)
{
KiroServer *server = kiro_server_new ();
KiroTrb *rb = kiro_trb_new ();
- kiro_trb_reshape(rb, 512*512, 15);
+ kiro_trb_reshape (rb, 512 * 512, 15);
GRand *rand = g_rand_new();
- if(0 > kiro_server_start(server, NULL, "60010", kiro_trb_get_raw_buffer(rb), kiro_trb_get_raw_size(rb)))
- {
- printf("Failed to start server properly.\n");
+
+ if (0 > kiro_server_start (server, NULL, "60010", kiro_trb_get_raw_buffer (rb), kiro_trb_get_raw_size (rb))) {
+ printf ("Failed to start server properly.\n");
goto done;
}
guint frame = 0;
gchar *buffer = NULL;
- while(1)
- {
- buffer = kiro_trb_dma_push(rb);
- print_current_frame(buffer, frame, 512, 512, rand);
+
+ while (1) {
+ buffer = kiro_trb_dma_push (rb);
+ print_current_frame (buffer, frame, 512, 512, rand);
frame++;
}
-
-
-done:
- g_rand_free(rand);
- g_object_unref(rb);
- g_object_unref(server);
- return 0;
+done:
+ g_rand_free (rand);
+ g_object_unref (rb);
+ g_object_unref (server);
+ return 0;
} \ No newline at end of file
diff --git a/test/test.c b/test/test.c
index 4aac2f5..c3e0028 100644
--- a/test/test.c
+++ b/test/test.c
@@ -7,10 +7,10 @@
struct test {
uint32_t zahl;
uint8_t buchstabe;
-} __attribute__((packed));
+} __attribute__ ((packed));
-int main(void)
+int main (void)
{
/*
void* ptr = malloc(sizeof(struct test) + sizeof(uint64_t));
@@ -19,33 +19,31 @@ int main(void)
foo.zahl = 42;
foo.buchstabe = 'R';
memcpy(ptr, &foo, sizeof(foo));
-
+
struct test *tmp = (struct test *)ptr;
printf("Zahl = %d\n",tmp->zahl);
printf("Buchstabe = %c\n", tmp->buchstabe);
printf("Remaining = %x\n", *((uint64_t *)(ptr+sizeof(struct test))));
*/
-
- KiroTrb *rb = g_object_new(KIRO_TYPE_TRB, NULL);
- kiro_trb_reshape(rb, sizeof(uint64_t), 3);
- void *buffer = kiro_trb_get_raw_buffer(rb);
+ KiroTrb *rb = g_object_new (KIRO_TYPE_TRB, NULL);
+ kiro_trb_reshape (rb, sizeof (uint64_t), 3);
+ void *buffer = kiro_trb_get_raw_buffer (rb);
uint64_t foo = 0xAFFED00F;
uint64_t bar = 0x1337BEEF;
- memcpy(kiro_trb_dma_push(rb), &foo, sizeof(foo));
- memcpy(kiro_trb_dma_push(rb), &foo, sizeof(foo));
- memcpy(kiro_trb_dma_push(rb), &foo, sizeof(foo));
- kiro_trb_push(rb, &bar);
- kiro_trb_push(rb, &foo);
- kiro_trb_push(rb, &foo);
- uint64_t *maman = kiro_trb_get_element(rb, 3);
- printf("Stored in old: %x\n", *maman);
- KiroTrb *rb2 = g_object_new(KIRO_TYPE_TRB, NULL);
- kiro_trb_clone(rb2, kiro_trb_get_raw_buffer(rb));
- maman = kiro_trb_get_element(rb2, 3);
- printf("Stored in New: %x\n", *maman);
- sleep(1);
- g_object_unref(rb);
- g_object_unref(rb2);
-
+ memcpy (kiro_trb_dma_push (rb), &foo, sizeof (foo));
+ memcpy (kiro_trb_dma_push (rb), &foo, sizeof (foo));
+ memcpy (kiro_trb_dma_push (rb), &foo, sizeof (foo));
+ kiro_trb_push (rb, &bar);
+ kiro_trb_push (rb, &foo);
+ kiro_trb_push (rb, &foo);
+ uint64_t *maman = kiro_trb_get_element (rb, 3);
+ printf ("Stored in old: %x\n", *maman);
+ KiroTrb *rb2 = g_object_new (KIRO_TYPE_TRB, NULL);
+ kiro_trb_clone (rb2, kiro_trb_get_raw_buffer (rb));
+ maman = kiro_trb_get_element (rb2, 3);
+ printf ("Stored in New: %x\n", *maman);
+ sleep (1);
+ g_object_unref (rb);
+ g_object_unref (rb2);
return 0;
} \ No newline at end of file