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