Skip to content

Commit b58f161

Browse files
committed
Add basic GitHub CI
1 parent 621aa9c commit b58f161

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CppSQLite CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, windows-latest, macos-latest]
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Build static library (CppSQLite3.o/CppSQLite3.obj)
21+
run: |
22+
c++ -c src/CppSQLite3.cpp -o CppSQLite3.o
23+
24+
- name: Build and run test program
25+
if: runner.os != 'Windows'
26+
run: |
27+
c++ src/test.cpp src/CppSQLite3.cpp -lsqlite3 -o testprog
28+
./testprog
29+
shell: bash
30+
31+
# Windows expects .exe and uses different shell
32+
- name: Build and run test program
33+
if: runner.os == 'Windows'
34+
run: |
35+
cl /EHsc /MD src/test.cpp src/CppSQLite3.cpp /I. /link sqlite3.lib
36+
testprog.exe
37+
shell: cmd

src/test.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "CppSQLite3.h"
2+
#include <iostream>
3+
#include <cassert>
4+
5+
int main() {
6+
try {
7+
CppSQLite3DB db;
8+
9+
// In-memory database
10+
db.open(":memory:");
11+
12+
db.execDML("CREATE TABLE test(id INTEGER PRIMARY KEY, name TEXT);");
13+
assert(db.tableExists("test"));
14+
15+
db.execDML("INSERT INTO test(name) VALUES ('Alice');");
16+
db.execDML("INSERT INTO test(name) VALUES ('Bob');");
17+
18+
// Query it back using both Query and Table
19+
{
20+
auto q = db.execQuery("SELECT * FROM test ORDER BY id;");
21+
int cnt = 0;
22+
while (!q.eof()) {
23+
int id = q.getIntField("id");
24+
const char* name = q.getStringField("name");
25+
std::cout << "Row " << id << ": " << name << std::endl;
26+
q.nextRow();
27+
++cnt;
28+
}
29+
assert(cnt == 2);
30+
}
31+
32+
{
33+
auto t = db.getTable("SELECT id, name FROM test;");
34+
assert(t.numRows() == 2);
35+
t.setRow(0);
36+
assert(std::string(t.getStringField(1)) == "Alice");
37+
t.setRow(1);
38+
assert(std::string(t.getStringField(1)) == "Bob");
39+
}
40+
41+
db.close();
42+
std::cout << "CppSQLite basic tests passed!" << std::endl;
43+
return 0;
44+
} catch(const CppSQLite3Exception& e) {
45+
std::cerr << "CppSQLite3Exception: " << e.errorMessage() << std::endl;
46+
return 1;
47+
}
48+
}

0 commit comments

Comments
 (0)