@@ -393,3 +393,52 @@ SENTRY_TEST(path_basename)
393393 TEST_CHECK (!sentry__path_basename (path , ".tar.gz" ));
394394 sentry__path_free (path );
395395}
396+
397+ SENTRY_TEST (path_copy )
398+ {
399+ #if defined(SENTRY_PLATFORM_NX )
400+ SKIP_TEST ();
401+ #endif
402+ sentry_path_t * src
403+ = sentry__path_from_str (SENTRY_TEST_PATH_PREFIX ".copy-src" );
404+ TEST_ASSERT (!!src );
405+ sentry_path_t * dst
406+ = sentry__path_from_str (SENTRY_TEST_PATH_PREFIX ".copy-dst" );
407+ TEST_ASSERT (!!dst );
408+
409+ // cleanup
410+ sentry__path_remove_all (src );
411+ sentry__path_remove_all (dst );
412+
413+ // copy file with content preserved
414+ sentry__path_write_buffer (src , "hello" , 5 );
415+ TEST_CHECK (sentry__path_copy (src , dst ) == 0 );
416+ TEST_CHECK (sentry__path_is_file (src ));
417+ TEST_CHECK (sentry__path_is_file (dst ));
418+ size_t len = 0 ;
419+ char * buf = sentry__path_read_to_buffer (dst , & len );
420+ TEST_ASSERT (!!buf );
421+ TEST_CHECK (len == 5 );
422+ TEST_CHECK (memcmp (buf , "hello" , 5 ) == 0 );
423+ sentry_free (buf );
424+ sentry__path_remove (dst );
425+
426+ // overwrite existing dst
427+ sentry__path_write_buffer (dst , "dst-data" , 8 );
428+ TEST_CHECK (sentry__path_copy (src , dst ) == 0 );
429+ TEST_CHECK (sentry__path_is_file (src ));
430+ buf = sentry__path_read_to_buffer (dst , & len );
431+ TEST_ASSERT (!!buf );
432+ TEST_CHECK (len == 5 );
433+ TEST_CHECK (memcmp (buf , "hello" , 5 ) == 0 );
434+ sentry_free (buf );
435+ sentry__path_remove (dst );
436+
437+ // copy nonexistent src
438+ sentry__path_remove (src );
439+ TEST_CHECK (sentry__path_copy (src , dst ) != 0 );
440+
441+ sentry__path_remove_all (dst );
442+ sentry__path_free (dst );
443+ sentry__path_free (src );
444+ }
0 commit comments