From 92ac709b7e87a82b3eb19f9ea34a0a48abe26d75 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sat, 26 Aug 2023 16:48:28 +0200 Subject: Adds safe versions of fl_filename_*, returning Fl_String --- test/unittest_core.cxx | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unittest_core.cxx b/test/unittest_core.cxx index 65fd71630..baccdbd04 100644 --- a/test/unittest_core.cxx +++ b/test/unittest_core.cxx @@ -21,6 +21,8 @@ #include #include #include +#include +#include /* Test Fl_String constructor and assignment. */ TEST(Fl_String, Assignment) { @@ -195,6 +197,29 @@ TEST(Fl_String, Non-Member Functions) { return true; } +/* Test additions to Fl_Preferences. */ +TEST(Fl_String, fl_filename_...) { + const Fl_String ref = "/test/me.txt"; + Fl_String name = fl_filename_name(ref); + EXPECT_STREQ(name.c_str(), "me.txt"); + name = fl_filename_name(Fl_String("/test/")); + EXPECT_STREQ(name.c_str(), ""); + Fl_String path = fl_filename_path(ref); + EXPECT_STREQ(path.c_str(), "/test/"); + Fl_String ext = fl_filename_ext(ref); + EXPECT_STREQ(ext.c_str(), ".txt"); + ext = fl_filename_setext(ref, ".rtf"); + EXPECT_STREQ(ext.c_str(), "/test/me.rtf"); + fl_putenv("FL_UNITTEST=unit/test"); + name = fl_filename_expand(Fl_String("abc/$FL_UNITTEST/xyz")); + EXPECT_STREQ(name.c_str(), "abc/unit/test/xyz"); + Fl_String abs = fl_filename_absolute(Fl_String("./abc/def.txt")); + Fl_String rel = fl_filename_relative(abs); + EXPECT_STREQ(rel.c_str(), "abc/def.txt"); + EXPECT_STREQ(ref.c_str(), "/test/me.txt"); + return true; +} + /* Test additions to Fl_Preferences. */ TEST(Fl_Preferences, Strings) { { @@ -318,9 +343,9 @@ public: // Run one single test and repeat calling this until all tests are done static void timer_cb(void*) { - // Run a test every few miliseconds to visualize the progress + // Run a test every few milliseconds to visualize the progress if (Ut_Suite::run_next_test()) - Fl::repeat_timeout(0.2, timer_cb); + Fl::repeat_timeout(0.15, timer_cb); } // Showing this tab for the first time will trigger the tests -- cgit v1.2.3