Skip to content

Commit 650ca44

Browse files
Merge branch 'develop' into feature/Image_upload_management
# Conflicts: # android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java # javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java
2 parents 5f4c890 + 1d4d523 commit 650ca44

8 files changed

Lines changed: 288 additions & 3 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/FileManagerTests.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,4 +925,60 @@ public void onComplete(Map<String, String> errors) {
925925
});
926926
verify(internalInterface, times(1)).sendRequests(any(List.class), any(OnMultipleRequestListener.class));
927927
}
928+
929+
/**
930+
* Test custom overridden SdlFile equals method
931+
*/
932+
public void testSdlFileEquals() {
933+
// Case 1: object is null, assertFalse
934+
SdlFile artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, true);
935+
SdlFile artwork2 = null;
936+
assertFalse(artwork1.equals(artwork2));
937+
938+
// Case 2 SoftButtonObjects are the same, assertTrue
939+
assertTrue(artwork1.equals(artwork1));
940+
941+
// Case 3: object is not an instance of SoftButtonObject, assertFalse
942+
assertFalse(artwork1.equals("Test"));
943+
944+
// Case 4: different StaticIcon status, assertFalse
945+
artwork1.setStaticIcon(true);
946+
artwork2 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, true);
947+
artwork2.setStaticIcon(false);
948+
assertFalse(artwork1.equals(artwork2));
949+
950+
// Case 5: different Persistent status, assertFalse
951+
artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
952+
artwork2 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, true);
953+
assertFalse(artwork1.equals(artwork2));
954+
955+
// Case 6: different name, assertFalse
956+
artwork2 = new SdlFile("image2", FileType.GRAPHIC_PNG, 1, false);
957+
assertFalse(artwork1.equals(artwork2));
958+
959+
// Case 7: different Uri
960+
Uri uri1 = Uri.parse("testUri1");
961+
Uri uri2 = Uri.parse("testUri2");
962+
artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, uri1, false);
963+
artwork2 = new SdlFile("image1", FileType.GRAPHIC_PNG, uri2, false);
964+
assertFalse(artwork1.equals(artwork2));
965+
966+
// Case 8: different FileData
967+
artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
968+
artwork2 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
969+
byte[] GENERAL_BYTE_ARRAY2 = new byte[2];
970+
artwork1.setFileData(Test.GENERAL_BYTE_ARRAY);
971+
artwork2.setFileData(GENERAL_BYTE_ARRAY2);
972+
assertFalse(artwork1.equals(artwork2));
973+
974+
// Case 9 different FileType, assertFalse
975+
artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
976+
artwork2 = new SdlFile("image1", FileType.AUDIO_WAVE, 1, false);
977+
assertFalse(artwork1.equals(artwork2));
978+
979+
// Case 10: they are equal, assertTrue
980+
artwork1 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
981+
artwork2 = new SdlFile("image1", FileType.GRAPHIC_PNG, 1, false);
982+
assertTrue(artwork1.equals(artwork2));
983+
}
928984
}

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

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.smartdevicelink.protocol.enums.FunctionID;
1010
import com.smartdevicelink.proxy.interfaces.ISdl;
1111
import com.smartdevicelink.proxy.rpc.Image;
12+
import com.smartdevicelink.proxy.rpc.OnButtonEvent;
13+
import com.smartdevicelink.proxy.rpc.OnButtonPress;
1214
import com.smartdevicelink.proxy.rpc.OnHMIStatus;
1315
import com.smartdevicelink.proxy.rpc.Show;
1416
import com.smartdevicelink.proxy.rpc.SoftButton;
@@ -25,6 +27,7 @@
2527
import org.mockito.invocation.InvocationOnMock;
2628
import org.mockito.stubbing.Answer;
2729

30+
import java.util.ArrayList;
2831
import java.util.Arrays;
2932
import java.util.Collections;
3033
import java.util.List;
@@ -305,4 +308,101 @@ public void testAssigningIdsToSoftButtonObjects() {
305308
assertEquals("SoftButtonObject id doesn't match the expected value", 100, sbo4.getButtonId());
306309
assertEquals("SoftButtonObject id doesn't match the expected value", 103, sbo5.getButtonId());
307310
}
311+
312+
/**
313+
* Test custom overridden softButtonObject equals method
314+
*/
315+
public void testSoftButtonObjectEquals() {
316+
SoftButtonObject softButtonObject1;
317+
SoftButtonObject softButtonObject2;
318+
319+
SoftButtonObject.OnEventListener testOnEventList1 = new SoftButtonObject.OnEventListener() {
320+
@Override
321+
public void onPress(SoftButtonObject softButtonObject, OnButtonPress onButtonPress) {
322+
}
323+
324+
@Override
325+
public void onEvent(SoftButtonObject softButtonObject, OnButtonEvent onButtonEvent) {
326+
}
327+
};
328+
329+
SoftButtonObject.OnEventListener testOnEventList2 = new SoftButtonObject.OnEventListener() {
330+
@Override
331+
public void onPress(SoftButtonObject softButtonObject, OnButtonPress onButtonPress) {
332+
}
333+
334+
@Override
335+
public void onEvent(SoftButtonObject softButtonObject, OnButtonEvent onButtonEvent) {
336+
}
337+
};
338+
339+
// Case 1: object is null, assertFalse
340+
softButtonObject1 = new SoftButtonObject("test", softButtonState1, null);
341+
softButtonObject2 = null;
342+
assertFalse(softButtonObject1.equals(softButtonObject2));
343+
344+
// Case 2 SoftButtonObjects are the same, assertTrue
345+
assertTrue(softButtonObject1.equals(softButtonObject1));
346+
347+
// Case 3: object is not an instance of SoftButtonObject assertFalse
348+
SdlArtwork artwork = new SdlArtwork("image1", FileType.GRAPHIC_PNG, 1, true);
349+
assertFalse(softButtonObject1.equals(artwork));
350+
351+
// Case 4: SoftButtonObjectState List are not same size, assertFalse
352+
List<SoftButtonState> softButtonStateList = new ArrayList<>();
353+
List<SoftButtonState> softButtonStateList2 = new ArrayList<>();
354+
softButtonStateList.add(softButtonState1);
355+
softButtonStateList2.add(softButtonState1);
356+
softButtonStateList2.add(softButtonState2);
357+
softButtonObject1 = new SoftButtonObject("hi", softButtonStateList, "Hi", null);
358+
softButtonObject2 = new SoftButtonObject("hi", softButtonStateList2, "Hi", null);
359+
assertFalse(softButtonObject1.equals(softButtonObject2));
360+
361+
// Case 5: SoftButtonStates are not the same, assertFalse
362+
softButtonObject1 = new SoftButtonObject("test", softButtonState1, null);
363+
softButtonObject2 = new SoftButtonObject("test", softButtonState2, null);
364+
assertFalse(softButtonObject1.equals(softButtonObject2));
365+
366+
// Case 6: SoftButtonObject names are not same, assertFalse
367+
softButtonObject1 = new SoftButtonObject("test", softButtonState1, null);
368+
softButtonObject2 = new SoftButtonObject("test23123", softButtonState1, null);
369+
assertFalse(softButtonObject1.equals(softButtonObject2));
370+
371+
// Case 7: SoftButtonObject currentStateName not same, assertFalse
372+
softButtonObject1 = new SoftButtonObject("hi", softButtonStateList, "Hi", null);
373+
softButtonObject2 = new SoftButtonObject("hi", softButtonStateList, "Hi2", null);
374+
assertFalse(softButtonObject1.equals(softButtonObject2));
375+
}
376+
377+
/**
378+
* Test custom overridden softButtonState equals method
379+
*/
380+
public void testSoftButtonStateEquals() {
381+
assertFalse(softButtonState1.equals(softButtonState2));
382+
SdlArtwork artwork1 = new SdlArtwork("image1", FileType.GRAPHIC_PNG, 1, true);
383+
SdlArtwork artwork2 = new SdlArtwork("image2", FileType.GRAPHIC_PNG, 1, true);
384+
385+
// Case 1: object is null, assertFalse
386+
softButtonState1 = new SoftButtonState("object1-state1", "o1s1", artwork1);
387+
softButtonState2 = null;
388+
assertFalse(softButtonState1.equals(softButtonState2));
389+
390+
// Case 2 SoftButtonObjects are the same, assertTrue
391+
assertTrue(softButtonState1.equals(softButtonState1));
392+
393+
// Case 3: object is not an instance of SoftButtonState, assertFalse
394+
assertFalse(softButtonState1.equals(artwork1));
395+
396+
// Case 4: different artwork, assertFalse
397+
softButtonState2 = new SoftButtonState("object1-state1", "o1s1", artwork2);
398+
assertFalse(softButtonState1.equals(softButtonState2));
399+
400+
// Case 5: different name, assertFalse
401+
softButtonState2 = new SoftButtonState("object1-state1 different name", "o1s1", artwork1);
402+
assertFalse(softButtonState1.equals(softButtonState2));
403+
404+
// Case 6 they are equal, assertTrue
405+
softButtonState2 = new SoftButtonState("object1-state1", "o1s1", artwork1);
406+
assertTrue(softButtonState1.equals(softButtonState2));
407+
}
308408
}

android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ public void setOverwrite(boolean overwrite) {
265265

266266
/**
267267
* Generates a file name from data by hashing the data and returning the last 16 chars
268+
*
268269
* @param data a byte array representing the data of the file
269270
* @return a String value representing the name that will be used to store the file in the head unit
270271
*/
@@ -292,6 +293,7 @@ private String generateFileNameFromData(@NonNull byte[] data) {
292293

293294
/**
294295
* Generates a file name from uri by hashing the uri string and returning the last 16 chars
296+
*
295297
* @param uri a URI value representing a file's location
296298
* @return a String value representing the name that will be used to store the file in the head unit
297299
*/
@@ -301,10 +303,44 @@ private String generateFileNameFromUri(@NonNull Uri uri) {
301303

302304
/**
303305
* Generates a file name from resourceId by hashing the id and returning the last 16 chars
306+
*
304307
* @param id an int value representing the android resource id of the file
305308
* @return a String value representing the name that will be used to store the file in the head unit
306309
*/
307310
private String generateFileNameFromResourceId(int id) {
308311
return generateFileNameFromData("ResourceId".concat(String.valueOf(id)).getBytes());
309312
}
313+
314+
/**
315+
* Used to compile hashcode for SdlFile for use to compare in overridden equals method
316+
* @return Custom hashcode of SdlFile variables
317+
*/
318+
@Override
319+
public int hashCode() {
320+
int result = 1;
321+
result += ((getName() == null) ? 0 : Integer.rotateLeft(getName().hashCode(), 1));
322+
result += ((getUri() == null) ? 0 : Integer.rotateLeft(getUri().hashCode(), 2));
323+
result += ((getFileData() == null) ? 0 : Integer.rotateLeft(getFileData().hashCode(), 3));
324+
result += ((getType() == null) ? 0 : Integer.rotateLeft(getType().hashCode(), 4));
325+
result += Integer.rotateLeft(Boolean.valueOf(isStaticIcon()).hashCode(), 5);
326+
result += Integer.rotateLeft(Boolean.valueOf(isPersistent()).hashCode(), 6);
327+
result += Integer.rotateLeft(Integer.valueOf(getResourceId()).hashCode(), 7);
328+
return result;
329+
}
330+
331+
/**
332+
* Uses our custom hashCode for SdlFile objects
333+
* @param o - The object to compare
334+
* @return boolean of whether the objects are the same or not
335+
*/
336+
@Override
337+
public boolean equals(Object o) {
338+
if (o == null) return false;
339+
// if this is the same memory address, it's the same
340+
if (this == o) return true;
341+
// if this is not an instance of SdlFile, not the same
342+
if (!(o instanceof SdlFile)) return false;
343+
// return comparison
344+
return hashCode() == o.hashCode();
345+
}
310346
}

base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonObject.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,36 @@ interface UpdateListener{
309309
*/
310310
void onUpdate();
311311
}
312+
313+
/**
314+
* Used to compile hashcode for SoftButtonsObjects for use to compare in equals method
315+
* @return Custom hashcode of SoftButtonObjects variables
316+
*/
317+
@Override
318+
public int hashCode() {
319+
int result = 1;
320+
result += ((getName() == null) ? 0 : Integer.rotateLeft(getName().hashCode(), 1));
321+
result += ((getCurrentStateName() == null) ? 0 : Integer.rotateLeft(getCurrentStateName().hashCode(), 2));
322+
result += Integer.rotateLeft(Integer.valueOf(getButtonId()).hashCode(), 3);
323+
for (int i = 0; i < this.states.size(); i++) {
324+
result += ((getStates().get(i) == null) ? 0 : Integer.rotateLeft(getStates().get(i).hashCode(), i + 4));
325+
}
326+
return result;
327+
}
328+
329+
/**
330+
* Uses our custom hashCode for SoftButtonObject objects
331+
* @param o - The object to compare
332+
* @return boolean of whether the objects are the same or not
333+
*/
334+
@Override
335+
public boolean equals(Object o) {
336+
if (o == null) return false;
337+
// if this is the same memory address, it's the same
338+
if (this == o) return true;
339+
// if this is not an instance of SoftButtonObject, not the same
340+
if (!(o instanceof SoftButtonObject)) return false;
341+
// return comparison
342+
return hashCode() == o.hashCode();
343+
}
312344
}

base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonState.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,32 @@ public SoftButton getSoftButton() {
158158
public SdlArtwork getArtwork() {
159159
return artwork;
160160
}
161+
162+
/**
163+
* Used to compile hashcode for SoftButtonState for use to compare in equals method
164+
* @return Custom hashcode of SoftButtonState variables
165+
*/
166+
@Override
167+
public int hashCode() {
168+
int result = 1;
169+
result += ((getName() == null) ? 0 : Integer.rotateLeft(getName().hashCode(), 1));
170+
result += ((getArtwork() == null) ? 0 : Integer.rotateLeft(getArtwork().hashCode(),2));
171+
return result;
172+
}
173+
174+
/**
175+
* Uses our custom hashCode for SoftButtonState objects
176+
* @param o - The object to compare
177+
* @return boolean of whether the objects are the same or not
178+
*/
179+
@Override
180+
public boolean equals(Object o) {
181+
if (o == null) return false;
182+
// if this is the same memory address, it's the same
183+
if (this == o) return true;
184+
// if this is not an instance of SoftButtonState, not the same
185+
if (!(o instanceof SoftButtonState)) return false;
186+
// return comparison
187+
return hashCode() == o.hashCode();
188+
}
161189
}

base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCell.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ public int hashCode() {
224224
result += ((getText() == null) ? 0 : Integer.rotateLeft(getText().hashCode(), 1));
225225
result += ((getSecondaryText() == null) ? 0 : Integer.rotateLeft(getSecondaryText().hashCode(), 2));
226226
result += ((getTertiaryText() == null) ? 0 : Integer.rotateLeft(getTertiaryText().hashCode(), 3));
227-
result += ((getArtwork() == null || getArtwork().getName() == null) ? 0 : Integer.rotateLeft(getArtwork().getName().hashCode(), 4));
228-
result += ((getSecondaryArtwork() == null || getSecondaryArtwork().getName() == null) ? 0 : Integer.rotateLeft(getSecondaryArtwork().getName().hashCode(), 5));
227+
result += ((getArtwork() == null) ? 0 : Integer.rotateLeft(getArtwork().hashCode(), 4));
228+
result += ((getSecondaryArtwork() == null) ? 0 : Integer.rotateLeft(getSecondaryArtwork().hashCode(), 5));
229229
result += ((getVoiceCommands() == null) ? 0 : Integer.rotateLeft(getVoiceCommands().hashCode(), 6));
230230
return result;
231231
}

base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ int getParentCellId() {
299299
public int hashCode() {
300300
int result = 1;
301301
result += ((getTitle() == null) ? 0 : Integer.rotateLeft(getTitle().hashCode(), 1));
302-
result += ((getIcon() == null || getIcon().getName() == null) ? 0 : Integer.rotateLeft(getIcon().getName().hashCode(), 2));
302+
result += ((getIcon() == null) ? 0 : Integer.rotateLeft(getIcon().hashCode(), 2));
303303
result += ((getVoiceCommands() == null) ? 0 : Integer.rotateLeft(getVoiceCommands().hashCode(), 3));
304304
result += ((getSubCells() == null) ? 0 : Integer.rotateLeft(1, 4));
305305
return result;

javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlFile.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,43 @@ private String generateFileNameFromData(@NonNull byte[] data) {
254254

255255
/**
256256
* Generates a file name from filePath by hashing the filePath and returning the last 16 chars
257+
*
257258
* @param filePath a String value representing the the location of the file
258259
* @return a String value representing the name that will be used to store the file in the head unit
259260
*/
260261
private String generateFileNameFromFilePath(String filePath) {
261262
return generateFileNameFromData(filePath.getBytes());
262263
}
264+
265+
/**
266+
* Used to compile hashcode for SdlFile for use to compare in equals method
267+
* @return Custom hashcode of SdlFile variables
268+
*/
269+
@Override
270+
public int hashCode() {
271+
int result = 1;
272+
result += ((getName() == null) ? 0 : Integer.rotateLeft(getName().hashCode(), 1));
273+
result += ((getFilePath() == null) ? 0 : Integer.rotateLeft(getFilePath().hashCode(), 2));
274+
result += ((getFileData() == null) ? 0 : Integer.rotateLeft(getFileData().hashCode(), 3));
275+
result += ((getType() == null) ? 0 : Integer.rotateLeft(getType().hashCode(), 4));
276+
result += Integer.rotateLeft(Boolean.valueOf(isStaticIcon()).hashCode(), 5);
277+
result += Integer.rotateLeft(Boolean.valueOf(isPersistent()).hashCode(), 6);
278+
return result;
279+
}
280+
281+
/**
282+
* Uses our custom hashCode for SdlFile objects
283+
* @param o - The object to compare
284+
* @return boolean of whether the objects are the same or not
285+
*/
286+
@Override
287+
public boolean equals(Object o) {
288+
if (o == null) return false;
289+
// if this is the same memory address, it's the same
290+
if (this == o) return true;
291+
// if this is not an instance of SdlFile, not the same
292+
if (!(o instanceof SdlFile)) return false;
293+
// return comparison
294+
return hashCode() == o.hashCode();
295+
}
263296
}

0 commit comments

Comments
 (0)