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

Unified Diff: test/DefaultFileSystem.cpp

Issue 10296001: Implement File API (Closed)
Patch Set: Addressed all remaining issues Created April 16, 2013, 11:55 a.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
Index: test/DefaultFileSystem.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/DefaultFileSystem.cpp
@@ -0,0 +1,56 @@
+#include <AdblockPlus.h>
+#include <gtest/gtest.h>
+
+#include "../src/Utils.h"
+
+namespace
+{
+ const std::string testPath = "libadblockplus-test-file";
+
+ void WriteString(AdblockPlus::FileSystem& fileSystem,
+ const std::string& content)
+ {
+ std::tr1::shared_ptr<std::stringstream> input(new std::stringstream);
+ *input << content;
+ fileSystem.Write(testPath, input);
+ }
+}
+
+TEST(DefaultFileSystemTest, WriteReadRemove)
+{
+ AdblockPlus::DefaultFileSystem fileSystem;
+ WriteString(fileSystem, "foo");
+ std::string output = AdblockPlus::Utils::Slurp(*fileSystem.Read(testPath));
+ fileSystem.Remove(testPath);
+ ASSERT_EQ("foo", output);
+}
+
+TEST(DefaultFileSystemTest, StatWorkingDirectory)
+{
+ AdblockPlus::DefaultFileSystem fileSystem;
+ const AdblockPlus::FileSystem::StatResult result = fileSystem.Stat(".");
+ ASSERT_TRUE(result.exists);
+ ASSERT_TRUE(result.isDirectory);
+ ASSERT_FALSE(result.isFile);
+ ASSERT_NE(0, result.lastModified);
+}
+
+TEST(DefaultFileSystemTest, WriteMoveStatRemove)
+{
+ AdblockPlus::DefaultFileSystem fileSystem;
+ WriteString(fileSystem, "foo");
+ AdblockPlus::FileSystem::StatResult result = fileSystem.Stat(testPath);
+ ASSERT_TRUE(result.exists);
+ ASSERT_TRUE(result.isFile);
+ ASSERT_FALSE(result.isDirectory);
+ ASSERT_NE(0, result.lastModified);
+ const std::string newTestPath = testPath + "-new";
+ fileSystem.Move(testPath, newTestPath);
+ result = fileSystem.Stat(testPath);
+ ASSERT_FALSE(result.exists);
+ result = fileSystem.Stat(newTestPath);
+ ASSERT_TRUE(result.exists);
+ fileSystem.Remove(newTestPath);
+ result = fileSystem.Stat(newTestPath);
+ ASSERT_FALSE(result.exists);
+}
« src/FileSystemJsObject.cpp ('K') | « src/Utils.cpp ('k') | test/FileSystemJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld