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 2012/06/01 14:11:15 UTC

svn commit: r1345097 - in /incubator/etch/trunk/binding-cpp/runtime: include/common/EtchException.h include/common/EtchObjectType.h src/main/CMakeLists.txt src/main/common/EtchException.cpp src/test/CMakeLists.txt src/test/common/EtchExceptionTest.cpp

Author: fitzner
Date: Fri Jun  1 12:11:15 2012
New Revision: 1345097

URL: http://svn.apache.org/viewvc?rev=1345097&view=rev
Log:
ETCH-184 Implementation of EtchException

EtchException and EtchExceptionType are created

Change-Id: I39cfcc5fb62bf6f8f28562a8c84fc3724cf71a18

Added:
    incubator/etch/trunk/binding-cpp/runtime/include/common/EtchException.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchException.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchExceptionTest.cpp
Modified:
    incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
    incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt

Added: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchException.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchException.h?rev=1345097&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchException.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchException.h Fri Jun  1 12:11:15 2012
@@ -0,0 +1,89 @@
+/* $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 __ETCHEXCEPTION_H__
+#define __ETCHEXCEPTION_H__
+
+#include "common/EtchObject.h"
+#include "common/EtchString.h"
+
+class EtchException : public EtchObject {
+public:
+
+  typedef capu::uint32_t EtchExceptionType;
+
+  enum {
+    EXCPTYPE_NONE = 0x0,
+    EXCPTYPE_BUILTIN = 0x1,
+    EXCPTYPE_USERDEFINED = 0x2
+  };
+
+
+  //Constructor
+  EtchException();
+
+  /**
+   * EtchException
+   * @param msg Exception Message
+   */
+  EtchException(EtchString &msg, status_t errcode, EtchExceptionType type);
+
+  //destructor
+  virtual ~EtchException();
+
+  //overridden
+  virtual capu::bool_t equals(const EtchObject * other);
+
+  /**
+   *
+   * @return Message of Exception
+   */
+  EtchString getErrorMessage();
+
+  /**
+   *
+   * @return Error Code of Exception
+   */
+  status_t getErrorCode();
+
+  /**
+   *
+   * @return Type of Exception
+   */
+  EtchExceptionType getExceptionType();
+
+  static const EtchObjectType* TYPE();
+
+protected:
+
+  EtchString mErrorMessage;
+  status_t mErrorcode;
+  EtchExceptionType mExcptype;
+
+  /**
+   * @param msg Message of exception
+   * @param errcode Error Code such as ETCH_EINVAL etc.
+   * @param type    Exception Type such as EXCPTYPE_USERDEFINED etc.
+   * @param type_id Typeid of Exception
+   */
+  EtchException(EtchString &msg, status_t errcode, EtchExceptionType type, const EtchObjectType* type_id);
+
+};
+
+#endif /* ETCHEXCEPTION_H */
+

Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h?rev=1345097&r1=1345096&r2=1345097&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h Fri Jun  1 12:11:15 2012
@@ -57,6 +57,7 @@ enum EtchObjectTypeIds {
   EOTID_VALUE_FACTORY,
   EOTID_TYPE,
   EOTID_STRUCT_VALUE,
+  EOTID_EXCEPTION,
 
   EOTID_NATIVE_INT8,
   EOTID_NATIVE_INT16,

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=1345097&r1=1345096&r2=1345097&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Fri Jun  1 12:11:15 2012
@@ -58,6 +58,7 @@ SET(MAIN_INCLUDES
     ${PROJECT_SOURCE_DIR}/include/transport/EtchTransportData.h
     ${PROJECT_SOURCE_DIR}/include/transport/EtchTransportMessage.h
     ${PROJECT_SOURCE_DIR}/include/transport/EtchTransportPacket.h
+    ${PROJECT_SOURCE_DIR}/include/common/EtchException.h
     ${PROJECT_SOURCE_DIR}/include/transport/EtchTcpConnection.h
     ${PROJECT_SOURCE_DIR}/include/transport/EtchTcpListener.h
     ${PROJECT_SOURCE_DIR}/include/transport/EtchTcpOption.h
@@ -101,6 +102,7 @@ SET(MAIN_SOURCES
     common/EtchDouble.cpp
     common/EtchSocket.cpp
     common/EtchServerSocket.cpp
+    common/EtchException.cpp
     util/EtchURL.cpp
     util/EtchResources.cpp
     transport/EtchFlexBuffer.cpp

Added: incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchException.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchException.cpp?rev=1345097&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchException.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchException.cpp Fri Jun  1 12:11:15 2012
@@ -0,0 +1,67 @@
+/* $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 "common/EtchException.h"
+
+const EtchObjectType* EtchException::TYPE() {
+  const static EtchObjectType TYPE(EOTID_EXCEPTION, NULL);
+  return &TYPE;
+}
+
+EtchException::EtchException()
+: EtchObject(EtchException::TYPE()), mErrorMessage(""), mErrorcode(0), mExcptype(0) {
+
+}
+
+EtchException::EtchException(EtchString &msg, status_t errcode, EtchExceptionType type)
+: EtchObject(EtchException::TYPE()), mErrorMessage(msg), mErrorcode(errcode), mExcptype(type) {
+
+}
+
+EtchException::EtchException(EtchString &msg, status_t errcode, EtchExceptionType type, const EtchObjectType* type_id)
+: EtchObject(type_id), mErrorMessage(msg), mErrorcode(errcode), mExcptype(type) {
+
+}
+
+EtchException::~EtchException() {
+
+}
+
+capu::bool_t EtchException::equals(const EtchObject* other) {
+  if (other == NULL)
+    return false;
+  if (other->getObjectType() != EtchException::TYPE())
+    return false;
+  EtchException * object = (EtchException *) other;
+
+  return ((object->mErrorcode == this->mErrorcode)
+          && (object->mExcptype == this->mExcptype)
+          && (object->mErrorMessage.equals(&this->mErrorMessage)));
+
+}
+
+EtchString EtchException::getErrorMessage() {
+  return mErrorMessage;
+}
+
+status_t EtchException::getErrorCode() {
+  return mErrorcode;
+}
+
+EtchException::EtchExceptionType EtchException::getExceptionType() {
+  return mExcptype;
+}

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=1345097&r1=1345096&r2=1345097&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt Fri Jun  1 12:11:15 2012
@@ -42,6 +42,7 @@ add_executable (etch-cpp-test
     common/EtchNativeArrayTest.cpp
     common/EtchHashTableTest.cpp
     common/EtchHashSetTest.cpp
+    common/EtchExceptionTest.cpp
     util/EtchURLTest.cpp
     util/EtchResourcesTest.cpp
     transport/EtchFlexBufferTest.cpp

Added: incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchExceptionTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchExceptionTest.cpp?rev=1345097&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchExceptionTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchExceptionTest.cpp Fri Jun  1 12:11:15 2012
@@ -0,0 +1,61 @@
+/* $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/EtchException.h"
+
+TEST(EtchExceptionTest, createTest) {
+  EtchString str("test message");
+  EtchException *test = NULL;
+  test = new EtchException(str, ETCH_ERROR, EtchException::EXCPTYPE_BUILTIN);
+  EXPECT_TRUE(test != NULL);
+  delete test;
+}
+
+TEST(EtchExceptionTest, getTests) {
+  EtchString str("test message");
+  EtchException *test = NULL;
+  test = new EtchException(str, ETCH_ERROR, EtchException::EXCPTYPE_BUILTIN);
+  EXPECT_TRUE(test != NULL);
+  EXPECT_TRUE(test->getErrorMessage().equals(&str));
+  EXPECT_TRUE(test->getErrorCode() == ETCH_ERROR);
+  EXPECT_TRUE(test->getExceptionType() == EtchException::EXCPTYPE_BUILTIN);
+  delete test;
+}
+
+TEST(EtchExceptionTest, equalsTest) {
+  EtchString str("test message");
+  EtchString str2("test2 message");
+  EtchException *test = NULL;
+  test = new EtchException(str, ETCH_ERROR, EtchException::EXCPTYPE_BUILTIN);
+  EtchException *test2 = NULL;
+  test2 = new EtchException(str2, ETCH_EINVAL, EtchException::EXCPTYPE_BUILTIN);
+  EtchException *test3 = NULL;
+  test3 = new EtchException(str, ETCH_ERROR, EtchException::EXCPTYPE_BUILTIN);
+
+  EXPECT_TRUE(test != NULL);
+  EXPECT_TRUE(test2 != NULL);
+  EXPECT_TRUE(test3 != NULL);
+
+  EXPECT_TRUE(test->equals(test3));
+  EXPECT_FALSE(test->equals(test2));
+
+  delete test;
+  delete test2;
+  delete test3;
+}