This directory contains comprehensive tests for the SVS C API using the Catch2 testing framework.
The tests are organized into separate files by functionality:
- c_api_error.cpp: Tests for error handling functionality
- c_api_algorithm.cpp: Tests for algorithm creation and configuration (Vamana)
- c_api_storage.cpp: Tests for storage configurations (Simple, LeanVec, LVQ, SQ)
- c_api_search_params.cpp: Tests for search parameter creation and configuration
- c_api_index_builder.cpp: Tests for index builder creation and configuration
- c_api_index.cpp: Tests for index building, searching, and basic operations
- c_api_dynamic_index.cpp: Tests for dynamic index operations (add, delete, consolidate, compact)
Note: The main() function is provided by Catch2::Catch2WithMain automatically.
The tests are built as part of the C API build process. To build them:
# From the build directory
cmake -DSVS_BUILD_C_API_TESTS=ON ..
make svs_c_api_testsTo disable building tests:
cmake -DSVS_BUILD_C_API_TESTS=OFF .../svs_c_api_tests# Run error handling tests only
./svs_c_api_tests "[c_api][error]"
# Run algorithm tests only
./svs_c_api_tests "[c_api][algorithm]"
# Run all index tests
./svs_c_api_tests "[c_api][index]"
# Run dynamic index tests
./svs_c_api_tests "[c_api][dynamic]"./svs_c_api_tests -s./svs_c_api_tests --list-testsctest -R svs_c_api_testsThe tests cover the following aspects of the C API:
- Error handle creation and cleanup
- Error state checking
- Error codes and messages
- NULL error handle support
- Vamana algorithm creation
- Parameter getters and setters (graph_degree, build_window_size, alpha, search_history)
- Invalid parameter handling
- Simple storage (Float32, Float16, Int8, Uint8)
- LeanVec storage (various primary/secondary combinations)
- LVQ storage (with and without residual)
- Scalar Quantization storage
- Vamana search parameter creation
- Various window sizes
- Index builder creation with different metrics (Euclidean, Cosine, Dot Product)
- Storage configuration
- Thread pool configuration (Native, OMP, Custom)
- Index building from data
- Searching with queries
- Different K values
- Distance calculation
- Vector reconstruction
- Thread count management
- Dynamic index building with/without explicit IDs
- Adding points
- Deleting points
- ID existence checking
- Index consolidation
- Index compaction
- Search after modifications
The tests follow the patterns established in the SVS project:
- Use
CATCH_TEST_CASEfor test case definitions - Use
CATCH_SECTIONfor test subsections - Use
CATCH_REQUIREfor assertions - Clean up all resources (free handles) after each test
- Test both success and error paths
- Test with and without NULL error handles
When adding new tests:
- Create a new
.cppfile or add to an existing one - Follow the existing structure and naming conventions
- Include proper copyright header
- Use appropriate test tags:
[c_api][functionality] - Add the new test file to
CMakeLists.txtif needed - Clean up all allocated resources
- Test both success and error conditions
- Catch2 v3.x (automatically fetched if not found)
- SVS C API library
- C++17 or later compiler
- Tests use a simple sequential thread pool for deterministic behavior
- Test data is generated programmatically for repeatability
- Some tests may be skipped if optional features are not enabled (e.g., LVQ/LeanVec)