mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 17:05:36 +01:00
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:
3
sqlite3/tests/.gitignore
vendored
Normal file
3
sqlite3/tests/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
sqlite3-tests
|
||||
*.d
|
||||
*.o
|
||||
38
sqlite3/tests/Makefile
Normal file
38
sqlite3/tests/Makefile
Normal 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
11
sqlite3/tests/check.h
Normal 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
16
sqlite3/tests/main.c
Normal 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;
|
||||
}
|
||||
11
sqlite3/tests/test-close.c
Normal file
11
sqlite3/tests/test-close.c
Normal 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
30
sqlite3/tests/test-open.c
Normal 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));
|
||||
}
|
||||
Reference in New Issue
Block a user