Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/DefaultFileSystem.cpp

Issue 29538640: Issue 5610 - Deal with a '/' base path (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created Sept. 7, 2017, 4:31 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/DefaultFileSystem.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/DefaultFileSystem.cpp
===================================================================
--- a/test/DefaultFileSystem.cpp
+++ b/test/DefaultFileSystem.cpp
@@ -10,16 +10,17 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <memory>
#include <sstream>
#include <AdblockPlus.h>
#include <gtest/gtest.h>
#include "../src/DefaultFileSystem.h"
#include "BaseJsTest.h"
using AdblockPlus::IFileSystem;
using AdblockPlus::FileSystemPtr;
@@ -30,16 +31,20 @@
{
const std::string testFileName = "libadblockplus-t\xc3\xa4st-file";
FileSystemPtr CreateDefaultFileSystem(const Scheduler& scheduler)
{
return FileSystemPtr(new DefaultFileSystem(scheduler, std::unique_ptr<DefaultFileSystemSync>(new DefaultFileSystemSync(""))));
}
+ class BasePathTest : public ::testing::Test
sergei 2017/09/08 08:11:40 It seems this fixture is not required, one can sim
hub 2017/09/08 13:10:26 Done.
+ {
+ };
+
class DefaultFileSystemTest : public ::testing::Test
{
public:
void SetUp() override
{
fileSystem = CreateDefaultFileSystem([this](const SchedulerTask& task)
{
fileSystemTasks.emplace_back(task);
@@ -68,16 +73,68 @@
fileSystemTasks.pop_front();
}
std::list<SchedulerTask> fileSystemTasks;
FileSystemPtr fileSystem;
};
}
+#ifdef _WIN32
+#define SLASH_STRING "\\"
+#else
+#define SLASH_STRING "/"
sergei 2017/09/08 08:11:40 These defines are already available as PATH_SEPARA
hub 2017/09/08 13:10:26 but they are single char, while this is a string.
sergei 2017/09/08 13:20:18 Acknowledged.
+#endif
+
+
+TEST_F(BasePathTest, BasePathTest)
sergei 2017/09/08 08:11:40 What about renaming it into something emphasizing
hub 2017/09/08 13:10:26 Done.
+{
+ class TestFSSync : public DefaultFileSystemSync
+ {
+ public:
+ explicit TestFSSync(const std::string& basePath)
+ : DefaultFileSystemSync(basePath)
+ {
+ }
+ const std::string& base() const
+ {
+ return basePath;
+ }
+ };
+
+ {
+ auto fs = std::unique_ptr<TestFSSync>(new TestFSSync(""));
+ EXPECT_EQ("", fs->base());
+ std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt");
+ EXPECT_EQ("bar" SLASH_STRING "baz.txt", fullPath);
+ }
+ {
+ auto fs = std::unique_ptr<TestFSSync>(new TestFSSync(SLASH_STRING));
+ EXPECT_EQ(SLASH_STRING, fs->base());
+ std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt");
+ EXPECT_EQ(SLASH_STRING "bar" SLASH_STRING "baz.txt", fullPath);
+ }
+ {
+ auto fs = std::unique_ptr<TestFSSync>(
+ new TestFSSync(SLASH_STRING "foo" SLASH_STRING));
+ EXPECT_EQ(SLASH_STRING "foo", fs->base());
+ std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt");
+ EXPECT_EQ(SLASH_STRING "foo" SLASH_STRING "bar" SLASH_STRING "baz.txt",
+ fullPath);
+ }
+ {
+ auto fs = std::unique_ptr<TestFSSync>(
+ new TestFSSync(SLASH_STRING "foo"));
+ EXPECT_EQ(SLASH_STRING "foo", fs->base());
+ std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt");
+ EXPECT_EQ(SLASH_STRING "foo" SLASH_STRING "bar" SLASH_STRING "baz.txt",
+ fullPath);
+ }
+}
+
TEST_F(DefaultFileSystemTest, WriteReadRemove)
{
WriteString("foo");
bool hasReadRun = false;
fileSystem->Read(testFileName,
[this, &hasReadRun](IFileSystem::IOBuffer&& content, const std::string& error)
{
« no previous file with comments | « src/DefaultFileSystem.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld