diff options
author | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-12-10 22:30:12 +0100 |
---|---|---|
committer | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-12-10 22:30:12 +0100 |
commit | 429d5f88b94ff28416cbfc6420b6389fa284df97 (patch) | |
tree | fb6fdaf7731de1ef396f98b748c56f3149801c84 /tests |
Import RTFL 0.1.1v0.1.1
Diffstat (limited to 'tests')
31 files changed, 1765 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..e63bcbc --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,137 @@ +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + -DCUR_WORKING_DIR='"@BASE_CUR_WORKING_DIR@/tests"' + +noinst_PROGRAMS = \ + rtfl-cat \ + rtfl-trickle \ + test-pipes-1 \ + test-select-1 \ + test-version-cmp \ + test-fltk-1 \ + test-fltk-2 \ + test-rtfl-objects-1-without-rtfl \ + test-rtfl-objects-1-with-rtfl \ + test-rtfl-objects-2-without-rtfl \ + test-rtfl-objects-2-with-rtfl \ + test-rtfl-objects-3-without-rtfl \ + test-rtfl-objects-3-with-rtfl \ + test-rtfl-stats-1-without-rtfl \ + test-rtfl-stats-1-with-rtfl \ + test-tools-1 \ + test-tools-2 \ + test-tools-3 \ + test-tools-4 \ + test-tools-5 \ + test-tools-6 \ + test-widgets-1 \ + test-widgets-2 \ + test-widgets-3 \ + test-widget-b-splines + +if HAS_GRAPHVIZ +noinst_PROGRAMS += \ + test-graphviz-1 +endif + +rtfl_cat_SOURCES = rtfl_cat.c + +rtfl_trickle_SOURCES = rtfl_trickle.c + +test_pipes_1_SOURCES = test_pipes_1.c + +test_select_1_SOURCES = test_select_1.c + +test_version_cmp_SOURCES = test_version_cmp.c + +test_fltk_1_SOURCES = test_fltk_1.cc +test_fltk_1_LDADD = @LIBFLTK_LIBS@ + +test_fltk_2_SOURCES = test_fltk_2.cc +test_fltk_2_LDADD = @LIBFLTK_LIBS@ + +test_graphviz_1_SOURCES = test_graphviz_1.c +test_graphviz_1_LDADD = @GRAPHVIZ_LIBS@ + +test_rtfl_objects_1_without_rtfl_SOURCES = test_rtfl_objects_1.cc +test_rtfl_objects_1_without_rtfl_LDADD = ../lout/liblout.a +test_rtfl_objects_1_with_rtfl_SOURCES = test_rtfl_objects_1_with_rtfl.cc +test_rtfl_objects_1_with_rtfl_LDADD = ../lout/liblout.a + +test_rtfl_objects_2_without_rtfl_SOURCES = test_rtfl_objects_2.cc +test_rtfl_objects_2_with_rtfl_SOURCES = test_rtfl_objects_2_with_rtfl.cc + +test_rtfl_objects_3_without_rtfl_SOURCES = test_rtfl_objects_3.cc +test_rtfl_objects_3_with_rtfl_SOURCES = test_rtfl_objects_3_with_rtfl.cc + +test_rtfl_stats_1_without_rtfl_SOURCES = test_rtfl_stats_1.cc +test_rtfl_stats_1_without_rtfl_LDADD = ../lout/liblout.a +test_rtfl_stats_1_with_rtfl_SOURCES = test_rtfl_stats_1_with_rtfl.cc +test_rtfl_stats_1_with_rtfl_LDADD = ../lout/liblout.a + +test_tools_1_SOURCES = test_tools_1.cc +test_tools_1_LDADD = \ + ../common/librtfl-tools.a \ + ../lout/liblout.a + +test_tools_2_SOURCES = test_tools_2.cc simple_sink.hh simple_sink.cc \ + testtools.hh testtools.cc +test_tools_2_LDADD = \ + ../common/librtfl-tools.a \ + ../lout/liblout.a + +test_tools_3_SOURCES = test_tools_3.cc simple_sink.hh simple_sink.cc +test_tools_3_LDADD = \ + ../common/librtfl-tools.a \ + ../lout/liblout.a + +test_tools_4_SOURCES = test_tools_4.cc simple_sink.hh simple_sink.cc \ + testtools.hh testtools.cc +test_tools_4_LDADD = \ + ../common/librtfl-tools.a \ + ../lout/liblout.a + +test_tools_5_SOURCES = test_tools_5.cc simple_sink.hh simple_sink.cc \ + testtools.hh testtools.cc +test_tools_5_LDADD = \ + ../common/librtfl-tools.a \ + ../lout/liblout.a + +test_tools_6_SOURCES = test_tools_6.cc simple_sink.hh simple_sink.cc \ + testtools.hh testtools.cc +test_tools_6_LDADD = \ + ../common/librtfl-tools.a \ + ../lout/liblout.a + +test_widgets_1_SOURCES = test_widgets_1.cc +test_widgets_1_LDADD = \ + ../dwr/libDw-rtfl.a \ + ../dw/libDw-fltk.a \ + ../dw/libDw-core.a \ + ../lout/liblout.a \ + @LIBFLTK_LIBS@ + +test_widgets_2_SOURCES = test_widgets_2.cc +test_widgets_2_LDADD = \ + ../dwr/libDw-rtfl.a \ + ../dw/libDw-fltk.a \ + ../dw/libDw-core.a \ + ../lout/liblout.a \ + @LIBFLTK_LIBS@ + +test_widgets_3_SOURCES = test_widgets_3.cc +test_widgets_3_LDADD = \ + ../dwr/libDw-rtfl.a \ + ../dw/libDw-fltk.a \ + ../dw/libDw-core.a \ + ../lout/liblout.a \ + @LIBFLTK_LIBS@ + +test_widget_b_splines_SOURCES = test_widget_b_splines.cc +test_widget_b_splines_LDADD = \ + ../dwr/libDw-rtfl.a \ + ../dw/libDw-fltk.a \ + ../dw/libDw-core.a \ + ../lout/liblout.a \ + @LIBFLTK_LIBS@ + diff --git a/tests/rtfl_cat.c b/tests/rtfl_cat.c new file mode 100644 index 0000000..65d2e06 --- /dev/null +++ b/tests/rtfl_cat.c @@ -0,0 +1,53 @@ +/* + * RTFL + * + * Copyright 2014 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +/* + * Simply copy stdin to stdout, with some debug messages printed to + * stderr. Used to test rtfl-tee. + */ + +#include <unistd.h> +#include <stdio.h> +#include <stdarg.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> + +static void syserr (const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + vfprintf (stderr, fmt, args); + fprintf (stderr, ": %s\n", strerror (errno)); + exit (1); +} + +int main (int argc, char *argv[]) +{ + char buf[2048]; + ssize_t n; + + do { + if ((n = read (0, buf, sizeof (buf))) == -1) syserr ("read failed"); + fprintf (stderr, "==> [%s] n = %d\n", argv[0], (int)n); + if (write (1, buf, n) == -1) syserr ("write failed"); + } while (n > 0); + + return 0; +} diff --git a/tests/rtfl_trickle.c b/tests/rtfl_trickle.c new file mode 100644 index 0000000..391534e --- /dev/null +++ b/tests/rtfl_trickle.c @@ -0,0 +1,55 @@ +/* + * RTFL + * + * Copyright 2014 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +/* + * Simply copy stdin to stdout, but slowly character by character. + * Used to test rtfl-tee. + */ + +#include <unistd.h> +#include <stdio.h> +#include <stdarg.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> + +static void syserr (const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + vfprintf (stderr, fmt, args); + fprintf (stderr, ": %s\n", strerror (errno)); + exit (1); +} + +int main (int argc, char *argv[]) +{ + char buf[2048]; + ssize_t n, i; + + do { + if ((n = read (0, buf, sizeof (buf))) == -1) syserr ("read failed"); + for (i = 0; i < n; i++) { + if (write (1, buf + i, 1) == -1) syserr ("write failed"); + usleep (250000); + } + } while (n > 0); + + return 0; +} diff --git a/tests/simple_sink.cc b/tests/simple_sink.cc new file mode 100644 index 0000000..d27fd18 --- /dev/null +++ b/tests/simple_sink.cc @@ -0,0 +1,61 @@ +#include "simple_sink.hh" +#include "common/tools.hh" + +#include <unistd.h> +#include <sys/timeb.h> + +namespace rtfl { + +namespace tests { + +using namespace rtfl::tools; + +SimpleSink::SimpleSink () +{ + startTime = getCurrentTime (); + msg ("<init>"); +} + +void SimpleSink::setLinesSource (LinesSource *source) +{ + msg ("setLinesSource: souce = %p", source); +} + +void SimpleSink::processLine (char *line) +{ + msg ("processLine: %s", line); +} + +void SimpleSink::timeout (int type) +{ + msg ("timeout: type = %d", type); +} + +void SimpleSink::finish () +{ + msg ("finish"); +} + +long SimpleSink::getCurrentTime () +{ + struct timeb t; + if (ftime (&t) == -1) + syserr ("ftime() failed"); + return t.time * 1000L + t.millitm; +} + +void SimpleSink::msg (const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + + long time = getCurrentTime () - startTime; + printf ("[SimpleSink] %2ld.%03ld -- ", time / 1000, time % 1000); + + vprintf (fmt, args); + putchar ('\n'); +} + +} // namespace tests + +} // namespace rtfl diff --git a/tests/simple_sink.hh b/tests/simple_sink.hh new file mode 100644 index 0000000..fb0a87a --- /dev/null +++ b/tests/simple_sink.hh @@ -0,0 +1,30 @@ +#ifndef __TESTS_SIMPLE_SINK_HH__ +#define __TESTS_SIMPLE_SINK_HH__ + +#include "common/lines.hh" + +namespace rtfl { + +namespace tests { + +class SimpleSink: public rtfl::tools::LinesSink { +private: + long getCurrentTime (); + void msg (const char *fmt, ...); + + long startTime; + +public: + SimpleSink (); + + void setLinesSource (rtfl::tools::LinesSource *source); + void processLine (char *line); + void timeout (int type); + void finish (); +}; + +} // namespace tests + +} // namespace rtfl + +#endif // __TESTS_SIMPLE_SINK_HH__ diff --git a/tests/test_fltk_1.cc b/tests/test_fltk_1.cc new file mode 100644 index 0000000..84d1cac --- /dev/null +++ b/tests/test_fltk_1.cc @@ -0,0 +1,64 @@ +/* + * RTFL + * + * Copyright 2014, 2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +#include <FL/Fl_Window.H> +#include <FL/Fl_Menu_Bar.H> +#include <FL/Fl_Menu_Item.H> +#include <FL/Fl.H> + +Fl_Window *window; +Fl_Menu_Bar *menu; + +static void changed (Fl_Widget *widget, void *data); + +Fl_Menu_Item menuItems[] = { + { "&Week", 0, 0, 0, FL_SUBMENU, 0, 0, 0, 0 }, + { "Monday", 0, changed, NULL, FL_MENU_TOGGLE, 0, 0, 0, 0 }, + { "Tuesday", 0, changed, NULL, FL_MENU_TOGGLE, 0, 0, 0, 0 }, + { "Wednesday", 0, changed, NULL, FL_MENU_TOGGLE, 0, 0, 0, 0 }, + { "Thursday", 0, changed, NULL, FL_MENU_TOGGLE, 0, 0, 0, 0 }, + { "Friday", 0, changed, NULL, FL_MENU_TOGGLE, 0, 0, 0, 0 }, + { "Saturday", 0, changed, NULL, FL_MENU_TOGGLE, 0, 0, 0, 0 }, + { "Sunday", 0, changed, NULL, FL_MENU_TOGGLE, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0 } + }; + +void changed (Fl_Widget *widget, void *data) +{ + printf ("Monday: %s\n", + menu->find_item("&Week/Monday")->value () ? "set" : "clear"); + printf ("Tuesday: %s\n", + menu->find_item("&Week/Tuesday")->value () ? "set" : "clear"); + printf ("etc.\n"); +} + +int main(int argc, char **argv) +{ + window = new Fl_Window(100, 24, "FLTK Test 1"); + window->box(FL_NO_BOX); + window->begin(); + + menu = new Fl_Menu_Bar(0, 0, 100, 24); + menu->copy(menuItems); + + window->show(); + int errorCode = Fl::run(); + return errorCode; +} diff --git a/tests/test_fltk_2.cc b/tests/test_fltk_2.cc new file mode 100644 index 0000000..6dacce3 --- /dev/null +++ b/tests/test_fltk_2.cc @@ -0,0 +1,47 @@ +/* + * RTFL + * + * Copyright 2014, 2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +#include <FL/Fl_Window.H> +#include <FL/Fl_Hold_Browser.H> +#include <FL/Fl.H> + +Fl_Window *window; +Fl_Hold_Browser *browser; + +int main(int argc, char **argv) +{ + window = new Fl_Window(500, 500, "FLTK Test 2"); + window->begin(); + + browser = new Fl_Hold_Browser (0, 0, 500, 500, NULL); + + for (int n = 0; n < 255; n++) { + char buf[256]; + + snprintf (buf, sizeof(buf), "@B%d@.0x%02x - %d", n, n, n); + browser->add (buf, NULL); + + snprintf (buf, sizeof(buf), "@i@B%d@.0x%02x - %d", n, n, n); + browser->add (buf, NULL); + } + + window->show(); + int errorCode = Fl::run(); + return errorCode; +} diff --git a/tests/test_graphviz_1.c b/tests/test_graphviz_1.c new file mode 100644 index 0000000..9199b25 --- /dev/null +++ b/tests/test_graphviz_1.c @@ -0,0 +1,46 @@ +#include <graphviz/gvc.h> + +int main(int argc, char *argv[]) +{ + Agnode_t *node1, *node2; + Agedge_t *edge1; + Agraph_t *graph; + GVC_t *gvc; + + gvc = gvContext (); + graph = agopen ("graph", Agdirected, NULL); + + node1 = agnode(graph, "node1", TRUE); + agsafeset (node1, "width", "1", ""); + agsafeset (node1, "height", "1", ""); + + node2 = agnode(graph, "node2", TRUE); + agsafeset (node2, "width", "1", ""); + agsafeset (node2, "height", "1", ""); + + edge1 = agedge(graph, node1, node2, "edge1", TRUE); + + puts ("---------- initially ----------"); + agwrite (graph, stdout); + + gvLayout (gvc, graph, "dot"); + gvRender(gvc, graph, "dot", NULL); + gvFreeLayout(gvc, graph); + + puts ("---------- after first layouting ----------"); + agwrite (graph, stdout); + + agsafeset (node2, "height", "2", ""); + + gvLayout (gvc, graph, "dot"); + gvRender(gvc, graph, "dot", NULL); + gvFreeLayout(gvc, graph); + + puts ("---------- after second layouting ----------"); + agwrite (graph, stdout); + + agclose (graph); + gvFreeContext(gvc); + + return 0; +} diff --git a/tests/test_pipes_1.c b/tests/test_pipes_1.c new file mode 100644 index 0000000..89e3256 --- /dev/null +++ b/tests/test_pipes_1.c @@ -0,0 +1,76 @@ +/* + * RTFL + * + * Copyright 2014 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +#include <unistd.h> +#include <stdio.h> +#include <stdarg.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <sys/select.h> + +static void syserr (const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + vfprintf (stderr, fmt, args); + fprintf (stderr, ": %s\n", strerror (errno)); + exit (1); +} + +int main (int argc, char *argv[]) +{ + int parent2child[2]; + char buf[2048]; + ssize_t n; + + if (pipe (parent2child) == -1) syserr ("pipe failed"); + + switch (fork ()) { + case -1: + syserr ("fork failed"); + break; + + case 0: + if (close (parent2child[1]) == -1) + syserr ("close(%d) failed", parent2child[0]); + if (close (0) == -1) syserr ("close(0) failed"); + if (dup2 (parent2child[0], 0) == -1) + syserr ("dup2(%d, 0) failed", parent2child[0]); + if (close (parent2child[0]) == -1) + syserr ("close(%d) failed", parent2child[0]); + + do { + if ((n = read (0, buf, sizeof (buf))) == -1) syserr ("read failed"); + fprintf (stderr, "[child] %d bytes read\n", (int)n); + } while (n > 0); + break; + + default: + if (close (parent2child[0]) == -1) + syserr ("close(%d) failed", parent2child[0]); + if (write (parent2child[1], "Hi!", 3) == -1) syserr ("write failed"); + if (close (parent2child[1]) == -1) + syserr ("close(%d) failed", parent2child[0]); + + break; + } + + return 0; +} diff --git a/tests/test_rtfl_objects_1.cc b/tests/test_rtfl_objects_1.cc new file mode 100644 index 0000000..11e16c4 --- /dev/null +++ b/tests/test_rtfl_objects_1.cc @@ -0,0 +1,118 @@ +/* + * RTFL + * + * Copyright 2013-2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +#include <stdlib.h> +#include "debug_rtfl.hh" +#include "lout/object.hh" +#include "lout/container.hh" + +using namespace lout::object; +using namespace lout::container::typed; + +class A +{ +private: + A *other; + List<Integer> *numbers; + +public: + A (); + ~A (); + void setOther (A *other); + int doSomething (int n); +}; + +class B: public A +{ +public: + B (); +}; + +class C: public A +{ +public: + C (); +}; + + +A::A () +{ + DBG_OBJ_CREATE ("A"); + + other = NULL; + numbers = new List<Integer> (true); +} + +A::~A () +{ + delete numbers; +} + +void A::setOther (A *other) +{ + DBG_OBJ_ASSOC_CHILD (other); + + this->other = other; +} + +int A::doSomething (int n) +{ + DBG_OBJ_ENTER ("", 0, "doSomething", "%d", n); + + DBG_OBJ_MSGF ("", 0, "some message: n = %d", n); + + int r = random () % 251; + numbers->append (new Integer (r)); + DBG_OBJ_ARRSET_NUM ("numbers", numbers->size () - 1, r); + + if (other && n > 0) + other->doSomething (n - 1); + + DBG_OBJ_LEAVE_VAL ("%d", r); + return r; +} + +B::B () +{ + DBG_OBJ_CREATE ("B"); +} + +C::C () +{ + DBG_OBJ_CREATE ("C"); +} + +int main (int argc, char *argv[]) +{ + DBG_OBJ_CLASS_COLOR ("A", "#ffa0a0"); + DBG_OBJ_CLASS_COLOR ("B", "#60ff60"); + DBG_OBJ_CLASS_COLOR ("C", "#b0b0ff"); + + A x; + B y; + C z; + + x.setOther (&y); + y.setOther (&z); + z.setOther (&x); + + x.doSomething (8); + + return 0; +} diff --git a/tests/test_rtfl_objects_1_with_rtfl.cc b/tests/test_rtfl_objects_1_with_rtfl.cc new file mode 100644 index 0000000..c1eb983 --- /dev/null +++ b/tests/test_rtfl_objects_1_with_rtfl.cc @@ -0,0 +1,2 @@ +#define DBG_RTFL +#include "test_rtfl_objects_1.cc" diff --git a/tests/test_rtfl_objects_2.cc b/tests/test_rtfl_objects_2.cc new file mode 100644 index 0000000..1cd134e --- /dev/null +++ b/tests/test_rtfl_objects_2.cc @@ -0,0 +1,69 @@ +/* + * RTFL + * + * Copyright 2013-2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +#include <stdlib.h> +#include "../debug_rtfl.hh" + +class A +{ +private: + int a; + +public: + inline A (int a) { DBG_OBJ_CREATE ("x::A"); this->a = a; } + inline void behaveAsA () { DBG_OBJ_MSGF ("", 0, "behaveAsA: a = %d", a); } +}; + +class B +{ +private: + int b; + +public: + inline B (int b) { DBG_OBJ_CREATE ("y::B"); this->b = b; } + inline void behaveAsB () { DBG_OBJ_MSGF ("", 0, "behaveAsB: b = %d", b); } +}; + +class C: public A, public B +{ +private: + int c; + +public: + inline C (int c): A (c / 3), B (c / 2) { + DBG_OBJ_CREATE ("z::C"); + DBG_OBJ_BASECLASS (A); + DBG_OBJ_BASECLASS (B); + this->c = c; + } + inline void behaveAsC () { DBG_OBJ_MSGF ("", 0, "behaveAsC: c = %d", c); } +}; + + +int main (int argc, char *argv[]) +{ + DBG_OBJ_CLASS_COLOR ("x::A", "#c0ff80"); + DBG_OBJ_CLASS_COLOR ("y::B", "#c0c0ff"); + DBG_OBJ_CLASS_COLOR ("z::C", "#ffa0a0"); + + C c (6); + c.behaveAsA (); + c.behaveAsB (); + c.behaveAsC (); +} diff --git a/tests/test_rtfl_objects_2_with_rtfl.cc b/tests/test_rtfl_objects_2_with_rtfl.cc new file mode 100644 index 0000000..2158044 --- /dev/null +++ b/tests/test_rtfl_objects_2_with_rtfl.cc @@ -0,0 +1,2 @@ +#define DBG_RTFL +#include "test_rtfl_objects_2.cc" diff --git a/tests/test_rtfl_objects_3.cc b/tests/test_rtfl_objects_3.cc new file mode 100644 index 0000000..6cbeb4f --- /dev/null +++ b/tests/test_rtfl_objects_3.cc @@ -0,0 +1,85 @@ +/* + * RTFL + * + * Copyright 2014, 2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +#include <stdlib.h> +#include "../debug_rtfl.hh" + +class A +{ +private: + A *otherA; + +public: + A (); + ~A (); + void setOtherA (A *newOtherA); + void doSomething (int level); + void doActualStuff (); +}; + +A::A () +{ + DBG_OBJ_CREATE ("A"); + otherA = NULL; +} + +A::~A () +{ + DBG_OBJ_DELETE (); +} + +void A::setOtherA (A *newOtherA) +{ + DBG_OBJ_ENTER ("all", 0, "setOtherA", "%p", newOtherA); + + otherA = newOtherA; + DBG_OBJ_ASSOC_CHILD (otherA); + + DBG_OBJ_LEAVE (); +} + +void A::doSomething (int level) +{ + DBG_OBJ_ENTER ("all", 0, "doSomething", "%d", level); + + if (level > 0) { + doActualStuff (); + if (otherA) + otherA->doSomething (level - 1); + } + + DBG_OBJ_LEAVE (); +} + +void A::doActualStuff () +{ + DBG_OBJ_ENTER0 ("all", 0, "doActualStuff"); + + DBG_OBJ_MSG ("all", 1, "(pretending ...)"); + + DBG_OBJ_LEAVE (); +} + +int main (int argc, char *argv[]) +{ + A a1, a2; + a1.setOtherA (&a2); + a2.setOtherA (&a1); + a1.doSomething (20); +} diff --git a/tests/test_rtfl_objects_3_with_rtfl.cc b/tests/test_rtfl_objects_3_with_rtfl.cc new file mode 100644 index 0000000..032f6aa --- /dev/null +++ b/tests/test_rtfl_objects_3_with_rtfl.cc @@ -0,0 +1,2 @@ +#define DBG_RTFL +#include "test_rtfl_objects_3.cc" diff --git a/tests/test_rtfl_stats_1.cc b/tests/test_rtfl_stats_1.cc new file mode 100644 index 0000000..9be443d --- /dev/null +++ b/tests/test_rtfl_stats_1.cc @@ -0,0 +1,54 @@ +/* + * RTFL + * + * Copyright 2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +// See "collect-stats" in this directory. + +#include "debug_rtfl.hh" +#include "lout/object.hh" +#include "lout/container.hh" + +using namespace lout::object; +using namespace lout::container::typed; + + +static void sortvec (Vector<Integer> *vec) +{ + DBG_GEN_TIME (); + DBG_OBJ_ENTER0_O ("", 0, NULL, "sortvec"); + + DBG_OBJ_MSGF_O ("", 0, NULL, "size = %d", vec->size ()); + + vec->sort (); + + DBG_GEN_TIME (); + DBG_OBJ_LEAVE_O (NULL); +} + +int main (int argc, char *argv[]) +{ + for (int i = 0; i < 20; i++) { + int n = 20000 * i; + Vector<Integer> vec (n, true); + for (int j = 0; j < n; j++) + vec.put (new Integer (random ())); + sortvec (&vec); + } + + return 0; +} diff --git a/tests/test_rtfl_stats_1_with_rtfl.cc b/tests/test_rtfl_stats_1_with_rtfl.cc new file mode 100644 index 0000000..da23c75 --- /dev/null +++ b/tests/test_rtfl_stats_1_with_rtfl.cc @@ -0,0 +1,2 @@ +#define DBG_RTFL +#include "test_rtfl_stats_1.cc" diff --git a/tests/test_select_1.c b/tests/test_select_1.c new file mode 100644 index 0000000..db92d06 --- /dev/null +++ b/tests/test_select_1.c @@ -0,0 +1,67 @@ +/* + * RTFL + * + * Copyright 2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +#include <unistd.h> +#include <stdio.h> +#include <stdarg.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <sys/select.h> + +static void syserr (const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + vfprintf (stderr, fmt, args); + fprintf (stderr, ": %s\n", strerror (errno)); + exit (1); +} + +int main (int argc, char *argv[]) +{ + int eos = 0; + while (!eos) { + fd_set readfds; + FD_ZERO (&readfds); + FD_SET (0, &readfds); + + struct timeval tv; + tv.tv_sec = 1; + tv.tv_usec = 0; + + if (select (1, &readfds, NULL, NULL, &tv) == -1) + syserr ("select failed"); + + if (FD_ISSET (0, &readfds)) { + char buf[1024]; + int n = read (0, buf, 1024); + if (n == -1) + syserr ("select read"); + else if (n == 0) + eos = 1; + else + if (write (1, buf, n) == -1) + syserr ("write failed"); + } else + puts ("---------- timeout? ----------"); + } + + return 0; +} diff --git a/tests/test_tools_1.cc b/tests/test_tools_1.cc new file mode 100644 index 0000000..a09b7aa --- /dev/null +++ b/tests/test_tools_1.cc @@ -0,0 +1,97 @@ +/* + * RTFL + * + * Copyright 2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +#include "common/tools.hh" + +using namespace lout::object; +using namespace lout::misc; +using namespace lout::container::untyped; +using namespace rtfl::tools; + +class TestObject: public Object +{ +private: + int n; + +public: + TestObject (int n); + ~TestObject (); + + void intoStringBuffer (StringBuffer *sb); +}; + +TestObject::TestObject (int n) +{ + this->n = n; +} + +TestObject::~TestObject () +{ + printf("(~TestObject: %d)\n", n); +} + +void TestObject::intoStringBuffer (StringBuffer *sb) +{ + sb->append ("TestObject: "); + sb->appendInt (n); +} + +int main(int argc, char **argv) +{ + String *id[4]; + TestObject *testObject[4]; + EquivalenceRelation rel (true, true); + + for (int i = 0; i < 4; i++) { + char idBuf[] = { 'i', (char)('1' + i), 0 }; + id[i] = new String(idBuf); + testObject[i] = new TestObject (i); + + // New key since they are deleted by EquivalenceRelation.remove() + // but later still needed for EquivalenceRelation.contains(). + rel.put (new String(id[i]->chars ()), testObject[i]); + } + + for (int i = 0; i < 4; i++) { + puts ("--------------------------------------------------"); + for (int j = 0; j < 4; j++) { + if (rel.contains (id[j])) { + Object *obj = rel.get (id[j]); + StringBuffer sb; + obj->intoStringBuffer (&sb); + puts (sb.getChars ()); + } else + puts ("(removed)"); + } + + if (i == 0) + rel.relate (id[0], id[1]); + + if (i == 1) + rel.relate (id[0], id[2]); + + if (i == 2) + rel.remove (id[0]); + } + + for (int i = 0; i < 4; i++) + delete id[i]; + + puts ("--------------------------------------------------"); +} diff --git a/tests/test_tools_2.cc b/tests/test_tools_2.cc new file mode 100644 index 0000000..0cf4cad --- /dev/null +++ b/tests/test_tools_2.cc @@ -0,0 +1,26 @@ +#include "simple_sink.hh" +#include "testtools.hh" + +using namespace rtfl::tools; +using namespace rtfl::tests; + +int main (int argc, char *argv[]) +{ + int fd1 = openPipe ("echo Hello; sleep 2"); + BlockingLinesSource s1 (fd1); + // Both commands start at the same time, even if fd2 is processed later; thus + // the "sleep" at the beginning of the second command. + int fd2 = openPipe ("sleep 2; echo World; sleep 2"); + BlockingLinesSource s2 (fd2); + + LinesSourceSequence lss (false); + lss.add (&s1); + lss.add (&s2); + lss.addTimeout(1, 123); + lss.addTimeout(3, 124); + + SimpleSink sink; + lss.setup (&sink); + + return 0; +} diff --git a/tests/test_tools_3.cc b/tests/test_tools_3.cc new file mode 100644 index 0000000..5762c90 --- /dev/null +++ b/tests/test_tools_3.cc @@ -0,0 +1,16 @@ +#include "simple_sink.hh" + +using namespace rtfl::tools; +using namespace rtfl::tests; + +int main (int argc, char *argv[]) +{ + BlockingLinesSource source (0); + for(int i = 0; i < 5; i++) + source.addTimeout(1 + i, 123 + i); + + SimpleSink sink; + source.setup (&sink); + + return 0; +} diff --git a/tests/test_tools_4.cc b/tests/test_tools_4.cc new file mode 100644 index 0000000..8727fa4 --- /dev/null +++ b/tests/test_tools_4.cc @@ -0,0 +1,19 @@ +#include "simple_sink.hh" +#include "testtools.hh" + +using namespace rtfl::tools; +using namespace rtfl::tests; + +int main (int argc, char *argv[]) +{ + int fd = + openPipe ("for i in $(seq 1 10); do echo Hello world $i; sleep 1; done"); + BlockingLinesSource source (fd); + for(int i = 0; i < 5; i++) + source.addTimeout(1 + i, 123 + i); + + SimpleSink sink; + source.setup (&sink); + + return 0; +} diff --git a/tests/test_tools_5.cc b/tests/test_tools_5.cc new file mode 100644 index 0000000..9f5f957 --- /dev/null +++ b/tests/test_tools_5.cc @@ -0,0 +1,37 @@ +#include "simple_sink.hh" +#include "testtools.hh" + +using namespace rtfl::tools; +using namespace rtfl::tests; + +class NotSoSimpleSink: public SimpleSink +{ +private: + LinesSource *source; + +public: + NotSoSimpleSink (LinesSource *source); + void processLine (char *line); +}; + +NotSoSimpleSink::NotSoSimpleSink (LinesSource *source) +{ + this->source = source; +} + +void NotSoSimpleSink::processLine (char *line) +{ + SimpleSink::processLine (line); + if (strcmp (line, "create") == 0) + source->addTimeout (2, 0); +} + +int main (int argc, char *argv[]) +{ + int fd = openPipe ("echo create; echo msg; sleep 5"); + BlockingLinesSource source (fd); + NotSoSimpleSink sink (&source); + source.setup (&sink); + + return 0; +} diff --git a/tests/test_tools_6.cc b/tests/test_tools_6.cc new file mode 100644 index 0000000..f02a19e --- /dev/null +++ b/tests/test_tools_6.cc @@ -0,0 +1,29 @@ +#include "simple_sink.hh" +#include "testtools.hh" + +using namespace rtfl::tools; +using namespace rtfl::tests; + +// Test LinesSourceSequence: make sure that LinesSourceSequence deals correctly +// with timeouts. +int main (int argc, char *argv[]) +{ + int fd1 = openPipe ("sleep 5"); + BlockingLinesSource s1 (fd1); + // Both commands start at the same time, even if fd2 is processed later; so + // it takes 10, not 15 secs totally. + int fd2 = openPipe ("sleep 10"); + BlockingLinesSource s2 (fd2); + + LinesSourceSequence lss (false); + lss.add (&s1); + lss.add (&s2); + + for (int i = 2; i <= 20; i += 2) + lss.addTimeout(i, i); + + SimpleSink sink; + lss.setup (&sink); + + return 0; +} diff --git a/tests/test_version_cmp.c b/tests/test_version_cmp.c new file mode 100644 index 0000000..98667d6 --- /dev/null +++ b/tests/test_version_cmp.c @@ -0,0 +1,49 @@ +// Used for "../configure.ac". + +#include <ctype.h> +#include <stdlib.h> + +static int version_cmp (const char *v1, const char *v2) +{ + const char *s1 = v1, *s2 = v2; + while (*s1 && *s2) { + if (isdigit (*s1) && isdigit (*s2)) { + char buf1[10], buf2[10]; + int n1 = 0, n2 = 0; + + while (isdigit (*s1)) { + if (n1 < 9) buf1[n1++] = *s1; + s1++; + } + + while (isdigit (*s2)) { + if (n2 < 9) buf2[n2++] = *s2; + s2++; + } + + buf1[n1] = buf2[n2] = 0; + int c = atoi (buf1) - atoi (buf2); + if (c != 0) + return c; + } else { + if (*s1 != *s2) + return *s1 - *s2; + s1++; + s2++; + } + } + + return *s1 - *s2; +} + +#include <stdio.h> + +int main (int argc, char *argv[]) +{ + printf ("%d, %d, %d %d\n", + version_cmp ("0.1", "0.001"), + version_cmp ("0.1", "0.002"), + version_cmp ("0.1a", "0.1"), + version_cmp ("2.38.0", "2.38.1")); + return 0; +} diff --git a/tests/test_widget_b_splines.cc b/tests/test_widget_b_splines.cc new file mode 100644 index 0000000..a4a5f02 --- /dev/null +++ b/tests/test_widget_b_splines.cc @@ -0,0 +1,123 @@ +/* + * RTFL + * + * Copyright 2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + + +#include <FL/Fl_Window.H> +#include <FL/Fl.H> + +#include "dw/core.hh" +#include "dw/fltkcore.hh" +#include "dw/fltkviewport.hh" +#include "dwr/tools.hh" + +using namespace dw; +using namespace dw::core; +using namespace dw::core::style; +using namespace dw::fltk; +using namespace rtfl::dw::tools; + +class BSplineWidget: public Widget +{ +public: + void sizeRequestImpl (Requisition *requisition); + void getExtremesImpl(Extremes *extremes); + void draw (View *view, Rectangle *area); + Iterator *iterator (Content::Type mask, bool atEnd); +}; + +void BSplineWidget::sizeRequestImpl (Requisition *requisition) +{ + requisition->width = getAvailWidth (true); + requisition->ascent = getAvailHeight (true); + requisition->descent = 0; +} + +void BSplineWidget::getExtremesImpl(Extremes *extremes) +{ + extremes->minWidth = extremes->maxWidth = extremes->minWidthIntrinsic = + extremes->maxWidthIntrinsic = 1; +} + +void BSplineWidget::draw (View *view, Rectangle *area) +{ + double xp[7] = { 0.4, 0.1, 0.2, 0.5, 0.5, 0.9, 0.7 }; + double yp[7] = { 0.1, 0.5, 0.8, 0.7, 0.2, 0.4, 0.9 }; + int x[7], y[7]; + + for (int i = 0; i < 7; i++) { + x[i] = allocation.x + xp[i] * allocation.width; + y[i] = allocation.y + yp[i] * getHeight (); + } + + for(int i = 0; i < 7; i++) { + view->drawArc (getStyle()->color, core::style::Color::SHADING_NORMAL, + true, x[i], y[i], 5, 5, 0, 360); + } + + drawBSpline (view, getStyle(), 4, 7, x, y); +} + +Iterator *BSplineWidget::iterator (Content::Type mask, bool atEnd) +{ + return new core::EmptyIterator (this, mask, atEnd); +} + +int main(int argc, char **argv) +{ + FltkPlatform *platform = new FltkPlatform (); + Layout *layout = new Layout (platform); + + Fl_Window *window = new Fl_Window(500, 400, "Dw Example"); + window->box(FL_NO_BOX); + window->begin(); + + FltkViewport *viewport = new FltkViewport (0, 0, 500, 400); + layout->attachView (viewport); + + StyleAttrs styleAttrs; + styleAttrs.initValues (); + styleAttrs.padding.setVal (5); + + FontAttrs fontAttrs; + fontAttrs.name = "DejaVu Sans"; + fontAttrs.size = 14; + fontAttrs.weight = 400; + fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; + fontAttrs.fontVariant = FONT_VARIANT_NORMAL; + styleAttrs.font = style::Font::create (layout, &fontAttrs); + + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); + + Style *style = Style::create (&styleAttrs); + + BSplineWidget *widget = new BSplineWidget (); + widget->setStyle (style); + layout->setWidget (widget); + style->unref(); + + window->resizable(viewport); + window->show(); + int errorCode = Fl::run(); + + delete layout; + + return errorCode; +} diff --git a/tests/test_widgets_1.cc b/tests/test_widgets_1.cc new file mode 100644 index 0000000..c6e2fed --- /dev/null +++ b/tests/test_widgets_1.cc @@ -0,0 +1,142 @@ +/* + * RTFL + * + * Copyright 2013-2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +#include <FL/Fl_Window.H> +#include <FL/Fl.H> + +#include "dw/core.hh" +#include "dw/fltkcore.hh" +#include "dw/fltkviewport.hh" + +#include "dwr/graph.hh" +#include "dwr/label.hh" +#include "dwr/hbox.hh" +#include "dwr/vbox.hh" +#include "dwr/toggle.hh" + +using namespace dw; +using namespace dw::core; +using namespace dw::core::style; +using namespace dw::fltk; + +using namespace rtfl::dw; + +int main(int argc, char **argv) +{ + FltkPlatform *platform = new FltkPlatform (); + Layout *layout = new Layout (platform); + + Fl_Window *window = new Fl_Window(500, 400, "Dw Example"); + window->box(FL_NO_BOX); + window->begin(); + + FltkViewport *viewport = new FltkViewport (0, 0, 500, 400); + layout->attachView (viewport); + + StyleAttrs styleAttrs; + styleAttrs.initValues (); + styleAttrs.padding.setVal (5); + + FontAttrs fontAttrs; + fontAttrs.name = "DejaVu Sans"; + fontAttrs.size = 14; + fontAttrs.weight = 400; + fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; + fontAttrs.fontVariant = FONT_VARIANT_NORMAL; + styleAttrs.font = style::Font::create (layout, &fontAttrs); + + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); + + Style *graphStyle = Style::create (&styleAttrs); + Graph *graph = new Graph (); + graph->setStyle (graphStyle); + layout->setWidget (graph); + graphStyle->unref(); + + styleAttrs.borderWidth.setVal (1); + styleAttrs.setBorderStyle (BORDER_OUTSET); + styleAttrs.setBorderColor (Color::create (layout, 0x000000)); + Style *textblockStyle = Style::create (&styleAttrs); + + styleAttrs.borderWidth.setVal (0); + styleAttrs.padding.setVal (0); + Style *textStyle = Style::create (&styleAttrs); + + graph->setRefStyle (textblockStyle); + + HBox *n1 = new HBox (false); + n1->setStyle (textblockStyle); + graph->addNode (n1); + + Label *l11 = new Label ("Hello <i>w<b>or</i>ld!</b>"); + l11->setStyle (textblockStyle); + n1->addChild (l11); + + Label *l12 = new Label ("More text ..."); + l12->setStyle (textblockStyle); + n1->addChild (l12); + + VBox *n2 = new VBox (false); + n2->setStyle (textblockStyle); + graph->addNode (n2); + + Label *l21 = new Label ("Ἐν ἀρχῇ ἦν ὁ Λόγος, καὶ ὁ Λόγος ἦν πρὸς τὸν Θεόν, " + "καὶ Θεὸς ἦν ὁ Λόγος."); + l21->setStyle (textblockStyle); + n2->addChild (l21); + + Label *l22 = new Label ("Οὗτος ἦν ἐν ἀρχῇ πρὸς τὸν Θεόν. πάντα δι' αὐτοῦ " + "ἐγένετο, καὶ χωρὶς αὐτοῦ ἐγένετο οὐδὲ ἕν ὃ " + "γέγονεν."); + l22->setStyle (textblockStyle); + n2->addChild (l22); + + Toggle *n3 = new Toggle (true); + n3->setStyle (textblockStyle); + graph->addNode (n3); + + Label *l31 = new Label ("small"); + l31->setStyle (textblockStyle); + n3->setSmall (l31); + + Label *l33 = new Label ("LLLAAAAARRRRRGGGEEE"); + l33->setStyle (textblockStyle); + n3->setLarge (l33); + + Label *n4 = new Label ("#4"); + n4->setStyle (textblockStyle); + graph->addNode (n4); + + graph->addEdge (n1, n2); + graph->addEdge (n1, n3); + graph->addEdge (n2, n1); + + textStyle->unref(); + textblockStyle->unref(); + + window->resizable(viewport); + window->show(); + int errorCode = Fl::run(); + + delete layout; + + return errorCode; +} diff --git a/tests/test_widgets_2.cc b/tests/test_widgets_2.cc new file mode 100644 index 0000000..c20b50c --- /dev/null +++ b/tests/test_widgets_2.cc @@ -0,0 +1,97 @@ +/* + * RTFL + * + * Copyright 2013-2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +#include <FL/Fl_Window.H> +#include <FL/Fl.H> + +#include "dw/core.hh" +#include "dw/fltkcore.hh" +#include "dw/fltkviewport.hh" + +#include "dwr/vbox.hh" +#include "dwr/label.hh" + +using namespace dw; +using namespace dw::core; +using namespace dw::core::style; +using namespace dw::fltk; + +using namespace rtfl::dw; + +int main(int argc, char **argv) +{ + FltkPlatform *platform = new FltkPlatform (); + Layout *layout = new Layout (platform); + + Fl_Window *window = new Fl_Window(500, 400, "Dw Example"); + window->box(FL_NO_BOX); + window->begin(); + + FltkViewport *viewport = new FltkViewport (0, 0, 500, 400); + layout->attachView (viewport); + + FontAttrs fontAttrs; + fontAttrs.name = "DejaVu Serif"; + fontAttrs.size = 14; + fontAttrs.weight = 400; + fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; + fontAttrs.fontVariant = FONT_VARIANT_NORMAL; + + StyleAttrs styleAttrs; + styleAttrs.font = style::Font::create (layout, &fontAttrs); + styleAttrs.initValues (); + styleAttrs.margin.setVal (5); + styleAttrs.borderWidth.setVal (1); + styleAttrs.setBorderStyle (BORDER_OUTSET); + styleAttrs.padding.setVal (5); + styleAttrs.setBorderColor (Color::create (layout, 0x000000)); + styleAttrs.color = Color::create (layout, 0x000000); + + Style *boxStyle = Style::create (&styleAttrs); + + styleAttrs.margin.setVal (0); + styleAttrs.borderWidth.setVal (0); + styleAttrs.padding.setVal (0); + styleAttrs.setBorderColor (Color::create (layout, 0x000000)); + Style *labelStyle = Style::create (&styleAttrs); + + VBox *box = new VBox (false); + box->setStyle (boxStyle); + layout->setWidget (box); + + for (int i = 0; i < 100000; i++) { + char buf[32]; + sprintf (buf, "Label №%d", i); + Label *label = new Label (buf); + label->setStyle (labelStyle); + box->addChild (label); + } + + boxStyle->unref(); + labelStyle->unref(); + + window->resizable(viewport); + window->show(); + int errorCode = Fl::run(); + + delete layout; + + return errorCode; +} diff --git a/tests/test_widgets_3.cc b/tests/test_widgets_3.cc new file mode 100644 index 0000000..5329200 --- /dev/null +++ b/tests/test_widgets_3.cc @@ -0,0 +1,97 @@ +/* + * RTFL + * + * Copyright 2014, 2015 Sebastian Geerken <sgeerken@dillo.org> + * + * 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/>. + */ + +#include <FL/Fl_Window.H> +#include <FL/Fl.H> + +#include "dw/core.hh" +#include "dw/fltkcore.hh" +#include "dw/fltkviewport.hh" + +#include "dwr/vbox.hh" +#include "dwr/label.hh" + +using namespace dw; +using namespace dw::core; +using namespace dw::core::style; +using namespace dw::fltk; + +using namespace rtfl::dw; + +int main(int argc, char **argv) +{ + FltkPlatform *platform = new FltkPlatform (); + Layout *layout = new Layout (platform); + + Fl_Window *window = new Fl_Window(500, 400, "Dw Example"); + window->box(FL_NO_BOX); + window->begin(); + + FltkViewport *viewport = new FltkViewport (0, 0, 500, 400); + layout->attachView (viewport); + + FontAttrs fontAttrs; + fontAttrs.name = "DejaVu Serif"; + fontAttrs.size = 14; + fontAttrs.weight = 400; + fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; + fontAttrs.fontVariant = FONT_VARIANT_NORMAL; + + StyleAttrs styleAttrs; + styleAttrs.font = style::Font::create (layout, &fontAttrs); + styleAttrs.initValues (); + styleAttrs.margin.setVal (5); + styleAttrs.borderWidth.setVal (1); + styleAttrs.setBorderStyle (BORDER_OUTSET); + styleAttrs.padding.setVal (5); + styleAttrs.setBorderColor (Color::create (layout, 0x000000)); + styleAttrs.color = Color::create (layout, 0x000000); + + Style *boxStyle = Style::create (&styleAttrs); + + styleAttrs.margin.setVal (0); + styleAttrs.borderWidth.setVal (0); + styleAttrs.padding.setVal (0); + styleAttrs.setBorderColor (Color::create (layout, 0x000000)); + Style *labelStyle = Style::create (&styleAttrs); + + VBox *box = new VBox (false); + box->setStyle (boxStyle); + layout->setWidget (box); + + for (int i = 0; i < 1000; i++) { + char buf[32]; + sprintf (buf, "Label №%d", i); + Label *label = new Label (buf); + label->setStyle (labelStyle); + box->addChild (label, i / 10); + } + + boxStyle->unref(); + labelStyle->unref(); + + window->resizable(viewport); + window->show(); + int errorCode = Fl::run(); + + delete layout; + + return errorCode; +} diff --git a/tests/testtools.cc b/tests/testtools.cc new file mode 100644 index 0000000..175f482 --- /dev/null +++ b/tests/testtools.cc @@ -0,0 +1,49 @@ +#include "testtools.hh" +#include "common/tools.hh" + +#include <unistd.h> + +using namespace rtfl::tools; + +namespace rtfl { + +namespace tests { + +int openPipe (const char *command) +{ + int pipefd[2]; + + if (pipe (pipefd) == -1) + syserr ("pipe failed"); + + switch (fork ()) { + case -1: + syserr ("fork failed"); + break; + + case 0: + if (close (pipefd[0]) == -1) + syserr ("close(%d) failed", pipefd[0]); + if (close (1) == -1) + syserr ("close(%d) failed", 1); + if (dup2 (pipefd[1], 1) == -1) + syserr ("dup2(%d, %d) failed", pipefd[1], 1); + if (close (pipefd[1]) == -1) + syserr ("close(%d) failed", pipefd[1]); + execlp ("sh", "sh", "-c", command, NULL); + syserr ("exec(\"%s\", \"%s\", \"%s\", \"%s\", NULL) failed", + "sh", "sh", "-c", command); + break; + + default: + if (close (pipefd[1]) == -1) + syserr ("close(%d) failed", pipefd[1]); + return pipefd[0]; + } + + return -1; +} + +} // namespace tests + +} // namespace rtfl diff --git a/tests/testtools.hh b/tests/testtools.hh new file mode 100644 index 0000000..77c52da --- /dev/null +++ b/tests/testtools.hh @@ -0,0 +1,14 @@ +#ifndef __TESTS_TEST_TOOLS_HH__ +#define __TESTS_TEST_TOOLS_HH__ + +namespace rtfl { + +namespace tests { + +int openPipe (const char *command); + +} // namespace tests + +} // namespace rtfl + +#endif // __TESTS_TEST_TOOLS_HH__ |