From cdb78737878d73db365e2af9be5729d39fbab2bb Mon Sep 17 00:00:00 2001 From: Markus Teich Date: Thu, 12 Jan 2017 20:17:35 +0100 Subject: [PATCH] auction: add test for auction-create --- src/auction/Makefile.am | 37 ++++++++------ src/auction/test_auction_create.sh | 80 ++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 15 deletions(-) create mode 100755 src/auction/test_auction_create.sh diff --git a/src/auction/Makefile.am b/src/auction/Makefile.am index 8518244fa..0c250a0b4 100644 --- a/src/auction/Makefile.am +++ b/src/auction/Makefile.am @@ -5,6 +5,7 @@ pkgcfgdir= $(pkgdatadir)/config.d/ libexecdir= $(pkglibdir)/libexec/ + dist_pkgcfg_DATA = \ auction.conf @@ -16,13 +17,22 @@ if USE_COVERAGE AM_CFLAGS = -fprofile-arcs -ftest-coverage endif -# use bin_PROGRAMS for gnunet-auction wrapper script libexec_PROGRAMS = \ + gnunet-service-auction + +gnunet_service_auction_SOURCES = \ + gnunet-service-auction.c +gnunet_service_auction_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + -ljansson \ + $(GN_LIBINTL) + + +bin_PROGRAMS = \ gnunet-auction-create \ gnunet-auction-info \ - gnunet-auction-join \ - gnunet-service-auction + gnunet-auction-join gnunet_auction_create_SOURCES = \ gnunet-auction-create.c @@ -45,23 +55,20 @@ gnunet_auction_join_LDADD = \ -ljansson \ $(GN_LIBINTL) -gnunet_service_auction_SOURCES = \ - gnunet-service-auction.c -gnunet_service_auction_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - -ljansson \ - $(GN_LIBINTL) - check_PROGRAMS = \ test_auction_api -if ENABLE_TEST_RUN -AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; -TESTS = $(check_PROGRAMS) -endif - test_auction_api_SOURCES = \ test_auction_api.c test_auction_api_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la + + +check_SCRIPTS = \ + test_auction_create.sh + +if ENABLE_TEST_RUN +AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; +TESTS = $(check_PROGRAMS) $(check_SCRIPTS) +endif diff --git a/src/auction/test_auction_create.sh b/src/auction/test_auction_create.sh new file mode 100755 index 000000000..b0f4de738 --- /dev/null +++ b/src/auction/test_auction_create.sh @@ -0,0 +1,80 @@ +#! /bin/sh + +trap 'rm -f test.json' EXIT + + +# missing required cmdline args +gnunet-auction-create -r 1 -d foo -p test.json && exit 1 +gnunet-auction-create -s 1 -d foo -p test.json && exit 1 +gnunet-auction-create -s 1 -r 1 -p test.json && exit 1 +gnunet-auction-create -s 1 -r 1 -d foo && exit 1 + + +# no pricemap +rm -f test.json +gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 + + +# json errors +cat <test.json +[,] +DOG +gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 + +cat <test.json +bla +DOG +gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 + + +# unexpected structures +cat <test.json +{"foo": "bar"} +DOG +gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 + +cat <test.json +{"currency": "foo"} +DOG +gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 + +cat <test.json +{"prices": []} +DOG +gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 + +cat <test.json +{"currency": "foo", "prices": "bar"} +DOG +gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 + + +# wrong array content +cat <test.json +{"currency": "foo", "prices": []} +DOG +gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 + +cat <test.json +{"currency": "foo", "prices": ["bar"]} +DOG +gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 + +cat <test.json +{"currency": "foo", "prices": [null]} +DOG +gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 + +cat <test.json +{"currency": "foo", "prices": [1, 2]} +DOG +gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1 + + +# correct example +cat <test.json +{"currency": "foo", "prices": [2, 1]} +DOG +gnunet-auction-create -s 1 -r 1 -d foo -p test.json || exit 1 + +rm -f test.json -- 2.25.1