You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by gr...@apache.org on 2011/01/24 17:55:21 UTC

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

Author: grandyho
Date: Mon Jan 24 16:55:20 2011
New Revision: 1062874

URL: http://svn.apache.org/viewvc?rev=1062874&view=rev
Log:
ETCH-149
initial changes for Linux

Added:
    incubator/etch/trunk/binding-cpp/runtime/include/util/
    incubator/etch/trunk/binding-cpp/runtime/include/util/EtchUtil.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/util/
    incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchUtil.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/test/util/
    incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchUtilTest.cpp
Modified:
    incubator/etch/trunk/binding-cpp/runtime/CMakeLists.txt
    incubator/etch/trunk/binding-cpp/runtime/README.txt
    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/main/CMakeLists.txt
    incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchString.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt

Modified: incubator/etch/trunk/binding-cpp/runtime/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/CMakeLists.txt?rev=1062874&r1=1062873&r2=1062874&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/CMakeLists.txt Mon Jan 24 16:55:20 2011
@@ -21,18 +21,19 @@ message (STATUS "using external librarie
 
 # Etch external
 IF (NOT ETCH_EXTERNAL_DEPENDS)
-    MESSAGE (FATAL_ERROR "ETCH_EXTERNAL_DEPENDS not set")
+  MESSAGE (FATAL_ERROR "ETCH_EXTERNAL_DEPENDS not set")
 ENDIF (NOT ETCH_EXTERNAL_DEPENDS)
 
 #VLD
 SET(VLD ${ETCH_EXTERNAL_DEPENDS}/vld/1.9h)
 
+
 # GTest
 SET(GTEST ${ETCH_EXTERNAL_DEPENDS}/gtest/1.5.0)
 
 # Set definitions
 IF (UNIX)
-    add_definitions (-D_GNU_SOURCE -D_REENTRANT -DLINUX=2 -D__LINUX__)
+  add_definitions (-D_GNU_SOURCE -D_REENTRANT -DLINUX=2 -D__LINUX__)
 ENDIF (UNIX)
 add_definitions (-D_UNICODE -DUNICODE)
 

Modified: incubator/etch/trunk/binding-cpp/runtime/README.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/README.txt?rev=1062874&r1=1062873&r2=1062874&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/README.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/README.txt Mon Jan 24 16:55:20 2011
@@ -1,2 +1,22 @@
-The current state of binding-cpp is under development. At the
-moment only win32 is supported for building the source code.
+The current state of binding-cpp is under development. 
+
+BUILD:
+*****
+The Build is cmake based. To build the sources, do:
+
+cd binding-cpp/runtime
+mkdir target
+cd target
+cmake -DETCH_EXTERNAL_DEPENDS:string=/your/path/to/external/dependencies ..
+
+NOTES: 
+******
+
+External dependencies: 
+- Google Test 1.5.0 (http://code.google.com/p/googletest/)
+
+Directory structure:
+
+/your/path/to/external/dependencies/
+	/gtest/1.5.0			contents of the Google Test tgz
+	

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=1062874&r1=1062873&r2=1062874&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchError.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchError.h Mon Jan 24 16:55:20 2011
@@ -25,8 +25,9 @@ typedef int32_t status_t;
 
 enum {
     ETCH_OK                 = 0,
-    ETCH_NO_ERROR           = 1,
-    ETCH_NOT_IMPLEMENTED    = 2
+    ETCH_EUNIMPL            = 1,
+    ETCH_ERANGE             = 2,
+    ETCH_EINVAL             = 3
 };
 
 #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=1062874&r1=1062873&r2=1062874&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchList.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchList.h Mon Jan 24 16:55:20 2011
@@ -117,7 +117,7 @@ void EtchList<T>::add(T data)
 template<class T>
 status_t EtchList<T>::get(int32_t index, T* data)
 {
-    return ETCH_NO_ERROR;
+    return ETCH_EUNIMPL;
 }
 
 #endif

Added: incubator/etch/trunk/binding-cpp/runtime/include/util/EtchUtil.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/util/EtchUtil.h?rev=1062874&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/util/EtchUtil.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/util/EtchUtil.h Mon Jan 24 16:55:20 2011
@@ -0,0 +1,31 @@
+/* $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 __ETCHUTIL_H__
+#define __ETCHUTIL_H__
+
+#include "common/EtchError.h"
+
+/*
+ * copy src to dst. Copies at most dst_size bytes. In case that
+ * dst is not long enough, dst will be '\0'. 
+ * Asserts that dstSize is length of dst.
+ */
+status_t etch_strcpy_s(char *dst, size_t dstSize, const char *src);
+
+#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=1062874&r1=1062873&r2=1062874&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Mon Jan 24 16:55:20 2011
@@ -22,10 +22,12 @@ add_library (etch-cpp STATIC
     common/EtchObject.cpp
     common/EtchString.cpp
     common/EtchInt32.cpp
+    util/EtchUtil.cpp
 )
 
 IF (UNIX)
-set_target_properties (etch-cpp PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
+  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/main/common/EtchString.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchString.cpp?rev=1062874&r1=1062873&r2=1062874&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchString.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchString.cpp Mon Jan 24 16:55:20 2011
@@ -17,6 +17,7 @@
  */
 
 #include "common/EtchString.h"
+#include "util/EtchUtil.h"
 
 EtchString::EtchString()
     : EtchObject(EtchString::TYPE_ID)
@@ -32,7 +33,7 @@ EtchString::EtchString(const char* strin
     if(string != NULL) {
         size_t len = strlen(string);
         m_data = new char[len + 1];
-        strcpy_s(m_data, len + 1, string);
+        etch_strcpy_s(m_data, len + 1, string);
     }
 }
 
@@ -53,7 +54,7 @@ void EtchString::set(const char* string)
     if(string != NULL) {
         size_t len = strlen(string);
         m_data = new char[len + 1];
-        strcpy_s(m_data, len + 1, string);
+        etch_strcpy_s(m_data, len + 1, string);
     }
 }
 

Added: incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchUtil.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchUtil.cpp?rev=1062874&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchUtil.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchUtil.cpp Mon Jan 24 16:55:20 2011
@@ -0,0 +1,50 @@
+/* $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 "util/EtchUtil.h"
+
+status_t etch_strcpy_s(char *dst, size_t dstSize, const char *src)
+{
+  char *d, *end;
+
+  if (dst == NULL || src == NULL) {
+    return ETCH_EINVAL;
+  }
+
+  if (dstSize == 0) {
+    return ETCH_ERANGE;
+  }
+
+  d = dst;
+  end = dst + dstSize - 1;
+
+  for (; d < end; ++d, ++src) {
+    if (!(*d = *src)) {
+      return ETCH_OK;
+    }
+  }
+  
+  // if src buffer is not 0 now, then we have bytes left in src --> error 
+  if(! (*d = *src)) {
+    return ETCH_OK;
+  } else {
+    // always null terminate 
+    *d = '\0';	
+    return ETCH_EINVAL;
+  }
+}

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=1062874&r1=1062873&r2=1062874&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt Mon Jan 24 16:55:20 2011
@@ -19,7 +19,10 @@
 include_directories (${PROJECT_SOURCE_DIR}/include)
 include_directories (${GTEST})
 include_directories (${GTEST}/include)
-include_directories (${VLD}/include)
+
+IF (WIN32)
+  include_directories (${VLD}/include)
+ENDIF (WIN32)
 
 add_executable (etch-cpp-test
     ${GTEST}/src/gtest-all.cc
@@ -28,11 +31,15 @@ add_executable (etch-cpp-test
     common/EtchStringTest.cpp
     common/EtchObjectTest.cpp
     common/EtchListTest.cpp
+    util/EtchUtilTest.cpp
 )
 
 target_link_libraries (etch-cpp-test etch-cpp)
-target_link_libraries (etch-cpp-test ${VLD}/lib/vld.lib)
+
+IF (WIN32)
+  target_link_libraries (etch-cpp-test ${VLD}/lib/vld.lib)
+ENDIF (WIN32)
 
 IF (UNIX)
-set_target_properties (etch-cpp-test PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
+  set_target_properties (etch-cpp-test PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32 -pthread")
 ENDIF (UNIX)

Added: incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchUtilTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchUtilTest.cpp?rev=1062874&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchUtilTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchUtilTest.cpp Mon Jan 24 16:55:20 2011
@@ -0,0 +1,45 @@
+/* $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 "util/EtchUtil.h"
+
+// Tests etch_strcpy_s
+TEST(EtchUtilTest, etch_strcpy_s) {
+  char* src = NULL;
+  char* dst = NULL;
+  int dstSize = 0;
+
+  status_t retval = etch_strcpy_s(dst, dstSize, src);
+  EXPECT_TRUE(retval == ETCH_EINVAL);
+
+  src = "Test";
+  dst = new char[5];
+  retval = etch_strcpy_s(dst, dstSize, src);
+  EXPECT_TRUE(retval == ETCH_ERANGE);
+
+  dstSize = 2;
+  retval = etch_strcpy_s(dst, dstSize, src);
+  EXPECT_TRUE(retval == ETCH_EINVAL);
+
+  dstSize = 5;
+  retval = etch_strcpy_s(dst, dstSize, src);
+  EXPECT_TRUE(retval == ETCH_OK);
+
+  delete[] dst;
+}