diff options
author | Bilal Alsharifi <599206+bilal-alsharifi@users.noreply.github.com> | 2020-04-09 17:54:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-09 17:54:16 -0400 |
commit | 18b5f861209ec0f7aa31bd55ea5f43d1e39cd900 (patch) | |
tree | a6ce7b3861598df9bc459421bf73de104ab8ddbf /android/sdl_android/src | |
parent | 7bf138ffe0bf858f2de06696e04f5da7024d24d3 (diff) | |
parent | 62a57bdbc2f8794ea020d6bdd293ba92789eb278 (diff) | |
download | sdl_android-18b5f861209ec0f7aa31bd55ea5f43d1e39cd900.tar.gz |
Merge pull request #1328 from smartdevicelink/bugfix/issue_1310_revisions
Inconsistencies in ScreenManager behavior if displayCapabilities is null & revisions
Diffstat (limited to 'android/sdl_android/src')
3 files changed, 243 insertions, 19 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicManagerTests.java index 3597c33f5..8aa9ae8a8 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicManagerTests.java @@ -5,6 +5,7 @@ import android.net.Uri; import com.smartdevicelink.AndroidTestCase2; import com.smartdevicelink.managers.BaseSubManager; +import com.smartdevicelink.managers.ManagerUtility; import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import com.smartdevicelink.proxy.interfaces.ISdl; @@ -21,6 +22,7 @@ import com.smartdevicelink.proxy.rpc.enums.TextFieldName; import org.json.JSONException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static org.mockito.Mockito.mock; @@ -90,6 +92,16 @@ public class TextAndGraphicManagerTests extends AndroidTestCase2 { return windowCapability; } + /** + * Used to simulate WindowCapability having no capabilities set + * @return windowCapability that has no capabilities set + */ + private WindowCapability getNullVarWindowCapability() { + + WindowCapability windowCapability = new WindowCapability(); + return windowCapability; + } + public void testInstantiation(){ assertNull(textAndGraphicManager.getTextField1()); @@ -117,17 +129,21 @@ public class TextAndGraphicManagerTests extends AndroidTestCase2 { assertNotNull(textAndGraphicManager.getBlankArtwork()); } + /** + * Test getting number of lines available to be set based off of windowCapability + */ public void testGetMainLines(){ // We want to test that the looping works. By default, it will return 4 if display cap is null + textAndGraphicManager.defaultMainWindowCapability = getNullVarWindowCapability(); // Null test - assertEquals(textAndGraphicManager.getNumberOfLines(), 4); + assertEquals(0, ManagerUtility.WindowCapabilityUtility.getMaxNumberOfMainFieldLines(textAndGraphicManager.defaultMainWindowCapability)); // The tests.java class has an example of this, but we must build it to do what // we need it to do. Build display cap w/ 3 main fields and test that it returns 3 textAndGraphicManager.defaultMainWindowCapability = getWindowCapability(3); - assertEquals(textAndGraphicManager.getNumberOfLines(), 3); + assertEquals(ManagerUtility.WindowCapabilityUtility.getMaxNumberOfMainFieldLines(textAndGraphicManager.defaultMainWindowCapability), 3); } public void testAssemble1Line(){ @@ -374,8 +390,141 @@ public class TextAndGraphicManagerTests extends AndroidTestCase2 { Show inputShow = new Show(); - // Force it to return display with support for only 4 lines of text textAndGraphicManager.defaultMainWindowCapability = getWindowCapability(4); + TextField tx1 = new TextField(); + TextField tx2 = new TextField(); + TextField tx3 = new TextField(); + TextField tx4 = new TextField(); + TextField tx5 = new TextField(); + TextField tx6 = new TextField(); + + tx1.setName(TextFieldName.mainField1); + tx2.setName(TextFieldName.mainField2); + tx3.setName(TextFieldName.mainField3); + tx4.setName(TextFieldName.mainField4); + tx5.setName(TextFieldName.mediaTrack); + tx6.setName(TextFieldName.templateTitle); + + List<TextField> textFieldNames = Arrays.asList(tx1,tx2,tx3,tx4,tx5,tx6); + textAndGraphicManager.defaultMainWindowCapability.setTextFields(textFieldNames); + + textAndGraphicManager.setMediaTrackTextField("HI"); + textAndGraphicManager.setTitle("bye"); + + // Force it to return display with support for only 4 lines of text + + textAndGraphicManager.setTextField1("It is"); + textAndGraphicManager.setTextField1Type(MetadataType.HUMIDITY); + + Show assembledShow = textAndGraphicManager.assembleShowText(inputShow); + + assertEquals(assembledShow.getMainField1(), "It is"); + assertEquals(assembledShow.getMainField2(), ""); + assertEquals(assembledShow.getMainField3(), ""); + assertEquals(assembledShow.getMainField4(), ""); + assertEquals(assembledShow.getMediaTrack(), "HI"); + assertEquals(assembledShow.getTemplateTitle(), "bye"); + + // test tags + MetadataTags tags = assembledShow.getMetadataTags(); + List<MetadataType> tagsList = new ArrayList<>(); + tagsList.add(MetadataType.HUMIDITY); + assertEquals(tags.getMainField1(), tagsList); + + textAndGraphicManager.setTextField2("Wednesday"); + textAndGraphicManager.setTextField2Type(MetadataType.CURRENT_TEMPERATURE); + + assembledShow = textAndGraphicManager.assembleShowText(inputShow); + assertEquals(assembledShow.getMainField1(), "It is"); + assertEquals(assembledShow.getMainField2(), "Wednesday"); + assertEquals(assembledShow.getMainField3(), ""); + assertEquals(assembledShow.getMainField4(), ""); + + // test tags + tags = assembledShow.getMetadataTags(); + tagsList = new ArrayList<>(); + List<MetadataType> tagsList2 = new ArrayList<>(); + tagsList.add(MetadataType.HUMIDITY); + tagsList2.add(MetadataType.CURRENT_TEMPERATURE); + assertEquals(tags.getMainField1(), tagsList); + assertEquals(tags.getMainField2(), tagsList2); + + textAndGraphicManager.setTextField3("My"); + textAndGraphicManager.setTextField3Type(MetadataType.MEDIA_ALBUM); + + assembledShow = textAndGraphicManager.assembleShowText(inputShow); + assertEquals(assembledShow.getMainField1(), "It is"); + assertEquals(assembledShow.getMainField2(), "Wednesday"); + assertEquals(assembledShow.getMainField3(), "My"); + assertEquals(assembledShow.getMainField4(), ""); + + // test tags + tags = assembledShow.getMetadataTags(); + tagsList = new ArrayList<>(); + tagsList2 = new ArrayList<>(); + List<MetadataType> tagsList3 = new ArrayList<>(); + tagsList.add(MetadataType.HUMIDITY); + tagsList2.add(MetadataType.CURRENT_TEMPERATURE); + tagsList3.add(MetadataType.MEDIA_ALBUM); + assertEquals(tags.getMainField1(), tagsList); + assertEquals(tags.getMainField2(), tagsList2); + assertEquals(tags.getMainField3(), tagsList3); + + textAndGraphicManager.setTextField4("Dudes"); + textAndGraphicManager.setTextField4Type(MetadataType.MEDIA_STATION); + + assembledShow = textAndGraphicManager.assembleShowText(inputShow); + assertEquals(assembledShow.getMainField1(), "It is"); + assertEquals(assembledShow.getMainField2(), "Wednesday"); + assertEquals(assembledShow.getMainField3(), "My"); + assertEquals(assembledShow.getMainField4(), "Dudes"); + + // test tags + tags = assembledShow.getMetadataTags(); + tagsList = new ArrayList<>(); + tagsList2 = new ArrayList<>(); + tagsList3 = new ArrayList<>(); + List<MetadataType> tagsList4 = new ArrayList<>(); + tagsList.add(MetadataType.HUMIDITY); + tagsList2.add(MetadataType.CURRENT_TEMPERATURE); + tagsList3.add(MetadataType.MEDIA_ALBUM); + tagsList4.add(MetadataType.MEDIA_STATION); + assertEquals(tags.getMainField1(), tagsList); + assertEquals(tags.getMainField2(), tagsList2); + assertEquals(tags.getMainField3(), tagsList3); + assertEquals(tags.getMainField4(), tagsList4); + + // try just setting line 1 and 4 + textAndGraphicManager.setTextField2(null); + textAndGraphicManager.setTextField3(null); + textAndGraphicManager.setTextField2Type(null); + textAndGraphicManager.setTextField3Type(null); + + assembledShow = textAndGraphicManager.assembleShowText(inputShow); + assertEquals(assembledShow.getMainField1(), "It is"); + assertEquals(assembledShow.getMainField2(), ""); + assertEquals(assembledShow.getMainField3(), ""); + assertEquals(assembledShow.getMainField4(), "Dudes"); + + // test tags + tags = assembledShow.getMetadataTags(); + tagsList = new ArrayList<>(); + tagsList4 = new ArrayList<>(); + tagsList.add(MetadataType.HUMIDITY); + tagsList4.add(MetadataType.MEDIA_STATION); + assertEquals(tags.getMainField1(), tagsList); + assertEquals(tags.getMainField4(), tagsList4); + } + + /** + * Testing if WindowCapability is null, TextFields should still update. + */ + public void testAssemble4LinesNullWindowCapability() { + + Show inputShow = new Show(); + + textAndGraphicManager.setMediaTrackTextField("HI"); + textAndGraphicManager.setTitle("bye"); textAndGraphicManager.setTextField1("It is"); textAndGraphicManager.setTextField1Type(MetadataType.HUMIDITY); @@ -386,6 +535,8 @@ public class TextAndGraphicManagerTests extends AndroidTestCase2 { assertEquals(assembledShow.getMainField2(), ""); assertEquals(assembledShow.getMainField3(), ""); assertEquals(assembledShow.getMainField4(), ""); + assertEquals(assembledShow.getMediaTrack(), "HI"); + assertEquals(assembledShow.getTemplateTitle(), "bye"); // test tags MetadataTags tags = assembledShow.getMetadataTags(); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperationTests.java index b29863110..3fbfcada9 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperationTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperationTests.java @@ -59,6 +59,9 @@ import static org.mockito.Mockito.mock; public class PreloadChoicesOperationTests extends AndroidTestCase2 { private PreloadChoicesOperation preloadChoicesOperation; + private PreloadChoicesOperation preloadChoicesOperationNullCapability; + private PreloadChoicesOperation preloadChoicesOperationEmptyCapability; + @Override public void setUp() throws Exception{ @@ -72,37 +75,74 @@ public class PreloadChoicesOperationTests extends AndroidTestCase2 { cellsToPreload.add(cell2); ImageField imageField = new ImageField(ImageFieldName.choiceImage, Arrays.asList(FileType.GRAPHIC_PNG, FileType.GRAPHIC_JPEG)); + ImageField imageField2 = new ImageField(); + imageField2.setName(ImageFieldName.choiceSecondaryImage); TextField textField = new TextField(TextFieldName.menuName, CharacterSet.CID1SET, 2, 2); + TextField textField2 = new TextField(); + TextField textField3 = new TextField(); + + textField2.setName(TextFieldName.secondaryText); + textField3.setName(TextFieldName.tertiaryText); + + WindowCapability windowCapability = new WindowCapability(); - windowCapability.setImageFields(Collections.singletonList(imageField)); + windowCapability.setImageFields(Arrays.asList(imageField, imageField2)); windowCapability.setImageTypeSupported(Arrays.asList(ImageType.STATIC, ImageType.DYNAMIC)); - windowCapability.setTextFields(Collections.singletonList(textField)); + windowCapability.setTextFields(Arrays.asList(textField, textField2, textField3)); ISdl internalInterface = mock(ISdl.class); FileManager fileManager = mock(FileManager.class); - preloadChoicesOperation = new PreloadChoicesOperation(internalInterface, fileManager, windowCapability, true, cellsToPreload, null); + preloadChoicesOperation = new PreloadChoicesOperation(internalInterface, fileManager, null, windowCapability, true, cellsToPreload, null); } - @Override - public void tearDown() throws Exception { - super.tearDown(); + /** + * Sets up PreloadChoicesOperation with WindowCapability being null + */ + public void setUpNullWindowCapability() { + + ChoiceCell cell1 = new ChoiceCell("cell 1"); + ChoiceCell cell2 = new ChoiceCell("cell 2", null, Test.GENERAL_ARTWORK); + HashSet<ChoiceCell> cellsToPreload = new HashSet<>(); + cellsToPreload.add(cell1); + cellsToPreload.add(cell2); + + ISdl internalInterface = mock(ISdl.class); + FileManager fileManager = mock(FileManager.class); + preloadChoicesOperationNullCapability = new PreloadChoicesOperation(internalInterface, fileManager, null, null, true, cellsToPreload, null); } - public void testHasTextFieldOfName(){ - boolean test = preloadChoicesOperation.hasTextFieldOfName(TextFieldName.secondaryText); - assertFalse(test); + /** + * Sets up PreloadChoicesOperation with an Capability not being set + * certain imageFields and TextFields + */ + public void setUpEmptyWindowCapability() { + + ChoiceCell cell1 = new ChoiceCell("cell 1"); + ChoiceCell cell2 = new ChoiceCell("cell 2", null, Test.GENERAL_ARTWORK); + HashSet<ChoiceCell> cellsToPreload = new HashSet<>(); + cellsToPreload.add(cell1); + cellsToPreload.add(cell2); - boolean test2 = preloadChoicesOperation.hasTextFieldOfName(TextFieldName.menuName); - assertTrue(test2); + ImageField imageField = new ImageField(); + imageField.setName(ImageFieldName.alertIcon); + + TextField textField = new TextField(); + textField.setName(TextFieldName.mainField1); + + WindowCapability windowCapability = new WindowCapability(); + windowCapability.setImageFields(Collections.singletonList(imageField)); + windowCapability.setTextFields(Collections.singletonList(textField)); + + ISdl internalInterface = mock(ISdl.class); + FileManager fileManager = mock(FileManager.class); + preloadChoicesOperationEmptyCapability = new PreloadChoicesOperation(internalInterface, fileManager, null, windowCapability, true, cellsToPreload, null); } - public void testHasImageFieldOfName(){ - boolean test = preloadChoicesOperation.hasImageFieldOfName(ImageFieldName.choiceImage); - assertTrue(test); - boolean test2 = preloadChoicesOperation.hasImageFieldOfName(ImageFieldName.appIcon); - assertFalse(test2); + @Override + public void tearDown() throws Exception { + super.tearDown(); } public void testArtworkNeedsUpload(){ @@ -116,4 +156,31 @@ public class PreloadChoicesOperationTests extends AndroidTestCase2 { assertEquals(artworksToUpload.size(), 1); } + /** + * Testing shouldSend method's with varying WindowCapability set. + */ + public void testShouldSendText() { + + setUpNullWindowCapability(); + assertTrue(preloadChoicesOperationNullCapability.shouldSendChoicePrimaryImage()); + assertTrue(preloadChoicesOperationNullCapability.shouldSendChoiceSecondaryImage()); + assertTrue(preloadChoicesOperationNullCapability.shouldSendChoiceSecondaryText()); + assertTrue(preloadChoicesOperationNullCapability.shouldSendChoiceTertiaryText()); + assertTrue(preloadChoicesOperationNullCapability.shouldSendChoiceText()); + + + assertTrue(preloadChoicesOperation.shouldSendChoicePrimaryImage()); + assertTrue(preloadChoicesOperation.shouldSendChoiceSecondaryImage()); + assertTrue(preloadChoicesOperation.shouldSendChoiceSecondaryText()); + assertTrue(preloadChoicesOperation.shouldSendChoiceTertiaryText()); + assertTrue(preloadChoicesOperation.shouldSendChoiceText()); + + setUpEmptyWindowCapability(); + assertFalse(preloadChoicesOperationEmptyCapability.shouldSendChoicePrimaryImage()); + assertFalse(preloadChoicesOperationEmptyCapability.shouldSendChoiceSecondaryImage()); + assertFalse(preloadChoicesOperationEmptyCapability.shouldSendChoiceSecondaryText()); + assertFalse(preloadChoicesOperationEmptyCapability.shouldSendChoiceTertiaryText()); + assertFalse(preloadChoicesOperationEmptyCapability.shouldSendChoiceText()); + } + } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java index a89a0771a..feca36cdf 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java @@ -46,6 +46,7 @@ import com.smartdevicelink.proxy.rpc.OnCommand; import com.smartdevicelink.proxy.rpc.OnHMIStatus; import com.smartdevicelink.proxy.rpc.SdlMsgVersion; import com.smartdevicelink.proxy.rpc.SetGlobalProperties; +import com.smartdevicelink.proxy.rpc.WindowCapability; import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.HMILevel; import com.smartdevicelink.proxy.rpc.enums.MenuLayout; @@ -57,6 +58,7 @@ import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.lang.reflect.Array; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -495,6 +497,10 @@ public class MenuManagerTests extends AndroidTestCase2 { menuManager.currentHMILevel = HMILevel.HMI_FULL; menuManager.currentSystemContext = SystemContext.SYSCTXT_MAIN; menuManager.sdlMsgVersion = new SdlMsgVersion(6,0); + menuManager.defaultMainWindowCapability = new WindowCapability(); + + List<MenuLayout> menuLayouts = Arrays.asList(MenuLayout.LIST, MenuLayout.TILES); + menuManager.defaultMainWindowCapability.setMenuLayoutsAvailable(menuLayouts); MenuConfiguration menuConfigurationTest = new MenuConfiguration(MenuLayout.LIST, MenuLayout.LIST); menuManager.setMenuConfiguration(menuConfigurationTest); |