summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2010-01-24 21:28:04 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2010-01-24 21:28:04 +0000
commitbf36ea80c319f307831f38c069d4e67442e4e81b (patch)
tree68fd9ed962c1b52a7e1af80683b82687a2286201 /test
parent0b5081f1bb14a923877c83d472e2c1dbd1792277 (diff)
downloadlibnsfb-bf36ea80c319f307831f38c069d4e67442e4e81b.tar.gz
libnsfb-bf36ea80c319f307831f38c069d4e67442e4e81b.tar.bz2
Add test for self-crossing polygons.
svn path=/trunk/libnsfb/; revision=9904
Diffstat (limited to 'test')
-rw-r--r--test/Makefile2
-rw-r--r--test/polystar2.c102
-rwxr-xr-xtest/runtest.sh1
3 files changed, 104 insertions, 1 deletions
diff --git a/test/Makefile b/test/Makefile
index b408f4a..b2320e3 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,3 +1,3 @@
-DIR_TEST_ITEMS := plottest:plottest.c;nsglobe.c frontend:frontend.c bezier:bezier.c path:path.c polygon:polygon.c polystar:polystar.c
+DIR_TEST_ITEMS := plottest:plottest.c;nsglobe.c frontend:frontend.c bezier:bezier.c path:path.c polygon:polygon.c polystar:polystar.c polystar2:polystar2.c
include build/makefiles/Makefile.subdir
diff --git a/test/polystar2.c b/test/polystar2.c
new file mode 100644
index 0000000..0037f62
--- /dev/null
+++ b/test/polystar2.c
@@ -0,0 +1,102 @@
+/* libnsfb ploygon plotter test program */
+
+#define _POSIX_C_SOURCE 199506L
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "libnsfb.h"
+#include "libnsfb_plot.h"
+#include "libnsfb_event.h"
+
+
+#include <time.h>
+// Sleep milliseconds
+static void sleepMilli(long ms)
+{
+ const struct timespec ts = {ms / 1000, ms % 1000 * 1000000};
+ nanosleep(&ts, NULL);
+}
+
+#define UNUSED(x) ((x) = (x))
+
+
+int main(int argc, char **argv)
+{
+ nsfb_t *nsfb;
+ nsfb_event_t event;
+ nsfb_bbox_t box;
+ uint8_t *fbptr;
+ int fbstride;
+
+ int sides;
+ int radius;
+ nsfb_point_t *points;
+ int loop;
+ double rotate;
+ int counter;
+ int colour;
+
+ UNUSED(argc);
+ UNUSED(argv);
+
+ nsfb = nsfb_init(NSFB_FRONTEND_SDL);
+ if (nsfb == NULL) {
+ fprintf(stderr, "Unable to initialise nsfb with SDL frontend\n");
+ return 1;
+ }
+
+ if (nsfb_init_frontend(nsfb) == -1) {
+ fprintf(stderr, "Unable to initialise nsfb frontend\n");
+ return 2;
+ }
+
+ /* get the geometry of the whole screen */
+ box.x0 = box.y0 = 0;
+ nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);
+ nsfb_get_framebuffer(nsfb, &fbptr, &fbstride);
+
+ radius = (box.x1 / 3);
+ sides = 5;
+ counter = 0;
+
+ for (rotate = 0; rotate < (2 * M_PI); rotate += (M_PI / 4)) {
+ /* claim the whole screen for update */
+ nsfb_claim(nsfb, &box);
+
+ nsfb_plot_clg(nsfb, 0xffffffff);
+
+ points = malloc(sizeof(nsfb_point_t) * sides);
+
+ for (loop = 0; loop < sides;loop++) {
+ points[(2 * loop) % sides].x = (box.x1 / 2) +
+ (radius * cos(loop * 2 * M_PI / sides + rotate));
+ points[(2 * loop) % sides].y = (box.y1 / 2) +
+ (radius * sin(loop * 2 * M_PI / sides + rotate));
+ }
+
+ if (counter % 3 == 0)
+ colour = 0xffff0000;
+ else if (counter % 3 == 1)
+ colour = 0xff00ff00;
+ else
+ colour = 0xff0000ff;
+
+ nsfb_plot_polygon(nsfb, (const int *)points, sides, colour);
+ free(points);
+
+ if (counter % 2 == 0)
+ sides += 2;
+ counter++;
+
+ nsfb_update(nsfb, &box);
+ sleepMilli(400);
+ }
+
+ while (event.type != NSFB_EVENT_CONTROL)
+ nsfb_event(nsfb, &event, -1);
+
+ return 0;
+}
diff --git a/test/runtest.sh b/test/runtest.sh
index b9ab599..f2eb0a4 100755
--- a/test/runtest.sh
+++ b/test/runtest.sh
@@ -8,4 +8,5 @@ ${TEST_PATH}/test_bezier
${TEST_PATH}/test_path
${TEST_PATH}/test_polygon
${TEST_PATH}/test_polystar
+${TEST_PATH}/test_polystar2