@@ -229,11 +229,11 @@ TEST_CASE_METHOD(
229229 tiledb_profile_alloc (name_, dir_.c_str (), &profile, &err);
230230 REQUIRE (profile != nullptr );
231231 SECTION (" success" ) {
232- rc = tiledb_profile_save (profile, &err);
232+ rc = tiledb_profile_save (profile, 0 , &err);
233233 REQUIRE (tiledb_status (rc) == TILEDB_OK);
234234 }
235235 SECTION (" null profile" ) {
236- rc = tiledb_profile_save (nullptr , &err);
236+ rc = tiledb_profile_save (nullptr , 0 , &err);
237237 REQUIRE (tiledb_status (rc) == TILEDB_ERR);
238238 }
239239
@@ -249,7 +249,7 @@ TEST_CASE_METHOD(
249249 tiledb_error_t * err = nullptr ;
250250 tiledb_profile_alloc (name_, dir_.c_str (), &profile, &err);
251251 REQUIRE (profile != nullptr );
252- rc = tiledb_profile_save (profile, &err);
252+ rc = tiledb_profile_save (profile, 0 , &err);
253253 REQUIRE (tiledb_status (rc) == TILEDB_OK);
254254 tiledb_profile_t * loaded_profile;
255255 // Use the same name and directory
@@ -275,7 +275,7 @@ TEST_CASE_METHOD(
275275 tiledb_profile_alloc (name_, dir_.c_str (), &profile, &err);
276276 REQUIRE (profile != nullptr );
277277 SECTION (" success" ) {
278- rc = tiledb_profile_save (profile, &err);
278+ rc = tiledb_profile_save (profile, 0 , &err);
279279 REQUIRE (tiledb_status (rc) == TILEDB_OK);
280280 rc = tiledb_profile_remove (name_, dir_.c_str (), &err);
281281 REQUIRE (tiledb_status (rc) == TILEDB_OK);
@@ -309,3 +309,55 @@ TEST_CASE_METHOD(
309309
310310 tiledb_profile_free (&profile);
311311}
312+
313+ TEST_CASE_METHOD (
314+ CAPINProfileFx,
315+ " C API: tiledb_profile_save with overwrite" ,
316+ " [capi][profile][save][overwrite]" ) {
317+ capi_return_t rc;
318+ tiledb_profile_t * p1;
319+ tiledb_error_t * err = nullptr ;
320+ tiledb_profile_alloc (name_, dir_.c_str (), &p1, &err);
321+ tiledb_profile_set_param (p1, " rest.token" , " token1" , &err);
322+ rc = tiledb_profile_save (p1, 0 , &err);
323+ REQUIRE (tiledb_status (rc) == TILEDB_OK);
324+
325+ // Attempt to save again without overwrite should fail
326+ tiledb_profile_t * p2;
327+ tiledb_profile_alloc (name_, dir_.c_str (), &p2, &err);
328+ tiledb_profile_set_param (p2, " rest.token" , " token2" , &err);
329+ rc = tiledb_profile_save (p2, 0 , &err);
330+ REQUIRE (tiledb_status (rc) == TILEDB_ERR);
331+ REQUIRE (err != nullptr );
332+ tiledb_error_free (&err);
333+
334+ // Verify that the original profile is unchanged
335+ tiledb_profile_t * loaded1;
336+ tiledb_profile_alloc (name_, dir_.c_str (), &loaded1, &err);
337+ tiledb_profile_load (loaded1, &err);
338+
339+ tiledb_string_t * value;
340+ tiledb_profile_get_param (loaded1, " rest.token" , &value, &err);
341+ const char * value_ptr;
342+ size_t value_len;
343+ tiledb_string_view (value, &value_ptr, &value_len);
344+ CHECK (std::string (value_ptr, value_len) == " token1" );
345+
346+ // Save with overwrite=1 should succeed
347+ rc = tiledb_profile_save (p2, 1 , &err);
348+ REQUIRE (tiledb_status (rc) == TILEDB_OK);
349+
350+ // Verify that the profile is updated
351+ tiledb_profile_t * loaded2;
352+ tiledb_profile_alloc (name_, dir_.c_str (), &loaded2, &err);
353+ tiledb_profile_load (loaded2, &err);
354+ tiledb_profile_get_param (loaded2, " rest.token" , &value, &err);
355+ tiledb_string_view (value, &value_ptr, &value_len);
356+ CHECK (std::string (value_ptr, value_len) == " token2" );
357+
358+ tiledb_string_free (&value);
359+ tiledb_profile_free (&p1);
360+ tiledb_profile_free (&p2);
361+ tiledb_profile_free (&loaded1);
362+ tiledb_profile_free (&loaded2);
363+ }
0 commit comments