diff options
author | Sree Harsha Totakura <sreeharsha@totakura.in> | 2015-03-05 15:59:22 +0100 |
---|---|---|
committer | Sree Harsha Totakura <sreeharsha@totakura.in> | 2015-03-05 15:59:22 +0100 |
commit | e6943f5a9e4fd6599a1ae15951c04bafddfe1a4d (patch) | |
tree | 4c949fb3e8ff1728ab76cd2d357d7620f04b4d74 | |
parent | bea425de6cbbfb054a19e0f2312c5ef00c2e1bbe (diff) | |
download | exchange-e6943f5a9e4fd6599a1ae15951c04bafddfe1a4d.tar.gz exchange-e6943f5a9e4fd6599a1ae15951c04bafddfe1a4d.zip |
Add testcase for DB layer
-rw-r--r-- | src/mint/Makefile.am | 11 | ||||
-rw-r--r-- | src/mint/test_mint_db.c | 81 |
2 files changed, 91 insertions, 1 deletions
diff --git a/src/mint/Makefile.am b/src/mint/Makefile.am index af0b48e84..19fba62f0 100644 --- a/src/mint/Makefile.am +++ b/src/mint/Makefile.am | |||
@@ -101,7 +101,8 @@ taler_mint_dbinit_LDFLAGS = $(POSTGRESQL_LDFLAGS) | |||
101 | 101 | ||
102 | check_PROGRAMS = \ | 102 | check_PROGRAMS = \ |
103 | test-mint-deposits \ | 103 | test-mint-deposits \ |
104 | test-mint-common | 104 | test-mint-common \ |
105 | test-mint-db | ||
105 | 106 | ||
106 | test_mint_deposits_SOURCES = \ | 107 | test_mint_deposits_SOURCES = \ |
107 | test_mint_deposits.c | 108 | test_mint_deposits.c |
@@ -120,3 +121,11 @@ test_mint_common_LDADD = \ | |||
120 | $(top_srcdir)/src/util/libtalerutil.la \ | 121 | $(top_srcdir)/src/util/libtalerutil.la \ |
121 | $(top_srcdir)/src/pq/libtalerpq.la \ | 122 | $(top_srcdir)/src/pq/libtalerpq.la \ |
122 | -lgnunetutil | 123 | -lgnunetutil |
124 | |||
125 | test_mint_db_SOURCES = \ | ||
126 | test_mint_db.c | ||
127 | test_mint_db_LDADD = \ | ||
128 | libtalermint_common.la \ | ||
129 | $(top_srcdir)/src/util/libtalerutil.la \ | ||
130 | $(top_srcdir)/src/pq/libtalerpq.la \ | ||
131 | -lgnunetutil | ||
diff --git a/src/mint/test_mint_db.c b/src/mint/test_mint_db.c new file mode 100644 index 000000000..4fa84eb38 --- /dev/null +++ b/src/mint/test_mint_db.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /* | ||
2 | This file is part of TALER | ||
3 | Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | TALER is free software; you can redistribute it and/or modify it under the | ||
6 | terms of the GNU General Public License as published by the Free Software | ||
7 | Foundation; either version 3, or (at your option) any later version. | ||
8 | |||
9 | TALER is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along with | ||
14 | TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file mint/test_mint_db.c | ||
19 | * @brief test cases for DB interaction functions | ||
20 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
21 | */ | ||
22 | |||
23 | #include "platform.h" | ||
24 | #include "mint_db.h" | ||
25 | |||
26 | static int result; | ||
27 | |||
28 | |||
29 | /** | ||
30 | * Main function that will be run by the scheduler. | ||
31 | * | ||
32 | * @param cls closure | ||
33 | * @param args remaining command-line arguments | ||
34 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
35 | * @param config configuration | ||
36 | */ | ||
37 | static void | ||
38 | run (void *cls, char *const *args, const char *cfgfile, | ||
39 | const struct GNUNET_CONFIGURATION_Handle *config) | ||
40 | { | ||
41 | PGconn *db; | ||
42 | |||
43 | db = NULL; | ||
44 | if (GNUNET_OK != TALER_MINT_DB_init ("postgres:///taler")) | ||
45 | { | ||
46 | result = 1; | ||
47 | return; | ||
48 | } | ||
49 | if (GNUNET_OK != TALER_MINT_DB_create_tables (GNUNET_YES)) | ||
50 | { | ||
51 | result = 2; | ||
52 | goto drop; | ||
53 | } | ||
54 | if (NULL == (db = TALER_MINT_DB_get_connection(GNUNET_YES))) | ||
55 | { | ||
56 | result = 3; | ||
57 | goto drop; | ||
58 | } | ||
59 | result = 0; | ||
60 | drop: | ||
61 | if (NULL != db) | ||
62 | GNUNET_break (GNUNET_OK == TALER_MINT_DB_drop_temporary (db)); | ||
63 | } | ||
64 | |||
65 | |||
66 | int | ||
67 | main (int argc, char *const argv[]) | ||
68 | { | ||
69 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
70 | GNUNET_GETOPT_OPTION_END | ||
71 | }; | ||
72 | |||
73 | result = -1; | ||
74 | if (GNUNET_OK != | ||
75 | GNUNET_PROGRAM_run (argc, argv, | ||
76 | "test-mint-db", | ||
77 | "Test cases for mint database helper functions.", | ||
78 | options, &run, NULL)) | ||
79 | return 3; | ||
80 | return result; | ||
81 | } | ||