gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated (70f09e5d0 -> cdb787378)


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated (70f09e5d0 -> cdb787378)
Date: Thu, 12 Jan 2017 20:18:39 +0100

This is an automated email from the git hooks/post-receive script.

mteich pushed a change to branch master
in repository gnunet.

    from 70f09e5d0 handle case upnpc not found nicely
     new cafbbb599 auction: add pricemap validation
     new 9006be70f auction: check for empty pricelist
     new cdb787378 auction: add test for auction-create

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/auction/Makefile.am             | 37 ++++++++++-------
 src/auction/gnunet-auction-create.c | 57 ++++++++++++++++++++++++++
 src/auction/test_auction_create.sh  | 80 +++++++++++++++++++++++++++++++++++++
 3 files changed, 159 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:address@hidden@};export 
PATH=$${GNUNET_PREFIX:address@hidden@}/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:address@hidden@};export 
PATH=$${GNUNET_PREFIX:address@hidden@}/bin:$$PATH;
+TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
+endif
diff --git a/src/auction/gnunet-auction-create.c 
b/src/auction/gnunet-auction-create.c
index c21e93f26..a4c029572 100644
--- a/src/auction/gnunet-auction-create.c
+++ b/src/auction/gnunet-auction-create.c
@@ -24,6 +24,9 @@
  * @author Markus Teich
  */
 #include "platform.h"
+
+#include <float.h>
+
 #include "gnunet_util_lib.h"
 #include "gnunet_json_lib.h"
 /* #include "gnunet_auction_service.h" */
@@ -56,6 +59,13 @@ run (void *cls,
         const char *cfgfile,
         const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+       unsigned int i;
+       double cur, prev = DBL_MAX;
+       json_t *pmap;
+       json_t *parray;
+       json_t *pnode;
+       json_error_t jerr;
+
        /* cmdline parsing */
        if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dstart.rel_value_us)
        {
@@ -82,6 +92,53 @@ run (void *cls,
                goto fail;
        }
 
+       /* parse and check pricemap validity */
+       if (!(pmap = json_load_file (fnprices, JSON_DECODE_INT_AS_REAL, &jerr)))
+       {
+               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                           "parsing pricemap json at %d:%d: %s\n",
+                           jerr.line, jerr.column, jerr.text);
+               goto fail;
+       }
+       if (-1 == json_unpack_ex (pmap, &jerr, JSON_VALIDATE_ONLY,
+                                 "{s:s, s:[]}", "currency", "prices"))
+       {
+               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                           "validating pricemap: %s\n", jerr.text);
+               goto fail;
+       }
+       if (!(parray = json_object_get (pmap, "prices")) || !json_is_array 
(parray))
+       {
+               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                           "could not get `prices` array node from 
pricemap\n");
+               goto fail;
+       }
+       if (0 == json_array_size (parray))
+       {
+               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "empty pricemap array\n");
+               goto fail;
+       }
+       json_array_foreach (parray, i, pnode)
+       {
+               if (-1 == json_unpack_ex (pnode, &jerr, 0, "F", &cur))
+               {
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                   "validating pricearray index %d: %s\n", i, 
jerr.text);
+                       goto fail;
+               }
+               if (prev <= cur)
+               {
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                   "validating pricearray index %d: "
+                                   "prices must be strictly monotonically 
decreasing\n",
+                                   i);
+                       goto fail;
+               }
+               prev = cur;
+       }
+
+       return;
+
 fail:
        ret = 1;
        return;
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 <<DOG >test.json
+[,]
+DOG
+gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1
+
+cat <<DOG >test.json
+bla
+DOG
+gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1
+
+
+# unexpected structures
+cat <<DOG >test.json
+{"foo": "bar"}
+DOG
+gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1
+
+cat <<DOG >test.json
+{"currency": "foo"}
+DOG
+gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1
+
+cat <<DOG >test.json
+{"prices": []}
+DOG
+gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1
+
+cat <<DOG >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 <<DOG >test.json
+{"currency": "foo", "prices": []}
+DOG
+gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1
+
+cat <<DOG >test.json
+{"currency": "foo", "prices": ["bar"]}
+DOG
+gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1
+
+cat <<DOG >test.json
+{"currency": "foo", "prices": [null]}
+DOG
+gnunet-auction-create -s 1 -r 1 -d foo -p test.json && exit 1
+
+cat <<DOG >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 <<DOG >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

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]