Skip to content

Instantly share code, notes, and snippets.

@jarib
Forked from anonymous/gist:1065472
Created July 5, 2011 18:20
Show Gist options
  • Save jarib/1065474 to your computer and use it in GitHub Desktop.
Save jarib/1065474 to your computer and use it in GitHub Desktop.
Patch to start creating a c++ main
Index: cpp/IEDriver/IEDriver.vcxproj
===================================================================
--- cpp/IEDriver/IEDriver.vcxproj (revision 12745)
+++ cpp/IEDriver/IEDriver.vcxproj (working copy)
@@ -25,26 +25,30 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <ConfigurationType>Application</ConfigurationType>
<UseOfAtl>Static</UseOfAtl>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
+ <UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <ConfigurationType>Application</ConfigurationType>
<UseOfAtl>Static</UseOfAtl>
<CharacterSet>Unicode</CharacterSet>
+ <UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <ConfigurationType>Application</ConfigurationType>
<UseOfAtl>Static</UseOfAtl>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
+ <UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <ConfigurationType>Application</ConfigurationType>
<UseOfAtl>Static</UseOfAtl>
<CharacterSet>Unicode</CharacterSet>
+ <UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -102,12 +106,13 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;Rpcrt4.lib;version.lib;iepmapi.lib;comsuppw.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AssemblyDebug>true</AssemblyDebug>
- <SubSystem>NotSet</SubSystem>
+ <SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
@@ -130,12 +135,13 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;Rpcrt4.lib;version.lib;iepmapi.lib;comsuppw.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AssemblyDebug>true</AssemblyDebug>
- <SubSystem>NotSet</SubSystem>
+ <SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
@@ -154,11 +160,12 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;Rpcrt4.lib;version.lib;iepmapi.lib;comsuppw.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <SubSystem>Windows</SubSystem>
+ <SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
@@ -179,11 +186,12 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;Rpcrt4.lib;version.lib;iepmapi.lib;comsuppw.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <SubSystem>Windows</SubSystem>
+ <SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX64</TargetMachine>
Index: cpp/IEDriver/WebDriver.cpp
===================================================================
--- cpp/IEDriver/WebDriver.cpp (revision 12745)
+++ cpp/IEDriver/WebDriver.cpp (working copy)
@@ -67,4 +67,24 @@
bool ServerIsRunning() {
return server != NULL;
-}
\ No newline at end of file
+}
+
+int main(int argc, char** argv) {
+ /*
+ if (argc != 2) {
+ cerr << "You must specify the port number as the only argument" << endl;
+ return -1;
+ }
+
+ int port = atoi(argv[1]);
+ */
+ int port = 7055;
+ cout << "Will listen on " << port << endl;
+
+ webdriver::Server* instance = StartServer(port);
+
+ while (true) {
+ ::Sleep(250);
+ }
+ return 0;
+}
Index: cpp/build.desc
===================================================================
--- cpp/build.desc (revision 12745)
+++ cpp/build.desc (working copy)
@@ -69,26 +69,28 @@
out = "Win32/Release/imehandler.dll"
)
-visualc_library(name = "ie_win32_dll",
+visualc_library(name = "ie_win32_exe",
deps = [
":atoms",
":ie_result_type_cpp",
":sizzle"
],
platform = "Win32",
+ target = "executable",
project = "IEDriver/IEDriver.vcxproj",
- out = "Win32/Release/IEDriver.dll"
+ out = "Win32/Release/IEDriver.exe"
)
-visualc_library(name = "ie_x64_dll",
+visualc_library(name = "ie_x64_exe",
deps = [
":atoms",
":ie_result_type_cpp",
":sizzle"
],
platform = "x64",
+ target = "executable",
project = "IEDriver/IEDriver.vcxproj",
- out = "x64/Release/IEDriver.dll"
+ out = "x64/Release/IEDriver.exe"
)
js_fragment_header(name = "atoms",
Index: java/client/test/com/thoughtworks/selenium/build.desc
===================================================================
--- java/client/test/com/thoughtworks/selenium/build.desc (revision 12745)
+++ java/client/test/com/thoughtworks/selenium/build.desc (working copy)
@@ -78,7 +78,7 @@
java_test(name = "ie-rc-test",
test_suite = "com.thoughtworks.selenium.SeleniumRcTestSuite",
sysproperties = [
- { "selenium.browser" : "*iexplore" },
+ { "selenium.browser" : "*iexploreproxy" },
],
deps = [
":rc-tests",
Index: java/client/src/org/openqa/selenium/os/CommandLine.java
===================================================================
--- java/client/src/org/openqa/selenium/os/CommandLine.java (revision 12745)
+++ java/client/src/org/openqa/selenium/os/CommandLine.java (working copy)
@@ -41,6 +41,7 @@
private volatile OutputStream drainTo;
private volatile Thread drainerThread;
private volatile int exitCode;
+ private volatile boolean daemonic;
private volatile boolean executed;
private volatile Process proc;
private volatile String allInput;
@@ -100,6 +101,10 @@
}
}
+ public void setDaemonic(boolean daemonic) {
+ this.daemonic = daemonic;
+ }
+
/**
* @return The platform specific env property name which contains the library path.
*/
@@ -170,13 +175,15 @@
public Process executeAsync() {
createProcess();
- new Thread() {
+ Thread thread = new Thread() {
@Override
public void run() {
setupDrainer();
waitFor();
- }
- }.start();
+ }
+ };
+ thread.setDaemon(daemonic);
+ thread.start();
cleanup = new Thread() {
@Override
Index: java/client/src/org/openqa/selenium/ie/InternetExplorerDriver.java
===================================================================
--- java/client/src/org/openqa/selenium/ie/InternetExplorerDriver.java (revision 12745)
+++ java/client/src/org/openqa/selenium/ie/InternetExplorerDriver.java (working copy)
@@ -19,10 +19,6 @@
import static org.openqa.selenium.remote.CapabilityType.PROXY;
-import com.sun.jna.Native;
-import com.sun.jna.Pointer;
-import com.sun.jna.win32.StdCallLibrary;
-
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Platform;
@@ -32,6 +28,7 @@
import org.openqa.selenium.io.FileHandler;
import org.openqa.selenium.io.TemporaryFilesystem;
import org.openqa.selenium.net.PortProber;
+import org.openqa.selenium.os.CommandLine;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.DriverCommand;
import org.openqa.selenium.remote.HttpCommandExecutor;
@@ -52,8 +49,8 @@
*/
public final static String INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS = "ignoreProtectedModeSettings";
- private Pointer server;
- private IEServer lib;
+ private CommandLine server;
+ private File executable;
private int port;
private WindowsProxyManager proxyManager;
@@ -105,14 +102,21 @@
}
protected void startClient() {
- initializeLib();
- server = lib.StartServer(port);
+ executable = extractExecutable();
+ server = new CommandLine(executable.getAbsolutePath(), String.valueOf(port));
+ server.setDaemonic(true);
+ server.copyOutputTo(System.err);
+ server.executeAsync();
+
+ PortProber.pollPort(port);
}
protected void stopClient() {
if (server != null) {
- lib.StopServer(server);
+ server.destroy();
}
+ executable = null;
+ server = null;
}
private static URL getServerUrl(int port) {
@@ -123,16 +127,17 @@
}
}
- private void initializeLib() {
+ private File extractExecutable() {
synchronized (this) {
- if (lib != null) {
- return;
+ if (executable != null) {
+ return executable;
}
File parentDir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("webdriver",
"libs");
try {
- FileHandler.copyResource(parentDir, getClass(), "IEDriver.dll");
+ FileHandler.copyResource(parentDir, getClass(), "IEDriver.exe");
+ executable = new File(parentDir, "IEDriver.exe");
} catch (IOException ioe) {
// TODO(simon): Delete this. Test code should not be in production code
try {
@@ -146,17 +151,18 @@
sourcePaths.add("..\\..\\build\\cpp\\" + arch + "\\Debug");
boolean copied = false;
for (String path : sourcePaths) {
- File sourceFile = new File(path, "IEDriver.dll");
+ File sourceFile = new File(path, "IEDriver.exe");
if (sourceFile.exists()) {
- FileHandler.copy(sourceFile, new File(
- parentDir, "IEDriver.dll"));
+ File to = new File(parentDir, "IEDriver.exe");
+ FileHandler.copy(sourceFile, to);
+ executable = to;
copied = true;
break;
}
}
if (!copied) {
throw new WebDriverException(
- "Couldn't find IEDriver.dll: " + arch);
+ "Couldn't find IEDriver.exe: " + arch);
}
} else {
throw new WebDriverException(ioe);
@@ -165,18 +171,9 @@
throw new WebDriverException(ioe2);
}
}
- System.setProperty("jna.library.path",
- System.getProperty("jna.library.path", "")
- + File.pathSeparator + parentDir);
-
- try {
- lib = (IEServer) Native.loadLibrary("IEDriver", IEServer.class);
- } catch (UnsatisfiedLinkError e) {
- System.out.println("new File(\".\").getAbsolutePath() = "
- + new File(".").getAbsolutePath());
- throw new WebDriverException(e);
- }
}
+
+ return executable;
}
private void prepareProxy(Capabilities caps) {
@@ -201,10 +198,4 @@
};
Runtime.getRuntime().addShutdownHook(cleanupThread);
}
-
- private interface IEServer extends StdCallLibrary {
- Pointer StartServer(int port);
-
- void StopServer(Pointer server);
- }
}
Index: java/client/src/org/openqa/selenium/ie/InternetExplorerKeyboard.java
===================================================================
--- java/client/src/org/openqa/selenium/ie/InternetExplorerKeyboard.java (revision 12745)
+++ java/client/src/org/openqa/selenium/ie/InternetExplorerKeyboard.java (working copy)
@@ -1,9 +1,6 @@
// Copyright 2010 Google Inc. All Rights Reserved.
package org.openqa.selenium.ie;
-import com.sun.jna.Pointer;
-import com.sun.jna.WString;
-
import org.openqa.selenium.Keyboard;
import org.openqa.selenium.Keys;
import org.openqa.selenium.remote.ErrorHandler;
@@ -39,7 +36,7 @@
// getActive().sendKeyUpEvent(keyToRelease);
}
- public void sendKeys(Pointer element, String keysSequence) {
+ public void sendKeys(Object element, String keysSequence) {
// int result = lib.wdeSendKeys(element, new WString(keysSequence));
// errors.verifyErrorCode(result, "send keys to");
@@ -47,7 +44,7 @@
// parent.waitForLoadToComplete();
}
- public void pressKey(Pointer element, Keys modifierKey) {
+ public void pressKey(Object element, Keys modifierKey) {
// int result = lib.wdeSendKeyPress(element, new WString(modifierKey.toString()));
//
// errors.verifyErrorCode(result, "send key press to");
@@ -55,7 +52,7 @@
// parent.waitForLoadToComplete();
}
- public void releaseKey(Pointer element, Keys modifierKey) {
+ public void releaseKey(Object element, Keys modifierKey) {
// int result = lib.wdeSendKeyRelease(element, new WString(modifierKey.toString()));
//
// errors.verifyErrorCode(result, "send key release to");
Index: java/client/src/org/openqa/selenium/ie/build.desc
===================================================================
--- java/client/src/org/openqa/selenium/ie/build.desc (revision 12745)
+++ java/client/src/org/openqa/selenium/ie/build.desc (working copy)
@@ -2,15 +2,14 @@
java_library(name = "ie",
srcs = [ "*.java" ],
resources = [
- {"//cpp:ie_win32_dll" : "x86/IEDriver.dll"},
- {"//cpp:ie_x64_dll" : "amd64/IEDriver.dll"}
+ {"//cpp:ie_win32_exe" : "x86/IEDriver.exe"},
+ {"//cpp:ie_x64_exe" : "amd64/IEDriver.exe"}
],
deps = [
":ie_result_type_java",
"//cpp:sizzle",
"//java/client/src/org/openqa/selenium/net",
"//java/client/src/org/openqa/selenium/remote",
- "//third_party/java/jna",
])
rake_task(name = "ie_result_type_java",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment