Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/issue_1729
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Kast committed Sep 27, 2021
2 parents 196d96e + 6834f99 commit 1e85ab2
Show file tree
Hide file tree
Showing 47 changed files with 5,612 additions and 3,640 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public void testClone() {
}

public static boolean equalTest(SdlArtwork original, SdlArtwork clone) {
if (original == null && clone == null) {
return true;
}

assertNotNull(original);
assertNotNull(clone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ public void testInstantiation() {
assertNull(screenManager.getTextField2Type());
assertNull(screenManager.getTextField3Type());
assertNull(screenManager.getTextField4Type());
assertNull(screenManager.getMenu());
assertTrue(screenManager.getMenu().isEmpty());
assertNull(screenManager.getVoiceCommands());
assertTrue(screenManager.getSoftButtonObjects().isEmpty());
assertNull(screenManager.getSoftButtonObjectByName("test"));
assertNull(screenManager.getSoftButtonObjectById(1));
assertEquals(screenManager.getDynamicMenuUpdatesMode(), DynamicMenuUpdatesMode.ON_WITH_COMPAT_MODE);
assertEquals(screenManager.getState(), BaseSubManager.READY);
assertNull(screenManager.getMenuConfiguration());
assertNull(screenManager.getMenuConfiguration().getMenuLayout());
assertNull(screenManager.getMenuConfiguration().getSubMenuLayout());
}

@Test
Expand Down Expand Up @@ -147,10 +148,9 @@ public void testSetMenuManagerFields() {
screenManager.setMenu(TestValues.GENERAL_MENUCELL_LIST);
screenManager.setMenuConfiguration(TestValues.GENERAL_MENU_CONFIGURATION);

assertEquals(screenManager.getMenu(), TestValues.GENERAL_MENUCELL_LIST);
assertEquals(screenManager.getDynamicMenuUpdatesMode(), DynamicMenuUpdatesMode.FORCE_ON);
// Should not set because of improper RAI response and improper HMI states
assertNull(screenManager.getMenuConfiguration());
assertEquals(screenManager.getMenu(), TestValues.GENERAL_MENUCELL_LIST);
assertEquals(screenManager.getMenuConfiguration(), TestValues.GENERAL_MENU_CONFIGURATION);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void testSettersAndGetters() {
choiceCell.setVoiceCommands(TestValues.GENERAL_STRING_LIST);
choiceCell.setArtwork(artwork);
choiceCell.setSecondaryArtwork(artwork);
choiceCell.setUniqueText(TestValues.GENERAL_STRING);
choiceCell.setUniqueTextId(TestValues.GENERAL_INT);

// use getters and assert equality
assertEquals(choiceCell.getText(), TestValues.GENERAL_STRING);
Expand All @@ -71,7 +71,7 @@ public void testSettersAndGetters() {
assertEquals(choiceCell.getArtwork(), artwork);
assertEquals(choiceCell.getSecondaryArtwork(), artwork);
assertEquals(choiceCell.getChoiceId(), MAX_ID);
assertEquals(choiceCell.getUniqueText(), TestValues.GENERAL_STRING);
assertEquals(choiceCell.getUniqueTextId(), TestValues.GENERAL_INTEGER);
}

@Test
Expand Down Expand Up @@ -121,14 +121,27 @@ public void testCellEquality() {
choiceCell3.setSecondaryText(TestValues.GENERAL_STRING);
choiceCell3.setTertiaryText(TestValues.GENERAL_STRING);

//UniqueText should not be taken into consideration when checking equality
choiceCell.setUniqueText(TestValues.GENERAL_STRING);
choiceCell2.setUniqueText(TestValues.GENERAL_STRING);
choiceCell3.setUniqueText(TestValues.GENERAL_STRING);

// Make sure our overridden method works, even though these are different objects in memory
assertTrue(choiceCell.equals(choiceCell2));
assertFalse(choiceCell.equals(choiceCell3));

}

@Test
public void testGetUniqueCellText() {
ChoiceCell choiceCell = new ChoiceCell("Test");
ChoiceCell choiceCell2 = new ChoiceCell("Test");
choiceCell2.setUniqueTextId(2);
ChoiceCell choiceCell3 = new ChoiceCell("Test");
choiceCell3.setUniqueTextId(3);

assertEquals((int) choiceCell.getUniqueTextId(), 1);
assertEquals(choiceCell.getUniqueText(), "Test");

assertEquals((int) choiceCell2.getUniqueTextId(), 2);
assertEquals(choiceCell2.getUniqueText(), "Test (2)");

assertEquals((int) choiceCell3.getUniqueTextId(), 3);
assertEquals(choiceCell3.getUniqueText(), "Test (3)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,21 @@

import com.livio.taskmaster.Taskmaster;
import com.smartdevicelink.managers.BaseSubManager;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.managers.ISdl;
import com.smartdevicelink.managers.file.FileManager;
import com.smartdevicelink.proxy.rpc.ImageField;
import com.smartdevicelink.proxy.rpc.KeyboardCapabilities;
import com.smartdevicelink.proxy.rpc.KeyboardLayoutCapability;
import com.smartdevicelink.proxy.rpc.KeyboardProperties;
import com.smartdevicelink.proxy.rpc.SdlMsgVersion;
import com.smartdevicelink.proxy.rpc.TextField;
import com.smartdevicelink.proxy.rpc.WindowCapability;
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
import com.smartdevicelink.proxy.rpc.enums.ImageFieldName;
import com.smartdevicelink.proxy.rpc.enums.KeyboardInputMask;
import com.smartdevicelink.proxy.rpc.enums.KeyboardLayout;
import com.smartdevicelink.proxy.rpc.enums.KeypressMode;
import com.smartdevicelink.proxy.rpc.enums.Language;
import com.smartdevicelink.proxy.rpc.enums.SystemContext;
import com.smartdevicelink.proxy.rpc.enums.TextFieldName;
import com.smartdevicelink.proxy.rpc.enums.TriggerSource;
import com.smartdevicelink.test.TestValues;

import org.junit.After;
import org.junit.Before;
Expand All @@ -68,13 +64,10 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNotSame;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue;
import static org.mockito.Mockito.doReturn;
Expand Down Expand Up @@ -103,16 +96,12 @@ public void setUp() throws Exception {
assertEquals(csm.getState(), BaseSubManager.SETTING_UP);
assertEquals(csm.currentSystemContext, SystemContext.SYSCTXT_MAIN);
assertEquals(csm.currentHMILevel, HMILevel.HMI_NONE);
assertEquals(csm.choiceCellIdMin, 1);
assertEquals(csm.nextChoiceId, 1);
assertFalse(csm.isVROptional);
assertNotNull(csm.fileManager);
assertNotNull(csm.preloadedChoices);
assertNotNull(csm.pendingPreloadChoices);
assertNotNull(csm.transactionQueue);
assertNotNull(csm.hmiListener);
assertNotNull(csm.onDisplayCapabilityListener);
assertNull(csm.pendingPresentOperation);
}

@After
Expand All @@ -123,11 +112,8 @@ public void tearDown() throws Exception {
assertNull(csm.currentHMILevel);
assertNull(csm.currentSystemContext);
assertNull(csm.defaultMainWindowCapability);
assertNull(csm.pendingPresentationSet);
assertNull(csm.pendingPresentOperation);

assertEquals(csm.transactionQueue.getTasksAsList().size(), 0);
assertEquals(csm.nextChoiceId, 1);

assertFalse(csm.isVROptional);

Expand Down Expand Up @@ -160,12 +146,6 @@ public void onError(String error) {
ChoiceSet choiceSet1 = new ChoiceSet("test", Collections.<ChoiceCell>emptyList(), choiceSetSelectionListener);
assertFalse(csm.setUpChoiceSet(choiceSet1));

// Identical cells will not be allowed
ChoiceCell cell1 = new ChoiceCell("test");
ChoiceCell cell2 = new ChoiceCell("test");
ChoiceSet choiceSet2 = new ChoiceSet("test", Arrays.asList(cell1, cell2), choiceSetSelectionListener);
assertFalse(csm.setUpChoiceSet(choiceSet2));

// cells that have duplicate text will be allowed if there is another property to make them unique because a unique name will be assigned and used
ChoiceCell cell3 = new ChoiceCell("test");
cell3.setSecondaryText("text 1");
Expand Down Expand Up @@ -208,103 +188,56 @@ public void testFindIfPresent() {
}

@Test
public void testUpdateIdsOnChoices() {

public void preloadChoicesAddsToQueue() {
ChoiceCell cell1 = new ChoiceCell("test");
ChoiceCell cell2 = new ChoiceCell("test2");
ChoiceCell cell3 = new ChoiceCell("test3");
LinkedHashSet<ChoiceCell> cellSet = new LinkedHashSet<>();
ArrayList<ChoiceCell> cellSet = new ArrayList<>();
cellSet.add(cell1);
cellSet.add(cell2);
cellSet.add(cell3);
// Cells are initially set to MAX_ID
assertEquals(cell1.getChoiceId(), 2000000000);
assertEquals(cell2.getChoiceId(), 2000000000);
assertEquals(cell3.getChoiceId(), 2000000000);
csm.updateIdsOnChoices(cellSet);
// We are looking for unique IDs
assertNotSame(cell1.getChoiceId(), 2000000000);
assertNotSame(cell2.getChoiceId(), 2000000000);
assertNotSame(cell3.getChoiceId(), 2000000000);
}
csm.preloadChoices(cellSet, new CompletionListener() {
@Override
public void onComplete(boolean success) {

@Test
public void testAddUniqueNamesToCells() {
ChoiceCell cell1 = new ChoiceCell("McDonalds", "1 mile away", null, null, null, null);
ChoiceCell cell2 = new ChoiceCell("McDonalds", "2 mile away", null, null, null, null);
ChoiceCell cell3 = new ChoiceCell("Starbucks", "3 mile away", null, null, null, null);
ChoiceCell cell4 = new ChoiceCell("McDonalds", "4 mile away", null, null, null, null);
ChoiceCell cell5 = new ChoiceCell("Starbucks", "5 mile away", null, null, null, null);
ChoiceCell cell6 = new ChoiceCell("Meijer", "6 mile away", null, null, null, null);
List<ChoiceCell> cellList = new ArrayList<>();

cellList.add(cell1);
cellList.add(cell2);
cellList.add(cell3);
cellList.add(cell4);
cellList.add(cell5);
cellList.add(cell6);

csm.addUniqueNamesToCells(cellList);

assertEquals(cell1.getUniqueText(), "McDonalds");
assertEquals(cell2.getUniqueText(), "McDonalds (2)");
assertEquals(cell3.getUniqueText(), "Starbucks");
assertEquals(cell4.getUniqueText(), "McDonalds (3)");
assertEquals(cell5.getUniqueText(), "Starbucks (2)");
assertEquals(cell6.getUniqueText(), "Meijer");
}
});
assertEquals(csm.transactionQueue.getTasksAsList().size(), 1);
}

@Test
public void testChoicesToBeRemovedFromPendingWithArray() {

ChoiceCell cell1 = new ChoiceCell("test");
ChoiceCell cell2 = new ChoiceCell("test2");
ChoiceCell cell3 = new ChoiceCell("test3");

HashSet<ChoiceCell> pendingPreloadSet = new HashSet<>();
pendingPreloadSet.add(cell1);
pendingPreloadSet.add(cell2);
pendingPreloadSet.add(cell3);

csm.pendingPreloadChoices.clear();
csm.pendingPreloadChoices = pendingPreloadSet;

List<ChoiceCell> choices = new ArrayList<>();
choices.add(cell2);

HashSet<ChoiceCell> returnedChoices = csm.choicesToBeRemovedFromPendingWithArray(choices);
public void preloadChoicesQueueEmptyWhenNoChoiceCells() {
ArrayList<ChoiceCell> cellSet = new ArrayList<>();
csm.preloadChoices(cellSet, new CompletionListener() {
@Override
public void onComplete(boolean success) {

assertEquals(returnedChoices.size(), 1);
for (ChoiceCell cell : returnedChoices) {
assertEquals(cell.getText(), "test2");
}
}
});
assertEquals(csm.transactionQueue.getTasksAsList().size(), 0);
}

@Test
public void testChoicesToBeUploadedWithArray() {

public void testPreloadChoicesQueueEmptyIfFileManagerNull() {
ChoiceCell cell1 = new ChoiceCell("test");
ChoiceCell cell2 = new ChoiceCell("test2");
ChoiceCell cell3 = new ChoiceCell("test3");
ArrayList<ChoiceCell> cellSet = new ArrayList<>();
cellSet.add(cell1);
cellSet.add(cell2);
cellSet.add(cell3);

HashSet<ChoiceCell> pendingDeleteSet = new HashSet<>();
pendingDeleteSet.add(cell1);
pendingDeleteSet.add(cell2);
pendingDeleteSet.add(cell3);

csm.preloadedChoices.clear();
csm.preloadedChoices = pendingDeleteSet;

List<ChoiceCell> choices = new ArrayList<>();
choices.add(cell2);

HashSet<ChoiceCell> returnedChoices = csm.choicesToBeDeletedWithArray(choices);
ISdl internalInterface = mock(ISdl.class);
when(internalInterface.getTaskmaster()).thenReturn(taskmaster);
FileManager fileManager = null;
ChoiceSetManager newCSM = new ChoiceSetManager(internalInterface, fileManager);
newCSM.preloadChoices(cellSet, new CompletionListener() {
@Override
public void onComplete(boolean success) {

assertEquals(returnedChoices.size(), 1);
for (ChoiceCell cell : returnedChoices) {
assertEquals(cell.getText(), "test2");
}
}
});
assertEquals(csm.transactionQueue.getTasksAsList().size(), 0);
}

@Test
Expand Down Expand Up @@ -474,51 +407,4 @@ public void testDismissingQueuedKeyboard() {
verify(testKeyboardOp, times(0)).dismissKeyboard();
verify(testKeyboardOp2, times(1)).dismissKeyboard();
}

@Test
public void testUniquenessForAvailableFields() {
WindowCapability windowCapability = new WindowCapability();
TextField secondaryText = new TextField();
secondaryText.setName(TextFieldName.secondaryText);
TextField tertiaryText = new TextField();
tertiaryText.setName(TextFieldName.tertiaryText);

List<TextField> textFields = new ArrayList<>();
textFields.add(secondaryText);
textFields.add(tertiaryText);
windowCapability.setTextFields(textFields);

ImageField choiceImage = new ImageField();
choiceImage.setName(ImageFieldName.choiceImage);
ImageField choiceSecondaryImage = new ImageField();
choiceSecondaryImage.setName(ImageFieldName.choiceSecondaryImage);
List<ImageField> imageFieldList = new ArrayList<>();
imageFieldList.add(choiceImage);
imageFieldList.add(choiceSecondaryImage);
windowCapability.setImageFields(imageFieldList);

csm.defaultMainWindowCapability = windowCapability;

ChoiceCell cell1 = new ChoiceCell("Item 1", "null", "tertiaryText", null, TestValues.GENERAL_ARTWORK, TestValues.GENERAL_ARTWORK);
ChoiceCell cell2 = new ChoiceCell("Item 1", "null2", "tertiaryText2", null, null, null);
List<ChoiceCell> choiceCellList = new ArrayList<>();
choiceCellList.add(cell1);
choiceCellList.add(cell2);

List<ChoiceCell> removedProperties = csm.removeUnusedProperties(choiceCellList);
assertNotNull(removedProperties.get(0).getSecondaryText());

textFields.remove(secondaryText);
textFields.remove(tertiaryText);
imageFieldList.remove(choiceImage);
imageFieldList.remove(choiceSecondaryImage);

removedProperties = csm.removeUnusedProperties(choiceCellList);
csm.addUniqueNamesBasedOnStrippedCells(removedProperties, choiceCellList);
assertEquals(choiceCellList.get(1).getUniqueText(), "Item 1 (2)");


}


}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void setUp() throws Exception {
cellsToDelete.add(cell2);

ISdl internalInterface = mock(ISdl.class);
deleteChoicesOperation = new DeleteChoicesOperation(internalInterface, cellsToDelete, null);
deleteChoicesOperation = new DeleteChoicesOperation(internalInterface, cellsToDelete, null, null);
}


Expand Down
Loading

0 comments on commit 1e85ab2

Please sign in to comment.