Skip to content

Commit

Permalink
Test for adding an empty list to memory file
Browse files Browse the repository at this point in the history
Although this scenario is not expected, make sure it is not crashing.
  • Loading branch information
jan-kolarik committed Nov 27, 2023
1 parent d31e368 commit de29b50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/libdnf5/repo/test_temp_files_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ void TempFilesMemoryTest::test_add_files_when_empty_storage() {
CPPUNIT_ASSERT_EQUAL(new_paths, memory.get_files());
}

void TempFilesMemoryTest::test_add_no_files_when_empty_storage() {
// make sure that adding an empty vector will not cause crashing

TempFilesMemory memory(base.get_weak_ptr(), parent_dir_path);
CPPUNIT_ASSERT(memory.get_files().empty());

std::vector<std::string> empty_paths = {};
memory.add_files(empty_paths);
CPPUNIT_ASSERT(memory.get_files().empty());
}

void TempFilesMemoryTest::test_add_files_when_existing_storage() {
std::vector<std::string> new_paths = {"path3", "path4"};
libdnf5::utils::fs::File(full_path, "w")
Expand Down
2 changes: 2 additions & 0 deletions test/libdnf5/repo/test_temp_files_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TempFilesMemoryTest : public BaseTestCase {
CPPUNIT_TEST(test_get_files_throws_exception_when_invalid_format);
CPPUNIT_TEST(test_get_files_returns_stored_values);
CPPUNIT_TEST(test_add_files_when_empty_storage);
CPPUNIT_TEST(test_add_no_files_when_empty_storage);
CPPUNIT_TEST(test_add_files_when_existing_storage);
CPPUNIT_TEST(test_add_files_deduplicates_and_sorts_data);
CPPUNIT_TEST(test_clear_deletes_storage_content);
Expand All @@ -48,6 +49,7 @@ class TempFilesMemoryTest : public BaseTestCase {
void test_get_files_throws_exception_when_invalid_format();
void test_get_files_returns_stored_values();
void test_add_files_when_empty_storage();
void test_add_no_files_when_empty_storage();
void test_add_files_when_existing_storage();
void test_add_files_deduplicates_and_sorts_data();
void test_clear_deletes_storage_content();
Expand Down

0 comments on commit de29b50

Please sign in to comment.