[WS2_32_APITEST]
[reactos.git] / rostests / apitests / crt / strlen.c
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>
14 typedef _Return_type_success_(return >= 0) long NTSTATUS, *PNTSTATUS;
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
31 Test_strlen(PFN_STRLEN pstrlen)
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);
42 EndSeh(STATUS_ACCESS_VIOLATION);
43 (void)len;
44
45 ok_int((int)pstrlen("test"), 4);
46
47 #if defined(_M_IX86) || defined(_M_AMD64)
48 eflags = __readeflags();
49 __writeeflags(eflags | EFLAGS_DF);
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
66 START_TEST(strlen)
67 {
68 Test_strlen(strlen);
69 #ifdef __GNUC__
70 Test_strlen(GCC_builtin_strlen);
71 #endif // __GNUC__
72 }