TOOLS: Showed proper error message when user input empty ip or port in 'Remote Device... 41/17041/5
authorshingil.kang <shingil.kang@samsung.com>
Mon, 3 Mar 2014 06:04:05 +0000 (15:04 +0900)
committershingil.kang <shingil.kang@samsung.com>
Tue, 4 Mar 2014 05:16:28 +0000 (14:16 +0900)
Change-Id: If078c5b019e041f4457b6e60acae1e4453208001
Signed-off-by: shingil.kang <shingil.kang@samsung.com>
org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionUIMessages.java
org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionUIMessages.properties
org.tizen.common.connection/src/org/tizen/common/connection/explorer/RemoteDeviceManagerDialog.java
org.tizen.common/src/org/tizen/common/util/ValidationUtil.java
org.tizen.common/test/src/org/tizen/common/util/ValidationUtilTest.java

index a3a4c6e..95f82ea 100644 (file)
@@ -64,7 +64,9 @@ public class ConnectionUIMessages extends NLS
     public static String Explorer_Messsage_PlatformLogReboot;
 
     public static String Remote_Message_EmptyName;
+    public static String Remote_Message_EmptyIp;
     public static String Remote_Message_InvalidIp;
+    public static String Remote_Message_EmptyPort;
     public static String Remote_Message_InvalidPort;
 
     static
index cc0af33..28f8466 100644 (file)
@@ -34,6 +34,8 @@ Explorer_Tree_Header = Files
 
 Explorer_Messsage_PlatformLogReboot = You must reboot this target to apply the change.
 
-Remote_Message_EmptyName = Name is empty.\nPlease input name. 
+Remote_Message_EmptyName = Name is empty.\nPlease input name.
+Remote_Message_EmptyIp = IP address is empty.\nPlease input IP address. 
 Remote_Message_InvalidIp = IP address is invalid.\nPlease input proper IP address.
-Remote_Message_InvalidPort = port is invalid.\nPlease input proper port.
+Remote_Message_EmptyPort = port is empty.\nPlease input port.
+Remote_Message_InvalidPort = port is invalid.\nPlease input proper port.
\ No newline at end of file
index e989690..6e6a26a 100644 (file)
@@ -60,7 +60,9 @@ import org.tizen.common.core.application.InstallPathConfig;
 import org.tizen.common.util.DialogUtil;
 import org.tizen.common.util.FilenameUtil;
 import org.tizen.common.util.HostUtil;
+import org.tizen.common.util.ValidationUtil;
 import org.tizen.sdblib.util.IOUtil;
+import org.tizen.sdblib.util.StringUtil;
 
 public class RemoteDeviceManagerDialog extends Dialog
 {
@@ -71,9 +73,6 @@ public class RemoteDeviceManagerDialog extends Dialog
 
     private static final String sdbConnectCommand = InstallPathConfig.getSDBPath() + " connect ";
     private static final String sdbDisconnectCommand = InstallPathConfig.getSDBPath() + " disconnect ";
-
-    private static final String IPADDRESS_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
-    private static final String PORT_PATTERN = "^(6553[0-5]|655[0-2]\\d|65[0-4]\\d\\d|6[0-4]\\d{3}|[1-5]\\d{4}|[1-9]\\d{0,3}|0)$";
     private static final String REMOTE_DEVICE_LIST_FILE = InstallPathConfig.getUserDataPath() + File.separator + "ide" + File.separator + "remote_device.list";
 
     private Button newButton;
@@ -366,28 +365,36 @@ public class RemoteDeviceManagerDialog extends Dialog
 
     private boolean isValidRemoteDevice(String name, String ip, String port)
     {
-        if (!name.equals(""))
+        if (!StringUtil.isEmpty(name))
         {
-            Pattern ipPattern = Pattern.compile(IPADDRESS_PATTERN);
-            Matcher ipMatcher = ipPattern.matcher(ip);
-
-            if (ipMatcher.find())
+            if (!StringUtil.isEmpty(ip))
             {
-                Pattern portPattern = Pattern.compile(PORT_PATTERN);
-                Matcher portMatcher = portPattern.matcher(port);
-
-                if (portMatcher.find())
+                if (ValidationUtil.checkForIP(ip))
                 {
-                    return true;
+                    if (!StringUtil.isEmpty(port))
+                    {
+                        if (ValidationUtil.checkForPort(port))
+                        {
+                            return true;
+                        }
+                        else
+                        {
+                            DialogUtil.openErrorDialog("\"" + port + "\" " + ConnectionUIMessages.Remote_Message_InvalidPort);
+                        }
+                    }
+                    else
+                    {
+                        DialogUtil.openErrorDialog(ConnectionUIMessages.Remote_Message_EmptyPort);
+                    }
                 }
                 else
                 {
-                    DialogUtil.openErrorDialog("\"" + port + "\" " + ConnectionUIMessages.Remote_Message_InvalidPort);
+                    DialogUtil.openErrorDialog("\"" + ip + "\" " + ConnectionUIMessages.Remote_Message_InvalidIp);
                 }
             }
             else
             {
-                DialogUtil.openErrorDialog("\"" + ip + "\" " + ConnectionUIMessages.Remote_Message_InvalidIp);
+                DialogUtil.openErrorDialog(ConnectionUIMessages.Remote_Message_EmptyIp);
             }
         }
         else
index 1d5da96..376f029 100644 (file)
@@ -61,6 +61,8 @@ public class ValidationUtil {
     private static final String REGEX_FILEURI = "([a-zA-Z0-9\\-_\\.!\\~\\*'\\(\\);\\?\\@\\&=\\+$,]|(%[a-fA-F0-9]{2}))*"; //$NON-NLS-1$
     private static final String REGEX_VERSION = "[0-9]{1,3}\\.[0-9]{1,3}(\\.[0-9]{1,5})?"; //$NON-NLS-1$
     private static final String REGEX_APPWIDGETID = "[0-9a-zA-Z]{10}\\.[0-9a-zA-Z]{1,52}\\.[0-9a-zA-Z]{1,}"; //$NON-NLS-1$
+    private static final String REGEX_IPADDRESS = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; //$NON-NLS-1$
+    private static final String REGEX_PORT = "^(6553[0-5]|655[0-2]\\d|65[0-4]\\d\\d|6[0-4]\\d{3}|[1-5]\\d{4}|[1-9]\\d{0,3}|0)$"; //$NON-NLS-1$
 
     public static final String WIDGET_CONTENT_FILE_EXTENSIONS[] = { ".html", ".htm", ".xhtml", ".xht", ".svg" }; // http://www.w3.org/TR/widgets/#default-start-files
     public static final String WIDGET_ICON_FILE_EXTENSIONS[] = { ".png", ".gif", ".jpg", ".ico" }; // http://www.w3.org/TR/widgets/#default-icons
@@ -205,6 +207,30 @@ public class ValidationUtil {
     }
 
     /**
+     * Checking for IP address.
+     * 
+     * @param ip
+     * @return {@code true} if id is valid IP
+     */
+    public static boolean checkForIP( String ip ) {
+        Pattern pattern = Pattern.compile( REGEX_IPADDRESS );
+        Matcher matcher = pattern.matcher( ip );
+        return matcher.matches();
+    }
+
+    /**
+     * Checking for port
+     * 
+     * @param port
+     * @return {@code true} if id is valid port
+     */
+    public static boolean checkForPort( String port ) {
+        Pattern pattern = Pattern.compile( REGEX_PORT );
+        Matcher matcher = pattern.matcher( port );
+        return matcher.matches();
+    }
+
+    /**
      * Checking for Widget icon file extension.
      * 
      * @param Icon file name
index c422384..fed6ce9 100755 (executable)
@@ -233,5 +233,45 @@ public class ValidationUtilTest {
             assertFalse( "Failed for \"" + id + "\"", ValidationUtil.checkForFileURI( id ) );
         }
     }
+    
+    /**
+     * Test {@link ValidationUtil#checkForIP(String value)}
+     *
+     * @throws Exception in case of failure in test
+     *
+     * @see {@link ValidationUtil#checkForIP(String value)}
+     */
+    @Test
+    public void test_checkForIP() throws Exception {
+        final String[] validedIPs = { "1.1.1.1", "11.11.11.11", "111.111.111.111", "255.255.255.255", "123.234.123.0" };
+        for ( String ip : validedIPs ) {
+            assertTrue( "Failed for \"" + ip + "\"", ValidationUtil.checkForIP( ip ) );
+        }
+
+        final String[] invalidedIPs = {"300.100.100.100", "1.1.1.1.1", "0.0.0.-1", "1.1.1.256", "a.1.1.1" };
+        for ( String ip : invalidedIPs) {
+            assertFalse( "Failed for \"" + ip + "\"", ValidationUtil.checkForIP( ip ) );
+        }
+    }
+    
+    /**
+     * Test {@link ValidationUtil#checkForPort(String value)}
+     *
+     * @throws Exception in case of failure in test
+     *
+     * @see {@link ValidationUtil#checkForPort(String value)}
+     */
+    @Test
+    public void test_checkForPort() throws Exception {
+        final String[] validedPorts = { "0", "1", "12", "123", "1234", "65535" };
+        for ( String port : validedPorts ) {
+            assertTrue( "Failed for \"" + port + "\"", ValidationUtil.checkForPort( port ) );
+        }
+
+        final String[] invalidedPorts = {"-1", "a", "2a", "65536", "123456" };
+        for ( String port : invalidedPorts ) {
+            assertFalse( "Failed for \"" + port + "\"", ValidationUtil.checkForPort( port ) );
+        }
+    }
 
 }