Skip to content

Commit d82ddd8

Browse files
authored
Merge pull request #1266 from smartdevicelink/feature/Image_upload_management
Generate name for SdlFile if not provided by developers
2 parents 1d4d523 + 363dd08 commit d82ddd8

7 files changed

Lines changed: 321 additions & 56 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/SdlArtworkTests.java renamed to android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/file/filetypes/SdlArtworkTests.java

File renamed without changes.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright (c) 2019 Livio, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following
13+
* disclaimer in the documentation and/or other materials provided with the
14+
* distribution.
15+
*
16+
* Neither the name of the Livio Inc. nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
package com.smartdevicelink.managers.file.filetypes;
34+
35+
import com.smartdevicelink.AndroidTestCase2;
36+
import com.smartdevicelink.test.Test;
37+
38+
public class SdlFileTests extends AndroidTestCase2 {
39+
40+
public void testConstructorWithNoParams() {
41+
SdlFile sdlFile;
42+
43+
// Case 1 (Setting data)
44+
sdlFile = new SdlFile();
45+
sdlFile.setFileData(Test.GENERAL_BYTE_ARRAY);
46+
assertEquals(sdlFile.getFileData(), Test.GENERAL_BYTE_ARRAY);
47+
sdlFile.setName(null);
48+
assertEquals(sdlFile.getName(), "e9800998ecf8427e");
49+
sdlFile.setName(Test.GENERAL_STRING);
50+
assertEquals(sdlFile.getName(), Test.GENERAL_STRING);
51+
sdlFile.setType(Test.GENERAL_FILETYPE);
52+
assertEquals(sdlFile.getType(), Test.GENERAL_FILETYPE);
53+
sdlFile.setPersistent(Test.GENERAL_BOOLEAN);
54+
assertEquals(sdlFile.isPersistent(), Test.GENERAL_BOOLEAN);
55+
56+
// Case 2 (Setting resourceId)
57+
sdlFile = new SdlFile();
58+
sdlFile.setResourceId(Test.GENERAL_INTEGER);
59+
assertEquals((Integer) sdlFile.getResourceId(), Test.GENERAL_INTEGER);
60+
sdlFile.setName(null);
61+
assertEquals(sdlFile.getName(), "ec9ebc78777cf40d");
62+
sdlFile.setName(Test.GENERAL_STRING);
63+
assertEquals(sdlFile.getName(), Test.GENERAL_STRING);
64+
sdlFile.setType(Test.GENERAL_FILETYPE);
65+
assertEquals(sdlFile.getType(), Test.GENERAL_FILETYPE);
66+
sdlFile.setPersistent(Test.GENERAL_BOOLEAN);
67+
assertEquals(sdlFile.isPersistent(), Test.GENERAL_BOOLEAN);
68+
69+
// Case 3 (Setting URI)
70+
sdlFile = new SdlFile();
71+
sdlFile.setUri(Test.GENERAL_URI);
72+
assertEquals(sdlFile.getUri(), Test.GENERAL_URI);
73+
sdlFile.setName(null);
74+
assertEquals(sdlFile.getName(), "d3467db131372140");
75+
sdlFile.setName(Test.GENERAL_STRING);
76+
assertEquals(sdlFile.getName(), Test.GENERAL_STRING);
77+
sdlFile.setType(Test.GENERAL_FILETYPE);
78+
assertEquals(sdlFile.getType(), Test.GENERAL_FILETYPE);
79+
sdlFile.setPersistent(Test.GENERAL_BOOLEAN);
80+
assertEquals(sdlFile.isPersistent(), Test.GENERAL_BOOLEAN);
81+
}
82+
83+
public void testConstructorWithResourceId() {
84+
// Case1 (Set the name manually)
85+
SdlFile sdlFile1 = new SdlFile(Test.GENERAL_STRING, Test.GENERAL_FILETYPE, Test.GENERAL_INTEGER, Test.GENERAL_BOOLEAN);
86+
assertEquals(sdlFile1.getName(), Test.GENERAL_STRING);
87+
assertEquals(sdlFile1.getType(), Test.GENERAL_FILETYPE);
88+
assertEquals((Integer) sdlFile1.getResourceId(), Test.GENERAL_INTEGER);
89+
assertEquals(sdlFile1.isPersistent(), Test.GENERAL_BOOLEAN);
90+
91+
// Case2 (Let the library generate a name)
92+
SdlFile sdlFile2 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_INTEGER, Test.GENERAL_BOOLEAN);
93+
SdlFile sdlFile3 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_INTEGER, Test.GENERAL_BOOLEAN);
94+
assertEquals(sdlFile2.getName(), sdlFile3.getName());
95+
assertEquals(sdlFile2.getName(), "ec9ebc78777cf40d");
96+
assertEquals(sdlFile2.getType(), Test.GENERAL_FILETYPE);
97+
assertEquals((Integer) sdlFile2.getResourceId(), Test.GENERAL_INTEGER);
98+
assertEquals(sdlFile2.isPersistent(), Test.GENERAL_BOOLEAN);
99+
}
100+
101+
public void testConstructorWithData() {
102+
// Case1 (Set the name manually)
103+
SdlFile sdlFile1 = new SdlFile(Test.GENERAL_STRING, Test.GENERAL_FILETYPE, Test.GENERAL_BYTE_ARRAY, Test.GENERAL_BOOLEAN);
104+
assertEquals(sdlFile1.getName(), Test.GENERAL_STRING);
105+
assertEquals(sdlFile1.getType(), Test.GENERAL_FILETYPE);
106+
assertEquals(sdlFile1.getFileData(), Test.GENERAL_BYTE_ARRAY);
107+
assertEquals(sdlFile1.isPersistent(), Test.GENERAL_BOOLEAN);
108+
109+
// Case2 (Let the library generate a name)
110+
SdlFile sdlFile2 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_BYTE_ARRAY, Test.GENERAL_BOOLEAN);
111+
SdlFile sdlFile3 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_BYTE_ARRAY, Test.GENERAL_BOOLEAN);
112+
assertEquals(sdlFile2.getName(), sdlFile3.getName());
113+
assertEquals(sdlFile2.getName(), "e9800998ecf8427e");
114+
assertEquals(sdlFile2.getType(), Test.GENERAL_FILETYPE);
115+
assertEquals(sdlFile2.getFileData(), Test.GENERAL_BYTE_ARRAY);
116+
assertEquals(sdlFile2.isPersistent(), Test.GENERAL_BOOLEAN);
117+
}
118+
119+
public void testConstructorWithUri() {
120+
// Case1 (Set the name manually)
121+
SdlFile sdlFile1 = new SdlFile(Test.GENERAL_STRING, Test.GENERAL_FILETYPE, Test.GENERAL_URI, Test.GENERAL_BOOLEAN);
122+
assertEquals(sdlFile1.getName(), Test.GENERAL_STRING);
123+
assertEquals(sdlFile1.getType(), Test.GENERAL_FILETYPE);
124+
assertEquals(sdlFile1.getUri(), Test.GENERAL_URI);
125+
assertEquals(sdlFile1.isPersistent(), Test.GENERAL_BOOLEAN);
126+
127+
// Case2 (Let the library generate a name)
128+
SdlFile sdlFile2 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_URI, Test.GENERAL_BOOLEAN);
129+
SdlFile sdlFile3 = new SdlFile(null, Test.GENERAL_FILETYPE, Test.GENERAL_URI, Test.GENERAL_BOOLEAN);
130+
assertEquals(sdlFile2.getName(), sdlFile3.getName());
131+
assertEquals(sdlFile2.getName(), "d3467db131372140");
132+
assertEquals(sdlFile2.getType(), Test.GENERAL_FILETYPE);
133+
assertEquals(sdlFile2.getUri(), Test.GENERAL_URI);
134+
assertEquals(sdlFile2.isPersistent(), Test.GENERAL_BOOLEAN);
135+
}
136+
}

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.smartdevicelink.test;
22

33
import android.graphics.Color;
4+
import android.net.Uri;
45
import android.util.Log;
56

67
import com.smartdevicelink.R;
@@ -264,6 +265,7 @@ public class Test {
264265
public static final ImageField GENERAL_IMAGEFIELD = new ImageField();
265266
public static final DeviceInfo GENERAL_DEVICEINFO = new DeviceInfo();
266267
public static final AppInfo GENERAL_APPINFO = new AppInfo();
268+
public static final Uri GENERAL_URI = Uri.parse("http://www.google.com");;
267269
public static final LayoutMode GENERAL_LAYOUTMODE = LayoutMode.LIST_ONLY;
268270
public static final MenuParams GENERAL_MENUPARAMS = new MenuParams();
269271
public static final SoftButton GENERAL_SOFTBUTTON = new SoftButton();

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,34 +55,34 @@ public SdlArtwork() {}
5555

5656
/**
5757
* Creates a new instance of SdlArtwork
58-
* @param fileName a String value representing the name that will be used to store the file in the head unit
58+
* @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name
5959
* @param fileType a FileType enum value representing the type of the file
6060
* @param id an int value representing the android resource id of the file
6161
* @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles
6262
*/
63-
public SdlArtwork(@NonNull String fileName, @NonNull FileType fileType, int id, boolean persistentFile) {
63+
public SdlArtwork(String fileName, @NonNull FileType fileType, int id, boolean persistentFile) {
6464
super(fileName, fileType, id, persistentFile);
6565
}
6666

6767
/**
6868
* Creates a new instance of SdlArtwork
69-
* @param fileName a String value representing the name that will be used to store the file in the head unit
69+
* @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name
7070
* @param fileType a FileType enum value representing the type of the file
7171
* @param uri a URI value representing a file's location. Currently, it only supports local files
7272
* @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles
7373
*/
74-
public SdlArtwork(@NonNull String fileName, @NonNull FileType fileType, Uri uri, boolean persistentFile) {
74+
public SdlArtwork(String fileName, @NonNull FileType fileType, Uri uri, boolean persistentFile) {
7575
super(fileName, fileType, uri, persistentFile);
7676
}
7777

7878
/**
7979
* Creates a new instance of SdlArtwork
80-
* @param fileName a String value representing the name that will be used to store the file in the head unit
80+
* @param fileName a String value representing the name that will be used to store the file in the head unit. You can pass null if you want the library to auto generate the name
8181
* @param fileType a FileType enum value representing the type of the file
8282
* @param data a byte array representing the data of the file
8383
* @param persistentFile a boolean value that indicates if the file is meant to persist between sessions / ignition cycles
8484
*/
85-
public SdlArtwork(@NonNull String fileName, @NonNull FileType fileType, byte[] data, boolean persistentFile) {
85+
public SdlArtwork(String fileName, @NonNull FileType fileType, byte[] data, boolean persistentFile) {
8686
super(fileName, fileType, data, persistentFile);
8787
}
8888

0 commit comments

Comments
 (0)