We're going to be using this instead of our internal db. I also made json_out_obj() take the str arg, as it didn't and I expected it to. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
182 lines
8.2 KiB
C
182 lines
8.2 KiB
C
#include "config.h"
|
|
|
|
#include "plugins/bkpr/sql.c"
|
|
#include "plugins/libplugin.c"
|
|
|
|
#include <common/json_filter.h>
|
|
#include <common/json_stream.h>
|
|
#include <common/fee_states.h>
|
|
#include <common/setup.h>
|
|
#include <common/utils.h>
|
|
#include <stdio.h>
|
|
#include <wire/wire.h>
|
|
|
|
/* AUTOGENERATED MOCKS START */
|
|
/* Generated stub for daemon_developer_mode */
|
|
bool daemon_developer_mode(char *argv[])
|
|
{ fprintf(stderr, "daemon_developer_mode called!\n"); abort(); }
|
|
/* Generated stub for daemon_setup */
|
|
void daemon_setup(const char *argv0 UNNEEDED,
|
|
void (*backtrace_print)(const char *fmt UNNEEDED, ...) UNNEEDED,
|
|
void (*backtrace_exit)(void))
|
|
{ fprintf(stderr, "daemon_setup called!\n"); abort(); }
|
|
/* Generated stub for deprecated_ok_ */
|
|
bool deprecated_ok_(bool deprecated_apis UNNEEDED,
|
|
const char *feature UNNEEDED,
|
|
const char *start UNNEEDED,
|
|
const char *end UNNEEDED,
|
|
const char **begs UNNEEDED,
|
|
void (*complain)(const char *feat UNNEEDED, bool allowing UNNEEDED, void *) UNNEEDED,
|
|
void *cbarg UNNEEDED)
|
|
{ fprintf(stderr, "deprecated_ok_ called!\n"); abort(); }
|
|
/* Generated stub for find_blockheight */
|
|
u32 find_blockheight(const struct bkpr *bkpr UNNEEDED, const struct bitcoin_txid *txid UNNEEDED)
|
|
{ fprintf(stderr, "find_blockheight called!\n"); abort(); }
|
|
/* Generated stub for first_fee_state */
|
|
enum htlc_state first_fee_state(enum side opener UNNEEDED)
|
|
{ fprintf(stderr, "first_fee_state called!\n"); abort(); }
|
|
/* Generated stub for fmt_wireaddr_without_port */
|
|
char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
|
|
{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
|
|
/* Generated stub for fromwire_wireaddr */
|
|
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
|
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
|
/* Generated stub for htlc_state_flags */
|
|
int htlc_state_flags(enum htlc_state state UNNEEDED)
|
|
{ fprintf(stderr, "htlc_state_flags called!\n"); abort(); }
|
|
/* Generated stub for htlc_state_name */
|
|
const char *htlc_state_name(enum htlc_state s UNNEEDED)
|
|
{ fprintf(stderr, "htlc_state_name called!\n"); abort(); }
|
|
/* Generated stub for is_asterix_notification */
|
|
bool is_asterix_notification(const char *notification_name UNNEEDED,
|
|
const char *subscriptions UNNEEDED)
|
|
{ fprintf(stderr, "is_asterix_notification called!\n"); abort(); }
|
|
/* Generated stub for json_filter_down */
|
|
bool json_filter_down(struct json_filter **filter UNNEEDED, const char *member UNNEEDED)
|
|
{ fprintf(stderr, "json_filter_down called!\n"); abort(); }
|
|
/* Generated stub for json_filter_finished */
|
|
bool json_filter_finished(const struct json_filter *filter UNNEEDED)
|
|
{ fprintf(stderr, "json_filter_finished called!\n"); abort(); }
|
|
/* Generated stub for json_filter_misused */
|
|
const char *json_filter_misused(const tal_t *ctx UNNEEDED, const struct json_filter *f UNNEEDED)
|
|
{ fprintf(stderr, "json_filter_misused called!\n"); abort(); }
|
|
/* Generated stub for json_filter_ok */
|
|
bool json_filter_ok(const struct json_filter *filter UNNEEDED, const char *member UNNEEDED)
|
|
{ fprintf(stderr, "json_filter_ok called!\n"); abort(); }
|
|
/* Generated stub for json_filter_up */
|
|
bool json_filter_up(struct json_filter **filter UNNEEDED)
|
|
{ fprintf(stderr, "json_filter_up called!\n"); abort(); }
|
|
/* Generated stub for json_scan */
|
|
const char *json_scan(const tal_t *ctx UNNEEDED,
|
|
const char *buffer UNNEEDED,
|
|
const jsmntok_t *tok UNNEEDED,
|
|
const char *guide UNNEEDED,
|
|
...)
|
|
{ fprintf(stderr, "json_scan called!\n"); abort(); }
|
|
/* Generated stub for json_scanv */
|
|
const char *json_scanv(const tal_t *ctx UNNEEDED,
|
|
const char *buffer UNNEEDED,
|
|
const jsmntok_t *tok UNNEEDED,
|
|
const char *guide UNNEEDED,
|
|
va_list ap UNNEEDED)
|
|
{ fprintf(stderr, "json_scanv called!\n"); abort(); }
|
|
/* Generated stub for json_to_int */
|
|
bool json_to_int(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, int *num UNNEEDED)
|
|
{ fprintf(stderr, "json_to_int called!\n"); abort(); }
|
|
/* Generated stub for json_to_msat */
|
|
bool json_to_msat(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
|
struct amount_msat *msat UNNEEDED)
|
|
{ fprintf(stderr, "json_to_msat called!\n"); abort(); }
|
|
/* Generated stub for json_to_node_id */
|
|
bool json_to_node_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
|
struct node_id *id UNNEEDED)
|
|
{ fprintf(stderr, "json_to_node_id called!\n"); abort(); }
|
|
/* Generated stub for json_to_number */
|
|
bool json_to_number(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
|
unsigned int *num UNNEEDED)
|
|
{ fprintf(stderr, "json_to_number called!\n"); abort(); }
|
|
/* Generated stub for json_to_outpoint */
|
|
bool json_to_outpoint(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
|
struct bitcoin_outpoint *op UNNEEDED)
|
|
{ fprintf(stderr, "json_to_outpoint called!\n"); abort(); }
|
|
/* Generated stub for json_to_secret */
|
|
bool json_to_secret(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, struct secret *dest UNNEEDED)
|
|
{ fprintf(stderr, "json_to_secret called!\n"); abort(); }
|
|
/* Generated stub for json_to_sha256 */
|
|
bool json_to_sha256(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, struct sha256 *dest UNNEEDED)
|
|
{ fprintf(stderr, "json_to_sha256 called!\n"); abort(); }
|
|
/* Generated stub for json_to_short_channel_id */
|
|
bool json_to_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
|
struct short_channel_id *scid UNNEEDED)
|
|
{ fprintf(stderr, "json_to_short_channel_id called!\n"); abort(); }
|
|
/* Generated stub for json_to_txid */
|
|
bool json_to_txid(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
|
struct bitcoin_txid *txid UNNEEDED)
|
|
{ fprintf(stderr, "json_to_txid called!\n"); abort(); }
|
|
/* Generated stub for json_to_u16 */
|
|
bool json_to_u16(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
|
uint16_t *num UNNEEDED)
|
|
{ fprintf(stderr, "json_to_u16 called!\n"); abort(); }
|
|
/* Generated stub for json_tok_bin_from_hex */
|
|
u8 *json_tok_bin_from_hex(const tal_t *ctx UNNEEDED, const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED)
|
|
{ fprintf(stderr, "json_tok_bin_from_hex called!\n"); abort(); }
|
|
/* Generated stub for last_fee_state */
|
|
enum htlc_state last_fee_state(enum side opener UNNEEDED)
|
|
{ fprintf(stderr, "last_fee_state called!\n"); abort(); }
|
|
/* Generated stub for log_level_name */
|
|
const char *log_level_name(enum log_level level UNNEEDED)
|
|
{ fprintf(stderr, "log_level_name called!\n"); abort(); }
|
|
/* Generated stub for new_channel_event */
|
|
struct channel_event *new_channel_event(const tal_t *ctx UNNEEDED,
|
|
const char *tag UNNEEDED,
|
|
struct amount_msat credit UNNEEDED,
|
|
struct amount_msat debit UNNEEDED,
|
|
struct amount_msat fees UNNEEDED,
|
|
struct sha256 *payment_id STEALS UNNEEDED,
|
|
u32 part_id UNNEEDED,
|
|
u64 timestamp UNNEEDED)
|
|
{ fprintf(stderr, "new_channel_event called!\n"); abort(); }
|
|
/* Generated stub for param_check */
|
|
bool param_check(struct command *cmd UNNEEDED,
|
|
const char *buffer UNNEEDED,
|
|
const jsmntok_t tokens[] UNNEEDED, ...)
|
|
{ fprintf(stderr, "param_check called!\n"); abort(); }
|
|
/* Generated stub for parse_filter */
|
|
struct command_result *parse_filter(struct command *cmd UNNEEDED,
|
|
const char *name UNNEEDED,
|
|
const char *buffer UNNEEDED,
|
|
const jsmntok_t *tok UNNEEDED)
|
|
{ fprintf(stderr, "parse_filter called!\n"); abort(); }
|
|
/* AUTOGENERATED MOCKS END */
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
common_setup(argv[0]);
|
|
/* No quote: should return same pointer */
|
|
const char *s1 = "simple";
|
|
const char *r1 = sql_string(tmpctx, s1);
|
|
assert(r1 == s1);
|
|
|
|
/* One quote: should return new string with doubled quote */
|
|
const char *s2 = "O'Reilly";
|
|
const char *r2 = sql_string(tmpctx, s2);
|
|
assert(strcmp(r2, "O''Reilly") == 0);
|
|
assert(r2 != s2); // New allocation
|
|
|
|
/* Multiple quotes */
|
|
const char *s3 = "'a'b'c'";
|
|
const char *r3 = sql_string(tmpctx, s3);
|
|
assert(strcmp(r3, "''a''b''c''") == 0);
|
|
|
|
/* All quotes */
|
|
const char *s4 = "''''";
|
|
const char *r4 = sql_string(tmpctx, s4);
|
|
assert(strcmp(r4, "''''''''") == 0);
|
|
|
|
/* Empty string: should return same pointer */
|
|
const char *s5 = "";
|
|
const char *r5 = sql_string(tmpctx, s5);
|
|
assert(r5 == s5);
|
|
common_shutdown();
|
|
}
|