aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2007-06-05 02:33:44 +0000
committerJason Woodward2007-06-05 02:33:44 +0000
commite2c6073c3078a666cf672c6d7a24b20bafe9e643 (patch)
treec610e8ea989826b1402de067ddb7858f024a600d
parent77a80e03c3eaa9f73b37ce73ffdf257584cfd713 (diff)
downloadslapt-get-e2c6073c3078a666cf672c6d7a24b20bafe9e643.tar.gz
* Wrapped generated slapt.h in ifndef guard
* Added initial unit testing to tree
-rw-r--r--ChangeLog4
-rw-r--r--Makefile13
-rw-r--r--src/curl.c5
-rw-r--r--src/package.c2
-rw-r--r--t/Makefile19
-rw-r--r--t/common.h16
-rw-r--r--t/data/md5_dummy1
-rw-r--r--t/data/rc13
-rw-r--r--t/test.c55
-rw-r--r--t/test_common.c96
-rw-r--r--t/test_common.h9
-rw-r--r--t/test_configuration.c101
-rw-r--r--t/test_configuration.h8
-rw-r--r--t/test_curl.c122
-rw-r--r--t/test_curl.h8
-rw-r--r--t/test_packages.c304
-rw-r--r--t/test_packages.h8
-rw-r--r--t/test_transaction.c96
-rw-r--r--t/test_transaction.h8
19 files changed, 873 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 03f99c0..cf8d503 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
-0.9.11i May 20, 2007
+0.9.11i Jun 04, 2007
+ * Wrapped generated slapt.h in ifndef guard
+ * Added initial unit testing to tree
* Individual package download size now represented by a float (Ricardo Garcia)
* replaced useless strlen(constant) calls
* Added shortcuts for update (u) and install (i) (thanks Piotr)
diff --git a/Makefile b/Makefile
index 4dc6d9e..ae4ea27 100644
--- a/Makefile
+++ b/Makefile
@@ -93,7 +93,7 @@ uninstall:
-readlink $(LIBDIR)/libslapt.so|xargs -r rm
-rm $(LIBDIR)/libslapt.so
-clean:
+clean: testclean
-if [ -f $(PACKAGE) ]; then rm $(PACKAGE);fi
-rm src/*.o
-rm src/*.a
@@ -160,5 +160,14 @@ libs: $(OBJS)
$(CC) -shared -o src/libslapt.so.$(VERSION) $(LIBOBJS)
( cd src; if [ -f libslapt.so ]; then rm libslapt.so;fi; ln -s libslapt.so.$(VERSION) libslapt.so )
ar -r src/libslapt.a $(LIBOBJS)
- cat src/main.h src/common.h src/configuration.h src/package.h src/curl.h src/transaction.h |grep -v '#include \"' > src/slapt.h
+ -@echo "#ifndef LIB_SLAPT" > src/slapt.h
+ -@echo "#define LIB_SLAPT 1" >> src/slapt.h
+ -@cat src/main.h src/common.h src/configuration.h src/package.h src/curl.h src/transaction.h |grep -v '#include \"' >> src/slapt.h
+ -@echo "#endif" >> src/slapt.h
+
+test: libs
+ (cd t; make runtest)
+
+testclean:
+ -@(cd t; make clean)
diff --git a/src/curl.c b/src/curl.c
index 3702c08..863ff49 100644
--- a/src/curl.c
+++ b/src/curl.c
@@ -221,13 +221,16 @@ int slapt_download_pkg(const slapt_rc_config *global_config,
int dl_return = -1, dl_total_size = 0;
long filetime = 0;
+ if (pkg == NULL)
+ return -1;
+
if (slapt_verify_downloaded_pkg(global_config,pkg) == 0)
return 0;
if (pkg->mirror == NULL || strlen(pkg->mirror) == 0)
return -1;
- chdir(global_config->working_dir); /* just in case */
+ /* chdir(global_config->working_dir); */ /* just in case */
slapt_create_dir_structure(pkg->location);
/* build the url, file name, and get the file size if the file is present */
diff --git a/src/package.c b/src/package.c
index ed65082..4fd3153 100644
--- a/src/package.c
+++ b/src/package.c
@@ -475,7 +475,7 @@ char *slapt_gen_short_pkg_description(slapt_pkg_info_t *pkg)
}
/* quit now if the description is going to be empty */
- if ((int)string_size < 0)
+ if ((int)string_size < 1)
return NULL;
short_description = strndup(
diff --git a/t/Makefile b/t/Makefile
new file mode 100644
index 0000000..6ef5958
--- /dev/null
+++ b/t/Makefile
@@ -0,0 +1,19 @@
+TESTOBJS=test.o test_common.o test_configuration.o test_curl.o test_packages.o test_transaction.o
+CC=gcc
+CURLFLAGS=`curl-config --libs`
+DEFINES=
+CFLAGS=-W -Werror -Wall -O2 -ansi -pedantic $(DEFINES)
+LDFLAGS=$(CURLFLAGS) -lz
+CHECKFLAGS=`pkg-config --libs check`
+
+test: $(TESTOBJS)
+ $(CC) -o test $(TESTOBJS) $(CFLAGS) ../src/libslapt.so $(CHECKFLAGS) $(LDFLAGS)
+
+runtest: test
+ ./test
+
+$(TESTOBJS):
+
+clean:
+ -rm *.o test
+ -rm -r data/slapt-get
diff --git a/t/common.h b/t/common.h
new file mode 100644
index 0000000..8679349
--- /dev/null
+++ b/t/common.h
@@ -0,0 +1,16 @@
+#ifndef TEST_COMMON
+
+#define TEST_COMMON 1
+
+#ifndef _GNU_SOURCE
+ #define _GNU_SOURCE
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <check.h>
+#include "../src/slapt.h"
+
+#endif
diff --git a/t/data/md5_dummy b/t/data/md5_dummy
new file mode 100644
index 0000000..c945953
--- /dev/null
+++ b/t/data/md5_dummy
@@ -0,0 +1 @@
+1234567890qwertyuiopasdfghjklzxcvbnm
diff --git a/t/data/rc1 b/t/data/rc1
new file mode 100644
index 0000000..991717c
--- /dev/null
+++ b/t/data/rc1
@@ -0,0 +1,3 @@
+WORKINGDIR=data/slapt-get
+EXCLUDE=^kernel-.*,^alsa-.*,^glibc.*,.*-[0-9]+dl$,^devs$,^udev$,aaa_elflibs,x86_64
+SOURCE=http://software.jaos.org/slackpacks/11.0/
diff --git a/t/test.c b/t/test.c
new file mode 100644
index 0000000..5b67cad
--- /dev/null
+++ b/t/test.c
@@ -0,0 +1,55 @@
+#include "common.h"
+#include "test_common.h"
+#include "test_configuration.h"
+#include "test_curl.h"
+#include "test_packages.h"
+#include "test_transaction.h"
+
+slapt_pkg_info_t pkg = {
+ "8598a2a6d683d098b09cdc938de1e3c7",
+ "gslapt",
+ "0.3.15-i386-1",
+ "http://software.jaos.org/slackpacks/11.0/",
+ ".",
+ "gslapt: gslapt (GTK slapt-get, an APT like system for Slackware)\n",
+ "",
+ "",
+ "",
+ ".tgz",
+ 115,
+ 440
+};
+
+Suite *slapt_test_suite()
+{
+ Suite *s = suite_create ("Slapt");
+
+ /* generic tests */
+ TCase *tc_packages = tcase_create ("Core");
+ /* tcase_add_checked_fixture (tc_packages, setup, teardown); */
+ /* tcase_add_test (tc_packages, test_money_create); */
+ suite_add_tcase (s, tc_packages);
+
+ return s;
+
+}
+
+int main(void)
+{
+ int number_failed;
+
+ Suite *s = slapt_test_suite();
+ SRunner *sr = srunner_create (s);
+
+ srunner_add_suite(sr, common_test_suite());
+ srunner_add_suite(sr, configuration_test_suite());
+ srunner_add_suite(sr, curl_test_suite());
+ srunner_add_suite(sr, packages_test_suite());
+ srunner_add_suite(sr, transaction_test_suite());
+
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+
+ srunner_free (sr);
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/t/test_common.c b/t/test_common.c
new file mode 100644
index 0000000..29b6c49
--- /dev/null
+++ b/t/test_common.c
@@ -0,0 +1,96 @@
+#include "test_common.h"
+
+
+START_TEST (test_slapt_open_file)
+{
+ const char *file = "./PACKAGES.TXT";
+
+ FILE *f = slapt_open_file(file,"w");
+ fail_if ( fileno(f) == -1, NULL);
+
+ fclose(f);
+ unlink(file);
+}
+END_TEST
+
+
+START_TEST (test_regex)
+{
+ slapt_regex_t *regex = slapt_init_regex("^[a-z]+$");
+ slapt_regex_t *invalid_regex = slapt_init_regex("^[-");
+
+ fail_if ( regex == NULL );
+ fail_unless ( invalid_regex == NULL );
+
+ slapt_execute_regex(regex, "abc");
+ fail_if (regex->reg_return == REG_NOMATCH);
+
+ slapt_execute_regex(regex, "123");
+ fail_unless (regex->reg_return == REG_NOMATCH);
+
+ slapt_free_regex(regex);
+}
+END_TEST
+
+
+START_TEST (test_slapt_create_dir_structure)
+{
+ const char *dir_name = "var/slapt-get";
+ DIR *d = NULL;
+
+ slapt_create_dir_structure("var/slapt-get");
+
+ d = opendir(dir_name);
+
+ fail_if (d == NULL);
+
+ closedir(d);
+
+ rmdir(dir_name);
+ rmdir("var");
+}
+END_TEST
+
+
+START_TEST (test_slapt_gen_md5_sum_of_file)
+{
+ const char *file = "data/md5_dummy";
+ char result_sum[SLAPT_MD5_STR_LEN];
+ FILE *f = fopen(file,"r");
+
+ slapt_gen_md5_sum_of_file(f,result_sum);
+ fail_unless ( strcmp("96ee23abf2770468e1aac755a0a99809",result_sum) == 0 );
+
+ fclose(f);
+
+}
+END_TEST
+
+
+START_TEST (test_slapt_str_replace_chr)
+{
+ const char *s = "/fake/path/to/file";
+ char *s_modified = slapt_str_replace_chr(s, '/', '_');
+
+ fail_unless ( strcmp(s_modified,"_fake_path_to_file") == 0 );
+
+ free(s_modified);
+}
+END_TEST
+
+
+Suite *common_test_suite()
+{
+ Suite *s = suite_create ("Common");
+ TCase *tc = tcase_create ("Common");
+
+ tcase_add_test (tc, test_slapt_open_file);
+ tcase_add_test (tc, test_regex);
+ tcase_add_test (tc, test_slapt_create_dir_structure);
+ tcase_add_test (tc, test_slapt_gen_md5_sum_of_file);
+ tcase_add_test (tc, test_slapt_str_replace_chr);
+
+ suite_add_tcase (s, tc);
+ return s;
+}
+
diff --git a/t/test_common.h b/t/test_common.h
new file mode 100644
index 0000000..92bf90a
--- /dev/null
+++ b/t/test_common.h
@@ -0,0 +1,9 @@
+
+#ifndef COMMON_TEST_SUITE
+
+#define COMMON_TEST_SUITE 1
+
+#include "common.h"
+Suite *common_test_suite();
+
+#endif
diff --git a/t/test_configuration.c b/t/test_configuration.c
new file mode 100644
index 0000000..36d23ca
--- /dev/null
+++ b/t/test_configuration.c
@@ -0,0 +1,101 @@
+#include "test_configuration.h"
+
+
+START_TEST (test_struct_config)
+{
+ slapt_rc_config *rc = NULL;
+
+ rc = slapt_init_config();
+ fail_if (rc == NULL);
+ slapt_free_rc_config(rc);
+ rc = NULL;
+
+ rc = slapt_read_rc_config("./data/rc1");
+ fail_if (rc == NULL);
+ {
+ struct slapt_source_list *s = rc->sources;
+ struct slapt_exclude_list *e = rc->exclude_list;
+
+ fail_if (s->count < 1);
+ fail_if (e->count != 8);
+ }
+ slapt_free_rc_config(rc);
+ rc = NULL;
+
+}
+END_TEST
+
+
+START_TEST (test_working_dir)
+{
+ DIR *d = NULL;
+ slapt_rc_config *rc = slapt_read_rc_config("data/rc1");
+
+ /* check that working_dir exists or make it if permissions allow */
+ /* void slapt_working_dir_init(const slapt_rc_config *global_config); */
+
+ slapt_working_dir_init(rc);
+
+ d = opendir("data/slapt-get");
+ fail_if (d == NULL);
+ closedir(d);
+ rmdir("data/slapt-get");
+
+}
+END_TEST
+
+
+START_TEST (test_exclude_list)
+{
+ struct slapt_exclude_list *e = slapt_init_exclude_list();
+
+ fail_if (e == NULL);
+ fail_if (e->count != 0);
+
+ slapt_add_exclude(e,"^foo$");
+ fail_if (e->count != 1);
+
+ slapt_remove_exclude(e,"^foo$");
+ fail_if (e->count != 0);
+
+ slapt_remove_exclude(e,"no_such_exclude");
+ fail_if (e->count != 0);
+
+ slapt_free_exclude_list(e);
+}
+END_TEST
+
+
+START_TEST (test_source_list)
+{
+ struct slapt_source_list *s = slapt_init_source_list();
+ fail_if (s == NULL);
+ fail_if (s->count != 0);
+
+ slapt_add_source(s,"http://www.test.org/dist/");
+ fail_if (s->count != 1);
+
+ slapt_remove_source (s,"http://www.test.org/dist/");
+ fail_if (s->count != 0);
+
+ slapt_free_source_list(s);
+}
+END_TEST
+
+
+
+
+Suite *configuration_test_suite()
+{
+ Suite *s = suite_create ("Configuration");
+ TCase *tc = tcase_create ("Configuration");
+
+ tcase_add_test (tc, test_struct_config);
+ tcase_add_test (tc, test_working_dir);
+ tcase_add_test (tc, test_exclude_list);
+ tcase_add_test (tc, test_source_list);
+
+ suite_add_tcase (s, tc);
+ return s;
+}
+
diff --git a/t/test_configuration.h b/t/test_configuration.h
new file mode 100644
index 0000000..686df76
--- /dev/null
+++ b/t/test_configuration.h
@@ -0,0 +1,8 @@
+#ifndef CONFIGURATION_TEST_SUITE
+
+#define CONFIGURATION_TEST_SUITE 1
+
+#include "common.h"
+Suite *configuration_test_suite();
+
+#endif
diff --git a/t/test_curl.c b/t/test_curl.c
new file mode 100644
index 0000000..8dd99bc
--- /dev/null
+++ b/t/test_curl.c
@@ -0,0 +1,122 @@
+#include "test_curl.h"
+extern slapt_pkg_info_t pkg;
+
+
+static int _progress_cb(void *clientp, double dltotal, double dlnow,
+ double ultotal, double ulnow)
+{
+ (void) clientp;
+ (void) dltotal;
+ (void) dlnow;
+ (void) ultotal;
+ (void) ulnow;
+ return 0;
+}
+
+START_TEST (test_slapt_get_mirror_data_from_source)
+{
+ FILE *f = NULL;
+ int r = -1;
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+ const char *url = "http://software.jaos.org/slackpacks/10.0/";
+ char *packages = "PACKAGES.TXT";
+ char *packages_gz = "PACKAGES.TXT.gz";
+ char *checksums = "CHECKSUMS.md5";
+ char *checksums_gz = "CHECKSUMS.md5.gz";
+ rc->progress_cb = _progress_cb; /* silence */
+
+ f = slapt_open_file("data/PACKAGES.TXT","w+b");
+ r = slapt_get_mirror_data_from_source(f, rc, url, packages);
+ fail_unless (r == 0);
+ fclose(f);
+
+ f = slapt_open_file("data/PACKAGES.TXT.gz","w+b");
+ r = slapt_get_mirror_data_from_source(f, rc, url, packages_gz);
+ fail_unless (r == 0);
+ fclose(f);
+
+ f = slapt_open_file("data/CHECKSUMS.md5","w+b");
+ r = slapt_get_mirror_data_from_source(f, rc, url, checksums);
+ fail_unless (r == 0);
+ fclose(f);
+
+ f = slapt_open_file("data/CHECKSUMS.md5.gz","w+b");
+ r = slapt_get_mirror_data_from_source(f, rc, url, checksums_gz);
+ fail_unless (r == 0);
+ fclose(f);
+
+ unlink("data/PACKAGES.TXT");
+ unlink("data/PACKAGES.TXT.gz");
+ unlink("data/CHECKSUMS.md5");
+ unlink("data/CHECKSUMS.md5.gz");
+
+ slapt_free_rc_config(rc);
+}
+END_TEST
+
+
+START_TEST (test_slapt_download_pkg)
+{
+ int r = -1;
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+ rc->progress_cb = _progress_cb; /* silence */
+ slapt_working_dir_init(rc);
+
+ r = slapt_download_pkg(rc, &pkg);
+ fail_unless (r == 0);
+
+ slapt_free_rc_config(rc);
+}
+END_TEST
+
+
+START_TEST (test_head)
+{
+ char *head = slapt_head_request("http://www.google.com/");
+ fail_if (head == NULL);
+ fail_if ( strstr(head,"Content-Type") == NULL);
+
+ slapt_write_head_cache(head, "data/head_request");
+ free(head);
+ head = NULL;
+
+ head = slapt_head_mirror_data("http://www.google.com/","data/head_request");
+ fail_unless (head == NULL);
+ free(head);
+ head = NULL;
+
+ head = slapt_read_head_cache("data/head_request");
+ fail_if (head == NULL);
+ free(head);
+
+ slapt_clear_head_cache("data/head_request");
+ unlink("data/head_request.head");
+}
+END_TEST
+
+
+START_TEST (test_progress_data)
+{
+ struct slapt_progress_data *d = slapt_init_progress_data();
+ fail_if (d == NULL);
+ fail_if (d->bytes != 0);
+ fail_if (d->start == 0);
+ slapt_free_progress_data(d);
+}
+END_TEST
+
+
+Suite *curl_test_suite()
+{
+ Suite *s = suite_create ("Curl");
+ TCase *tc = tcase_create ("Curl");
+
+ tcase_add_test (tc, test_slapt_get_mirror_data_from_source);
+ tcase_add_test (tc, test_slapt_download_pkg);
+ tcase_add_test (tc, test_head);
+ tcase_add_test (tc, test_progress_data);
+
+ suite_add_tcase (s, tc);
+ return s;
+}
+
diff --git a/t/test_curl.h b/t/test_curl.h
new file mode 100644
index 0000000..4b9d23a
--- /dev/null
+++ b/t/test_curl.h
@@ -0,0 +1,8 @@
+#ifndef CURL_TEST_SUITE
+
+#define CURL_TEST_SUITE 1
+
+#include "common.h"
+Suite *curl_test_suite();
+
+#endif
diff --git a/t/test_packages.c b/t/test_packages.c
new file mode 100644
index 0000000..6ba0a51
--- /dev/null
+++ b/t/test_packages.c
@@ -0,0 +1,304 @@
+#include "test_packages.h"
+extern slapt_pkg_info_t pkg;
+
+
+START_TEST (test_struct_pkg)
+{
+ slapt_pkg_info_t *cpy = slapt_init_pkg();
+ fail_if (cpy == NULL);
+
+ cpy = slapt_copy_pkg(cpy, &pkg);
+ fail_if (cpy == NULL);
+
+ {
+ char *pkg_str = slapt_stringify_pkg(&pkg);
+ char *cpy_str = slapt_stringify_pkg(cpy);
+
+ fail_if (pkg_str == NULL);
+ fail_if (cpy_str == NULL);
+ fail_unless (strcmp(pkg_str,cpy_str) == 0);
+
+ free(pkg_str);
+ free(cpy_str);
+ }
+
+ slapt_free_pkg(cpy);
+}
+END_TEST
+
+
+START_TEST (test_pkg_info)
+{
+ size_t i = -1;
+ char *string = NULL;
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+
+ string = slapt_gen_short_pkg_description(&pkg);
+ fail_if (string == NULL);
+ fail_unless (strcmp(string,"gslapt (GTK slapt-get, an APT like system for Slackware)") == 0);
+ free(string); string = NULL;
+
+ string = slapt_gen_filename_from_url("http://software.jaos.org/slackpacks/11.0/","PACKAGES.TXT");
+ fail_if (string == NULL);
+ fail_unless (strcmp(string,".http:##software.jaos.org#slackpacks#11.0#PACKAGES.TXT") == 0);
+ free(string); string = NULL;
+
+ string = slapt_gen_head_cache_filename(".http:##software.jaos.org#slackpacks#11.0#PACKAGES.TXT");
+ fail_if (string == NULL);
+ fail_unless (strcmp(string,".http:##software.jaos.org#slackpacks#11.0#PACKAGES.TXT.head") == 0);
+ free(string); string = NULL;
+
+ string = slapt_gen_pkg_url(&pkg);
+ fail_if (string == NULL);
+ fail_unless (strcmp(string,"http://software.jaos.org/slackpacks/11.0/./gslapt-0.3.15-i386-1.tgz") == 0);
+ free(string); string = NULL;
+
+ slapt_add_exclude(rc->exclude_list,"^gslapt$");
+ fail_if (slapt_is_excluded(rc,&pkg) == 0);
+ slapt_remove_exclude(rc->exclude_list,"^gslapt$");
+
+ fail_unless (slapt_download_pkg(rc, &pkg) == 0);
+ fail_unless (slapt_verify_downloaded_pkg(rc,&pkg) == 0);
+
+ i = slapt_get_pkg_file_size(rc, &pkg);
+ fail_if (i < 1);
+
+ string = strdup(pkg.description);
+ slapt_clean_description(string, pkg.name);
+ fail_unless (strcmp(string," gslapt (GTK slapt-get, an APT like system for Slackware)\n") == 0);
+ free(string); string = NULL;
+
+ /* retrieve the packages changelog entry, if any. Returns NULL otherwise */
+ /* char *slapt_get_pkg_changelog(const slapt_pkg_info_t *pkg); */
+
+ slapt_free_rc_config(rc);
+}
+END_TEST
+
+
+START_TEST (test_pkg_list)
+{
+ struct slapt_pkg_list *list = slapt_init_pkg_list();
+ fail_if (list == NULL);
+ fail_unless (list->pkg_count == 0);
+
+ slapt_add_pkg_to_pkg_list(list, &pkg);
+ fail_unless (list->pkg_count == 1);
+
+ slapt_free_pkg_list(list);
+ list = NULL;
+
+ list = slapt_get_installed_pkgs();
+ fail_if (list == NULL);
+ /* fail_unless (list->pkg_count == 0); could be anything */
+ slapt_free_pkg_list(list);
+ list = NULL;
+
+
+ /* parse the PACKAGES.TXT file
+ struct slapt_pkg_list *slapt_parse_packages_txt(FILE *);
+ */
+
+ /*
+ return a list of available packages must be already chdir'd to
+ rc_config->working_dir. Otherwise, open a filehandle to the package data
+ and pass it to slapt_parse_packages_txt();
+ struct slapt_pkg_list *slapt_get_available_pkgs(void);
+ */
+
+ /* get a list of obsolete packages
+ struct slapt_pkg_list *
+ slapt_get_obsolete_pkgs ( const slapt_rc_config *global_config,
+ struct slapt_pkg_list *avail_pkgs,
+ struct slapt_pkg_list *installed_pkgs);
+ */
+
+ /*
+ fill in the md5sum of the package
+ void slapt_get_md5sums(struct slapt_pkg_list *pkgs, FILE *checksum_file);
+ */
+
+}
+END_TEST
+
+
+START_TEST (test_pkg_search)
+{
+ slapt_pkg_info_t *p = NULL;
+ struct slapt_pkg_list *l = NULL;
+ struct slapt_pkg_list *list = slapt_init_pkg_list();
+ slapt_add_pkg_to_pkg_list(list, &pkg);
+
+ p = slapt_get_newest_pkg(list, "gslapt");
+ fail_if (p == NULL);
+
+ p = slapt_get_exact_pkg(list, "gslapt", "0.3.15-i386-1");
+ fail_if (p == NULL);
+
+ p = slapt_get_pkg_by_details(list, "gslapt", "0.3.15-i386-1", ".");
+ fail_if (p == NULL);
+
+ l = slapt_search_pkg_list(list, "^gslapt$");
+ fail_if (l == NULL);
+ fail_unless (l->pkg_count == 1);
+
+ slapt_free_pkg_list(list);
+
+}
+END_TEST
+
+
+START_TEST (test_pkgtool)
+{
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+ /* disabled... */
+ /*
+ int r = -1;
+ r = slapt_install_pkg(rc, &pkg);
+ r = slapt_upgrade_pkg(rc, &pkg);
+ r = slapt_remove_pkg(rc, &pkg);
+ */
+
+ slapt_free_rc_config(rc);
+}
+END_TEST
+
+
+START_TEST (test_version)
+{
+ fail_unless (slapt_cmp_pkg_versions("3","3") == 0);
+ fail_unless (slapt_cmp_pkg_versions("4","3") > 0);
+ fail_unless (slapt_cmp_pkg_versions("3","4") < 0);
+
+ fail_unless (slapt_cmp_pkg_versions("3.8.1-i486-1","3.8.1-i486-1") == 0);
+ fail_unless (slapt_cmp_pkg_versions("3.8.1-i486-1jsw","3.8.1-i486-1") == 0);
+ fail_unless (slapt_cmp_pkg_versions("3.8.1-i586-1","3.8.1-i486-1") == 0);
+ fail_unless (slapt_cmp_pkg_versions("3.8.1-i586-1","3.8.1-i686-1") == 0);
+ fail_unless (slapt_cmp_pkg_versions("3.8.1-i486","3.8.1-i486") == 0);
+ fail_unless (slapt_cmp_pkg_versions("3.8.1-i486-1","3.8.1-i486-1") == 0);
+
+ fail_unless (slapt_cmp_pkg_versions("3.8.1p1-i486-1","3.8p1-i486-1") > 0);
+ fail_unless (slapt_cmp_pkg_versions("3.8.1-i486-1","3.8-i486-1") > 0);
+ fail_unless (slapt_cmp_pkg_versions("3.8.1-i486-1","3.8-i486-3") > 0);
+
+ fail_unless (slapt_cmp_pkg_versions("3.8.1_1-i486-1","3.8.1_2-i486-1") < 0);
+
+ fail_unless (slapt_cmp_pkg_versions("IIIalpha9.8-i486-2","IIIalpha9.7-i486-3") > 0);
+ fail_unless (slapt_cmp_pkg_versions("4.13b-i386-2","4.12b-i386-1") > 0);
+ fail_unless (slapt_cmp_pkg_versions("4.13b-i386-2","4.13a-i386-2") > 0);
+ fail_unless (slapt_cmp_pkg_versions("1.4rc5-i486-2","1.4rc4-i486-2") > 0);
+}
+END_TEST
+
+
+START_TEST (test_dependency)
+{
+ /*
+ resolve dependencies
+ returns 0 on success, -1 on error setting conflict_err and missing_err
+ (usually called with transaction->conflict_err and transaction->missing_err)
+ int slapt_get_pkg_dependencies(const slapt_rc_config *global_config,
+ struct slapt_pkg_list *avail_pkgs,
+ struct slapt_pkg_list *installed_pkgs,
+ slapt_pkg_info_t *pkg,
+ struct slapt_pkg_list *deps,
+ struct slapt_pkg_err_list *conflict_err,
+ struct slapt_pkg_err_list *missing_err);
+ */
+
+ /*
+ return list of package conflicts
+ struct slapt_pkg_list *slapt_get_pkg_conflicts(struct slapt_pkg_list *avail_pkgs,
+ struct slapt_pkg_list *installed_pkgs,
+ slapt_pkg_info_t *pkg);
+ */
+
+ /*
+ return list of packages required by
+ struct slapt_pkg_list *slapt_is_required_by(const slapt_rc_config *global_config,
+ struct slapt_pkg_list *avail,
+ slapt_pkg_info_t *pkg);
+ */
+}
+END_TEST
+
+
+START_TEST (test_cache)
+{
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+
+ slapt_clean_pkg_dir(rc->working_dir);
+
+ /* not easily testable due to timeout
+ struct slapt_pkg_list *list = slapt_init_pkg_list();
+ slapt_purge_old_cached_pkgs(rc, NULL, list);
+ */
+
+ slapt_free_rc_config(rc);
+}
+END_TEST
+
+
+START_TEST (test_error)
+{
+ struct slapt_pkg_err_list *list = slapt_init_pkg_err_list();
+
+ slapt_add_pkg_err_to_list(list, "gslapt", "Server returned 404");
+
+ fail_unless ( slapt_search_pkg_err_list(list, "gslapt", "Server returned 404") == 1);
+
+ slapt_free_pkg_err_list(list);
+}
+END_TEST
+
+
+START_TEST (test_network)
+{
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+
+ /* must chdir to working dir */
+ /* fail_unless (slapt_update_pkg_cache(rc) == 0); */
+
+ /* write pkg data to disk
+ void slapt_write_pkg_data(const char *source_url,FILE *d_file,
+ struct slapt_pkg_list *pkgs);
+ */
+
+ /* download the PACKAGES.TXT and CHECKSUMS.md5 files
+ struct slapt_pkg_list *slapt_get_pkg_source_packages (const slapt_rc_config *global_config,
+ const char *url);
+ struct slapt_pkg_list *slapt_get_pkg_source_patches (const slapt_rc_config *global_config,
+ const char *url);
+ FILE *slapt_get_pkg_source_checksums (const slapt_rc_config *global_config,
+ const char *url);
+ int slapt_get_pkg_source_changelog (const slapt_rc_config *global_config,
+ const char *url);
+ */
+
+ slapt_free_rc_config(rc);
+}
+END_TEST
+
+
+
+Suite *packages_test_suite()
+{
+ Suite *s = suite_create ("Packages");
+ TCase *tc = tcase_create ("Packages");
+
+ tcase_add_test (tc, test_struct_pkg);
+ tcase_add_test (tc, test_pkg_info);
+ tcase_add_test (tc, test_pkg_list);
+ tcase_add_test (tc, test_pkg_search);
+ tcase_add_test (tc, test_pkgtool);
+ tcase_add_test (tc, test_version);
+ tcase_add_test (tc, test_dependency);
+ tcase_add_test (tc, test_cache);
+ tcase_add_test (tc, test_error);
+ tcase_add_test (tc, test_network);
+
+ suite_add_tcase (s, tc);
+ return s;
+}
+
+
diff --git a/t/test_packages.h b/t/test_packages.h
new file mode 100644
index 0000000..09fe822
--- /dev/null
+++ b/t/test_packages.h
@@ -0,0 +1,8 @@
+#ifndef PACKAGES_TEST_SUITE
+
+#define PACKAGES_TEST_SUITE 1
+
+#include "common.h"
+Suite *packages_test_suite();
+
+#endif
diff --git a/t/test_transaction.c b/t/test_transaction.c
new file mode 100644
index 0000000..2452944
--- /dev/null
+++ b/t/test_transaction.c
@@ -0,0 +1,96 @@
+#include "test_transaction.h"
+extern slapt_pkg_info_t pkg;
+
+
+START_TEST (test_transaction)
+{
+ slapt_transaction_t *t = slapt_init_transaction();
+ fail_if (t == NULL);
+
+ slapt_add_install_to_transaction(t, &pkg);
+ fail_unless (t->install_pkgs->pkg_count == 1);
+ fail_unless (slapt_search_transaction(t, "gslapt") == 1);
+ fail_unless (slapt_search_transaction_by_pkg(t, &pkg) == 1);
+ t = slapt_remove_from_transaction(t, &pkg);
+
+ slapt_add_remove_to_transaction(t, &pkg);
+ fail_unless (t->remove_pkgs->pkg_count == 1);
+ fail_unless (slapt_search_transaction(t, "gslapt") == 1);
+ fail_unless (slapt_search_transaction_by_pkg(t, &pkg) == 1);
+ t = slapt_remove_from_transaction(t, &pkg);
+
+ slapt_add_exclude_to_transaction(t, &pkg);
+ fail_unless (t->exclude_pkgs->pkg_count == 1);
+
+ slapt_add_upgrade_to_transaction(t, &pkg, &pkg);
+ /* fail_unless (slapt_search_upgrade_transaction(t, &pkg) == 1); */
+
+ slapt_free_transaction(t);
+}
+END_TEST
+
+
+START_TEST (test_handle_transaction)
+{
+ slapt_transaction_t *t = slapt_init_transaction();
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+
+ /*
+ download and install/remove/upgrade packages as defined in the transaction
+ returns 0 on success
+ int slapt_handle_transaction(const slapt_rc_config *,slapt_transaction_t *);
+ */
+
+ slapt_free_transaction(t);
+ slapt_free_rc_config(rc);
+}
+END_TEST
+
+
+START_TEST (test_transaction_dependencies)
+{
+ slapt_transaction_t *t = slapt_init_transaction();
+ slapt_rc_config *rc = slapt_read_rc_config("./data/rc1");
+
+ /*
+ add dependencies for package to transaction, returns -1 on error, 0 otherwise
+ int slapt_add_deps_to_trans(const slapt_rc_config *global_config,
+ slapt_transaction_t *tran,
+ struct slapt_pkg_list *avail_pkgs,
+ struct slapt_pkg_list *installed_pkgs, slapt_pkg_info_t *pkg);
+ */
+
+ /*
+ check to see if a package has a conflict already present in the transaction
+ returns conflicted package or NULL if none
+ slapt_pkg_info_t *slapt_is_conflicted(slapt_transaction_t *tran,
+ struct slapt_pkg_list *avail_pkgs,
+ struct slapt_pkg_list *installed_pkgs,
+ slapt_pkg_info_t *pkg);
+ */
+
+ /*
+ generate a list of suggestions based on the current packages
+ in the transaction
+ void slapt_generate_suggestions(slapt_transaction_t *tran);
+ */
+
+ slapt_free_transaction(t);
+ slapt_free_rc_config(rc);
+}
+END_TEST
+
+
+Suite *transaction_test_suite()
+{
+ Suite *s = suite_create ("Transaction");
+ TCase *tc = tcase_create ("Transaction");
+
+ tcase_add_test (tc, test_transaction);
+ tcase_add_test (tc, test_handle_transaction);
+ tcase_add_test (tc, test_transaction_dependencies);
+
+ suite_add_tcase (s, tc);
+ return s;
+}
+
diff --git a/t/test_transaction.h b/t/test_transaction.h
new file mode 100644
index 0000000..5cac32c
--- /dev/null
+++ b/t/test_transaction.h
@@ -0,0 +1,8 @@
+#ifndef TRANSACTION_TEST_SUITE
+
+#define TRANSACTION_TEST_SUITE 1
+
+#include "common.h"
+Suite *transaction_test_suite();
+
+#endif