Initial pass on SQLite C ABI

This adds initial SQLite C ABI compatibility to Limbo to make sure we
drive the Rust API in the right way that allows us to implement SQLite
semantics.
This commit is contained in:
Pekka Enberg
2024-03-03 09:19:06 +02:00
parent 3420556018
commit f5cc3a08f0
14 changed files with 465 additions and 9 deletions

3
sqlite3/tests/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
sqlite3-tests
*.d
*.o

38
sqlite3/tests/Makefile Normal file
View File

@@ -0,0 +1,38 @@
V =
ifeq ($(strip $(V)),)
E = @echo
Q = @
else
E = @\#
Q =
endif
export E Q
PROGRAM = sqlite3-tests
CFLAGS = -g -Wall -std=c17 -MMD -MP
LIBS ?= -lsqlite3
OBJS += main.o
OBJS += test-close.o
OBJS += test-open.o
OBJS += test-prepare.o
all: $(PROGRAM)
%.o: %.c
$(E) " CC " $@
$(Q) $(CC) $(CFLAGS) -c $< -o $@
$(PROGRAM): $(OBJS)
$(E) " LINK " $@
$(Q) $(CC) $(LIBS) -o $@ $^
clean:
$(E) " CLEAN"
$(Q) rm -f $(PROGRAM)
$(Q) rm -f $(OBJS) *.d
.PHONY: clean
-include $(OBJS:.o=.d)

11
sqlite3/tests/check.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef CHECK_H
#define CHECK_EQUAL(expected, actual) \
do { \
if ((expected) != (actual)) { \
fprintf(stderr, "%s:%d: Assertion failed: %d != %d\n", __FILE__, __LINE__, (expected), (actual)); \
exit(1); \
} \
} while (0)
#endif

16
sqlite3/tests/main.c Normal file
View File

@@ -0,0 +1,16 @@
extern void test_open_misuse();
extern void test_open_not_found();
extern void test_open_existing();
extern void test_close();
extern void test_prepare_misuse();
int main(int argc, char *argv[])
{
test_open_misuse();
test_open_not_found();
test_open_existing();
test_close();
test_prepare_misuse();
return 0;
}

View File

@@ -0,0 +1,11 @@
#include <sqlite3.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include "check.h"
void test_close(void)
{
CHECK_EQUAL(SQLITE_OK, sqlite3_close(NULL));
}

30
sqlite3/tests/test-open.c Normal file
View File

@@ -0,0 +1,30 @@
#include "check.h"
#include <sqlite3.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
void test_open_misuse(void)
{
CHECK_EQUAL(SQLITE_MISUSE, sqlite3_open(NULL, NULL));
CHECK_EQUAL(SQLITE_MISUSE, sqlite3_open("local.db", NULL));
}
void test_open_not_found(void)
{
sqlite3 *db;
CHECK_EQUAL(SQLITE_CANTOPEN, sqlite3_open("not-found/local.db", &db));
}
// TODO: test_open_create
void test_open_existing(void)
{
sqlite3 *db;
CHECK_EQUAL(SQLITE_OK, sqlite3_open("../../testing/hello.db", &db));
CHECK_EQUAL(SQLITE_OK, sqlite3_close(db));
}