-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1939 Duplicate call detector test cases.
- Loading branch information
Dennis Sheirer
committed
Sep 4, 2024
1 parent
e6a8048
commit 0cee16e
Showing
6 changed files
with
220 additions
and
14 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
30 changes: 30 additions & 0 deletions
30
src/main/java/io/github/dsheirer/preference/duplicate/ICallManagementProvider.java
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,30 @@ | ||
/* | ||
* ***************************************************************************** | ||
* Copyright (C) 2014-2024 Dennis Sheirer | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* **************************************************************************** | ||
*/ | ||
|
||
package io.github.dsheirer.preference.duplicate; | ||
|
||
/** | ||
* Interface for a call management value provider. | ||
*/ | ||
public interface ICallManagementProvider | ||
{ | ||
boolean isDuplicateCallDetectionEnabled(); | ||
boolean isDuplicateCallDetectionByTalkgroupEnabled(); | ||
boolean isDuplicateCallDetectionByRadioEnabled(); | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/io/github/dsheirer/preference/duplicate/TestCallManagementProvider.java
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,58 @@ | ||
/* | ||
* ***************************************************************************** | ||
* Copyright (C) 2014-2024 Dennis Sheirer | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* **************************************************************************** | ||
*/ | ||
|
||
package io.github.dsheirer.preference.duplicate; | ||
|
||
/** | ||
* Test implementation of duplicate call detection preferences. | ||
*/ | ||
public class TestCallManagementProvider implements ICallManagementProvider | ||
{ | ||
private final boolean mByTalkgroup; | ||
private final boolean mByRadio; | ||
|
||
/** | ||
* Constructs an instance | ||
* @param byTalkgroup to enable duplicate detection by talkgroup | ||
* @param byRadio to enable duplicate detection by radio | ||
*/ | ||
public TestCallManagementProvider(boolean byTalkgroup, boolean byRadio) | ||
{ | ||
mByTalkgroup = byTalkgroup; | ||
mByRadio = byRadio; | ||
} | ||
|
||
@Override | ||
public boolean isDuplicateCallDetectionEnabled() | ||
{ | ||
return mByTalkgroup || mByRadio; | ||
} | ||
|
||
@Override | ||
public boolean isDuplicateCallDetectionByTalkgroupEnabled() | ||
{ | ||
return mByTalkgroup; | ||
} | ||
|
||
@Override | ||
public boolean isDuplicateCallDetectionByRadioEnabled() | ||
{ | ||
return mByRadio; | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
src/test/java/io/github/dsheirer/audio/DuplicateCallDetectionTest.java
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,106 @@ | ||
/* | ||
* ***************************************************************************** | ||
* Copyright (C) 2014-2024 Dennis Sheirer | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* **************************************************************************** | ||
*/ | ||
|
||
package io.github.dsheirer.audio; | ||
|
||
import io.github.dsheirer.alias.AliasList; | ||
import io.github.dsheirer.identifier.Identifier; | ||
import io.github.dsheirer.identifier.Role; | ||
import io.github.dsheirer.identifier.configuration.SiteConfigurationIdentifier; | ||
import io.github.dsheirer.identifier.configuration.SystemConfigurationIdentifier; | ||
import io.github.dsheirer.module.decode.p25.identifier.radio.APCO25RadioIdentifier; | ||
import io.github.dsheirer.module.decode.p25.identifier.talkgroup.APCO25Talkgroup; | ||
import io.github.dsheirer.preference.duplicate.ICallManagementProvider; | ||
import io.github.dsheirer.preference.duplicate.TestCallManagementProvider; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class DuplicateCallDetectionTest | ||
{ | ||
@Test | ||
void sameCallOnDifferentSites() | ||
{ | ||
AliasList aliasList = new AliasList("test"); | ||
AudioSegment audioSegment1 = new AudioSegment(aliasList, 1); | ||
audioSegment1.addIdentifier(SystemConfigurationIdentifier.create("Test System")); | ||
audioSegment1.addIdentifier(SiteConfigurationIdentifier.create("Test Site 1")); | ||
audioSegment1.addIdentifier(APCO25Talkgroup.create(1)); | ||
audioSegment1.addIdentifier(APCO25RadioIdentifier.createFrom(2)); | ||
|
||
AudioSegment audioSegment2 = new AudioSegment(aliasList, 2); | ||
audioSegment2.addIdentifier(SystemConfigurationIdentifier.create("Test System")); | ||
audioSegment2.addIdentifier(SiteConfigurationIdentifier.create("Test Site 2")); | ||
audioSegment2.addIdentifier(APCO25Talkgroup.create(1)); | ||
audioSegment2.addIdentifier(APCO25RadioIdentifier.createFrom(2)); | ||
|
||
boolean testByTalkgroup = true; | ||
boolean testByRadio = false; | ||
ICallManagementProvider provider = new TestCallManagementProvider(testByTalkgroup, testByRadio); | ||
DuplicateCallDetector.SystemDuplicateCallDetector detector = new DuplicateCallDetector.SystemDuplicateCallDetector(provider); | ||
|
||
List<Identifier> to1 = audioSegment1.getIdentifierCollection().getIdentifiers(Role.TO); | ||
List<Identifier> to2 = audioSegment2.getIdentifierCollection().getIdentifiers(Role.TO); | ||
//Test for duplicate by TO identifiers | ||
assertTrue(DuplicateCallDetector.SystemDuplicateCallDetector.isDuplicate(to1, to2), "TO identifiers should be equivalent"); | ||
|
||
List<Identifier> from1 = audioSegment1.getIdentifierCollection().getIdentifiers(Role.FROM); | ||
List<Identifier> from2 = audioSegment2.getIdentifierCollection().getIdentifiers(Role.FROM); | ||
//Test for duplicate by FROM identifiers | ||
assertTrue(DuplicateCallDetector.SystemDuplicateCallDetector.isDuplicate(from1, from2), "FROM identifiers should be equivalent"); | ||
} | ||
|
||
/** | ||
* Test: same call, same site, same source radio, simulcasting to two different talkgroups. | ||
*/ | ||
@Test | ||
void sameCallSameSiteSameRadioSimulcastToDifferentTalkgroups() | ||
{ | ||
AliasList aliasList = new AliasList("test"); | ||
|
||
AudioSegment audioSegment1 = new AudioSegment(aliasList, 1); | ||
audioSegment1.addIdentifier(SystemConfigurationIdentifier.create("Test System")); | ||
audioSegment1.addIdentifier(SiteConfigurationIdentifier.create("Test Site 1")); | ||
audioSegment1.addIdentifier(APCO25Talkgroup.create(1)); | ||
audioSegment1.addIdentifier(APCO25RadioIdentifier.createFrom(2)); | ||
|
||
AudioSegment audioSegment2 = new AudioSegment(aliasList, 2); | ||
audioSegment2.addIdentifier(SystemConfigurationIdentifier.create("Test System")); | ||
audioSegment2.addIdentifier(SiteConfigurationIdentifier.create("Test Site 1")); | ||
audioSegment2.addIdentifier(APCO25Talkgroup.create(2)); | ||
audioSegment2.addIdentifier(APCO25RadioIdentifier.createFrom(2)); | ||
|
||
boolean testByTalkgroup = true; | ||
boolean testByRadio = true; | ||
ICallManagementProvider provider = new TestCallManagementProvider(testByTalkgroup, testByRadio); | ||
DuplicateCallDetector.SystemDuplicateCallDetector detector = new DuplicateCallDetector.SystemDuplicateCallDetector(provider); | ||
|
||
List<Identifier> to1 = audioSegment1.getIdentifierCollection().getIdentifiers(Role.TO); | ||
List<Identifier> to2 = audioSegment2.getIdentifierCollection().getIdentifiers(Role.TO); | ||
//Test for duplicate by TO identifiers | ||
assertFalse(DuplicateCallDetector.SystemDuplicateCallDetector.isDuplicate(to1, to2), "TO identifiers should not be equivalent"); | ||
|
||
List<Identifier> from1 = audioSegment1.getIdentifierCollection().getIdentifiers(Role.FROM); | ||
List<Identifier> from2 = audioSegment2.getIdentifierCollection().getIdentifiers(Role.FROM); | ||
//Test for duplicate by FROM identifiers | ||
assertTrue(DuplicateCallDetector.SystemDuplicateCallDetector.isDuplicate(from1, from2), "FROM identifiers should be equivalent"); | ||
} | ||
} |