summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilal Alsharifi <599206+bilal-alsharifi@users.noreply.github.com>2019-10-11 13:32:07 -0400
committerGitHub <noreply@github.com>2019-10-11 13:32:07 -0400
commitcae0a9fa025a3b73758996c81fb44dd59c8bf2e9 (patch)
tree8353aea63792b5be85f36e83bc8ecbb48279dcb8
parent25216910ec03589a1d03a5d21c26947569dd6f40 (diff)
parent3b6f97fd000678a453bb047b10ac802fb6fb12f6 (diff)
downloadsdl_android-cae0a9fa025a3b73758996c81fb44dd59c8bf2e9.tar.gz
Merge pull request #1196 from smartdevicelink/bugfix/issue_1193
Fix Issue 1193 and fix clone operations
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/SdlArtworkTests.java50
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java47
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java35
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java40
-rw-r--r--base/src/main/java/com/smartdevicelink/proxy/rpc/enums/StaticIconName.java4
-rw-r--r--javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java32
6 files changed, 145 insertions, 63 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/SdlArtworkTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/SdlArtworkTests.java
new file mode 100644
index 000000000..395b06e27
--- /dev/null
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/SdlArtworkTests.java
@@ -0,0 +1,50 @@
+package com.smartdevicelink.managers.file;
+
+import com.smartdevicelink.AndroidTestCase2;
+import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
+import com.smartdevicelink.proxy.rpc.enums.StaticIconName;
+import com.smartdevicelink.test.Test;
+
+public class SdlArtworkTests extends AndroidTestCase2 {
+
+ public void testClone(){
+ SdlArtwork original = Test.GENERAL_ARTWORK;
+ SdlArtwork clone = original.clone();
+
+ equalTest(original, clone);
+
+
+ SdlArtwork artwork = new SdlArtwork(StaticIconName.ALBUM);
+ assertNotNull(artwork);
+
+ SdlArtwork staticIconClone = artwork.clone();
+ assertNotNull(staticIconClone);
+
+
+ assertTrue(clone instanceof Cloneable);
+ assertTrue(artwork instanceof Cloneable);
+
+ }
+
+ public static boolean equalTest(SdlArtwork original, SdlArtwork clone){
+
+ assertNotNull(original);
+ assertNotNull(clone);
+ assertNotSame(original,clone);
+
+
+ assertEquals(original.getResourceId(), clone.getResourceId());
+
+ assertEquals(original.getFileData(), clone.getFileData());
+
+ assertNotNull(original.getImageRPC());
+ assertNotNull(clone.getImageRPC());
+
+ assertNotSame(original.getImageRPC(),clone.getImageRPC());
+ assertEquals(original.getImageRPC().getIsTemplate(), clone.getImageRPC().getIsTemplate());
+ assertEquals(original.getImageRPC().getValue(), clone.getImageRPC().getValue());
+ assertEquals(original.getImageRPC().getImageType(), clone.getImageRPC().getImageType());
+
+ return true;
+ }
+}
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java
index f19fb4a6b..0a629d808 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java
@@ -33,9 +33,14 @@
package com.smartdevicelink.managers.screen.menu;
import com.smartdevicelink.AndroidTestCase2;
+import com.smartdevicelink.managers.file.SdlArtworkTests;
+import com.smartdevicelink.proxy.rpc.enums.MenuLayout;
import com.smartdevicelink.proxy.rpc.enums.TriggerSource;
import com.smartdevicelink.test.Test;
+import java.util.ArrayList;
+import java.util.List;
+
public class MenuCellTests extends AndroidTestCase2 {
@@ -115,4 +120,46 @@ public class MenuCellTests extends AndroidTestCase2 {
assertFalse(menuCell.equals(menuCell3));
}
+ public void testClone(){
+ MenuCell original = new MenuCell(Test.GENERAL_STRING, Test.GENERAL_ARTWORK, Test.GENERAL_STRING_LIST, menuSelectionListener);
+ MenuCell clone = original.clone();
+
+ assertNotNull(clone);
+ assertNotSame(original, clone);
+
+ assertEquals(original.getTitle(), clone.getTitle());
+ assertEquals(original.getCellId(), clone.getCellId());
+ assertEquals(original.getParentCellId(), clone.getParentCellId());
+
+ SdlArtworkTests.equalTest(original.getIcon(), clone.getIcon());
+
+ //Test subcells
+ List<MenuCell> subcells = new ArrayList<>();
+ subcells.add(original.clone());
+ subcells.add(clone.clone());
+
+ original = new MenuCell(Test.GENERAL_STRING, MenuLayout.LIST, Test.GENERAL_ARTWORK,subcells);
+ clone = original.clone();
+
+ assertNotNull(original.getSubCells());
+ assertNotNull(clone.getSubCells());
+ assertNotSame(original.getSubCells(), clone.getSubCells());
+
+ List<MenuCell> originalSubCells = original.getSubCells();
+ List<MenuCell> cloneSubCells = clone.getSubCells();
+
+ assertEquals(originalSubCells.size(), cloneSubCells.size());
+
+ for(int i = 0; i < originalSubCells.size(); i++){
+
+ assertNotNull(originalSubCells.get(i));
+ assertNotNull(cloneSubCells.get(i));
+
+ assertNotSame(originalSubCells.get(i), cloneSubCells.get(i));
+ }
+
+
+
+ }
+
}
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java
index b1885d1a9..e7db70ee6 100644
--- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java
+++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java
@@ -39,6 +39,7 @@ import com.smartdevicelink.proxy.rpc.Image;
import com.smartdevicelink.proxy.rpc.enums.FileType;
import com.smartdevicelink.proxy.rpc.enums.ImageType;
import com.smartdevicelink.proxy.rpc.enums.StaticIconName;
+import com.smartdevicelink.util.DebugTool;
/**
* A class that extends SdlFile, representing artwork (JPEG, PNG, or BMP) to be uploaded to core
@@ -110,8 +111,8 @@ public class SdlArtwork extends SdlFile implements Cloneable{
}
@Override
- public void setType(@NonNull FileType fileType) {
- if(fileType.equals(FileType.GRAPHIC_JPEG) || fileType.equals(FileType.GRAPHIC_PNG)
+ public void setType(FileType fileType) {
+ if(fileType == null || fileType.equals(FileType.GRAPHIC_JPEG) || fileType.equals(FileType.GRAPHIC_PNG)
|| fileType.equals(FileType.GRAPHIC_BMP)){
super.setType(fileType);
}else{
@@ -144,31 +145,21 @@ public class SdlArtwork extends SdlFile implements Cloneable{
/**
* Creates a deep copy of the object
- * @return deep copy of the object
+ * @return deep copy of the object, null if an exception occurred
*/
@Override
public SdlArtwork clone() {
- final SdlArtwork clone;
- try {
- clone = (SdlArtwork) super.clone();
+ try{
+ SdlArtwork artwork = (SdlArtwork) super.clone();
+ if(artwork != null){
+ artwork.imageRPC = artwork.createImageRPC();
+ }
+ return artwork;
} catch (CloneNotSupportedException e) {
- throw new RuntimeException("superclass messed up", e);
- }
- clone.setName(this.getName());
- clone.setResourceId(this.getResourceId());
- clone.setUri(this.getUri() == null ? null : Uri.parse(this.getUri().toString()));
- if (this.getFileData() != null){
- byte[] data = new byte[this.getFileData().length];
- for (int i = 0; i < this.getFileData().length; i++) {
- data[i] = this.getFileData()[i];
+ if(DebugTool.isDebugEnabled()){
+ throw new RuntimeException("Clone not supported by super class");
}
- clone.setFileData(data);
}
- clone.setType(this.getType());
- clone.setPersistent(this.isPersistent());
- clone.setStaticIcon(this.isStaticIcon());
- clone.isTemplate = this.isTemplate;
- clone.imageRPC = this.createImageRPC();
- return clone;
+ return null;
}
} \ No newline at end of file
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java
index 519dcad93..5265bb6b9 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java
@@ -37,6 +37,7 @@ import android.support.annotation.Nullable;
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
import com.smartdevicelink.proxy.rpc.enums.MenuLayout;
+import com.smartdevicelink.util.DebugTool;
import java.util.ArrayList;
import java.util.List;
@@ -322,33 +323,30 @@ public class MenuCell implements Cloneable{
/**
* Creates a deep copy of the object
- * @return deep copy of the object
+ * @return deep copy of the object, null if an exception occurred
*/
@Override
public MenuCell clone() {
- final MenuCell clone;
try {
- clone = (MenuCell) super.clone();
+ MenuCell clone = (MenuCell) super.clone();
+ if(this.icon != null){
+ clone.icon = this.icon.clone();
+ }
+ if(this.subCells != null){
+ ArrayList<MenuCell> cloneSubCells = new ArrayList<>();
+ for(MenuCell subCell : subCells){
+ cloneSubCells.add(subCell.clone());
+ }
+ clone.subCells = cloneSubCells;
+ }
+
+ return clone;
} catch (CloneNotSupportedException e) {
- throw new RuntimeException("superclass messed up", e);
- }
- clone.title = this.title;
- clone.icon = this.icon == null ? null : this.icon.clone();
- clone.voiceCommands = null;
- if (this.voiceCommands != null){
- clone.voiceCommands = new ArrayList<>();
- clone.voiceCommands.addAll(this.voiceCommands);
- }
- clone.subCells = null;
- if (this.subCells != null) {
- clone.subCells = new ArrayList<>();
- for (MenuCell subCell : this.subCells) {
- clone.subCells.add(subCell == null ? null : subCell.clone());
+ if(DebugTool.isDebugEnabled()){
+ throw new RuntimeException("Clone not supported by super class");
}
}
- clone.menuSelectionListener = this.menuSelectionListener;
- clone.parentCellId = this.parentCellId;
- clone.cellId = this.cellId;
- return clone;
+
+ return null;
}
}
diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/StaticIconName.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/StaticIconName.java
index 03e321e61..cf5d50976 100644
--- a/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/StaticIconName.java
+++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/enums/StaticIconName.java
@@ -933,6 +933,10 @@ public enum StaticIconName {
return null;
}
+ /**
+ * Returns the string representation of the hex value associated with this static icon
+ * @return string of the hex value representation of this static icon
+ */
@Override
public String toString() {
return INTERNAL_NAME;
diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java b/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java
index f13b523aa..eb947fe0a 100644
--- a/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java
+++ b/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java
@@ -36,6 +36,7 @@ import com.smartdevicelink.proxy.rpc.Image;
import com.smartdevicelink.proxy.rpc.enums.FileType;
import com.smartdevicelink.proxy.rpc.enums.ImageType;
import com.smartdevicelink.proxy.rpc.enums.StaticIconName;
+import com.smartdevicelink.util.DebugTool;
/**
* A class that extends SdlFile, representing artwork (JPEG, PNG, or BMP) to be uploaded to core
@@ -97,8 +98,8 @@ public class SdlArtwork extends SdlFile implements Cloneable{
@Override
- public void setType(@NonNull FileType fileType) {
- if(fileType.equals(FileType.GRAPHIC_JPEG) || fileType.equals(FileType.GRAPHIC_PNG)
+ public void setType(FileType fileType) {
+ if(fileType == null || fileType.equals(FileType.GRAPHIC_JPEG) || fileType.equals(FileType.GRAPHIC_PNG)
|| fileType.equals(FileType.GRAPHIC_BMP)){
super.setType(fileType);
}else{
@@ -135,26 +136,17 @@ public class SdlArtwork extends SdlFile implements Cloneable{
*/
@Override
public SdlArtwork clone() {
- final SdlArtwork clone;
- try {
- clone = (SdlArtwork) super.clone();
+ try{
+ SdlArtwork artwork = (SdlArtwork) super.clone();
+ if(artwork != null){
+ artwork.imageRPC = artwork.createImageRPC();
+ }
+ return artwork;
} catch (CloneNotSupportedException e) {
- throw new RuntimeException("superclass messed up", e);
- }
- clone.setName(this.getName());
- clone.setFilePath(this.getFilePath());
- if (this.getFileData() != null){
- byte[] data = new byte[this.getFileData().length];
- for (int i = 0; i < this.getFileData().length; i++) {
- data[i] = this.getFileData()[i];
+ if(DebugTool.isDebugEnabled()){
+ throw new RuntimeException("Clone not supported by super class");
}
- clone.setFileData(data);
}
- clone.setType(this.getType());
- clone.setPersistent(this.isPersistent());
- clone.setStaticIcon(this.isStaticIcon());
- clone.isTemplate = this.isTemplate;
- clone.imageRPC = this.createImageRPC();
- return clone;
+ return null;
}
} \ No newline at end of file