1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "precompiled_sal.hxx" 25 #include "sal/config.h" 26 27 #include "gtest/gtest.h" 28 #include "rtl/math.hxx" 29 #include "rtl/ustring.h" 30 #include "rtl/ustring.hxx" 31 #include "sal/types.h" 32 33 namespace { 34 35 class Test: public ::testing::Test { 36 }; 37 38 TEST_F(Test, test_stringToDouble_good) { 39 rtl_math_ConversionStatus status; 40 sal_Int32 end; 41 double res = rtl::math::stringToDouble( 42 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" +1.E01foo")), 43 sal_Unicode('.'), sal_Unicode(','), &status, &end); 44 ASSERT_EQ(rtl_math_ConversionStatus_Ok, status); 45 ASSERT_EQ(sal_Int32(RTL_CONSTASCII_LENGTH(" +1.E01")), end); 46 ASSERT_EQ(10.0, res); 47 } 48 49 TEST_F(Test, test_stringToDouble_bad) { 50 rtl_math_ConversionStatus status; 51 sal_Int32 end; 52 double res = rtl::math::stringToDouble( 53 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" +Efoo")), 54 sal_Unicode('.'), sal_Unicode(','), &status, &end); 55 ASSERT_EQ(rtl_math_ConversionStatus_Ok, status); 56 ASSERT_EQ(sal_Int32(0), end); 57 ASSERT_EQ(0.0, res); 58 } 59 60 } 61 62 int main(int argc, char **argv) 63 { 64 ::testing::InitGoogleTest(&argc, argv); 65 return RUN_ALL_TESTS(); 66 } 67