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: Rebased. Corrected most of the review issues. Created July 4, 2017, 7:57 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,114 @@
* 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;
+using AdblockPlus::Sync;
+
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;
+
+ fileSystem->Write(testPath, content, [&sync](const std::string& error)
+ {
+ EXPECT_TRUE(error.empty());
+
+ sync.Set();
+ });
+
+ sync.WaitFor();
}
}
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)
+ {
+ EXPECT_TRUE(error.empty());
+ EXPECT_EQ("foo", content);
+
+ fileSystem->Remove(testPath, [&sync](const std::string& error)
+ {
+ EXPECT_TRUE(error.empty());
+ sync.Set();
+ });
+ });
+
+ EXPECT_TRUE(sync.WaitFor());
}
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)
+ {
+ EXPECT_TRUE(error.empty());
+ ASSERT_TRUE(result.exists);
+ ASSERT_TRUE(result.isDirectory);
+ ASSERT_FALSE(result.isFile);
+ ASSERT_NE(0, result.lastModified);
+ sync.Set();
+ });
+
+ EXPECT_TRUE(sync.WaitFor());
}
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)
+ {
+ EXPECT_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)
+ {
+ EXPECT_TRUE(error.empty());
+ fileSystem->Stat(testPath, [fileSystem, &sync, newTestPath](const IFileSystem::StatResult& result, const std::string& error)
+ {
+ EXPECT_TRUE(error.empty());
+ ASSERT_FALSE(result.exists);
+ fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](const IFileSystem::StatResult& result, const std::string& error)
+ {
+ EXPECT_TRUE(error.empty());
+ ASSERT_TRUE(result.exists);
+ fileSystem->Remove(newTestPath, [fileSystem, &sync, newTestPath](const std::string& error)
+ {
+ EXPECT_TRUE(error.empty());
+ fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](const IFileSystem::StatResult& result, const std::string& error)
+ {
+ EXPECT_TRUE(error.empty());
+ ASSERT_FALSE(result.exists);
+ sync.Set();
+ });
+ });
+ });
+ });
+ });
+ });
+
+ EXPECT_TRUE(sync.WaitFor());
}

Powered by Google App Engine
This is Rietveld