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/01/12 11:08:47 UTC
svn commit: r1230468 - in /incubator/etch/trunk/binding-cpp/runtime:
include/common/EtchComparator.h include/common/EtchError.h
include/common/EtchList.h src/test/common/EtchListTest.cpp
Author: veithm
Date: Thu Jan 12 10:08:46 2012
New Revision: 1230468
URL: http://svn.apache.org/viewvc?rev=1230468&view=rev
Log:
ETCH-135 Double Linked List Etch Wrapper
Change-Id: I282ee8a50ca6b31f420bd564fcd2baaeea29434b
Added:
incubator/etch/trunk/binding-cpp/runtime/include/common/EtchComparator.h
Modified:
incubator/etch/trunk/binding-cpp/runtime/include/common/EtchError.h
incubator/etch/trunk/binding-cpp/runtime/include/common/EtchList.h
incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchListTest.cpp
Added: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchComparator.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchComparator.h?rev=1230468&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchComparator.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchComparator.h Thu Jan 12 10:08:46 2012
@@ -0,0 +1,151 @@
+/* $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 __ETCHCOMPARATOR_H__
+#define __ETCHCOMPARATOR_H__
+#include "common/EtchString.h"
+
+template <class T>
+class EtchComparator {
+public:
+
+ inline capu::bool_t operator() (T first, T second) {
+ return first.equals(&second);
+ }
+};
+
+template <class T>
+class EtchComparator <T*> {
+public:
+
+ inline capu::bool_t operator() (T* first, T* second) {
+ return first->equals(second);
+ }
+};
+
+template<>
+class EtchComparator <capu::int32_t> {
+public:
+
+ inline capu::bool_t operator() (capu::int32_t first, capu::int32_t second) {
+ return first == second;
+ }
+};
+
+template<>
+class EtchComparator <capu::int32_t*> {
+public:
+
+ inline capu::bool_t operator() (capu::int32_t* first, capu::int32_t* second) {
+ return *first == *second;
+ }
+};
+
+template<>
+class EtchComparator <capu::double_t> {
+public:
+
+ inline capu::bool_t operator() (capu::double_t first, capu::double_t second) {
+ return first == second;
+ }
+};
+
+template<>
+class EtchComparator <capu::double_t*> {
+public:
+
+ inline capu::bool_t operator() (capu::double_t* first, capu::double_t* second) {
+ return *first == *second;
+ }
+};
+
+template<>
+class EtchComparator <capu::int64_t> {
+public:
+
+ inline capu::bool_t operator() (capu::int64_t first, capu::int64_t second) {
+ return first == second;
+ }
+};
+
+template<>
+class EtchComparator <capu::int64_t*> {
+public:
+
+ inline capu::bool_t operator() (capu::int64_t* first, capu::int64_t* second) {
+ return *first == *second;
+ }
+};
+
+template<>
+class EtchComparator <capu::int8_t*> {
+public:
+
+ inline capu::bool_t operator() (capu::int8_t* first, capu::int8_t* second) {
+ return *first == *second;
+ }
+};
+
+template<>
+class EtchComparator <capu::int8_t> {
+public:
+
+ inline capu::bool_t operator() (capu::int8_t* first, capu::int8_t* second) {
+ return *first == *second;
+ }
+};
+
+template<>
+class EtchComparator <capu::int16_t> {
+public:
+
+ inline capu::bool_t operator() (capu::int16_t first, capu::int16_t second) {
+ return first == second;
+ }
+};
+
+template<>
+class EtchComparator <capu::int16_t*> {
+public:
+
+ inline capu::bool_t operator() (capu::int16_t* first, capu::int16_t* second) {
+ return *first == *second;
+ }
+};
+
+template<>
+class EtchComparator <capu::bool_t*> {
+public:
+
+ inline capu::bool_t operator() (capu::bool_t* first, capu::bool_t* second) {
+ return *first == *second;
+ }
+};
+
+template<>
+class EtchComparator <capu::bool_t> {
+public:
+
+ inline capu::bool_t operator() (capu::bool_t first, capu::bool_t second) {
+ return first == second;
+ }
+};
+
+#endif
Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchError.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchError.h?rev=1230468&r1=1230467&r2=1230468&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchError.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchError.h Thu Jan 12 10:08:46 2012
@@ -1,19 +1,19 @@
-/* $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,
+/* $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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
#ifndef __ETCHERROR_H__
@@ -24,10 +24,23 @@
typedef capu::int32_t status_t;
enum {
- ETCH_OK = 0,
- ETCH_EUNIMPL = 1,
- ETCH_ERANGE = 2,
- ETCH_EINVAL = 3
+
+ //RANGE BETWEEN 0X0000 AND 0XFFFF are shared with CAPU
+ ETCH_OK = 0,
+ ETCH_EUNIMPL = 1,
+ ETCH_ERANGE = 2,
+ ETCH_EINVAL = 3,
+ ETCH_ERROR = 4,
+ ETCH_SOCKET_EBIND = 5,
+ ETCH_SOCKET_ESOCKET = 6,
+ ETCH_SOCKET_ECONNECT = 7,
+ ETCH_SOCKET_ELISTEN = 8,
+ ETCH_SOCKET_ECLOSE = 9,
+ ETCH_SOCKET_EADDR = 10,
+ ETCH_ENO_MEMORY = 11,
+ ETCH_TIMEOUT = 12,
+ ETCH_ENOT_EXIST = 13
+ //RANGE BETWEEN 0XFFFF TO OXFFFFFFF ARE ERROR CODES FOR ONLY ETCH
};
#endif
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=1230468&r1=1230467&r2=1230468&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchList.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchList.h Thu Jan 12 10:08:46 2012
@@ -1,123 +1,211 @@
-/* $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,
+/* $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.
+ * 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/EtchError.h"
+#include "common/EtchComparator.h"
+#include "capu/container/List.h"
-/**
- * String type.
- */
-template <class T>
-class EtchList :
- public EtchObject
-{
+template <class T, class C = EtchComparator<T> >
+class EtchList : public EtchObject {
private:
- /**
- * Internal ListItem
- */
- class Item
- {
- public:
- Item()
- {
- next = NULL;
- }
-
- T data;
- Item* next;
- };
+
+ capu::List<T, C> mList;
public:
- /**
- * TypeId for EtchList.
- */
- static const capu::int32_t TYPE_ID = EOTID_LIST;
-
- /**
- * Constructs EtchList.
- */
- EtchList();
-
- /**
- * Destructure.
- */
- virtual ~EtchList();
-
- /**
- * Add a new element to the list.
- */
- void add(T data);
-
- /**
- * Get element at index.
- */
- status_t get(capu::int32_t index, T* data);
+ typedef typename capu::List<T, C>::Iterator Iterator;
+ static const capu::int32_t TYPE_ID = EOTID_LIST;
+
+ /**
+ * 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
+ */
+ 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
+ */
+ 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
+ */
+ status_t set(capu::int32_t index, 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
+ */
+ 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();
-private:
- Item* m_head;
- Item* m_tail;
};
-template<class T>
-EtchList<T>::EtchList()
- : EtchObject(EtchList<T>::TYPE_ID)
- , m_head(NULL)
- , m_tail(NULL)
-{
-}
-
-template<class T>
-EtchList<T>::~EtchList()
-{
- if(m_head != NULL) {
- Item* item = m_head;
- while(item != NULL) {
- Item* delete_item = item;
- item = item->next;
- delete delete_item;
- }
- }
-}
-
-template<class T>
-void EtchList<T>::add(T data)
-{
- Item* item = new Item();
- item->data = data;
- item->next = NULL;
-
- if(m_tail == NULL) {
- m_head = item;
- m_tail = item;
- } else {
- m_tail->next = item;
- m_tail = item;
- }
-}
-
-template<class T>
-status_t EtchList<T>::get(capu::int32_t index, T* data)
-{
- return ETCH_EUNIMPL;
+template<class T, class C>
+EtchList<T, C>::EtchList()
+: EtchObject(EtchList<T, C>::TYPE_ID) {
+
+}
+
+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>
+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>
+capu::bool_t EtchList<T, C>::contains(const T element) {
+ 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>
+capu::int32_t EtchList<T, C>::set(capu::int32_t index, T element, T* elementOld) {
+ return mList.set(index, element, elementOld);
}
+#endif /* ETCHDOUBLELINKEDLIST_H */
-#endif
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchListTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchListTest.cpp?rev=1230468&r1=1230467&r2=1230468&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchListTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchListTest.cpp Thu Jan 12 10:08:46 2012
@@ -1,47 +1,371 @@
-/* $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,
+/* $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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
#include <gtest/gtest.h>
#include "common/EtchInt32.h"
#include "common/EtchList.h"
-// Tests positive input.
-TEST(EtchListTest, Constructor_Default) {
- EtchList<EtchInt32*>* l1 = new EtchList<EtchInt32*>();
- delete l1;
-}
-
-TEST(EtchListTest, add) {
- //EtchList<EtchInt32*>* l1 = new EtchList<EtchInt32*>();
- //add smart pointer here
- //l1->add(new EtchInt32(42));
- EtchList<capu::int32_t>* l1 = new EtchList<capu::int32_t>();
- l1->add(42);
- l1->add(84);
- delete l1;
-}
-
-TEST(EtchListTest, get) {
- //EtchList<EtchInt32*>* l1 = new EtchList<EtchInt32*>();
- //add smart pointer here
- //l1->add(new EtchInt32(42));
- //EtchList<capu::int32_t>* l1 = new EtchList<capu::int32_t>();
- //l1->add(42);
- //l1->add(84);
- //delete l1;
+TEST(EtchList, Constructor_Default) {
+ //create an empty linked list
+ EtchList<EtchInt32*>* list = new EtchList<EtchInt32*>();
+ delete list;
}
+
+TEST(EtchList, addTest) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1;
+ EtchInt32 data2;
+ EtchInt32 data3;
+ status_t result;
+
+ data1.set(32);
+ data2.set(43);
+ //append element to the linked list
+ result = list->add(data1);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ //append another element to linked list
+ result = list->add(data2);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ //Get added elements to compare that if they are correctly added or not
+ list->get(0, &data3);
+ EXPECT_TRUE(data3.get() == data1.get());
+
+ list->get(1, &data3);
+ EXPECT_TRUE(data3.get() == data2.get());
+
+ delete list;
+}
+
+TEST(EtchList, removeAt) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1;
+ EtchInt32 data2;
+ EtchInt32 data3;
+ status_t result;
+
+ data1.set(32);
+ data2.set(43);
+ data3.set(56);
+ //add some elements to linked list
+ result = list->add(data1);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ result = list->add(data3);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ result = list->add(data2);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ //removing element at index 1
+ result = list->removeAt(1);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ //removing element at index 1
+ result = list->removeAt(1);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ //removing element at index 0 (HEAD)
+ result = list->removeAt(0, &data1);
+ EXPECT_TRUE(result == ETCH_OK);
+ EXPECT_TRUE(data1.get() == 32);
+
+ //remove element from out of index
+ result = list->removeAt(1000);
+ EXPECT_TRUE(result == ETCH_EINVAL);
+
+ //check size of list
+ EXPECT_TRUE(list->size() == 0);
+
+ delete list;
+}
+
+TEST(EtchList, get) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1;
+ EtchInt32 data2;
+ EtchInt32 data3;
+ EtchInt32 data4;
+
+ status_t result;
+
+ data1.set(32);
+ data2.set(43);
+ data3.set(56);
+
+ //add some element to the linked list
+ result = list->add(data1);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ result = list->add(data3);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ result = list->add(data2);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ //get the added elements by using its index and compare the values with inserted elements
+ result = list->get(0, &data4);
+ EXPECT_TRUE(result == ETCH_OK);
+ EXPECT_TRUE(data1.get() == data4.get());
+
+ result = list->get(1, &data4);
+ EXPECT_TRUE(result == ETCH_OK);
+ EXPECT_TRUE(data3.get() == data4.get());
+
+ result = list->get(2, &data4);
+ EXPECT_TRUE(result == ETCH_OK);
+ EXPECT_TRUE(data2.get() == data4.get());
+
+ result = list->get(123, NULL);
+ EXPECT_TRUE(result == ETCH_EINVAL);
+
+ delete list;
+}
+
+TEST(EtchList, size) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1;
+ EtchInt32 data2;
+ EtchInt32 data3;
+ EtchInt32 data4;
+
+ capu::int32_t result;
+
+ data1.set(32);
+ data2.set(43);
+ data3.set(56);
+
+ //size of empty list
+ result = list->size();
+ EXPECT_TRUE(result == 0);
+
+ //add some elements and check the size for each step
+ list->add(data1);
+ result = list->size();
+ EXPECT_TRUE(result == 1);
+
+ list->add(data1);
+ result = list->size();
+ EXPECT_TRUE(result == 2);
+
+ list->add(data1);
+ result = list->size();
+ EXPECT_TRUE(result == 3);
+
+ delete list;
+}
+
+TEST(EtchList, empty) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1;
+ EtchInt32 data2;
+ EtchInt32 data3;
+ EtchInt32 data4;
+
+ capu::bool_t result;
+
+ data1.set(32);
+ data2.set(43);
+ data3.set(56);
+
+ //check the empty list
+ result = list->isEmpty();
+ EXPECT_TRUE(result == true);
+
+ //add some element
+ list->add(data1);
+ result = list->isEmpty();
+ EXPECT_TRUE(result == false);
+
+ delete list;
+}
+
+TEST(EtchList, set) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1(32);
+ EtchInt32 data2(43);
+
+ EXPECT_TRUE(list->add(data1) == ETCH_OK);
+ EXPECT_TRUE(list->add(data2) == ETCH_OK);
+ EXPECT_TRUE(list->set(1, data1) == ETCH_OK);
+ EXPECT_TRUE(list->set(0, data1) == ETCH_OK);
+ EXPECT_TRUE(list->get(1, &data2) == ETCH_OK);
+ EXPECT_TRUE(list->set(2, data1) == ETCH_EINVAL);
+ EXPECT_TRUE(data2.get() == data1.get());
+ delete list;
+}
+
+TEST(EtchList, find) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1(32);
+ EtchInt32 data2(43);
+ EtchInt32 data3(44);
+ capu::int32_t result;
+
+ //add some elements
+ list->add(data1);
+ list->add(data2);
+ list->add(data3);
+
+ //find the elements
+ result = list->find(data1);
+ EXPECT_TRUE(result == 0);
+
+ result = list->find(data2);
+ EXPECT_TRUE(result == 1);
+
+ result = list->find(data3);
+ EXPECT_TRUE(result == 2);
+
+ delete list;
+}
+
+TEST(EtchList, contains) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1(32);
+ EtchInt32 data2(43);
+ EtchInt32 data3(44);
+
+ EtchInt32 check_value(0);
+ capu::bool_t result;
+
+ // fill the linked
+ list->add(data1);
+ list->add(data1);
+ list->add(data2);
+ list->add(data3);
+
+ //check an elements to be contained by linked list or not
+ result = list->contains(check_value);
+ EXPECT_TRUE(result == false);
+
+ result = list->contains(data3);
+ EXPECT_TRUE(result == true);
+
+ delete list;
+}
+
+TEST(EtchList, clear) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1(32);
+ EtchInt32 data2(43);
+ EtchInt32 data3(44);
+ status_t result;
+
+ //add some dummy values to the linked list
+ list->add(data1);
+ list->add(data1);
+ list->add(data2);
+ list->add(data3);
+
+ //remove all elements from the linked list
+ result = list->clear();
+ EXPECT_TRUE(result == ETCH_OK);
+
+ result = list->add(data1);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ result = list->get(0, &data2);
+ EXPECT_TRUE(data1.get() == data2.get());
+ delete list;
+}
+
+TEST(EtchList, addTestIndex) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1(32);
+ EtchInt32 data2(43);
+ EtchInt32 data3(44);
+ EtchInt32 new_value(5);
+
+ EtchInt32 check_value(0);
+ status_t result;
+
+ // add some dummy elements to linked list
+ list->add(data1);
+ list->add(data1);
+ list->add(data2);
+ list->add(data3);
+
+ //before the replacing the element
+ result = list->get(1, &check_value);
+ EXPECT_TRUE(check_value.get() == data1.get());
+
+ //replace the element
+ result = list->add(1, new_value);
+ EXPECT_TRUE(result == ETCH_OK);
+
+ //after the replacing the element, check the values
+ result = list->get(1, &check_value);
+ EXPECT_TRUE(check_value.get() == new_value.get());
+
+ result = list->get(0, &check_value);
+ EXPECT_TRUE(check_value.get() == data1.get());
+
+ delete list;
+}
+
+TEST(EtchListIterator, hasNext) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1;
+ EtchInt32 data2;
+ EtchList<EtchInt32>::Iterator it = list->begin();
+ EXPECT_TRUE(it.hasNext() == false);
+
+ data1.set(32);
+ data2.set(43);
+
+ it = list->begin();
+ capu::bool_t resultb = it.hasNext();
+ EXPECT_TRUE(resultb == false);
+
+ list->add(data1);
+ it = list->begin();
+
+ resultb = it.hasNext();
+ EXPECT_TRUE(resultb == true);
+ delete list;
+}
+
+TEST(EtchListIterator, next) {
+ EtchList<EtchInt32>* list = new EtchList<EtchInt32 > ();
+ EtchInt32 data1;
+ EtchInt32 data2;
+ EtchInt32 data3;
+ EtchList<EtchInt32>::Iterator it = list->begin();
+ capu::int32_t cnt = 0;
+
+ EXPECT_TRUE(it.hasNext() == false);
+
+ data1.set(32);
+ data2.set(43);
+ list->add(data1);
+ list->add(data2);
+ it = list->begin();
+ while (it.hasNext()) {
+ it.next(&data3);
+ if (cnt == 0)
+ EXPECT_TRUE(data3.get() == data1.get());
+ else
+ EXPECT_TRUE(data3.get() == data2.get());
+ cnt++;
+ }
+ delete list;
+}
+
+