sc/inc/stringutil.hxx | 3 + sc/prj/build.lst | 1 sc/source/core/tool/stringutil.cxx | 6 ++- sc/test/main.cxx | 30 ++++++++++++++++ sc/test/makefile.mk | 68 +++++++++++++++++++++++++++++++++++++ sc/test/stringutiltests.cxx | 40 +++++++++++++++++++++ 6 files changed, 145 insertions(+), 3 deletions(-)
New commits: commit 10458a24f4e6cc311e65fb80ce576fed39937be2 Author: Damjan Jovanovic <dam...@apache.org> Date: Mon Apr 4 04:11:07 2016 +0000 #i126901# CSV import: values with + or - followed by thousand separator and 3 digits (eg. +,123) are imported as a number Do not allow numbers parsed from CVS files when "Detect special numbers" is off, to contain thousand separators before digits, even if after a +/- sign (eg. -,123 or +,789). Treat these as strings instead. Also added unit tests for this and exported the ScStringUtil class so it can be tested. Patch by: me diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx index 1b06228..0094055 100644 --- a/sc/inc/stringutil.hxx +++ b/sc/inc/stringutil.hxx @@ -25,8 +25,9 @@ #define SC_STRINGUTIL_HXX #include "rtl/ustring.hxx" +#include "scdllapi.h" -class ScStringUtil +class SC_DLLPUBLIC ScStringUtil { public: /** diff --git a/sc/prj/build.lst b/sc/prj/build.lst index e3a62f8..4d898ca 100644 --- a/sc/prj/build.lst +++ b/sc/prj/build.lst @@ -48,6 +48,7 @@ sc sc\addin\datefunc nmake - all sc_addfu sc_add sc_sdi sc_inc NULL sc sc\addin\rot13 nmake - all sc_adrot sc_add sc_sdi sc_inc NULL sc sc\addin\util nmake - all sc_adutil sc_addfu sc_adrot sc_sdi sc_inc NULL sc sc\util nmake - all sc_util sc_addfu sc_adrot sc_adutil sc_app sc_attr sc_cctrl sc_cosrc sc_data sc_dbgui sc_dif sc_docsh sc_drfnc sc_excel sc_form sc_html sc_lotus sc_qpro sc_misc sc_name sc_nvipi sc_opt sc_page sc_rtf sc_scalc sc_style sc_tool sc_uisrc sc_sidebar sc_undo sc_unobj sc_view sc_xcl97 sc_xml sc_acc sc_ftools sc_inc sc_vba NULL +sc sc\test nmake - all sc_test sc_util NULL # remarked due to the fact, key press is need in this test. # sc sc\qa\complex\calcPreview nmake - all qa_calcpreview NULL diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx index 539c34f..50fae6a 100644 --- a/sc/source/core/tool/stringutil.cxx +++ b/sc/source/core/tool/stringutil.cxx @@ -45,6 +45,7 @@ bool ScStringUtil::parseSimpleNumber( const sal_Unicode* p = rStr.getStr(); sal_Int32 nPosDSep = -1, nPosGSep = -1; sal_uInt32 nDigitCount = 0; + bool haveSeenDigit = false; for (sal_Int32 i = 0; i < n; ++i) { @@ -57,6 +58,7 @@ bool ScStringUtil::parseSimpleNumber( { // this is a digit. aBuf.append(c); + haveSeenDigit = true; ++nDigitCount; } else if (c == dsep) @@ -81,8 +83,8 @@ bool ScStringUtil::parseSimpleNumber( { // this is a group (thousand) separator. - if (i == 0) - // not allowed as the first character. + if (!haveSeenDigit) + // not allowed before digits. return false; if (nPosDSep >= 0) diff --git a/sc/test/main.cxx b/sc/test/main.cxx new file mode 100644 index 0000000..0777abb --- /dev/null +++ b/sc/test/main.cxx @@ -0,0 +1,30 @@ +/************************************************************** + * + * 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 "precompiled_sc.hxx" + +#include "gtest/gtest.h" + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/sc/test/makefile.mk b/sc/test/makefile.mk new file mode 100644 index 0000000..2ba9cbe --- /dev/null +++ b/sc/test/makefile.mk @@ -0,0 +1,68 @@ +#************************************************************** +# +# 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. +# +#************************************************************** + + + +PRJ=.. + +PRJNAME=sc +TARGET=tests + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.IF "$(ENABLE_UNIT_TESTS)" != "YES" + +all: + @echo "unit tests are disabled. Nothing do do." + +.ELSE + + +# --- Common ---------------------------------------------------------- + +APP1OBJS= \ + $(SLO)$/main.obj \ + $(SLO)$/stringutiltests.obj + +APP1TARGET= sc_tests +APP1STDLIBS= \ + $(ISCLIB) \ + $(SALLIB) \ + $(GTESTLIB) + +APP1RPATH = NONE +APP1TEST = enabled + +# END ------------------------------------------------------------------ + +# --- Targets ------------------------------------------------------ + +.ENDIF # "$(ENABLE_UNIT_TESTS)" != "YES" + +.INCLUDE : target.mk + +.IF "$(verbose)"!="" || "$(VERBOSE)"!="" +CDEFS+= -DVERBOSE +.ENDIF diff --git a/sc/test/stringutiltests.cxx b/sc/test/stringutiltests.cxx new file mode 100644 index 0000000..4f08c7f2 --- /dev/null +++ b/sc/test/stringutiltests.cxx @@ -0,0 +1,40 @@ +/************************************************************** + * + * 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 "precompiled_sc.hxx" + +#include "gtest/gtest.h" + +#include "stringutil.hxx" + + +namespace +{ + +TEST(StringUtilsTest, TestSignThenThousandSeparator) +{ + ScStringUtil stringUtil; + double doubleValue; + EXPECT_FALSE(stringUtil.parseSimpleNumber(::rtl::OUString::createFromAscii("+,123"), sal_Unicode('.'), sal_Unicode(','), doubleValue)); + EXPECT_FALSE(stringUtil.parseSimpleNumber(::rtl::OUString::createFromAscii("-,123"), sal_Unicode('.'), sal_Unicode(','), doubleValue)); +} + +} _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits