@@ -25,6 +25,9 @@ struct TestResult {
2525 std::string message;
2626};
2727
28+ // Database path used by main(); set in main() so same-path-reuse tests use it
29+ static const char * g_db_path = " ./seekdb.db" ;
30+
2831// Test database open (database is already open in main, just verify it's open)
2932TestResult test_open () {
3033 // Database is already open in main(), so just verify we can create a connection
@@ -2713,13 +2716,13 @@ TestResult test_empty_json_metadata() {
27132716 return {true , " " };
27142717}
27152718
2716- // Same-process same-path reuse: second seekdb_open() with same path (relative) must return success (no "db opened by other process").
2719+ // Same-process same-path reuse: second seekdb_open() with same path must return success (no "db opened by other process").
27172720TestResult test_embedded_same_path_reuse_relative () {
2718- // Database already opened in main() with "./seekdb.db"; open again with same path must succeed
2719- int ret = seekdb_open (" ./seekdb.db " );
2721+ // Re-open with the same path used in main() (relative or absolute)
2722+ int ret = seekdb_open (g_db_path );
27202723 if (ret != SEEKDB_SUCCESS) {
27212724 const char * err = seekdb_last_error ();
2722- return {false , std::string (" second seekdb_open(\" ./seekdb.db \" ) should succeed, got: " ) + (err ? err : " unknown" )};
2725+ return {false , std::string (" second seekdb_open(same path ) should succeed, got: " ) + (err ? err : " unknown" )};
27232726 }
27242727 return {true , " " };
27252728}
@@ -2730,7 +2733,7 @@ TestResult test_embedded_same_path_reuse_absolute() {
27302733 if (getcwd (cwd, sizeof (cwd)) == nullptr ) {
27312734 return {false , " getcwd failed" };
27322735 }
2733- std::string abs_path = std::string (cwd) + " /seekdb.db " ;
2736+ std::string abs_path = (g_db_path[ 0 ] == ' / ' ) ? g_db_path : ( std::string (cwd) + " /" + g_db_path) ;
27342737 int ret = seekdb_open (abs_path.c_str ());
27352738 if (ret != SEEKDB_SUCCESS) {
27362739 const char * err = seekdb_last_error ();
@@ -4304,14 +4307,17 @@ TestResult test_stmt_store_result() {
43044307 return {true , " " };
43054308}
43064309
4307- int main () {
4310+ int main (int argc, char * argv[]) {
4311+ // Database path: argv[1] if provided, else default relative path (same as other bindings)
4312+ g_db_path = (argc >= 2 && argv[1 ] && argv[1 ][0 ] != ' \0 ' ) ? argv[1 ] : " ./seekdb.db" ;
4313+
43084314 std::cout << std::string (70 , ' =' ) << std::endl;
43094315 std::cout << " SeekDB C++ Binding Test Suite" << std::endl;
43104316 std::cout << std::string (70 , ' =' ) << std::endl;
43114317 std::cout << std::endl;
4312-
4318+
43134319 // Open database once at the beginning
4314- int ret = seekdb_open (" ./seekdb.db " );
4320+ int ret = seekdb_open (g_db_path );
43154321 if (ret != SEEKDB_SUCCESS) {
43164322 std::cerr << " Failed to open database: " << ret << std::endl;
43174323 return 1 ;
0 commit comments