Skip to content

Commit f53ad0e

Browse files
committed
RCDB C++ tests automation
1 parent 381346e commit f53ad0e

16 files changed

Lines changed: 325 additions & 376 deletions

File tree

.github/workflows/cpp-tests.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: C++ tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches: [main]
7+
8+
jobs:
9+
cpp-sqlite:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Install build dependencies
16+
run: |
17+
sudo apt-get update
18+
sudo apt-get install -y cmake g++ libsqlite3-dev
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.12"
24+
25+
# The C++ unit tests read a fixture SQLite database. We build it with the
26+
# `rcdb` CLI - the single, canonical way to initialize an RCDB database -
27+
# so there is no checked-in binary fixture to drift out of sync.
28+
- name: Install rcdb (provides the `rcdb db init` test fixture)
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install --editable $GITHUB_WORKSPACE/python
32+
33+
- name: Create the C++ test SQLite database
34+
run: |
35+
rcdb -c "sqlite:////$GITHUB_WORKSPACE/cpp_test.sqlite" db init --add-cpp-tests --confirm
36+
37+
- name: Configure and build C++ tests (SQLite only)
38+
run: |
39+
cmake -S $GITHUB_WORKSPACE/cpp -B $GITHUB_WORKSPACE/cpp/build -DWITH_SQLITE=ON -DWITH_MYSQL=OFF
40+
cmake --build $GITHUB_WORKSPACE/cpp/build --target test_rcdb_cpp -j
41+
42+
- name: Run C++ tests
43+
env:
44+
# 4-slash form: SQLAlchemy (used to seed) and the C++ SqLiteProvider parser
45+
# (strips the leading "sqlite:///") both resolve this to the same absolute path.
46+
RCDB_TEST_CONNECTION: "sqlite:////${{ github.workspace }}/cpp_test.sqlite"
47+
run: $GITHUB_WORKSPACE/cpp/build/test_rcdb_cpp

.github/workflows/python-tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Python tests
22

3-
on: [push]
3+
on:
4+
push:
5+
pull_request:
6+
branches: [main]
47

58
jobs:
69
build:

cpp/CMakeLists.txt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
#(!) this CMake build system IS experimental and is made mostly for using CLion IDE.
2-
# Scons - is the main RCDB make system, so please use it in order to build rcdb.lib and examples
1+
# RCDB C++ is a header-only library - nothing here is required to USE it (just #include the headers
2+
# and link sqlite3 and/or the mysql client). This CMake project builds the unit tests and examples.
3+
#
4+
# Build & run the SQLite unit tests:
5+
# cmake -S . -B build -DWITH_SQLITE=ON -DWITH_MYSQL=OFF
6+
# cmake --build build --target test_rcdb_cpp
7+
# RCDB_TEST_CONNECTION="sqlite:///<path-to>.sqlite" ./build/test_rcdb_cpp
8+
# Create the test database with: rcdb -c sqlite:///<path-to>.sqlite db init --add-cpp-tests --confirm
39

410
cmake_minimum_required(VERSION 3.4)
511
project(rcdb_cpp)
@@ -68,17 +74,27 @@ SET(TEST_SOURCE_FILES
6874
include/RCDB/StringUtils.h
6975
include/RCDB/ConfigParser.h
7076

71-
tests/test_Connection.cpp
7277
tests/test_ConditionType.cpp
73-
tests/test_MySqlProvider.cpp
74-
tests/test_SqLiteProvider.cpp
7578

7679
tests/catch.hpp
7780
tests/catch.cpp
7881
tests/test_ConfigParser.cpp
7982
include/json/json.hpp
8083
)
8184

85+
# Provider tests are gated by the corresponding DB backend, so an SQLite-only
86+
# build does not need MySQL headers (mysql.h) and a MySQL-only build does not need SQLite.
87+
if(WITH_MYSQL)
88+
list(APPEND TEST_SOURCE_FILES tests/test_MySqlProvider.cpp)
89+
endif()
90+
91+
# The Connection and SqLiteProvider tests both pull in the SQLiteCpp amalgamation,
92+
# whose out-of-line definitions are not `inline`. Compile them as a single unity
93+
# translation unit (tests/test_sqlite_unity.cpp) so the definitions appear once.
94+
if(WITH_SQLITE)
95+
list(APPEND TEST_SOURCE_FILES tests/test_sqlite_unity.cpp)
96+
endif()
97+
8298
add_executable(test_rcdb_cpp ${TEST_SOURCE_FILES})
8399
add_executable(examples_trigger_params examples/get_trigger_params.cpp)
84100
add_executable(examples_fadc_masks examples/get_fadc_masks.cpp)

cpp/SConstruct

Lines changed: 0 additions & 97 deletions
This file was deleted.

cpp/examples/SConscript

Lines changed: 0 additions & 49 deletions
This file was deleted.

cpp/tests/SConscript

Lines changed: 0 additions & 64 deletions
This file was deleted.

cpp/tests/test_sqlite_unity.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Unity translation unit for the SQLite-backed tests.
2+
//
3+
// The vendored SQLiteCpp amalgamation (include/RCDB/SQLiteCpp.h) defines its
4+
// member functions out-of-line WITHOUT `inline`, so it is only safe to pull
5+
// into a single translation unit per binary - exactly how every cpp/examples
6+
// program (each a single .cpp) uses it. The test binary is the only consumer
7+
// that links several object files, so test_Connection.cpp and
8+
// test_SqLiteProvider.cpp - both of which transitively include SQLiteCpp.h -
9+
// would otherwise produce duplicate-symbol link errors.
10+
//
11+
// Compiling them together here makes SQLiteCpp.h's include guard collapse the
12+
// definitions to one copy. The two source files keep their own TEST_CASEs and
13+
// remain editable/standalone for IDEs; CMake compiles this unity file instead
14+
// of the two individually (see cpp/CMakeLists.txt, WITH_SQLITE branch).
15+
16+
#include "test_SqLiteProvider.cpp"
17+
#include "test_Connection.cpp"

docs/Cpp.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ In order for your code to build ensure flags/configuration:
6868

6969
* Code ```#define RCDB_MYSQL```
7070
* Compiler arguments ```-DRCDB_MYSQL```
71-
* Scons ```env.Append(CPPDEFINES=['RCDB_MYSQL', 'RCDB_SQLITE'])```
72-
* CMAKE ```add_definitions(-DRCDB_MYSQL)```
73-
* SMBS ```AddRcdb()``` in SConscript
71+
* CMake ```-DWITH_MYSQL=ON``` (which does ```add_definitions(-DRCDB_MYSQL)```)
7472

7573

7674
### Dependencies
@@ -123,15 +121,29 @@ rapidjson::Document ToJsonDocument(); /// For JSon document
123121
rcdb::ValueTypes GetValueType(); /// Returns the type enum
124122
```
125123

126-
## Examples
124+
## Building the tests and examples (CMake)
127125

128-
Examples are located in [$RCDB_HOME/cpp/examples](https://github.com/JeffersonLab/rcdb/tree/main/cpp/examples) folder. To build them use `with-examples=true` scons flag:
126+
The C++ tests and examples are built with CMake. SQLite-only is the default; add
127+
`-DWITH_MYSQL=ON` to also build the MySQL provider (needs `libmysqlclient-dev`).
129128

130129
```bash
131130
cd $RCDB_HOME/cpp
132-
scons with-examples=true #...
131+
cmake -S . -B build -DWITH_SQLITE=ON -DWITH_MYSQL=OFF
132+
cmake --build build --target test_rcdb_cpp # unit tests
133+
cmake --build build # everything, incl. examples
133134
```
134135

136+
The unit tests need a SQLite database with test data. Create one with the `rcdb` CLI
137+
and point `RCDB_TEST_CONNECTION` at it:
138+
139+
```bash
140+
rcdb -c sqlite:///cpp_test.sqlite db init --add-cpp-tests --confirm
141+
RCDB_TEST_CONNECTION="sqlite:///cpp_test.sqlite" ./build/test_rcdb_cpp
142+
```
143+
144+
Examples are located in the [$RCDB_HOME/cpp/examples](https://github.com/JeffersonLab/rcdb/tree/main/cpp/examples) folder
145+
and are built as the `examples_*` targets by the `cmake --build build` command above.
146+
135147
After examples are built they are located in `$RCDB_HOME/cpp/bin` directory named as `exmpl_<...>`
136148

137149
<br>

docs/Database-Installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ rcdb -c sqlite:///test.sqlite db init --drop-all
5454
The command to upgrade DB structure from previous RCDB versions:
5555

5656
```bash
57-
rcdb -c sqlite:///test.sqlite db upgrade
57+
rcdb -c sqlite:///test.sqlite db update
5858
```
5959

0 commit comments

Comments
 (0)