IShell\r
{\r
/**\r
+ * Terminate shell after delay and convert result to object of T\r
+ * \r
+ * @param instance instance for result\r
+ * @param delay\r
+ * @return\r
+ * \r
+ * @throws Exception\r
+ */\r
+ <T> T expect( final T instance, long delay) throws Exception;\r
+ \r
+ /**\r
* Convert result to object of T\r
* \r
* @param instance instance for result\r
*/\r
<T> T expect( final T instance ) throws Exception;\r
\r
+ /**\r
+ * Write data to the process shell executed\r
+ * \r
+ * @param data data written to the process\r
+ * @param delay time over which data written\r
+ * @throws Exception\r
+ */\r
+ public void write( final String data, final long delay ) throws Exception;\r
+ \r
}\r
import static org.tizen.sdblib.util.ThreadUtil.trySleep;\r
\r
import java.io.BufferedReader;\r
+import java.io.BufferedWriter;\r
+import java.io.IOException;\r
+import java.io.OutputStreamWriter;\r
import java.io.StringReader;\r
import java.lang.annotation.Annotation;\r
import java.lang.reflect.Array;\r
{\r
return new Shell( cmd );\r
}\r
+ \r
+ /**\r
+ * Starting entry method and wait until process is terminated\r
+ * \r
+ * @param cmd command to execute\r
+ * \r
+ * @throw Exception If execution fail\r
+ */\r
+ public static\r
+ void\r
+ runAndWait(\r
+ final String cmd\r
+ )\r
+ throws Exception\r
+ {\r
+ Shell shell = new Shell( cmd );\r
+ shell.process.waitFor();\r
+ }\r
\r
/**\r
* process\r
* Error stream dispenser\r
*/\r
final StreamGobbler error;\r
-\r
+ \r
/**\r
- * Constructor with command\r
+ * Writer for writing data to the process\r
+ */\r
+ final BufferedWriter out;\r
+ \r
+ /**\r
+ * Constructor with command and boot the input and error stream\r
* \r
* @param cmd command to execution\r
* \r
{\r
process = Runtime.getRuntime().exec( cmd );\r
startTime = System.currentTimeMillis();\r
- \r
in = new StreamGobbler( process.getInputStream() );\r
error = new StreamGobbler( process.getErrorStream() );\r
+ out = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));\r
\r
in.boot();\r
error.boot();\r
}\r
\r
- /* (non-Javadoc)\r
+ /** (non-Javadoc)\r
+ * @see org.tizen.common.IShell#write(String, long)\r
+ */\r
+ public\r
+ void\r
+ write(\r
+ final String data,\r
+ final long delay\r
+ )\r
+ throws Exception\r
+ {\r
+ if(delay > 0) {\r
+ Thread.sleep(delay);\r
+ }\r
+ out.append(data);\r
+ out.newLine();\r
+ try {\r
+ out.flush();\r
+ }\r
+ catch (IOException e){\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ /** (non-Javadoc)\r
+ * @see org.tizen.common.IShell#expect(Object, long)\r
+ */\r
+ public <T>\r
+ T\r
+ expect(\r
+ final T instance,\r
+ long delay\r
+ )\r
+ throws Exception\r
+ {\r
+ trySleep(delay);\r
+ process.destroy();\r
+ final String result = in.getResult();\r
+ \r
+ return convert(instance, result);\r
+ }\r
+ \r
+ /** (non-Javadoc)\r
* @see org.tizen.common.IShell#expect(java.lang.Object)\r
*/\r
public <T>\r
}\r
\r
final String result = in.getResult();\r
- \r
+ return convert(instance, result);\r
+ }\r
+ \r
+ private <T>\r
+ T\r
+ convert (\r
+ final T instance, \r
+ String result\r
+ ) \r
+ throws Exception {\r
final BufferedReader reader = new BufferedReader( new StringReader( result ) );\r
\r
String line = null;\r
package org.tizen.common.sdb;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.tizen.common.Shell.run;
+import static org.junit.Assert.*;
+import static org.tizen.common.Shell.*;
import static org.tizen.common.sdb.SdbTestUtil.*;
-import org.junit.BeforeClass;
+import java.text.MessageFormat;
+
import org.junit.Test;
import org.tizen.common.Pattern;
*/
public class ConnectTest {
- @BeforeClass
- public static void prepareTest() throws Exception{
- SdbTestUtil.prepareTest();
- }
+ //connect and disconnect works async
+ public static final int CONNECT_SLEEP = 1000;
/**
* Test {sdb connect}
try {
int port = getPorts()[0];
- run( SDB_PATH + " disconnect").expect(new ConnectResult());
- run( SDB_PATH + " connect " + LOOPBACK_IP + ":" + port).expect(new ConnectResult());
-
- boolean success = false;
- String errMsg = "";
- for(int i=0; i < MAX_TRIAL; i++) {
- final ConnectResult result = run( SDB_PATH + " devices").expect( new ConnectResult() );
- if(result == null) {
- errMsg = "result for sdb devices for connect is null";
- }
- else if(result.tcpPortNums == null) {
- errMsg = "tcp port number of sdb devices for connect is null";
- }
- else if(result.tcpPortNums.length <= 0) {
- errMsg = "no devices are connected";
- }
- else {
- assertTrue("More than one devices are connected", result.tcpPortNums.length == 1);
- int tcpPort = new Integer(result.tcpPortNums[0]);
- assertEquals(String.format("Device port: '%s' and connected port: '%s' are not matched", port, tcpPort), port, tcpPort);
- success = true;
- break;
- }
- }
- assertTrue(errMsg, success);
+ runAndWait(SDB_PATH + " disconnect");
+ Thread.sleep(CONNECT_SLEEP);
+ runAndWait( SDB_PATH + " connect " + LOOPBACK_IP + ":" + port);
+ final ConnectResult result = run( SDB_PATH + " devices").expect( new ConnectResult() );
+ assertNotNull("tcp port number of sdb devices for connect is null", result.tcpPortNums);
+ int tcpPort = new Integer(result.tcpPortNums[0]);
+ assertTrue("More than one devices are connected", result.tcpPortNums.length == 1);
+ assertEquals(MessageFormat.format("Device port: \'{0}\' and connected port: \'{1}\' are not matched", port, result.tcpPortNums[0]),
+ port, tcpPort);
}
finally {
- run( SDB_PATH + " disconnect");
+ runAndWait( SDB_PATH + " disconnect");
}
}
@Test
public void test_disconnect() throws Exception {
- class DisconnectResult {
- @Pattern( pattern = "{0}", index = 0) public String wholeStrings[];
- }
-
try {
- run( SDB_PATH + " disconnect").expect(new DisconnectResult());
+ runAndWait( SDB_PATH + " disconnect");
+ Thread.sleep(CONNECT_SLEEP);
int ports[] = getPorts();
- run( SDB_PATH + " connect " + LOOPBACK_IP + ":" + ports[0]).expect(new DisconnectResult());
- run( SDB_PATH + " disconnect " + LOOPBACK_IP + ":" + ports[0]).expect(new DisconnectResult());
-
- boolean success = true;
- String errMsg = "";
- for(int i=0; i< MAX_TRIAL; i++) {
- final DisconnectResult result = run( SDB_PATH + " devices").expect( new DisconnectResult() );
- if(result == null) {
- errMsg = "result of sdb devices for disconnect is null";
- success = false;
- }
- else {
- String[] wholeStrings = result.wholeStrings;
-
- for(String wholeString: wholeStrings) {
- if(wholeString.contains(LOOPBACK_IP)) {
- errMsg = "disconnect failed";
- success = false;
- break;
- }
- }
- }
- if(success) {
- break;
- }
- success = true;
+ runAndWait( SDB_PATH + " connect " + LOOPBACK_IP + ":" + ports[0]);
+ Thread.sleep(CONNECT_SLEEP);
+ runAndWait( SDB_PATH + " disconnect " + LOOPBACK_IP + ":" + ports[0]);
+ Thread.sleep(CONNECT_SLEEP);
+ String[] results = SdbTestUtil.runAndGetWholeString(SDB_PATH + " devices", true);
+ for(String result: results) {
+ assertFalse(MessageFormat.format("fail to disconnect {0}", result), result.contains(LOOPBACK_IP));
}
-
- assertTrue(errMsg, success);
-
}
finally {
- run( SDB_PATH + " disconnect");
+ runAndWait( SDB_PATH + " disconnect");
}
}
package org.tizen.common.sdb;
import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
import org.junit.Test;
/**
*/
public class DevicesTest {
- @BeforeClass
- public static void prepareTest() throws Exception{
- SdbTestUtil.prepareTest();
- }
-
/**
* Test {sdb devices}
*
package org.tizen.common.sdb;
import static org.junit.Assert.*;
-import static org.tizen.common.Shell.run;
import static org.tizen.common.sdb.SdbTestUtil.SDB_PATH;
-import org.junit.BeforeClass;
import org.junit.Test;
-import org.tizen.common.Pattern;
/**
* <p>
*/
public class GetSerialNoTest {
- @BeforeClass
- public static void prepareTest() throws Exception {
- SdbTestUtil.prepareTest();
- }
-
/**
* Test {sdb get-serialno}
*
*/
@Test
public void test_getserialno() throws Exception {
-
- class GetSerialNoResult {
- @Pattern( pattern = "{0}", index = 0) public String serialNo[];
- }
String[] serialNos = SdbTestUtil.getSerialNumber();
String serialNo = serialNos[0];
- final GetSerialNoResult result = run( String.format("%s -s %s get-serialno", SDB_PATH, serialNo)).expect(new GetSerialNoResult() );
-
- assertNotNull("result of get-serialno is null", result);
- assertNotNull("parsing result of get-serialno is null", result.serialNo);
- assertTrue("cannot parse result of get-serialno", result.serialNo.length > 0);
- assertEquals(serialNo, result.serialNo[0]);
+ String[] wholeStrings = SdbTestUtil.runAndGetWholeString(String.format("%s -s %s get-serialno", SDB_PATH, serialNo), true);
+ assertTrue("cannot parse result of get-serialno", wholeStrings.length > 0);
+ assertEquals(serialNo, wholeStrings[0]);
}
}
package org.tizen.common.sdb;
import static org.junit.Assert.*;
-import static org.tizen.common.Shell.run;
import static org.tizen.common.sdb.SdbTestUtil.SDB_PATH;
import java.text.MessageFormat;
-import org.junit.BeforeClass;
import org.junit.Test;
-import org.tizen.common.Pattern;
/**
* <p>
*/
public class GetStateTest {
- @BeforeClass
- public static void prepareTest() throws Exception {
- SdbTestUtil.prepareTest();
- }
-
/**
* Test {sdb get-serialno}
*
@Test
public void test_getstate() throws Exception {
- class GetStateResult {
- @Pattern( pattern = "{0}", index = 0) public String state[];
- }
String[] serialNos = SdbTestUtil.getSerialNumber();
String serialNo = serialNos[0];
-
- final GetStateResult result = run( String.format("%s -s %s get-state", SDB_PATH, serialNo)).expect(new GetStateResult() );
-
- assertNotNull("result of get-state is null", result);
- assertNotNull("parsing result of get-state is null", result.state);
- assertTrue("cannot parse result of get-state", result.state.length > 0);
- String _state = result.state[0];
- assertTrue(MessageFormat.format("unexpected state {0}", _state), _state.equals("offline") || _state.equals("device"));
+ String[] states = SdbTestUtil.runAndGetWholeString(String.format("%s -s %s get-state", SDB_PATH, serialNo), true);
+ assertTrue("cannot parse result of get-state", states.length > 0);
+ assertTrue(MessageFormat.format("unexpected state {0}", states[0]),
+ states[0].equals("offline") || states[0].equals("device"));
}
}
package org.tizen.common.sdb;
import static org.junit.Assert.assertTrue;
-import static org.tizen.common.Shell.run;
+import static org.tizen.common.Shell.*;
import static org.tizen.common.sdb.SdbTestUtil.*;
import java.io.BufferedInputStream;
import java.io.OutputStream;
import java.text.MessageFormat;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.tizen.common.Pattern;
import org.tizen.common.util.FileUtil;
*/
public class InstallTest {
- @BeforeClass
- public static void prepareTest() throws Exception{
- SdbTestUtil.prepareTest();
- }
+ public static int INSTALL_WAIT = 1000;
/**
* Test {sdb install, sdb uninstall (native)}
assertTrue("tpk file is not copied", new File(copiedName).exists());
String serialNumber = getSerialNumber()[0];
- run( SDB_PATH + String.format(" -s %s uninstall %s", serialNumber, appId)).expect(new InstallUninstallResult());
- run( SDB_PATH + String.format(" -s %s install %s", serialNumber, copiedName)).expect(new InstallUninstallResult());
-
+ runAndWait(SDB_PATH + String.format(" -s %s uninstall %s", serialNumber, appId));
+ runAndWait( SDB_PATH + String.format(" -s %s install %s", serialNumber, copiedName));
boolean success = false;
String errMsg = "";
for(int i=0; i < MAX_TRIAL; i++) {
success = true;
break;
}
+ Thread.sleep(INSTALL_WAIT);
}
assertTrue(errMsg, success);
- run( SDB_PATH + String.format(" -s %s uninstall %s", serialNumber, appId)).expect(new InstallUninstallResult());
-
+ runAndWait( SDB_PATH + String.format(" -s %s uninstall %s", serialNumber, appId));
success = false;
for(int i=0; i< MAX_TRIAL; i++) {
InstallUninstallResult result = run( SDB_PATH + String.format(" -s %s shell pkgcmd -l | grep %s", serialNumber, appId)).
success = true;
break;
}
- Thread.sleep(1000);
+ Thread.sleep(INSTALL_WAIT);
}
assertTrue(errMsg, success);
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.tizen.common.Shell.run;
+import static org.tizen.common.Shell.*;
import static org.tizen.common.sdb.SdbTestUtil.*;
import java.io.File;
import java.text.MessageFormat;
import java.util.List;
-import org.junit.BeforeClass;
import org.junit.Test;
-import org.tizen.common.Pattern;
import org.tizen.common.util.FileUtil;
import org.tizen.common.util.FileUtilTest;
* @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
*/
public class PullPushTest {
-
- @BeforeClass
- public static void prepareTest() throws Exception{
- SdbTestUtil.prepareTest();
- }
/**
* Test {sdb push, sdb pull (file)}
@Test
public void test_pushPullFile() throws Exception {
- class PushResult {
- @Pattern( pattern = "{0}", index = 0 ) public String wholeString;
- }
-
final String pushFileName = "push_file";
final String pullFileName = "pull_file";
final String tmpDir = "/tmp";
final String targetDst = tmpDir + "/" + pushFileName;
- String fileContent = generateRandomString(400, FILE_CONTENT_CHAR_LIST);
- File pushFile = new File(pushFileName);
- if(pushFile.exists()) {
- FileUtil.recursiveDelete(pushFile);
- }
-
- File pullFile = new File(pullFileName);
- if(pullFile.exists()) {
- FileUtil.recursiveDelete(pullFile);
- }
try {
- FileUtil.createTextFile(pushFile, fileContent, null);
-
- assertTrue(MessageFormat.format("fail to create file {0}", pushFile.getAbsolutePath()), pushFile.exists());
-
- String serialNumber = getSerialNumber()[0];
-
- run( SDB_PATH + String.format(" -s %s shell rm -rf %s", serialNumber, targetDst)).expect(new PushResult());
- run( SDB_PATH + String.format(" -s %s push %s %s", serialNumber, pushFileName, targetDst)).expect(new PushResult());
-
- boolean success = false;
- String errMsg = "";
- for(int i=0; i< MAX_TRIAL; i++) {
- PushResult result = run(SDB_PATH + String.format(" -s %s shell ls %s", serialNumber, targetDst)).expect(new PushResult());
- if(result == null) {
- errMsg = "result of shell is null";
- }
- else if(result.wholeString == null) {
- errMsg = "wholeString of shell is null";
- }
- else if(result.wholeString.equals(targetDst)) {
- success = true;
- break;
- }
- Thread.sleep(1000);
- }
- assertTrue(errMsg, success);
- run( SDB_PATH + String.format(" -s %s pull %s %s", serialNumber, targetDst, pullFileName)).expect(new PushResult());
-
- success = false;
- for(int i=0; i< MAX_TRIAL; i++) {
- if(pullFile.exists()) {
- success = true;
- break;
- }
- Thread.sleep(1000);
- }
-
- assertTrue(MessageFormat.format("fail to pull file {0}", pullFile.getAbsolutePath()), success);
- String result = FileUtil.readTextFile(pullFile, null);
-
- assertEquals(MessageFormat.format("pushed file {0} and pull file {1} are not same", pushFile.getAbsolutePath(), pullFile.getAbsolutePath()),
- result, fileContent);
+ pushPullAndCheck(pushFileName, targetDst, pullFileName, true);
}
finally {
+ File pushFile = new File(pushFileName);
if(pushFile.exists()) {
FileUtil.recursiveDelete(pushFile);
}
+ File pullFile = new File(pullFileName);
if(pullFile.exists()) {
FileUtil.recursiveDelete(pullFile);
}
@Test
public void test_pushPullDir() throws Exception {
- class PullResult {
- @Pattern( pattern = "{0}", index = 0 ) public String wholeString;
- }
-
final String pushDirName = "push_dir";
final String pullDirName = "pull_dir";
final String tmpDir = "/tmp";
final String targetDst = tmpDir + "/" + pushDirName;
-
-
- File pushDir = new File(pushDirName);
- if(pushDir.exists()) {
- FileUtil.recursiveDelete(pushDir);
- }
-
- File pullDir = new File(pullDirName);
- if(pullDir.exists()) {
- FileUtil.recursiveDelete(pullDir);
- }
-
try {
- generateRandomDir(pushDir, 5, 5, 3);
-
- assertTrue(MessageFormat.format("fail to create push directory {0}", pushDir.getAbsolutePath()), pushDir.exists());
-
- String serialNumber = getSerialNumber()[0];
- run( SDB_PATH + String.format(" -s %s shell rm -rf %s", serialNumber, targetDst)).expect(new PullResult());
- run( SDB_PATH + String.format(" -s %s push %s %s", serialNumber, pushDirName, targetDst)).expect(new PullResult());
-
- boolean success = false;
- String errMsg = "";
- for(int i=0; i< MAX_TRIAL; i++) {
- PullResult result = run(SDB_PATH + String.format(" -s %s shell ls -d %s", serialNumber, targetDst)).expect(new PullResult());
- if(result == null) {
- errMsg = "result of shell is null";
- }
- else if(result.wholeString == null) {
- errMsg = "wholeString of shell is null";
- }
- else if(result.wholeString.equals(targetDst)) {
- success = true;
- break;
- }
- else {
- errMsg = MessageFormat.format("Expected {0}, Actual {1}", targetDst, result.wholeString);
- }
- Thread.sleep(1000);
- }
-
- assertTrue(errMsg, success);
- run( SDB_PATH + String.format(" -s %s pull %s %s", serialNumber, targetDst, pullDirName)).expect(new PullResult());
-
- success = false;
- for(int i=0; i< MAX_TRIAL; i++) {
- if(pullDir.exists()) {
- success = true;
- break;
- }
- }
-
- assertTrue(MessageFormat.format("fail to pull directory {0}", pullDir.getAbsolutePath()), success);
- List<File> notPushPullList = FileUtilTest.compareFiles(pushDir.getAbsolutePath(), pullDir.getAbsolutePath());
- assertTrue(String.format("Following files are not pushed or pulled\n%s", listFiles(notPushPullList)), notPushPullList.size() == 0);
- List<File> morePushPullList = FileUtilTest.compareFiles(pullDir.getAbsolutePath(), pushDir.getAbsolutePath());
- assertTrue(String.format("Following files are pushed or pulled but not in source\n%s", listFiles(morePushPullList)), FileUtilTest.compareFiles(pullDir.getAbsolutePath(), pushDir.getAbsolutePath()).size() == 0);
+ pushPullAndCheck(pushDirName, targetDst, pullDirName, false);
}
finally {
+ File pushDir = new File(pushDirName);
if(pushDir.exists()) {
FileUtil.recursiveDelete(pushDir);
}
+ File pullDir = new File(pullDirName);
if(pullDir.exists()) {
FileUtil.recursiveDelete(pullDir);
}
}
}
+ private void pushPullAndCheck(String pushSrc, String pushDst, String pullDst, boolean file) throws Exception {
+
+ File pushFile = new File(pushSrc);
+ if(pushFile.exists()) {
+ FileUtil.recursiveDelete(pushFile);
+ }
+
+ File pullFile = new File(pullDst);
+ if(pullFile.exists()) {
+ FileUtil.recursiveDelete(pullFile);
+ }
+
+ String fileContent = "";
+ if(file) {
+ fileContent = generateRandomString(400, FILE_CONTENT_CHAR_LIST);
+ FileUtil.createTextFile(pushFile, fileContent, null);
+ }
+ else {
+ generateRandomDir(pushFile, 5, 5, 3);
+ }
+
+ assertTrue(MessageFormat.format("fail to create file {0}", pushFile.getAbsolutePath()), pushFile.exists());
+ String serialNumber = getSerialNumber()[0];
+ runAndWait( SDB_PATH + String.format(" -s %s shell rm -rf %s", serialNumber, pushDst));
+ assertTrue(MessageFormat.format("rm fail to remove {0}", pushDst),
+ checkTargetFileExist(pushDst, serialNumber, file, false));
+ runAndWait( SDB_PATH + String.format(" -s %s push %s %s", serialNumber, pushSrc, pushDst));
+ assertTrue(MessageFormat.format("{0} does not exist in target {1}", pushDst, serialNumber),
+ checkTargetFileExist(pushDst, serialNumber, file, true));
+ runAndWait( SDB_PATH + String.format(" -s %s pull %s %s", serialNumber, pushDst, pullDst));
+ assertTrue(MessageFormat.format("{0} does not exist in host", pullFile.getAbsolutePath()), pullFile.exists());
+
+ if( file ) {
+ String result = FileUtil.readTextFile(pullFile, null);
+ assertEquals(MessageFormat.format("pushed file {0} and pull file {1} are not same", pushFile.getAbsolutePath(), pullFile.getAbsolutePath()),
+ result, fileContent);
+ }
+ else {
+ List<File> notPushPullList = FileUtilTest.compareFiles(pushFile.getAbsolutePath(), pullFile.getAbsolutePath());
+ assertTrue(String.format("Following files are not pushed or pulled\n%s",
+ listFiles(notPushPullList)), notPushPullList.size() == 0);
+ List<File> morePushPullList = FileUtilTest.compareFiles(pullFile.getAbsolutePath(), pushFile.getAbsolutePath());
+ assertTrue(String.format("Following files are pushed or pulled but not in source\n%s", listFiles(morePushPullList)),
+ FileUtilTest.compareFiles(pullFile.getAbsolutePath(), pushFile.getAbsolutePath()).size() == 0);
+ }
+ }
+
private String listFiles(List<File> fileList) {
StringBuffer buffer = new StringBuffer();
for(File file: fileList) {
}
return buffer.toString();
}
+
+ private boolean checkTargetFileExist(String fileName, String serial, boolean file, boolean exist) throws Exception {
+ String[] results = null;
+ for( int i =0; i < MAX_TRIAL; i++) {
+ if(file) {
+ results = runAndGetWholeString(SDB_PATH + String.format(" -s %s shell ls %s", serial, fileName), true);
+ }
+ else {
+ results = runAndGetWholeString(SDB_PATH + String.format(" -s %s shell ls -d %s", serial, fileName), true);
+ }
+ for(String result: results) {
+ if(exist) {
+ if(result.equals(fileName)) {
+ return true;
+ }
+ }
+ else {
+ if(result.contains("No such file or directory")) {
+ return true;
+ }
+ }
+ }
+ Thread.sleep(1000);
+ }
+ return false;
+ }
}
--- /dev/null
+/*
+ * Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Ho Namkoong <ho.namkoong@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.common.sdb;
+
+import static org.junit.Assert.*;
+import static org.tizen.common.sdb.SdbTestUtil.*;
+import static org.tizen.common.Shell.*;
+
+import java.text.MessageFormat;
+
+import org.junit.Test;
+import org.tizen.common.IShell;
+import org.tizen.common.Pattern;
+import org.tizen.common.Token;
+
+/**
+ * <p>
+ * RootTest
+ *
+ * Test case for sdb root on and sdb root off
+ *
+ * </p>
+ *
+ * @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+public class RootTest {
+
+ class RootResult {
+ @Token(from = "Switched to", to = "account mode")
+ public String result;
+ }
+
+ /**
+ * Test {sdb root on}
+ *
+ * @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+ @Test
+ public void test_root_on() throws Exception{
+
+ String[] serials = getSerialNumber();
+ runAndWait(MessageFormat.format("{0} -s {1} {2}", SDB_PATH, serials[0], "root off"));
+ RootResult result = run(MessageFormat.format("{0} -s {1} {2}", SDB_PATH, serials[0], "root on"))
+ .expect(new RootResult());
+
+ assertNotNull("output of root on is null", result);
+ assertEquals("'root'", result.result);
+ runShellAndExpect(serials[0], "#");
+ }
+
+ /**
+ * Test {sdb root off}
+ *
+ * @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+ @Test
+ public void test_root_off() throws Exception {
+
+ String[] serials = getSerialNumber();
+ runAndWait(MessageFormat.format("{0} -s {1} {2}", SDB_PATH, serials[0], "root on"));
+ RootResult result = run(MessageFormat.format("{0} -s {1} {2}", SDB_PATH, serials[0], "root off")).
+ expect(new RootResult());
+
+ assertNotNull("output of root off is null", result);
+ assertEquals("'developer'", result.result);
+ runShellAndExpect(serials[0], "$");
+ }
+
+ private static void runShellAndExpect(String serial, String expect) throws Exception {
+ class RootShellResult {
+ @Pattern(pattern = "sh-4.1{0}exit", index = 0)
+ public String token;
+ }
+
+ IShell shell = run(String.format("%s -s %s %s", SDB_PATH, serial, "shell"));
+ shell.write("exit", 1000);
+ RootShellResult result = shell.expect(new RootShellResult());
+
+ assertNotNull("output of shell is null", result.token);
+ assertEquals(expect, result.token);
+ }
+}
*/
package org.tizen.common.sdb;
+import static org.tizen.common.Shell.runAndWait;
+
+import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
*/
@RunWith(Suite.class)
@SuiteClasses({ ConnectTest.class, DevicesTest.class, GetSerialNoTest.class,
- GetStateTest.class, InstallTest.class, PullPushTest.class, StartKillTest.class})
+ GetStateTest.class, InstallTest.class, PullPushTest.class, VersionTest.class,
+ ShellTest.class, StatusWindowTest.class, RootTest.class, StartKillTest.class})
public class SdbTestSuite {
+ @BeforeClass
+ public static void prepareTest() throws Exception {
+ runAndWait( SdbTestUtil.SDB_PATH + " kill-server");
+ Thread.sleep(1000);
+ runAndWait(SdbTestUtil.SDB_PATH + " start-server");
+ Thread.sleep(1000);
+ }
+
}
package org.tizen.common.sdb;
import static org.junit.Assert.*;
-import static org.tizen.common.Shell.run;
+import static org.tizen.common.Shell.*;
import java.io.File;
+import java.text.MessageFormat;
import java.util.Random;
+import org.tizen.common.IShell;
import org.tizen.common.Pattern;
import org.tizen.common.util.FileUtil;
import org.tizen.common.util.StringUtil;
static final String LOOPBACK_IP = "127.0.0.1";
static final int MAX_TRIAL = 10;
+ static final char CTRL_C = '\u0003';
static String SDB_PATH;
static {
static int[] getPorts() throws Exception {
class PortResult {
@Pattern( pattern = "emulator-{0}\t{1}", index = 0) public String[] devicePortNum;
- @Pattern( pattern = "{0}", index = 0) public String[] wholeString;
};
final PortResult resultString = run( SDB_PATH + " devices" ).expect( new PortResult() );
class SerialResult {
@Pattern( pattern = "{0}\t{1}", index = 0 ) public String[] deviceSerialName;
- @Pattern(pattern = "{0}", index = 0) public String[] wholeString;
};
String[] result = null;
}
}
- static void prepareTest() throws Exception {
- run( SDB_PATH + " kill-server").expect(new SdbTestUtil());
- run(SDB_PATH + " start-server").expect(new SdbTestUtil());
+ static String[] getWholeString(IShell shell, boolean assertNotNull) throws Exception {
+ class WholeResult {
+ @Pattern( pattern = "{0}", index = 0) public String wholeStrings[];
+ }
+
+ WholeResult result = shell.expect(new WholeResult());
+ if(assertNotNull) {
+ assertNotNull("output of shell is null", result.wholeStrings);
+ }
+ return result.wholeStrings;
+ }
+
+ static String[] runAndGetWholeString(String command, boolean assertNotNull) throws Exception {
+ class WholeResult {
+ @Pattern( pattern = "{0}", index = 0) public String wholeStrings[];
+ }
+
+ WholeResult result = run(command).expect(new WholeResult());
+ if(assertNotNull) {
+ assertNotNull(MessageFormat.format("Result of command {0} is null", command), result.wholeStrings);
+ }
+ return result.wholeStrings;
}
}
--- /dev/null
+/*
+ * Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Ho Namkoong <ho.namkoong@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.common.sdb;
+
+import static org.junit.Assert.*;
+import static org.tizen.common.Shell.*;
+import static org.tizen.common.sdb.SdbTestUtil.*;
+
+import org.junit.Test;
+import org.tizen.common.IShell;
+
+/**
+ * <p>
+ * ShellTest
+ *
+ * Test case for sdb shell
+ *
+ * </p>
+ *
+ * @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+public class ShellTest {
+
+ /**
+ * Test {sdb shell}
+ *
+ * @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+ @Test
+ public void test_shell() throws Exception{
+ String[] serials = getSerialNumber();
+ IShell shell = run(String.format("%s -s %s %s", SDB_PATH, serials[0], "shell"));
+ shell.write("exit", 1000);
+ String[] results = getWholeString(shell, true);
+
+ boolean success = false;
+ for(String result: results) {
+ if(result.contains("sh-4.1")) {
+ success = true;
+ break;
+ }
+ }
+
+ assertTrue("fail to launch shell", success);
+ }
+
+}
package org.tizen.common.sdb;
import static org.junit.Assert.*;
-import static org.tizen.common.Shell.run;
-import static org.tizen.common.sdb.SdbTestUtil.SDB_PATH;
+import static org.tizen.common.Shell.*;
+import static org.tizen.common.sdb.SdbTestUtil.*;
import org.junit.Test;
-import org.tizen.common.Pattern;
/**
* <p>
* @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
*/
public class StartKillTest {
-
- class StartKillResult {
- @Pattern( pattern = "{0}", index = 0) public String wholeString[];
- }
/**
* Test {sdb start-server, kill-server}
public void test_start_kill_server() throws Exception {
try {
- run(SDB_PATH + " kill-server").expect(new StartKillResult());
- StartKillResult result = run(SDB_PATH + " start-server").expect(new StartKillResult());
- assertNotNull("result of start-server is null", result);
- assertNotNull("parsing result of start-server is null", result.wholeString);
-
- boolean success = false;
- for(int i = 0; i< result.wholeString.length; i++) {
- if(result.wholeString[i].contains("daemon not running")) {
- success = true;
- break;
- }
- }
+ runAndWait(SDB_PATH + " kill-server");
+ startServerAndCheck("sdb is not started or killed");
- assertTrue("sdb is not started or killed", success);
+ String[] results = runAndGetWholeString(SDB_PATH + " start-server", false);
+ assertNull("sdb is not started", results);
- result = run(SDB_PATH + " start-server").expect(new StartKillResult());
- assertNotNull("result of start-server is null", result);
- assertNull("sdb is not started", result.wholeString);
-
- run(SDB_PATH + " kill-server").expect(new StartKillResult());
- result = run(SDB_PATH + " start-server").expect(new StartKillResult());
- assertNotNull("result of start-server is null", result);
- assertNotNull("parsing result of start-server is null", result.wholeString);
-
- success = false;
- for(int i = 0; i< result.wholeString.length; i++) {
- if(result.wholeString[i].contains("daemon not running")) {
- success = true;
- break;
- }
- }
-
- assertTrue("sdb is not killed", success);
+ runAndWait(SDB_PATH + " kill-server");
+ startServerAndCheck("sdb is not killed");
}
finally {
run(SDB_PATH + " kill-server");
}
}
+
+ private static void startServerAndCheck(String msg) throws Exception {
+ String[] results = runAndGetWholeString(SDB_PATH + " start-server", true);
+
+ boolean success = false;
+ for(String result: results) {
+ if(result.contains("daemon not running")) {
+ success = true;
+ break;
+ }
+ }
+ assertTrue(msg, success);
+ }
}
--- /dev/null
+/*
+ * Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Ho Namkoong <ho.namkoong@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.common.sdb;
+
+import static org.junit.Assert.*;
+import static org.tizen.common.sdb.SdbTestUtil.*;
+import static org.tizen.common.Shell.*;
+
+import java.text.MessageFormat;
+
+import org.junit.Test;
+import org.tizen.common.Pattern;
+
+/**
+ * <p>
+ * StatusWindowTest
+ *
+ * Test case for sdb status-window
+ *
+ * </p>
+ *
+ * @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+public class StatusWindowTest {
+
+ /**
+ * Test {sdb status-window}
+ *
+ * @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+ @Test
+ public void test_status_window() throws Exception{
+
+ class StatusWindowResult {
+ @Pattern(pattern = "State:{0}", index = 0)
+ public String state;
+ }
+
+ String[] serials = getSerialNumber();
+ StatusWindowResult result = run(String.format("%s -s %s %s", SDB_PATH, serials[0], "status-window")).
+ expect(new StatusWindowResult(), 2000);
+ assertNotNull("result of status-window is null", result.state);
+ assertTrue(MessageFormat.format("unexpected state: {0}", result.state),
+ result.state.equals("device") || result.state.equals("offline"));
+
+ }
+
+}
--- /dev/null
+/*
+ * Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Ho Namkoong <ho.namkoong@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.common.sdb;
+
+import static org.junit.Assert.*;
+import static org.tizen.common.sdb.SdbTestUtil.*;
+
+import org.junit.Test;
+
+/**
+ * <p>
+ * VersionTest
+ *
+ * Test case for sdb version
+ *
+ * </p>
+ *
+ * @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+public class VersionTest {
+
+ /**
+ * Test {sdb version}
+ *
+ * @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+ @Test
+ public void test_version() throws Exception {
+ String[] results = runAndGetWholeString(String.format("%s %s", SdbTestUtil.SDB_PATH, "version"), true);
+ assertTrue(results[0].contains("Smart Development Bridge version"));
+ }
+
+}