1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPLv2+ - See COPYING in the top level directory 4 * PURPOSE: Test for RtlGetLengthWithoutTrailingPathSeperators 5 * PROGRAMMER: David Quintana <gigaherz@gmail.com> 6 */ 7 8 #define WIN32_NO_STATUS 9 #include <apitest.h> 10 #include <ndk/rtlfuncs.h> 11 12 #define MakeTestEntry_Success(str, expect) \ 13 { str, expect, STATUS_SUCCESS, __LINE__ } 14 15 struct test_data { 16 PWSTR input; 17 ULONG expected_output; 18 NTSTATUS expected_result; 19 int line; 20 } test_entries[] = { 21 22 /* NULL in UNICODE_STRING */ 23 MakeTestEntry_Success( NULL, 0 ), 24 25 /* Length tests */ 26 MakeTestEntry_Success( L"", 0 ), 27 MakeTestEntry_Success( L"T", 1 ), 28 MakeTestEntry_Success( L"Te", 2 ), 29 MakeTestEntry_Success( L"Tes", 3 ), 30 MakeTestEntry_Success( L"Test", 4 ), 31 32 /* Separators tests */ 33 MakeTestEntry_Success( L"\\.", 2 ), 34 MakeTestEntry_Success( L"\\.", 2 ), 35 MakeTestEntry_Success( L"\\.\\", 2 ), 36 MakeTestEntry_Success( L"\\.\\T", 4 ), 37 MakeTestEntry_Success( L"\\.\\Te", 5 ), 38 MakeTestEntry_Success( L"\\.\\Tes", 6 ), 39 MakeTestEntry_Success( L"\\.\\Test", 7 ), 40 MakeTestEntry_Success( L"\\.\\Test\\", 7 ), 41 MakeTestEntry_Success( L"\\.\\Test\\s", 9 ), 42 MakeTestEntry_Success( L"\\.\\T\\est", 8 ), 43 MakeTestEntry_Success( L"\\.\\T\\e\\st", 9 ), 44 MakeTestEntry_Success( L"\\.\\T\\e\\s\\t", 10 ), 45 MakeTestEntry_Success( L"\\.\\T\\e\\s\\t\\", 10 ), 46 MakeTestEntry_Success( L"\\Tests\\String\\", 13 ), 47 MakeTestEntry_Success( L"\\.\\Test\\String\\", 14 ), 48 MakeTestEntry_Success( L"\\.\\Tests\\String\\", 15 ), 49 MakeTestEntry_Success( L"\\.\\Tests\\String\\s", 17 ), 50 MakeTestEntry_Success( L"\\.\\Tests\\String\\as", 18 ), 51 MakeTestEntry_Success( L"\\.\\Tests\\String\\asd", 19 ), 52 MakeTestEntry_Success( L"\\.\\Tests\\String\\asdf", 20 ), 53 MakeTestEntry_Success( L"\\Tests\\String\\sdfsdf\\", 20 ), 54 MakeTestEntry_Success( L"C:\\Tests\\String\\sdfsdf\\", 22 ), 55 56 /* Separator-only tests */ 57 MakeTestEntry_Success( L"\\", 0 ), 58 MakeTestEntry_Success( L"/", 0 ), 59 60 /* Mixed separators tests */ 61 MakeTestEntry_Success( L"/Test/String", 12 ), 62 MakeTestEntry_Success( L"\\Test/String", 12 ), 63 MakeTestEntry_Success( L"/Test\\String", 12 ), 64 MakeTestEntry_Success( L"\\Test/String", 12 ), 65 MakeTestEntry_Success( L"/Test/String\\", 12 ), 66 MakeTestEntry_Success( L"\\Test/String\\", 12 ), 67 MakeTestEntry_Success( L"/Test\\String\\", 12 ), 68 MakeTestEntry_Success( L"\\Test/String\\", 12 ), 69 MakeTestEntry_Success( L"/Test/String/", 12 ), 70 MakeTestEntry_Success( L"\\Test/String/", 12 ), 71 MakeTestEntry_Success( L"/Test\\String/", 12 ), 72 MakeTestEntry_Success( L"\\Test/String/", 12 ), 73 MakeTestEntry_Success( L"\\Test/String/", 12 ), 74 MakeTestEntry_Success( L"\\Test\\\\String/", 13 ), 75 76 /* Common path formats tests */ 77 MakeTestEntry_Success( L"Test\\String", 11 ), 78 MakeTestEntry_Success( L"\\Test\\String", 12 ), 79 MakeTestEntry_Success( L".\\Test\\String", 13 ), 80 MakeTestEntry_Success( L"\\.\\Test\\String", 14 ), 81 MakeTestEntry_Success( L"\\??\\Test\\String", 15 ), 82 83 /* Redundant trailing tests */ 84 MakeTestEntry_Success( L"\\??\\Test\\String\\", 15 ), 85 MakeTestEntry_Success( L"\\??\\Test\\String\\\\", 15 ), 86 MakeTestEntry_Success( L"\\??\\Test\\String\\\\\\\\\\", 15 ), 87 88 }; 89 90 int num_tests = sizeof(test_entries) / sizeof(struct test_data); 91 92 START_TEST(RtlGetLengthWithoutTrailingPathSeperators) 93 { 94 ULONG len; 95 UNICODE_STRING str; 96 NTSTATUS res; 97 int i; 98 99 struct test_data * pentry = test_entries; 100 101 for(i = 0; i < num_tests; i++, pentry++) 102 { 103 RtlInitUnicodeString( 104 &str, pentry->input); 105 106 len = 0xDEADBEEF; 107 108 StartSeh() 109 res = RtlGetLengthWithoutTrailingPathSeperators(0, &str, &len); 110 EndSeh(STATUS_SUCCESS); 111 112 ok(res == pentry->expected_result, 113 "Unexpected result 0x%08lx (expected 0x%08lx) in [%d:%d]\n", 114 res, pentry->expected_result, 115 i, pentry->line); 116 ok(len == pentry->expected_output, 117 "Unexpected length %lu (expected %lu) in [%d:%d]\n", 118 len, pentry->expected_output, 119 i, pentry->line); 120 } 121 122 // Invalid parameters 123 124 len = 0xDEADBEEF; 125 126 StartSeh() 127 res = RtlGetLengthWithoutTrailingPathSeperators(0, NULL, &len); 128 EndSeh(STATUS_SUCCESS); 129 130 ok(res == STATUS_INVALID_PARAMETER, 131 "Unexpected result 0x%08lx (expected STATUS_INVALID_PARAMETER)\n", 132 res); 133 ok(len == 0, 134 "Unexpected length %08lx (expected 0)\n", 135 len); 136 137 StartSeh() 138 res = RtlGetLengthWithoutTrailingPathSeperators(0, &str, NULL); 139 EndSeh(STATUS_SUCCESS); 140 141 ok(res == STATUS_INVALID_PARAMETER, 142 "Unexpected result 0x%08lx (expected STATUS_INVALID_PARAMETER)\n", 143 res); 144 145 StartSeh() 146 res = RtlGetLengthWithoutTrailingPathSeperators(0, NULL, NULL); 147 EndSeh(STATUS_SUCCESS); 148 149 ok(res == STATUS_INVALID_PARAMETER, 150 "Unexpected result 0x%08lx (expected STATUS_INVALID_PARAMETER)\n", 151 res); 152 153 for(i = 0; i < 32; i++) 154 { 155 len = 0xDEADBEEF; 156 157 StartSeh() 158 res = RtlGetLengthWithoutTrailingPathSeperators(1<<i, &str, &len); 159 EndSeh(STATUS_SUCCESS); 160 161 ok(res == STATUS_INVALID_PARAMETER, 162 "Unexpected result 0x%08lx (expected STATUS_INVALID_PARAMETER)\n", 163 res); 164 165 ok(len == 0, 166 "Unexpected length %08lx (expected 0)\n", 167 len); 168 } 169 170 len = 0xDEADBEEF; 171 172 StartSeh() 173 res = RtlGetLengthWithoutTrailingPathSeperators(0xFFFFFFFF, &str, &len); 174 EndSeh(STATUS_SUCCESS); 175 176 ok(res == STATUS_INVALID_PARAMETER, 177 "Unexpected result 0x%08lx (expected STATUS_INVALID_PARAMETER)\n", 178 res); 179 180 ok(len == 0, 181 "Unexpected length %08lx (expected 0)\n", 182 len); 183 } 184