tests: import a test for the sqlite2 engine
This commit is contained in:
parent
de8c580371
commit
7baf0a93f6
|
@ -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
|
cppflags_force=-I ../include
|
||||||
cflags_force=`pkg-config --cflags libSystem`
|
cflags_force=`pkg-config --cflags libSystem`
|
||||||
cflags=-W -Wall -g -O2 -pedantic -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector-all
|
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_force=`pkg-config --libs libSystem` -L $(OBJDIR)../src -lDatabase
|
||||||
ldflags=-pie
|
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
|
#targets
|
||||||
[clint.log]
|
[clint.log]
|
||||||
|
@ -19,6 +19,16 @@ script=./fixme.sh
|
||||||
depends=fixme.sh,$(OBJDIR)../src/libDatabase.a
|
depends=fixme.sh,$(OBJDIR)../src/libDatabase.a
|
||||||
enabled=0
|
enabled=0
|
||||||
|
|
||||||
|
[sqlite2]
|
||||||
|
type=binary
|
||||||
|
sources=sqlite2.c
|
||||||
|
depends=$(OBJDIR)sqlite2.db
|
||||||
|
|
||||||
|
[sqlite2.db]
|
||||||
|
type=script
|
||||||
|
script=./database.sh
|
||||||
|
depends=sqlite2.sql
|
||||||
|
|
||||||
[sqlite3]
|
[sqlite3]
|
||||||
type=binary
|
type=binary
|
||||||
sources=sqlite3.c
|
sources=sqlite3.c
|
||||||
|
|
95
tests/sqlite2.c
Normal file
95
tests/sqlite2.c
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2016-2022 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* 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 <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <System.h>
|
||||||
|
#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;
|
||||||
|
}
|
21
tests/sqlite2.sql
Normal file
21
tests/sqlite2.sql
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
-- $Id$
|
||||||
|
-- Copyright (c) 2016 Pierre Pronchery <khorben@defora.org>
|
||||||
|
-- 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
DROP TABLE "table";
|
||||||
|
|
||||||
|
CREATE TABLE "table" (
|
||||||
|
table_id INTEGER PRIMARY KEY
|
||||||
|
);
|
|
@ -109,6 +109,12 @@ else
|
||||||
failures="$failures python.sh"
|
failures="$failures python.sh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if $PKGCONFIG --exists "sqlite"; then
|
||||||
|
tests="$tests sqlite2"
|
||||||
|
else
|
||||||
|
failures="$failures sqlite2"
|
||||||
|
fi
|
||||||
|
|
||||||
if $PKGCONFIG --exists "sqlite3"; then
|
if $PKGCONFIG --exists "sqlite3"; then
|
||||||
tests="$tests sqlite3"
|
tests="$tests sqlite3"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user