Skip to content

Commit

Permalink
Merge branch 'check'
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaffaye committed Jan 24, 2011
2 parents 31ccec6 + 1a1b7cd commit 0aeaa8b
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libpkg/pkg_util.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -272,14 +272,16 @@ 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);
else
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");

Expand Down
17 changes: 17 additions & 0 deletions 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 <bsd.prog.mk>
99 changes: 99 additions & 0 deletions tests/manifest.c
@@ -0,0 +1,99 @@
#include <check.h>
#include <pkg.h>
#include <string.h>

#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);
}
3 changes: 3 additions & 0 deletions tests/manifest.h
@@ -0,0 +1,3 @@
#include <check.h>

TCase * tcase_manifest(void);
20 changes: 20 additions & 0 deletions tests/test.c
@@ -0,0 +1,20 @@
#include <check.h>

#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);
}

0 comments on commit 0aeaa8b

Please sign in to comment.