Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <check.h> | ||
|
||
TCase * tcase_manifest(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |