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

Unified Diff: test/DefaultFileSystem.cpp

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Updated implementation. Created June 2, 2017, 3:49 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
Index: test/DefaultFileSystem.cpp
===================================================================
--- a/test/DefaultFileSystem.cpp
+++ b/test/DefaultFileSystem.cpp
@@ -14,60 +14,116 @@
* 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 <sstream>
#include <AdblockPlus.h>
#include <gtest/gtest.h>
+#include "BaseJsTest.h"
+
+using AdblockPlus::IFileSystem;
+
+
namespace
{
const std::string testPath = "libadblockplus-t\xc3\xa4st-file";
- void WriteString(AdblockPlus::FileSystem& fileSystem,
+ void WriteString(const AdblockPlus::FileSystemPtr& fileSystem,
const std::string& content)
{
- std::stringstream input;
- input << content;
- fileSystem.Write(testPath, input);
+ Sync sync;
+
+ auto input = std::make_shared<std::stringstream>();
+ *input << content;
+ fileSystem->Write(testPath, input, [&sync](const std::string& error)
+ {
+ ASSERT_TRUE(error.empty());
+
+ sync.Set();
+ });
+
+ sync.Wait();
}
}
TEST(DefaultFileSystemTest, WriteReadRemove)
{
- AdblockPlus::DefaultFileSystem fileSystem;
+ Sync sync;
+ AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem();
WriteString(fileSystem, "foo");
- std::stringstream output;
- output << fileSystem.Read(testPath)->rdbuf();
- fileSystem.Remove(testPath);
- ASSERT_EQ("foo", output.str());
+ fileSystem->Read(testPath, [fileSystem, &sync](std::string&& content, const std::string& error)
+ {
+ ASSERT_TRUE(error.empty());
+ ASSERT_EQ("foo", content);
+
+ fileSystem->Remove(testPath, [&sync](const std::string& error)
+ {
+ ASSERT_TRUE(error.empty());
+ sync.Set();
+ });
+ });
+
+ sync.Wait();
}
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);
+ Sync sync;
+ AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem();
+ fileSystem->Stat(".",
+ [fileSystem, &sync](const IFileSystem::StatResult result, const std::string& error)
+ {
+ ASSERT_TRUE(error.empty());
+ ASSERT_TRUE(result.exists);
+ ASSERT_TRUE(result.isDirectory);
+ ASSERT_FALSE(result.isFile);
+ ASSERT_NE(0, result.lastModified);
+ sync.Set();
+ });
+
+ sync.Wait();
}
TEST(DefaultFileSystemTest, WriteMoveStatRemove)
{
- AdblockPlus::DefaultFileSystem fileSystem;
+ Sync sync;
+ AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem();
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);
+
+ fileSystem->Stat(testPath,
+ [fileSystem, &sync](const IFileSystem::StatResult& result, const std::string& error)
+ {
+ ASSERT_TRUE(error.empty());
+ 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, [fileSystem, &sync, newTestPath](const std::string& error)
+ {
+ ASSERT_TRUE(error.empty());
+ fileSystem->Stat(testPath, [fileSystem, &sync, newTestPath](const IFileSystem::StatResult& result, const std::string& error)
+ {
+ ASSERT_TRUE(error.empty());
+ ASSERT_FALSE(result.exists);
+ fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](const IFileSystem::StatResult& result, const std::string& error)
+ {
+ ASSERT_TRUE(error.empty());
+ ASSERT_TRUE(result.exists);
+ fileSystem->Remove(newTestPath, [fileSystem, &sync, newTestPath](const std::string& error)
+ {
+ ASSERT_TRUE(error.empty());
+ fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](const IFileSystem::StatResult& result, const std::string& error)
+ {
+ ASSERT_TRUE(error.empty());
+ ASSERT_FALSE(result.exists);
+ sync.Set();
+ });
+ });
+ });
+ });
+ });
+ });
+
+ sync.Wait();
}
« lib/init.js ('K') | « test/BaseJsTest.cpp ('k') | test/FileSystemJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld