/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2013-2016, Regents of the University of California.
 *
 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
 *
 * ChronoShare is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * ChronoShare is distributed in the hope that it will be useful, 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 copies of the GNU General Public License along with
 * ChronoShare, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 *
 * See AUTHORS.md for complete list of ChronoShare authors and contributors.
 */

#include "fs-watcher.h"
#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/thread/thread.hpp>
#include <QtGui>
#include <fstream>
#include <iostream>
#include <set>

using namespace std;
using namespace boost;
namespace fs = boost::filesystem;

BOOST_AUTO_TEST_SUITE(TestFsWatcherDelay)

void
onChange(const fs::path& file)
{
  cerr << "onChange called" << endl;
}

void
onDelete(const fs::path& file)
{
  cerr << "onDelete called" << endl;
}

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);
  app.exec();
  sleep(100);
}

void
SlowWrite(fs::path& file)
{
  fs::ofstream off(file, std::ios::out);

  for (int i = 0; i < 10; i++) {
    off << i << endl;
    usleep(200000);
  }
}

BOOST_AUTO_TEST_CASE(TestFsWatcherDelay)
{
  fs::path dir = fs::absolute(fs::path("TestFsWatcher"));
  if (fs::exists(dir)) {
    fs::remove_all(dir);
  }

  fs::create_directory(dir);

  FsWatcher::LocalFile_Change_Callback fileChange = boost::bind(onChange, _1);
  FsWatcher::LocalFile_Change_Callback fileDelete = boost::bind(onDelete, _1);

  fs::path file = dir / "test.text";

  thread watcherThread(run, dir, fileChange, fileDelete);

  thread writeThread(SlowWrite, file);


  usleep(10000000);

  // cleanup
  if (fs::exists(dir)) {
    fs::remove_all(dir);
  }

  usleep(1000000);
}

BOOST_AUTO_TEST_SUITE_END()
