aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2012-09-03 09:02:31 +0200
committerThomas White <taw@bitwiz.org.uk>2012-09-03 09:02:31 +0200
commite855e14baa0c00bb0da4da1aef4d120f10c7a65e (patch)
tree2e46daa98cf0cea9abbaa01250cbd6df4070504c /tests
parent29978f93c0dba6a6a2b164168650620589667fa3 (diff)
"Finished" parser
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/render_test_sc1.c95
-rw-r--r--tests/storycode_test.c28
3 files changed, 122 insertions, 2 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 5549a63..b352eb3 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -3,3 +3,4 @@
.dirstamp
storycode_test
render_test
+render_test_sc1
diff --git a/tests/render_test_sc1.c b/tests/render_test_sc1.c
new file mode 100644
index 0000000..9cbf042
--- /dev/null
+++ b/tests/render_test_sc1.c
@@ -0,0 +1,95 @@
+/*
+ * render_test_sc1.c
+ *
+ * Colloquium - A tiny presentation program
+ *
+ * Copyright (c) 2012 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <gtk/gtk.h>
+#include <string.h>
+
+#include "../src/storycode.h"
+#include "../src/render.h"
+#include "../src/layout.h"
+#include "../src/stylesheet.h"
+
+
+static gint mw_destroy(GtkWidget *w, void *p)
+{
+ exit(0);
+}
+
+static gboolean draw_sig(GtkWidget *da, cairo_t *cr, struct frame *fr)
+{
+ PangoContext *pc;
+ GtkAllocation allocation;
+ gint w, h;
+
+ w = gtk_widget_get_allocated_width(da);
+ h = gtk_widget_get_allocated_height(da);
+
+ /* Overall background */
+ cairo_rectangle(cr, 0.0, 0.0, w, h);
+ cairo_set_source_rgb(cr, 0.9, 0.9, 0.9);
+ cairo_fill(cr);
+
+ pc = gtk_widget_get_pango_context(da);
+
+ gtk_widget_get_allocation(da, &allocation);
+
+ layout_frame(fr, allocation.width, allocation.height);
+ render_frame(fr, cr, pc);
+
+ return FALSE;
+}
+
+
+int main(int argc, char *argv[])
+{
+ GtkWidget *window;
+ GtkWidget *drawingarea;
+ struct frame *fr;
+
+ gtk_init(&argc, &argv);
+
+ fr = sc_unpack("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur.\\f{Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.} Wibble Wobble.");
+
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+ drawingarea = gtk_drawing_area_new();
+ gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(drawingarea));
+ gtk_widget_set_size_request(GTK_WIDGET(drawingarea), 320, 200);
+
+ g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(mw_destroy),
+ NULL);
+
+ g_signal_connect(G_OBJECT(drawingarea), "draw",
+ G_CALLBACK(draw_sig), fr);
+
+ gtk_widget_show_all(window);
+ gtk_main();
+
+ return 0;
+}
diff --git a/tests/storycode_test.c b/tests/storycode_test.c
index a39fa72..e9987ef 100644
--- a/tests/storycode_test.c
+++ b/tests/storycode_test.c
@@ -35,14 +35,38 @@ int main(int argc, char *argv[])
SCBlockList *bl;
SCBlockListIterator *iter;
struct scblock *b;
+ const char *tt = "\\bg[a=b]{wibble \\f{wobble}}\\bg{rwawr}Wobble"
+ "\\f{wibble \\bg[muhu]{wobble}}";
- bl = sc_find_blocks("\\bg{wibble \\f{wobble}}\\bg{rwawr}Wobble", "bg");
+ printf("'%s' ->\n", tt);
+ bl = sc_find_blocks(tt, "bg");
+
+ if ( bl == NULL ) {
+ printf("Failed to find blocks.\n");
+ return 1;
+ }
+
+ for ( b = sc_block_list_first(bl, &iter);
+ b != NULL;
+ b = sc_block_list_next(bl, iter) )
+ {
+ printf(" \\%s [%s] {%s}\n", b->name, b->options, b->contents);
+ }
+ sc_block_list_free(bl);
+
+ printf("->\n");
+ bl = sc_find_blocks(tt, NULL);
+
+ if ( bl == NULL ) {
+ printf("Failed to find blocks.\n");
+ return 1;
+ }
for ( b = sc_block_list_first(bl, &iter);
b != NULL;
b = sc_block_list_next(bl, iter) )
{
- printf("'%s'\n", b->contents);
+ printf(" \\%s [%s] {%s}\n", b->name, b->options, b->contents);
}
sc_block_list_free(bl);