From 12c725a26b6b32d06cc9accc692dd60458d58ff3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mariusz=20Pluci=C5=84ski?= <vshader@gmail.com>
Date: Mon, 5 Jul 2010 22:12:04 +0200
Subject: gameux/tests: add simple test for AddGame and RemoveGame game

---
 dlls/gameux/tests/Makefile.in    |    3 +-
 dlls/gameux/tests/gameexplorer.c |   59 +++++++++++++++++++++++++++++++++++++-
 dlls/gameux/tests/neu.gdf.xml    |   34 ++++++++++++++++++++++
 dlls/gameux/tests/rsrc.rc        |   26 ++++++++++++++++
 4 files changed, 120 insertions(+), 2 deletions(-)
 create mode 100644 dlls/gameux/tests/neu.gdf.xml
 create mode 100644 dlls/gameux/tests/rsrc.rc

diff --git a/dlls/gameux/tests/Makefile.in b/dlls/gameux/tests/Makefile.in
index 0b8e4eb..62989dc 100644
--- a/dlls/gameux/tests/Makefile.in
+++ b/dlls/gameux/tests/Makefile.in
@@ -3,11 +3,12 @@ TOPOBJDIR = ../../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 TESTDLL   = gameux.dll
-IMPORTS   = oleaut32 ole32 user32 kernel32
+IMPORTS   = oleaut32 ole32 user32 kernel32 shlwapi
 
 C_SRCS = \
 	gameexplorer.c \
 	gamestatistics.c
 	
+RC_SRCS = rsrc.rc
 
 @MAKE_TEST_RULES@
diff --git a/dlls/gameux/tests/gameexplorer.c b/dlls/gameux/tests/gameexplorer.c
index 601131d..1c8382c 100644
--- a/dlls/gameux/tests/gameexplorer.c
+++ b/dlls/gameux/tests/gameexplorer.c
@@ -26,6 +26,8 @@
 #include "ole2.h"
 #include "objsafe.h"
 #include "objbase.h"
+#include "shlwapi.h"
+
 #include "gameux.h"
 
 #include "wine/test.h"
@@ -47,7 +49,7 @@ static void test_create( void )
     }
     else
         skip("IGameExplorer cannot be created\n");
-
+    
     /* interface available up from Win7 */
     hr = CoCreateInstance( &CLSID_GameExplorer, NULL, CLSCTX_INPROC_SERVER, &IID_IGameExplorer2, (LPVOID*)&ge2);
     if(ge2)
@@ -59,6 +61,60 @@ static void test_create( void )
         skip("IGameExplorer2 cannot be created\n");
 }
 
+
+static void test_addgame( void )
+{
+    static const GUID defaultGUID = { 0x01234567, 0x89AB, 0xCDEF, { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF } };
+
+    HRESULT hr;
+
+    IGameExplorer* ge = NULL;
+    WCHAR sExeName[MAX_PATH];
+    WCHAR sExePath[MAX_PATH];
+    BSTR bstrExeName, bstrExePath;
+    LPWSTR lpEnd;
+    DWORD dwExeNameLen;
+    GUID guid;
+
+    hr = CoCreateInstance( &CLSID_GameExplorer, NULL, CLSCTX_INPROC_SERVER, &IID_IGameExplorer, (LPVOID*)&ge);
+    if(ge)
+    {
+        ok( hr == S_OK, "cannot create coclass IGameExplorer\n");
+
+        dwExeNameLen = GetModuleFileNameW( NULL, sExeName, sizeof(sExeName)/sizeof(sExeName[0]) );
+        ok(dwExeNameLen != 0, "GetModuleFileNameW returned invalid value\n");
+
+        lpEnd = StrRChrW(sExeName, NULL, '\\');
+        lstrcpynW(sExePath, sExeName, lpEnd-sExeName+1);
+
+        bstrExeName = SysAllocString(sExeName);
+        ok(bstrExeName!=NULL, "cannot allocate string for exe name\n");
+
+        bstrExePath = SysAllocString(sExePath);
+        ok(bstrExePath!=NULL, "cannot allocate string for exe path\n");
+
+        memcpy(&guid, &defaultGUID, sizeof(guid));
+
+        trace("IGameExplorer::AddGame(%p, %s, %s, GIS_CURRENT_USER, guid)\n", ge, wine_dbgstr_w(bstrExeName), wine_dbgstr_w(bstrExePath));
+        hr = IGameExplorer_AddGame(ge, bstrExeName, bstrExePath, GIS_CURRENT_USER, &guid);
+        ok(SUCCEEDED(hr), "IGameExplorer::AddGame failed (error 0x%08x)\n", hr);
+        ok(memcmp(&guid, &defaultGUID, sizeof(guid))==0, "AddGame unexpectedly modified GUID\n");
+
+
+
+        hr = IGameExplorer_RemoveGame(ge, guid);
+        ok(SUCCEEDED(hr), "IGameExplorer::RemoveGame failed (error 0x%08x)\n", hr);
+
+        SysFreeString(bstrExePath);
+        SysFreeString(bstrExeName);
+
+        hr = IGameExplorer_Release(ge);
+        ok(SUCCEEDED(hr), "IGameExplorer::Release failed\n");
+    }
+    else
+        skip("IGameExplorer cannot be created\n");
+}
+
 START_TEST(gameexplorer)
 {
     HRESULT r;
@@ -67,6 +123,7 @@ START_TEST(gameexplorer)
     ok( r == S_OK, "failed to init COM\n");
 
     test_create();
+    test_addgame();
 
     CoUninitialize();
 }
diff --git a/dlls/gameux/tests/neu.gdf.xml b/dlls/gameux/tests/neu.gdf.xml
new file mode 100644
index 0000000..f71c79b
--- /dev/null
+++ b/dlls/gameux/tests/neu.gdf.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<GameDefinitionFile xmlns:baseTypes="urn:schemas-microsoft-com:GamesExplorerBaseTypes.v1" xmlns="urn:schemas-microsoft-com:GameDescription.v1">
+    <GameDefinition gameID="{17A6558E-60BE-4078-B66F-9C3ADA2A32E6}">
+        <Name>Testing application</Name>
+        <Description>Application created for testing windows Game Explorer</Description>
+        <ReleaseDate>2010-06-16</ReleaseDate>
+        <Genres>
+            <Genre>Action</Genre>
+            <Genre>Children</Genre>
+            <Genre>Life Simulation</Genre>
+            <Genre>MMORPG</Genre>
+            <Genre>RPG</Genre>
+        </Genres>
+        <Ratings>
+            <Rating ratingSystemID="{00010203-0405-0607-0809-0a0b0c0d0e0f}" ratingID="{10111213-1415-1617-1819-1a1b1c1d1e1f}">
+                <Descriptor descriptorID="{20212223-2425-2627-2829-2a2b2c2d2e2f}" />
+            </Rating>
+        </Ratings>
+        <Version>
+            <VersionNumber versionNumber="1.0.0.0" />
+        </Version>
+        <SavedGames baseKnownFolderID="{4c5c32ff-bb9d-43b0-b5b4-2d72e54eaaa4}" path="saves" />
+        <WindowsSystemPerformanceRating minimum="3.4" recommended="4.0" />
+        <Developers>
+            <Developer URI="http://example.com">Developer</Developer>
+        </Developers>
+        <Publishers>
+            <Publisher URI="http://example.org">Publisher</Publisher>
+        </Publishers>
+        <GameExecutables>
+            <GameExecutable path="gameux_crosstest.exe" />
+        </GameExecutables>
+    </GameDefinition>
+</GameDefinitionFile>
diff --git a/dlls/gameux/tests/rsrc.rc b/dlls/gameux/tests/rsrc.rc
new file mode 100644
index 0000000..7856fa8
--- /dev/null
+++ b/dlls/gameux/tests/rsrc.rc
@@ -0,0 +1,26 @@
+/*
+ * Resources script for GameUX testing
+ *
+ * Copyright (C) 2010 Mariusz Pluciński
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "windef.h"
+#include "winuser.h"
+#include <gameux.h>
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT
+ID_GDF_XML          DATA          "neu.gdf.xml"
-- 
1.7.1.1

