You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by fi...@apache.org on 2011/08/04 14:09:34 UTC

svn commit: r1153858 - in /incubator/etch/trunk/binding-cpp/runtime: include/common/ src/main/ src/test/ src/test/common/

Author: fitzner
Date: Thu Aug  4 12:09:32 2011
New Revision: 1153858

URL: http://svn.apache.org/viewvc?rev=1153858&view=rev
Log:
ETCH-139, ETCH-154 NativeArray, native datatypes

Implementation of EtchNativeArray and tests

This patch comes from Martin Veith (see Issue ETCH-133)

Added:
    incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNative.h
      - copied, changed from r1152287, incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h
    incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNativeArray.h
    incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchNativeArrayTest.cpp
Modified:
    incubator/etch/trunk/binding-cpp/runtime/include/common/EtchConfig.h
    incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
    incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt

Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchConfig.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchConfig.h?rev=1153858&r1=1153857&r2=1153858&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchConfig.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchConfig.h Thu Aug  4 12:09:32 2011
@@ -1,35 +1,35 @@
-/* $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 __ETCHCONFIG_H__
-#define __ETCHCONFIG_H__
-
-#include "stdio.h"
-#include "stdlib.h"
-#include "string.h"
+/* $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. 
+ */
 
-#ifdef _WIN32
-typedef char int8_t;
-typedef short int16_t;
-typedef int int32_t;
-typedef signed __int64 int64_t;
-#else //other OS should be C99 compliant
-#include "stdint.h"
-#endif //_WIN32
-
-#endif
+#ifndef __ETCHCONFIG_H__
+#define __ETCHCONFIG_H__
+
+#include "stdio.h"
+#include "stdlib.h"
+#include "string.h"
+
+#ifdef _WIN32
+typedef char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+typedef signed __int64 int64_t;
+#else //other OS should be C99 compliant
+#include "stdint.h"
+#endif //_WIN32
+
+#endif

Copied: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNative.h (from r1152287, incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNative.h?p2=incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNative.h&p1=incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h&r1=1152287&r2=1153858&rev=1153858&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNative.h Thu Aug  4 12:09:32 2011
@@ -1,59 +1,44 @@
-/* $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 __ETCHOBJECT_H__
-#define __ETCHOBJECT_H__
-
-#include "EtchConfig.h"
-
-enum EtchObjectTypeIds {
-    EOTID_INT32     = 0,
-    EOTID_BOOL,
-    EOTID_BYTE,
-    EOTID_SHORT,
-    EOTID_LONG,
-    EOTID_DOUBLE,
-    EOTID_FLOAT,
-    EOTID_STRING,
-    EOTID_DATE,
-    EOTID_LIST
-};
-
-class EtchObject
-{
-public:
-    /**
-     * Constructor.
-     */
-    EtchObject(int32_t typeId);
-    
-    /**
-     * Destructor.
-     */
-    virtual ~EtchObject();
-
-    /**
-     * Returns object type id.
-     */
-    int32_t getObjectTypeId();
-
-private:
-    int32_t m_typeId;
-};
-
-#endif
+/* $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 __ETCHNATIVE_H__
+#define __ETCHNATIVE_H__
+
+#include "common/EtchObject.h"
+#include "common/EtchError.h"
+
+class EtchNative {
+ public:
+
+  /**
+   * TypeIds for native types
+   */
+  static const int32_t INT8 = EOTID_NATIVE_INT8;
+  static const int32_t INT16 = EOTID_NATIVE_INT16;
+  static const int32_t INT32 = EOTID_NATIVE_INT32;
+  static const int32_t INT64 = EOTID_NATIVE_INT64;
+  static const int32_t DOUBLE = EOTID_NATIVE_DOUBLE;
+  static const int32_t FLOAT = EOTID_NATIVE_FLOAT;
+  static const int32_t LONG = EOTID_NATIVE_LONG;
+  static const int32_t SHORT = EOTID_NATIVE_SHORT;
+  static const int32_t BOOL = EOTID_NATIVE_BOOL;
+  static const int32_t BYTE = EOTID_NATIVE_BYTE;
+ 
+};
+
+#endif

Added: 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=1153858&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNativeArray.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchNativeArray.h Thu Aug  4 12:09:32 2011
@@ -0,0 +1,191 @@
+/* $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 __ETCHNATIVEARRAY_H__
+#define __ETCHNATIVEARRAY_H__
+
+#include "common/EtchObject.h"
+#include "common/EtchError.h"
+
+template<class T, int32_t content_type_id>
+class EtchNativeArray :
+    public EtchObject
+{
+public:
+
+    /**
+     * TypeId for EtchNativeArray.
+     */
+    static const int32_t TYPE_ID = EOTID_NATIVE_ARRAY;
+
+    /**
+     * Constructs a EtchNativeArray object.
+     * T must be a pointer to a subclass of EtchObject (e.g. EtchInt32*) for this
+     * class to work correctly.
+     */
+    EtchNativeArray(int32_t length);
+
+    /**
+     * Destructor for Etch Nativearray.
+     * Frees array if content_owned was set.
+     */
+    virtual ~EtchNativeArray();
+
+    /**
+     * returns the TypeID of the content of this native array.
+     */
+    int32_t getContentTypeId();
+
+    /**
+     * gets the EtchObject at index i in result
+     * returns ETCH_ERANGE, if out of bounds.
+     * returns ETCH_OK otherwise
+     */
+    status_t get(int32_t index, T* result);
+
+      /**
+     * gets a block of EtchObject at index i in result
+     * @param index The start index of the array
+     * @param buffer The destination buffer
+     * @param buffer_size The size of the destination buffer
+     * @param offset The offset of the buffer where the data should be copied to
+     * @param count The number of elements
+     * returns ETCH_INVAL if the buffer is NULL
+     * returns ETCH_ERANGE, if out of bounds.
+     * returns ETCH_OK otherwise
+     */
+    status_t get(int32_t index, T* buffer, int32_t buffer_size, int32_t offset, int32_t count);
+    
+    
+    /**
+     * sets the EtchObject at index i in result
+     * if content_owned, old value will be freed.
+     * returns ETCH_ERANGE, if out of bounds.
+     * returns ETCH_OK otherwise
+     */
+    status_t set(T value, int32_t index);
+    
+    /**
+     * sets a block of the EtchObject at index i in result
+     * if content_owned, old value will be freed.
+     * @param index The start index of the array
+     * @param buffer The source buffer
+     * @param buffer_size The size of the source buffer
+     * @param offset The offset of the buffer from where on the data should be copied
+     * @param count The number of elements
+     * returns ETCH_INVAL if the buffer is NULL
+     * returns ETCH_ERANGE, if out of bounds.
+     * returns ETCH_OK otherwise
+     */
+    status_t set(int32_t index, T* buffer, int32_t buffer_size, int32_t offset, int32_t count);
+
+    
+    
+private:
+    T* m_array;
+    int32_t m_length;
+    int32_t m_content_type_id;
+};
+
+template<class T, int32_t content_type_id>
+EtchNativeArray<T, content_type_id>::EtchNativeArray(int32_t length)
+      : EtchObject(EtchNativeArray::TYPE_ID),
+      m_length(length) 
+{
+  m_array = new T[length];
+  m_content_type_id = content_type_id;
+}
+
+template<class T, int32_t content_type_id>
+EtchNativeArray<T, content_type_id>::~EtchNativeArray()
+{
+	delete[] m_array;
+}
+
+template<class T, int32_t content_type_id>
+status_t EtchNativeArray<T, content_type_id>::set(T value, int32_t index)
+{
+  if(0 <= index && index < m_length) {
+    m_array[index] = value;
+    return ETCH_OK;
+  }
+  return ETCH_ERANGE;
+}
+
+template<class T, int32_t content_type_id>
+int32_t EtchNativeArray<T, content_type_id>::getContentTypeId() {
+	return m_content_type_id;
+}
+
+template<class T, int32_t content_type_id>
+status_t EtchNativeArray<T, content_type_id>::get(int32_t index, T* result)
+{
+  if (result == NULL)
+  {
+    return ETCH_EINVAL;
+  }
+  else if (0 <= index && index < m_length) {
+    *result = m_array[index];
+    return ETCH_OK;
+  }
+  return ETCH_ERANGE;
+}
+
+template<class T, int32_t content_type_id>
+  status_t EtchNativeArray<T, content_type_id>::set(int32_t index, T* buffer, int32_t buffer_size, int32_t offset, int32_t count )
+{
+  if (buffer == NULL)
+  {
+      return ETCH_EINVAL;
+  }
+  if (0 <= index && index < m_length && (m_length - index) >= count && buffer_size <= (m_length - index) && buffer_size >= count && (offset+count) <= buffer_size) 
+  {
+      for (int i = 0;i < count - offset;i++,index++)
+      {
+          m_array[index] = buffer[offset+i];
+      }
+      
+       return ETCH_OK;
+  }
+  return ETCH_ERANGE;
+}
+
+
+template<class T, int32_t content_type_id>
+  status_t EtchNativeArray<T, content_type_id>::get(int32_t index, T* buffer, int32_t buffer_size, int32_t offset, int32_t count )
+{
+  if (buffer == NULL)
+  {
+    return ETCH_EINVAL;
+  }
+  if (0 <= index && index < m_length && (m_length - index) >= count && buffer_size >= (m_length - index && buffer_size >= count) && (offset+count) <= buffer_size)
+  {
+      
+      for(int i = 0;i < count - offset;i++,index++)
+      {
+          buffer[offset+i] = m_array[index];
+      }
+      
+      return ETCH_OK;
+  }
+  return ETCH_ERANGE;
+}
+
+
+
+#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=1153858&r1=1153857&r2=1153858&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObject.h Thu Aug  4 12:09:32 2011
@@ -1,59 +1,73 @@
-/* $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 __ETCHOBJECT_H__
-#define __ETCHOBJECT_H__
-
-#include "EtchConfig.h"
-
-enum EtchObjectTypeIds {
-    EOTID_INT32     = 0,
+/* $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 __ETCHOBJECT_H__
+#define __ETCHOBJECT_H__
+
+#include "EtchConfig.h"
+
+enum EtchObjectTypeIds {
+    EOTID_INT32     = 0,
     EOTID_BOOL,
     EOTID_BYTE,
     EOTID_SHORT,
     EOTID_LONG,
-    EOTID_DOUBLE,
-    EOTID_FLOAT,
-    EOTID_STRING,
-    EOTID_DATE,
-    EOTID_LIST
-};
-
-class EtchObject
-{
-public:
-    /**
-     * Constructor.
-     */
-    EtchObject(int32_t typeId);
-    
-    /**
-     * Destructor.
-     */
-    virtual ~EtchObject();
-
-    /**
-     * Returns object type id.
-     */
-    int32_t getObjectTypeId();
-
-private:
-    int32_t m_typeId;
-};
-
-#endif
+    EOTID_DOUBLE,
+    EOTID_FLOAT,
+    EOTID_STRING,
+    EOTID_DATE,
+    EOTID_LIST,
+    EOTID_NATIVE_ARRAY,
+    EOTID_BYTES,
+    EOTID_OBJECT,
+      
+    EOTID_NATIVE_INT8,
+    EOTID_NATIVE_INT16,
+    EOTID_NATIVE_INT32,
+    EOTID_NATIVE_INT64,
+    EOTID_NATIVE_DOUBLE,
+    EOTID_NATIVE_FLOAT,
+    EOTID_NATIVE_LONG,
+    EOTID_NATIVE_SHORT,
+    EOTID_NATIVE_BOOL,
+    EOTID_NATIVE_BYTE,
+};
+
+class EtchObject
+{
+public:
+    /**
+     * Constructor.
+     */
+    EtchObject(int32_t typeId);
+    
+    /**
+     * Destructor.
+     */
+    virtual ~EtchObject();
+
+    /**
+     * Returns object type id.
+     */
+    int32_t getObjectTypeId();
+
+private:
+    int32_t m_typeId;
+};
+
+#endif

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt?rev=1153858&r1=1153857&r2=1153858&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Thu Aug  4 12:09:32 2011
@@ -1,39 +1,39 @@
-#
-# 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. 
-#
-
-# set include dirs
-include_directories (${PROJECT_SOURCE_DIR}/include)
-
-add_library (etch-cpp STATIC
-    common/EtchObject.cpp
-    common/EtchString.cpp
-    common/EtchInt32.cpp
+#
+# 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. 
+#
+
+# set include dirs
+include_directories (${PROJECT_SOURCE_DIR}/include)
+
+add_library (etch-cpp STATIC
+    common/EtchObject.cpp
+    common/EtchString.cpp
+    common/EtchInt32.cpp
     common/EtchBool.cpp
     common/EtchByte.cpp
     common/EtchShort.cpp
     common/EtchLong.cpp
     common/EtchFloat.cpp
     common/EtchDouble.cpp
-    util/EtchUtil.cpp
-)
-
-IF (UNIX)
-  set_target_properties (etch-cpp PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
-ENDIF (UNIX)
-
-set_target_properties (etch-cpp PROPERTIES OUTPUT_NAME "etch")
-
+    util/EtchUtil.cpp
+)
+
+IF (UNIX)
+  set_target_properties (etch-cpp PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
+ENDIF (UNIX)
+
+set_target_properties (etch-cpp PROPERTIES OUTPUT_NAME "etch")
+

Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt?rev=1153858&r1=1153857&r2=1153858&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt Thu Aug  4 12:09:32 2011
@@ -33,9 +33,10 @@ add_executable (etch-cpp-test
     common/EtchLongTest.cpp
     common/EtchFloatTest.cpp
     common/EtchDoubleTest.cpp
-    common/EtchStringTest.cpp
-    common/EtchObjectTest.cpp
-    common/EtchListTest.cpp
+    common/EtchStringTest.cpp
+    common/EtchObjectTest.cpp
+    common/EtchListTest.cpp
+    common/EtchNativeArrayTest.cpp
     util/EtchUtilTest.cpp
     ${GTEST}/src/gtest-all.cc
     main.cpp

Added: 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=1153858&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchNativeArrayTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchNativeArrayTest.cpp Thu Aug  4 12:09:32 2011
@@ -0,0 +1,162 @@
+/* $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.
+ */
+
+#include <gtest/gtest.h>
+#include "common/EtchInt32.h"
+#include "common/EtchNative.h"
+#include "common/EtchNativeArray.h"
+
+
+TEST(EtchNativeArrayTest, Constructor_Default) {
+  EtchNativeArray<EtchInt32*, EtchInt32::TYPE_ID>* na =
+    new EtchNativeArray<EtchInt32*, EtchInt32::TYPE_ID>(10);
+    delete na;
+}
+
+TEST(EtchNativeArrayTest, Constructor_Array) {
+
+    EtchInt32* int1 = new EtchInt32(42);
+    EtchInt32* int2  = new EtchInt32(43);
+
+    EtchNativeArray<EtchInt32*, EtchInt32::TYPE_ID>* na1 =
+      new EtchNativeArray<EtchInt32*, EtchInt32::TYPE_ID>(2);
+
+    na1->set(int1,0);
+    na1->set(int2,1);
+
+    EXPECT_TRUE(na1->getObjectTypeId() == (EtchNativeArray<EtchInt32,EtchInt32::TYPE_ID>::TYPE_ID));
+
+    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());
+    }
+
+    status_t ret = na1->get(i, &value);
+    ASSERT_EQ(ETCH_ERANGE, ret);
+
+    delete na1;
+    delete int1;
+    delete int2;
+}
+
+TEST(EtchNativeArrayTest, setget) {
+
+    EtchInt32* int1 = new EtchInt32(42);
+    EtchInt32* int2 = new EtchInt32(43);
+    EtchNativeArray<EtchInt32*, EtchInt32::TYPE_ID>* na1 =
+      new EtchNativeArray<EtchInt32*, EtchInt32::TYPE_ID>(2);
+    EXPECT_TRUE(na1->getObjectTypeId() == (EtchNativeArray<EtchInt32, EtchInt32::TYPE_ID>::TYPE_ID));
+    
+    na1->set(int1,0);
+    na1->set(int2,1);
+
+    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);
+
+    na1->set(newValue, 1);
+
+    status_t ret = na1->get(1, &value);
+    ASSERT_EQ(ETCH_OK, ret);
+    ASSERT_EQ(44, newValue->get());
+
+    //Test setget of block
+    EtchNativeArray<EtchInt32*, EtchInt32::TYPE_ID> *native_array = new EtchNativeArray<EtchInt32*, EtchInt32::TYPE_ID> (2);
+    EtchInt32* int3 = new EtchInt32[2]();
+    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);
+    
+    ret = native_array->get(0,&int1,2,0,2);
+    EXPECT_TRUE(ret == ETCH_OK);
+    
+    EXPECT_TRUE(int1[0].get() == 2);
+    EXPECT_TRUE(int1[1].get() == 4);
+
+
+    //Test setget of block of native type
+    EtchNativeArray<int, EtchNative::INT32> *native_array2 = new EtchNativeArray<int, EtchNative::INT32> (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;
+    delete na1;
+    delete int2;
+    delete newValue;
+    delete native_array;
+    delete native_array2;
+}