Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sre] Add test for the multiple event handler and function override.
Signed-off-by: Stéphane Galland <galland@arakhne.org>
- Loading branch information
1 parent
58df131
commit 75629d7
Showing
4 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
...arl/io/sarl/sre/tests/runtime/internal/eventguard/BehaviorGuardEvaluatorRegistryTest.sarl
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,69 @@ | ||
/* | ||
* $Id$ | ||
* | ||
* SARL is an general-purpose agent programming language. | ||
* More details on http://www.sarl.io | ||
* | ||
* Copyright (C) 2014-2020 the original authors or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sarl.sre.tests.runtime.internal.eventguard | ||
|
||
import io.sarl.sre.tests.runtime.internal.eventguard.mocks.Agent1 | ||
import io.sarl.sre.tests.testutils.^extension.PropertyRestoreExtension | ||
import io.sarl.sre.tests.testutils.^extension.SreRunContext | ||
import io.sarl.sre.tests.testutils.^extension.SreRunExtension | ||
import io.sarl.tests.api.extensions.ContextInitExtension | ||
import io.sarl.tests.api.extensions.JavaVersionCheckExtension | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Tag | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.^extension.ExtendWith | ||
|
||
import static io.sarl.sre.tests.testutils.Constants.* | ||
|
||
import static extension io.sarl.tests.api.tools.TestAssertions.* | ||
import static extension org.junit.jupiter.api.Assertions.* | ||
|
||
/** | ||
* @author $Author: sgalland$ | ||
* @version $FullVersion$ | ||
* @mavengroupid $GroupId$ | ||
* @mavenartifactid $ArtifactId$ | ||
*/ | ||
@ExtendWith(#[ | ||
typeof(ContextInitExtension), | ||
typeof(JavaVersionCheckExtension), | ||
typeof(PropertyRestoreExtension), | ||
typeof(SreRunExtension) | ||
]) | ||
@DisplayName("run: event and function overriding test") | ||
@Tag("run") | ||
class BehaviorGuardEvaluatorRegistryTest { | ||
|
||
@Test | ||
@DisplayName("Override of event handler and action") | ||
def overrideOfEventHanderAndMethod(extension rc : SreRunContext) { | ||
typeof(Agent1).runSre(null, true, STANDARD_TIMEOUT) | ||
|
||
var all = allResults | ||
2.assertEquals(all.size) | ||
|
||
// These is two data into the results because there is 2 "on Event0". | ||
// The data are the same because of the function overriding. | ||
all.assertContains("myfunction in Agent1", "myfunction in Agent1") | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...oject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/eventguard/mocks/Agent0.sarl
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,51 @@ | ||
/* | ||
* $Id$ | ||
* | ||
* SARL is an general-purpose agent programming language. | ||
* More details on http://www.sarl.io | ||
* | ||
* Copyright (C) 2014-2020 the original authors or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sarl.sre.tests.runtime.internal.eventguard.mocks | ||
|
||
import io.sarl.sre.tests.testutils.agents.TestingAgent | ||
import io.sarl.core.DefaultContextInteractions | ||
import io.sarl.core.Schedules | ||
import io.sarl.core.Lifecycle | ||
|
||
abstract agent Agent0 extends TestingAgent { | ||
|
||
uses DefaultContextInteractions, Schedules, Lifecycle | ||
|
||
def runAgentTest : RunPolicy { | ||
in(1000) [ | ||
new Event0().emit | ||
] | ||
in(2000) [ | ||
killMe | ||
] | ||
return RunPolicy::STANDARD | ||
} | ||
|
||
def myfunction : void { | ||
addResult("myfunction in Agent0") | ||
} | ||
|
||
on Event0 { | ||
myfunction | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...oject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/eventguard/mocks/Agent1.sarl
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,36 @@ | ||
/* | ||
* $Id$ | ||
* | ||
* SARL is an general-purpose agent programming language. | ||
* More details on http://www.sarl.io | ||
* | ||
* Copyright (C) 2014-2020 the original authors or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sarl.sre.tests.runtime.internal.eventguard.mocks | ||
|
||
import io.sarl.sre.tests.testutils.agents.TestingAgent.RunPolicy | ||
|
||
agent Agent1 extends Agent0 { | ||
|
||
override myfunction : void { | ||
addResult("myfunction in Agent1") | ||
} | ||
|
||
on Event0 { | ||
myfunction | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...oject.tests/src/test/sarl/io/sarl/sre/tests/runtime/internal/eventguard/mocks/Event0.sarl
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,24 @@ | ||
/* | ||
* $Id$ | ||
* | ||
* SARL is an general-purpose agent programming language. | ||
* More details on http://www.sarl.io | ||
* | ||
* Copyright (C) 2014-2020 the original authors or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sarl.sre.tests.runtime.internal.eventguard.mocks | ||
|
||
event Event0 |