Skip to content

Commit 18b5f86

Browse files
Merge pull request #1328 from smartdevicelink/bugfix/issue_1310_revisions
Inconsistencies in ScreenManager behavior if displayCapabilities is null & revisions
2 parents 7bf138f + 62a57bd commit 18b5f86

9 files changed

Lines changed: 443 additions & 110 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicManagerTests.java

Lines changed: 154 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.smartdevicelink.AndroidTestCase2;
77
import com.smartdevicelink.managers.BaseSubManager;
8+
import com.smartdevicelink.managers.ManagerUtility;
89
import com.smartdevicelink.managers.file.FileManager;
910
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
1011
import com.smartdevicelink.proxy.interfaces.ISdl;
@@ -21,6 +22,7 @@
2122
import org.json.JSONException;
2223

2324
import java.util.ArrayList;
25+
import java.util.Arrays;
2426
import java.util.List;
2527

2628
import static org.mockito.Mockito.mock;
@@ -90,6 +92,16 @@ private WindowCapability getWindowCapability(int numberOfMainFields){
9092
return windowCapability;
9193
}
9294

95+
/**
96+
* Used to simulate WindowCapability having no capabilities set
97+
* @return windowCapability that has no capabilities set
98+
*/
99+
private WindowCapability getNullVarWindowCapability() {
100+
101+
WindowCapability windowCapability = new WindowCapability();
102+
return windowCapability;
103+
}
104+
93105
public void testInstantiation(){
94106

95107
assertNull(textAndGraphicManager.getTextField1());
@@ -117,17 +129,21 @@ public void testInstantiation(){
117129
assertNotNull(textAndGraphicManager.getBlankArtwork());
118130
}
119131

132+
/**
133+
* Test getting number of lines available to be set based off of windowCapability
134+
*/
120135
public void testGetMainLines(){
121136

122137
// We want to test that the looping works. By default, it will return 4 if display cap is null
138+
textAndGraphicManager.defaultMainWindowCapability = getNullVarWindowCapability();
123139

124140
// Null test
125-
assertEquals(textAndGraphicManager.getNumberOfLines(), 4);
141+
assertEquals(0, ManagerUtility.WindowCapabilityUtility.getMaxNumberOfMainFieldLines(textAndGraphicManager.defaultMainWindowCapability));
126142

127143
// The tests.java class has an example of this, but we must build it to do what
128144
// we need it to do. Build display cap w/ 3 main fields and test that it returns 3
129145
textAndGraphicManager.defaultMainWindowCapability = getWindowCapability(3);
130-
assertEquals(textAndGraphicManager.getNumberOfLines(), 3);
146+
assertEquals(ManagerUtility.WindowCapabilityUtility.getMaxNumberOfMainFieldLines(textAndGraphicManager.defaultMainWindowCapability), 3);
131147
}
132148

133149
public void testAssemble1Line(){
@@ -374,8 +390,141 @@ public void testAssemble4Lines() {
374390

375391
Show inputShow = new Show();
376392

377-
// Force it to return display with support for only 4 lines of text
378393
textAndGraphicManager.defaultMainWindowCapability = getWindowCapability(4);
394+
TextField tx1 = new TextField();
395+
TextField tx2 = new TextField();
396+
TextField tx3 = new TextField();
397+
TextField tx4 = new TextField();
398+
TextField tx5 = new TextField();
399+
TextField tx6 = new TextField();
400+
401+
tx1.setName(TextFieldName.mainField1);
402+
tx2.setName(TextFieldName.mainField2);
403+
tx3.setName(TextFieldName.mainField3);
404+
tx4.setName(TextFieldName.mainField4);
405+
tx5.setName(TextFieldName.mediaTrack);
406+
tx6.setName(TextFieldName.templateTitle);
407+
408+
List<TextField> textFieldNames = Arrays.asList(tx1,tx2,tx3,tx4,tx5,tx6);
409+
textAndGraphicManager.defaultMainWindowCapability.setTextFields(textFieldNames);
410+
411+
textAndGraphicManager.setMediaTrackTextField("HI");
412+
textAndGraphicManager.setTitle("bye");
413+
414+
// Force it to return display with support for only 4 lines of text
415+
416+
textAndGraphicManager.setTextField1("It is");
417+
textAndGraphicManager.setTextField1Type(MetadataType.HUMIDITY);
418+
419+
Show assembledShow = textAndGraphicManager.assembleShowText(inputShow);
420+
421+
assertEquals(assembledShow.getMainField1(), "It is");
422+
assertEquals(assembledShow.getMainField2(), "");
423+
assertEquals(assembledShow.getMainField3(), "");
424+
assertEquals(assembledShow.getMainField4(), "");
425+
assertEquals(assembledShow.getMediaTrack(), "HI");
426+
assertEquals(assembledShow.getTemplateTitle(), "bye");
427+
428+
// test tags
429+
MetadataTags tags = assembledShow.getMetadataTags();
430+
List<MetadataType> tagsList = new ArrayList<>();
431+
tagsList.add(MetadataType.HUMIDITY);
432+
assertEquals(tags.getMainField1(), tagsList);
433+
434+
textAndGraphicManager.setTextField2("Wednesday");
435+
textAndGraphicManager.setTextField2Type(MetadataType.CURRENT_TEMPERATURE);
436+
437+
assembledShow = textAndGraphicManager.assembleShowText(inputShow);
438+
assertEquals(assembledShow.getMainField1(), "It is");
439+
assertEquals(assembledShow.getMainField2(), "Wednesday");
440+
assertEquals(assembledShow.getMainField3(), "");
441+
assertEquals(assembledShow.getMainField4(), "");
442+
443+
// test tags
444+
tags = assembledShow.getMetadataTags();
445+
tagsList = new ArrayList<>();
446+
List<MetadataType> tagsList2 = new ArrayList<>();
447+
tagsList.add(MetadataType.HUMIDITY);
448+
tagsList2.add(MetadataType.CURRENT_TEMPERATURE);
449+
assertEquals(tags.getMainField1(), tagsList);
450+
assertEquals(tags.getMainField2(), tagsList2);
451+
452+
textAndGraphicManager.setTextField3("My");
453+
textAndGraphicManager.setTextField3Type(MetadataType.MEDIA_ALBUM);
454+
455+
assembledShow = textAndGraphicManager.assembleShowText(inputShow);
456+
assertEquals(assembledShow.getMainField1(), "It is");
457+
assertEquals(assembledShow.getMainField2(), "Wednesday");
458+
assertEquals(assembledShow.getMainField3(), "My");
459+
assertEquals(assembledShow.getMainField4(), "");
460+
461+
// test tags
462+
tags = assembledShow.getMetadataTags();
463+
tagsList = new ArrayList<>();
464+
tagsList2 = new ArrayList<>();
465+
List<MetadataType> tagsList3 = new ArrayList<>();
466+
tagsList.add(MetadataType.HUMIDITY);
467+
tagsList2.add(MetadataType.CURRENT_TEMPERATURE);
468+
tagsList3.add(MetadataType.MEDIA_ALBUM);
469+
assertEquals(tags.getMainField1(), tagsList);
470+
assertEquals(tags.getMainField2(), tagsList2);
471+
assertEquals(tags.getMainField3(), tagsList3);
472+
473+
textAndGraphicManager.setTextField4("Dudes");
474+
textAndGraphicManager.setTextField4Type(MetadataType.MEDIA_STATION);
475+
476+
assembledShow = textAndGraphicManager.assembleShowText(inputShow);
477+
assertEquals(assembledShow.getMainField1(), "It is");
478+
assertEquals(assembledShow.getMainField2(), "Wednesday");
479+
assertEquals(assembledShow.getMainField3(), "My");
480+
assertEquals(assembledShow.getMainField4(), "Dudes");
481+
482+
// test tags
483+
tags = assembledShow.getMetadataTags();
484+
tagsList = new ArrayList<>();
485+
tagsList2 = new ArrayList<>();
486+
tagsList3 = new ArrayList<>();
487+
List<MetadataType> tagsList4 = new ArrayList<>();
488+
tagsList.add(MetadataType.HUMIDITY);
489+
tagsList2.add(MetadataType.CURRENT_TEMPERATURE);
490+
tagsList3.add(MetadataType.MEDIA_ALBUM);
491+
tagsList4.add(MetadataType.MEDIA_STATION);
492+
assertEquals(tags.getMainField1(), tagsList);
493+
assertEquals(tags.getMainField2(), tagsList2);
494+
assertEquals(tags.getMainField3(), tagsList3);
495+
assertEquals(tags.getMainField4(), tagsList4);
496+
497+
// try just setting line 1 and 4
498+
textAndGraphicManager.setTextField2(null);
499+
textAndGraphicManager.setTextField3(null);
500+
textAndGraphicManager.setTextField2Type(null);
501+
textAndGraphicManager.setTextField3Type(null);
502+
503+
assembledShow = textAndGraphicManager.assembleShowText(inputShow);
504+
assertEquals(assembledShow.getMainField1(), "It is");
505+
assertEquals(assembledShow.getMainField2(), "");
506+
assertEquals(assembledShow.getMainField3(), "");
507+
assertEquals(assembledShow.getMainField4(), "Dudes");
508+
509+
// test tags
510+
tags = assembledShow.getMetadataTags();
511+
tagsList = new ArrayList<>();
512+
tagsList4 = new ArrayList<>();
513+
tagsList.add(MetadataType.HUMIDITY);
514+
tagsList4.add(MetadataType.MEDIA_STATION);
515+
assertEquals(tags.getMainField1(), tagsList);
516+
assertEquals(tags.getMainField4(), tagsList4);
517+
}
518+
519+
/**
520+
* Testing if WindowCapability is null, TextFields should still update.
521+
*/
522+
public void testAssemble4LinesNullWindowCapability() {
523+
524+
Show inputShow = new Show();
525+
526+
textAndGraphicManager.setMediaTrackTextField("HI");
527+
textAndGraphicManager.setTitle("bye");
379528

380529
textAndGraphicManager.setTextField1("It is");
381530
textAndGraphicManager.setTextField1Type(MetadataType.HUMIDITY);
@@ -386,6 +535,8 @@ public void testAssemble4Lines() {
386535
assertEquals(assembledShow.getMainField2(), "");
387536
assertEquals(assembledShow.getMainField3(), "");
388537
assertEquals(assembledShow.getMainField4(), "");
538+
assertEquals(assembledShow.getMediaTrack(), "HI");
539+
assertEquals(assembledShow.getTemplateTitle(), "bye");
389540

390541
// test tags
391542
MetadataTags tags = assembledShow.getMetadataTags();

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperationTests.java

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
public class PreloadChoicesOperationTests extends AndroidTestCase2 {
6060

6161
private PreloadChoicesOperation preloadChoicesOperation;
62+
private PreloadChoicesOperation preloadChoicesOperationNullCapability;
63+
private PreloadChoicesOperation preloadChoicesOperationEmptyCapability;
64+
6265

6366
@Override
6467
public void setUp() throws Exception{
@@ -72,37 +75,74 @@ public void setUp() throws Exception{
7275
cellsToPreload.add(cell2);
7376

7477
ImageField imageField = new ImageField(ImageFieldName.choiceImage, Arrays.asList(FileType.GRAPHIC_PNG, FileType.GRAPHIC_JPEG));
78+
ImageField imageField2 = new ImageField();
79+
imageField2.setName(ImageFieldName.choiceSecondaryImage);
7580
TextField textField = new TextField(TextFieldName.menuName, CharacterSet.CID1SET, 2, 2);
7681

82+
TextField textField2 = new TextField();
83+
TextField textField3 = new TextField();
84+
85+
textField2.setName(TextFieldName.secondaryText);
86+
textField3.setName(TextFieldName.tertiaryText);
87+
88+
7789
WindowCapability windowCapability = new WindowCapability();
78-
windowCapability.setImageFields(Collections.singletonList(imageField));
90+
windowCapability.setImageFields(Arrays.asList(imageField, imageField2));
7991
windowCapability.setImageTypeSupported(Arrays.asList(ImageType.STATIC, ImageType.DYNAMIC));
80-
windowCapability.setTextFields(Collections.singletonList(textField));
92+
windowCapability.setTextFields(Arrays.asList(textField, textField2, textField3));
8193

8294
ISdl internalInterface = mock(ISdl.class);
8395
FileManager fileManager = mock(FileManager.class);
84-
preloadChoicesOperation = new PreloadChoicesOperation(internalInterface, fileManager, windowCapability, true, cellsToPreload, null);
96+
preloadChoicesOperation = new PreloadChoicesOperation(internalInterface, fileManager, null, windowCapability, true, cellsToPreload, null);
8597
}
8698

87-
@Override
88-
public void tearDown() throws Exception {
89-
super.tearDown();
99+
/**
100+
* Sets up PreloadChoicesOperation with WindowCapability being null
101+
*/
102+
public void setUpNullWindowCapability() {
103+
104+
ChoiceCell cell1 = new ChoiceCell("cell 1");
105+
ChoiceCell cell2 = new ChoiceCell("cell 2", null, Test.GENERAL_ARTWORK);
106+
HashSet<ChoiceCell> cellsToPreload = new HashSet<>();
107+
cellsToPreload.add(cell1);
108+
cellsToPreload.add(cell2);
109+
110+
ISdl internalInterface = mock(ISdl.class);
111+
FileManager fileManager = mock(FileManager.class);
112+
preloadChoicesOperationNullCapability = new PreloadChoicesOperation(internalInterface, fileManager, null, null, true, cellsToPreload, null);
90113
}
91114

92-
public void testHasTextFieldOfName(){
93-
boolean test = preloadChoicesOperation.hasTextFieldOfName(TextFieldName.secondaryText);
94-
assertFalse(test);
115+
/**
116+
* Sets up PreloadChoicesOperation with an Capability not being set
117+
* certain imageFields and TextFields
118+
*/
119+
public void setUpEmptyWindowCapability() {
120+
121+
ChoiceCell cell1 = new ChoiceCell("cell 1");
122+
ChoiceCell cell2 = new ChoiceCell("cell 2", null, Test.GENERAL_ARTWORK);
123+
HashSet<ChoiceCell> cellsToPreload = new HashSet<>();
124+
cellsToPreload.add(cell1);
125+
cellsToPreload.add(cell2);
95126

96-
boolean test2 = preloadChoicesOperation.hasTextFieldOfName(TextFieldName.menuName);
97-
assertTrue(test2);
127+
ImageField imageField = new ImageField();
128+
imageField.setName(ImageFieldName.alertIcon);
129+
130+
TextField textField = new TextField();
131+
textField.setName(TextFieldName.mainField1);
132+
133+
WindowCapability windowCapability = new WindowCapability();
134+
windowCapability.setImageFields(Collections.singletonList(imageField));
135+
windowCapability.setTextFields(Collections.singletonList(textField));
136+
137+
ISdl internalInterface = mock(ISdl.class);
138+
FileManager fileManager = mock(FileManager.class);
139+
preloadChoicesOperationEmptyCapability = new PreloadChoicesOperation(internalInterface, fileManager, null, windowCapability, true, cellsToPreload, null);
98140
}
99141

100-
public void testHasImageFieldOfName(){
101-
boolean test = preloadChoicesOperation.hasImageFieldOfName(ImageFieldName.choiceImage);
102-
assertTrue(test);
103142

104-
boolean test2 = preloadChoicesOperation.hasImageFieldOfName(ImageFieldName.appIcon);
105-
assertFalse(test2);
143+
@Override
144+
public void tearDown() throws Exception {
145+
super.tearDown();
106146
}
107147

108148
public void testArtworkNeedsUpload(){
@@ -116,4 +156,31 @@ public void testArtworksToUpload(){
116156
assertEquals(artworksToUpload.size(), 1);
117157
}
118158

159+
/**
160+
* Testing shouldSend method's with varying WindowCapability set.
161+
*/
162+
public void testShouldSendText() {
163+
164+
setUpNullWindowCapability();
165+
assertTrue(preloadChoicesOperationNullCapability.shouldSendChoicePrimaryImage());
166+
assertTrue(preloadChoicesOperationNullCapability.shouldSendChoiceSecondaryImage());
167+
assertTrue(preloadChoicesOperationNullCapability.shouldSendChoiceSecondaryText());
168+
assertTrue(preloadChoicesOperationNullCapability.shouldSendChoiceTertiaryText());
169+
assertTrue(preloadChoicesOperationNullCapability.shouldSendChoiceText());
170+
171+
172+
assertTrue(preloadChoicesOperation.shouldSendChoicePrimaryImage());
173+
assertTrue(preloadChoicesOperation.shouldSendChoiceSecondaryImage());
174+
assertTrue(preloadChoicesOperation.shouldSendChoiceSecondaryText());
175+
assertTrue(preloadChoicesOperation.shouldSendChoiceTertiaryText());
176+
assertTrue(preloadChoicesOperation.shouldSendChoiceText());
177+
178+
setUpEmptyWindowCapability();
179+
assertFalse(preloadChoicesOperationEmptyCapability.shouldSendChoicePrimaryImage());
180+
assertFalse(preloadChoicesOperationEmptyCapability.shouldSendChoiceSecondaryImage());
181+
assertFalse(preloadChoicesOperationEmptyCapability.shouldSendChoiceSecondaryText());
182+
assertFalse(preloadChoicesOperationEmptyCapability.shouldSendChoiceTertiaryText());
183+
assertFalse(preloadChoicesOperationEmptyCapability.shouldSendChoiceText());
184+
}
185+
119186
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.smartdevicelink.proxy.rpc.OnHMIStatus;
4747
import com.smartdevicelink.proxy.rpc.SdlMsgVersion;
4848
import com.smartdevicelink.proxy.rpc.SetGlobalProperties;
49+
import com.smartdevicelink.proxy.rpc.WindowCapability;
4950
import com.smartdevicelink.proxy.rpc.enums.FileType;
5051
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
5152
import com.smartdevicelink.proxy.rpc.enums.MenuLayout;
@@ -57,6 +58,7 @@
5758
import org.mockito.invocation.InvocationOnMock;
5859
import org.mockito.stubbing.Answer;
5960

61+
import java.lang.reflect.Array;
6062
import java.util.Arrays;
6163
import java.util.Collections;
6264
import java.util.List;
@@ -495,6 +497,10 @@ public void testSetMenuConfiguration(){
495497
menuManager.currentHMILevel = HMILevel.HMI_FULL;
496498
menuManager.currentSystemContext = SystemContext.SYSCTXT_MAIN;
497499
menuManager.sdlMsgVersion = new SdlMsgVersion(6,0);
500+
menuManager.defaultMainWindowCapability = new WindowCapability();
501+
502+
List<MenuLayout> menuLayouts = Arrays.asList(MenuLayout.LIST, MenuLayout.TILES);
503+
menuManager.defaultMainWindowCapability.setMenuLayoutsAvailable(menuLayouts);
498504

499505
MenuConfiguration menuConfigurationTest = new MenuConfiguration(MenuLayout.LIST, MenuLayout.LIST);
500506
menuManager.setMenuConfiguration(menuConfigurationTest);

0 commit comments

Comments
 (0)