diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2010-08-20 23:37:48 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2010-08-20 23:37:48 +0200 |
commit | 8d60fd48d88e5159e4acc654aaa69e08d2736331 (patch) | |
tree | 15a25c399f5f98a65376a7ac8c3666910a905a71 /test | |
parent | f7d68eb7da63d2e437055f703d60ee9863147d7f (diff) | |
parent | f5c598b518d1f906148534d015f50075d3e8242d (diff) |
merge
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 17 | ||||
-rw-r--r-- | test/cookies.c | 970 | ||||
-rw-r--r-- | test/dw_anchors_test.cc | 16 | ||||
-rw-r--r-- | test/dw_border_test.cc | 18 | ||||
-rw-r--r-- | test/dw_example.cc | 10 | ||||
-rw-r--r-- | test/dw_find_test.cc | 12 | ||||
-rw-r--r-- | test/dw_float_test.cc | 7 | ||||
-rw-r--r-- | test/dw_images_scaled.cc | 22 | ||||
-rw-r--r-- | test/dw_images_scaled2.cc | 18 | ||||
-rw-r--r-- | test/dw_images_simple.cc | 25 | ||||
-rw-r--r-- | test/dw_imgbuf_mem_test.cc | 15 | ||||
-rw-r--r-- | test/dw_links.cc | 41 | ||||
-rw-r--r-- | test/dw_links2.cc | 43 | ||||
-rw-r--r-- | test/dw_lists.cc | 16 | ||||
-rw-r--r-- | test/dw_resource_test.cc | 14 | ||||
-rw-r--r-- | test/dw_table.cc | 10 | ||||
-rw-r--r-- | test/dw_table_aligned.cc | 14 | ||||
-rw-r--r-- | test/dw_ui_test.cc | 16 | ||||
-rw-r--r-- | test/fltk_browser.cc | 5 | ||||
-rw-r--r-- | test/form.cc | 19 | ||||
-rw-r--r-- | test/form.hh | 12 | ||||
-rw-r--r-- | test/shapes.cc | 5 |
22 files changed, 1157 insertions, 168 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index bde2b0f8..709196f4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -5,6 +5,7 @@ noinst_PROGRAMS = \ dw-anchors-test \ dw-example \ dw-find-test \ + dw-float-test \ dw-links \ dw-links2 \ dw-images-simple \ @@ -18,7 +19,8 @@ noinst_PROGRAMS = \ dw-resource-test \ dw-ui-test \ fltk-browser \ - shapes + shapes \ + cookies dw_anchors_test_SOURCES = dw_anchors_test.cc dw_anchors_test_LDADD = \ @@ -44,6 +46,14 @@ dw_find_test_LDADD = \ ../lout/liblout.a \ @LIBFLTK_LIBS@ +dw_float_test_SOURCES = dw_float_test.cc +dw_float_test_LDADD = \ + ../dw/libDw-widgets.a \ + ../dw/libDw-fltk.a \ + ../dw/libDw-core.a \ + ../lout/liblout.a \ + @LIBFLTK_LIBS@ + dw_links_SOURCES = dw_links.cc dw_links_LDADD = \ ../dw/libDw-widgets.a \ @@ -151,3 +161,8 @@ shapes_SOURCES = shapes.cc shapes_LDADD = \ ../dw/libDw-core.a \ ../lout/liblout.a + +cookies_SOURCES = cookies.c +cookies_LDADD = \ + ../dpip/libDpip.a \ + ../dlib/libDlib.a diff --git a/test/cookies.c b/test/cookies.c new file mode 100644 index 00000000..af59cb48 --- /dev/null +++ b/test/cookies.c @@ -0,0 +1,970 @@ +/* + * Dillo cookies test + * + * 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/>. + */ + +/* + * This has a big blob of the current src/IO/dpi.c in it. + * I hope there's a better way. + */ + +#include <stdlib.h> /* malloc, etc. */ +#include <unistd.h> /* read, etc. */ +#include <stdio.h> +#include <stdarg.h> /* va_list */ +#include <string.h> /* strchr */ +#include <errno.h> +#include <ctype.h> +#include <time.h> +/* net */ +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <netinet/in.h> + + +#define _MSG(...) + +#define MSG_INNARDS(prefix, ...) \ + D_STMT_START { \ + printf(prefix __VA_ARGS__); \ + fflush (stdout); \ + } D_STMT_END + +#define MSG(...) MSG_INNARDS("", __VA_ARGS__) +#define MSG_ERR(...) MSG_INNARDS("** ERROR **: ", __VA_ARGS__) + + +#include "../dlib/dlib.h" +#include "../dpip/dpip.h" + +static uint_t failed = 0; +static uint_t passed = 0; + +static char SharedKey[32]; + +/* + * Read all the available data from a filedescriptor. + * This is intended for short answers, i.e. when we know the server + * will write it all before being preempted. For answers that may come + * as an stream with delays, non-blocking is better. + * Return value: read data, or NULL on error and no data. + */ +static char *Dpi_blocking_read(int fd) +{ + int st; + const int buf_sz = 8*1024; + char buf[buf_sz], *msg = NULL; + Dstr *dstr = dStr_sized_new(buf_sz); + + do { + st = read(fd, buf, buf_sz); + if (st < 0) { + if (errno == EINTR) { + continue; + } else { + MSG_ERR("[Dpi_blocking_read] %s\n", dStrerror(errno)); + break; + } + } else if (st > 0) { + dStr_append_l(dstr, buf, st); + } + } while (st == buf_sz); + + msg = (dstr->len > 0) ? dstr->str : NULL; + dStr_free(dstr, (dstr->len > 0) ? FALSE : TRUE); + return msg; +} + +static void Dpi_close_fd(int fd) +{ + int st; + + dReturn_if (fd < 0); + do + st = close(fd); + while (st < 0 && errno == EINTR); +} + +static int Dpi_make_socket_fd() +{ + int fd, ret = -1; + + if ((fd = socket(AF_INET, SOCK_STREAM, 0)) != -1) { + ret = fd; + } + return ret; +} + +/* + * Read dpid's communication keys from its saved file. + * Return value: 1 on success, -1 on error. + */ +static int Dpi_read_comm_keys(int *port) +{ + FILE *In; + char *fname, *rcline = NULL, *tail; + int i, ret = -1; + + fname = dStrconcat(dGethomedir(), "/.dillo/dpid_comm_keys", NULL); + if ((In = fopen(fname, "r")) == NULL) { + MSG_ERR("[Dpi_read_comm_keys] %s\n", dStrerror(errno)); + } else if ((rcline = dGetline(In)) == NULL) { + MSG_ERR("[Dpi_read_comm_keys] empty file: %s\n", fname); + } else { + *port = strtol(rcline, &tail, 10); + for (i = 0; *tail && isxdigit(tail[i+1]); ++i) + SharedKey[i] = tail[i+1]; + SharedKey[i] = 0; + ret = 1; + } + if (In) + fclose(In); + dFree(rcline); + dFree(fname); + + return ret; +} + +static int Dpi_check_dpid_ids() +{ + struct sockaddr_in sin; + const socklen_t sin_sz = sizeof(sin); + int sock_fd, dpid_port, ret = -1; + + /* socket connection test */ + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + + if (Dpi_read_comm_keys(&dpid_port) != -1) { + sin.sin_port = htons(dpid_port); + if ((sock_fd = Dpi_make_socket_fd()) == -1) { + MSG("Dpi_check_dpid_ids: sock_fd=%d %s\n", sock_fd, dStrerror(errno)); + } else if (connect(sock_fd, (struct sockaddr *)&sin, sin_sz) == -1) { + MSG("Dpi_check_dpid_ids: %s\n", dStrerror(errno)); + } else { + Dpi_close_fd(sock_fd); + ret = 1; + } + } + return ret; +} + +static int Dpi_blocking_write(int fd, const char *msg, int msg_len) +{ + int st, sent = 0; + + while (sent < msg_len) { + st = write(fd, msg + sent, msg_len - sent); + if (st < 0) { + if (errno == EINTR) { + continue; + } else { + MSG_ERR("[Dpi_blocking_write] %s\n", dStrerror(errno)); + break; + } + } + sent += st; + } + + return (sent == msg_len) ? 1 : -1; +} + +/* + * Start dpid. + * Return: 0 starting now, 1 Error. + */ +static int Dpi_start_dpid(void) +{ + pid_t pid; + int st_pipe[2], ret = 1; + char *answer; + + /* create a pipe to track our child's status */ + if (pipe(st_pipe)) + return 1; + + pid = fork(); + if (pid == 0) { + /* This is the child process. Execute the command. */ + char *path1 = dStrconcat(dGethomedir(), "/.dillo/dpid", NULL); + Dpi_close_fd(st_pipe[0]); + if (execl(path1, "dpid", (char*)NULL) == -1) { + dFree(path1); + if (execlp("dpid", "dpid", (char*)NULL) == -1) { + MSG("Dpi_start_dpid (child): %s\n", dStrerror(errno)); + if (Dpi_blocking_write(st_pipe[1], "ERROR", 5) == -1) { + MSG("Dpi_start_dpid (child): can't write to pipe.\n"); + } + Dpi_close_fd(st_pipe[1]); + _exit (EXIT_FAILURE); + } + } + } else if (pid < 0) { + /* The fork failed. Report failure. */ + MSG("Dpi_start_dpid: %s\n", dStrerror(errno)); + /* close the unused pipe */ + Dpi_close_fd(st_pipe[0]); + Dpi_close_fd(st_pipe[1]); + + } else { + /* This is the parent process, check our child status... */ + Dpi_close_fd(st_pipe[1]); + if ((answer = Dpi_blocking_read(st_pipe[0])) != NULL) { + MSG("Dpi_start_dpid: can't start dpid\n"); + dFree(answer); + } else { + ret = 0; + } + Dpi_close_fd(st_pipe[0]); + } + + return ret; +} + +/* + * Confirm that the dpid is running. If not, start it. + * Return: 0 running OK, 1 starting (EAGAIN), 2 Error. + */ +static int Dpi_check_dpid(int num_tries) +{ + static int starting = 0; + int check_st = 1, ret = 2; + + check_st = Dpi_check_dpid_ids(); + _MSG("Dpi_check_dpid: check_st=%d\n", check_st); + + if (check_st == 1) { + /* connection test with dpi server passed */ + starting = 0; + ret = 0; + } else { + if (!starting) { + /* start dpid */ + if (Dpi_start_dpid() == 0) { + starting = 1; + ret = 1; + } + } else if (++starting < num_tries) { + /* starting */ + ret = 1; + } else { + /* we waited too much, report an error... */ + starting = 0; + } + } + + _MSG("Dpi_check_dpid:: %s\n", + (ret == 0) ? "OK" : (ret == 1 ? "EAGAIN" : "ERROR")); + return ret; +} + + +static int Dpi_blocking_start_dpid(void) +{ + int cst, try = 0, + n_tries = 12; /* 3 seconds */ + + /* test the dpid, and wait a bit for it to start if necessary */ + while ((cst = Dpi_check_dpid(n_tries)) == 1) { + MSG("Dpi_blocking_start_dpid: try %d\n", ++try); + usleep(250000); /* 1/4 sec */ + } + return cst; +} + + +/* + * Return the dpi server's port number, or -1 on error. + * (A query is sent to dpid and then its answer parsed) + * note: as the available servers and/or the dpi socket directory can + * change at any time, we'll ask each time. If someday we find + * that connecting each time significantly degrades performance, + * an optimized approach can be tried. + */ +static int Dpi_get_server_port(const char *server_name) +{ + int sock_fd = -1, dpi_port = -1; + int dpid_port, ok = 0; + struct sockaddr_in sin; + char *cmd, *request, *rply = NULL, *port_str; + socklen_t sin_sz; + + dReturn_val_if_fail (server_name != NULL, dpi_port); + _MSG("Dpi_get_server_port:: server_name = [%s]\n", server_name); + + /* Read dpid's port from saved file */ + if (Dpi_read_comm_keys(&dpid_port) != -1) { + ok = 1; + } + if (ok) { + /* Connect a socket with dpid */ + ok = 0; + sin_sz = sizeof(sin); + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sin.sin_port = htons(dpid_port); + if ((sock_fd = Dpi_make_socket_fd()) == -1 || + connect(sock_fd, (struct sockaddr *)&sin, sin_sz) == -1) { + MSG("Dpi_get_server_port: %s\n", dStrerror(errno)); + } else { + ok = 1; + } + } + if (ok) { + /* ask dpid to check the dpi and send its port number back */ + ok = 0; + request = a_Dpip_build_cmd("cmd=%s msg=%s", "check_server", server_name); + _MSG("[%s]\n", request); + + if (Dpi_blocking_write(sock_fd, request, strlen(request)) == -1) { + MSG("Dpi_get_server_port: %s\n", dStrerror(errno)); + } else { + ok = 1; + } + dFree(request); + } + if (ok) { + /* Get the reply */ + ok = 0; + if ((rply = Dpi_blocking_read(sock_fd)) == NULL) { + MSG("Dpi_get_server_port: can't read server port from dpid.\n"); + } else { + ok = 1; + } + } + if (ok) { + /* Parse reply */ + ok = 0; + cmd = a_Dpip_get_attr(rply, "cmd"); + if (strcmp(cmd, "send_data") == 0) { + port_str = a_Dpip_get_attr(rply, "msg"); + _MSG("Dpi_get_server_port: rply=%s\n", rply); + _MSG("Dpi_get_server_port: port_str=%s\n", port_str); + dpi_port = strtol(port_str, NULL, 10); + dFree(port_str); + ok = 1; + } + dFree(cmd); + } + dFree(rply); + Dpi_close_fd(sock_fd); + + return ok ? dpi_port : -1; +} + + +static int Dpi_connect_socket(const char *server_name, int retry) +{ + struct sockaddr_in sin; + int sock_fd, err, dpi_port, ret=-1; + char *cmd = NULL; + + /* Query dpid for the port number for this server */ + if ((dpi_port = Dpi_get_server_port(server_name)) == -1) { + _MSG("Dpi_connect_socket:: can't get port number for %s\n", server_name); + return -1; + } + _MSG("Dpi_connect_socket: server=%s port=%d\n", server_name, dpi_port); + + /* connect with this server's socket */ + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sin.sin_port = htons(dpi_port); + + if ((sock_fd = Dpi_make_socket_fd()) == -1) { + perror("[dpi::socket]"); + } else if (connect(sock_fd, (void*)&sin, sizeof(sin)) == -1) { + err = errno; + sock_fd = -1; + MSG("[dpi::connect] errno:%d %s\n", errno, dStrerror(errno)); + if (retry) { + switch (err) { + case ECONNREFUSED: case EBADF: case ENOTSOCK: case EADDRNOTAVAIL: + sock_fd = Dpi_connect_socket(server_name, FALSE); + break; + } + } + + /* send authentication Key (the server closes sock_fd on error) */ + } else if (!(cmd = a_Dpip_build_cmd("cmd=%s msg=%s", "auth", SharedKey))) { + MSG_ERR("[Dpi_connect_socket] Can't make auth message.\n"); + } else if (Dpi_blocking_write(sock_fd, cmd, strlen(cmd)) == -1) { + MSG_ERR("[Dpi_connect_socket] Can't send auth message.\n"); + } else { + ret = sock_fd; + } + dFree(cmd); + + return ret; +} + + +char *a_Dpi_send_blocking_cmd(const char *server_name, const char *cmd) +{ + int cst, sock_fd; + char *ret = NULL; + + /* test the dpid, and wait a bit for it to start if necessary */ + if ((cst = Dpi_blocking_start_dpid()) != 0) { + return ret; + } + + if ((sock_fd = Dpi_connect_socket(server_name, TRUE)) == -1) { + MSG_ERR("[a_Dpi_send_blocking_cmd] Can't connect to server.\n"); + } else if (Dpi_blocking_write(sock_fd, cmd, strlen(cmd)) == -1) { + MSG_ERR("[a_Dpi_send_blocking_cmd] Can't send message.\n"); + } if ((ret = Dpi_blocking_read(sock_fd)) == NULL) { + MSG_ERR("[a_Dpi_send_blocking_cmd] Can't read message.\n"); + } + Dpi_close_fd(sock_fd); + + return ret; +} + + + +void a_Cookies_set(const char *cookie, const char *host, const char *path, + const char *date) +{ + char *cmd, *dpip_tag; + + if (date) + cmd = a_Dpip_build_cmd("cmd=%s cookie=%s host=%s path=%s date=%s", + "set_cookie", cookie, + host, path, date); + else + cmd = a_Dpip_build_cmd("cmd=%s cookie=%s host=%s path=%s", + "set_cookie", cookie, + host, path); + + dpip_tag = a_Dpi_send_blocking_cmd("cookies", cmd); + _MSG("a_Cookies_set: dpip_tag = {%s}\n", dpip_tag); + dFree(dpip_tag); + dFree(cmd); +} + + +char *a_Cookies_get_query(const char *scheme, const char *host, + const char *path) +{ + char *cmd, *dpip_tag, *query; + + cmd = a_Dpip_build_cmd("cmd=%s scheme=%s host=%s path=%s", + "get_cookie", scheme, + host, path); + + /* Get the answer from cookies.dpi */ + _MSG("cookies.c: a_Dpi_send_blocking_cmd cmd = {%s}\n", cmd); + dpip_tag = a_Dpi_send_blocking_cmd("cookies", cmd); + _MSG("cookies.c: after a_Dpi_send_blocking_cmd resp={%s}\n", dpip_tag); + dFree(cmd); + + if (dpip_tag != NULL) { + query = a_Dpip_get_attr(dpip_tag, "cookie"); + dFree(dpip_tag); + } else { + query = dStrdup(""); + } + + return query; +} + +static void expect(int lineno, const char *exp_reply, + const char *scheme, const char *host, const char *path) +{ + char *reply = a_Cookies_get_query(scheme, host, path); + + if (strcmp(reply, exp_reply)) { + MSG("line %d: EXPECTED: %s GOT: %s\n", lineno, exp_reply, reply); + failed++; + } else { + passed++; + } +} + +static void toomany() +{ + a_Cookies_set("1=1", "toomany.com", "/", NULL); + a_Cookies_set("2=1", "toomany.com", "/", NULL); + a_Cookies_set("3=1", "toomany.com", "/", NULL); + a_Cookies_set("4=1", "toomany.com", "/", NULL); + a_Cookies_set("5=1", "toomany.com", "/", NULL); + a_Cookies_set("6=1", "toomany.com", "/", NULL); + a_Cookies_set("7=1", "toomany.com", "/path/", NULL); + a_Cookies_set("8=1", "toomany.com", "/", NULL); + a_Cookies_set("9=1", "toomany.com", "/", NULL); + a_Cookies_set("10=1", "toomany.com", "/", NULL); + a_Cookies_set("11=1", "toomany.com", "/", NULL); + a_Cookies_set("12=1", "toomany.com", "/", NULL); + a_Cookies_set("13=1", "toomany.com", "/", NULL); + a_Cookies_set("14=1", "toomany.com", "/", NULL); + a_Cookies_set("15=1", "toomany.com", "/", NULL); + a_Cookies_set("16=1", "toomany.com", "/", NULL); + a_Cookies_set("17=1", "toomany.com", "/", NULL); + a_Cookies_set("18=1", "toomany.com", "/", NULL); + a_Cookies_set("19=1", "toomany.com", "/", NULL); + a_Cookies_set("20=1", "toomany.com", "/", NULL); + a_Cookies_set("21=1", "toomany.com", "/", NULL); + /* 1 was oldest and discarded */ + expect(__LINE__, "Cookie: 7=1; 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; " + "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; " + "20=1; 21=1\r\n", "http", "toomany.com", "/path/"); + sleep(1); + /* touch all of them except #7 (path matching) */ + expect(__LINE__, "Cookie: 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; " + "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; " + "20=1; 21=1\r\n", "http", "toomany.com", "/"); + a_Cookies_set("22=1", "toomany.com", "/", NULL); + /* 7 was oldest and discarded */ + expect(__LINE__, "Cookie: 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; " + "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; " + "20=1; 21=1; 22=1\r\n", "http", "toomany.com", "/path/"); +} + +static void maxage() +{ + time_t t = time(NULL)+1000; + char *server_date = dStrdup(ctime(&t)); + + a_Cookies_set("name=val; max-age=0", "maxage0.com", "/", NULL); + expect(__LINE__, "", "http", "maxage0.com", "/"); + + a_Cookies_set("name=val; max-age=100", "maxage100.com", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "maxage100.com", "/"); + + a_Cookies_set("name=val; max-age=-100", "maxage-100.com", "/", NULL); + expect(__LINE__, "", "http", "maxage-100.com", "/"); + + a_Cookies_set("name=val; max-age=2000000000", "maxage-huge.com", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "maxage-huge.com", "/"); + /* just having a server date shouldn't matter */ + + a_Cookies_set("name=val; max-age=0", "maxage0s.com", "/", server_date); + expect(__LINE__, "", "http", "maxage0s.com", "/"); + + a_Cookies_set("name=val; max-age=100", "maxage100s.com", "/", server_date); + expect(__LINE__, "Cookie: name=val\r\n", "http", "maxage100s.com", "/"); + + a_Cookies_set("name=val; max-age=-100", "maxage-100s.com", "/",server_date); + expect(__LINE__, "", "http", "maxage-100s.com", "/"); + + /* MAX-AGE and EXPIRES */ + a_Cookies_set("name=val; max-age=90; expires=Wed Jan 20 01:26:32 2010", + "maxagelater.com", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "maxagelater.com", "/"); + + a_Cookies_set("name=val; max-age=90; expires=Wed Jan 20 01:26:32 2010", + "maxagelaters.com", "/", server_date); + expect(__LINE__, "Cookie: name=val\r\n", "http", "maxagelaters.com", "/"); + + dFree(server_date); +} + +static void expires_server_ahead() +{ + char *string; + time_t t = time(NULL)+1000; + char *server_date = dStrdup(ctime(&t)); + time_t expt = t + 1000; + char *exp_date = dStrdup(ctime(&expt)); + + string = dStrconcat("name=val; expires=", exp_date, NULL); + a_Cookies_set(string, "e2000s1000.com", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "e2000s1000.com", "/"); + + a_Cookies_set(string, "e2000s1000s.com", "/", server_date); + expect(__LINE__, "Cookie: name=val\r\n", "http", "e2000s1000s.com", "/"); + + expt = t - 500; /* past for the server, future for us */ + dFree(exp_date); + exp_date = dStrdup(ctime(&expt)); + + string = dStrconcat("name=val; expires=", exp_date, NULL); + a_Cookies_set(string, "e500s1000.com", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "e500s1000.com", "/"); + + a_Cookies_set(string, "e500s1000s.com", "/", server_date); + expect(__LINE__, "", "http", "e500s1000s.com", "/"); + + expt = t; /* expire at future-for-us server date */ + dFree(exp_date); + exp_date = dStrdup(ctime(&expt)); + + string = dStrconcat("name=val; expires=", exp_date, NULL); + a_Cookies_set(string, "e1000s1000.com", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "e1000s1000.com", "/"); + + a_Cookies_set(string, "e1000s1000s.com", "/", server_date); + expect(__LINE__, "", "http", "e1000s1000s.com", "/"); + + expt = time(NULL); /* now */ + dFree(exp_date); + exp_date = dStrdup(ctime(&expt)); + + string = dStrconcat("name=val; expires=", exp_date, NULL); + a_Cookies_set(string, "e0s1000.com", "/", NULL); + expect(__LINE__, "", "http", "e0s1000.com", "/"); + + a_Cookies_set(string, "e0s1000s.com", "/", server_date); + expect(__LINE__, "", "http", "e0s1000s.com", "/"); + + dFree(exp_date); + dFree(server_date); +} + +static void expires_server_behind() +{ + char *string; + time_t t = time(NULL)-1000; + char *server_date = dStrdup(ctime(&t)); + + time_t expt = t + 1000; + char *exp_date = dStrdup(ctime(&expt)); + + string = dStrconcat("name=val; expires=", exp_date, NULL); + a_Cookies_set(string, "e0s-1000.com", "/", NULL); + expect(__LINE__, "", "http", "e0s-1000.com", "/"); + + a_Cookies_set(string, "e0s-1000s.com", "/", server_date); + expect(__LINE__, "Cookie: name=val\r\n", "http", "e0s-1000s.com","/"); + + expt = t + 500; /* future for the server, past for us */ + dFree(exp_date); + exp_date = dStrdup(ctime(&expt)); + + string = dStrconcat("name=val; expires=", exp_date, NULL); + a_Cookies_set(string, "e-500s-1000.com", "/", NULL); + expect(__LINE__, "", "http", "e-500s-1000.com", "/"); + + a_Cookies_set(string, "e-500s-1000s.com", "/", server_date); + expect(__LINE__, "Cookie: name=val\r\n", "http", "e-500s-1000s.com", "/"); + + expt = t; /* expire at past-for-us server date */ + dFree(exp_date); + exp_date = dStrdup(ctime(&expt)); + + string = dStrconcat("name=val; expires=", exp_date, NULL); + a_Cookies_set(string, "e-1000s-1000.com", "/", NULL); + expect(__LINE__, "", "http", "e-1000s-1000.com", "/"); + + a_Cookies_set(string, "e-1000s-1000s.com", "/", server_date); + expect(__LINE__, "", "http", "e-1000s-1000s.com", "/"); + + dFree(server_date); + dFree(exp_date); +} + +static void expires_extremes() +{ + time_t t; + char *server_date; + + a_Cookies_set("name=val; expires=Fri Dec 13 20:45:52 1901", "expmin.com", + "/", NULL); + expect(__LINE__, "", "http", "expmin.com", "/"); + + a_Cookies_set("name=val; expires=Wed Dec 31 23:59:59 1969", "expneg.com", + "/", NULL); + expect(__LINE__, "", "http", "expneg.com", "/"); + + a_Cookies_set("name=val; expires=Thu Jan 1 00:00:00 1970", "expepoch.com", + "/", NULL); + expect(__LINE__, "", "http", "expepoch.com", "/"); + + /* TODO: revisit these tests in a few decades */ + a_Cookies_set("name=val; expires=Tue Jan 19 03:14:07 2038", "expmax.com", + "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "expmax.com", "/"); + + a_Cookies_set("name=val; expires=Sun Jan 1 00:00:00 2040", "pastmax.com", + "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "pastmax.com", "/"); + + t = time(NULL)+1000; + server_date = dStrdup(ctime(&t)); + + a_Cookies_set("name=val; expires=Fri Dec 13 20:45:52 1901", "expmina.com", + "/", server_date); + expect(__LINE__, "", "http", "expmina.com", "/"); + + a_Cookies_set("name=val; expires=Wed Dec 31 23:59:59 1969", "expnega.com", + "/", server_date); + expect(__LINE__, "", "http", "expnega.com", "/"); + + a_Cookies_set("name=val; expires=Thu Jan 1 00:00:00 1970", "expepocha.com", + "/", server_date); + expect(__LINE__, "", "http", "expepocha.com", "/"); + + a_Cookies_set("name=val; expires=Tue Jan 19 03:14:07 2038", "expmaxa.com", + "/", server_date); + expect(__LINE__, "Cookie: name=val\r\n", "http", "expmaxa.com", "/"); + + a_Cookies_set("name=val; expires=Sun Jan 1 00:00:00 2040", "pastmaxa.com", + "/", server_date); + expect(__LINE__, "Cookie: name=val\r\n", "http", "pastmaxa.com", "/"); + + t = time(NULL)-1000; + dFree(server_date); + server_date = dStrdup(ctime(&t)); + + a_Cookies_set("name=val; expires=Fri Dec 13 20:45:52 1901", "expminb.com", + "/", server_date); + expect(__LINE__, "", "http", "expminb.com", "/"); + + a_Cookies_set("name=val; expires=Wed Dec 31 23:59:59 1969", "expnegb.com", + "/", server_date); + expect(__LINE__, "", "http", "expnegb.com", "/"); + + a_Cookies_set("name=val; expires=Thu Jan 1 00:00:00 1970", "expepochb.com", + "/", server_date); + expect(__LINE__, "", "http", "expepochb.com", "/"); + + a_Cookies_set("name=val; expires=Tue Jan 19 03:14:07 2038", "expmaxb.com", + "/", server_date); + expect(__LINE__, "Cookie: name=val\r\n", "http", "expmaxb.com", "/"); + + a_Cookies_set("name=val; expires=Sun Jan 1 00:00:00 2040", "pastmaxb.com", + "/", server_date); + expect(__LINE__, "Cookie: name=val\r\n", "http", "pastmaxb.com", "/"); + + dFree(server_date); +} + +static void path() +{ + a_Cookies_set("name=val; path=/", "p1.com", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p1.com", "/"); + + a_Cookies_set("name=val; path=/dir1", "p2.com", "/dir2", NULL); + expect(__LINE__, "", "http", "p2.com", "/"); + expect(__LINE__, "", "http", "p2.com", "/d"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p2.com", "/dir1"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p2.com", "/dir1/"); + expect(__LINE__, "", "http", "p2.com", "/dir2"); + expect(__LINE__, "", "http", "p2.com", "/dir11"); + + a_Cookies_set("name=val; path=dir1", "p3.com", "/dir2", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p3.com", "/"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p3.com", "/dir1"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p3.com", "/dir2"); + + a_Cookies_set("name=val; path=/dir1/", "p4.com", "/dir2", NULL); + expect(__LINE__, "", "http", "p4.com", "/"); + /* this next one strikes me as a bit odd, personally, but I suppose it's not + * a big deal */ + expect(__LINE__, "", "http", "p4.com", "/dir1"); + expect(__LINE__, "", "http", "p4.com", "/dir11"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p4.com", "/dir1/"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p4.com", "/dir1/sub"); + + a_Cookies_set("name=val", "p5.com", "/dir/subdir", NULL); + expect(__LINE__, "", "http", "p5.com", "/"); + expect(__LINE__, "", "http", "p5.com", "/bir"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p5.com", "/dir"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p5.com", "/dir/"); + + a_Cookies_set("name=val", "p6.com", "/dir/subdir/", NULL); + expect(__LINE__, "", "http", "p6.com", "/dir/"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p6.com", "/dir/subdir"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "p6.com", "/dir/subdir/s"); +} + +int main() +{ + a_Cookies_set("name=val", "ordinary.com", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "ordinary.com", "/"); + + toomany(); + maxage(); + expires_server_ahead(); + expires_server_behind(); + expires_extremes(); + + a_Cookies_set("name=val; expires=\"Sun Jan 10 00:00:00 2038\"", + "quoted-date.org", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "quoted-date.org", "/"); + + a_Cookies_set("name=val; expires=\"Sun Jan 11 00:00:00 1970\"", + "quoted-pastdate.org", "/", NULL); + expect(__LINE__, "", "http", "quoted-pastdate.org", "/"); + + path(); + + /* LEADING/TRAILING DOTS AND A LITTLE PUBLIC SUFFIX */ + a_Cookies_set("name=val; domain=co.uk", "www.co.uk", "/", NULL); + expect(__LINE__, "", "http", "www.co.uk", "/"); + + a_Cookies_set("name=val; domain=.co.uk", "www.co.uk", "/", NULL); + expect(__LINE__, "", "http", "www.co.uk", "/"); + + a_Cookies_set("name=val; domain=co.uk.", "www.co.uk.", "/", NULL); + expect(__LINE__, "", "http", "www.co.uk.", "/"); + + a_Cookies_set("name=val; domain=.co.uk.", "www.co.uk.", "/", NULL); + expect(__LINE__, "", "http", ".www.co.uk.", "/"); + + a_Cookies_set("name=val; domain=co.org", "www.co.org", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "www.co.org", "/"); + + a_Cookies_set("name=val; domain=.cp.org", "www.cp.org", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "www.cp.org", "/"); + + + /* DOTDOMAIN */ + a_Cookies_set("name=val; domain=.dotdomain.org", "dotdomain.org", "/", + NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "dotdomain.org", "/"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "www.dotdomain.org", "/"); + + /* HOST_ONLY */ + a_Cookies_set("name=val; domain=.hostonly.org", "hostonly.org", "/", NULL); + a_Cookies_set("name2=val2", "hostonly.org", "/", NULL); + a_Cookies_set("name3=val3; domain=hostonly.org", "hostonly.org", "/", NULL); + expect(__LINE__, "Cookie: name=val; name2=val2; name3=val3\r\n", "http", + "hostonly.org", "/"); + a_Cookies_set("name=new; domain=.hostonly.org", "hostonly.org", "/", NULL); + expect(__LINE__, "Cookie: name=new; name2=val2; name3=val3\r\n", "http", + "hostonly.org", "/"); + a_Cookies_set("name2=new2", "hostonly.org", "/", NULL); + expect(__LINE__, "Cookie: name=new; name2=new2; name3=val3\r\n", "http", + "hostonly.org", "/"); + a_Cookies_set("name3=new3; domain=hostonly.org", "hostonly.org", "/", NULL); + expect(__LINE__, "Cookie: name=new; name2=new2; name3=new3\r\n", "http", + "hostonly.org", "/"); + + /* SUBDOMAIN */ + a_Cookies_set("name=val; domain=www.subdomain.com", "subdomain.com", "/", + NULL); + a_Cookies_set("name=val; domain=.www.subdomain.com", "subdomain.com", "/", + NULL); + expect(__LINE__, "", "http", "subdomain.com", "/"); + expect(__LINE__, "", "http", "www.subdomain.com", "/"); + + /* SUPERDOMAIN(?) */ + a_Cookies_set("name=val; domain=.supdomain.com", "www.supdomain.com", "/", + NULL); + a_Cookies_set("name2=val2; domain=supdomain.com", "www.supdomain.com", "/", + NULL); + expect(__LINE__, "Cookie: name=val; name2=val2\r\n", "http", + "sub2.sub.supdomain.com", "/"); + expect(__LINE__, "Cookie: name=val; name2=val2\r\n", "http", + "www.supdomain.com", "/"); + expect(__LINE__, "Cookie: name=val; name2=val2\r\n", "http", + "supdomain.com", "/"); + + /* UNRELATED */ + a_Cookies_set("name=val; domain=another.com", "unrelated.com", "/", NULL); + expect(__LINE__, "", "http", "another.com", "/"); + a_Cookies_set("name=val; domain=another.com", "a.org", "/", NULL); + expect(__LINE__, "", "http", "another.com", "/"); + a_Cookies_set("name=val; domain=another.com", "badguys.com", "/", NULL); + expect(__LINE__, "", "http", "another.com", "/"); + a_Cookies_set("name=val; domain=another.com", "more.badguys.com", "/", + NULL); + expect(__LINE__, "", "http", "another.com", "/"); + a_Cookies_set("name=val; domain=another.com", "verybadguys.com", "/", NULL); + expect(__LINE__, "", "http", "another.com", "/"); + + a_Cookies_set("name=val; domain=similar.com", "imilar.com", "/", NULL); + a_Cookies_set("name2=val2; domain=similar.com", "ssimilar.com", "/", NULL); + a_Cookies_set("name3=val3; domain=.similar.com", "imilar.com", "/", NULL); + a_Cookies_set("name4=val4; domain=.similar.com", "timilar.com", "/", NULL); + a_Cookies_set("name4=val4; domain=.similar.com", "tiimilar.com", "/", NULL); + expect(__LINE__, "", "http", "similar.com", "/"); + + /* SECURE */ + a_Cookies_set("name=val; secure", "secure.com", "/", NULL); + expect(__LINE__, "", "http", "secure.com", "/"); + expect(__LINE__, "Cookie: name=val\r\n", "https", "secure.com", "/"); + + /* HTTPONLY */ + a_Cookies_set("name=val; HttpOnly", "httponly.net", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "httponly.net", "/"); + + /* GIBBERISH ATTR IGNORED */ + a_Cookies_set("name=val; ldkfals", "gibberish.net", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "gibberish.net", "/"); + + /* WHITESPACE/DELIMITERS */ + a_Cookies_set(" name=val ", "whitespace.net", "/", NULL); + a_Cookies_set("name2=val2;", "whitespace.net", "/", NULL); + expect(__LINE__, "Cookie: name=val; name2=val2\r\n", "http", + "whitespace.net", "/"); + + /* NAMELESS/VALUELESS */ + a_Cookies_set("value", "nonameval.org", "/", NULL); + a_Cookies_set("name=", "nonameval.org", "/", NULL); + a_Cookies_set("name2= ", "nonameval.org", "/", NULL); + expect(__LINE__, "Cookie: name=; name2=\r\n", "http", "nonameval.org", "/"); + a_Cookies_set("=val2", "nonameval.org", "/", NULL); + expect(__LINE__, "Cookie: name=; name2=\r\n", "http", "nonameval.org", "/"); + + + /* SOME IP ADDRS */ + + a_Cookies_set("name=val", "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]", + "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", + "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]", "/"); + + a_Cookies_set("name=val", "[::FFFF:129.144.52.38]", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "[::FFFF:129.144.52.38]", + "/"); + + a_Cookies_set("name=val", "127.0.0.1", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "127.0.0.1", "/"); + + a_Cookies_set("name=val; domain=128.0.0.1", "128.0.0.1", "/", NULL); + expect(__LINE__, "Cookie: name=val\r\n", "http", "128.0.0.1", "/"); + + a_Cookies_set("name=val; domain=130.0.0.1", "129.0.0.1", "/", NULL); + expect(__LINE__, "", "http", "129.0.0.1", "/"); + expect(__LINE__, "", "http", "130.0.0.1", "/"); + + a_Cookies_set("name=val", "2.0.0.1", "/", NULL); + a_Cookies_set("name=bad; domain=22.0.0.1", "2.0.0.1", "/", NULL); + a_Cookies_set("name=bad; domain=.0.0.1", "2.0.0.1", "/", NULL); + a_Cookies_set("name=bad; domain=not-ip.org", "2.0.0.1", "/", NULL); + expect(__LINE__, "", "http", "22.0.0.1", "/"); + expect(__LINE__, "", "http", "not-ip.org", "/"); + expect(__LINE__, "Cookie: name=val\r\n", "http", "2.0.0.1", "/"); + +#if 0 +HAD BEEN PLAYING AROUND WITH REAL PUBLIC SUFFIX +a_Cookies_set("name=val;domain=sub.sub.yokohama.jp", "sub.sub.yokohama.jp", "/", NULL); +MSG("sub sub yokohama should work: %s\n", + a_Cookies_get_query("http", "sub.sub.yokohama.jp", "/")); +a_Cookies_set("name=val; domain=sub.tokyo.jp", "sub.sub.tokyo.jp", "/", NULL); +MSG("sub tokyo jp should fail: %s\n", + a_Cookies_get_query("http", "sub.sub.tokyo.jp", "/")); +a_Cookies_set("name=val; domain=pref.chiba.jp", "sub.pref.chiba.jp", "/", NULL); +MSG("pref chiba jp should succeed: %s\n", + a_Cookies_get_query("http", "sub.pref.chiba.jp", "/")); +a_Cookies_set("name=val; domain=org", "www.dillo.org", "/", NULL); +a_Cookies_set("name=val; domain=org", "dillo.org", "/", NULL); +a_Cookies_set("name=val; domain=org", ".dillo.org", "/", NULL); +a_Cookies_set("name=val; domain=org.", ".dillo.org", "/", NULL); +a_Cookies_set("name=val; domain=org.", ".dillo.org.", "/", NULL); +MSG("org should fail: %s\n", + a_Cookies_get_query("http", "www.dillo.org", "/")); +#endif + + MSG("TESTS: passed: %u failed: %u\n", passed, failed); + return 0; +} diff --git a/test/dw_anchors_test.cc b/test/dw_anchors_test.cc index 8615439e..977d724a 100644 --- a/test/dw_anchors_test.cc +++ b/test/dw_anchors_test.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -57,7 +56,7 @@ static void textTimeout (void *data) { Textblock *oldTop = topTextblock; topTextblock = new Textblock (false); - + if (oldTop) { oldTop->addLinebreak (wordStyle); oldTop->addWidget (topTextblock, widgetStyle); @@ -73,7 +72,7 @@ static void textTimeout (void *data) buf[0] = toupper (buf[0]); topTextblock->addText (buf, headingStyle); topTextblock->addParbreak (5, headingStyle); - + for (int i = 0; i < 30; i++) { strcpy (buf, numbers[textblockNo]); if (i == 0) @@ -85,7 +84,7 @@ static void textTimeout (void *data) } topTextblock->flush (); - + textblockNo++; if (textblockNo < 10) ::fltk::repeat_timeout (1, textTimeout, NULL); @@ -99,7 +98,7 @@ int main(int argc, char **argv) platform = new FltkPlatform (); layout = new Layout (platform); - window = new ::fltk::Window(250, 200, "Dw Find Test"); + window = new ::fltk::Window(250, 200, "Dw Anchors Test"); window->begin(); viewport = new FltkViewport (50, 0, 200, 200); @@ -121,13 +120,14 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; StyleAttrs styleAttrs; styleAttrs.initValues (); styleAttrs.font = Font::create (layout, &fontAttrs); styleAttrs.margin.setVal (5); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); topWidgetStyle = Style::create (layout, &styleAttrs); styleAttrs.margin.left = 20; diff --git a/test/dw_border_test.cc b/test/dw_border_test.cc index 0c2b7783..b7586608 100644 --- a/test/dw_border_test.cc +++ b/test/dw_border_test.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -49,7 +48,7 @@ int main(int argc, char **argv) styleAttrs.initValues (); styleAttrs.margin.setVal (5); styleAttrs.borderWidth.setVal (2); - styleAttrs.setBorderColor (Color::createShaded (layout, 0xffffff)); + styleAttrs.setBorderColor (Color::create (layout, 0xffffff)); styleAttrs.setBorderStyle (BORDER_INSET); styleAttrs.padding.setVal (5); @@ -58,17 +57,18 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); Style *widgetStyle1 = Style::create (layout, &styleAttrs); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffff80); + styleAttrs.backgroundColor = Color::create (layout, 0xffff80); styleAttrs.margin.setVal (0); styleAttrs.borderWidth.setVal (1); - styleAttrs.setBorderColor (Color::createSimple (layout, 0x4040ff)); + styleAttrs.setBorderColor (Color::create (layout, 0x4040ff)); styleAttrs.setBorderStyle (BORDER_SOLID); styleAttrs.padding.setVal (1); @@ -89,7 +89,7 @@ int main(int argc, char **argv) const char *words1[] = { "Some", "random", "text.", NULL }; const char *words2[] = { "A", "nested", "paragraph.", NULL }; - + for(int i = 0; words1[i]; i++) { if(i != 0) textblock1->addSpace (wordStyle); @@ -98,7 +98,7 @@ int main(int argc, char **argv) for(int i = 0; i < 1; i++) { textblock1->addParbreak(0, wordStyle); - + Textblock *textblock2 = new Textblock (false); textblock1->addWidget (textblock2, widgetStyle2); diff --git a/test/dw_example.cc b/test/dw_example.cc index 75b891e2..1ce643f8 100644 --- a/test/dw_example.cc +++ b/test/dw_example.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -50,14 +49,15 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = dw::core::style::FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs); styleAttrs.color = - dw::core::style::Color::createSimple (layout, 0x000000); + dw::core::style::Color::create (layout, 0x000000); styleAttrs.backgroundColor = - dw::core::style::Color::createSimple (layout, 0xffffff); + dw::core::style::Color::create (layout, 0xffffff); - dw::core::style::Style *widgetStyle = + dw::core::style::Style *widgetStyle = dw::core::style::Style::create (layout, &styleAttrs); dw::Textblock *textblock = new dw::Textblock (false); diff --git a/test/dw_find_test.cc b/test/dw_find_test.cc index a43b4e59..a0743754 100644 --- a/test/dw_find_test.cc +++ b/test/dw_find_test.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -44,11 +43,11 @@ static ::fltk::Widget *resultLabel; static void findCallback (::fltk::Widget *widget, void *data) { //switch(layout->search ("worm", true)) { - switch(layout->search ("WORM", false)) { + switch(layout->search ("WORM", false, false)) { case FindtextState::SUCCESS: resultLabel->label("SUCCESS"); break; - + case FindtextState::RESTART: resultLabel->label("RESTART"); break; @@ -94,13 +93,14 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; StyleAttrs styleAttrs; styleAttrs.initValues (); styleAttrs.font = Font::create (layout, &fontAttrs); styleAttrs.margin.setVal (10); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); Style *topWidgetStyle = Style::create (layout, &styleAttrs); styleAttrs.margin.setVal (0); diff --git a/test/dw_float_test.cc b/test/dw_float_test.cc index f0ba1b55..8966b2af 100644 --- a/test/dw_float_test.cc +++ b/test/dw_float_test.cc @@ -52,15 +52,16 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); Style *widgetStyle = Style::create (layout, &styleAttrs); styleAttrs.borderWidth.setVal (1); - styleAttrs.setBorderColor (Color::createShaded (layout, 0x808080)); + styleAttrs.setBorderColor (Color::create (layout, 0x808080)); styleAttrs.setBorderStyle (BORDER_DASHED); styleAttrs.width = createAbsLength(100); styleAttrs.vloat = FLOAT_LEFT; diff --git a/test/dw_images_scaled.cc b/test/dw_images_scaled.cc index dfaf57b9..c9f6e76e 100644 --- a/test/dw_images_scaled.cc +++ b/test/dw_images_scaled.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -58,13 +57,13 @@ static void imageDrawTimeout (void *data) buf[4 * x + 2] = imgRow * 255 / 199; buf[4 * x + 3] = (199 - imgRow) * 255 / 199; } - + imgbuf->copyRow (imgRow, buf); - image->drawRow (imgRow); + image->drawRow (imgRow); imgRow++; } } - + if(imgRow < 200) ::fltk::repeat_timeout (0.5, imageDrawTimeout, NULL); } @@ -80,13 +79,13 @@ static void imageDrawTimeout (void *data) buf[3 * x + 1] = (399 - x) * 255 / 399; buf[3 * x + 2] = imgRow * 255 / 199; } - + imgbuf->copyRow (imgRow, buf); - image->drawRow (imgRow); + image->drawRow (imgRow); imgRow++; } } - + if(imgRow < 200) ::fltk::repeat_timeout (0.5, imageDrawTimeout, NULL); } @@ -113,10 +112,11 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); Style *widgetStyle = Style::create (layout, &styleAttrs); @@ -133,7 +133,7 @@ int main(int argc, char **argv) image = new dw::Image (""); textblock->addWidget (image, imageStyle); - textblock->addSpace (imageStyle); + textblock->addSpace (imageStyle); imageStyle->unref(); diff --git a/test/dw_images_scaled2.cc b/test/dw_images_scaled2.cc index 39c55046..175ef414 100644 --- a/test/dw_images_scaled2.cc +++ b/test/dw_images_scaled2.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -56,14 +55,14 @@ static void imageDrawTimeout (void *data) buf[3 * x + 1] = (399 - x) * 255 / 399; buf[3 * x + 2] = imgRow * 255 / 199; } - + imgbuf->copyRow (imgRow, buf); - image1->drawRow (imgRow); - image2->drawRow (imgRow); + image1->drawRow (imgRow); + image2->drawRow (imgRow); imgRow++; } } - + if(imgRow < 200) ::fltk::repeat_timeout (0.5, imageDrawTimeout, NULL); } @@ -88,10 +87,11 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); Style *widgetStyle = Style::create (layout, &styleAttrs); @@ -109,7 +109,7 @@ int main(int argc, char **argv) Style *wordStyle = Style::create (layout, &styleAttrs); styleAttrs.borderWidth.setVal (1); - styleAttrs.setBorderColor (Color::createShaded (layout, 0x000080)); + styleAttrs.setBorderColor (Color::create (layout, 0x000080)); styleAttrs.setBorderStyle (BORDER_SOLID); styleAttrs.padding.setVal (1); styleAttrs.backgroundColor = NULL; diff --git a/test/dw_images_simple.cc b/test/dw_images_simple.cc index 78629d55..39b7ed90 100644 --- a/test/dw_images_simple.cc +++ b/test/dw_images_simple.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -41,9 +40,10 @@ static int imgRow = 0; static void imageInitTimeout (void *data) { + const bool resize = true; //imgbuf = layout->createImgbuf (Imgbuf::RGBA, 400, 200); imgbuf = layout->createImgbuf (Imgbuf::RGB, 400, 200); - image->setBuffer (imgbuf); + image->setBuffer (imgbuf, resize); } /* @@ -58,13 +58,13 @@ static void imageDrawTimeout (void *data) buf[4 * x + 2] = imgRow * 255 / 199; buf[4 * x + 3] = (199 - imgRow) * 255 / 199; } - + imgbuf->copyRow (imgRow, buf); - image->drawRow (imgRow); + image->drawRow (imgRow); imgRow++; } } - + if(imgRow < 200) ::fltk::repeat_timeout (0.5, imageDrawTimeout, NULL); } @@ -80,13 +80,13 @@ static void imageDrawTimeout (void *data) buf[3 * x + 1] = (399 - x) * 255 / 399; buf[3 * x + 2] = imgRow * 255 / 199; } - + imgbuf->copyRow (imgRow, buf); - image->drawRow (imgRow); + image->drawRow (imgRow); imgRow++; } } - + if(imgRow < 200) ::fltk::repeat_timeout (0.5, imageDrawTimeout, NULL); } @@ -111,10 +111,11 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); Style *widgetStyle = Style::create (layout, &styleAttrs); @@ -131,7 +132,7 @@ int main(int argc, char **argv) image = new dw::Image (""); textblock->addWidget (image, imageStyle); - textblock->addSpace (imageStyle); + textblock->addSpace (imageStyle); imageStyle->unref(); diff --git a/test/dw_imgbuf_mem_test.cc b/test/dw_imgbuf_mem_test.cc index 897e47f8..33131134 100644 --- a/test/dw_imgbuf_mem_test.cc +++ b/test/dw_imgbuf_mem_test.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -34,7 +33,7 @@ void solution1 () { FltkPlatform *platform = new FltkPlatform (); Layout *layout = new Layout (platform); - + Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100); rootbuf->ref (); // Extra reference by the dicache. printf ("=== Can be deleted? %s.\n", @@ -49,7 +48,7 @@ void solution1 () printf ("=== Can be deleted? %s.\n", rootbuf->lastReference () ? "Yes" : "No"); rootbuf->unref (); // Extra reference by the dicache. - + delete layout; } @@ -57,7 +56,7 @@ void solution2 () { FltkPlatform *platform = new FltkPlatform (); Layout *layout = new Layout (platform); - + Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100); rootbuf->setDeleteOnUnref (false); printf ("=== Can be deleted? %s.\n", @@ -72,7 +71,7 @@ void solution2 () printf ("=== Can be deleted? %s.\n", !rootbuf->isReferred () ? "Yes" : "No"); delete rootbuf; - + delete layout; } @@ -91,13 +90,13 @@ void solution3 () { FltkPlatform *platform = new FltkPlatform (); Layout *layout = new Layout (platform); - + Imgbuf *rootbuf = layout->createImgbuf (Imgbuf::RGB, 100, 100); rootbuf->connectDeletion (new RootbufDeletionReceiver ()); Imgbuf *scaledbuf = rootbuf->getScaledBuf (50, 50); rootbuf->unref (); scaledbuf->unref (); - + delete layout; } diff --git a/test/dw_links.cc b/test/dw_links.cc index 4d15d520..44628b28 100644 --- a/test/dw_links.cc +++ b/test/dw_links.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -33,35 +32,38 @@ using namespace dw::core; using namespace dw::core::style; using namespace dw::fltk; -class LinkTestReceiver: public Widget::LinkReceiver +class LinkTestReceiver: public Layout::LinkReceiver { - bool enter (Widget *widget, int link, int x, int y); - bool press (Widget *widget, int link, int x, int y, EventButton *event); - bool release (Widget *widget, int link, int x, int y, EventButton *event); - bool click (Widget *widget, int link, int x, int y, EventButton *event); + bool enter (Widget *widget, int link, int img, int x, int y); + bool press (Widget *widget, int link, int img, int x, int y, + EventButton *event); + bool release (Widget *widget, int link, int img, int x, int y, + EventButton *event); + bool click (Widget *widget, int link, int img, + int x, int y, EventButton *event); }; -bool LinkTestReceiver::enter (Widget *widget, int link, int x, int y) +bool LinkTestReceiver::enter (Widget *widget, int link, int img, int x, int y) { printf ("enter: %d\n", link); return true; } -bool LinkTestReceiver::press (Widget *widget, int link, int x, int y, +bool LinkTestReceiver::press (Widget *widget, int link, int img, int x, int y, EventButton *event) { printf ("press: %d\n", link); return true; } -bool LinkTestReceiver::release (Widget *widget, int link, int x, int y, +bool LinkTestReceiver::release (Widget *widget, int link, int img, int x,int y, EventButton *event) { printf ("release: %d\n", link); return true; } -bool LinkTestReceiver::click (Widget *widget, int link, int x, int y, +bool LinkTestReceiver::click (Widget *widget, int link, int img, int x, int y, EventButton *event) { printf ("click: %d\n", link); @@ -89,10 +91,11 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); Style *widgetStyle = Style::create (layout, &styleAttrs); @@ -100,7 +103,7 @@ int main(int argc, char **argv) textblock->setStyle (widgetStyle); layout->setWidget (textblock); - textblock->connectLink (&linkTestReceiver); + layout->connectLink (&linkTestReceiver); widgetStyle->unref(); @@ -110,10 +113,10 @@ int main(int argc, char **argv) Style *wordStyle = Style::create (layout, &styleAttrs); - styleAttrs.color = Color::createSimple (layout, 0x0000ff); + styleAttrs.color = Color::create (layout, 0x0000ff); styleAttrs.textDecoration = TEXT_DECORATION_UNDERLINE; styleAttrs.cursor = CURSOR_POINTER; - + for(int i = 1; i <= 10; i++) { char buf[4]; sprintf(buf, "%d.", i); @@ -130,15 +133,15 @@ int main(int argc, char **argv) textblock->addText(words1[j], wordStyle); textblock->addSpace(wordStyle); } - + styleAttrs.x_link = i; Style *linkStyle = Style::create (layout, &styleAttrs); - + for(int j = 0; words2[j]; j++) { textblock->addText(words2[j], linkStyle); textblock->addSpace(wordStyle); } - + linkStyle->unref (); textblock->addParbreak(10, wordStyle); diff --git a/test/dw_links2.cc b/test/dw_links2.cc index e1db9011..294950af 100644 --- a/test/dw_links2.cc +++ b/test/dw_links2.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -33,35 +32,38 @@ using namespace dw::core; using namespace dw::core::style; using namespace dw::fltk; -class LinkTestReceiver: public Widget::LinkReceiver +class LinkTestReceiver: public Layout::LinkReceiver { - bool enter (Widget *widget, int link, int x, int y); - bool press (Widget *widget, int link, int x, int y, EventButton *event); - bool release (Widget *widget, int link, int x, int y, EventButton *event); - bool click (Widget *widget, int link, int x, int y, EventButton *event); + bool enter (Widget *widget, int link, int img, int x, int y); + bool press (Widget *widget, int link, int img, int x, int y, + EventButton *event); + bool release (Widget *widget, int link, int img, int x, int y, + EventButton *event); + bool click (Widget *widget, int link, int img, int x, int y, + EventButton *event); }; -bool LinkTestReceiver::enter (Widget *widget, int link, int x, int y) +bool LinkTestReceiver::enter (Widget *widget, int link, int img, int x, int y) { printf ("enter: %d\n", link); return true; } -bool LinkTestReceiver::press (Widget *widget, int link, int x, int y, +bool LinkTestReceiver::press (Widget *widget, int link, int img, int x, int y, EventButton *event) { printf ("press: %d\n", link); return true; } -bool LinkTestReceiver::release (Widget *widget, int link, int x, int y, +bool LinkTestReceiver::release (Widget *widget, int link, int img, int x,int y, EventButton *event) { printf ("release: %d\n", link); return true; } -bool LinkTestReceiver::click (Widget *widget, int link, int x, int y, +bool LinkTestReceiver::click (Widget *widget, int link, int img, int x, int y, EventButton *event) { printf ("click: %d\n", link); @@ -76,7 +78,7 @@ int main(int argc, char **argv) FltkPlatform *platform = new FltkPlatform (); Layout *layout = new Layout (platform); - ::fltk::Window *window = new ::fltk::Window(200, 300, "Dw Links"); + ::fltk::Window *window = new ::fltk::Window(200, 300, "Dw Links2"); window->begin(); ::fltk::Widget *Panel = new ::fltk::Widget(0, 0, ww, lh, "CONTROL PANEL"); @@ -117,10 +119,11 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); Style *widgetStyle = Style::create (layout, &styleAttrs); @@ -128,7 +131,7 @@ int main(int argc, char **argv) textblock->setStyle (widgetStyle); layout->setWidget (textblock); - textblock->connectLink (new LinkTestReceiver ()); + layout->connectLink (new LinkTestReceiver ()); widgetStyle->unref(); @@ -138,10 +141,10 @@ int main(int argc, char **argv) Style *wordStyle = Style::create (layout, &styleAttrs); - styleAttrs.color = Color::createSimple (layout, 0x0000ff); + styleAttrs.color = Color::create (layout, 0x0000ff); styleAttrs.textDecoration = TEXT_DECORATION_UNDERLINE; styleAttrs.cursor = CURSOR_POINTER; - + for(int i = 1; i <= 30; i++) { char buf[4]; sprintf(buf, "%d.", i); @@ -158,15 +161,15 @@ int main(int argc, char **argv) textblock->addText (words1[j], wordStyle); textblock->addSpace(wordStyle); } - + styleAttrs.x_link = i; Style *linkStyle = Style::create (layout, &styleAttrs); - + for(int j = 0; words2[j]; j++) { textblock->addText (words2[j], linkStyle); textblock->addSpace(wordStyle); } - + linkStyle->unref (); textblock->addParbreak(10, wordStyle); diff --git a/test/dw_lists.cc b/test/dw_lists.cc index 99e78149..2725c34d 100644 --- a/test/dw_lists.cc +++ b/test/dw_lists.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -54,10 +53,11 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); Style *widgetStyle = Style::create (layout, &styleAttrs); @@ -75,8 +75,8 @@ int main(int argc, char **argv) styleAttrs.margin.setVal (5); styleAttrs.padding.setVal (5); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffff40); - styleAttrs.setBorderColor (Color::createSimple (layout, 0x000000)); + styleAttrs.backgroundColor = Color::create (layout, 0xffff40); + styleAttrs.setBorderColor (Color::create (layout, 0x000000)); styleAttrs.setBorderStyle (BORDER_SOLID); styleAttrs.borderWidth.setVal (1); @@ -90,7 +90,7 @@ int main(int argc, char **argv) "comes", "some", "more", "text", "to", "demonstrate", "word", "wrapping.", NULL }; - + for(int i = 0; wordsPar[i]; i++) { if(i != 0) textblock->addSpace (wordStyle); @@ -109,7 +109,7 @@ int main(int argc, char **argv) char buf[16]; sprintf (buf, "%d.", i); - listItem->initWithText (strdup (buf), wordStyle); + listItem->initWithText (buf, wordStyle); for(int j = 0; wordsItem[j]; j++) { if(j != 0) diff --git a/test/dw_resource_test.cc b/test/dw_resource_test.cc index fc825836..28611bb0 100644 --- a/test/dw_resource_test.cc +++ b/test/dw_resource_test.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -40,7 +39,7 @@ int main(int argc, char **argv) FltkPlatform *platform = new FltkPlatform (); Layout *layout = new Layout (platform); - ::fltk::Window *window = new ::fltk::Window(410, 210, "Dw Simple Image"); + ::fltk::Window *window = new ::fltk::Window(410, 210, "Dw Resource test"); window->begin(); FltkViewport *viewport = new FltkViewport (0, 0, 410, 210); @@ -55,10 +54,11 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); Style *widgetStyle = Style::create (layout, &styleAttrs); @@ -72,10 +72,10 @@ int main(int argc, char **argv) styleAttrs.backgroundColor = NULL; SelectionResource *res = layout->getResourceFactory()->createListResource - (ListResource::SELECTION_AT_MOST_ONE); + (ListResource::SELECTION_AT_MOST_ONE, 4); //SelectionResource *res = // layout->getResourceFactory()->createOptionMenuResource (); - + Embed *embed = new Embed (res); textblock->addWidget (embed, widgetStyle); textblock->addSpace (widgetStyle); diff --git a/test/dw_table.cc b/test/dw_table.cc index d269d551..b0e9c4db 100644 --- a/test/dw_table.cc +++ b/test/dw_table.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -51,9 +50,9 @@ int main(int argc, char **argv) styleAttrs.padding.setVal (0); styleAttrs.borderWidth.setVal (1); styleAttrs.setBorderStyle (BORDER_OUTSET); - styleAttrs.setBorderColor (Color::createShaded (layout, 0xffffff)); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.setBorderColor (Color::create (layout, 0xffffff)); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); styleAttrs.hBorderSpacing = 5; styleAttrs.vBorderSpacing = 5; @@ -62,6 +61,7 @@ int main(int argc, char **argv) fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); Style *tableStyle = Style::create (layout, &styleAttrs); diff --git a/test/dw_table_aligned.cc b/test/dw_table_aligned.cc index beb8525d..67cf21f3 100644 --- a/test/dw_table_aligned.cc +++ b/test/dw_table_aligned.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -50,17 +49,18 @@ int main(int argc, char **argv) styleAttrs.margin.setVal (5); styleAttrs.borderWidth.setVal (1); styleAttrs.setBorderStyle (BORDER_OUTSET); - styleAttrs.setBorderColor (Color::createShaded (layout, 0x808080)); + styleAttrs.setBorderColor (Color::create (layout, 0x808080)); FontAttrs fontAttrs; fontAttrs.name = "Bitstream Charter"; fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xa0a0a0); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xa0a0a0); styleAttrs.hBorderSpacing = 5; styleAttrs.vBorderSpacing = 5; @@ -74,7 +74,7 @@ int main(int argc, char **argv) styleAttrs.borderWidth.setVal (1); styleAttrs.setBorderStyle (BORDER_INSET); - + Style *cellStyle = Style::create (layout, &styleAttrs); styleAttrs.borderWidth.setVal (0); @@ -104,7 +104,7 @@ int main(int argc, char **argv) cell->addText (buf, wordStyle); cell->flush (); - } + } wordStyle->unref(); cellStyle->unref(); diff --git a/test/dw_ui_test.cc b/test/dw_ui_test.cc index 5ce949ef..2bc35893 100644 --- a/test/dw_ui_test.cc +++ b/test/dw_ui_test.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -53,14 +52,15 @@ int main(int argc, char **argv) StyleAttrs styleAttrs; styleAttrs.initValues (); styleAttrs.margin.setVal (5); - styleAttrs.color = Color::createSimple (layout, 0x000000); - styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); + styleAttrs.color = Color::create (layout, 0x000000); + styleAttrs.backgroundColor = Color::create (layout, 0xffffff); FontAttrs fontAttrs; fontAttrs.name = "Helvetica"; fontAttrs.size = 14; fontAttrs.weight = 400; fontAttrs.style = FONT_STYLE_NORMAL; + fontAttrs.letterSpacing = 0; styleAttrs.font = Font::create (layout, &fontAttrs); Style *tableStyle = Style::create (layout, &styleAttrs); @@ -79,10 +79,10 @@ int main(int argc, char **argv) // First of all, the resources. Later, they are embedded into the // widget tree. EntryResource *entryres1 = - layout->getResourceFactory()->createEntryResource (10, false); + layout->getResourceFactory()->createEntryResource (10, false, NULL); entryres1->setText ("Hi!"); EntryResource *entryres2 = - layout->getResourceFactory()->createEntryResource (10, true); + layout->getResourceFactory()->createEntryResource (10, true, NULL); MultiLineTextResource *textres = layout->getResourceFactory()->createMultiLineTextResource (15,3); RadioButtonResource *radiores1 = @@ -95,13 +95,13 @@ int main(int argc, char **argv) SelectionResource *selres[2]; selres[0] = layout->getResourceFactory()->createOptionMenuResource (); selres[1] = layout->getResourceFactory()->createListResource - (ListResource::SELECTION_AT_MOST_ONE); + (ListResource::SELECTION_AT_MOST_ONE, 4); LabelButtonResource *buttonres = layout->getResourceFactory()->createLabelButtonResource ("Run!"); // Note on complex buttons: before any operations on the widget, which // need a layout, the complex button resource should be created, since - // then, a layout and a platform are instanciated. + // then, a layout and a platform are instantiated. Textblock *cbuttontext = new Textblock(false); ComplexButtonResource *cbuttonres = layout->getResourceFactory()->createComplexButtonResource (cbuttontext, diff --git a/test/fltk_browser.cc b/test/fltk_browser.cc index 4186156e..11dfcbeb 100644 --- a/test/fltk_browser.cc +++ b/test/fltk_browser.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -40,7 +39,7 @@ int main (int argc, char *argv[]) new Item ("second"); new Item ("third"); } - + window->resizable(browser); window->show(); return run(); diff --git a/test/form.cc b/test/form.cc index 5e8e0471..4bebd520 100644 --- a/test/form.cc +++ b/test/form.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -50,7 +49,7 @@ const char *Form::TextResourceDecorator::getValue () Form::RadioButtonResourceDecorator::RadioButtonResourceDecorator (const char *name, RadioButtonResource *resource, const char **values): - Form::ResourceDecorator (name) + Form::ResourceDecorator (name) { this->resource = resource; @@ -60,7 +59,7 @@ Form::RadioButtonResourceDecorator::RadioButtonResourceDecorator this->values = new const char*[n + 1]; for(int i = 0; i < n; i++) this->values[i] = strdup (values[i]); - values[n] = 0; + this->values[n] = 0; } Form::RadioButtonResourceDecorator::~RadioButtonResourceDecorator () @@ -100,7 +99,7 @@ const char *Form::CheckButtonResourceDecorator::getValue () Form::SelectionResourceDecorator::SelectionResourceDecorator (const char *name, SelectionResource *resource, const char **values): - Form::ResourceDecorator (name) + Form::ResourceDecorator (name) { this->resource = resource; @@ -163,18 +162,18 @@ Form::FormClickedReceiver::~FormClickedReceiver () delete name; delete[] value; } - -void Form::FormClickedReceiver::clicked (ButtonResource *resource, - int buttonNo, int x, int y) + +void Form::FormClickedReceiver::clicked (Resource *resource, + dw::core::EventButton *event) { - form->send (name, value, x, y); + form->send (name, value, event->xCanvas, event->yCanvas); } Form::Form () { resources = new lout::container::typed::List <ResourceDecorator> (true); activateReceiver = new FormActivateReceiver (this); - clickedReceivers = + clickedReceivers = new lout::container::typed::List <FormClickedReceiver> (true); } diff --git a/test/form.hh b/test/form.hh index a04460f4..6235c6cc 100644 --- a/test/form.hh +++ b/test/form.hh @@ -55,7 +55,7 @@ private: /** * \brief Decorates instances of dw::core::ui::RadioButtonResource. * - * This class has to be instanciated only once for a group of radio + * This class has to be instantiated only once for a group of radio * buttons. */ class RadioButtonResourceDecorator: public ResourceDecorator @@ -113,14 +113,14 @@ private: public: inline FormActivateReceiver (Form *form) { this->form = form; } - + void activate (dw::core::ui::Resource *resource); void enter (dw::core::ui::Resource *resource); void leave (dw::core::ui::Resource *resource); }; class FormClickedReceiver: - public dw::core::ui::ButtonResource::ClickedReceiver + public dw::core::ui::Resource::ClickedReceiver { private: Form *form; @@ -129,9 +129,9 @@ private: public: FormClickedReceiver (Form *form, const char *name, const char *value); ~FormClickedReceiver (); - - void clicked (dw::core::ui::ButtonResource *resource, int buttonNo, - int x, int y); + + void clicked(dw::core::ui::Resource *resource, + dw::core::EventButton *event); }; lout::container::typed::List <ResourceDecorator> *resources; diff --git a/test/shapes.cc b/test/shapes.cc index 8d33152b..30aa7d81 100644 --- a/test/shapes.cc +++ b/test/shapes.cc @@ -14,8 +14,7 @@ * 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -23,7 +22,7 @@ #include "../dw/core.hh" using namespace dw::core; -using namespace misc; +using namespace lout::misc; int main() { |