Skip to content

Commit

Permalink
[FIX] : add test case for a crash for particulur compareason case in …
Browse files Browse the repository at this point in the history
…Natural Sorting
  • Loading branch information
aiekick committed Jul 7, 2024
1 parent 64a3d01 commit 797cbb8
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ImGuiFileDialog
2 changes: 1 addition & 1 deletion mainWinLinuxMacos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main(int, char**) {
if (!glfwInit()) return 1;

// Decide GL+GLSL versions
#if APPLE
#ifdef __APPLE__
// GL 3.2 + GLSL 150
const char* glsl_version = "#version 150";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,4 @@ SetTest(Test_IGFD_Utils_NaturalCompare_0)
SetTest(Test_IGFD_Utils_NaturalCompare_1)
SetTest(Test_IGFD_Utils_NaturalCompare_2)
SetTest(Test_IGFD_Utils_NaturalCompare_3)
SetTest(Test_IGFD_Utils_NaturalCompare_4)
35 changes: 35 additions & 0 deletions tests/ImGuiFileDialog/Test_Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,40 @@ bool Test_IGFD_Utils_NaturalCompare_3() {
return true;
};

// natural sort : a crash occured is std::sort where a is filedialog_1 and b is filedialog
bool Test_IGFD_Utils_NaturalCompare_4() {
static constexpr size_t s_count_items = 16U;
std::array<std::string, s_count_items> bad_sort = //
{
"filed", //
"file", //
"filedialog_1", //
"filedialog", //
"filedialog_2", //
};

std::sort(bad_sort.begin(), bad_sort.end(), //
[](const std::string& a, const std::string& b) -> bool { //
return IGFD::Utils::NaturalCompare(a, b, true, false);
});

std::array<std::string, s_count_items> good_sort = //
{
"file", //
"filed", //
"filedialog", //
"filedialog_1", //
"filedialog_2", //
};

for (size_t idx = 0; idx < s_count_items; ++idx) {
if (good_sort.at(idx) != bad_sort.at(idx)) {
return false;
}
}
return true;
};

////////////////////////////////////////////////////////////////////////////
//// ENTRY POINT ///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -524,6 +558,7 @@ bool Test_Utils(const std::string& vTest) {
else IfTestExist(Test_IGFD_Utils_NaturalCompare_1);
else IfTestExist(Test_IGFD_Utils_NaturalCompare_2);
else IfTestExist(Test_IGFD_Utils_NaturalCompare_3);
else IfTestExist(Test_IGFD_Utils_NaturalCompare_4);

assert(0);

Expand Down
2 changes: 1 addition & 1 deletion tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main(int argc, char** argv) {
return Test_ImGuiFileDialog(argv[1]) ? 0 : 1;
}

return Test_ImGuiFileDialog("Test_IGFD_Utils_ExtractNumFromStringAtPos_2") ? 0 : 1;
return Test_ImGuiFileDialog("Test_IGFD_Utils_NaturalCompare_4") ? 0 : 1;

return 0;
}

0 comments on commit 797cbb8

Please sign in to comment.