From 130cfa256f4802415bc612547d443740d65dab7a Mon Sep 17 00:00:00 2001 From: rtrimana Date: Mon, 28 Nov 2016 15:27:30 -0800 Subject: [PATCH] Testing for list/vector data types --- config/iotpolicy/testclasspolicy.pol | 15 ++++++ iotjava/iotrmi/C++/IoTRMIUtil.hpp | 8 +++ iotjava/iotrmi/C++/basics/TestClass.hpp | 50 +++++++++++++++++++ iotjava/iotrmi/C++/basics/TestClass_Stub.cpp | 29 +++++++++++ iotjava/iotrmi/Java/basics/TestClass.java | 43 ++++++++++++++++ .../iotrmi/Java/basics/TestClass_Stub.java | 18 +++++++ 6 files changed, 163 insertions(+) diff --git a/config/iotpolicy/testclasspolicy.pol b/config/iotpolicy/testclasspolicy.pol index e2b70cc..36ded08 100644 --- a/config/iotpolicy/testclasspolicy.pol +++ b/config/iotpolicy/testclasspolicy.pol @@ -16,6 +16,14 @@ public interface TestClassInterface { public boolean[] getBooleanArray(boolean in[]); public char[] getCharArray(char in[]); + public List getByteList(List in); + public List getShortList(List in); + public List getLongList(List in); + public List getFloatList(List in); + public List getDoubleList(List in); + public List getBooleanList(List in); + public List getCharList(List in); + public int getA(); public void setA(int _int); public void setB(float _float); @@ -40,6 +48,13 @@ public interface TestClassInterface { method = "getDoubleArray(double in[])"; method = "getBooleanArray(boolean in[])"; method = "getCharArray(char in[])"; + method = "getByteList(List in)"; + method = "getShortList(List in)"; + method = "getLongList(List in)"; + method = "getFloatList(List in)"; + method = "getDoubleList(List in)"; + method = "getBooleanList(List in)"; + method = "getCharList(List in)"; method = "getA()"; method = "setA(int _int)"; method = "setB(float _float)"; diff --git a/iotjava/iotrmi/C++/IoTRMIUtil.hpp b/iotjava/iotrmi/C++/IoTRMIUtil.hpp index 5da411c..2c3be17 100644 --- a/iotjava/iotrmi/C++/IoTRMIUtil.hpp +++ b/iotjava/iotrmi/C++/IoTRMIUtil.hpp @@ -300,6 +300,10 @@ void* IoTRMIUtil::getParamObject(void* retObj, const char* type, char* paramByte } else if ( string(type).find("*") != string::npos) { // This is an array type, i.e. vector retObj = getArrayParamObject(retObj, type, paramBytes, len); + } else if ( (string(type).find("<") != string::npos) && + (string(type).find(">") != string::npos)) { + // This is a vector/list type + retObj = getArrayParamObject(retObj, type, paramBytes, len); } else { cerr << "IoTRMIUtil: Unrecognizable type: " << type << endl; exit(-1); @@ -389,6 +393,10 @@ char* IoTRMIUtil::getObjectBytes(char* retObjBytes, void* obj, const char* type) } else if ( string(type).find("*") != string::npos) { // This is an array type, i.e. vector retObjBytes = getArrayObjectBytes(retObjBytes, obj, type); + } else if ( (string(type).find("<") != string::npos) && + (string(type).find(">") != string::npos)) { + // This is a vector/list type + retObjBytes = getArrayObjectBytes(retObjBytes, obj, type); } else { cerr << "IoTRMIUtil: Unrecognizable type: " << type << endl; exit(-1); diff --git a/iotjava/iotrmi/C++/basics/TestClass.hpp b/iotjava/iotrmi/C++/basics/TestClass.hpp index 24fe1ac..fe758d7 100644 --- a/iotjava/iotrmi/C++/basics/TestClass.hpp +++ b/iotjava/iotrmi/C++/basics/TestClass.hpp @@ -29,6 +29,14 @@ class TestClass : public TestClassInterface { vector getBooleanArray(vector in); vector getCharArray(vector in); + vector getByteList(vector in); + vector getShortList(vector in); + vector getLongList(vector in); + vector getFloatList(vector in); + vector getDoubleList(vector in); + vector getBooleanList(vector in); + vector getCharList(vector in); + int getA(); void setA(int _int); void setB(float _float); @@ -147,6 +155,48 @@ vector TestClass::getCharArray(vector in) { return in; } +// List +vector TestClass::getByteList(vector in) { + + return in; +} + + +vector TestClass::getShortList(vector in) { + + return in; +} + + +vector TestClass::getLongList(vector in) { + + return in; +} + + +vector TestClass::getFloatList(vector in) { + + return in; +} + + +vector TestClass::getDoubleList(vector in) { + + return in; +} + + +vector TestClass::getBooleanList(vector in) { + + return in; +} + + +vector TestClass::getCharList(vector in) { + + return in; +} + int TestClass::getA() { diff --git a/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp b/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp index 1d8ad91..bac2b0e 100644 --- a/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp +++ b/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp @@ -53,6 +53,35 @@ int main(int argc, char *argv[]) in7.push_back('c'); in7.push_back('e'); cout << "Return value: " << tcStub->getCharArray(in7)[0] << ", " << tcStub->getCharArray(in7)[1] << endl; + cout << "==== VECTOR/LIST ====" << endl; + vector inl1; + inl1.push_back(68); + inl1.push_back(69); + cout << "Return value: " << tcStub->getByteList(inl1)[0] << ", " << tcStub->getByteList(inl1)[1] << endl; + vector inl2; + inl2.push_back(1234); + inl2.push_back(1235); + cout << "Return value: " << tcStub->getShortList(inl2)[0] << ", " << tcStub->getShortList(inl2)[1] << endl; + vector inl3; + inl3.push_back(12345678); + inl3.push_back(12356782); + cout << "Return value: " << tcStub->getLongList(inl3)[0] << ", " << tcStub->getLongList(inl3)[1] << endl; + vector inl4; + inl4.push_back(12.345); + inl4.push_back(12.346); + cout << "Return value: " << tcStub->getFloatList(inl4)[0] << ", " << tcStub->getFloatList(inl4)[1] << endl; + vector inl5; + inl5.push_back(12345.678); + inl5.push_back(12345.543); + cout << "Return value: " << tcStub->getDoubleList(inl5)[0] << ", " << tcStub->getDoubleList(inl5)[1] << endl; + vector inl6; + inl6.push_back(true); + inl6.push_back(false); + cout << "Return value: " << tcStub->getBooleanList(inl6)[0] << ", " << tcStub->getBooleanList(inl6)[1] << endl; + vector inl7; + inl7.push_back('c'); + inl7.push_back('e'); + cout << "Return value: " << tcStub->getCharList(inl7)[0] << ", " << tcStub->getCharList(inl7)[1] << endl; cout << "==== OTHERS ====" << endl; cout << "Return value: " << tcStub->getA() << endl; cout << "Return value: " << tcStub->setAndGetA(123) << endl; diff --git a/iotjava/iotrmi/Java/basics/TestClass.java b/iotjava/iotrmi/Java/basics/TestClass.java index 4f55242..6373238 100644 --- a/iotjava/iotrmi/Java/basics/TestClass.java +++ b/iotjava/iotrmi/Java/basics/TestClass.java @@ -116,6 +116,49 @@ public class TestClass implements TestClassInterface { } + // Lists + public List getByteList(List in) { + + return in; + } + + + public List getShortList(List in) { + + return in; + } + + + public List getLongList(List in) { + + return in; + } + + + public List getFloatList(List in) { + + return in; + } + + + public List getDoubleList(List in) { + + return in; + } + + + public List getBooleanList(List in) { + + return in; + } + + + public List getCharList(List in) { + + return in; + } + + // Other functions public int getA() { diff --git a/iotjava/iotrmi/Java/basics/TestClass_Stub.java b/iotjava/iotrmi/Java/basics/TestClass_Stub.java index 01b1bdd..67b69dc 100644 --- a/iotjava/iotrmi/Java/basics/TestClass_Stub.java +++ b/iotjava/iotrmi/Java/basics/TestClass_Stub.java @@ -1,4 +1,6 @@ import java.util.Arrays; +import java.util.List; +import java.util.ArrayList; import iotruntime.master.CommunicationHandler; public class TestClass_Stub { @@ -42,6 +44,22 @@ public class TestClass_Stub { char[] in7 = { 'c', 'e' }; System.out.println("Return value: " + Arrays.toString(tcstub.getCharArray(in7))); + System.out.println("==== LIST ===="); + List inl1 = Arrays.asList(new Byte[] { 68, 69 }); + System.out.println("Return value: " + tcstub.getByteList(inl1)); + List inl2 = Arrays.asList(new Short[] { (short)1234, (short)1235 }); + System.out.println("Return value: " + tcstub.getShortList(inl2)); + List inl3 = Arrays.asList(new Long[] { 12345678l, 12356782l }); + System.out.println("Return value: " + tcstub.getLongList(inl3)); + List inl4 = Arrays.asList(new Float[] { 12.345f, 12.346f }); + System.out.println("Return value: " + tcstub.getFloatList(inl4)); + List inl5 = Arrays.asList(new Double[] { 12345.678, 12345.543 }); + System.out.println("Return value: " + tcstub.getDoubleList(inl5)); + List inl6 = Arrays.asList(new Boolean[] { true, false }); + System.out.println("Return value: " + tcstub.getBooleanList(inl6)); + List inl7 = Arrays.asList(new Character[] { 'c', 'e' }); + System.out.println("Return value: " + tcstub.getCharList(inl7)); + System.out.println("==== OTHERS ===="); System.out.println("Return value: " + tcstub.getA()); System.out.println("Return value: " + tcstub.setAndGetA(123)); -- 2.34.1