From 0333cf00baf4d5b796347334af1f15d5bb9a2df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 20 Mar 2019 12:59:11 +0100 Subject: Fix BLI_path_frame_strip The `BLI_path_frame_strip` function was completely broken, unless the number of digits in the sequence number was the same as the length of the extension. In other words, it would work fine for `file.0001.abc` (4 digit `0001` and 4 char `.abc`), but other combinations would truncate to the shortest (`file.001.abc` would become `file.###.ab` and `file.00001.a` would become `file.##.a`). The dependency between the sequence number and the file extension is now removed. The behaviour has changed a little bit in the case where there are no numbers in the filename. Previously, `path="filename.abc"` would result in `path="filename.abc"` and `ext=""`, but now it results in `path="filename"` and `ext=".abc"`. This way `ext` always contains the extension, and the behaviour is consistent regardless of whether there were any numbers found. Furthermore, I've removed the `bool set_frame_char` parameter, because it was unclear, probably also buggy, and most importantly, never used. I've also added a unit test for the `BLI_path_frame_strip` function. --- tests/gtests/blenlib/BLI_path_util_test.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/gtests/blenlib/BLI_path_util_test.cc b/tests/gtests/blenlib/BLI_path_util_test.cc index 41fad661ea9..1cd1cbc345d 100644 --- a/tests/gtests/blenlib/BLI_path_util_test.cc +++ b/tests/gtests/blenlib/BLI_path_util_test.cc @@ -462,3 +462,25 @@ TEST(path_util, SplitDirfile) EXPECT_STREQ("", file); } } + +#define PATH_FRAME_STRIP(input_path, expect_path, expect_ext) \ +{ \ + char path[FILE_MAX]; \ + char ext[FILE_MAX]; \ + BLI_strncpy(path, (input_path), FILE_MAX); \ + BLI_path_frame_strip(path, ext); \ + EXPECT_STREQ(path, expect_path); \ + EXPECT_STREQ(ext, expect_ext); \ +} + +/* BLI_path_frame_strip */ +TEST(path_util, PathFrameStrip) +{ + PATH_FRAME_STRIP("", "", ""); + PATH_FRAME_STRIP("nonum.abc", "nonum", ".abc"); + PATH_FRAME_STRIP("fileonly.001.abc", "fileonly.###", ".abc"); + PATH_FRAME_STRIP("/abspath/to/somefile.001.abc", "/abspath/to/somefile.###", ".abc"); + PATH_FRAME_STRIP("/ext/longer/somefile.001.alembic", "/ext/longer/somefile.###", ".alembic"); + PATH_FRAME_STRIP("/ext/shorter/somefile.123001.abc", "/ext/shorter/somefile.######", ".abc"); +} +#undef PATH_FRAME_STRIP -- cgit v1.2.3