-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: sync events can not have the same name if they are in different …
…classes (#2054) * test for sync event with same name * using full name instead of name * fix test
- Loading branch information
1 parent
d0bb9d5
commit c91308f
Showing
4 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using NUnit.Framework; | ||
|
||
|
||
namespace Mirror.Tests.RemoteAttrributeTest | ||
{ | ||
public delegate void SomeEventDelegate(int someNumber); | ||
|
||
class EventBehaviour1 : NetworkBehaviour | ||
{ | ||
[SyncEvent] | ||
public event SomeEventDelegate EventWithName; | ||
|
||
public void CallEvent(int i) | ||
{ | ||
EventWithName.Invoke(i); | ||
} | ||
} | ||
|
||
class EventBehaviour2 : NetworkBehaviour | ||
{ | ||
[SyncEvent] | ||
public event SomeEventDelegate EventWithName; | ||
|
||
[SyncEvent] | ||
public event SomeEventDelegate EventSecond; | ||
|
||
public void CallEvent(int i) | ||
{ | ||
EventWithName.Invoke(i); | ||
} | ||
} | ||
|
||
public class SyncEventSameNameTest : RemoteTestBase | ||
{ | ||
[Test] | ||
public void EventsWithSameNameCanBothBeCalled() | ||
{ | ||
EventBehaviour1 behaviour1 = CreateHostObject<EventBehaviour1>(true); | ||
EventBehaviour2 behaviour2 = CreateHostObject<EventBehaviour2>(true); | ||
|
||
const int someInt1 = 20; | ||
const int someInt2 = 21; | ||
|
||
int callCount1 = 0; | ||
int callCount2 = 0; | ||
behaviour1.EventWithName += incomingInt => | ||
{ | ||
callCount1++; | ||
Assert.That(incomingInt, Is.EqualTo(someInt1)); | ||
}; | ||
behaviour2.EventWithName += incomingInt => | ||
{ | ||
callCount2++; | ||
Assert.That(incomingInt, Is.EqualTo(someInt2)); | ||
}; | ||
|
||
behaviour1.CallEvent(someInt1); | ||
ProcessMessages(); | ||
Assert.That(callCount1, Is.EqualTo(1)); | ||
Assert.That(callCount2, Is.EqualTo(0)); | ||
|
||
behaviour2.CallEvent(someInt2); | ||
ProcessMessages(); | ||
Assert.That(callCount1, Is.EqualTo(1)); | ||
Assert.That(callCount2, Is.EqualTo(1)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.