mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
86
base/base_tests/file_name_utils_tests.cpp
Normal file
86
base/base_tests/file_name_utils_tests.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include "testing/testing.hpp"
|
||||
|
||||
#include "base/file_name_utils.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
UNIT_TEST(FileName_Smoke)
|
||||
{
|
||||
std::string name = "/Users/xxx/Documents/test.test";
|
||||
TEST_EQUAL(base::GetFileExtension(name), ".test", ());
|
||||
base::GetNameFromFullPath(name);
|
||||
TEST_EQUAL(name, "test.test", ());
|
||||
base::GetNameFromFullPath(name);
|
||||
TEST_EQUAL(name, "test.test", ());
|
||||
base::GetNameWithoutExt(name);
|
||||
TEST_EQUAL(name, "test", ());
|
||||
|
||||
name = "C:\\My Documents\\test.test";
|
||||
TEST_EQUAL(base::GetFileExtension(name), ".test", ());
|
||||
base::GetNameFromFullPath(name);
|
||||
TEST_EQUAL(name, "test.test", ());
|
||||
base::GetNameWithoutExt(name);
|
||||
TEST_EQUAL(name, "test", ());
|
||||
|
||||
name = "/";
|
||||
TEST_EQUAL(base::GetFileExtension(name), std::string(), ());
|
||||
base::GetNameFromFullPath(name);
|
||||
TEST(name.empty(), ());
|
||||
|
||||
name = "C:\\";
|
||||
TEST_EQUAL(base::GetFileExtension(name), std::string(), ());
|
||||
base::GetNameFromFullPath(name);
|
||||
TEST(name.empty(), ());
|
||||
|
||||
name = "../test";
|
||||
TEST_EQUAL(base::GetFileExtension(name), std::string(), ());
|
||||
base::GetNameFromFullPath(name);
|
||||
TEST_EQUAL(name, "test", ());
|
||||
base::GetNameWithoutExt(name);
|
||||
TEST_EQUAL(name, "test", ());
|
||||
}
|
||||
|
||||
// TODO (@gorshenin): implement a Clean() method to clean file path
|
||||
// (remove redundant separators, correctly collapse dots, dot-dots, etc.).
|
||||
#ifndef OMIM_OS_WINDOWS
|
||||
|
||||
UNIT_TEST(FileName_GetDirectory)
|
||||
{
|
||||
TEST_EQUAL("/tmp", base::GetDirectory("/tmp/evil\\file"), ());
|
||||
TEST_EQUAL(".", base::GetDirectory("evil\\file"), ());
|
||||
|
||||
TEST_EQUAL("/", base::GetDirectory("/somefile.txt"), ());
|
||||
|
||||
TEST_EQUAL("/", base::GetDirectory("////somefile"), ());
|
||||
TEST_EQUAL("a/b", base::GetDirectory("a/b///somefile.txt"), ());
|
||||
|
||||
TEST_EQUAL("/a/b", base::GetDirectory("/a/b/c"), ());
|
||||
TEST_EQUAL("/a/b", base::GetDirectory("/a/b/c.txt"), ());
|
||||
|
||||
TEST_EQUAL(".", base::GetDirectory("somefile.txt"), ());
|
||||
TEST_EQUAL(".", base::GetDirectory("somefile"), ());
|
||||
}
|
||||
|
||||
UNIT_TEST(FilePath_Slash)
|
||||
{
|
||||
TEST_EQUAL("/", base::AddSlashIfNeeded(""), ());
|
||||
TEST_EQUAL("/", base::AddSlashIfNeeded("/"), ());
|
||||
TEST_EQUAL("./", base::AddSlashIfNeeded("."), ());
|
||||
TEST_EQUAL("data/", base::AddSlashIfNeeded("data"), ());
|
||||
TEST_EQUAL("data/", base::AddSlashIfNeeded("data/"), ());
|
||||
TEST_EQUAL("/data/", base::AddSlashIfNeeded("/data"), ());
|
||||
TEST_EQUAL("/data/", base::AddSlashIfNeeded("/data/"), ());
|
||||
TEST_EQUAL("../../data/", base::AddSlashIfNeeded("../../data"), ());
|
||||
TEST_EQUAL("../../data/", base::AddSlashIfNeeded("../../data/"), ());
|
||||
}
|
||||
|
||||
UNIT_TEST(FilePath_Join)
|
||||
{
|
||||
TEST_EQUAL("/root//path//file", base::JoinPath("/root/", "/path/", "/file"), ());
|
||||
TEST_EQUAL("omim/strings.txt", base::JoinPath("omim", "strings.txt"), ());
|
||||
TEST_EQUAL("omim/strings.txt", base::JoinPath("omim/", "strings.txt"), ());
|
||||
TEST_EQUAL("../../omim/strings.txt", base::JoinPath("..", "..", "omim", "strings.txt"), ());
|
||||
TEST_EQUAL("../../omim/strings.txt", base::JoinPath("../", "..", "omim/", "strings.txt"), ());
|
||||
}
|
||||
|
||||
#endif // OMIM_OS_WINDOWS
|
||||
Reference in New Issue
Block a user