ReactOS  0.4.13-dev-73-gcfe54aa
strlen.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Test for strlen
5  * PROGRAMMER: Timo Kreuzer <timo.kreuzer@reactos.org>
6  */
7 
8 #include <apitest.h>
9 
10 #include <stdio.h>
11 #include <tchar.h>
12 #include <pseh/pseh2.h>
13 #include <ntstatus.h>
15 
16 #ifdef __GNUC__
17 #pragma GCC diagnostic ignored "-Wnonnull"
18 
19 size_t
20 GCC_builtin_strlen(const char *str)
21 {
22  return __builtin_strlen(str);
23 }
24 #endif
25 
26 #define EFLAGS_DF 0x400L
27 
28 typedef size_t (*PFN_STRLEN)(const char *);
29 
30 void
32 {
33  size_t len;
34 #if defined(_M_IX86) || defined(_M_AMD64)
35  volatile uintptr_t eflags;
36  char *teststr = "a\0bcdefghijk";
37 #endif
38 
39  /* basic parameter tests */
40  StartSeh()
41  len = pstrlen(NULL);
43  (void)len;
44 
45  ok_int((int)pstrlen("test"), 4);
46 
47 #if defined(_M_IX86) || defined(_M_AMD64)
48  eflags = __readeflags();
50  len = pstrlen(teststr + 4);
51  eflags = __readeflags();
52  ok((eflags & EFLAGS_DF) != 0, "Direction flag in ELFAGS was changed.");
53 
54  /* Only test this for the exported versions, intrinsics might do it
55  differently. It's up to us to not do fishy stuff! Also crtdll does
56  not do it like this. */
57 #ifndef TEST_CRTDLL
58  if (pstrlen == strlen)
59  {
60  ok(len == 8, "Should not have gone backwards (got len %i)", (int)len);
61  }
62 #endif // TEST_CRTDLL
63 #endif
64 }
65 
67 {
69 #ifdef __GNUC__
70  Test_strlen(GCC_builtin_strlen);
71 #endif // __GNUC__
72 }
LOCAL struct eflags eflags[]
* PNTSTATUS
Definition: strlen.c:14
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ok_int(x, y)
Definition: sprintf.c:21
LONG NTSTATUS
Definition: precomp.h:26
void Test_strlen(PFN_STRLEN pstrlen)
Definition: strlen.c:31
#define StartSeh()
Definition: _sntprintf.h:16
size_t(* PFN_STRLEN)(const char *)
Definition: strlen.c:28
typedef _Return_type_success_(return >=0) long NTSTATUS
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
unsigned int uintptr_t
Definition: crtdefs.h:300
#define ok(value,...)
START_TEST(strlen)
Definition: strlen.c:66
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
__kernel_size_t size_t
Definition: linux.h:237
unsigned long
Definition: typeof.h:101
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1550
GLenum GLsizei len
Definition: glext.h:6722
#define EFLAGS_DF
Definition: strlen.c:26
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17