diff options
Diffstat (limited to 'devtest/src/main/java/com')
4 files changed, 132 insertions, 0 deletions
diff --git a/devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml b/devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml new file mode 100644 index 00000000..537f0c47 --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/DevTestRunner.gwt.xml @@ -0,0 +1,5 @@ +<module rename-to="test"> + <inherits name='com.google.gwt.query.Query'/> + <entry-point class='com.google.gwt.query.client.DevTestRunner'/> +</module> + diff --git a/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java b/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java new file mode 100644 index 00000000..046fdf11 --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java @@ -0,0 +1,50 @@ +/*
+ * Copyright 2009 Google Inc.
+ *
+ * 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.
+ */
+package com.google.gwt.query.client;
+
+import static com.google.gwt.query.client.GQuery.$;
+
+import com.google.gwt.core.client.EntryPoint;
+
+/**
+ * This module is thought to emulate a test environment similar to
+ * GWTTestCase, but running it in development mode.
+ *
+ * The main goal of it is to execute tests in a faster way, because you only need
+ * to push reload in your browser.
+ *
+ * @author manolo
+ *
+ */
+public class DevTestRunner extends MyTestCase implements EntryPoint {
+
+ public void onModuleLoad() {
+ gwtSetUp();
+ testDomManip();
+ }
+
+ public void testDomManip() {
+ String content = "<span class='branchA'><span class='target'>branchA target</span></span>"
+ + "<span class='branchB'><span class='target'>branchB target</span></span>";
+
+ $(e).html("");
+ $(e).append(content);
+ assertEquals(4, $("span", e).size());
+ assertEquals(2, $("span.target", e).size());
+ assertHtmlEquals(content, $(e).html());
+ }
+
+}
diff --git a/devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java b/devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java new file mode 100644 index 00000000..e505812a --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/client/MyTestCase.java @@ -0,0 +1,69 @@ +/*
+ * Copyright 2009 Google Inc.
+ *
+ * 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.
+ */
+package com.google.gwt.query.client;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.RootPanel;
+
+/**
+ * Just a simple class to emulate JUnit TestCase
+ */
+public class MyTestCase {
+
+ static Element e = null;
+ static HTML testPanel = null;
+
+ public void gwtSetUp() {
+ if (e == null) {
+ testPanel = new HTML();
+ RootPanel.get().add(testPanel);
+ e = testPanel.getElement();
+ e.setId("core-tst");
+ } else {
+ e.setInnerHTML("");
+ }
+ }
+
+ public static void assertNotNull(Object a) {
+ check(a != null, "assertNotNull: actual object is null");
+ }
+
+ public static void assertEquals(Object a, Object b) {
+ check(a.equals(b), "assertEquals: expected=" + a + " actual=" + b);
+ }
+
+ public static void check(boolean condition, String message) {
+ if (!condition) {
+ RuntimeException e = new RuntimeException(message);
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ protected static void assertHtmlEquals(Object expected, Object actual) {
+ assertEquals(iExplorerFixHtml(expected), iExplorerFixHtml(actual));
+ }
+
+ protected static String iExplorerFixHtml(Object s) {
+ return s.toString().trim().toLowerCase().
+ replaceAll("[\r\n]", "").
+ replaceAll(" ([\\w]+)=[\"']([^\"']+)[\"']", " $1=$2").
+ replaceAll("\\s+\\$h=\"[^\"]+\"", "").
+ replaceAll(" added=[^ >]+", "");
+ }
+
+}
diff --git a/devtest/src/main/java/com/google/gwt/query/public/test.html b/devtest/src/main/java/com/google/gwt/query/public/test.html new file mode 100644 index 00000000..1c447858 --- /dev/null +++ b/devtest/src/main/java/com/google/gwt/query/public/test.html @@ -0,0 +1,8 @@ +<html>
+ <head>
+ <script language="javascript" src="test.nocache.js"></script>
+ </head>
+ <body>
+ </body>
+</html>
+
\ No newline at end of file |