You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/03/02 08:32:10 UTC
svn commit: r1296071 - in /incubator/etch/trunk/binding-cpp/runtime:
include/common/EtchList.h include/common/EtchNativeArray.h
include/common/EtchObject.h src/test/common/EtchNativeArrayTest.cpp
Author: veithm
Date: Fri Mar 2 07:32:09 2012
New Revision: 1296071
URL: http://svn.apache.org/viewvc?rev=1296071&view=rev
Log:
ETCH-150 Implementation of basic primitive data types for the NSDL
some neccessary fixes
Change-Id: I2fb79dc482150dfd5b1f43ea33aa2b0e57d85ccc
Modified:
incubator/etch/trunk/binding-cpp/runtime/include/common/EtchList.h
incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNativeArray.h
incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h
incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchNativeArrayTest.cpp
Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchList.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchList.h?rev=1296071&r1=1296070&r2=1296071&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchList.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchList.h Fri Mar 2 07:32:09 2012
@@ -1,213 +1,213 @@
-/* $Id$
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version
- * 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __ETCHLIST_H__
-#define __ETCHLIST_H__
-
-#include "common/EtchObject.h"
-#include "common/EtchComparator.h"
-#include "capu/container/List.h"
-
-template <class T, class C = EtchComparator<T> >
-class EtchList : public EtchObject {
-private:
- capu::List<T, C> mList;
-
-public:
-
- typedef typename capu::List<T, C>::Iterator Iterator;
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ETCHLIST_H__
+#define __ETCHLIST_H__
+
+#include "common/EtchObject.h"
+#include "common/EtchComparator.h"
+#include "capu/container/List.h"
+
+template <class T, class C = EtchComparator<T> >
+class EtchList : public EtchObject {
+private:
+ capu::List<T, C> mList;
+
+public:
+
+ typedef typename capu::List<T, C>::Iterator Iterator;
static const EtchObjectType TYPE;
-
- /**
- * Default Constructor
- */
- EtchList();
-
- /**
- * Destructor
- */
- ~EtchList();
-
- /**
- * Add element to the end of list
- * @param element element that will be added
- * @return ETCH_ENO_MEMORY if allocation of element is failed
- * ETCH_OK if the element is successfully added
- */
+
+ /**
+ * Default Constructor
+ */
+ EtchList();
+
+ /**
+ * Destructor
+ */
+ ~EtchList();
+
+ /**
+ * Add element to the end of list
+ * @param element element that will be added
+ * @return ETCH_ENO_MEMORY if allocation of element is failed
+ * ETCH_OK if the element is successfully added
+ */
status_t add(const T &element);
-
- /**
- * It will insert new element to specified position only the element at specified index with given element
- *
- * @param index index of element which will be inserted
- * @param element new value that will replace the old value
- *
- * @return ETCH_EINVAL if given index is invalid.
- * ETCH_ENO_MEMORY if allocation of element is failed
- * ETCH_OK if the element is successfully added
- * ETCH_ERROR otherwise
- */
+
+ /**
+ * It will insert new element to specified position only the element at specified index with given element
+ *
+ * @param index index of element which will be inserted
+ * @param element new value that will replace the old value
+ *
+ * @return ETCH_EINVAL if given index is invalid.
+ * ETCH_ENO_MEMORY if allocation of element is failed
+ * ETCH_OK if the element is successfully added
+ * ETCH_ERROR otherwise
+ */
status_t add(capu::int32_t index, const T &element);
-
- /**
- * remove the element in the specified index and if the element_old
- * parameter is not NULL, the removed element will be put to element_old
- * @param index index of element that will be removed
- * @param elementOld the buffer which will keep the copy of the removed element
- * @return ETCH_EINVAL invalid index
- * ETCH_OK if the element is successfully removed
- */
- status_t removeAt(capu::int32_t index, T* elementOld = NULL);
-
- /**
- * get a single element on specified index
- * @param index index of element that will be get
- * @param result the buffer that the retrieved element will be stored
- * @return ETCH_EINVAL invalid index
- * ETCH_OK otherwise
- */
- status_t get(capu::int32_t index, T* result);
-
- /**
- * return size of list
- * @return return the size of list
- */
- capu::int32_t size();
-
- /**
- * check the list is empty or not
- * @return true if empty
- * false otherwise
- */
- capu::bool_t isEmpty();
-
- /**
- * returns an iterator pointing to the beginning of list
- * @return iterator
- */
- Iterator begin();
-
- /**
- * finds the index of given element in the link list
- * if you are using an object you need to overload == operator
- *
- * @param element the value that will be searched
- * @return -1 if the value either does not exist or given value is NULL
- * otherwise index of value on linked list
- */
+
+ /**
+ * remove the element in the specified index and if the element_old
+ * parameter is not NULL, the removed element will be put to element_old
+ * @param index index of element that will be removed
+ * @param elementOld the buffer which will keep the copy of the removed element
+ * @return ETCH_EINVAL invalid index
+ * ETCH_OK if the element is successfully removed
+ */
+ status_t removeAt(capu::int32_t index, T* elementOld = NULL);
+
+ /**
+ * get a single element on specified index
+ * @param index index of element that will be get
+ * @param result the buffer that the retrieved element will be stored
+ * @return ETCH_EINVAL invalid index
+ * ETCH_OK otherwise
+ */
+ status_t get(capu::int32_t index, T* result);
+
+ /**
+ * return size of list
+ * @return return the size of list
+ */
+ capu::int32_t size();
+
+ /**
+ * check the list is empty or not
+ * @return true if empty
+ * false otherwise
+ */
+ capu::bool_t isEmpty();
+
+ /**
+ * returns an iterator pointing to the beginning of list
+ * @return iterator
+ */
+ Iterator begin();
+
+ /**
+ * finds the index of given element in the link list
+ * if you are using an object you need to overload == operator
+ *
+ * @param element the value that will be searched
+ * @return -1 if the value either does not exist or given value is NULL
+ * otherwise index of value on linked list
+ */
capu::int32_t find(const T &element);
-
- /**
- *
- * @param index the index of element that will be replaced
- * @param element element that will be overwritten to existing place
- * @param elementOld the buffer to keep the existing
- * @return ETCH_EINVAL if the index is not valid
- * ETCH_OK otherwise
- */
+
+ /**
+ *
+ * @param index the index of element that will be replaced
+ * @param element element that will be overwritten to existing place
+ * @param elementOld the buffer to keep the existing
+ * @return ETCH_EINVAL if the index is not valid
+ * ETCH_OK otherwise
+ */
status_t set(capu::int32_t index, const T &element, T* elementOld = NULL);
-
- /**
- * check that if the list contains the given parameter or not
- * if you are using an object you need to overload == operator
- * @param element element that will be checked
- * @return true list contains it
- * false otherwise
- */
+
+ /**
+ * check that if the list contains the given parameter or not
+ * if you are using an object you need to overload == operator
+ * @param element element that will be checked
+ * @return true list contains it
+ * false otherwise
+ */
capu::bool_t contains(const T &element);
-
- /**
- * removes all elements from linked list
- *
- * @return ETCH_OK if all of the elements are deleted
- *
- */
- status_t clear();
-
-};
-
-template<class T, class C>
+
+ /**
+ * removes all elements from linked list
+ *
+ * @return ETCH_OK if all of the elements are deleted
+ *
+ */
+ status_t clear();
+
+};
+
+template<class T, class C>
const EtchObjectType EtchList<T, C>::TYPE(EOTID_LIST, NULL);
template<class T, class C>
-EtchList<T, C>::EtchList()
+EtchList<T, C>::EtchList()
: EtchObject(&EtchList<T, C>::TYPE) {
-
-}
-
-template<class T, class C>
-EtchList<T, C>::~EtchList() {
-
-}
-
-template<class T, class C>
+
+}
+
+template<class T, class C>
+EtchList<T, C>::~EtchList() {
+
+}
+
+template<class T, class C>
status_t EtchList<T, C>::add(const T &element) {
- return mList.add(element);
-}
-
-template<class T, class C>
+ return mList.add(element);
+}
+
+template<class T, class C>
status_t EtchList<T, C>::add(capu::int32_t index, const T &element) {
- return mList.add(index, element);
-}
-
-template<class T, class C>
-typename EtchList<T, C>::Iterator EtchList<T, C>::begin() {
- return mList.begin();
-}
-
-template<class T, class C>
-status_t EtchList<T, C>::clear() {
- return mList.clear();
-}
-
-template<class T, class C>
+ return mList.add(index, element);
+}
+
+template<class T, class C>
+typename EtchList<T, C>::Iterator EtchList<T, C>::begin() {
+ return mList.begin();
+}
+
+template<class T, class C>
+status_t EtchList<T, C>::clear() {
+ return mList.clear();
+}
+
+template<class T, class C>
capu::bool_t EtchList<T, C>::contains(const T &element) {
- return mList.contains(element);
-}
-
-template<class T, class C>
+ return mList.contains(element);
+}
+
+template<class T, class C>
capu::int32_t EtchList<T, C>::find(const T &element) {
- return mList.find(element);
-}
-
-template<class T, class C>
-status_t EtchList<T, C>::get(capu::int32_t index, T* result) {
- return mList.get(index, result);
-}
-
-template<class T, class C>
-capu::bool_t EtchList<T, C>::isEmpty() {
- return mList.isEmpty();
-}
-
-template<class T, class C>
-status_t EtchList<T, C>::removeAt(capu::int32_t index, T* elementOld) {
- return mList.removeAt(index, elementOld);
-}
-
-template<class T, class C>
-capu::int32_t EtchList<T, C>::size() {
- return mList.size();
-}
-
-template<class T, class C>
+ return mList.find(element);
+}
+
+template<class T, class C>
+status_t EtchList<T, C>::get(capu::int32_t index, T* result) {
+ return mList.get(index, result);
+}
+
+template<class T, class C>
+capu::bool_t EtchList<T, C>::isEmpty() {
+ return mList.isEmpty();
+}
+
+template<class T, class C>
+status_t EtchList<T, C>::removeAt(capu::int32_t index, T* elementOld) {
+ return mList.removeAt(index, elementOld);
+}
+
+template<class T, class C>
+capu::int32_t EtchList<T, C>::size() {
+ return mList.size();
+}
+
+template<class T, class C>
capu::int32_t EtchList<T, C>::set(capu::int32_t index, const T &element, T* elementOld) {
- return mList.set(index, element, elementOld);
-}
-#endif /* ETCHDOUBLELINKEDLIST_H */
-
+ return mList.set(index, element, elementOld);
+}
+#endif /* ETCHDOUBLELINKEDLIST_H */
+
Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNativeArray.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNativeArray.h?rev=1296071&r1=1296070&r2=1296071&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNativeArray.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNativeArray.h Fri Mar 2 07:32:09 2012
@@ -35,12 +35,12 @@ public:
/**
* Constructs a EtchNativeArray object.
*/
- EtchNativeArray(capu::int32_t length);
+ EtchNativeArray(capu::int32_t length, const EtchObjectType* content_type_id);
/**
* Constructs a EtchNativeArray object.
*/
- EtchNativeArray(capu::int32_t length, T* array);
+ EtchNativeArray(capu::int32_t length, T* array, const EtchObjectType* content_type_id);
/**
* Destructor for Etch Nativearray.
@@ -49,6 +49,11 @@ public:
virtual ~EtchNativeArray();
/**
+ * returns the TypeID of the content of this native array.
+ */
+ const EtchObjectType* getContentType();
+
+ /**
* gets the EtchObject at index i in result
* returns ETCH_ERANGE, if out of bounds.
* returns ETCH_OK otherwise
@@ -100,32 +105,49 @@ public:
* Returns the pointer to the beginning of array
*/
T* getArray();
+ /**
+ * set the content type id will be deleted or not
+ */
+ void setDeleteMode(capu::bool_t isDelete);
private:
T* mArray;
+ capu::bool_t mIsDeleteContentType;
capu::int32_t mLength;
+ const EtchObjectType* mContentType;
};
template<class T>
const EtchObjectType EtchNativeArray<T>::TYPE(EOTID_NATIVE_ARRAY, EtchObjectType::getType<T>());
template<class T>
-EtchNativeArray<T>::EtchNativeArray(capu::int32_t length)
-: EtchObject(&EtchNativeArray::TYPE),
+EtchNativeArray<T>::EtchNativeArray(capu::int32_t length, const EtchObjectType* content_type_id)
+: EtchObject(&EtchNativeArray::TYPE), mIsDeleteContentType(false),
mLength(length) {
mArray = new T[length];
+ mContentType = content_type_id;
}
template<class T>
-EtchNativeArray<T>::EtchNativeArray(capu::int32_t length, T* array)
-: EtchObject(&EtchNativeArray::TYPE), mArray(array),
+EtchNativeArray<T>::EtchNativeArray(capu::int32_t length, T* array, const EtchObjectType* content_type_id)
+: EtchObject(&EtchNativeArray::TYPE), mArray(array), mIsDeleteContentType(false),
mLength(length) {
-
+ mContentType = content_type_id;
}
template<class T>
EtchNativeArray<T>::~EtchNativeArray() {
delete[] mArray;
+
+ if (mIsDeleteContentType && (mContentType != NULL)) {
+ const EtchObjectType * content = mContentType->getObjectComponentType();
+ while (content) {
+ const EtchObjectType * tmp = content;
+ content = content->getObjectComponentType();
+ delete tmp;
+ }
+ delete mContentType;
+ }
}
template<class T>
@@ -138,12 +160,17 @@ status_t EtchNativeArray<T>::set(capu::i
}
template<class T>
-T* EtchNativeArray<T>::getArray() {
+const EtchObjectType * EtchNativeArray<T>::getContentType() {
+ return mContentType;
+}
+
+template<class T >
+T * EtchNativeArray<T>::getArray() {
return mArray;
}
-template<class T>
-status_t EtchNativeArray<T>::get(capu::int32_t index, T* result) {
+template<class T >
+status_t EtchNativeArray<T>::get(capu::int32_t index, T * result) {
if (result == NULL) {
return ETCH_EINVAL;
} else if (0 <= index && index < mLength) {
@@ -153,7 +180,7 @@ status_t EtchNativeArray<T>::get(capu::i
return ETCH_ERANGE;
}
-template<class T>
+template<class T >
status_t EtchNativeArray<T>::set(capu::int32_t index, T* buffer, capu::int32_t buffer_size, capu::int32_t offset, capu::int32_t count) {
if (buffer == NULL) {
return ETCH_EINVAL;
@@ -168,7 +195,7 @@ status_t EtchNativeArray<T>::set(capu::i
return ETCH_ERANGE;
}
-template<class T>
+template<class T >
status_t EtchNativeArray<T>::get(capu::int32_t index, T* buffer, capu::int32_t buffer_size, capu::int32_t offset, capu::int32_t count) {
if (buffer == NULL) {
return ETCH_EINVAL;
@@ -184,8 +211,13 @@ status_t EtchNativeArray<T>::get(capu::i
return ETCH_ERANGE;
}
-template<class T>
+template<class T >
capu::int32_t EtchNativeArray<T>::getLength() {
return mLength;
}
+
+template<class T>
+void EtchNativeArray<T>::setDeleteMode(capu::bool_t isDelete) {
+ mIsDeleteContentType = isDelete;
+}
#endif //__ETCHNATIVEARRAY_H__
Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h?rev=1296071&r1=1296070&r2=1296071&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h Fri Mar 2 07:32:09 2012
@@ -23,7 +23,6 @@
#include "EtchObjectType.h"
class EtchObject {
-
public:
/**
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchNativeArrayTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchNativeArrayTest.cpp?rev=1296071&r1=1296070&r2=1296071&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchNativeArrayTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchNativeArrayTest.cpp Fri Mar 2 07:32:09 2012
@@ -20,180 +20,202 @@
#include "common/EtchInt32.h"
#include "common/EtchNativeArray.h"
-
TEST(EtchNativeArrayTest, Constructor_Default) {
EtchNativeArray<EtchInt32*>* na =
- new EtchNativeArray<EtchInt32*>(10);
- delete na;
+ new EtchNativeArray<EtchInt32*>(10, &EtchInt32::TYPE);
+ delete na;
}
TEST(EtchNativeArrayTest, Constructor_Array) {
- EtchInt32* int1 = new EtchInt32(42);
- EtchInt32* int2 = new EtchInt32(43);
+ EtchInt32* int1 = new EtchInt32(42);
+ EtchInt32* int2 = new EtchInt32(43);
- EtchNativeArray<EtchInt32*>* na1 =
- new EtchNativeArray<EtchInt32*>(2);
+ EtchNativeArray<EtchInt32*>* na1 =
+ new EtchNativeArray<EtchInt32*>(2, &EtchInt32::TYPE);
- na1->set(0, int1);
- na1->set(1, int2);
+ na1->set(0, int1);
+ na1->set(1, int2);
- EXPECT_TRUE(na1->getObjectType()->equals(&EtchNativeArray<EtchInt32*>::TYPE));
-
- EtchInt32* value = NULL;
- int i = 0;
- for(i = 0; i < 2; i++) {
- status_t ret = na1->get(i, &value);
- ASSERT_EQ(ETCH_OK, ret);
- ASSERT_EQ(42 + i, value->get());
- }
+ EXPECT_TRUE(na1->getObjectType()->equals(&EtchNativeArray<EtchInt32*>::TYPE));
+ EtchInt32* value = NULL;
+ int i = 0;
+ for (i = 0; i < 2; i++) {
status_t ret = na1->get(i, &value);
- ASSERT_EQ(ETCH_ERANGE, ret);
+ ASSERT_EQ(ETCH_OK, ret);
+ ASSERT_EQ(42 + i, value->get());
+ }
+
+ status_t ret = na1->get(i, &value);
+ ASSERT_EQ(ETCH_ERANGE, ret);
- delete na1;
- delete int1;
- delete int2;
+ delete na1;
+ delete int1;
+ delete int2;
}
TEST(EtchNativeArrayTest, setget) {
- EtchInt32* int1 = new EtchInt32(42);
- EtchInt32* int2 = new EtchInt32(43);
- EtchNativeArray<EtchInt32*>* na1 =
- new EtchNativeArray<EtchInt32*>(2);
- EXPECT_TRUE(na1->getObjectType()->equals(&EtchNativeArray<EtchInt32*>::TYPE));
-
- na1->set(0, int1);
- na1->set(1, int2);
-
- EtchInt32* value = NULL;
- int i = 0;
- for(i = 0; i < 2; i++) {
- status_t ret = na1->get(i, &value);
- ASSERT_EQ(ETCH_OK, ret);
- ASSERT_EQ(42 + i, value->get());
- }
-
- EtchInt32* newValue = new EtchInt32(44);
+ EtchInt32* int1 = new EtchInt32(42);
+ EtchInt32* int2 = new EtchInt32(43);
+ EtchNativeArray<EtchInt32*>* na1 =
+ new EtchNativeArray<EtchInt32*>(2, &EtchInt32::TYPE);
+ EXPECT_TRUE(na1->getObjectType()->equals(&EtchNativeArray<EtchInt32*>::TYPE));
+
+ na1->set(0, int1);
+ na1->set(1, int2);
+
+ EtchInt32* value = NULL;
+ int i = 0;
+ for (i = 0; i < 2; i++) {
+ status_t ret = na1->get(i, &value);
+ ASSERT_EQ(ETCH_OK, ret);
+ ASSERT_EQ(42 + i, value->get());
+ }
- na1->set(1, newValue);
+ EtchInt32* newValue = new EtchInt32(44);
- status_t ret = na1->get(1, &value);
- ASSERT_EQ(ETCH_OK, ret);
- ASSERT_EQ(44, newValue->get());
+ na1->set(1, newValue);
- //Test setget of block
- EtchNativeArray<EtchInt32*> *native_array = new EtchNativeArray<EtchInt32*> (2);
- EtchInt32** int3 = new EtchInt32*[2];
- int3[0] = new EtchInt32();
- int3[1] = new EtchInt32();
-
- int3[0]->set(2);
- int3[1]->set(4);
-
- ret = native_array->set(0,NULL,0,0,0);
- EXPECT_TRUE(ret == ETCH_EINVAL);
-
- ret = native_array->get(0,NULL,0,0,0);
- EXPECT_TRUE(ret == ETCH_EINVAL);
-
- ret = native_array->set(0,int3,2,0,2);
- EXPECT_TRUE(ret == ETCH_OK);
-
- EtchInt32** int6 = new EtchInt32*[2];
- ret = native_array->get(0,int6,2,0,2);
- EXPECT_TRUE(ret == ETCH_OK);
-
- EXPECT_TRUE(int6[0]->get() == 2);
- EXPECT_TRUE(int6[1]->get() == 4);
-
- //Test setget of block of native type
- EtchNativeArray<int> *native_array2 = new EtchNativeArray<int> (2);
- int int4[2];
- int int5[2];
- int4[0] = 3;
- int4[1] = 5;
-
- ret = native_array2->set(0,NULL,0,0,0);
- EXPECT_TRUE(ret == ETCH_EINVAL);
-
- ret = native_array2->get(0,NULL,0,0,0);
- EXPECT_TRUE(ret == ETCH_EINVAL);
-
- ret = native_array2->set(0,(int*) int4,2,0,2);
- EXPECT_TRUE(ret == ETCH_OK);
-
- ret = native_array2->get(0,(int* )int5,2,0,2);
- EXPECT_TRUE(ret == ETCH_OK);
-
- EXPECT_TRUE(int5[0] == 3);
- EXPECT_TRUE(int5[1] == 5);
-
- //index out of bounds
- ret = native_array2->set(5,(int*) int4,2,0,2);
- EXPECT_TRUE(ret == ETCH_ERANGE);
-
- //buffer size smaller then count
- ret = native_array2->set(0,(int*) int4,1,0,2);
- EXPECT_TRUE(ret == ETCH_ERANGE);
-
- //offset + count out of range
- ret = native_array2->set(0,(int*) int4,2,2,2);
- EXPECT_TRUE(ret == ETCH_ERANGE);
-
- //index out of bounds
- ret = native_array2->get(5,(int*) int5,2,0,2);
- EXPECT_TRUE(ret == ETCH_ERANGE);
-
- //buffer size smaller then count
- ret = native_array2->get(0,(int*) int5,1,0,2);
- EXPECT_TRUE(ret == ETCH_ERANGE);
-
- //offset + count out of range
- ret = native_array2->set(0,(int*) int5,2,2,2);
- EXPECT_TRUE(ret == ETCH_ERANGE);
-
- delete int3[0];
- delete int3[1];
- delete[] int3;
- delete[] int6;
- delete na1;
- delete int1;
- delete int2;
- delete newValue;
- delete native_array;
- delete native_array2;
+ status_t ret = na1->get(1, &value);
+ ASSERT_EQ(ETCH_OK, ret);
+ ASSERT_EQ(44, newValue->get());
+
+ //Test setget of block
+ EtchNativeArray<EtchInt32*> *native_array = new EtchNativeArray<EtchInt32*> (2, &EtchInt32::TYPE);
+ EtchInt32** int3 = new EtchInt32*[2];
+ int3[0] = new EtchInt32();
+ int3[1] = new EtchInt32();
+
+ int3[0]->set(2);
+ int3[1]->set(4);
+
+ ret = native_array->set(0, NULL, 0, 0, 0);
+ EXPECT_TRUE(ret == ETCH_EINVAL);
+
+ ret = native_array->get(0, NULL, 0, 0, 0);
+ EXPECT_TRUE(ret == ETCH_EINVAL);
+
+ ret = native_array->set(0, int3, 2, 0, 2);
+ EXPECT_TRUE(ret == ETCH_OK);
+
+ EtchInt32** int6 = new EtchInt32*[2];
+ ret = native_array->get(0, int6, 2, 0, 2);
+ EXPECT_TRUE(ret == ETCH_OK);
+
+ EXPECT_TRUE(int6[0]->get() == 2);
+ EXPECT_TRUE(int6[1]->get() == 4);
+
+ //Test setget of block of native type
+ EtchNativeArray<int> *native_array2 = new EtchNativeArray<int> (2, &EtchObjectType::NATIVE_INT32);
+ capu::int32_t int4[2];
+ capu::int32_t int5[2];
+ int4[0] = 3;
+ int4[1] = 5;
+
+ ret = native_array2->set(0, NULL, 0, 0, 0);
+ EXPECT_TRUE(ret == ETCH_EINVAL);
+
+ ret = native_array2->get(0, NULL, 0, 0, 0);
+ EXPECT_TRUE(ret == ETCH_EINVAL);
+
+ ret = native_array2->set(0, (int*) int4, 2, 0, 2);
+ EXPECT_TRUE(ret == ETCH_OK);
+
+ ret = native_array2->get(0, (int*) int5, 2, 0, 2);
+ EXPECT_TRUE(ret == ETCH_OK);
+
+ EXPECT_TRUE(int5[0] == 3);
+ EXPECT_TRUE(int5[1] == 5);
+
+ //index out of bounds
+ ret = native_array2->set(5, (int*) int4, 2, 0, 2);
+ EXPECT_TRUE(ret == ETCH_ERANGE);
+
+ //buffer size smaller then count
+ ret = native_array2->set(0, (int*) int4, 1, 0, 2);
+ EXPECT_TRUE(ret == ETCH_ERANGE);
+
+ //offset + count out of range
+ ret = native_array2->set(0, (int*) int4, 2, 2, 2);
+ EXPECT_TRUE(ret == ETCH_ERANGE);
+
+ //index out of bounds
+ ret = native_array2->get(5, (int*) int5, 2, 0, 2);
+ EXPECT_TRUE(ret == ETCH_ERANGE);
+
+ //buffer size smaller then count
+ ret = native_array2->get(0, (int*) int5, 1, 0, 2);
+ EXPECT_TRUE(ret == ETCH_ERANGE);
+
+ //offset + count out of range
+ ret = native_array2->set(0, (int*) int5, 2, 2, 2);
+ EXPECT_TRUE(ret == ETCH_ERANGE);
+
+ delete int3[0];
+ delete int3[1];
+ delete[] int3;
+ delete[] int6;
+ delete na1;
+ delete int1;
+ delete int2;
+ delete newValue;
+ delete native_array;
+ delete native_array2;
}
TEST(EtchNativeArrayTest, multiDimensionalArrays) {
- EtchInt32* int1 = new EtchInt32(1);
- EtchInt32* int2 = new EtchInt32(2);
- EtchInt32* int3 = new EtchInt32(3);
- EtchInt32* int4 = new EtchInt32(4);
-
- EtchNativeArray<EtchInt32*>* subArray1 = new EtchNativeArray<EtchInt32*>(2);
- EtchNativeArray<EtchInt32*>* subArray2 = new EtchNativeArray<EtchInt32*>(2);
- subArray1->set(0,int1);
- subArray1->set(1,int2);
- subArray2->set(0,int3);
- subArray2->set(1,int4);
-
- EtchNativeArray<EtchNativeArray<EtchInt32*>*>* mainArray = new EtchNativeArray<EtchNativeArray<EtchInt32*>*>(2);
- mainArray->set(0,subArray1);
- mainArray->set(1,subArray2);
- const EtchObjectType *ot = mainArray->getObjectType();
- //get type of main array
- EXPECT_TRUE(ot->equals(&EtchNativeArray<EtchNativeArray<EtchInt32*>*>::TYPE));
- //get component type of main array = type of subarray
- EXPECT_TRUE(ot->getObjectComponentType()->equals(&EtchNativeArray<EtchInt32*>::TYPE));
- //get component type of subarray
- EXPECT_TRUE(ot->getObjectComponentType()->getObjectComponentType()->equals(&EtchInt32::TYPE));
-
- EtchNativeArray<EtchInt32*>* result;
- mainArray->get(0,&result);
- EtchInt32* int5;
- result->get(0,&int5);
- EXPECT_EQ(1,int5->get());
-}
\ No newline at end of file
+ EtchInt32* int1 = new EtchInt32(1);
+ EtchInt32* int2 = new EtchInt32(2);
+ EtchInt32* int3 = new EtchInt32(3);
+ EtchInt32* int4 = new EtchInt32(4);
+
+ EtchNativeArray<EtchInt32*>* subArray1 = new EtchNativeArray<EtchInt32*>(2, &EtchInt32::TYPE);
+ EtchNativeArray<EtchInt32*>* subArray2 = new EtchNativeArray<EtchInt32*>(2, &EtchInt32::TYPE);
+ subArray1->set(0, int1);
+ subArray1->set(1, int2);
+ subArray2->set(0, int3);
+ subArray2->set(1, int4);
+
+ EtchNativeArray<EtchNativeArray<EtchInt32*>*>* mainArray = new EtchNativeArray<EtchNativeArray<EtchInt32*>*>(2, &EtchNativeArray<EtchNativeArray<EtchInt32*>*>::TYPE);
+ mainArray->set(0, subArray1);
+ mainArray->set(1, subArray2);
+ const EtchObjectType *ot = mainArray->getObjectType();
+ //get type of main array
+ EXPECT_TRUE(ot->equals(&EtchNativeArray<EtchNativeArray<EtchInt32*>*>::TYPE));
+ //get component type of main array = type of subarray
+ EXPECT_TRUE(ot->getObjectComponentType()->equals(&EtchNativeArray<EtchInt32*>::TYPE));
+ //get component type of subarray
+ EXPECT_TRUE(ot->getObjectComponentType()->getObjectComponentType()->equals(&EtchInt32::TYPE));
+
+ EtchNativeArray<EtchInt32*>* result;
+ mainArray->get(0, &result);
+ EtchInt32* int5;
+ result->get(0, &int5);
+ EXPECT_EQ(1, int5->get());
+
+ delete int1;
+ delete int2;
+ delete int3;
+ delete int4;
+
+ delete subArray1;
+ delete subArray2;
+ delete mainArray;
+}
+
+TEST(EtchNativeArrayTest, DeleteModeTest) {
+ EtchNativeArray<EtchInt32*>* Array1 = new EtchNativeArray<EtchInt32*>(2, &EtchInt32::TYPE);
+ Array1->setDeleteMode(false);
+ EtchNativeArray<EtchInt32*>* Array2 = new EtchNativeArray<EtchInt32*>(2, new EtchObjectType(EOTID_INT32, NULL));
+ Array2->setDeleteMode(true);
+ EtchNativeArray<EtchInt32*>* Array3 = new EtchNativeArray<EtchInt32*>(2, NULL);
+ Array3->setDeleteMode(true);
+
+
+ delete Array1;
+ delete Array2;
+ delete Array3;
+}