Skip to content

Commit

Permalink
Interconnect: verify signals on classes with multiple inheritance.
Browse files Browse the repository at this point in the history
Fails badly on MSVC in Release build.
  • Loading branch information
mosra committed Sep 23, 2016
1 parent 33252cb commit 1e8e9e8
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/Corrade/Interconnect/Test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ struct Test: TestSuite::Tester {

void emit();
void emitterSubclass();
void emitterMultipleInheritanceA();
void emitterMultipleInheritanceB();
void emitterMultipleInheritanceC();
void receiverSubclass();
void slotInReceiverBase();
void virtualSlot();
Expand Down Expand Up @@ -135,6 +138,9 @@ Test::Test() {

&Test::emit,
&Test::emitterSubclass,
&Test::emitterMultipleInheritanceA,
&Test::emitterMultipleInheritanceB,
&Test::emitterMultipleInheritanceC,
&Test::receiverSubclass,
&Test::slotInReceiverBase,
&Test::virtualSlot,
Expand Down Expand Up @@ -411,6 +417,76 @@ void Test::emitterSubclass() {
CORRADE_VERIFY(!postman.hasSignalConnections());
}

void Test::emitterMultipleInheritanceA() {
class Base {
int:32; /* Some padding to prevent empty base optimization */
};

/* Emitter inherited second */
struct MultiplyInherited: Base, Interconnect::Emitter {
Signal newMessage(int price, const std::string& value) {
return emit<MultiplyInherited, int, const std::string&>(&MultiplyInherited::newMessage, price, value);
}
};

MultiplyInherited postman;
Mailbox mailbox;

Interconnect::connect(postman, &MultiplyInherited::newMessage, mailbox, &Mailbox::addMessage);

postman.newMessage(5, "hello");
CORRADE_COMPARE(mailbox.messages, (std::vector<std::string>{"hello"}));
CORRADE_COMPARE(mailbox.money, 5);
}

void Test::emitterMultipleInheritanceB() {
class Base {
int:32; /* Some padding to prevent empty base optimization */
};

/* Emitter inherited first */
struct MultiplyInherited: Interconnect::Emitter, Base {
Signal newMessage(int price, const std::string& value) {
return emit(&MultiplyInherited::newMessage, price, value);
}
};

MultiplyInherited postman;
Mailbox mailbox;

Interconnect::connect(postman, &MultiplyInherited::newMessage, mailbox, &Mailbox::addMessage);

postman.newMessage(5, "hello");
CORRADE_COMPARE(mailbox.messages, (std::vector<std::string>{"hello"}));
CORRADE_COMPARE(mailbox.money, 5);
}

void Test::emitterMultipleInheritanceC() {
class Base {
int:32; /* Some padding to prevent empty base optimization */
};

/* Calling emit from a function that has different return type than Signal */
struct MultiplyInherited: Interconnect::Emitter, Base {
Signal newMessage(int price, const std::string& value) {
return emit(&MultiplyInherited::newMessage, price, value);
}

void newMessageNoReturn(int price, const std::string& value) {
emit(&MultiplyInherited::newMessage, price, value);
}
};

MultiplyInherited postman;
Mailbox mailbox;

Interconnect::connect(postman, &MultiplyInherited::newMessage, mailbox, &Mailbox::addMessage);

postman.newMessageNoReturn(5, "hello");
CORRADE_COMPARE(mailbox.messages, (std::vector<std::string>{"hello"}));
CORRADE_COMPARE(mailbox.money, 5);
}

void Test::receiverSubclass() {
class BlueMailbox: public Mailbox {
public:
Expand Down

0 comments on commit 1e8e9e8

Please sign in to comment.