Index: trunk/src/VBox/Runtime/testcase/tstRTPath.cpp
===================================================================
--- trunk/src/VBox/Runtime/testcase/tstRTPath.cpp	(revision 82968)
+++ trunk/src/VBox/Runtime/testcase/tstRTPath.cpp	(revision 85383)
@@ -353,4 +353,81 @@
             RTTestFailed(hTest, "sub-test #%u: got '%s', expected '%s' (style %#x)",
                          i, szPath, s_aTests[i].pszOut, s_aTests[i].fFlags);
+    }
+}
+
+
+static void testFindCommon(RTTEST hTest)
+{
+    RTTestSub(hTest, "RTPathFindCommon");
+
+    static struct
+    {
+        char const *apszPaths[4];
+        uint32_t    fFlags;
+        char const *pszCommon;
+    } const aTests[] =
+    {
+        /* Simple stuff first. */
+        { { "",                     "",                 "",                     NULL, },            RTPATH_STR_F_STYLE_UNIX,
+            "" },
+        { { "none",                 "none",             "",                     NULL, },            RTPATH_STR_F_STYLE_UNIX,
+            "" },
+        /* Missing start slash. */
+        { { "/path/to/stuff1",      "path/to/stuff2",   NULL,                   NULL, },            RTPATH_STR_F_STYLE_UNIX,
+            "" },
+        /* Working stuff. */
+        { { "/path/to/stuff1",      "/path/to/stuff2",  "/path/to/stuff3",      NULL, },            RTPATH_STR_F_STYLE_UNIX,
+            "/path/to/" },
+        { { "/path/to/stuff1",      "/path/to/",        "/path/",               NULL, },            RTPATH_STR_F_STYLE_UNIX,
+            "/path/" },
+        { { "/path/to/stuff1",      "/",                "/path/",               NULL, },            RTPATH_STR_F_STYLE_UNIX,
+            "" },
+        { { "/path/to/../stuff1",   "./../",            "/path/to/stuff2/..",   NULL, },            RTPATH_STR_F_STYLE_UNIX,
+            "" },
+
+#if 0 /** @todo */
+        /* Things that should be working that aren't: */
+        { { "a/single/path",        NULL,               NULL,                   NULL, },            RTPATH_STR_F_STYLE_UNIX,
+            "a/single/path" },
+        { { "a/single\\path",       NULL,               NULL,                   NULL, },            RTPATH_STR_F_STYLE_DOS,
+            "a/single\\path" },
+        { { "C:\\Windows",          NULL,               NULL,                   NULL, },            RTPATH_STR_F_STYLE_DOS,
+            "C:\\Windows" },
+        { { "c:/windows",           "c:\\program files", "C:\\AppData",         NULL, },            RTPATH_STR_F_STYLE_DOS,
+            "c:/" },
+        { { "//usr/bin/env",        "/usr//bin/env",   "/usr/bin///env",        "/usr/bin/env", },  RTPATH_STR_F_STYLE_UNIX,
+            "//usr/bin/env" },
+        { { "//usr/bin/env",        "/usr//./././bin/env", "/usr/bin///env",    "/usr/bin/env", },  RTPATH_STR_F_STYLE_UNIX,
+            "//usr/bin/env" },
+        { { "//./what/ever",        "\\\\.\\what\\is\\up", "\\\\.\\\\what\\is\\up", NULL, },        RTPATH_STR_F_STYLE_DOS,
+            "//./what/" },
+        { { "//./unc/is/weird",     "///./unc/is/weird", NULL,                  NULL, },            RTPATH_STR_F_STYLE_DOS,
+            "" },
+        { { "/path/to/stuff1",      "path/to/stuff2",   NULL,                   NULL, },            RTPATH_STR_F_STYLE_UNIX | RTPATH_STR_F_NO_START,
+            "/path/to/" },
+        { { "path/to/stuff1",       "//path\\/to\\stuff2", NULL,                NULL, },            RTPATH_STR_F_STYLE_DOS | RTPATH_STR_F_NO_START,
+            "path/to/" },
+
+        /* '..' elements are not supported for now and leads to zero return. */
+        { { "/usr/bin/env",         "/usr/../usr/bin/env", "/usr/bin/../bin/env", NULL, },          RTPATH_STR_F_STYLE_UNIX,
+            "" },
+        { { "/lib/",                "/lib/amd64/../lib.so", "/lib/i386/../libdl.so", NULL, },       RTPATH_STR_F_STYLE_UNIX,
+            "" },
+#endif
+    };
+
+    for (size_t i = 0; i < RT_ELEMENTS(aTests); i++)
+    {
+        size_t cPaths = RT_ELEMENTS(aTests[i].apszPaths);
+        while (cPaths > 0 && aTests[i].apszPaths[cPaths - 1] == NULL)
+            cPaths--;
+
+        size_t const cchCommon = RTPathFindCommonEx(cPaths, aTests[i].apszPaths, aTests[i].fFlags);
+        size_t const cchExpect = strlen(aTests[i].pszCommon);
+        if (cchCommon != cchExpect)
+            RTTestFailed(hTest,
+                         "Test %zu failed: got %zu, expected %zu (cPaths=%zu: '%s' '%s' '%s' '%s', fFlags=%#x)", i, cchCommon,
+                         cchExpect, cPaths, aTests[i].apszPaths[0], aTests[i].apszPaths[1], aTests[i].apszPaths[2],
+                         aTests[i].apszPaths[3], aTests[i].fFlags);
     }
 }
@@ -1087,4 +1164,5 @@
     testPurgeFilename(hTest);
     testEnsureTrailingSeparator(hTest);
+    testFindCommon(hTest);
 
     /*
