Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlois Zoitl2018-03-23 21:22:13 +0000
committerAlois Zoitl2018-03-23 21:26:01 +0000
commit437d0a54af1a389c6f2b9cab7cd5d9caed969765 (patch)
tree1676b3820c61ca9c379c52ddf8e0a84f001e8969
parent4d7709b164b5147b92934142c30ec45b88a3ac68 (diff)
downloadorg.eclipse.4diac.forte-437d0a54af1a389c6f2b9cab7cd5d9caed969765.tar.gz
org.eclipse.4diac.forte-437d0a54af1a389c6f2b9cab7cd5d9caed969765.tar.xz
org.eclipse.4diac.forte-437d0a54af1a389c6f2b9cab7cd5d9caed969765.zip
[532845] fixed toString issues of any datatypes
derived any types where not correctly responding inToString the getToStringSize returned the wrong value for anytypes added tests to check it for regressions Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=532845 Signed-off-by: Alois Zoitl <alois.zoitl@gmx.at>
-rw-r--r--src/core/datatypes/forte_any.cpp4
-rw-r--r--src/core/datatypes/forte_any_elementary.cpp2
-rw-r--r--tests/core/datatypes/CMakeLists.txt1
-rw-r--r--tests/core/datatypes/anytostringtests.cpp97
4 files changed, 101 insertions, 3 deletions
diff --git a/src/core/datatypes/forte_any.cpp b/src/core/datatypes/forte_any.cpp
index b12f44a04..bc17cf453 100644
--- a/src/core/datatypes/forte_any.cpp
+++ b/src/core/datatypes/forte_any.cpp
@@ -105,7 +105,7 @@ CStringDictionary::TStringId CIEC_ANY::parseTypeName(const char *pa_pacValue, co
int CIEC_ANY::toString(char* pa_pacValue, unsigned int pa_nBufferSize) const{
int nRetVal = -1;
- if((strlen(scm_acAnyToStringResponse) +1) < pa_nBufferSize){
+ if((strlen(scm_acAnyToStringResponse) +1) <= pa_nBufferSize){
nRetVal = static_cast<int>(strlen(scm_acAnyToStringResponse));
memcpy(pa_pacValue, scm_acAnyToStringResponse, nRetVal);
pa_pacValue[nRetVal] = '\0';
@@ -208,7 +208,7 @@ void CIEC_ANY::specialCast(const CIEC_ANY &pa_roSrcValue, CIEC_ANY &pa_roDstValu
}
const TForteByte CIEC_ANY::csm_aStringBufferSize[] = {
- 0 /*e_ANY*/,
+ 9 /*e_ANY*/,
6 /*e_BOOL (0, 1)*/,
5 /*e_SINT (-128, +127)*/,
7 /*e_INT (-32768, +32767)*/,
diff --git a/src/core/datatypes/forte_any_elementary.cpp b/src/core/datatypes/forte_any_elementary.cpp
index 3e3e4dc05..8004fc09a 100644
--- a/src/core/datatypes/forte_any_elementary.cpp
+++ b/src/core/datatypes/forte_any_elementary.cpp
@@ -101,7 +101,7 @@ int CIEC_ANY_ELEMENTARY::toString(char* pa_acValue, unsigned int pa_nBufferSize)
}
#endif
default: {
- return -1;
+ return CIEC_ANY::toString(pa_acValue, pa_nBufferSize);
}
}
diff --git a/tests/core/datatypes/CMakeLists.txt b/tests/core/datatypes/CMakeLists.txt
index df54c3346..ad4ab0007 100644
--- a/tests/core/datatypes/CMakeLists.txt
+++ b/tests/core/datatypes/CMakeLists.txt
@@ -15,6 +15,7 @@
forte_test_add_link_directories(${CMAKE_BINARY_DIR}/src/core/datatypes)
forte_test_add_sourcefile_cpp(CIEC_ANY_tests.cpp)
+ forte_test_add_sourcefile_cpp(anytostringtests.cpp)
forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_any.cpp)
forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_any_elementary.cpp)
forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_any_date.cpp)
diff --git a/tests/core/datatypes/anytostringtests.cpp b/tests/core/datatypes/anytostringtests.cpp
new file mode 100644
index 000000000..2b473e08f
--- /dev/null
+++ b/tests/core/datatypes/anytostringtests.cpp
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2018 fortiss GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alois Zoitl - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+#include <boost/test/unit_test.hpp>
+#include "../../../src/core/datatypes/forte_any.h"
+#include "../../../src/core/datatypes/forte_any_bit.h"
+#include "../../../src/core/datatypes/forte_any_date.h"
+#include "../../../src/core/datatypes/forte_any_derived.h"
+#include "../../../src/core/datatypes/forte_any_elementary.h"
+#include "../../../src/core/datatypes/forte_any_int.h"
+#include "../../../src/core/datatypes/forte_any_magnitude.h"
+#include "../../../src/core/datatypes/forte_any_num.h"
+#include "../../../src/core/datatypes/forte_any_real.h"
+#include "../../../src/core/datatypes/forte_any_string.h"
+
+BOOST_AUTO_TEST_SUITE(CIEC_ARRAY_function_test)
+ void performToStringTests(CIEC_ANY &paTestee){
+ char buffer[10];
+
+ for(int i = 0; i < 9; i++){
+ BOOST_CHECK_EQUAL(paTestee.toString(buffer, i), -1);
+ }
+
+ BOOST_CHECK_EQUAL(paTestee.toString(buffer, 9), strlen("ND (ANY)"));
+ BOOST_CHECK_EQUAL(0, strcmp(buffer, "ND (ANY)"));
+
+ BOOST_CHECK_EQUAL(paTestee.toString(buffer, 10), strlen("ND (ANY)"));
+ BOOST_CHECK_EQUAL(0, strcmp(buffer, "ND (ANY)"));
+
+ }
+
+
+ BOOST_AUTO_TEST_CASE(ANY_toString_Test){
+ CIEC_ANY *poTest = CIEC_ANY::createDataType(0);
+ performToStringTests(*poTest);
+ delete poTest;
+ }
+
+ BOOST_AUTO_TEST_CASE(ANY_BIT_toString_Test){
+ CIEC_ANY *poTest = CIEC_ANY_BIT::createDataType(0);
+ performToStringTests(*poTest);
+ delete poTest;
+ }
+
+ BOOST_AUTO_TEST_CASE(ANY_DERIVED_toString_Test){
+ CIEC_ANY *poTest = CIEC_ANY_DERIVED::createDataType(0);
+ performToStringTests(*poTest);
+ delete poTest;
+ }
+
+ BOOST_AUTO_TEST_CASE(ANY_ELEMENTARY_toString_Test){
+ CIEC_ANY *poTest = CIEC_ANY_ELEMENTARY::createDataType(0);
+ performToStringTests(*poTest);
+ delete poTest;
+ }
+
+ BOOST_AUTO_TEST_CASE(ANY_INT_toString_Test){
+ CIEC_ANY *poTest = CIEC_ANY_INT::createDataType(0);
+ performToStringTests(*poTest);
+ delete poTest;
+ }
+
+ BOOST_AUTO_TEST_CASE(ANY_MAGNITUDE_toString_Test){
+ CIEC_ANY *poTest = CIEC_ANY_MAGNITUDE::createDataType(0);
+ performToStringTests(*poTest);
+ delete poTest;
+ }
+
+ BOOST_AUTO_TEST_CASE(ANY_NUM_toString_Test){
+ CIEC_ANY *poTest = CIEC_ANY_NUM::createDataType(0);
+ performToStringTests(*poTest);
+ delete poTest;
+ }
+
+ BOOST_AUTO_TEST_CASE(ANY_REAL_toString_Test){
+ CIEC_ANY *poTest = CIEC_ANY_REAL::createDataType(0);
+ performToStringTests(*poTest);
+ delete poTest;
+ }
+
+ BOOST_AUTO_TEST_CASE(ANY_STRING_toString_Test){
+ CIEC_ANY *poTest = CIEC_ANY_STRING::createDataType(0);
+ performToStringTests(*poTest);
+ delete poTest;
+ }
+
+
+
+BOOST_AUTO_TEST_SUITE_END()
+

Back to the top