Skip to content

Commit 2642889

Browse files
committed
Bring back empty batches
Signed-off-by: Aleksandr Motsjonov <[email protected]>
1 parent cd9b9d0 commit 2642889

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

include/rawtoaces/image_converter.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ namespace util
1212
{
1313

1414
/// Collect all files from given `paths` into batches.
15-
/// For each path that is a directory, create an entry in the returned batches and fill it with the file names
16-
/// (unless all files are filtered out in which case no batch is created).
17-
/// All paths that are files are added to the first batch.
15+
/// For each path that is a directory, entries are created in the returned batches
16+
/// and fill it with the file names. Invalid paths are skipped with an error message.
17+
/// First batch is reserved for all paths that are files. If no such paths are provided,
18+
/// first batch will be empty.
19+
///
1820
/// @param paths vector of paths to files or directories to process.
1921
/// @return vector of batches, where each batch contains files from one input path.
20-
/// Non-existent paths are skipped with an error message.
2122
std::vector<std::vector<std::string>>
2223
collect_image_files( const std::vector<std::string> &paths );
2324

src/rawtoaces_util/image_converter.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,6 @@ collect_image_files( const std::vector<std::string> &paths )
108108
}
109109
}
110110

111-
// Remove empty batches
112-
batches.erase(
113-
std::remove_if(
114-
batches.begin(),
115-
batches.end(),
116-
[]( const std::vector<std::string> &batch ) {
117-
return batch.empty();
118-
} ),
119-
batches.end() );
120-
121111
return batches;
122112
}
123113

tests/test_image_converter.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ void test_collect_image_files_directory()
136136
std::vector<std::vector<std::string>> batches =
137137
collect_image_files( paths );
138138

139-
OIIO_CHECK_EQUAL( batches.size(), 1 );
140-
OIIO_CHECK_EQUAL( batches[0].size(), 5 );
139+
OIIO_CHECK_EQUAL(
140+
batches.size(),
141+
2 ); // Empty batch for file paths, one batch for directory
142+
OIIO_CHECK_EQUAL( batches[0].size(), 0 );
143+
OIIO_CHECK_EQUAL( batches[1].size(), 5 );
141144

142145
// Check that the correct files are included
143146
std::vector<std::string> expected_files = {
@@ -151,7 +154,7 @@ void test_collect_image_files_directory()
151154
for ( const auto &expected: expected_files )
152155
{
153156
bool found = false;
154-
for ( const auto &actual: batches[0] )
157+
for ( const auto &actual: batches[1] )
155158
{
156159
if ( actual == expected )
157160
{
@@ -183,8 +186,7 @@ void test_collect_image_files_single_file()
183186
OIIO_CHECK_EQUAL( batches[0][0], test_file );
184187
}
185188

186-
/// Verifies that collect_image_files skips nonexistent paths and creates no batches
187-
/// when given a path that doesn't exist, ensuring proper error handling for invalid input paths
189+
/// Verifies that collect_image_files skips nonexistent paths and creates no batches for them.
188190
void test_collect_image_files_nonexistent_path()
189191
{
190192
std::cout << std::endl
@@ -193,7 +195,7 @@ void test_collect_image_files_nonexistent_path()
193195
std::vector<std::vector<std::string>> batches =
194196
collect_image_files( paths );
195197

196-
OIIO_CHECK_EQUAL( batches.size(), 0 );
198+
OIIO_CHECK_EQUAL( batches.size(), 1 ); // Empty batch for file paths
197199
}
198200

199201
/// Ensures that when given an empty directory, collect_image_files creates no batches
@@ -207,11 +209,15 @@ void test_collect_image_files_empty_directory()
207209
std::vector<std::vector<std::string>> batches =
208210
collect_image_files( paths );
209211

210-
OIIO_CHECK_EQUAL( batches.size(), 0 );
212+
OIIO_CHECK_EQUAL(
213+
batches.size(),
214+
2 ); // Empty batch for file paths, one batch for directory
215+
OIIO_CHECK_EQUAL( batches[0].size(), 0 );
216+
OIIO_CHECK_EQUAL( batches[1].size(), 0 );
211217
}
212218

213219
/// Verifies that when a directory contains only files that should be filtered out
214-
/// (like .DS_Store, .jpg, .exr), collect_image_files does not create a batch,
220+
/// (like .DS_Store, .jpg, .exr)
215221
void test_collect_image_files_directory_with_only_filtered_files()
216222
{
217223
std::cout << std::endl
@@ -224,7 +230,11 @@ void test_collect_image_files_directory_with_only_filtered_files()
224230
std::vector<std::vector<std::string>> batches =
225231
collect_image_files( paths );
226232

227-
OIIO_CHECK_EQUAL( batches.size(), 0 );
233+
OIIO_CHECK_EQUAL(
234+
batches.size(),
235+
2 ); // Empty batch for file paths, one batch for directory
236+
OIIO_CHECK_EQUAL( batches[0].size(), 0 );
237+
OIIO_CHECK_EQUAL( batches[1].size(), 0 );
228238
}
229239

230240
/// Tests collect_image_files with multiple input paths (files and directories)

0 commit comments

Comments
 (0)