Author: hbelusca
Date: Mon Mar 6 19:14:27 2017
New Revision: 74118
URL:
http://svn.reactos.org/svn/reactos?rev=74118&view=rev
Log:
[KERNEL32_APITEST]: Add basic tests for lstrlenA/W, focusing on its special handling of
the NULL pointer.
We detect that the NULL pointer is handled separately because no exception is generated,
contrary to when the function is called with truly invalid pointers.
I thank Mark for having mentioned the vectored exception handling to me, needed to catch
first-chance exceptions.
Added:
trunk/rostests/apitests/kernel32/lstrlen.c (with props)
Modified:
trunk/rostests/apitests/kernel32/CMakeLists.txt
trunk/rostests/apitests/kernel32/testlist.c
Modified: trunk/rostests/apitests/kernel32/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/kernel32/CMakeLi…
==============================================================================
--- trunk/rostests/apitests/kernel32/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/rostests/apitests/kernel32/CMakeLists.txt [iso-8859-1] Mon Mar 6 19:14:27 2017
@@ -14,6 +14,7 @@
interlck.c
LoadLibraryExW.c
lstrcpynW.c
+ lstrlen.c
MultiByteToWideChar.c
PrivMoveFileIdentityW.c
SetConsoleWindowInfo.c
Added: trunk/rostests/apitests/kernel32/lstrlen.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/kernel32/lstrlen…
==============================================================================
--- trunk/rostests/apitests/kernel32/lstrlen.c (added)
+++ trunk/rostests/apitests/kernel32/lstrlen.c [iso-8859-1] Mon Mar 6 19:14:27 2017
@@ -0,0 +1,56 @@
+/*
+ * PROJECT: ReactOS api tests
+ * LICENSE: GPLv2+ - See COPYING in the top level directory
+ * PURPOSE: Tests for lstrlenA/W
+ * PROGRAMMER: Hermes Belusca-Maito
+ */
+
+#include <apitest.h>
+
+#define WIN32_NO_STATUS
+#include <stdio.h>
+
+LONG WINAPI VEHandler_1(PEXCEPTION_POINTERS ExceptionInfo)
+{
+ /*
+ * Vectored Exception Handler possibly called for lstrlen(NULL).
+ * Expected not to be called!
+ */
+ ok(FALSE, "VEHandler_1 called!\n");
+ return EXCEPTION_CONTINUE_SEARCH;
+}
+
+LONG WINAPI VEHandler_2(PEXCEPTION_POINTERS ExceptionInfo)
+{
+ /* Vectored Exception Handler that should be called for lstrlen(<invalid_ptr>)
*/
+ ok(TRUE, "VEHandler_2 not called?\n");
+ return EXCEPTION_CONTINUE_SEARCH;
+}
+
+START_TEST(lstrlen)
+{
+ PVOID pVEH;
+
+ /* Test basic functionality */
+ ok(lstrlenA( "Hello World!") == 12, "lstrlenA failed!\n");
+ ok(lstrlenW(L"Hello World!") == 12, "lstrlenW failed!\n");
+
+ /*
+ * NULL buffer is special and is considered separately;
+ * no internal exception is generated.
+ * Use Vectored Exception Handling to monitor for first-chance exceptions.
+ */
+pVEH = AddVectoredExceptionHandler(1, VEHandler_1);
+ ok(lstrlenA(NULL) == 0, "lstrlenA should have returned 0.\n");
+ ok(lstrlenW(NULL) == 0, "lstrlenW should have returned 0.\n");
+RemoveVectoredExceptionHandler(pVEH);
+
+ /*
+ * Test some invalid buffers. Internal exceptions should be generated.
+ * Use Vectored Exception Handling to monitor for first-chance exceptions.
+ */
+pVEH = AddVectoredExceptionHandler(1, VEHandler_2);
+ ok(lstrlenA( (LPSTR)0xbaadf00d) == 0, "lstrlenA should have returned
0.\n");
+ ok(lstrlenW((LPWSTR)0xbaadf00d) == 0, "lstrlenW should have returned
0.\n");
+RemoveVectoredExceptionHandler(pVEH);
+}
Propchange: trunk/rostests/apitests/kernel32/lstrlen.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/rostests/apitests/kernel32/testlist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/kernel32/testlis…
==============================================================================
--- trunk/rostests/apitests/kernel32/testlist.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/kernel32/testlist.c [iso-8859-1] Mon Mar 6 19:14:27 2017
@@ -15,6 +15,7 @@
extern void func_interlck(void);
extern void func_LoadLibraryExW(void);
extern void func_lstrcpynW(void);
+extern void func_lstrlen(void);
extern void func_Mailslot(void);
extern void func_MultiByteToWideChar(void);
extern void func_PrivMoveFileIdentityW(void);
@@ -39,6 +40,7 @@
{ "interlck", func_interlck },
{ "LoadLibraryExW", func_LoadLibraryExW },
{ "lstrcpynW", func_lstrcpynW },
+ { "lstrlen", func_lstrlen },
{ "MailslotRead", func_Mailslot },
{ "MultiByteToWideChar", func_MultiByteToWideChar },
{ "PrivMoveFileIdentityW", func_PrivMoveFileIdentityW },