### Eclipse Workspace Patch 1.0
#P org.eclipse.pde.ui.tests
Index: src/org/eclipse/pde/ui/tests/AllPDETests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/AllPDETests.java,v
retrieving revision 1.23
diff -u -r1.23 AllPDETests.java
--- src/org/eclipse/pde/ui/tests/AllPDETests.java 4 Jan 2008 20:05:37 -0000 1.23
+++ src/org/eclipse/pde/ui/tests/AllPDETests.java 11 Mar 2008 14:54:57 -0000
@@ -12,9 +12,9 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-
import org.eclipse.pde.ui.tests.imports.AllImportTests;
import org.eclipse.pde.ui.tests.model.bundle.AllBundleModelTests;
+import org.eclipse.pde.ui.tests.model.cheatsheet.AllCheatSheetModelTests;
import org.eclipse.pde.ui.tests.model.xml.AllXMLModelTests;
import org.eclipse.pde.ui.tests.target.AllTargetTests;
import org.eclipse.pde.ui.tests.wizards.AllNewProjectTests;
@@ -28,6 +28,7 @@
suite.addTest(AllImportTests.suite());
suite.addTest(AllBundleModelTests.suite());
suite.addTest(AllXMLModelTests.suite());
+ suite.addTest(AllCheatSheetModelTests.suite());
return suite;
}
Index: src/org/eclipse/pde/ui/tests/model/cheatsheet/AllCheatSheetModelTests.java
===================================================================
RCS file: src/org/eclipse/pde/ui/tests/model/cheatsheet/AllCheatSheetModelTests.java
diff -N src/org/eclipse/pde/ui/tests/model/cheatsheet/AllCheatSheetModelTests.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/pde/ui/tests/model/cheatsheet/AllCheatSheetModelTests.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.ui.tests.model.cheatsheet;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllCheatSheetModelTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test Suite for testing the cheatsheet model"); //$NON-NLS-1$
+ suite.addTestSuite(SimpleCSIntroTestCase.class);
+ return suite;
+ }
+
+}
Index: src/org/eclipse/pde/ui/tests/model/cheatsheet/SimpleCSIntroTestCase.java
===================================================================
RCS file: src/org/eclipse/pde/ui/tests/model/cheatsheet/SimpleCSIntroTestCase.java
diff -N src/org/eclipse/pde/ui/tests/model/cheatsheet/SimpleCSIntroTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/pde/ui/tests/model/cheatsheet/SimpleCSIntroTestCase.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.ui.tests.model.cheatsheet;
+
+import org.eclipse.pde.internal.core.icheatsheet.simple.*;
+
+public class SimpleCSIntroTestCase extends AbstractCheatSheetModelTestCase {
+
+ protected static String INTRO_HREF = "/org.eclipse.platform.doc.user/reference/ref-cheatsheets.htm"; //$NON-NLS-1$
+ protected static String DESCRIPTION = "some description"; //$NON-NLS-1$
+
+ public void testAddSimpleCSIntro() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("");
+ buffer.append(LF);
+ buffer.append("");
+ buffer.append(DESCRIPTION);
+ buffer.append("");
+ buffer.append(LF);
+ buffer.append("");
+ setXMLContents(buffer, LF);
+ load();
+
+ ISimpleCS model = fModel.getSimpleCS();
+ String title = model.getTitle();
+
+ // check intro
+ ISimpleCSIntro intro = model.getIntro();
+ assertNotNull(intro);
+ assertEquals(intro.getHref(), INTRO_HREF);
+
+ // check description
+ ISimpleCSDescription description = intro.getDescription();
+ assertNotNull(description);
+ assertEquals(DESCRIPTION, description.getContent());
+ }
+
+}
Index: src/org/eclipse/pde/ui/tests/model/cheatsheet/AbstractCheatSheetModelTestCase.java
===================================================================
RCS file: src/org/eclipse/pde/ui/tests/model/cheatsheet/AbstractCheatSheetModelTestCase.java
diff -N src/org/eclipse/pde/ui/tests/model/cheatsheet/AbstractCheatSheetModelTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/pde/ui/tests/model/cheatsheet/AbstractCheatSheetModelTestCase.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.ui.tests.model.cheatsheet;
+
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.pde.internal.core.text.IModelTextChangeListener;
+import org.eclipse.pde.internal.core.text.cheatsheet.simple.SimpleCSModel;
+import org.eclipse.pde.internal.core.text.plugin.XMLTextChangeListener;
+import org.eclipse.text.edits.*;
+
+public abstract class AbstractCheatSheetModelTestCase extends TestCase {
+
+ protected static final String LF = "\n"; //$NON-NLS-1$
+ protected static final String CR = "\r"; //$NON-NLS-1$
+ protected static final String CRLF = CR + LF;
+
+ protected Document fDocument;
+ protected SimpleCSModel fModel;
+ protected IModelTextChangeListener fListener;
+
+ public AbstractCheatSheetModelTestCase() {
+ }
+
+ protected void setUp() throws Exception {
+ fDocument = new Document();
+ }
+
+ protected void load() {
+ load(false);
+ }
+
+ protected void load(boolean addListener) {
+ try {
+ fModel = new SimpleCSModel(fDocument, false);
+ fModel.load();
+ if (!fModel.isLoaded() || !fModel.isValid())
+ fail("model cannot be loaded");
+ if (addListener) {
+ fListener = new XMLTextChangeListener(fModel.getDocument());
+ fModel.addModelChangedListener(fListener);
+ }
+ } catch (CoreException e) {
+ fail("model cannot be loaded");
+ }
+ }
+
+ protected void setXMLContents(StringBuffer body, String newline) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("");
+ sb.append(newline);
+ sb.append("");
+ sb.append(newline);
+ if (body != null)
+ sb.append(body.toString());
+ sb.append(newline);
+ sb.append("");
+ sb.append(newline);
+ fDocument.set(sb.toString());
+ }
+
+ protected void reload() {
+ TextEdit[] ops = fListener.getTextOperations();
+ if (ops.length == 0)
+ return;
+ MultiTextEdit multi = new MultiTextEdit();
+ multi.addChildren(ops);
+ try {
+ multi.apply(fDocument);
+ } catch (MalformedTreeException e) {
+ fail(e.getMessage());
+ } catch (BadLocationException e) {
+ fail(e.getMessage());
+ }
+ load();
+ }
+}