diff --git a/libpkg/pkg_util.c b/libpkg/pkg_util.c index ac5056f518..ab423a4362 100644 --- a/libpkg/pkg_util.c +++ b/libpkg/pkg_util.c @@ -230,7 +230,7 @@ file_fetch(const char *url, const char *dest) off_t tfetched, rfetched, wfetched; int retry = 3; time_t begin_dl, now; - char buf[BUFSIZ], sz[8]; + char buf[BUFSIZ]; if ((fetchStatURL(url, &st, "") < 0) || st.size == -1) { /* TODO error handling */ @@ -272,7 +272,8 @@ file_fetch(const char *url, const char *dest) tfetched += rfetched; now = time(NULL); - +/* TODO: callback, this is the job of the UI */ +#if 0 if ((now - begin_dl) > 0) humanize_number(sz, 8, (int64_t)(tfetched / (now - begin_dl)), "Bps", HN_AUTOSCALE, HN_DECIMAL); @@ -280,6 +281,7 @@ file_fetch(const char *url, const char *dest) humanize_number(sz, 8, 0, "Bps", HN_AUTOSCALE, HN_DECIMAL); printf("\r%s\t%s %d%%", url, sz, (int)(((float)tfetched / (float)st.size) * 100)); +#endif } printf("\n"); diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000000..8b7d9e1f3e --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,17 @@ +PROG= test +SRCS= test.c \ + manifest.c \ + +CFLAGS+=-I. \ + -I/usr/local/include \ + -I../libpkg +LDADD+= -L/usr/local/lib \ + -lcheck \ + -L../libpkg \ + -lpkg +NO_MAN= true + +run: ${PROG} + @env LD_LIBRARY_PATH=../libpkg ./${PROG} + +.include diff --git a/tests/manifest.c b/tests/manifest.c new file mode 100644 index 0000000000..bdd0814cd8 --- /dev/null +++ b/tests/manifest.c @@ -0,0 +1,99 @@ +#include +#include +#include + +#include "manifest.h" + +char manifest[] = "" + "@pkg_format_version 0.9\n" + "@name foobar\n" + "@version 0.3\n" + "@origin foo/bar\n" + "@comment A dummy manifest\n" + "@arch amd64\n" + "@osversion 800500\n" + "@www http://www.foobar.com\n" + "@maintainer test@pkgng.lan\n" + "@dep depfoo dep/foo 1.2\n" + "@dep depbar dep/bar 3.4\n" + "@conflict foo-*\n" + "@conflict bar-*\n" + "@exec true && echo hello\n" + "@exec false || echo world\n" + "@option foo true\n" + "@option bar false\n"; + +START_TEST(parse_manifest) +{ + struct pkg *p; + struct pkg **deps; + struct pkg_conflict **conflicts; + struct pkg_exec **execs; + struct pkg_options **options; + int i; + + fail_unless(pkg_new(&p) == 0); + fail_unless(pkg_parse_manifest(p, manifest) == 0); + + fail_unless(strcmp(pkg_get(p, PKG_NAME), "foobar") == 0); + fail_unless(strcmp(pkg_get(p, PKG_VERSION), "0.3") == 0); + fail_unless(strcmp(pkg_get(p, PKG_ORIGIN), "foo/bar") == 0); + fail_unless(strcmp(pkg_get(p, PKG_COMMENT), "A dummy manifest") == 0); + fail_unless(strcmp(pkg_get(p, PKG_ARCH), "amd64") == 0); + fail_unless(strcmp(pkg_get(p, PKG_OSVERSION), "800500") == 0); + fail_unless(strcmp(pkg_get(p, PKG_WWW), "http://www.foobar.com") == 0); + fail_unless(strcmp(pkg_get(p, PKG_MAINTAINER), "test@pkgng.lan") == 0); + + deps = pkg_deps(p); + fail_if(deps == NULL); + for (i = 0; deps[i] != NULL; i++) { + if (i == 0) { + fail_unless(strcmp(pkg_get(deps[i], PKG_NAME), "depfoo") == 0); + fail_unless(strcmp(pkg_get(deps[i], PKG_ORIGIN), "dep/foo") == 0); + fail_unless(strcmp(pkg_get(deps[i], PKG_VERSION), "1.2") == 0); + } else if (i == 1) { + fail_unless(strcmp(pkg_get(deps[i], PKG_NAME), "depbar") == 0); + fail_unless(strcmp(pkg_get(deps[i], PKG_ORIGIN), "dep/bar") == 0); + fail_unless(strcmp(pkg_get(deps[i], PKG_VERSION), "3.4") == 0); + } + } + fail_unless(i == 2); + + conflicts = pkg_conflicts(p); + fail_if(conflicts == NULL); + for (i = 0; conflicts[i] != NULL; i++) { + if (i == 0) { + fail_unless(strcmp(pkg_conflict_glob(conflicts[i]), "foo-*") == 0); + } else if (i == 1) { + fail_unless(strcmp(pkg_conflict_glob(conflicts[i]), "bar-*") == 0); + } + } + fail_unless(i == 2); + + execs = pkg_execs(p); + fail_if(execs == NULL); + /* TODO when this bug is resolved */ + + options = pkg_options(p); + fail_if(options == NULL); + for (i = 0; options[i] != NULL; i++) { + if (i == 0) { + fail_unless(strcmp(pkg_option_opt(options[i]), "foo") == 0); + fail_unless(strcmp(pkg_option_value(options[i]), "true") == 0); + } else if (i == 1) { + fail_unless(strcmp(pkg_option_opt(options[i]), "bar") == 0); + fail_unless(strcmp(pkg_option_value(options[i]), "false") == 0); + } + } + fail_unless(i == 2); +} +END_TEST + +TCase * +tcase_manifest(void) +{ + TCase *tc = tcase_create("Manifest"); + tcase_add_test(tc, parse_manifest); + + return (tc); +} diff --git a/tests/manifest.h b/tests/manifest.h new file mode 100644 index 0000000000..9c593b65ea --- /dev/null +++ b/tests/manifest.h @@ -0,0 +1,3 @@ +#include + +TCase * tcase_manifest(void); diff --git a/tests/test.c b/tests/test.c new file mode 100644 index 0000000000..46d1ee10ba --- /dev/null +++ b/tests/test.c @@ -0,0 +1,20 @@ +#include + +#include "manifest.h" + +int +main() +{ + int nfailed = 0; + Suite *s = suite_create("pkgng"); + + suite_add_tcase(s, tcase_manifest()); + + /* Run the tests ...*/ + SRunner *sr = srunner_create(s); + srunner_set_log(sr, "test.log"); + srunner_run_all(sr, CK_NORMAL); + nfailed = srunner_ntests_failed(sr); + srunner_free(sr); + return (nfailed == 0 ? 0 : 1); +}