diff --git a/tests/project.conf b/tests/project.conf index 3e1e92d..7493ed0 100644 --- a/tests/project.conf +++ b/tests/project.conf @@ -1,10 +1,10 @@ -targets=clint.log,fixme.log,pylint.log,shlint.log,sqlite3,sqlite3.db,tests.log +targets=clint.log,fixme.log,pylint.log,shlint.log,sqlite2,sqlite2.db,sqlite3,sqlite3.db,tests.log cppflags_force=-I ../include cflags_force=`pkg-config --cflags libSystem` cflags=-W -Wall -g -O2 -pedantic -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector-all ldflags_force=`pkg-config --libs libSystem` -L $(OBJDIR)../src -lDatabase ldflags=-pie -dist=Makefile,clint.sh,database.sh,fixme.sh,pkgconfig.sh,pylint.sh,python.sh,shlint.sh,sqlite3.sql,tests.sh +dist=Makefile,clint.sh,database.sh,fixme.sh,pkgconfig.sh,pylint.sh,python.sh,shlint.sh,sqlite2.sql,sqlite3.sql,tests.sh #targets [clint.log] @@ -19,6 +19,16 @@ script=./fixme.sh depends=fixme.sh,$(OBJDIR)../src/libDatabase.a enabled=0 +[sqlite2] +type=binary +sources=sqlite2.c +depends=$(OBJDIR)sqlite2.db + +[sqlite2.db] +type=script +script=./database.sh +depends=sqlite2.sql + [sqlite3] type=binary sources=sqlite3.c diff --git a/tests/sqlite2.c b/tests/sqlite2.c new file mode 100644 index 0000000..4d84679 --- /dev/null +++ b/tests/sqlite2.c @@ -0,0 +1,95 @@ +/* $Id$ */ +/* Copyright (c) 2016-2022 Pierre Pronchery */ +/* This file is part of DeforaOS Database libDatabase */ +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + + + +#include +#include +#include +#include +#include "Database.h" + +#ifndef PROGNAME_SQLITE2 +# define PROGNAME_SQLITE2 "sqlite2" +#endif + + +/* sqlite2 */ +/* private */ +/* prototypes */ +static int _sqlite2(void); + +static int _usage(void); + + +/* functions */ +/* sqlite2 */ +static int _sqlite2(void) +{ + Config * config; + Database * db; + String * filename; + char const * p; + + if((config = config_new()) == NULL) + { + error_print(PROGNAME_SQLITE2); + return -1; + } + if((p = getenv("OBJDIR")) != NULL) + filename = string_new_append(p, "/sqlite2.db", NULL); + else + filename = string_new("sqlite2.db"); + if(filename == NULL + || config_set(config, NULL, "filename", filename) != 0) + { + error_print(PROGNAME_SQLITE2); + string_delete(filename); + config_delete(config); + return -1; + } + string_delete(filename); + db = database_new("sqlite2", config, NULL); + config_delete(config); + if(db == NULL) + return 2; + if(database_query(db, "SELECT * FROM \"table\"", NULL, NULL) != 0) + { + error_print(PROGNAME_SQLITE2); + database_delete(db); + return 2; + } + database_delete(db); + return 0; +} + + +/* usage */ +static int _usage(void) +{ + fputs("Usage: " PROGNAME_SQLITE2 "\n", stderr); + return 1; +} + + +/* public */ +/* functions */ +/* main */ +int main(int argc, char * argv[]) +{ + if(argc != 1) + return _usage(); + return (_sqlite2() == 0) ? 0 : 2; +} diff --git a/tests/sqlite2.sql b/tests/sqlite2.sql new file mode 100644 index 0000000..7d96a37 --- /dev/null +++ b/tests/sqlite2.sql @@ -0,0 +1,21 @@ +-- $Id$ +-- Copyright (c) 2016 Pierre Pronchery +-- This file is part of DeforaOS Database libDatabase +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, version 3 of the License. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + + +DROP TABLE "table"; + +CREATE TABLE "table" ( + table_id INTEGER PRIMARY KEY +); diff --git a/tests/tests.sh b/tests/tests.sh index c12c048..39199f5 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -109,6 +109,12 @@ else failures="$failures python.sh" fi +if $PKGCONFIG --exists "sqlite"; then + tests="$tests sqlite2" +else + failures="$failures sqlite2" +fi + if $PKGCONFIG --exists "sqlite3"; then tests="$tests sqlite3" else