[Spice-devel] [PATCH] spicec-tests: add controller_test
Hans de Goede
hdegoede at redhat.com
Wed Oct 20 10:48:32 PDT 2010
Hi,
Why disable all channels? Or am I reading the code wrong?
Also the use of wchars rather then chars when sending certain
strings is not consistent with how the xpi handles things
(but I guess it is consistent with how the activex handles some
things? That would explain some parts of the client which
are not working well together with the XPI.
I think we first need to discuss the wchar versus char thing
in more detail before putting in a testcase.
So lets discuss this on irc tomorrow morning.
Regards,
Hans
On 10/20/2010 05:59 PM, Arnon Gilboa wrote:
> ---
> client/tests/controller_test/build | 4 +
> client/tests/controller_test/controller_test.cpp | 201 ++++++++++++++++++++
> client/tests/controller_test/controller_test.sln | 20 ++
> .../tests/controller_test/controller_test.vcproj | 198 +++++++++++++++++++
> 4 files changed, 423 insertions(+), 0 deletions(-)
> create mode 100755 client/tests/controller_test/build
> create mode 100644 client/tests/controller_test/controller_test.cpp
> create mode 100644 client/tests/controller_test/controller_test.sln
> create mode 100644 client/tests/controller_test/controller_test.vcproj
>
> diff --git a/client/tests/controller_test/build b/client/tests/controller_test/build
> new file mode 100755
> index 0000000..995372f
> --- /dev/null
> +++ b/client/tests/controller_test/build
> @@ -0,0 +1,4 @@
> +#!/bin/bash
> +
> +g++ -I ../../../../spice-protocol/ -o spice_controller controller_test.cpp
> +
> diff --git a/client/tests/controller_test/controller_test.cpp b/client/tests/controller_test/controller_test.cpp
> new file mode 100644
> index 0000000..cc0a484
> --- /dev/null
> +++ b/client/tests/controller_test/controller_test.cpp
> @@ -0,0 +1,201 @@
> +#include<stdio.h>
> +#include<stdint.h>
> +#include<spice/controller_prot.h>
> +
> +#ifdef WIN32
> +
> +#include<windows.h>
> +
> +#define PIPE_NAME TEXT("\\\\.\\pipe\\SpiceController-%lu")
> +
> +static HANDLE pipe = INVALID_HANDLE_VALUE;
> +
> +#else
> +
> +#include<sys/socket.h>
> +#include<sys/types.h>
> +#include<sys/un.h>
> +#include<stdlib.h>
> +#include<unistd.h>
> +#include<string.h>
> +#include<errno.h>
> +
> +typedef void *LPVOID;
> +typedef const void *LPCVOID;
> +typedef unsigned long DWORD;
> +typedef char TCHAR;
> +
> +#define PIPE_NAME "/tmp/SpiceController-%lu.uds"
> +
> +static int sock = -1;
> +
> +#endif
> +
> +#define PIPE_NAME_MAX_LEN 256
> +
> +void write_to_pipe(LPCVOID data, DWORD size)
> +{
> +#ifdef WIN32
> + DWORD written;
> + if (!WriteFile(pipe, data, size,&written, NULL) || written != size) {
> + printf("Write to pipe failed %u\n", GetLastError());
> + }
> +#else
> + if (send(sock, data, size, 0) != size) {
> + printf("send failed, (%d) %s\n", errno, strerror(errno));
> + }
> +#endif
> +}
> +
> +void send_init()
> +{
> + ControllerInit msg = {{CONTROLLER_MAGIC, CONTROLLER_VERSION, sizeof(msg)}, 0,
> + CONTROLLER_FLAG_EXCLUSIVE};
> + write_to_pipe((LPCVOID)&msg, sizeof(msg));
> +}
> +
> +void send_msg(uint32_t id)
> +{
> + ControllerMsg msg = {id, sizeof(msg)};
> + write_to_pipe((LPCVOID)&msg, sizeof(msg));
> +}
> +
> +void send_value(uint32_t id, uint32_t value)
> +{
> + ControllerValue msg = {{id, sizeof(msg)}, value};
> + write_to_pipe((LPCVOID)&msg, sizeof(msg));
> +}
> +
> +void send_data(uint32_t id, uint8_t* data, size_t data_size)
> +{
> + size_t size = sizeof(ControllerData) + data_size;
> + ControllerData* msg = (ControllerData*)malloc(size);
> + msg->base.id = id;
> + msg->base.size = (uint32_t)size;
> + memcpy(msg->data, data, data_size);
> + write_to_pipe((LPCVOID)msg, (DWORD)size);
> + free(msg);
> +}
> +
> +DWORD read_from_pipe(LPVOID data, DWORD size)
> +{
> + DWORD read;
> +#ifdef WIN32
> + if (!ReadFile(pipe, data, size,&read, NULL)) {
> + printf("Read from pipe failed %u\n", GetLastError());
> + }
> +#else
> + if (read = recv(sock, data, size, 0)&& (read == -1 || read == 0)) {
> + printf("recv failed, (%d) %s\n", errno, strerror(errno));
> + }
> +#endif
> + return read;
> +}
> +
> +#define HOST "localhost"
> +#define PORT 5931
> +#define SPORT 0
> +#define PWD ""
> +#define SECURE_CHANNELS "main,inputs,playback"
> +#define DISABLED_CHANNELS "playback,record"
> +#define TITLE L"Hello from controller"
> +#define HOTKEYS "toggle-fullscreen=shift+f1,release-cursor=shift+f2"
> +#define MENU L"0\r4864\rS&end Ctrl+Alt+Del\tCtrl+Alt+End\r0\r\n" \
> + L"0\r5120\r&Toggle full screen\tShift+F11\r0\r\n" \
> + L"0\r1\r&Special keys\r4\r\n" \
> + L"1\r5376\r&Send Shift+F11\r0\r\n" \
> + L"1\r5632\r&Send Shift+F12\r0\r\n" \
> + L"1\r5888\r&Send Ctrl+Alt+End\r0\r\n" \
> + L"0\r1\r-\r1\r\n" \
> + L"0\r2\rChange CD\r4\r\n" \
> + L"2\r3\rNo CDs\r0\r\n" \
> + L"2\r4\r[Eject]\r0\r\n" \
> + L"0\r5\r-\r1\r\n" \
> + L"0\r6\rPlay\r0\r\n" \
> + L"0\r7\rSuspend\r0\r\n" \
> + L"0\r8\rStop\r0\r\n"
> +
> +#define TLS_CIPHERS "NONE"
> +#define CA_FILE "NONE"
> +#define HOST_SUBJECT "NONE"
> +
> +int main(int argc, char *argv[])
> +{
> + int spicec_pid = (argc> 1 ? atoi(argv[1]) : 0);
> + char* host = (argc> 2 ? argv[2] : (char*)HOST);
> + int port = (argc> 3 ? atoi(argv[3]) : PORT);
> + TCHAR pipe_name[PIPE_NAME_MAX_LEN];
> + ControllerValue msg;
> + DWORD read;
> +
> +#ifdef WIN32
> + _snwprintf_s(pipe_name, PIPE_NAME_MAX_LEN, PIPE_NAME_MAX_LEN, PIPE_NAME, spicec_pid);
> + printf("Creating Spice controller connection %S\n", pipe_name);
> + pipe = CreateFile(pipe_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
> + if (pipe == INVALID_HANDLE_VALUE) {
> + printf("Could not open pipe %u\n", GetLastError());
> + return -1;
> + }
> +#else
> + snprintf(pipe_name, PIPE_NAME_MAX_LEN, PIPE_NAME, spicec_pid);
> + printf("Creating a controller connection %s\n", pipe_name);
> + struct sockaddr_un remote;
> + if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
> + printf("Could not open socket, (%d) %s\n", errno, strerror(errno));
> + return -1;
> + }
> + remote.sun_family = AF_UNIX;
> + strcpy(remote.sun_path, pipe_name);
> + if (connect(sock, (struct sockaddr *)&remote,
> + strlen(remote.sun_path) + sizeof(remote.sun_family)) == -1) {
> + printf("Socket connect failed, (%d) %s\n", errno, strerror(errno));
> + close(sock);
> + return -1;
> + }
> +#endif
> + send_init();
> + printf("Setting Spice parameters\n");
> + send_data(CONTROLLER_HOST, (uint8_t*)host, strlen(host) + 1);
> + send_value(CONTROLLER_PORT, port);
> + send_value(CONTROLLER_SPORT, SPORT);
> + send_data(CONTROLLER_PASSWORD, (uint8_t*)PWD, sizeof(PWD));
> + //send_data(CONTROLLER_SECURE_CHANNELS, (uint8_t*)SECURE_CHANNELS, sizeof(SECURE_CHANNELS));
> + send_data(CONTROLLER_DISABLE_CHANNELS, (uint8_t*)DISABLED_CHANNELS, sizeof(DISABLED_CHANNELS));
> + //send_data(CONTROLLER_TLS_CIPHERS, (uint8_t*)TLS_CIPHERS, sizeof(TLS_CIPHERS));
> + //send_data(CONTROLLER_CA_FILE, (uint8_t*)CA_FILE, sizeof(CA_FILE));
> + //send_data(CONTROLLER_HOST_SUBJECT, (uint8_t*)HOST_SUBJECT, sizeof(HOST_SUBJECT));
> + send_data(CONTROLLER_SET_TITLE, (uint8_t*)TITLE, sizeof(TITLE));
> + send_data(CONTROLLER_HOTKEYS, (uint8_t*)HOTKEYS, sizeof(HOTKEYS));
> + send_data(CONTROLLER_CREATE_MENU, (uint8_t*)MENU, sizeof(MENU));
> +
> + send_value(CONTROLLER_FULL_SCREEN, /*CONTROLLER_SET_FULL_SCREEN |*/ CONTROLLER_AUTO_DISPLAY_RES);
> + printf("Show...\n");
> + getchar();
> + send_msg(CONTROLLER_SHOW);
> +
> + printf("Connect...\n");
> + getchar();
> + send_msg(CONTROLLER_CONNECT);
> +
> + printf("Hide...\n");
> + getchar();
> + send_msg(CONTROLLER_HIDE);
> +
> + printf("Show...\n");
> + getchar();
> + send_msg(CONTROLLER_SHOW);
> +
> + //send_msg(CONTROLLER_DELETE_MENU);
> + //send_msg(CONTROLLER_HIDE);
> + while ((read = read_from_pipe(&msg, sizeof(msg))) == sizeof(msg)) {
> + printf("Received id %u, size %u, value %u\n", msg.base.id, msg.base.size, msg.value);
> + }
> + printf("Press<Enter> to close connection\n");
> + getchar();
> +#ifdef WIN32
> + CloseHandle(pipe);
> +#else
> + close(sock);
> +#endif
> + return 0;
> +}
> diff --git a/client/tests/controller_test/controller_test.sln b/client/tests/controller_test/controller_test.sln
> new file mode 100644
> index 0000000..20a8955
> --- /dev/null
> +++ b/client/tests/controller_test/controller_test.sln
> @@ -0,0 +1,20 @@
> +
> +Microsoft Visual Studio Solution File, Format Version 10.00
> +# Visual Studio 2008
> +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "controller_test", "controller_test.vcproj", "{6DFCEAF5-D081-46F0-AE15-42C5D3240CFD}"
> +EndProject
> +Global
> + GlobalSection(SolutionConfigurationPlatforms) = preSolution
> + Debug|Win32 = Debug|Win32
> + Release|Win32 = Release|Win32
> + EndGlobalSection
> + GlobalSection(ProjectConfigurationPlatforms) = postSolution
> + {6DFCEAF5-D081-46F0-AE15-42C5D3240CFD}.Debug|Win32.ActiveCfg = Debug|Win32
> + {6DFCEAF5-D081-46F0-AE15-42C5D3240CFD}.Debug|Win32.Build.0 = Debug|Win32
> + {6DFCEAF5-D081-46F0-AE15-42C5D3240CFD}.Release|Win32.ActiveCfg = Release|Win32
> + {6DFCEAF5-D081-46F0-AE15-42C5D3240CFD}.Release|Win32.Build.0 = Release|Win32
> + EndGlobalSection
> + GlobalSection(SolutionProperties) = preSolution
> + HideSolutionNode = FALSE
> + EndGlobalSection
> +EndGlobal
> diff --git a/client/tests/controller_test/controller_test.vcproj b/client/tests/controller_test/controller_test.vcproj
> new file mode 100644
> index 0000000..f5783d1
> --- /dev/null
> +++ b/client/tests/controller_test/controller_test.vcproj
> @@ -0,0 +1,198 @@
> +<?xml version="1.0" encoding="Windows-1252"?>
> +<VisualStudioProject
> + ProjectType="Visual C++"
> + Version="9.00"
> + Name="controller_test"
> + ProjectGUID="{6DFCEAF5-D081-46F0-AE15-42C5D3240CFD}"
> + RootNamespace="controller_test"
> + Keyword="Win32Proj"
> + TargetFrameworkVersion="131072"
> + >
> + <Platforms>
> + <Platform
> + Name="Win32"
> + />
> + </Platforms>
> + <ToolFiles>
> + </ToolFiles>
> + <Configurations>
> + <Configuration
> + Name="Debug|Win32"
> + OutputDirectory="$(SolutionDir)$(ConfigurationName)"
> + IntermediateDirectory="$(ConfigurationName)"
> + ConfigurationType="1"
> + CharacterSet="1"
> + >
> + <Tool
> + Name="VCPreBuildEventTool"
> + />
> + <Tool
> + Name="VCCustomBuildTool"
> + />
> + <Tool
> + Name="VCXMLDataGeneratorTool"
> + />
> + <Tool
> + Name="VCWebServiceProxyGeneratorTool"
> + />
> + <Tool
> + Name="VCMIDLTool"
> + />
> + <Tool
> + Name="VCCLCompilerTool"
> + Optimization="0"
> + AdditionalIncludeDirectories="..\..\windows;..\..\..\..\spice-protocol"
> + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
> + MinimalRebuild="true"
> + BasicRuntimeChecks="3"
> + RuntimeLibrary="1"
> + UsePrecompiledHeader="0"
> + WarningLevel="3"
> + Detect64BitPortabilityProblems="false"
> + DebugInformationFormat="4"
> + />
> + <Tool
> + Name="VCManagedResourceCompilerTool"
> + />
> + <Tool
> + Name="VCResourceCompilerTool"
> + />
> + <Tool
> + Name="VCPreLinkEventTool"
> + />
> + <Tool
> + Name="VCLinkerTool"
> + LinkIncremental="2"
> + GenerateDebugInformation="true"
> + SubSystem="1"
> + RandomizedBaseAddress="1"
> + DataExecutionPrevention="0"
> + TargetMachine="1"
> + />
> + <Tool
> + Name="VCALinkTool"
> + />
> + <Tool
> + Name="VCManifestTool"
> + />
> + <Tool
> + Name="VCXDCMakeTool"
> + />
> + <Tool
> + Name="VCBscMakeTool"
> + />
> + <Tool
> + Name="VCFxCopTool"
> + />
> + <Tool
> + Name="VCAppVerifierTool"
> + />
> + <Tool
> + Name="VCPostBuildEventTool"
> + />
> + </Configuration>
> + <Configuration
> + Name="Release|Win32"
> + OutputDirectory="$(SolutionDir)$(ConfigurationName)"
> + IntermediateDirectory="$(ConfigurationName)"
> + ConfigurationType="1"
> + CharacterSet="1"
> + WholeProgramOptimization="1"
> + >
> + <Tool
> + Name="VCPreBuildEventTool"
> + />
> + <Tool
> + Name="VCCustomBuildTool"
> + />
> + <Tool
> + Name="VCXMLDataGeneratorTool"
> + />
> + <Tool
> + Name="VCWebServiceProxyGeneratorTool"
> + />
> + <Tool
> + Name="VCMIDLTool"
> + />
> + <Tool
> + Name="VCCLCompilerTool"
> + AdditionalIncludeDirectories="..\..\windows;..\..\..\..\spice-protocol"
> + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
> + RuntimeLibrary="2"
> + UsePrecompiledHeader="0"
> + WarningLevel="3"
> + Detect64BitPortabilityProblems="false"
> + DebugInformationFormat="3"
> + />
> + <Tool
> + Name="VCManagedResourceCompilerTool"
> + />
> + <Tool
> + Name="VCResourceCompilerTool"
> + />
> + <Tool
> + Name="VCPreLinkEventTool"
> + />
> + <Tool
> + Name="VCLinkerTool"
> + LinkIncremental="1"
> + GenerateDebugInformation="true"
> + SubSystem="1"
> + OptimizeReferences="2"
> + EnableCOMDATFolding="2"
> + RandomizedBaseAddress="1"
> + DataExecutionPrevention="0"
> + TargetMachine="1"
> + />
> + <Tool
> + Name="VCALinkTool"
> + />
> + <Tool
> + Name="VCManifestTool"
> + />
> + <Tool
> + Name="VCXDCMakeTool"
> + />
> + <Tool
> + Name="VCBscMakeTool"
> + />
> + <Tool
> + Name="VCFxCopTool"
> + />
> + <Tool
> + Name="VCAppVerifierTool"
> + />
> + <Tool
> + Name="VCPostBuildEventTool"
> + />
> + </Configuration>
> + </Configurations>
> + <References>
> + </References>
> + <Files>
> + <Filter
> + Name="Source Files"
> + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
> + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
> + >
> + <File
> + RelativePath=".\controller_test.cpp"
> + >
> + </File>
> + </Filter>
> + <Filter
> + Name="Header Files"
> + Filter="h;hpp;hxx;hm;inl;inc;xsd"
> + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
> + >
> + </Filter>
> + <Filter
> + Name="Resource Files"
> + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
> + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
> + >
> + </Filter>
> + </Files>
> + <Globals>
> + </Globals>
> +</VisualStudioProject>
>
>
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
More information about the Spice-devel
mailing list