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 package complex.numberformatter;
25 
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.util.XNumberFormatsSupplier;
29 import com.sun.star.util.XNumberFormatter;
30 
31 import org.junit.After;
32 import org.junit.AfterClass;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.openoffice.test.OfficeConnection;
37 import static org.junit.Assert.*;
38 
39 public class NumberFormatterUnitTest {
40     private XMultiServiceFactory m_xMSF = null;
41 
before()42     @Before public void before() {
43         try {
44             m_xMSF = getMSF();
45         } catch (Exception e) {
46             fail ("Cannot create service factory!");
47         }
48         if (m_xMSF == null) {
49             fail ("Cannot create service factory!");
50         }
51     }
52 
after()53     @After public void after() {
54         m_xMSF = null;
55     }
56 
57     @Test
testDollarDotNumberFormat()58     public void testDollarDotNumberFormat() throws Exception
59     {
60         Object numberFormatterService = m_xMSF.createInstance( "com.sun.star.util.NumberFormatter" );
61         XNumberFormatter numberFormatter = UnoRuntime.queryInterface( XNumberFormatter.class, numberFormatterService );
62         Object numberFormatsSupplierService = m_xMSF.createInstance( "com.sun.star.util.NumberFormatsSupplier" );
63         XNumberFormatsSupplier numberFormatsSupplier = UnoRuntime.queryInterface( XNumberFormatsSupplier.class, numberFormatsSupplierService );
64         numberFormatter.attachNumberFormatsSupplier( numberFormatsSupplier );
65 
66         // Bug 82687 - Text entry or CSV import treats $.nn as text
67         double number = numberFormatter.convertStringToNumber(0, "$.1");
68         assertEquals(0.1, number, 0.00001);
69     }
70 
getMSF()71     private XMultiServiceFactory getMSF()
72     {
73         final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
74         return xMSF1;
75     }
76 
77     // setup and close connections
setUpConnection()78     @BeforeClass public static void setUpConnection() throws Exception {
79         System.out.println("setUpConnection()");
80         connection.setUp();
81     }
82 
tearDownConnection()83     @AfterClass public static void tearDownConnection()
84         throws InterruptedException, com.sun.star.uno.Exception
85     {
86         System.out.println("tearDownConnection()");
87         connection.tearDown();
88     }
89 
90     private static final OfficeConnection connection = new OfficeConnection();
91 
92 }
93