[axel-commits] r62 - in /branches/3.x-broken: doc/ROADMAP src/axel.c src/axel.h src/conf.c src/helper.c src/helper.h src/proto.c src/url.c src/url.h src/urllist.c src/urllist.h test/test_url.c test/test_urllist.c test/test_urllist.h test/tests.h
phihag-guest at users.alioth.debian.org
phihag-guest at users.alioth.debian.org
Fri Nov 14 12:13:22 UTC 2008
Author: phihag-guest
Date: Fri Nov 14 12:13:22 2008
New Revision: 62
URL: http://svn.debian.org/wsvn/axel/?sc=1&rev=62
Log:
Added URL lists and URL priorities
added debug_print and debug_printf for debugging
Various fixes
Added:
branches/3.x-broken/src/urllist.c
branches/3.x-broken/src/urllist.h
branches/3.x-broken/test/test_urllist.c
branches/3.x-broken/test/test_urllist.h
Modified:
branches/3.x-broken/doc/ROADMAP
branches/3.x-broken/src/axel.c
branches/3.x-broken/src/axel.h
branches/3.x-broken/src/conf.c
branches/3.x-broken/src/helper.c
branches/3.x-broken/src/helper.h
branches/3.x-broken/src/proto.c
branches/3.x-broken/src/url.c
branches/3.x-broken/src/url.h
branches/3.x-broken/test/test_url.c
branches/3.x-broken/test/tests.h
Modified: branches/3.x-broken/doc/ROADMAP
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/doc/ROADMAP?rev=62&op=diff
==============================================================================
--- branches/3.x-broken/doc/ROADMAP (original)
+++ branches/3.x-broken/doc/ROADMAP Fri Nov 14 12:13:22 2008
@@ -42,6 +42,7 @@
* Check chinese man file, correct installation
* Find out whether chinese manpage should be installed
* Scrap crappy OS workaround? (Test on Windows)
+* axel: new -> init, free -> destroy ?
Bugs
====
@@ -89,6 +90,9 @@
* Don't discard first HTTP connection, but use it adaptively (start requests from the end, RST as soon as first task is fullfilled)
* A -1 option: Just make one request, and only one.
* IPv6 support
+* Add AXEL_THREADED option: If not set, don't use threads, but select()
+* OUTPUT_FLAGS option to output all the flag's names in --help or so
+* configure options minimal and allfeatures
3.3
===
Modified: branches/3.x-broken/src/axel.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/axel.c?rev=62&op=diff
==============================================================================
--- branches/3.x-broken/src/axel.c (original)
+++ branches/3.x-broken/src/axel.c Fri Nov 14 12:13:22 2008
@@ -25,8 +25,8 @@
#include "axel.h"
+static void axel_examine(axel_t* axel);
static void axel_prepare(axel_t* axel);
-static void axel_init(axel_t* axel);
static void axel_teardown(axel_t* axel);
@@ -72,10 +72,9 @@
void axel_abort(axel_t* axel, int ret) {
axel->state = ret == 0 ? AXEL_STATE_ERROR;
-
- if (ret != 0) {
- axel_teardown(axel);
- }
+ axel_update_status(axel);
+
+ axel_teardown(axel);
if (axel->abort_handler != NULL) {
axel->abort_handler(axel, ret);
@@ -84,26 +83,32 @@
}
}
-/* Add a URL. urlstr is a pointer to a string specified by the user */
-void axel_add_urlstr(axel_t* axel, const char* urlstr) {
- axel_add_url(axel, url_parse(urlstr));
-}
-
-/* Add a URL. From now on, the heap entry pointed to is owned by the axel_t struct */
-void axel_add_url(axel_t* axel, url_t* url) {
- axel_add_url_prio(axel, url,
- url_li_t* p = axel->urls;
- while (p != NULL) {
- p = p->next;
- }
- p->next = url_li_new(url);
+/**
+* Add a URL. urlstr is a pointer to a string specified by the user
+* @param priority The priority of this URL. If not URL_PRIO_NONE, this overwrites any priority in the URL.
+* @return 1 iff the URL was added
+*/
+_Bool axel_addurlstr(axel_t* axel, const char* urlstr, int priority) {
+ url_t* url = url_parse_heuristic(urlstr);
+
+ if (url == NULL) {
+ return 0;
+ }
+
+ if (priority != URL_PRIO_NONE) {
+ url->priority = priority;
+ }
+
+ urllist_add(axel->urls, url);
+
+ return 1;
}
axel_t* axel_new(const conf_t* conf) {
axel_t* res = malloc( sizeof( axel_t ) );
res->conf = conf;
- res->urls = NULL;
+ urllist_init(&(res->urls));
res->conncount = -1;
// conn is set once we know conncount
@@ -128,10 +133,7 @@
}
void axel_free(axel_t* axel) {
- url_li_t* urlip = axel->urls;
- while (urlip != NULL) {
- urlip = url_li_free(urlip);
- }
+ urllist_free(axel->urls);
free(axel->filename);
free(axel->statefilename);
@@ -143,10 +145,10 @@
* Start downloading a file. If you want to know anything more about the download, register handlers.
*/
void axel_start(axel_t* axel) {
- axel_prepare(axel);
+ axel_examine(axel);
if (axel->state == AXEL_STATE_READY) {
- axel_init(axel);
+ axel_prepare(axel);
}
}
@@ -154,17 +156,18 @@
/**
* Find out file size, file name and stuff
*/
-static void axel_prepare(axel_t* axel) {
+static void axel_examine(axel_t* axel) {
// TODO determine filename
// TODO determine file size
axel->state = AXEL_STATE_READY;
+ axel_update_status();
}
/**
* Initialize a prepared download, start all threads
*/
-static void axel_init(axel_t* axel) {
+static void axel_prepare(axel_t* axel) {
// TODO set conncount according to conf
// Determine file name
@@ -189,7 +192,7 @@
// TODO start threads
-
+ axel_update_status(axel);
}
/**
@@ -207,32 +210,6 @@
-
-/**
-* Construct a new item of a URL list.
-* @param url The Item. From now on, it is owned by this struct
-*/
-inline url_li_t* url_li_new(url_t* url) {
- url_li_t* res = malloc(sizeof(url_li_t));
-
- res->url = url;
- res->next = NULL;
-
- return res;
-}
-
-/**
-* Free a URL list item, including the URL itself.
-* @return The next item in the list of URLs
-*/
-inline url_li_t* url_li_free(url_li_t* urlli) {
- url_li_t* next = urlli->next;
-
- free(urlli->url);
- free(urlli);
-
- return res;
-}
Modified: branches/3.x-broken/src/axel.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/axel.h?rev=62&op=diff
==============================================================================
--- branches/3.x-broken/src/axel.h (original)
+++ branches/3.x-broken/src/axel.h Fri Nov 14 12:13:22 2008
@@ -82,6 +82,7 @@
#include "proto.h"
#include "conn.h"
#include "search.h"
+#include "urllist.h"
// Special value for delay_time, see below
#define AXEL_DELAY_TIME_ABORT (-1)
@@ -100,10 +101,12 @@
// Download correctly finished
#define AXEL_STATE_FINISHED 5
+// TODO can we guarantee anything for the handlers?
+
// A download to a single file, probably from multiple sources
struct axel_struct {
const conf_t* conf; // Not owned by this structure
- url_li_t* urls; // Linked list of URLs to read
+ urllist_t urls; // Linked list of URLs to read
int conncount; // The number of connections, -1 if conn is not yet initialized
conn_t** conn; // array of connections, of size conncount. Owned by this struct.
@@ -122,7 +125,7 @@
long long start_utime; // Start time in microseconds
// The download's state, one of the AXEL_STATE_* constants
- int state; // TODO check whether we read this state at all
+ volatile sig_atomic_t state; // TODO check whether we read this state at all
/**
* Time to wait because of speed limit.
@@ -144,7 +147,7 @@
*/
void (*abort_handler)(struct axel_struct* axel, int ret);
/**
- * A handler that displays the download's state. Is called "frequently".
+ * A handler that displays the download's state. Is called "frequently" and on every update of state.
* Leave as NULL for no status display
*/
void (*status_handler)(const struct axel_struct* axel);
@@ -153,8 +156,7 @@
// Main axel API: The following methods are used by the frontend.
axel_t* axel_new(const conf_t *conf);
-void axel_add_url(axel_t* axel, const url_t* url);
-void axel_add_urlstr(axel_t* axel, const char* urlstr);
+_Bool axel_addurlstr(axel_t* axel, const char* urlstr, int priority);
void axel_start(axel_t* axel);
void axel_free(axel_t* axel);
@@ -162,13 +164,3 @@
void axel_message_fmt(const axel_t *axel, const char *format, ... );
void axel_update_status(const axel_t* axel);
void axel_abort(axel_t* axel, int ret);
-
-// An item of a URL list
-struct url_li_struct {
- url_t* url;
- url_li_struct* next; // NULL for end of list
-};
-typedef struct url_li_struct url_li_t;
-
-url_li_t* url_li_new(url_t* url);
-void url_li_free(url_li_t* urlli);
Modified: branches/3.x-broken/src/conf.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/conf.c?rev=62&op=diff
==============================================================================
--- branches/3.x-broken/src/conf.c (original)
+++ branches/3.x-broken/src/conf.c Fri Nov 14 12:13:22 2008
@@ -150,6 +150,7 @@
memset( conf->interfaces, 0, sizeof( if_t ) );
conf->interfaces->next = conf->interfaces;
+ // TODO get this kind of initialization into a method of its own
if( ( s2 = getenv( "http_proxy" ) ) != NULL )
strncpy( conf->http_proxy, s2, MAX_STRING );
else if( ( s2 = getenv( "HTTP_PROXY" ) ) != NULL )
Modified: branches/3.x-broken/src/helper.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/helper.c?rev=62&op=diff
==============================================================================
--- branches/3.x-broken/src/helper.c (original)
+++ branches/3.x-broken/src/helper.c Fri Nov 14 12:13:22 2008
@@ -131,3 +131,17 @@
return ( (long long) time->tv_sec * 1000000 + (long long) time->tv_usec);
}
+
+#ifdef DEBUG
+void debug_print(const char* msg) {
+ debug_printf("%s", msg);
+}
+
+void debug_printf(const char* format, ...) {
+ va_list params;
+
+ va_start(params, format);
+ vfprintf(stderr, format, params);
+ va_end(params);
+}
+#endif
Modified: branches/3.x-broken/src/helper.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/helper.h?rev=62&op=diff
==============================================================================
--- branches/3.x-broken/src/helper.h (original)
+++ branches/3.x-broken/src/helper.h Fri Nov 14 12:13:22 2008
@@ -21,3 +21,12 @@
char* uitoa(unsigned int ui);
long long getutime();
+
+#ifdef DEBUG
+ void debug_print(const char* msg);
+ void debug_printf(const char* format, ...);
+
+ #define DEBUG_ASSERT(assertion,msg) {if (!(assertion)) { debug_print(msg);}}
+#else
+ #define DEBUG_ASSERT(assertion,msg) ;
+#endif
Modified: branches/3.x-broken/src/proto.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/proto.c?rev=62&op=diff
==============================================================================
--- branches/3.x-broken/src/proto.c (original)
+++ branches/3.x-broken/src/proto.c Fri Nov 14 12:13:22 2008
@@ -36,20 +36,20 @@
return PROTO_DEFAULT;
}
- if (strcmp(protostr, PROTO_HTTP_NAME) == 0) {
+ if (strcasecmp(protostr, PROTO_HTTP_NAME) == 0) {
return PROTO_HTTP;
}
#ifdef FTP
- else if (strcmp(protostr, PROTO_FTP_NAME) == 0) {
+ else if (strcasecmp(protostr, PROTO_FTP_NAME) == 0) {
return PROTO_FTP;
}
#endif
#ifdef SSL
- else if (strcmp(protostr, PROTO_HTTPS_NAME) == 0) {
+ else if (strcasecmp(protostr, PROTO_HTTPS_NAME) == 0) {
return PROTO_HTTPS;
}
#ifdef FTP
- else if (strcmp(protostr, PROTO_FTPS_NAME) == 0) {
+ else if (strcasecmp(protostr, PROTO_FTPS_NAME) == 0) {
return PROTO_FTPS;
}
#endif
Modified: branches/3.x-broken/src/url.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/url.c?rev=62&op=diff
==============================================================================
--- branches/3.x-broken/src/url.c (original)
+++ branches/3.x-broken/src/url.c Fri Nov 14 12:13:22 2008
@@ -96,7 +96,7 @@
res = (char*) realloc(res, resp - res + 1);
#ifdef DEBUG
- fprintf(stderr, "Original|Result of heuristic URL decoding:\n%s\n%s", urlstr, res);
+ debug_printf("Original|Result of heuristic URL decoding:\n%s\n%s", urlstr, res);
#endif
return res;
@@ -130,11 +130,16 @@
host = schemesep + strlen(URL_SCHEME_SEP); // Host and rest of the URL
}
res->proto = proto_getid(protostr);
- free(protostr);
+
if (res->proto == PROTO_ERR) {
+ #ifdef DEBUG
+ debug_printf("Unsupported protocol %s", protostr);
+ #endif
+ free(protostr);
free(res);
return NULL;
}
+ free(protostr);
// Request (directory name, file, request, fragment)
char* const request = strchr(host, URL_DIR_SEPCHAR);
@@ -195,27 +200,30 @@
heap_substr_upto(&(res->host), host, portstart);
}
+ res->priority = URL_PRIO_DEFAULT;
+
#ifdef DEBUG
- sprintf(stderr, "Parsed URL:\n");
- sprintf(stderr, "Protocol: %s (Internal ID: %d)\n", proto_getname(res->proto), proto);
+ debug_print("Parsed URL:\n");
+ debug_printf("Protocol: %s (Internal ID: %d)\n", proto_getname(res->proto), proto);
if (res->user != NULL) {
- sprintf(stderr, "User name: %s\n", res->user);
+ debug_printf("User name: %s\n", res->user);
}
if (res->pass != NULL) {
- sprintf(stderr, "Password: %s\n", res->pass);
- }
- sprintf(stderr, "Host: %s\n"; res->host);
- sprintf(stderr, "Port: %d\n", res->port);
+ debug_printf("Password: %s\n", res->pass);
+ }
+ debug_printf("Host: %s\n"; res->host);
+ debug_printf("Port: %d\n", res->port);
if (res->dir != NULL) {
- sprintf(stderr, "Directory: %s\n", res->dir);
- }
- if (res->fikename != NULL) {
- sprintf(stderr, "File name: %s\n", res->filename);
+ debug_printf("Directory: %s\n", res->dir);
+ }
+ if (res->filename != NULL) {
+ debug_printf("File name: %s\n", res->filename);
}
if (res->query != NULL) {
- sprintf(stderr, "Query: %s\n", res->query);
- }
- sprintf(stderr, "\n");
+ debug_printf("Query: %s\n", res->query);
+ }
+ debug_printf("Priority: %d\n", res->priority);
+ debug_print("\n");
#endif
return res;
Modified: branches/3.x-broken/src/url.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/url.h?rev=62&op=diff
==============================================================================
--- branches/3.x-broken/src/url.h (original)
+++ branches/3.x-broken/src/url.h Fri Nov 14 12:13:22 2008
@@ -31,6 +31,15 @@
#define URL_DIR_SEPCHAR '/'
#define URL_QUERY_SEPCHAR '?'
+#define URL_PRIO_MAX INT_MAX
+#define URL_PRIO_MIN INT_MIN
+#define URL_PRIO_DEFAULT 50
+// No priority specified
+#define URL_PRIO_NONE 49
+// Add this n times to ensure all URLs with a lower n will not be requested until this URL is removed
+// This value may be used by others; it must therefore be a power of 2 and 256.
+#define URL_PRIO_GROUPSIZE 256
+
// All string fields are stored unencoded
typedef struct {
/* Protocol id as defined in proto.h */
@@ -42,10 +51,13 @@
char* query; // Query and fragment of the URL without the initiating question mark, NULL for none
char* user; // NULL if no user specified (set anonymous if user is necessary)
char* pass; // NULL if no password specified (set to any value if required)
+
+ // Metadata
+ int priority;
} url_t;
char* url_encode(const char* origurl);
-char* url_heuristic_decode(const char * urlstr)
+char* url_heuristic_decode(const char* urlstr);
url_t* url_parse_heuristic(const char* urlstr);
url_t* url_parse_unencoded(const char* urlstr);
Added: branches/3.x-broken/src/urllist.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/urllist.c?rev=62&op=file
==============================================================================
--- branches/3.x-broken/src/urllist.c (added)
+++ branches/3.x-broken/src/urllist.c Fri Nov 14 12:13:22 2008
@@ -1,0 +1,172 @@
+static url_li_t* url_li_new(url_t* url);
+static url_li_t* url_li_free(url_li_t* urlli);
+static void url_li_freeall(url_li_t* urlli);
+
+static _Bool urllist_incurgroup(urllist_t* ul, int prio);
+static void urllist_advancenext(urllist_t* ul);
+
+static void urllist_lock(ul);
+static void urllist_unlock(ul);
+
+void urllist_init(urllist_t* ul) {
+ ul->head = NULL;
+ ul->next = NULL;
+ ul->heap = NULL;
+
+ pthread_mutex_init(& ul->lock, NULL);
+}
+
+void urllist_destroy(urllist_t* ul) {
+ url_li_freeall(ul->head);
+ url_li_freeall(ul->heap);
+
+ pthread_mutex_destroy(& ul->lock);
+}
+
+/**
+* Adds a URL to a URL list. From now on, the pointer to the url struct belongs to this struct.
+* An URL struct must not be added twice.
+*/
+void urllist_add(urllist_t* ul, url_t* url) {
+ DEBUG_ASSERT(url != NULL, "Internal error: urllist_addurl(, NULL)");
+
+ urllist_lock(ul);
+
+ int prio = url->priority;
+ url_li_t* item = url_li_new(url);
+
+ url_li_t* prev = NULL;
+ url_li_t* cur = ul->head;
+
+ while ((cur != NULL) && (cur->url->priority >= prio)) {
+ prev = cur;
+ cur = cur->next;
+ }
+
+ item->next = cur;
+ if (prev == NULL) {
+ ul->head = item;
+ } else {
+ prev->next = item;
+ }
+
+ // Update the pointer to the next URL in line
+ if ((ul->next == NULL) || (ul>next->priority < prio)) {
+ ul->next = item;
+ }
+
+ urllist_unlock(ul);
+}
+
+/**
+* Removes an URL from the list. The pointer to the URL becomes invalid afterwards iff 1 is returned!
+* @return 1 iff the URL was removed
+*/
+_Bool urllist_remove(urllist_t* ul, url_t* url) {
+ DEBUG_ASSERT(url != NULL, "Internal error: urllist_removeurl(, NULL)");
+
+ urllist_lock(ul);
+
+ url_li_t* prev = NULL;
+ url_li_t* cur = ul>head;
+
+ while ((cur != NULL) && (cur->url != url)) {
+ prev = cur;
+ cur = cur->next;
+ }
+
+ if (cur == NULL) { // URL not found
+ return 0;
+ }
+
+ if (prev == NULL) {
+ ul->head = cur->next;
+ } else {
+ prev->next = cur->next;
+ }
+
+ urllist_advancenext(ul);
+
+ // Move list item to the heap
+ cur->next = ul->heap;
+ ul->heap = cur;
+
+ urllist_unlock(ul);
+
+ return 1;
+}
+
+url_t* urllist_next(urllist_t* ul) {
+ urllist_lock(ul);
+
+ url_t* res = ul->next->url;
+ urllist_advancenext(ul);
+
+ urllist_unlock(ul);
+
+ return res;
+}
+
+/**
+* Construct a new item of a URL list.
+*/
+inline static url_li_t* url_li_new(url_t* url) {
+ url_li_t* res = malloc(sizeof(url_li_t));
+
+ res->url = url;
+ res->next = NULL;
+
+ return res;
+}
+
+/**
+* Free a URL list item, including the URL itself.
+* @return The next item in the list of URLs
+*/
+inline static url_li_t* url_li_free(url_li_t* urlli) {
+ url_li_t* res = urlli->next;
+
+ free(urlli->url);
+ free(urlli);
+
+ return res;
+}
+
+/**
+* Frees a chain of URL list items
+*/
+static void url_li_freeall(url_li_t* urlli) {
+ while (urlli != NULL) {
+ urlli = url_li_free(urlli);
+ }
+}
+
+/**
+* Helper method to check whether a priority is still in the active group.
+*/
+inline static _Bool urllist_incurgroup(const urllist_t* ul, int prio) {
+ DEBUG_ASSERT(ul->head != NULL, "");
+
+ return (ul->head->url->priority & URLLIST_GROUPMASK) == (prio & URLLIST_GROUPMASK);
+}
+
+/**
+* Move the next pointer to the next URL element to return.
+*/
+static void urllist_advancenext(urllist_t* ul) {
+ url_li_t* nx = ul->next->next;
+
+ if ((nx != NULL) && (urllist_incurgroup(ul, nx->url->priority))) {
+ ul->next = nx;
+ } else {
+ ul->next = head;
+ }
+}
+
+inline static void urllist_lock(ul) {
+ pthread_mutex_lock(& ul->lock);
+}
+
+inline static void urllist_unlock(ul) {
+ pthread_mutex_unlock(& ul->lock);
+}
Added: branches/3.x-broken/src/urllist.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/urllist.h?rev=62&op=file
==============================================================================
--- branches/3.x-broken/src/urllist.h (added)
+++ branches/3.x-broken/src/urllist.h Fri Nov 14 12:13:22 2008
@@ -1,0 +1,30 @@
+/**
+A list of URLs with an associated priority (the higher, the sooner this URL is requested).
+Priorities are grouped in ... groups. Any two URLs are in a common group iff their priorities are identical except for the last eight bits.
+
+All URLs are owned by this struct.
+*/
+
+#define URLLIST_GROUPMASK (~(URL_PRIO_GROUPSIZE - 1))
+
+// An element of the list
+struct url_li_struct {
+ url_t* url;
+ struct url_li_struct* next; // NULL for end of list
+};
+typedef struct url_li_struct url_li_t;
+
+typedef struct {
+ url_li_t* head; // The URL with the highest priority
+ url_li_t* next; // The next URL to serve by urllist_next.
+ url_li_t* heap; // Keeps track of all removed URLs
+
+ pthread_mutex_t lock;
+} urllist_t;
+
+void urllist_init(urllist_t* ul);
+void urllist_add(urllist_t* ul, url_t* url);
+_Bool urllist_remove(urllist_t* ul, url_t* url);
+url_t* urllist_next(urllist_t* ul);
+void urllist_destroy(urllist_t* ul);
+
Modified: branches/3.x-broken/test/test_url.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/test/test_url.c?rev=62&op=diff
==============================================================================
--- branches/3.x-broken/test/test_url.c (original)
+++ branches/3.x-broken/test/test_url.c Fri Nov 14 12:13:22 2008
@@ -22,6 +22,8 @@
static void test_url_request();
static void test_url_request_single(const struct url_t* u, const char* expected);
+
+static void test_url_priority();
static const url_t* test_helper_urlgen(
int proto,
@@ -40,6 +42,7 @@
CU_add_test(ps, "url_parse_unencoded", test_url_parse_unencoded);
CU_add_test(ps, "url_str", test_url_str);
CU_add_test(ps, "url_request", test_url_request);
+ CU_add_test(ps, "URL priorities", test_url_priority);
}
static void test_url_encode() {
@@ -223,6 +226,20 @@
free(got);
}
+static void test_url_priority() {
+ url_t* u = parse_url_heuristic("http://example.com/2");
+ CU_ASSERT_EQUALS(u->priority, URL_PRIORITY_DEFAULT);
+ url_free(u);
+
+ u = parse_url_heuristic("{10}http://example.com/2");
+ CU_ASSERT_EQUALS(u->priority, 10);
+ url_free(u);
+
+ u = parse_url_heuristic("{-10}http://example.com/2");
+ CU_ASSERT_EQUALS(u->priority, -10);
+ url_free(u);
+}
+
static const url_t* test_helper_urlgen(
int proto,
const char* user, const char* pass,
Added: branches/3.x-broken/test/test_urllist.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/test/test_urllist.c?rev=62&op=file
==============================================================================
--- branches/3.x-broken/test/test_urllist.c (added)
+++ branches/3.x-broken/test/test_urllist.c Fri Nov 14 12:13:22 2008
@@ -1,0 +1,79 @@
+
+static void test_urllist();
+
+void test_urllist_suite() {
+ CU_pSuite ps = CU_add_suite("A sorted list of URLs", NULL, NULL);
+
+ CU_add_test(ps, "urllist_*", test_urllist;
+}
+
+static void test_urllist() {
+ int i;
+
+ urllist_t* ul = alloca(sizeof(urllist_t));
+ urllist_init(ul);
+
+ CU_ASSERT_PTR_NOT_NULL(ul);
+ CU_ASSERT_PTR_NULL(urllist_next(ul));
+
+ url_t* url1 = url_parse_heuristic("http://example.org/1");
+ ulrllist_add(ul, url1, URL_PRIO_DEFAULT);
+
+ url_t* url2 = url_parse_heuristic("{42}http://example.org/2");
+ ulrllist_add(ul, url2);
+
+ url_t* url3 = url_parse_heuristic("{42}http://example.org/3");
+ ulrllist_add(ul, url3);
+
+ url_t* url4 = url_parse_heuristic("http://example.org/4");
+ ulrllist_add(ul, url4, 47);
+
+ CU_ASSERT_TRUE(urllist_remove(url1));
+ CU_ASSERT_FALSE(urllist_remove(url1));
+ CU_ASSERT_TRUE(urllist_remove(url3));
+ CU_ASSERT_FALSE(urllist_remove(url1));
+
+ CU_ASSERT_PTR_EQUAL(urllist_next(ul), url4);
+ CU_ASSERT_PTR_EQUAL(urllist_next(ul), url2);
+ CU_ASSERT_PTR_EQUAL(urllist_next(ul), url4);
+ CU_ASSERT_PTR_EQUAL(urllist_next(ul), url2);
+ CU_ASSERT_PTR_EQUAL(urllist_next(ul), url4);
+ CU_ASSERT_PTR_EQUAL(urllist_next(ul), url2);
+
+ CU_ASSERT_TRUE(urllist_remove(url4));
+
+ for (i = 0;i < 10;i++) {
+ CU_ASSERT_PTR_EQUAL(urllist_next(ul), url2);
+ }
+
+ url_t* url5 = url_parse_heuristic("http://example.org/4");
+ ulrllist_add(ul, url5, 10 + URL_PRIO_GROUPSIZE);
+
+ url_t* url6 = url_parse_heuristic("http://example.org/4");
+ ulrllist_add(ul, url6, 8 + URL_PRIO_GROUPSIZE);
+
+ for (i = 0;i < 7;i++) {
+ CU_ASSERT_PTR_EQUAL(urllist_next(ul), url6);
+ CU_ASSERT_PTR_EQUAL(urllist_next(ul), url5);
+ }
+
+ CU_ASSERT_TRUE(urllist_remove(ul, url5));
+
+ for (i = 0;i < 4;i++) {
+ CU_ASSERT_PTR_EQUAL(urllist_next(ul), url6);
+ }
+
+ CU_ASSERT_TRUE(urllist_remove(ul, url6));
+
+ for (i = 0;i < 5;i++) {
+ CU_ASSERT_TRUE(urllist_next(ul), url2);
+ }
+
+ CU_ASSERT_TRUE(urllist_remove(ul, url2));
+
+ for (i = 0;i < 5;i++) {
+ CU_ASSERT_PTR_NULL(urllist_next(ul));
+ }
+
+ urllist_destroy(ul);
+}
Added: branches/3.x-broken/test/test_urllist.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/test/test_urllist.h?rev=62&op=file
==============================================================================
--- branches/3.x-broken/test/test_urllist.h (added)
+++ branches/3.x-broken/test/test_urllist.h Fri Nov 14 12:13:22 2008
@@ -1,0 +1,1 @@
+void test_urllist_suite();
Modified: branches/3.x-broken/test/tests.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/test/tests.h?rev=62&op=diff
==============================================================================
--- branches/3.x-broken/test/tests.h (original)
+++ branches/3.x-broken/test/tests.h Fri Nov 14 12:13:22 2008
@@ -4,3 +4,4 @@
#include "test_url.h"
#include "test_helper.h"
+#include "test_urllist.h"
More information about the axel-commits
mailing list