From: Tomas Mlcoch Date: Thu, 12 Jan 2012 09:25:05 +0000 (+0100) Subject: Add new ctests X-Git-Tag: upstream/0.2.1~594 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=359b6eb483e2a6da8d38bc34ff0bd66591ed1a7d;p=services%2Fcreaterepo_c.git Add new ctests --- diff --git a/Makefile b/Makefile index 3db4d49..01137f9 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,10 @@ SWIG=/usr/bin/swig - -# FIXME: There must be -O option in cflags or we get: _parsepkg.so: undefined symbol: stat -# link option -lc should solves this problem but it seems to be doesn't working - -CFLAGS=-O -DDEBUG -I/usr/include/python2.7/ `pkg-config --cflags glib-2.0` `xml2-config --cflags` -LINKFLAGS=`pkg-config --libs glib-2.0` `xml2-config --libs` -lrpm -lrpmio -lc +CFLAGS=-O -fPIC -DDEBUG -I/usr/include/python2.7/ `pkg-config --cflags glib-2.0` `xml2-config --cflags` +LINKFLAGS=`pkg-config --libs glib-2.0` `xml2-config --libs` -lrpm -lrpmio all: package.so xml_dump.so parsehdr.so parsepkg.so - -ctests: parsepkg_test_01 + +ctests: parsepkg_test_01 xml_dump_primary_test_01 xml_dump_filelists_test_01 xml_dump_other_test_01 test: main @@ -49,26 +45,31 @@ xml_dump_other.o: xml_dump_other.c xml_dump.h gcc $(CFLAGS) -c xml_dump_other.c package.so: package_wrap.o package.o - ld $(LINKFLAGS) -shared package.o package_wrap.o -o _package.so + ld $(LINKFLAGS) -shared package.o package_wrap.o -o _package.so -lc xml_dump.so: package.o xml_dump_wrap.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o - ld $(LINKFLAGS) -shared package.o xml_dump_wrap.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o -o _xml_dump.so + ld $(LINKFLAGS) -shared package.o xml_dump_wrap.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o -o _xml_dump.so -lc parsehdr.so: parsehdr_wrap.o parsehdr.o package.o xml_dump.o misc.o - ld $(LINKFLAGS) -shared misc.o parsehdr_wrap.o parsehdr.o package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o -o _parsehdr.so + ld $(LINKFLAGS) -shared misc.o parsehdr_wrap.o parsehdr.o package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o -o _parsehdr.so -lc parsepkg.so: parsepkg_wrap.o parsepkg.o parsehdr.o package.o xml_dump.o misc.o - ld $(LINKFLAGS) -shared misc.o parsepkg_wrap.o parsepkg.o parsehdr.o package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o -o _parsepkg.so + ld $(LINKFLAGS) -shared misc.o parsepkg_wrap.o parsepkg.o parsehdr.o package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o -o _parsepkg.so -lc # Tests parsepkg_test_01: parsepkg.o parsehdr.o package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o gcc $(LINKFLAGS) $(CFLAGS) parsepkg.o parsehdr.o package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o ctests/parsepkg_test_01.c -o ctests/parsepkg_test_01 -# Main +xml_dump_primary_test_01: package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o + gcc $(LINKFLAGS) $(CFLAGS) package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o ctests/xml_dump_primary_test_01.c -o ctests/xml_dump_primary_test_01 + +xml_dump_filelists_test_01: package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o + gcc $(LINKFLAGS) $(CFLAGS) package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o ctests/xml_dump_filelists_test_01.c -o ctests/xml_dump_filelists_test_01 + +xml_dump_other_test_01: package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o + gcc $(LINKFLAGS) $(CFLAGS) package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o ctests/xml_dump_other_test_01.c -o ctests/xml_dump_other_test_01 -main: package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o - gcc $(LINKFLAGS) $(CFLAGS) package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o main.c -o main clean: - rm -f *.o *.so package_wrap.* main + rm -f *.o *.so *_wrap.* main *.pyc diff --git a/ctests/parsepkg_test_01.c b/ctests/parsepkg_test_01.c index 5064160..4010fe8 100644 --- a/ctests/parsepkg_test_01.c +++ b/ctests/parsepkg_test_01.c @@ -1,14 +1,20 @@ #include +#include "../constants.h" #include "../xml_dump.h" #include "../package.h" #include "../parsepkg.h" int main() { struct XmlStruct res; - res = xml_from_package_file("icedax-1.1.10-2.fc14.i686.rpm", "", "", "", 4, 10,12); + res = xml_from_package_file("icedax-1.1.10-2.fc14.i686.rpm", PKG_CHECKSUM_SHA256, "", "", 4); printf("Test - Start\n"); printf("%s\n\n%s\n\n%s\n", res.primary, res.filelists, res.other); printf("Test - Done\n"); + + free(res.primary); + free(res.filelists); + free(res.other); + return 0; } \ No newline at end of file diff --git a/main.c b/ctests/xml_dump_filelists_test_01.c similarity index 92% rename from main.c rename to ctests/xml_dump_filelists_test_01.c index fa6b29f..d0fae7d 100644 --- a/main.c +++ b/ctests/xml_dump_filelists_test_01.c @@ -1,6 +1,6 @@ #include -#include "package.h" -#include "xml_dump.h" +#include "../package.h" +#include "../xml_dump.h" int main() { Package *package = package_new(); @@ -92,7 +92,7 @@ int main() { package->files = g_slist_append(package->files, pkgfile6); package->files = g_slist_append(package->files, pkgfile7); - +/* ChangelogEntry *chlog = changelog_entry_new(); chlog->author = "foobar"; chlog->date = 1234567; @@ -105,17 +105,13 @@ int main() { package->changelogs = g_slist_append(package->changelogs, chlog); package->changelogs = g_slist_append(package->changelogs, chlog2); +*/ - - //printf("Jde se dumpovat\n"); - char *ret = xml_dump_primary(package, NULL); + char *ret = xml_dump_filelists(package, NULL); printf("%s\n\n", ret); - ret = xml_dump_filelists(package, NULL); - printf("%s\n\n", ret); - - ret = xml_dump_other(package, NULL); - printf("%s\n\n", ret); + package_free(package); + free(ret); return 0; } diff --git a/ctests/xml_dump_other_test_01.c b/ctests/xml_dump_other_test_01.c new file mode 100644 index 0000000..d9a6e98 --- /dev/null +++ b/ctests/xml_dump_other_test_01.c @@ -0,0 +1,118 @@ +#include +#include "../package.h" +#include "../xml_dump.h" + +int main() { + Package *package = package_new(); + + package->name = "ŠŠŠJMÉNÓ"; + package->pkgKey = 111; + package->pkgId = "32543dsafchecksum"; + package->arch = "i386"; + package->version = "88"; + package->epoch = "11"; + package->release = "08"; + package->summary = "short summary"; + package->description = "long description"; + package->url = "http://foo.bar"; + package->time_file = 123456; + package->time_build = 234567; + package->rpm_license = "GPL"; + package->rpm_vendor = "we"; + package->rpm_group = "grupa"; + package->rpm_buildhost = "superman"; + package->rpm_sourcerpm = "neco.src.rpm"; + package->rpm_header_start = 1; + package->rpm_header_end = 100; + package->rpm_packager = "batman"; + package->size_package = 777; + package->size_installed = 888; + package->size_archive = 666; + package->location_href = "tady"; + package->location_base = ""; + package->checksum_type = "sha256"; + +/* + Dependency *file = dependency_new(); + file->name = "soubor"; + file->flags = "A"; + file->epoch = "1"; + file->version = "2"; + file->release = "3"; + file->pre = 1; + + package->requires = g_slist_append(package->requires, file); + package->requires = g_slist_append(package->requires, file); + package->requires = g_slist_append(package->requires, file); + package->requires = g_slist_append(package->requires, file); + + package->provides = g_slist_append(package->provides, file); + package->provides = g_slist_append(package->provides, file); + package->provides = g_slist_append(package->provides, file); + + package->conflicts = g_slist_append(package->conflicts, file); + package->conflicts = g_slist_append(package->conflicts, file); + + package->obsoletes = g_slist_append(package->obsoletes, file); + + + PackageFile *pkgfile = package_file_new(); + pkgfile->name = "/bin/neco"; + pkgfile->type = ""; + + PackageFile *pkgfile2 = package_file_new(); + pkgfile2->name = "/usr/addresar"; + pkgfile2->type = "dir"; + + PackageFile *pkgfile3 = package_file_new(); + pkgfile3->name = "/etc/neco.conf"; + pkgfile3->type = ""; + + PackageFile *pkgfile4 = package_file_new(); + pkgfile4->name = "/usr/lib/sendmail"; + pkgfile4->type = ""; + + PackageFile *pkgfile5 = package_file_new(); + pkgfile5->name = "/etc/neco.dir"; + pkgfile5->type = "dir"; + + PackageFile *pkgfile6 = package_file_new(); + pkgfile6->name = "/bin/neco.dir"; + pkgfile6->type = "dir"; + + PackageFile *pkgfile7 = package_file_new(); + pkgfile7->name = "/usr/lib/sendmail"; + pkgfile7->type = "dir"; + + package->files = g_slist_append(package->files, pkgfile); + package->files = g_slist_append(package->files, pkgfile2); + package->files = g_slist_append(package->files, pkgfile3); + package->files = g_slist_append(package->files, pkgfile4); + package->files = g_slist_append(package->files, pkgfile5); + package->files = g_slist_append(package->files, pkgfile6); + package->files = g_slist_append(package->files, pkgfile7); +*/ + + ChangelogEntry *chlog = changelog_entry_new(); + chlog->author = "foobar"; + chlog->date = 1234567; + chlog->changelog = "very long changelog message"; + + ChangelogEntry *chlog2 = changelog_entry_new(); + chlog2->author = "foobar2"; + chlog2->date = 67890; + chlog2->changelog = "short changelog message"; + + package->changelogs = g_slist_append(package->changelogs, chlog); + package->changelogs = g_slist_append(package->changelogs, chlog2); + + + char *ret = xml_dump_other(package, NULL); + printf("%s\n\n", ret); + + package_free(package); + free(ret); + + return 0; +} + diff --git a/ctests/xml_dump_primary_test_01.c b/ctests/xml_dump_primary_test_01.c new file mode 100644 index 0000000..73ec45f --- /dev/null +++ b/ctests/xml_dump_primary_test_01.c @@ -0,0 +1,141 @@ +#include +#include "../package.h" +#include "../xml_dump.h" + +int main() { + Package *package = package_new(); + + package->name = "ŠŠŠJMÉNÓ"; + package->pkgKey = 111; + package->pkgId = "32543dsafchecksum"; + package->arch = "i386"; + package->version = "88"; + package->epoch = "11"; + package->release = "08"; + package->summary = "short summary"; + package->description = "long description"; + package->url = "http://foo.bar"; + package->time_file = 123456; + package->time_build = 234567; + package->rpm_license = "GPL"; + package->rpm_vendor = "we"; + package->rpm_group = "grupa"; + package->rpm_buildhost = "superman"; + package->rpm_sourcerpm = "neco.src.rpm"; + package->rpm_header_start = 1; + package->rpm_header_end = 100; + package->rpm_packager = "batman"; + package->size_package = 777; + package->size_installed = 888; + package->size_archive = 666; + package->location_href = "tady"; + package->location_base = ""; + package->checksum_type = "sha256"; + + + int x; + for (x=0; x<4; x++) { + Dependency *file = dependency_new(); + file->name = "soubor"; + file->flags = "A"; + file->epoch = "1"; + file->version = "2"; + file->release = "3"; + file->pre = 1; + package->requires = g_slist_append(package->requires, file); + } + + for (x=0; x<3; x++) { + Dependency *file = dependency_new(); + file->name = "soubor"; + file->flags = "A"; + file->epoch = "1"; + file->version = "2"; + file->release = "3"; + file->pre = 1; + package->provides = g_slist_append(package->provides, file); + } + + for (x=0; x<2; x++) { + Dependency *file = dependency_new(); + file->name = "soubor"; + file->flags = "A"; + file->epoch = "1"; + file->version = "2"; + file->release = "3"; + file->pre = 1; + package->conflicts = g_slist_append(package->conflicts, file); + } + + Dependency *file = dependency_new(); + file->name = "soubor"; + file->flags = "A"; + file->epoch = "1"; + file->version = "2"; + file->release = "3"; + file->pre = 1; + package->obsoletes = g_slist_append(package->obsoletes, file); + + + PackageFile *pkgfile = package_file_new(); + pkgfile->name = "/bin/neco"; + pkgfile->type = ""; + + PackageFile *pkgfile2 = package_file_new(); + pkgfile2->name = "/usr/addresar"; + pkgfile2->type = "dir"; + + PackageFile *pkgfile3 = package_file_new(); + pkgfile3->name = "/etc/neco.conf"; + pkgfile3->type = ""; + + PackageFile *pkgfile4 = package_file_new(); + pkgfile4->name = "/usr/lib/sendmail"; + pkgfile4->type = ""; + + PackageFile *pkgfile5 = package_file_new(); + pkgfile5->name = "/etc/neco.dir"; + pkgfile5->type = "dir"; + + PackageFile *pkgfile6 = package_file_new(); + pkgfile6->name = "/bin/neco.dir"; + pkgfile6->type = "dir"; + + PackageFile *pkgfile7 = package_file_new(); + pkgfile7->name = "/usr/lib/sendmail"; + pkgfile7->type = "dir"; + + package->files = g_slist_append(package->files, pkgfile); + package->files = g_slist_append(package->files, pkgfile2); + package->files = g_slist_append(package->files, pkgfile3); + package->files = g_slist_append(package->files, pkgfile4); + package->files = g_slist_append(package->files, pkgfile5); + package->files = g_slist_append(package->files, pkgfile6); + package->files = g_slist_append(package->files, pkgfile7); + + +/* + ChangelogEntry *chlog = changelog_entry_new(); + chlog->author = "foobar"; + chlog->date = 1234567; + chlog->changelog = "very long changelog message"; + + ChangelogEntry *chlog2 = changelog_entry_new(); + chlog2->author = "foobar2"; + chlog2->date = 67890; + chlog2->changelog = "short changelog message"; + + package->changelogs = g_slist_append(package->changelogs, chlog); + package->changelogs = g_slist_append(package->changelogs, chlog2); +*/ + + //printf("Jde se dumpovat\n"); + char *ret = xml_dump_primary(package, NULL); + printf("%s\n\n", ret); + + package_free(package); + free(ret); + + return 0; +} +