summaryrefslogtreecommitdiff
path: root/src/pq
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-06-10 17:39:34 +0200
committerChristian Grothoff <christian@grothoff.org>2015-06-10 17:39:34 +0200
commit9a3dd7cb25a410270a2feb672aa84afd8ea4bca2 (patch)
tree2f9fd1f2cc1211a7f36fd1249eba9d94ce5791f8 /src/pq
parentaef3b7c350e34f71425ef403d3e5991aced2eb57 (diff)
downloadexchange-9a3dd7cb25a410270a2feb672aa84afd8ea4bca2.tar.gz
exchange-9a3dd7cb25a410270a2feb672aa84afd8ea4bca2.tar.bz2
exchange-9a3dd7cb25a410270a2feb672aa84afd8ea4bca2.zip
new test for uint and json APIs
Diffstat (limited to 'src/pq')
-rw-r--r--src/pq/Makefile.am4
-rw-r--r--src/pq/db_pq.c1
-rw-r--r--src/pq/pq_helper.c2
-rw-r--r--src/pq/test_pq.c45
4 files changed, 45 insertions, 7 deletions
diff --git a/src/pq/Makefile.am b/src/pq/Makefile.am
index 746094ce4..2187d494b 100644
--- a/src/pq/Makefile.am
+++ b/src/pq/Makefile.am
@@ -17,7 +17,7 @@ libtalerpq_la_SOURCES = \
libtalerpq_la_LIBADD = \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunetutil \
+ -lgnunetutil -ljansson \
-lpq $(XLIB)
libtalerpq_la_LDFLAGS = \
@@ -36,5 +36,5 @@ test_pq_SOURCES = \
test_pq_LDADD = \
libtalerpq.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunetutil \
+ -lgnunetutil -ljansson \
-lpq $(XLIB)
diff --git a/src/pq/db_pq.c b/src/pq/db_pq.c
index 693da2f35..e1a082e44 100644
--- a/src/pq/db_pq.c
+++ b/src/pq/db_pq.c
@@ -237,6 +237,7 @@ TALER_PQ_exec_prepared (PGconn *db_conn,
char *str;
str = json_dumps (json, JSON_COMPACT);
+ GNUNET_assert (NULL != str);
scratch[soff++] = str;
param_values[off] = (void *) str;
param_lengths[off] = strlen (str);
diff --git a/src/pq/pq_helper.c b/src/pq/pq_helper.c
index 01441dec3..f4b0c0109 100644
--- a/src/pq/pq_helper.c
+++ b/src/pq/pq_helper.c
@@ -294,7 +294,7 @@ TALER_PQ_result_spec_uint16 (const char *name,
*/
struct TALER_PQ_ResultSpec
TALER_PQ_result_spec_uint32 (const char *name,
- uint16_t *u32)
+ uint32_t *u32)
{
struct TALER_PQ_ResultSpec res =
{TALER_PQ_RF_UINT32, (void *) u32, sizeof (*u32), (name), NULL };
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c
index c89313b64..bda227587 100644
--- a/src/pq/test_pq.c
+++ b/src/pq/test_pq.c
@@ -13,7 +13,6 @@
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/
-
/**
* @file pq/test_pq.c
* @brief Tests for Postgres convenience API
@@ -61,10 +60,14 @@ postgres_prepare (PGconn *db_conn)
",namount_frac"
",namount_curr"
",vsize"
+ ",u16"
+ ",u32"
+ ",u64"
+ ",json"
") VALUES "
"($1, $2, $3, $4, $5, $6,"
- "$7, $8, $9, $10, $11, $12);",
- 11, NULL);
+ "$7, $8, $9, $10, $11, $12, $13, $14, $15, $16);",
+ 16, NULL);
PREPARE ("test_select",
"SELECT"
" pub"
@@ -79,6 +82,10 @@ postgres_prepare (PGconn *db_conn)
",namount_frac"
",namount_curr"
",vsize"
+ ",u16"
+ ",u32"
+ ",u64"
+ ",json"
" FROM test_pq"
" ORDER BY abs_time DESC "
" LIMIT 1;",
@@ -116,6 +123,14 @@ run_queries (PGconn *conn)
char msg[] = "Hello";
void *msg2;
size_t msg2_len;
+ uint16_t u16;
+ uint16_t u162;
+ uint32_t u32;
+ uint32_t u322;
+ uint64_t u64;
+ uint64_t u642;
+ json_t *json;
+ json_t *json2;
priv = GNUNET_CRYPTO_rsa_private_key_create (1024);
pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv);
@@ -130,6 +145,12 @@ run_queries (PGconn *conn)
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount ("EUR:4.4",
&hamount));
+ u16 = 16;
+ u32 = 32;
+ u64 = 64;
+ json = json_object ();
+ json_object_set (json, "foo", json_integer (42));
+ GNUNET_assert (NULL != json);
/* FIXME: test TALER_PQ_result_spec_variable_size */
{
struct TALER_PQ_QueryParam params_insert[] = {
@@ -141,6 +162,10 @@ run_queries (PGconn *conn)
TALER_PQ_query_param_amount (&hamount),
TALER_PQ_query_param_amount_nbo (&namount),
TALER_PQ_query_param_fixed_size (msg, strlen (msg)),
+ TALER_PQ_query_param_uint16 (&u16),
+ TALER_PQ_query_param_uint32 (&u32),
+ TALER_PQ_query_param_uint64 (&u64),
+ TALER_PQ_query_param_json (json),
TALER_PQ_query_param_end
};
struct TALER_PQ_QueryParam params_select[] = {
@@ -155,6 +180,10 @@ run_queries (PGconn *conn)
TALER_PQ_result_spec_amount ("hamount", &hamount2),
TALER_PQ_result_spec_amount_nbo ("namount", &namount2),
TALER_PQ_result_spec_variable_size ("vsize", &msg2, &msg2_len),
+ TALER_PQ_result_spec_uint16 ("u16", &u162),
+ TALER_PQ_result_spec_uint32 ("u32", &u322),
+ TALER_PQ_result_spec_uint64 ("u64", &u642),
+ TALER_PQ_result_spec_json ("json", &json2),
TALER_PQ_result_spec_end
};
@@ -219,7 +248,11 @@ run_queries (PGconn *conn)
strncmp (msg,
msg2,
msg2_len));
-
+ GNUNET_break (16 == u162);
+ GNUNET_break (32 == u322);
+ GNUNET_break (64 == u642);
+ GNUNET_break (42 == json_integer_value (json_object_get (json2, "foo")));
+ json_decref (json2);
TALER_PQ_cleanup_result (results_select);
PQclear (result);
}
@@ -269,6 +302,10 @@ main(int argc,
",namount_frac INT4 NOT NULL"
",namount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",vsize VARCHAR NOT NULL"
+ ",u16 INT2 NOT NULL"
+ ",u32 INT4 NOT NULL"
+ ",u64 INT8 NOT NULL"
+ ",json VARCHAR NOT NULL"
")");
if (PGRES_COMMAND_OK != PQresultStatus (result))
{