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: Changes from review Created Sept. 8, 2017, 1:09 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;
@@ -68,16 +69,67 @@
fileSystemTasks.pop_front();
}
std::list<SchedulerTask> fileSystemTasks;
FileSystemPtr fileSystem;
};
}
+#ifdef _WIN32
+#define SLASH_STRING "\\"
+#else
+#define SLASH_STRING "/"
+#endif
+
+TEST(DefaultFileSystemBasePathTest, BasePathAndResolveTest)
+{
+ 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