Initial import of Dillo

This commit is contained in:
2025-02-28 13:34:30 -05:00
parent bd4e3eebd8
commit 20fea64cb5
496 changed files with 156174 additions and 0 deletions

66
test/unit/Makefile.am Normal file
View File

@ -0,0 +1,66 @@
AM_CPPFLAGS = \
-I$(top_srcdir) \
-DCUR_SRC_DIR="\"$(srcdir)\"" \
-DCUR_WORKING_DIR='"@BASE_CUR_WORKING_DIR@/test/unit"'
AM_CFLAGS = @LIBFLTK_CFLAGS@
AM_CXXFLAGS = @LIBFLTK_CXXFLAGS@
LDADD = \
$(top_builddir)/lout/liblout.a
TESTS = \
containers \
identity \
liang \
notsosimplevector \
shapes \
unicode_test
# Some test are broken, so only build them
check_PROGRAMS = $(TESTS) \
cookies \
trie
EXTRA_DIST = \
hyph-en-us.pat \
hyph-de.pat
containers_SOURCES = containers.cc
containers_LDADD = \
$(top_builddir)/lout/liblout.a \
$(top_builddir)/dlib/libDlib.a
notsosimplevector_SOURCES = notsosimplevector.cc
identity_SOURCES = identity.cc
identity_LDADD = \
$(top_builddir)/lout/liblout.a \
$(top_builddir)/dlib/libDlib.a
cookies_SOURCES = cookies.c
cookies_LDADD = \
$(top_builddir)/dpip/libDpip.a \
$(top_builddir)/dlib/libDlib.a
shapes_SOURCES = shapes.cc
shapes_LDADD = \
$(top_builddir)/dw/libDw-core.a \
$(top_builddir)/dlib/libDlib.a \
$(top_builddir)/lout/liblout.a
unicode_test_SOURCES = unicode_test.cc
unicode_test_LDADD = \
$(top_builddir)/lout/liblout.a \
@LIBFLTK_LIBS@ @LIBX11_LIBS@
liang_SOURCES = liang.cc
liang_LDADD = \
$(top_builddir)/dw/libDw-widgets.a \
$(top_builddir)/dw/libDw-fltk.a \
$(top_builddir)/dw/libDw-core.a \
$(top_builddir)/lout/liblout.a \
$(top_builddir)/dlib/libDlib.a \
@LIBFLTK_LIBS@ @LIBX11_LIBS@
trie_SOURCES = trie.cc
trie_LDADD = \
$(top_builddir)/dw/libDw-widgets.a \
$(top_builddir)/dw/libDw-fltk.a \
$(top_builddir)/dw/libDw-core.a \
$(top_builddir)/lout/liblout.a \
$(top_builddir)/dlib/libDlib.a \
@LIBFLTK_LIBS@ @LIBX11_LIBS@

157
test/unit/containers.cc Normal file
View File

@ -0,0 +1,157 @@
#include "lout/object.hh"
#include "lout/container.hh"
using namespace lout::object;
using namespace lout::container::typed;
class ReverseComparator: public Comparator
{
private:
Comparator *reversed;
public:
ReverseComparator (Comparator *reversed) { this->reversed = reversed; }
int compare(Object *o1, Object *o2) { return - reversed->compare (o1, o2); }
};
void testHashSet ()
{
puts ("--- testHashSet ---");
HashSet<String> h(true);
h.put (new String ("one"));
h.put (new String ("two"));
h.put (new String ("three"));
puts (h.toString());
}
void testHashTable ()
{
puts ("--- testHashTable ---");
HashTable<String, Integer> h(true, true);
h.put (new String ("one"), new Integer (1));
h.put (new String ("two"), new Integer (2));
h.put (new String ("three"), new Integer (3));
puts (h.toString());
h.put (new String ("one"), new Integer (4));
h.put (new String ("two"), new Integer (5));
h.put (new String ("three"), new Integer (6));
puts (h.toString());
}
void testVector1 ()
{
ReverseComparator reverse (&standardComparator);
puts ("--- testVector (1) ---");
Vector<String> v (true, 1);
v.put (new String ("one"));
v.put (new String ("two"));
v.put (new String ("three"));
puts (v.toString());
v.sort (&reverse);
puts (v.toString());
v.sort ();
puts (v.toString());
}
void testVector2 ()
{
puts ("--- testVector (2) ---");
Vector<String> v (true, 1);
v.insertSorted (new String ("one"));
puts (v.toString());
v.insertSorted (new String ("two"));
puts (v.toString());
v.insertSorted (new String ("three"));
puts (v.toString());
v.insertSorted (new String ("five"));
puts (v.toString());
v.insertSorted (new String ("six"));
puts (v.toString());
v.insertSorted (new String ("four"));
puts (v.toString());
for (int b = 0; b < 2; b++) {
bool mustExist = b;
printf ("mustExist = %s\n", mustExist ? "true" : "false");
String k ("alpha");
printf (" '%s' -> %d\n", k.chars(), v.bsearch (&k, mustExist));
for (Iterator<String> it = v.iterator(); it.hasNext(); ) {
String *k1 = it.getNext();
printf (" '%s' -> %d\n", k1->chars(), v.bsearch (k1, mustExist));
char buf[64];
strcpy (buf, k1->chars());
strcat (buf, "-var");
String k2 (buf);
printf (" '%s' -> %d\n", k2.chars(), v.bsearch (&k2, mustExist));
}
}
}
void testVector3 ()
{
// Regression test: resulted once incorrectly (0, 2, 3), should
// result in (1, 2, 3).
puts ("--- testVector (3) ---");
Vector<String> v (true, 1);
String k ("omega");
v.put (new String ("alpha"));
printf (" -> %d\n", v.bsearch (&k, false));
v.put (new String ("beta"));
printf (" -> %d\n", v.bsearch (&k, false));
v.put (new String ("gamma"));
printf (" -> %d\n", v.bsearch (&k, false));
}
void testStackAsQueue ()
{
puts ("--- testStackAsQueue ---");
Stack<Integer> s (true);
for (int i = 1; i <= 10; i++)
s.pushUnder (new Integer (i));
while (s.size () > 0) {
Integer *i = s.getTop ();
printf ("%d\n", i->getValue ());
s.pop ();
}
}
int main (int argc, char *argv[])
{
testHashSet ();
testHashTable ();
testVector1 ();
testVector2 ();
testVector3 ();
testStackAsQueue ();
return 0;
}

1164
test/unit/cookies.c Normal file

File diff suppressed because it is too large Load Diff

14236
test/unit/hyph-de.pat Normal file

File diff suppressed because it is too large Load Diff

4960
test/unit/hyph-en-us.pat Normal file

File diff suppressed because it is too large Load Diff

55
test/unit/identity.cc Normal file
View File

@ -0,0 +1,55 @@
/*
* This small program tests how IdentifiableObject works with multiple
* inheritance ("diamond" inheritance, more precisely, since all
* classes have there root in IdentifiableObject.)
*
* Current status: With virtual superclasses, you get a class
* hierarchy "root -> A -> B -> C", so that the first part of this
* example works actually (C is a subclass of A and of B), but the
* second fails (it should print "false", but it is erroneously
* assumed that B is a subclass of A.)
*/
#include "lout/identity.hh"
using namespace lout::identity;
class A: virtual public IdentifiableObject
{
public:
static int CLASS_ID;
inline A () { registerName ("A", &CLASS_ID); }
};
class B: virtual public IdentifiableObject
{
public:
static int CLASS_ID;
inline B () { registerName ("B", &CLASS_ID); }
};
class C: public A, public B
{
public:
static int CLASS_ID;
inline C () { registerName ("C", &CLASS_ID); }
};
int A::CLASS_ID = -1, B::CLASS_ID = -1, C::CLASS_ID = -1;
int main (int argc, char *argv[])
{
printf ("A: %d, B: %d, C: %d\n", A::CLASS_ID, B::CLASS_ID, C::CLASS_ID);
C x;
assert (x.instanceOf (A::CLASS_ID));
assert (x.instanceOf (B::CLASS_ID));
assert (x.instanceOf (C::CLASS_ID));
printf ("x: %d\n", x.getClassId ());
B y;
printf ("y: %d; instance of A: %s\n",
y.getClassId (), y.instanceOf (B::CLASS_ID) ? "true" : "false");
return 0;
}

106
test/unit/liang.cc Normal file
View File

@ -0,0 +1,106 @@
/*
* File: liang.cc
*
* Copyright 2012-2016 Sebastian Geerken <sgeerken@dillo.org>
* Copyright 2012-2013 Johannes Hofmann <Johannes.Hofmann@gmx.de>
* Copyright 2023 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* 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/>.
*/
/* Tests the hyphenation of words in different languages with the Liang
* algorithm. The hyphenator requires the .pat pattern files which can
* be downloaded from CTAN. */
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include "dw/fltkcore.hh"
#include "dw/hyphenator.hh"
dw::fltk::FltkPlatform *platform;
void hyph(dw::Hyphenator *h, const char *word, const char *parts)
{
int p = 0;
char buf[1024];
int numBreaks;
int *breakPos = h->hyphenateWord(platform, word, &numBreaks);
memset(buf, 0, 1024);
for (int i = 0; i < numBreaks + 1; i++) {
int start = (i == 0 ? 0 : breakPos[i - 1]);
int end = (i == numBreaks ? strlen (word) : breakPos[i]);
if (i != 0)
buf[p++] = '-';
for (int j = start; j < end; j++)
buf[p++] = word[j];
}
if (strcmp(parts, buf) != 0) {
fprintf(stderr, "mismatch input=%s output=%s expected=%s\n",
word, buf, parts);
exit(1);
}
printf("%s\n", buf);
if (breakPos)
free(breakPos);
}
dw::Hyphenator get_hyphenator(const char *path)
{
if (access(path, F_OK) != 0) {
fprintf(stderr, "cannot access %s file: %s", path,
strerror(errno));
exit(1);
}
return dw::Hyphenator(path, "", 512);
}
void hyph_en_us()
{
dw::Hyphenator h = get_hyphenator(CUR_SRC_DIR "/hyph-en-us.pat");
hyph(&h, "supercalifragilisticexpialidocious", "su-per-cal-ifrag-ilis-tic-ex-pi-ali-do-cious");
hyph(&h, "incredible", "in-cred-i-ble");
hyph(&h, "hyphenation", "hy-phen-ation");
hyph(&h, "...", "...");
}
void hyph_de()
{
dw::Hyphenator h = get_hyphenator(CUR_SRC_DIR "/hyph-de.pat");
hyph(&h, "...", "...");
hyph(&h, "weiß", "weiß");
hyph(&h, "Ackermann", "Acker-mann");
hyph(&h, "Grundstücksverkehrsgenehmigungszuständigkeits",
"Grund-stücks-ver-kehrs-ge-neh-mi-gungs-zu-stän-dig-keits");
hyph(&h, "Donaudampfschifffahrtskapitänsmützenknopf",
"Do-nau-dampf-schiff-fahrts-ka-pi-täns-müt-zen-knopf");
hyph(&h, "www.dillo.org", "www.dil-lo.org");
}
int main(void)
{
platform = new dw::fltk::FltkPlatform();
hyph_en_us();
hyph_de();
return 0;
}

View File

@ -0,0 +1,63 @@
#include "lout/misc.hh"
static void print (lout::misc::NotSoSimpleVector<int> *v)
{
for (int i = 0; i < v->size(); i++) {
// Uncomment for debugging, after making the respective members public.
//if (v->startExtra != -1 && i == v->startExtra + v->numExtra)
// printf (" ]");
if (i > 0)
printf (", ");
//if (i == v->startExtra)
// printf ("[ ");
printf ("%d", v->get(i));
}
printf (" (%d elements)\n", v->size ());
}
int main (int argc, char *argv[])
{
lout::misc::NotSoSimpleVector<int> v(1);
for (int i = 1; i <= 10; i++) {
v.increase ();
v.set(v.size () - 1, i);
}
print (&v);
v.insert (2, 4);
for (int i = 0; i < 5; i++)
v.set (2 + i, 31 + i);
print (&v);
v.insert (8, 4);
for (int i = 0; i < 5; i++)
v.set (8 + i, 51 + i);
print (&v);
v.insert (10, 4);
for (int i = 0; i < 5; i++)
v.set (10 + i, 531 + i);
print (&v);
v.insert (1, 4);
for (int i = 0; i < 5; i++)
v.set (1 + i, 21 + i);
print (&v);
int n = v.size ();
v.insert (n, 5);
for (int i = 0; i < 5; i++)
v.set (n + i, 101 + i);
print (&v);
return 0;
}

49
test/unit/shapes.cc Normal file
View File

@ -0,0 +1,49 @@
/*
* Dillo Widget
*
* Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
* Copyright 2023 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* 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 "dw/core.hh"
using namespace dw::core;
using namespace lout::misc;
int main()
{
Polygon poly;
poly.addPoint(50, 10);
poly.addPoint(90, 90);
poly.addPoint(10, 90);
if (!poly.isPointWithin(50, 50)) {
printf("poly.isPointWithin(50, 50) failed\n");
exit(1);
}
if (poly.isPointWithin(10, 10)) {
printf("!poly.isPointWithin(10, 10) failed\n");
exit(1);
}
if (poly.isPointWithin(90, 50)) {
printf("!poly.isPointWithin(90, 50) failed\n");
exit(1);
}
return 0;
}

14
test/unit/trie.cc Normal file
View File

@ -0,0 +1,14 @@
#include "dw/hyphenator.hh"
int main (int argc, char *argv[])
{
if (argc < 2) {
fprintf(stderr, "Usage: trie <pattern file>\n");
exit (1);
}
/* Use pack = 1024 to create a really small trie - can take a while.
*/
dw::Hyphenator hyphenator (argv[1], NULL, 1024);
hyphenator.saveTrie (stdout);
}

60
test/unit/unicode_test.cc Normal file
View File

@ -0,0 +1,60 @@
/*
* File: unicode_test.cc
*
* Copyright 2012 Sebastian Geerken <sgeerken@dillo.org>
* Copyright 2023 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* 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 <string.h>
#include <stdio.h>
#include <FL/fl_utf8.h>
#include "lout/unicode.hh"
using namespace lout::unicode;
int main (int argc, char *argv[])
{
// 0-terminated string
const char *t1 = "abcäöüабв";
// not 0-terminated; copy from 0-terminated
int t2len = strlen (t1);
char *t2 = new char[t2len];
for (int i = 0; i < t2len; i++)
t2[i] = t1[i];
puts ("===== misc::unicode, 0-terminated =====");
for (const char *s = t1; s; s = nextUtf8Char (s))
printf ("%3d -> U+%04x ('%s')\n", (int)(s - t1), decodeUtf8(s), s);
puts ("===== Fltk, 0-terminated =====");
for (const char *s = t1; *s; s = fl_utf8fwd (s + 1, t1, t1 + strlen (t1)))
printf ("%3d -> U+%04x ('%s')\n", (int)(s - t1), decodeUtf8(s), s);
puts ("===== misc::unicode, not 0-terminated =====");
for (const char *s = t2; s; s = nextUtf8Char (s, t2len - (s - t2)))
printf ("%3d -> U+%04x\n", (int)(s - t2),
decodeUtf8(s, t2len - (s - t2)));
puts ("===== Fltk, not 0-terminated =====");
for (const char *s = t2; s - t2 < t2len; s = fl_utf8fwd (s + 1, t2, t2 + t2len))
printf ("%3d -> U+%04x\n", (int)(s - t2),
decodeUtf8(s, t2len - (s - t2)));
delete[] t2;
return 0;
}