From 0efd89e8bce45cd9a859e75781cea5e85b0016c2 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Wed, 25 Feb 2004 05:44:08 +0000 Subject: [PATCH] This checkin takes us a little closer to the unit tests running. I'm still seeing non-ignorable differences in the golden file, which I must address. M README - remove quotes from env vars M webclient/src_moz/WrapperFactoryImpl.cpp - make the native.waitForDebugger mechanism work on Win32. M webclient/test/automated/src/classes/org/mozilla/webclient/CompareFiles.java - Tweaks to optionally ignore WARNING: messages - Tweaks to ignore lines containing keywords, such as nativeBinDir, which changes from platform to platform and user to user M webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java - formatting git-svn-id: svn://10.0.0.236/trunk@153203 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/java/README | 8 +++- .../webclient/src_moz/WrapperFactoryImpl.cpp | 14 ++++-- .../org/mozilla/webclient/CompareFiles.java | 45 +++++++++++++++---- .../mozilla/webclient/WebclientTestCase.java | 2 +- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/mozilla/java/README b/mozilla/java/README index 2f85d58c114..f0dcc713223 100644 --- a/mozilla/java/README +++ b/mozilla/java/README @@ -37,6 +37,7 @@ How To Build: ###### build.unix.classes=true +build.win32.classes=false build.home=/home/edburns/Projects/mozilla/MOZILLA_1_4/mozilla/dist/classes compile.debug=true ###### @@ -55,11 +56,14 @@ How to run the Junit tests: * Set the following variables in your environment -NSPR_LOG_MODULES="webclient:4,webclientstub:4" -NSPR_LOG_FILE="logfile.txt" +NSPR_LOG_MODULES=webclient:4,webclientstub:4 +NSPR_LOG_FILE=logfile.txt * cd to mozilla/java/webclient +* Kill any running mozilla instances. These will mess up the + profilemanager code. + * run ant test How to run the test browser (broken as of this writing): diff --git a/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp b/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp index 9538bf73366..773f9978bfc 100644 --- a/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp +++ b/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp @@ -45,6 +45,9 @@ #ifdef XP_UNIX #include // for getpid #endif +#ifdef XP_PC +#include // for GetCurrentProcessId() +#endif static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); @@ -133,17 +136,20 @@ Java_org_mozilla_webclient_impl_wrapper_1native_WrapperFactoryImpl_nativeAppInit PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, ("WrapperFactoryImpl_nativeAppInitialize: exiting\n")); -#ifdef XP_UNIX char propValue[50]; ::util_getSystemProperty(env, "native.waitForDebugger", propValue, 50); if (nsnull != propValue[0] && 0 < nsCRT::strlen(propValue)) { +#ifdef XP_UNIX pid_t pid = getpid(); printf("++++++++++++++++debug: pid is: %d\n", pid); - fflush(stdout); - sleep(7); - } #endif +#ifdef XP_PC + printf("++++++++++++++++debug: pid is: %d\n", GetCurrentProcessId()); +#endif + fflush(stdout); + PR_Sleep(700000); + } // Store our pointer to the global vm if (nsnull == gVm) { // declared in ../src_share/jni_util.h diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CompareFiles.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CompareFiles.java index 3c365cef35d..ec9476e6d7b 100644 --- a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CompareFiles.java +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CompareFiles.java @@ -1,5 +1,5 @@ /* - * $Id: CompareFiles.java,v 1.1 2002-10-01 00:39:28 edburns%acm.org Exp $ + * $Id: CompareFiles.java,v 1.2 2004-02-25 05:44:08 edburns%acm.org Exp $ */ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -43,7 +43,9 @@ public class CompareFiles { public static boolean filesIdentical (String newFileName, String oldFileName, List oldLinesToIgnore, - int ignorePrefix) + boolean ignorePrefix, + boolean ignoreWarnings, + List ignoreKeywords) throws IOException { boolean same = true; @@ -68,13 +70,23 @@ public class CompareFiles { } while (null != newLine && null != oldLine) { - if (0 < ignorePrefix) { - newLine = newLine.substring(ignorePrefix); - oldLine = oldLine.substring(ignorePrefix); + if (ignorePrefix) { + int bracketColon = 0; + if (-1 != (bracketColon = newLine.indexOf("]: "))) { + newLine = newLine.substring(bracketColon + 3); + } + if (-1 != (bracketColon = oldLine.indexOf("]: "))) { + oldLine = oldLine.substring(bracketColon + 3); + } } - if (!newLine.equals(oldLine)) { - + if (ignoreWarnings && newLine.startsWith("WARNING:")) { + // we're ignoring warnings, no-op + newLine = newReader.readLine(); // swallow the WARNING line + continue; + + } + else if (!newLine.equals(oldLine)) { if (null != oldLinesToIgnore) { // go thru the list of oldLinesToIgnore and see if // the current oldLine matches any of them. @@ -91,12 +103,29 @@ public class CompareFiles { // important if (!foundMatch) { same = false; + System.out.println("newLine: " + newLine); + System.out.println("oldLine: " + oldLine); break; } } else { same = false; - break; + if (null != ignoreKeywords && 0 < ignoreKeywords.size()) { + Iterator iter = ignoreKeywords.iterator(); + while (iter.hasNext()) { + if (-1 != newLine.indexOf((String) iter.next())) { + // we're ignoring lines that contain this + // keyword, no-op + same = true; + break; + } + } + } + if (!same) { + System.out.println("newLine: " + newLine); + System.out.println("oldLine: " + oldLine); + break; + } } } diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java index 671e1875c42..6758999685c 100644 --- a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java @@ -1 +1 @@ -/* * $Id: WebclientTestCase.java,v 1.3 2004-02-25 03:06:36 edburns%acm.org Exp $ */ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (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.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is Sun * Microsystems, Inc. Portions created by Sun are * Copyright (C) 1999 Sun Microsystems, Inc. All * Rights Reserved. * * Contributor(s): Ed Burns <edburns@acm.org> */ package org.mozilla.webclient; // WebclientTestCase.java import java.util.ArrayList; import java.io.IOException; import org.mozilla.util.Assert; import org.mozilla.util.ParameterCheck; import junit.framework.TestCase; /** * * WebclientTestCase is a class ... * * Lifetime And Scope

* * @version $Id: WebclientTestCase.java,v 1.3 2004-02-25 03:06:36 edburns%acm.org Exp $ * * @see Blah * @see Bloo * */ public abstract class WebclientTestCase extends TestCase { // // Protected Constants // public static final String WEBCLIENTSTUB_LOG_MODULE = "webclientstub"; public static final String WEBCLIENT_LOG_MODULE = "webclient"; public static final String OUTPUT_FILE_ROOT = "./build.test/"; // // Class Variables // // // Instance Variables // // Attribute Instance Variables // Relationship Instance Variables // // Constructors and Initializers // public WebclientTestCase() { super("WebclientTestCase"); } public WebclientTestCase(String name) { super(name); } // // Class methods // // // Methods From TestCase // public void setUp() { verifyPreconditions(); } // // General Methods // /** * assertTrue that the string logModuleName is a correct log module * string as specified in pr_log.h, and that its value is at least n. */ protected void verifyLogModuleValueIsAtLeastN(String logModuleName, int n) { int i = 0; String logModuleValue = null; assertTrue(null != (logModuleValue = System.getProperty("NSPR_LOG_MODULES"))); assertTrue(-1 != (i = logModuleValue.indexOf(logModuleName + ":"))); try { i = Integer. valueOf(logModuleValue.substring(i + logModuleName.length() + 1, i + logModuleName.length() + 2)). intValue(); assertTrue(i >= n); } catch (Throwable e) { e.printStackTrace(); assertTrue(false); } } protected void verifyBinDirSet() { assertTrue("BROWSER_BIN_DIR is not set", null != System.getProperty("BROWSER_BIN_DIR")); } protected String getBrowserBinDir() { return System.getProperty("BROWSER_BIN_DIR"); } /** * assertTrue that NSPR_LOG_FILE is set. */ protected String verifyOutputFileIsSet() { String logFileValue = null; assertTrue(null != (logFileValue = System.getProperty("NSPR_LOG_FILE"))); return logFileValue; } /** * This implementation checks that the proper environment vars are set. */ protected void verifyPreconditions() { String nsprLogModules = null; // make sure we have at least PR_LOG_DEBUG set verifyLogModuleValueIsAtLeastN(WEBCLIENTSTUB_LOG_MODULE, 4); verifyLogModuleValueIsAtLeastN(WEBCLIENT_LOG_MODULE, 4); verifyBinDirSet(); if (sendOutputToFile()) { verifyOutputFileIsSet(); } } public boolean verifyExpectedOutput() { boolean result = false; CompareFiles cf = new CompareFiles(); String errorMessage = null; String outputFileName = null; String correctFileName = null; // If this testcase doesn't participate in file comparison if (!this.sendOutputToFile() && (null == this.getExpectedOutputFilename())) { return true; } if (this.sendOutputToFile() ) { outputFileName = verifyOutputFileIsSet(); } correctFileName = OUTPUT_FILE_ROOT + this.getExpectedOutputFilename(); errorMessage = "File Comparison failed: diff -u " + outputFileName + " " + correctFileName; ArrayList ignoreList = null; String [] ignore = null; if (null != (ignore = this.getLinesToIgnore())) { ignoreList = new ArrayList(); for (int i = 0; i < ignore.length; i++) { ignoreList.add(ignore[i]); } } try { result = cf.filesIdentical(outputFileName, correctFileName,ignoreList, getIgnorePrefix()); } catch (IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); } if (!result) { System.out.println(errorMessage); } System.out.println("VERIFY:"+result); return result; } /** * @return the name of the expected output filename for this testcase. */ public String getExpectedOutputFilename() { return null; } public String [] getLinesToIgnore() { return null; } public int getIgnorePrefix() { return 15; } // 15 is the ignore prefix // for output from PR_LOG public boolean sendOutputToFile() { return false; } } // end of class WebclientTestCase \ No newline at end of file +/* * $Id: WebclientTestCase.java,v 1.4 2004-02-25 05:44:08 edburns%acm.org Exp $ */ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (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.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is Sun * Microsystems, Inc. Portions created by Sun are * Copyright (C) 1999 Sun Microsystems, Inc. All * Rights Reserved. * * Contributor(s): Ed Burns <edburns@acm.org> */ package org.mozilla.webclient; // WebclientTestCase.java import java.util.ArrayList; import java.util.List; import java.io.IOException; import org.mozilla.util.Assert; import org.mozilla.util.ParameterCheck; import junit.framework.TestCase; /** * * WebclientTestCase is a class ... * * Lifetime And Scope

* * @version $Id: WebclientTestCase.java,v 1.4 2004-02-25 05:44:08 edburns%acm.org Exp $ * * @see Blah * @see Bloo * */ public abstract class WebclientTestCase extends TestCase { // // Protected Constants // public static final String WEBCLIENTSTUB_LOG_MODULE = "webclientstub"; public static final String WEBCLIENT_LOG_MODULE = "webclient"; public static final String OUTPUT_FILE_ROOT = "./build.test/"; // // Class Variables // // // Instance Variables // // Attribute Instance Variables // Relationship Instance Variables // // Constructors and Initializers // public WebclientTestCase() { super("WebclientTestCase"); } public WebclientTestCase(String name) { super(name); } // // Class methods // // // Methods From TestCase // public void setUp() { verifyPreconditions(); } // // General Methods // /** * assertTrue that the string logModuleName is a correct log module * string as specified in pr_log.h, and that its value is at least n. */ protected void verifyLogModuleValueIsAtLeastN(String logModuleName, int n) { int i = 0; String logModuleValue = null; assertTrue(null != (logModuleValue = System.getProperty("NSPR_LOG_MODULES"))); assertTrue(-1 != (i = logModuleValue.indexOf(logModuleName + ":"))); try { i = Integer. valueOf(logModuleValue.substring(i + logModuleName.length() + 1, i + logModuleName.length() + 2)). intValue(); assertTrue(i >= n); } catch (Throwable e) { e.printStackTrace(); assertTrue(false); } } protected void verifyBinDirSet() { assertTrue("BROWSER_BIN_DIR is not set", null != System.getProperty("BROWSER_BIN_DIR")); } protected String getBrowserBinDir() { return System.getProperty("BROWSER_BIN_DIR"); } /** * assertTrue that NSPR_LOG_FILE is set. */ protected String verifyOutputFileIsSet() { String logFileValue = null; assertTrue(null != (logFileValue = System.getProperty("NSPR_LOG_FILE"))); return logFileValue; } /** * This implementation checks that the proper environment vars are set. */ protected void verifyPreconditions() { String nsprLogModules = null; // make sure we have at least PR_LOG_DEBUG set verifyLogModuleValueIsAtLeastN(WEBCLIENTSTUB_LOG_MODULE, 4); verifyLogModuleValueIsAtLeastN(WEBCLIENT_LOG_MODULE, 4); verifyBinDirSet(); if (sendOutputToFile()) { verifyOutputFileIsSet(); } } public boolean verifyExpectedOutput() { boolean result = false; CompareFiles cf = new CompareFiles(); String errorMessage = null; String outputFileName = null; String correctFileName = null; // If this testcase doesn't participate in file comparison if (!this.sendOutputToFile() && (null == this.getExpectedOutputFilename())) { return true; } if (this.sendOutputToFile() ) { outputFileName = verifyOutputFileIsSet(); } correctFileName = OUTPUT_FILE_ROOT + this.getExpectedOutputFilename(); errorMessage = "File Comparison failed: diff -u " + outputFileName + " " + correctFileName; ArrayList ignoreList = null; String [] ignore = null; if (null != (ignore = this.getLinesToIgnore())) { ignoreList = new ArrayList(); for (int i = 0; i < ignore.length; i++) { ignoreList.add(ignore[i]); } } try { result = cf.filesIdentical(outputFileName, correctFileName,ignoreList, getIgnorePrefix(), getIgnoreWarnings(), getIgnoreKeywords()); } catch (IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); } if (!result) { System.out.println(errorMessage); } System.out.println("VERIFY:"+result); return result; } /** * @return the name of the expected output filename for this testcase. */ public String getExpectedOutputFilename() { return null; } public String [] getLinesToIgnore() { return null; } public List getIgnoreKeywords() { ArrayList result = new ArrayList(); result.add("nativeBinDir"); return result; } public boolean getIgnorePrefix() { return true; } public boolean getIgnoreWarnings() { return true; } public boolean sendOutputToFile() { return false; } } // end of class WebclientTestCase \ No newline at end of file