Reactos
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Test for StrRStrA/W
5 * COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6 */
7
8#include "shelltest.h"
9#include <versionhelpers.h>
10
11typedef PSTR (WINAPI *FN_StrRStrA)(PCSTR, PCSTR, PCSTR pszSearch);
12typedef PWSTR (WINAPI *FN_StrRStrW)(PCWSTR, PCWSTR, PCWSTR pszSearch);
13
14static VOID TEST_StrRStrA(VOID)
15{
16 PCSTR psz, pch;
17 PSTR ret;
18 FN_StrRStrA StrRStrA = (FN_StrRStrA)GetProcAddress(GetModuleHandleW(L"shell32"), MAKEINTRESOURCEA(389));
19
20 if (!StrRStrA)
21 {
22 skip("StrRStrA not found\n");
23 return;
24 }
25
26 psz = "ABCBC";
27 ret = StrRStrA(psz, NULL, "BC");
28 ok_ptr(ret, psz + 3);
29
30 psz = "ABCBC";
31 pch = &psz[2];
32 ret = StrRStrA(psz, pch, "BC");
33 ok_ptr(ret, &psz[1]);
34
35 psz = "ABCBC";
36 ret = StrRStrA(psz, psz, "BC");
37 ok(!ret, "ret was '%s'\n", ret);
38
39 psz = "ABCBC";
40 pch = &psz[lstrlenA(psz)];
41 ret = StrRStrA(psz, pch, "BC");
42 ok_ptr(ret, psz + 3);
43}
44
45static VOID TEST_StrRStrW(VOID)
46{
47 PCWSTR psz, pch;
48 PWSTR ret;
49 FN_StrRStrW StrRStrW = (FN_StrRStrW)GetProcAddress(GetModuleHandleW(L"shell32"), MAKEINTRESOURCEA(392));
50
51 if (!StrRStrW)
52 {
53 skip("StrRStrW not found\n");
54 return;
55 }
56
57 psz = L"ABCBC";
58 ret = StrRStrW(psz, NULL, L"BC");
59 ok_ptr(ret, psz + 3);
60
61 psz = L"ABCBC";
62 pch = &psz[2];
63 ret = StrRStrW(psz, pch, L"BC");
64 ok_ptr(ret, &psz[1]);
65
66 psz = L"ABCBC";
67 ret = StrRStrW(psz, psz, L"BC");
68 ok(!ret, "ret was '%S'\n", ret);
69
70 psz = L"ABCBC";
71 pch = &psz[lstrlenW(psz)];
72 ret = StrRStrW(psz, pch, L"BC");
73 ok_ptr(ret, psz + 3);
74}
75
76static BOOL IsWindowsServer2003SP2OrGreater(VOID)
77{
78 return IsWindowsVersionOrGreater(5, 2, 2);
79}
80
81START_TEST(StrRStr)
82{
83 if (IsWindowsVistaOrGreater())
84 {
85 skip("Vista+\n");
86 return;
87 }
88
89 if (!IsWindowsServer2003SP2OrGreater())
90 {
91 skip("Before 2K3 SP3\n");
92 return;
93 }
94
95 TEST_StrRStrA();
96 TEST_StrRStrW();
97}