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 package api.i18n; 24 25 import com.sun.star.i18n.TransliterationModules; 26 import com.sun.star.i18n.XExtendedTransliteration; 27 import com.sun.star.lang.Locale; 28 import com.sun.star.uno.UnoRuntime; 29 import com.sun.star.uno.XComponentContext; 30 import org.junit.After; 31 import org.junit.AfterClass; 32 import org.junit.Before; 33 import org.junit.BeforeClass; 34 import org.junit.Assert; 35 import org.junit.Test; 36 import org.openoffice.test.uno.UnoApp; 37 38 /** 39 * 40 */ 41 public class XExtendedTransliterationTest { 42 private static final UnoApp app = new UnoApp(); 43 44 private XComponentContext xContext = null; 45 public XExtendedTransliteration oObj = null; 46 // private Locale loc = new Locale("ja", "JP", "") ; 47 private Locale loc = new Locale("en", "US", "") ; 48 49 // setup and close connections 50 @BeforeClass setUpConnection()51 public static void setUpConnection() throws Exception 52 { 53 app.start(); 54 } 55 56 @AfterClass tearDownConnection()57 public static void tearDownConnection() throws InterruptedException, com.sun.star.uno.Exception 58 { 59 app.close(); 60 } 61 62 @Before before()63 public void before() throws Exception { 64 xContext = app.getComponentContext(); 65 oObj = UnoRuntime.queryInterface( 66 XExtendedTransliteration.class, 67 xContext.getServiceManager().createInstanceWithContext("com.sun.star.i18n.Transliteration", xContext) 68 ); 69 oObj.loadModule(TransliterationModules.LOWERCASE_UPPERCASE, loc); 70 } 71 72 /** 73 * Check lowercase - uppercase conversion of chars 74 */ 75 @Test _transliterateChar2Char()76 public void _transliterateChar2Char() { 77 boolean result = true; 78 char in = 'a'; 79 char out = ' '; 80 try { 81 out = oObj.transliterateChar2Char(in) ; 82 result &= out == 'A'; 83 in = '$'; // should not be changed 84 out = oObj.transliterateChar2Char(in) ; 85 result &= out == '$'; 86 } 87 catch(com.sun.star.i18n.MultipleCharsOutputException e) { 88 e.printStackTrace(System.out); 89 } 90 Assert.assertTrue("transliterateChar2Char()", result); 91 } 92 93 /** 94 * Check lowercase - uppercase conversion of char to string 95 */ _transliterateChar2String()96 public void _transliterateChar2String() { 97 boolean result = true; 98 char in = 'a'; 99 String out = null; 100 out = oObj.transliterateChar2String('a') ; 101 result &= out.equals("A"); 102 in = '$'; // should not be changed 103 out = oObj.transliterateChar2String(in) ; 104 result &= out.equals("$"); 105 Assert.assertTrue("transliterateChar2String()", result); 106 } 107 108 /** 109 * Check lowercase - uppercase conversion of strings 110 */ _transliterateString2String()111 public void _transliterateString2String() { 112 boolean result = true; 113 String in = "aAbBcC"; 114 String out = null; 115 out = oObj.transliterateString2String(in, 0, 6) ; 116 result &= out.equals("AABBCC"); 117 in = "$"; // should not be changed 118 out = oObj.transliterateString2String(in, 0, 1) ; 119 result &= out.equals("$"); 120 Assert.assertTrue("transliterateString2String()", result); 121 } 122 } 123