/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2013-2015 Regents of the University of California.
 *
 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
 *
 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * ndn-cxx library 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 Lesser General Public License for more details.
 *
 * You should have received copies of the GNU General Public License and GNU Lesser
 * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
 */

#include "util/signal.hpp"

#include "boost-test.hpp"

namespace ndn {
namespace util {
namespace signal {
namespace tests {

BOOST_AUTO_TEST_SUITE(UtilSignal)

class SignalOwner0
{
public:
  Signal<SignalOwner0> sig;

public:
  DECLARE_SIGNAL_EMIT(sig)

  bool
  isSigEmpty()
  {
    return sig.isEmpty();
  }
};

BOOST_AUTO_TEST_CASE(ZeroSlot)
{
  SignalOwner0 so;
  BOOST_CHECK_NO_THROW(so.emitSignal(sig));
}

BOOST_AUTO_TEST_CASE(TwoListeners)
{
  SignalOwner0 so;

  int hit1 = 0, hit2 = 0;
  so.sig.connect([&hit1] { ++hit1; });
  so.sig.connect([&hit2] { ++hit2; });

  so.emitSignal(sig);

  BOOST_CHECK_EQUAL(hit1, 1);
  BOOST_CHECK_EQUAL(hit2, 1);
}

class SignalOwner1
{
public:
  Signal<SignalOwner1, int> sig;

protected:
  DECLARE_SIGNAL_EMIT(sig)
};

class SignalEmitter1 : public SignalOwner1
{
public:
  void
  emitTestSignal()
  {
    this->emitSignal(sig, 8106);
  }
};

BOOST_AUTO_TEST_CASE(OneArgument)
{
  SignalEmitter1 se;

  int hit = 0;
  se.sig.connect([&hit] (int a) {
    ++hit;
    BOOST_CHECK_EQUAL(a, 8106);
  });
  se.emitTestSignal();

  BOOST_CHECK_EQUAL(hit, 1);
}

BOOST_AUTO_TEST_CASE(TwoArguments)
{
  Signal<std::remove_pointer<decltype(this)>::type, int, int> sig;

  int hit = 0;
  sig.connect([&hit] (int a, int b) {
    ++hit;
    BOOST_CHECK_EQUAL(a, 21);
    BOOST_CHECK_EQUAL(b, 22);
  });
  sig(21, 22);

  BOOST_CHECK_EQUAL(hit, 1);
}

class RefObject
{
public:
  RefObject()
  {
  }

  RefObject(const RefObject& other)
  {
    ++s_copyCount;
  }

public:
  static int s_copyCount;
};
int RefObject::s_copyCount = 0;

// Signal passes arguments by reference,
// but it also allows a handler that accept arguments by value
BOOST_AUTO_TEST_CASE(HandlerByVal)
{
  RefObject refObject;
  RefObject::s_copyCount = 0;

  Signal<std::remove_pointer<decltype(this)>::type, RefObject> sig;
  sig.connect([] (RefObject ro) {});
  sig(refObject);

  BOOST_CHECK_EQUAL(RefObject::s_copyCount, 1);
}

// Signal passes arguments by reference, and no copying
// is necessary when handler accepts arguments by reference
BOOST_AUTO_TEST_CASE(HandlerByRef)
{
  RefObject refObject;
  RefObject::s_copyCount = 0;

  Signal<std::remove_pointer<decltype(this)>::type, RefObject> sig;
  sig.connect([] (const RefObject& ro) {});
  sig(refObject);

  BOOST_CHECK_EQUAL(RefObject::s_copyCount, 0);
}

BOOST_AUTO_TEST_CASE(ManualDisconnect)
{
  SignalOwner0 so;

  int hit = 0;
  Connection c1 = so.sig.connect([&hit] { ++hit; });
  BOOST_CHECK_EQUAL(c1.isConnected(), true);

  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 1); // handler called

  Connection c2 = c1; // make a copy
  BOOST_CHECK_EQUAL(c2.isConnected(), true);
  BOOST_CHECK_EQUAL(c1.isConnected(), true);
  c2.disconnect();
  BOOST_CHECK_EQUAL(c2.isConnected(), false);
  BOOST_CHECK_EQUAL(c1.isConnected(), false);
  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 1); // handler not called

  BOOST_CHECK_NO_THROW(c2.disconnect());
  BOOST_CHECK_NO_THROW(c1.disconnect());
}

BOOST_AUTO_TEST_CASE(ManualDisconnectDestructed)
{
  unique_ptr<SignalOwner0> so(new SignalOwner0());

  int hit = 0;
  Connection connection = so->sig.connect([&hit] { ++hit; });

  so->emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 1); // handler called

  BOOST_CHECK_EQUAL(connection.isConnected(), true);
  so.reset(); // destruct Signal
  BOOST_CHECK_EQUAL(connection.isConnected(), false);
  BOOST_CHECK_NO_THROW(connection.disconnect());
}

BOOST_AUTO_TEST_CASE(AutoDisconnect)
{
  SignalOwner0 so;

  int hit = 0;
  {
    ScopedConnection sc = so.sig.connect([&hit] { ++hit; });

    BOOST_CHECK_EQUAL(sc.isConnected(), true);
    so.emitSignal(sig);
    BOOST_CHECK_EQUAL(hit, 1); // handler called

    // sc goes out of scope, disconnecting
  }

  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 1); // handler not called
}

BOOST_AUTO_TEST_CASE(AutoDisconnectAssign)
{
  SignalOwner0 so;

  int hit1 = 0, hit2 = 0;
  ScopedConnection sc = so.sig.connect([&hit1] { ++hit1; });
  BOOST_CHECK_EQUAL(sc.isConnected(), true);

  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit1, 1); // handler1 called

  sc = so.sig.connect([&hit2] { ++hit2; }); // handler1 is disconnected
  BOOST_CHECK_EQUAL(sc.isConnected(), true);

  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit1, 1); // handler1 not called
  BOOST_CHECK_EQUAL(hit2, 1); // handler2 called
}

BOOST_AUTO_TEST_CASE(AutoDisconnectAssignSame)
{
  SignalOwner0 so;

  int hit = 0;
  Connection c1 = so.sig.connect([&hit] { ++hit; });

  ScopedConnection sc(c1);
  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 1); // handler called
  BOOST_CHECK_EQUAL(c1.isConnected(), true);
  BOOST_CHECK_EQUAL(sc.isConnected(), true);

  sc = c1; // assign same connection
  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 2); // handler called
  BOOST_CHECK_EQUAL(c1.isConnected(), true);
  BOOST_CHECK_EQUAL(sc.isConnected(), true);

  Connection c2 = c1;
  sc = c2; // assign a copy of same connection
  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 3); // handler called
  BOOST_CHECK_EQUAL(c1.isConnected(), true);
  BOOST_CHECK_EQUAL(c2.isConnected(), true);
  BOOST_CHECK_EQUAL(sc.isConnected(), true);
}

BOOST_AUTO_TEST_CASE(AutoDisconnectRelease)
{
  SignalOwner0 so;

  int hit = 0;
  {
    ScopedConnection sc = so.sig.connect([&hit] { ++hit; });

    so.emitSignal(sig);
    BOOST_CHECK_EQUAL(hit, 1); // handler called
    BOOST_CHECK_EQUAL(sc.isConnected(), true);

    sc.release();
    BOOST_CHECK_EQUAL(sc.isConnected(), false);
    // sc goes out of scope, but not disconnecting
  }

  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 2); // handler called
}

BOOST_AUTO_TEST_CASE(AutoDisconnectMove)
{
  SignalOwner0 so;
  unique_ptr<ScopedConnection> sc2;

  int hit = 0;
  {
    ScopedConnection sc = so.sig.connect([&hit] { ++hit; });

    so.emitSignal(sig);
    BOOST_CHECK_EQUAL(hit, 1); // handler called
    BOOST_CHECK_EQUAL(sc.isConnected(), true);

    sc2.reset(new ScopedConnection(std::move(sc)));
    BOOST_CHECK_EQUAL(sc.isConnected(), false);
    BOOST_CHECK_EQUAL(sc2->isConnected(), true);

    // sc goes out of scope, but not disconnecting
  }

  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 2); // handler called
}

BOOST_AUTO_TEST_CASE(ConnectSingleShot)
{
  SignalOwner0 so;

  int hit = 0;
  so.sig.connectSingleShot([&hit] { ++hit; });

  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 1); // handler called

  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 1); // handler not called
}

BOOST_AUTO_TEST_CASE(ConnectSingleShotDisconnected)
{
  SignalOwner0 so;

  int hit = 0;
  Connection conn = so.sig.connectSingleShot([&hit] { ++hit; });
  BOOST_CHECK_EQUAL(conn.isConnected(), true);
  conn.disconnect();
  BOOST_CHECK_EQUAL(conn.isConnected(), false);

  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 0); // handler not called
}

BOOST_AUTO_TEST_CASE(ConnectSingleShot1)
{
  SignalEmitter1 se;

  int hit = 0;
  se.sig.connectSingleShot([&hit] (int) { ++hit; });

  se.emitTestSignal();
  BOOST_CHECK_EQUAL(hit, 1); // handler called

  se.emitTestSignal();
  BOOST_CHECK_EQUAL(hit, 1); // handler not called
}

BOOST_AUTO_TEST_CASE(ConnectInHandler)
{
  SignalOwner0 so;

  int hit1 = 0, hit2 = 0; bool hasHandler2 = false;
  so.sig.connect([&] {
    ++hit1;
    if (!hasHandler2) {
      so.sig.connect([&] { ++hit2; });
      hasHandler2 = true;
    }
  });

  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit1, 1); // handler1 called
  BOOST_CHECK_EQUAL(hit2, 0); // handler2 not called

  // new subscription takes effect
  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit1, 2); // handler1 called
  BOOST_CHECK_EQUAL(hit2, 1); // handler2 called
}

BOOST_AUTO_TEST_CASE(DisconnectSelfInHandler)
{
  SignalOwner0 so;

  int hit = 0;
  Connection connection;
  BOOST_CHECK_EQUAL(connection.isConnected(), false);
  connection = so.sig.connect(bind([] (int& hit, SignalOwner0& so, Connection& connection) {
    ++hit;
    BOOST_CHECK_EQUAL(connection.isConnected(), true);
    connection.disconnect();
    BOOST_CHECK_EQUAL(connection.isConnected(), false);
    BOOST_CHECK_EQUAL(so.isSigEmpty(), false); // disconnecting hasn't taken effect
  }, ref(hit), ref(so), ref(connection)));
  // Bug 2302, 2523: variables needs to be bound to the handler;
  // lambda capture won't work because closure would be destructed at .disconnect

  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 1); // handler called
  BOOST_CHECK_EQUAL(connection.isConnected(), false);

  // disconnecting takes effect
  BOOST_CHECK_EQUAL(so.isSigEmpty(), true);
  so.emitSignal(sig);
  BOOST_CHECK_EQUAL(hit, 1); // handler not called
}

BOOST_AUTO_TEST_CASE(ThrowInHandler)
{
  SignalOwner0 so;

  struct HandlerError : public std::exception
  {
  };

  int hit = 0;
  so.sig.connect([&] {
    ++hit;
    BOOST_THROW_EXCEPTION(HandlerError());
  });

  BOOST_CHECK_THROW(so.emitSignal(sig), HandlerError);
  BOOST_CHECK_EQUAL(hit, 1); // handler called

  BOOST_CHECK_THROW(so.emitSignal(sig), HandlerError);
  BOOST_CHECK_EQUAL(hit, 2); // handler called
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace tests
} // namespace signal
} // namespace util
} // namespace ndn
