Ejemplo n.º 1
0
// profile time for emission with 4 slots, 2 in group 0 and 2 in group 1
static void benchSignalEmissionGroups()
{
	Signal<void ( void*, uint64_t )> sigIncrement;
	sigIncrement.connect( testCounterAdd2 );
	sigIncrement.connect( testCounterAdd2 );
	sigIncrement.connect( 1, testCounterAdd2 );
	sigIncrement.connect( 1, testCounterAdd2 );

	const uint64_t startCounter = TestCounter::get();
	const uint64_t benchStart = timestampBenchmark();

	uint64_t i;
	for( i = 0; i < 1000000; i++ )
		sigIncrement.emit( nullptr, 1 );

	const uint64_t benchDone = timestampBenchmark();
	const uint64_t endCounter = TestCounter::get();

	assert( endCounter - startCounter == ( i * 4 ) );

	cout << "OK" << endl;
	cout << "\tper emission: " << double( benchDone - benchStart ) / double( i ) << "ns"
	<< ", per slot: " << double( benchDone - benchStart ) / double( i * 4 ) << "ns"
	<< endl;
}
Ejemplo n.º 2
0
TEST(core_signal_test, empty_slot_is_not_same_as_no_slot) {
  Signal signal;

  signal.connect();
  ASSERT_EQ(1u, signal.size());

  signal.connect(Signal::Slot());
  ASSERT_EQ(2u, signal.size());
}
Ejemplo n.º 3
0
TEST(core_signal_test, executing_signal_actually_works_for_all_of_them) {
  Signal signal;
  int a = 0, b = 0;

  signal.connect([&a](int _i) { a = _i; });
  signal.connect([&b](int _i) { b = _i + 1; });

  signal(5);

  ASSERT_EQ(2u, signal.size());
  ASSERT_EQ(5, a);
  ASSERT_EQ(6, b);
}
Ejemplo n.º 4
0
Archivo: main.cpp Proyecto: CCJY/coliru
int main()
{  
    Signal<void(int)> signal;
    signal.connect(anyFunc);

    signal.connect(
          [] (int num) {
             // TODO: Implement handler logic here.
          }
    );
    signal.emit( 0 );
    
    return 0;
}
Ejemplo n.º 5
0
TEST(SignalTest, SignalBase) {
	unsigned counter = 0;
	auto f = [&counter]() { ++counter; };

	Signal<> sig;

	sig();
	ASSERT_EQ(0, counter);

	ConnectionRef c0 = sig.connect(f);
	ASSERT_EQ(0, counter);
	ASSERT_TRUE(c0.isValid());
	ASSERT_TRUE(c0.isConnected());

	sig();
	ASSERT_EQ(1, counter);
	ASSERT_TRUE(c0.isValid());
	ASSERT_TRUE(c0.isConnected());

	ConnectionRef c1 = sig.connect(f);
	ASSERT_EQ(1, counter);
	ASSERT_TRUE(c0.isValid());
	ASSERT_TRUE(c0.isConnected());
	ASSERT_TRUE(c1.isValid());
	ASSERT_TRUE(c1.isConnected());

	sig();
	ASSERT_EQ(3, counter);
	ASSERT_TRUE(c0.isValid());
	ASSERT_TRUE(c0.isConnected());
	ASSERT_TRUE(c1.isValid());
	ASSERT_TRUE(c1.isConnected());

	c1.disconnect();
	ASSERT_EQ(3, counter);
	ASSERT_TRUE(c0.isValid());
	ASSERT_TRUE(c0.isConnected());
	ASSERT_TRUE(c1.isValid());
	ASSERT_FALSE(c1.isConnected());

	sig();
	ASSERT_EQ(4, counter);
	ASSERT_TRUE(c0.isValid());
	ASSERT_TRUE(c0.isConnected());
	ASSERT_TRUE(c1.isValid());
	ASSERT_FALSE(c1.isConnected());
}
Ejemplo n.º 6
0
TEST(core_signal_test, can_add_and_execute_free_function) {
  Signal signal;

  signal.connect(&Foo);
  ASSERT_EQ(5, foo);

  signal(10);
  ASSERT_EQ(10, foo);
}
Ejemplo n.º 7
0
TEST(SignalTest, DisconnectAll) {
	unsigned counter = 0;
	auto f = [&counter]() { ++counter; };

	Signal<> sig;

	sig.connect(f);
	sig.connect(f);
	sig.connect(f);

	sig();
	ASSERT_EQ(3, counter);

	sig.disconnectAll();

	sig();
	ASSERT_EQ(3, counter);
}
Ejemplo n.º 8
0
TEST(core_signal_test, can_add_and_execute_static_method) {
  Signal signal;

  signal.connect(&TestStruct::Foo);
  ASSERT_EQ(1, TestStruct::foo);

  signal(4);
  ASSERT_EQ(4, TestStruct::foo);
}
Ejemplo n.º 9
0
TEST(core_signal_test, can_add_and_execute_method_with_additional_parameter) {
  Signal signal;
  TestStruct testStruct;

  signal.connect(&TestStruct::Boo2, &testStruct, std::placeholders::_1, 5);
  ASSERT_EQ(2, testStruct.boo2);

  signal(9);
  ASSERT_EQ(14, testStruct.boo2);
}
Ejemplo n.º 10
0
TEST(core_signal_test,
     add_and_execute_static_method_with_additional_parameter) {
  Signal signal;

  signal.connect(TestStruct::Foo2, 8, std::placeholders::_1);
  ASSERT_EQ(1, TestStruct::foo2);

  signal(4);
  ASSERT_EQ(12, TestStruct::foo2);
}
Ejemplo n.º 11
0
TEST(core_signal_test,
     add_and_execute_free_function_with_additional_parameter) {
  Signal signal;

  signal.connect(&Foo2, 4, std::placeholders::_1);
  ASSERT_EQ(5, foo2);

  signal(10);
  ASSERT_EQ(14, foo2);
}
Ejemplo n.º 12
0
TEST(core_signal_test, can_add_and_execute_method) {
  Signal signal;
  TestStruct testStruct;

  signal.connect(&TestStruct::Boo, &testStruct, std::placeholders::_1);
  ASSERT_EQ(2, testStruct.boo);

  signal(9);
  ASSERT_EQ(9, testStruct.boo);
}
Ejemplo n.º 13
0
TEST(core_signal_test, clear_erases_all_slots) {
  Signal signal;

  signal.connect([](int) {});
  signal.connect([](int) {});
  ASSERT_EQ(2u, signal.size());

  signal.clear();
  ASSERT_EQ(0u, signal.size());
}
Ejemplo n.º 14
0
int main() {
    Signal<void()> sig;

    HelloWorld hello;
    sig.connect(hello);

    sig();

    return 0;
}
Ejemplo n.º 15
0
int main(int argc, char const *argv[])
{
    Signal<void(int)> mySignal;
    Foobar f;

    int lol = 5;

    Connection myConnection = mySignal.connect( std::bind(&Foobar::doSomething, &f , std::placeholders::_1) );
    mySignal.connect( [](int stuff) { std::cout << "lambda did stuff " << stuff << std::endl;  } );

    mySignal.notify(1337);

    std::cout << myConnection.getId() << std::endl;
    myConnection.disconnect();
    std::cout << myConnection.getId() << std::endl;

    mySignal.notify(7331);

    return 0;
}
Ejemplo n.º 16
0
TEST(SignalTest, BlockConnect) {
	unsigned counter = 0;
	auto f = [&counter]() { ++counter; };

	Signal<> sig;

	{
		sig.connect(f);
	}

	sig();
	ASSERT_EQ(1, counter);
}
Ejemplo n.º 17
0
    //________________________________________________________
    void SignalHandler::connect( GObject* object, const std::string& signal, GCallback callback, gpointer data )
    {
        // check if object is already connected
        if( _objects.find( object ) == _objects.end() )
        {

            // insert object
            _objects.insert( object );

            // insert destroy signal
            Signal destroyId;
            destroyId.connect( object, "destroy", (GCallback) destroyNotifyEvent, this );
            _signals.push_back( destroyId );

        }

        // insert signal
        Signal signalId;
        signalId.connect( object, signal, callback, data );
        _signals.push_back( signalId );

    }
Ejemplo n.º 18
0
Handle<Value> Signal_Connect(const Arguments& args)
{
    HandleScope handle_scope;

    Signal* self = GetPtr(args.This());
    assert(self);

    if ((args.Length() == 2) && args[0]->IsObject() && args[1]->IsFunction())
    {
        self->connect(Persistent<Object>::New(args[0]->ToObject()),
                      Persistent<Object>::New(args[1]->ToObject()));
    }
    else if ((args.Length() == 1) && args[0]->IsFunction())
    {
        self->connect(Persistent<Object>::New(args[0]->ToObject()));
    }
    else
    {
        return ThrowException(String::New("Invalid parameters, valid syntax:\nconnect(object, function)\nconnect(function)"));
    }

    return Handle<Value>();
}
Ejemplo n.º 19
0
    //____________________________________________________________________________________________
    bool Animations::registerWidget( GtkWidget* widget )
    {

        if( _allWidgets.find( widget ) != _allWidgets.end() ) return false;

        #if OXYGEN_DEBUG
        std::cerr << "Oxygen::Animations::registerWidget - " << widget << " (" << (widget ? G_OBJECT_TYPE_NAME( widget ):"0x0") << ")" << std::endl;
        #endif

        Signal destroyId;
        destroyId.connect( G_OBJECT( widget ), "destroy", G_CALLBACK( destroyNotifyEvent ), this );
        _allWidgets.insert( std::make_pair( widget, destroyId ) );
        return true;

    }
Ejemplo n.º 20
0
TEST(SignalTest, SlotTracker) {
	unsigned counter = 0;
	auto f = [&counter]() { ++counter; };

	Signal<> sig;

	ConnectionRef c0;
	{
		SlotTracker tracker;
		c0 = sig.connect(f).track(tracker);

		sig();
		ASSERT_EQ(1, counter);
	}
	ASSERT_TRUE(c0.isValid());
	ASSERT_FALSE(c0.isConnected());

	sig();
	ASSERT_EQ(1, counter);
}
  void benchmark_invocation(unsigned num_connections)
{
  static const unsigned num_invocations = 1000000;

  Signal signal;
  std::cout << num_connections << " connections, invoking " << num_invocations << " times: ";
  unsigned n;
  for(n = 0; n < num_connections; ++n)
  {
    signal.connect(myslot());
  }
  {
    boost::progress_timer timer;
    unsigned i;
    for(i = 0; i < num_invocations; ++i)
    {
      signal(0);
    }
  }
}
  void benchmark_connect_disconnect()
{
  static const unsigned num_connections = 1000000;
  std::vector<typename connection_type<Signal>::type> connections(num_connections);

  Signal signal;
  std::cout << "connecting " << num_connections << " connections then disconnecting: ";
  unsigned n;
  {
    boost::progress_timer timer;
    for(n = 0; n < num_connections; ++n)
    {
      connections.at(n) = signal.connect(myslot());
    }
    for(n = 0; n < num_connections; ++n)
    {
      connections.at(n).disconnect();
    }
  }
}
Ejemplo n.º 23
0
TEST(SignalTest, ConnectionOwn) {
	unsigned counter = 0;
	auto f = [&counter]() { ++counter; };

	Signal<> sig;

	ConnectionRef c0;
	{
		ConnectionRef tmp = sig.connect(f);
		tmp.own();
		c0 = tmp;
		ASSERT_TRUE(tmp.isOwning());
		ASSERT_FALSE(c0.isOwning());

		sig();
		ASSERT_EQ(1, counter);
	}
	ASSERT_TRUE(c0.isValid());
	ASSERT_FALSE(c0.isConnected());

	sig();
	ASSERT_EQ(1, counter);
}
Ejemplo n.º 24
0
		int main(int argc, char **argv) {
			Signal<int(int)> sig;

			Test("disconnect non existing");
			{
				bool res;
				res = sig.disconnect(0);
				ASSERT(!res);
			}

			Test("connect");
			size_t id = sig.connect(Util::dummy);

			Test("single connection: check result");
			const int input = 100;
			auto numVal = sig.emit(input);
			auto val = sig.results();
			ASSERT(numVal == val->size());
			ASSERT(val->size() == 1);
			ASSERT((*val)[0] == Util::dummy(input));

			Test("multiple connections: check results");
			size_t id2 = sig.connect(dummy2);
			size_t id3 = sig.connect(Util::dummy);
			size_t id4 = sig.connect(dummy2);
			numVal = sig.emit(input);
			val = sig.results();
			ASSERT(numVal == val->size());
			ASSERT(val->size() == 4);
			ASSERT((*val)[0] == Util::dummy(input));
			ASSERT((*val)[1] == dummy2(input));
			ASSERT((*val)[2] == Util::dummy(input));
			ASSERT((*val)[3] == dummy2(input));

			Test("multiple connections: ask results again");
			auto val2 = sig.results();
			ASSERT(numVal == val2->size());
			ASSERT(val2->size() == 4);
			ASSERT((*val2)[0] == Util::dummy(input));
			ASSERT((*val2)[1] == dummy2(input));
			ASSERT((*val2)[2] == Util::dummy(input));
			ASSERT((*val2)[3] == dummy2(input));

			Test("disconnections");
			{
				bool res;
				res = sig.disconnect(id2);
				ASSERT(res);

				res = sig.disconnect(id);
				ASSERT(res);

				//disconnect again
				res = sig.disconnect(id);
				ASSERT(!res);

				//wrong id
				res = sig.disconnect(id + 1);
				ASSERT(!res);
			}

			return 0;
		}