[GDI+: 4/10] graphics test
Evan Stade
estade at gmail.com
Mon Jun 11 13:55:17 CDT 2007
Hi,
Changelog:
*added first GDI+ graphics test (constructors/destructor)
dlls/gdiplus/tests/Makefile.in | 1
dlls/gdiplus/tests/graphics.c | 157 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 158 insertions(+), 0 deletions(-)
-Evan Stade
-------------- next part --------------
diff --git a/dlls/gdiplus/tests/Makefile.in b/dlls/gdiplus/tests/Makefile.in
index 14bc936..4f3007d 100644
--- a/dlls/gdiplus/tests/Makefile.in
+++ b/dlls/gdiplus/tests/Makefile.in
@@ -6,6 +6,7 @@ TESTDLL = gdiplus.dll
IMPORTS = user32 gdi32 kernel32 gdiplus
CTESTS = \
+ graphics.c \
pen.c
@MAKE_TEST_RULES@
diff --git a/dlls/gdiplus/tests/graphics.c b/dlls/gdiplus/tests/graphics.c
new file mode 100644
index 0000000..29a4b55
--- /dev/null
+++ b/dlls/gdiplus/tests/graphics.c
@@ -0,0 +1,157 @@
+/*
+ * Unit test suite for graphics
+ *
+ * Copyright (C) 2007 Google (Evan Stade)
+ *
+ * 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 <stdarg.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include "windows.h"
+#include "wingdi.h"
+#include "windef.h"
+#include "winbase.h"
+#include "gdiplus.h"
+#include "wine/test.h"
+
+#define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
+
+/* heighth and width of test windows */
+#define WND_SZ (16)
+
+#define SIMPLE_WINDOW_PROC(testname) \
+static LRESULT WINAPI testname##_window_proc(HWND hwnd, UINT msg, WPARAM wparam, \
+ LPARAM lparam) \
+{ \
+ PAINTSTRUCT ps; \
+ HDC hdc; \
+ \
+ switch (msg) \
+ { \
+ case WM_PAINT: \
+ hdc = BeginPaint(hwnd, &ps); \
+ testname (hwnd, hdc); \
+ EndPaint(hwnd, &ps); \
+ return 0; \
+ default: \
+ return DefWindowProc(hwnd, msg, wparam, lparam); \
+ } \
+}
+
+static void constructor(HWND hwnd, HDC hdc)
+{
+ GpStatus stat;
+ GpGraphics *graphics = NULL;
+
+ stat = GdipCreateFromHDC(NULL, &graphics);
+ expect(stat, OutOfMemory);
+ stat = GdipDeleteGraphics(graphics);
+ expect(stat, InvalidParameter);
+
+ stat = GdipCreateFromHDC(hdc, &graphics);
+ expect(stat, Ok);
+ stat = GdipDeleteGraphics(graphics);
+ expect(stat, Ok);
+
+ stat = GdipCreateFromHWND(NULL, &graphics);
+ expect(stat, Ok);
+ stat = GdipDeleteGraphics(graphics);
+ expect(stat, Ok);
+
+ stat = GdipCreateFromHWND(hwnd, &graphics);
+ expect(stat, Ok);
+ stat = GdipDeleteGraphics(graphics);
+ expect(stat, Ok);
+
+ stat = GdipCreateFromHDC(hdc, NULL);
+ expect(stat, InvalidParameter);
+}
+
+SIMPLE_WINDOW_PROC(constructor)
+
+static BOOL RegisterHelper(WNDPROC x, LPCTSTR ClassName)
+{
+ WNDCLASS wndClass;
+
+ wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
+ wndClass.lpfnWndProc = x;
+ wndClass.cbClsExtra = 0;
+ wndClass.cbWndExtra = 0;
+ wndClass.hInstance = NULL;
+
+ wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+ wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
+ wndClass.lpszMenuName = NULL;
+ wndClass.lpszClassName = TEXT(ClassName);
+
+ if(!RegisterClassA(&wndClass)) return FALSE;
+
+ return TRUE;
+}
+
+static BOOL RegisterWindowClasses(void)
+{
+ BOOL ret;
+
+ ret = RegisterHelper(constructor_window_proc, TEXT("Constructor"));
+
+ return ret;
+}
+
+static void window_test_runner(LPCTSTR ClassName, LPCTSTR Caption)
+{
+ HWND hwnd;
+
+ hwnd = CreateWindow(
+ ClassName,
+ Caption,
+ WS_POPUP,
+ 0, 0, WND_SZ, WND_SZ,
+ 0, 0, 0, NULL);
+
+ assert(hwnd);
+
+ ShowWindow(hwnd, SW_SHOW);
+ UpdateWindow(hwnd);
+ DestroyWindow(hwnd);
+}
+
+static void test_constructor_destructor(void)
+{
+ window_test_runner(TEXT("Constructor"), TEXT("Graphics constructor test"));
+}
+
+START_TEST(graphics)
+{
+ struct GdiplusStartupInput gdiplusStartupInput;
+ ULONG_PTR gdiplusToken;
+
+ if (!RegisterWindowClasses()) assert(0);
+
+ gdiplusStartupInput.GdiplusVersion=1;
+ gdiplusStartupInput.DebugEventCallback=NULL;
+ gdiplusStartupInput.SuppressBackgroundThread=0;
+ gdiplusStartupInput.SuppressExternalCodecs=0;
+
+ GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
+
+ test_constructor_destructor();
+
+ GdiplusShutdown(gdiplusToken);
+}
--
1.4.1
More information about the wine-patches
mailing list