1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.eclipse.common.util;
17  
18  import org.eclipse.swt.SWT;
19  import org.eclipse.swt.graphics.Color;
20  
21  /**
22   * {@link SWTUtil} のためのテストクラスです。<br />
23   * 
24   * @author y-komori
25   */
26  public class SWTUtilTest extends AbstractShellTest {
27  
28      public void testConvertConstantName() {
29          assertEquals("Aaa", SWTUtil.convertConstantName("AAA"));
30          assertEquals("AaaBbb", SWTUtil.convertConstantName("AAA_BBB"));
31          assertEquals("AaaBbbCcc", SWTUtil.convertConstantName("AAA_BBB_CCC"));
32  
33      }
34  
35      public void testGetSWTConstant() {
36          assertEquals(SWT.ABORT, SWTUtil.getSWTConstant("ABORT"));
37          assertEquals(SWT.BOLD, SWTUtil.getSWTConstant("BOLD"));
38          assertEquals(SWT.CLOSE, SWTUtil.getSWTConstant("CLOSE"));
39          assertEquals(SWT.NONE, SWTUtil.getSWTConstant("NONE"));
40          assertEquals(SWT.NONE, SWTUtil.getSWTConstant("dummy"));
41      }
42  
43      public void testGetStyle() {
44          assertEquals(SWT.RIGHT, SWTUtil.getStyle("RIGHT"));
45          assertEquals(SWT.HORIZONTAL | SWT.SHADOW_IN | SWT.CENTER, SWTUtil
46                  .getStyle("HORIZONTAL,SHADOW_IN,CENTER"));
47          assertEquals(SWT.HORIZONTAL | SWT.SHADOW_IN | SWT.CENTER, SWTUtil
48                  .getStyle("SHADOW_IN,CENTER,HORIZONTAL"));
49          assertEquals(SWT.VERTICAL | SWT.SHADOW_OUT | SWT.LEFT, SWTUtil
50                  .getStyle(" VERTICAL  , SHADOW_OUT ,  LEFT  "));
51          assertEquals(SWT.VERTICAL | SWT.LEFT, SWTUtil
52                  .getStyle(" VERTICAL  , dummy ,  LEFT  "));
53          assertEquals(SWT.NONE, SWTUtil.getStyle(""));
54          assertEquals(SWT.NONE, SWTUtil.getStyle(", dummy , , ,"));
55          assertEquals(SWT.NONE, SWTUtil.getStyle(null));
56      }
57  
58      public void testGetColor() {
59          assertEquals((new Color(display, 255, 0, 0)).toString(), SWTUtil
60                  .getColor("#FF0000").toString());
61          assertEquals((new Color(display, 0, 255, 0)).toString(), SWTUtil
62                  .getColor("#00FF00").toString());
63          assertEquals((new Color(display, 0, 0, 255)).toString(), SWTUtil
64                  .getColor("#0000FF").toString());
65      }
66  }