ReactOS 0.4.15-dev-7897-g78dc504
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
19size_t
20GCC_builtin_strlen(const char *str)
21{
22 return __builtin_strlen(str);
23}
24#endif
25
26#define EFLAGS_DF 0x400L
27
28typedef size_t (*PFN_STRLEN)(const char *);
29
30void
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)
50 len = pstrlen(teststr + 4);
51
52#ifdef _M_AMD64
53 ok((__readeflags() & EFLAGS_DF) != 0, "Direction flag in ELFAGS was changed.\n");
54#else
55 ok((__readeflags() & EFLAGS_DF) == 0, "Direction flag in ELFAGS was not changed.\n");
56#endif
58
59 /* Only test this for the exported versions, intrinsics might do it
60 differently. It's up to us to not do fishy stuff! Also crtdll does
61 not do it like this. */
62#ifndef TEST_CRTDLL
63 if (pstrlen == strlen)
64 {
65 ok(len == 8, "Should not have gone backwards (got len %i)", (int)len);
66 }
67#endif // TEST_CRTDLL
68#endif
69}
70
72{
74#ifdef __GNUC__
75 Test_strlen(GCC_builtin_strlen);
76#endif // __GNUC__
77}
#define StartSeh()
Definition: _sntprintf.h:16
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
LONG NTSTATUS
Definition: precomp.h:26
unsigned int uintptr_t
Definition: crtdefs.h:321
#define NULL
Definition: types.h:112
unsigned long
Definition: typeof.h:102
__kernel_size_t size_t
Definition: linux.h:237
GLenum GLsizei len
Definition: glext.h:6722
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1669
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1674
#define EFLAGS_DF
Definition: strlen.c:26
* PNTSTATUS
Definition: strlen.c:14
size_t(* PFN_STRLEN)(const char *)
Definition: strlen.c:28
void Test_strlen(PFN_STRLEN pstrlen)
Definition: strlen.c:31
#define _Return_type_success_(expr)
Definition: ms_sal.h:263
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
const WCHAR * str