Skip to content

Commit 462249a

Browse files
Add enum elements to the RPCGenericTests map
1 parent f8d2c4e commit 462249a

1 file changed

Lines changed: 61 additions & 9 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/RPCGenericTests.java

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class RPCGenericTests {
3636

3737
private final String XML_FILE_NAME = "MOBILE_API.xml";
3838
private final String RPC_PACKAGE_PREFIX = "com.smartdevicelink.proxy.rpc.";
39+
private final String ENUM_PACKAGE_PREFIX = "com.smartdevicelink.proxy.rpc.enums.";
3940
private final String TEST_VALUES_CLASS = "com.smartdevicelink.test.TestValues";
4041
private Map<String, RPC> rpcMandatoryParamsMapFromXml;
4142
private Map<String, RPC> rpcAllParamsMapFromXml;
@@ -45,7 +46,8 @@ private class RPC {
4546
private String type;
4647
private boolean isDeprecated;
4748
private boolean skip;
48-
private List<Parameter> parameters;
49+
private List<Parameter> parameters; // For functions and structs
50+
private List<Element> elements; // For enums
4951

5052
public RPC setRPCName(String rpcName) {
5153
this.rpcName = rpcName;
@@ -71,6 +73,11 @@ public RPC setParameters(List<Parameter> parameters) {
7173
this.parameters = parameters;
7274
return this;
7375
}
76+
77+
public RPC setElements(List<Element> elements) {
78+
this.elements = elements;
79+
return this;
80+
}
7481
}
7582

7683
private class Parameter {
@@ -147,6 +154,33 @@ public Parameter setSkip(boolean skip) {
147154
}
148155
}
149156

157+
private class Element {
158+
private String rpcName;
159+
private String name;
160+
private boolean isDeprecated;
161+
private boolean skip;
162+
163+
public Element setRPCName(String rpcName) {
164+
this.rpcName = rpcName;
165+
return this;
166+
}
167+
168+
public Element setName(String name) {
169+
this.name = name;
170+
return this;
171+
}
172+
173+
public Element setDeprecated(boolean deprecated) {
174+
isDeprecated = deprecated;
175+
return this;
176+
}
177+
178+
public Element setSkip(boolean skip) {
179+
this.skip = skip;
180+
return this;
181+
}
182+
}
183+
150184
@Before
151185
public void setUp() {
152186
// Map that has keys correspond to the RPCs names and values correspond to RPCs properties and their params
@@ -171,6 +205,7 @@ private Map<String, RPC> getRPCsMap(String fileName, boolean includeMandatoryPar
171205
String getterMethodName2;
172206
Class<?> javaParamType;
173207
boolean skipParam;
208+
boolean skipElement;
174209
while (event != XmlPullParser.END_DOCUMENT) {
175210
String elementType = myParser.getName();
176211
switch (event) {
@@ -204,10 +239,12 @@ private Map<String, RPC> getRPCsMap(String fileName, boolean includeMandatoryPar
204239
.setType(elementType)
205240
.setDeprecated(isDeprecated)
206241
.setSkip(skipRPC)
207-
.setParameters(new ArrayList<Parameter>());
242+
.setParameters(new ArrayList<Parameter>())
243+
.setElements(new ArrayList<Element>());
208244
rpcParamsMap.put(rpcName, rpc);
209245

210246
}
247+
211248
// Store the params for the current RPC in the map
212249
if (elementType.equals("param") && myParser.getAttributeValue(null, "until") == null) {
213250
setterMethodName = null;
@@ -366,6 +403,20 @@ private Map<String, RPC> getRPCsMap(String fileName, boolean includeMandatoryPar
366403
rpcParamsMap.get(rpcName).parameters.add(param);
367404
}
368405
}
406+
407+
// Store the elements for the current RPC in the map
408+
if (elementType.equals("element") && myParser.getAttributeValue(null, "until") == null) {
409+
skipElement = false;
410+
String elementName = myParser.getAttributeValue(null, "name");
411+
412+
Element element = new Element()
413+
.setRPCName(rpcName)
414+
.setName(elementName)
415+
.setDeprecated(isDeprecated)
416+
.setSkip(skipElement);
417+
418+
rpcParamsMap.get(rpcName).elements.add(element);
419+
}
369420
break;
370421
}
371422
event = myParser.next();
@@ -386,8 +437,8 @@ private boolean isDeprecated (AnnotatedElement element) {
386437
return false;
387438
}
388439

389-
// This method makes sure that for every RPC, there is a constructor that has all the mandatory params
390-
// It also checks if there are RPC in the XML file that don't exist in the code
440+
// This method makes sure that for every function and struct RPC, there is a constructor that has all the mandatory params
441+
// It also checks if there are function and struct RPCs in the XML file that don't exist in the code
391442
@Test
392443
public void testMandatoryParamsMatch() {
393444
// List of RPC names that don't have a constructor that has all mandatory params
@@ -526,7 +577,7 @@ private Class<?> findJavaTypeForParam(String type, boolean isArray) {
526577
return javaType;
527578
}
528579

529-
// This method makes sure that for every RPC, the constructor that has the mandatory params is setting the values correctly
580+
// This method makes sure that for every function and struct RPC, the constructor that has the mandatory params is setting the values correctly
530581
@Test
531582
public void testMandatoryParamsValues() {
532583
// List of RPC names that have a constructor which is not settings the values for the mandatory params correctly
@@ -618,13 +669,14 @@ public void testMandatoryParamsValues() {
618669
}
619670

620671
/**
621-
* This method makes sure that for every param in every RPC:
622-
* - A setter exists and its name matches the RPC spec
672+
* This method makes sure that for every function and struct RPC, the class exists in the code
673+
* and its annotations match the RPC spec. And for every param in that RPC:
674+
* - A setter exists and its name & annotations match the RPC spec
623675
* - The setter return type matches the RPC type (to make RPCs chainable)
624-
* - A getter exists and its name matches the RPC spec
676+
* - A getter exists and its name & annotations match the RPC spec
625677
*/
626678
@Test
627-
public void testParamsSettersAndGetters() {
679+
public void testFunctionsAndStructs() {
628680
List<String> errors = new ArrayList<>();
629681

630682
// Loop through all RPCs that were loaded from RPC spec XML file

0 commit comments

Comments
 (0)