aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamilo Bernal2013-05-16 15:31:18 (EDT)
committerRoland Grunberg2013-05-29 13:43:56 (EDT)
commitcae48a22e30a260e964a44c89b977417474032ab (patch)
tree8cc986e6eb43bb017b77654cd0f72c7615bd37c4
parent4c98d8b6b6c06497e9448c4c23eece065dd3c80b (diff)
downloadorg.eclipse.linuxtools-cae48a22e30a260e964a44c89b977417474032ab.zip
org.eclipse.linuxtools-cae48a22e30a260e964a44c89b977417474032ab.tar.gz
org.eclipse.linuxtools-cae48a22e30a260e964a44c89b977417474032ab.tar.bz2
Perf: Add tests for the source diassembly view's search functionalityrefs/changes/34/13134/4
Change-Id: Ia4c21eb26ce6461e34b2972b087a84b9e2df837c Reviewed-on: https://git.eclipse.org/r/13134 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com> IP-Clean: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/AllPerfTests.java3
-rw-r--r--perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/FindActionTest.java105
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/SourceDisassemblyView.java27
3 files changed, 133 insertions, 2 deletions
diff --git a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/AllPerfTests.java b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/AllPerfTests.java
index f3ddb8b..41307f1 100644
--- a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/AllPerfTests.java
+++ b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/AllPerfTests.java
@@ -15,7 +15,8 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
- LaunchTabsTest.class,ModelTest.class,DataManipulatorTest.class,SaveSessionTest.class,StatsComparisonTest.class,LaunchTest.class, LaunchRemoteTest.class
+ LaunchTabsTest.class,ModelTest.class,DataManipulatorTest.class,SaveSessionTest.class,
+ StatsComparisonTest.class,LaunchTest.class, LaunchRemoteTest.class, FindActionTest.class
})
public class AllPerfTests {
diff --git a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/FindActionTest.java b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/FindActionTest.java
new file mode 100644
index 0000000..d00f9c8
--- /dev/null
+++ b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/FindActionTest.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.perf.tests;
+
+import static org.junit.Assert.assertEquals;
+import org.eclipse.linuxtools.internal.perf.ui.SourceDisassemblyView;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Shell;
+import org.junit.Test;
+
+/**
+ * Tests for perf source disassembly find text dialog.
+ */
+public class FindActionTest {
+ private static final String SAMPLE_STRS[] = new String[] { "sample", "styled", "text", " ", "tyled", "ample" };
+
+ @Test
+ public void testFindAction() {
+ for (String strFind : SAMPLE_STRS) {
+ int[] offsets = new int[] { 0, strFind.length()/2, strFind.length()};
+ for (int offset : offsets) {
+ testForwardSearch(offset , strFind);
+ testBackwardSearch(offset , strFind);
+ }
+ }
+ }
+
+ /**
+ * Test forward search functionality.
+ * @param offset offset at which searching starts
+ * @param findStr the string to find
+ */
+ private void testForwardSearch(int offset, String findStr) {
+ StubSourceDisassemblyView stubView = new StubSourceDisassemblyView();
+ String searchStr = stubView.getContent();
+ int[] indices = new int[]{
+ /*
+ * SourceDisassemblyView#findAndSelect parameters:
+ * - widgetOffset, findstring, searchforward, casesensitive, wholeword
+ */
+ stubView.findAndSelect(offset, findStr, true, true, false),
+ stubView.findAndSelect(offset, findStr, true, false, false)
+ };
+
+ int expected = -1;
+ for(int actual : indices){
+ expected = searchStr.indexOf(findStr, offset);
+ assertEquals("Failed on the following case:"
+ + " offset= " + offset
+ + " substring= " + findStr,
+ expected, actual);
+ }
+ }
+
+ /**
+ * Test backward search functionality.
+ * @param offset offset at which searching starts
+ * @param findStr the string to find
+ */
+ private void testBackwardSearch(int offset, String findStr) {
+
+ StubSourceDisassemblyView stubView = new StubSourceDisassemblyView();
+ String searchStr = stubView.getContent().substring(0, offset);
+ int[] indices = new int[]{
+ /*
+ * SourceDisassemblyView#findAndSelect parameters:
+ * - widgetOffset, findString, searchForward, caseSensitive, wholeWord
+ */
+ stubView.findAndSelect(offset, findStr, false, true, false),
+ stubView.findAndSelect(offset, findStr, false, false, false)
+ };
+
+ int expected = -1;
+ for(int actual : indices){
+ expected = searchStr.lastIndexOf(findStr, offset - 1);
+ assertEquals("Failed on the following case:"
+ + " offset= " + offset
+ + " substring= " + findStr,
+ expected, actual);
+ }
+ }
+
+ /**
+ * Stub source disassemlby view part.
+ */
+ private static class StubSourceDisassemblyView extends
+ SourceDisassemblyView {
+ public StubSourceDisassemblyView() {
+ Shell parent = new Shell();
+ StyledText txt = new StyledText(parent, SWT.DEFAULT);
+ txt.setText("sample styled text");
+ txt.setEditable(false);
+ setStyledText(txt);
+ }
+ }
+}
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/SourceDisassemblyView.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/SourceDisassemblyView.java
index a54a038..5b3fd4a 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/SourceDisassemblyView.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/SourceDisassemblyView.java
@@ -49,8 +49,8 @@ public class SourceDisassemblyView extends ViewPart implements IFindReplaceTarge
private static String ASM = "\\s+([0-9]+\\.[0-9]+ )?:\\s+[0-9a-f]+:\\s+[0-9a-z]+\\s+.*"; //$NON-NLS-1$
private static String CODE = "\\s+:\\s+.*"; //$NON-NLS-1$
private static String WORD_BOUNDARY = "\\b"; //$NON-NLS-1$'
- private StyledText text;
private static int SECONDARY_ID = 0;
+ private StyledText text;
public SourceDisassemblyView() {
}
@@ -74,6 +74,31 @@ public class SourceDisassemblyView extends ViewPart implements IFindReplaceTarge
return;
}
+ /**
+ * Set styled text field (only used for testing).
+ *
+ * @param txt StyledText to set.
+ */
+ protected void setStyledText(StyledText txt) {
+ text = txt;
+ }
+
+ /**
+ * Get the text content of this view.
+ *
+ * @return String content of this view
+ */
+ public String getContent() {
+ return (text == null) ? "" : text.getText(); //$NON-NLS-1$
+ }
+
+ /**
+ * Set styled text field based on the specified string, which is parsed in
+ * order to set appropriate styles to be used for rendering the widget
+ * content.
+ *
+ * @param input text content of widget.
+ */
private void setStyledText (String input) {
List<StyleRange> styles = new ArrayList<StyleRange> ();
int ptr = 0;