Update style to (almost) conform to ndn-cxx style using clang-format
diff --git a/tests/unit-tests/fs-watcher.t.cpp b/tests/unit-tests/fs-watcher.t.cpp
index e74c06a..22b1838 100644
--- a/tests/unit-tests/fs-watcher.t.cpp
+++ b/tests/unit-tests/fs-watcher.t.cpp
@@ -17,18 +17,16 @@
*
* See AUTHORS.md for complete list of ChronoShare authors and contributors.
*/
-
#include "fs-watcher.hpp"
-#include <boost/make_shared.hpp>
+#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/thread/thread.hpp>
-#include <boost/bind.hpp>
-#include <boost/lexical_cast.hpp>
+#include <QtGui>
#include <fstream>
#include <set>
-#include <QtGui>
-#include <iostream>
using namespace std;
using namespace boost;
@@ -37,45 +35,44 @@
BOOST_AUTO_TEST_SUITE(TestFsWatcher)
void
-onChange(set<string> &files, const fs::path &file)
+onChange(set<string>& files, const fs::path& file)
{
cerr << "onChange called" << endl;
files.insert(file.string());
}
void
-onDelete(set<string> &files, const fs::path &file)
+onDelete(set<string>& files, const fs::path& file)
{
files.erase(file.string());
}
-void create_file( const fs::path & ph, const std::string & contents )
+void
+create_file(const fs::path& ph, const std::string& contents)
{
- std::ofstream f( ph.string().c_str() );
- if ( !f )
- {
+ std::ofstream f(ph.string().c_str());
+ if (!f) {
abort();
}
- if ( !contents.empty() )
- {
+ if (!contents.empty()) {
f << contents;
}
}
-void run(fs::path dir, FsWatcher::LocalFile_Change_Callback c, FsWatcher::LocalFile_Change_Callback d)
+void
+run(fs::path dir, FsWatcher::LocalFile_Change_Callback c, FsWatcher::LocalFile_Change_Callback d)
{
int x = 0;
- QCoreApplication app (x, 0);
- FsWatcher watcher (dir.string().c_str(), c, d);
+ QCoreApplication app(x, 0);
+ FsWatcher watcher(dir.string().c_str(), c, d);
app.exec();
sleep(100);
}
-BOOST_AUTO_TEST_CASE (TestFsWatcher)
+BOOST_AUTO_TEST_CASE(TestFsWatcher)
{
fs::path dir = fs::absolute(fs::path("TestFsWatcher"));
- if (fs::exists(dir))
- {
+ if (fs::exists(dir)) {
fs::remove_all(dir);
}
@@ -83,7 +80,7 @@
set<string> files;
- FsWatcher::LocalFile_Change_Callback fileChange = boost::bind(onChange,ref(files), _1);
+ FsWatcher::LocalFile_Change_Callback fileChange = boost::bind(onChange, ref(files), _1);
FsWatcher::LocalFile_Change_Callback fileDelete = boost::bind(onDelete, ref(files), _1);
thread workThread(run, dir, fileChange, fileDelete);
@@ -100,8 +97,7 @@
// =========== check create a bunch of files in sub dir =============
fs::path subdir = dir / "sub";
fs::create_directory(subdir);
- for (int i = 0; i < 10; i++)
- {
+ for (int i = 0; i < 10; i++) {
string filename = boost::lexical_cast<string>(i);
create_file(subdir / filename.c_str(), boost::lexical_cast<string>(i));
}
@@ -110,18 +106,16 @@
// test.txt
// sub/0..9
BOOST_CHECK_EQUAL(files.size(), 11);
- for (int i = 0; i < 10; i++)
- {
+ for (int i = 0; i < 10; i++) {
string filename = boost::lexical_cast<string>(i);
- BOOST_CHECK(files.find("sub/" +filename) != files.end());
+ BOOST_CHECK(files.find("sub/" + filename) != files.end());
}
// ============== check copy directory with files to two levels of sub dirs =================
fs::create_directory(dir / "sub1");
fs::path subdir1 = dir / "sub1" / "sub2";
fs::copy_directory(subdir, subdir1);
- for (int i = 0; i < 5; i++)
- {
+ for (int i = 0; i < 5; i++) {
string filename = boost::lexical_cast<string>(i);
fs::copy_file(subdir / filename.c_str(), subdir1 / filename.c_str());
}
@@ -131,15 +125,13 @@
// sub/0..9
// sub1/sub2/0..4
BOOST_CHECK_EQUAL(files.size(), 16);
- for (int i = 0; i < 5; i++)
- {
+ for (int i = 0; i < 5; i++) {
string filename = boost::lexical_cast<string>(i);
BOOST_CHECK(files.find("sub1/sub2/" + filename) != files.end());
}
// =============== check remove files =========================
- for (int i = 0; i < 7; i++)
- {
+ for (int i = 0; i < 7; i++) {
string filename = boost::lexical_cast<string>(i);
fs::remove(subdir / filename.c_str());
}
@@ -148,8 +140,7 @@
// sub/7..9
// sub1/sub2/0..4
BOOST_CHECK_EQUAL(files.size(), 9);
- for (int i = 0; i < 10; i++)
- {
+ for (int i = 0; i < 10; i++) {
string filename = boost::lexical_cast<string>(i);
if (i < 7)
BOOST_CHECK(files.find("sub/" + filename) == files.end());
@@ -159,8 +150,7 @@
// =================== check remove files again, remove the whole dir this time ===================
// before remove check
- for (int i = 0; i < 5; i++)
- {
+ for (int i = 0; i < 5; i++) {
string filename = boost::lexical_cast<string>(i);
BOOST_CHECK(files.find("sub1/sub2/" + filename) != files.end());
}
@@ -169,15 +159,13 @@
BOOST_CHECK_EQUAL(files.size(), 4);
// test.txt
// sub/7..9
- for (int i = 0; i < 5; i++)
- {
+ for (int i = 0; i < 5; i++) {
string filename = boost::lexical_cast<string>(i);
BOOST_CHECK(files.find("sub1/sub2/" + filename) == files.end());
}
// =================== check rename files =======================
- for (int i = 7; i < 10; i++)
- {
+ for (int i = 7; i < 10; i++) {
string filename = boost::lexical_cast<string>(i);
fs::rename(subdir / filename.c_str(), dir / filename.c_str());
}
@@ -188,8 +176,7 @@
// 9
// sub
BOOST_CHECK_EQUAL(files.size(), 4);
- for (int i = 7; i < 10; i++)
- {
+ for (int i = 7; i < 10; i++) {
string filename = boost::lexical_cast<string>(i);
BOOST_CHECK(files.find("sub/" + filename) == files.end());
BOOST_CHECK(files.find(filename) != files.end());
@@ -197,31 +184,30 @@
create_file(dir / "add-removal-check.txt", "add-removal-check");
usleep(1200000);
- BOOST_CHECK (files.find("add-removal-check.txt") != files.end());
+ BOOST_CHECK(files.find("add-removal-check.txt") != files.end());
- fs::remove (dir / "add-removal-check.txt");
+ fs::remove(dir / "add-removal-check.txt");
usleep(1200000);
- BOOST_CHECK (files.find("add-removal-check.txt") == files.end());
+ BOOST_CHECK(files.find("add-removal-check.txt") == files.end());
create_file(dir / "add-removal-check.txt", "add-removal-check");
usleep(1200000);
- BOOST_CHECK (files.find("add-removal-check.txt") != files.end());
+ BOOST_CHECK(files.find("add-removal-check.txt") != files.end());
- fs::remove (dir / "add-removal-check.txt");
+ fs::remove(dir / "add-removal-check.txt");
usleep(1200000);
- BOOST_CHECK (files.find("add-removal-check.txt") == files.end());
+ BOOST_CHECK(files.find("add-removal-check.txt") == files.end());
create_file(dir / "add-removal-check.txt", "add-removal-check");
usleep(1200000);
- BOOST_CHECK (files.find("add-removal-check.txt") != files.end());
+ BOOST_CHECK(files.find("add-removal-check.txt") != files.end());
- fs::remove (dir / "add-removal-check.txt");
+ fs::remove(dir / "add-removal-check.txt");
usleep(1200000);
- BOOST_CHECK (files.find("add-removal-check.txt") == files.end());
+ BOOST_CHECK(files.find("add-removal-check.txt") == files.end());
// cleanup
- if (fs::exists(dir))
- {
+ if (fs::exists(dir)) {
fs::remove_all(dir);
}
}