Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. tpath.c
  5. Abstract:
  6. Test for canonicalization helpers.
  7. Author:
  8. Rita Wong (ritaw) 22-Feb-1993
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windef.h>
  19. #include <winbase.h>
  20. #include <nwcanon.h>
  21. #ifndef UNICODE
  22. #define UNICODE
  23. #endif
  24. DWORD
  25. TestCanonLocalName(
  26. IN LPWSTR LocalName,
  27. IN DWORD ExpectedError
  28. );
  29. DWORD
  30. TestCanonRemoteName(
  31. IN LPWSTR RemoteName,
  32. IN DWORD ExpectedError
  33. );
  34. // BYTE WorkBuffer[1024];
  35. void __cdecl
  36. main(
  37. void
  38. )
  39. {
  40. TestCanonLocalName(
  41. L"x:",
  42. NO_ERROR
  43. );
  44. TestCanonLocalName(
  45. L"B:",
  46. NO_ERROR
  47. );
  48. TestCanonLocalName(
  49. L"prn",
  50. NO_ERROR
  51. );
  52. TestCanonLocalName(
  53. L"lpt1:",
  54. NO_ERROR
  55. );
  56. TestCanonLocalName(
  57. L"*:",
  58. ERROR_INVALID_NAME
  59. );
  60. TestCanonLocalName(
  61. L"B",
  62. ERROR_INVALID_NAME
  63. );
  64. TestCanonLocalName(
  65. L"abc",
  66. ERROR_INVALID_NAME
  67. );
  68. TestCanonLocalName(
  69. L"\\:",
  70. ERROR_INVALID_NAME
  71. );
  72. TestCanonRemoteName(
  73. L"\\:",
  74. ERROR_INVALID_NAME
  75. );
  76. TestCanonRemoteName(
  77. L"\\\\Ser:ver",
  78. ERROR_INVALID_NAME
  79. );
  80. TestCanonRemoteName(
  81. L"\\\\*",
  82. ERROR_INVALID_NAME
  83. );
  84. TestCanonRemoteName(
  85. L"\\\\:",
  86. ERROR_INVALID_NAME
  87. );
  88. TestCanonRemoteName(
  89. L"\\\\Server\\Volume",
  90. NO_ERROR
  91. );
  92. TestCanonRemoteName(
  93. L"\\\\Server\\Volume\\Dir1\\Directory2\\ALongDirectory3",
  94. NO_ERROR
  95. );
  96. TestCanonRemoteName(
  97. L"\\\\Server\\Volume\\",
  98. ERROR_INVALID_NAME
  99. );
  100. TestCanonRemoteName(
  101. L"Server\\Volume\\",
  102. ERROR_INVALID_NAME
  103. );
  104. TestCanonRemoteName(
  105. L"\\\\Server\\Volu:me",
  106. ERROR_INVALID_NAME
  107. );
  108. TestCanonRemoteName(
  109. L"\\\\Server\\Volume\\\\Dir",
  110. ERROR_INVALID_NAME
  111. );
  112. TestCanonRemoteName(
  113. L"\\\\Server/Volume\\Dir",
  114. ERROR_INVALID_NAME
  115. );
  116. TestCanonRemoteName(
  117. L"\\\\Server\\Volume:",
  118. ERROR_INVALID_NAME
  119. );
  120. TestCanonRemoteName(
  121. L"\\\\Server",
  122. ERROR_INVALID_NAME
  123. );
  124. }
  125. DWORD
  126. TestCanonLocalName(
  127. IN LPWSTR LocalName,
  128. IN DWORD ExpectedError
  129. )
  130. {
  131. DWORD status;
  132. DWORD OutputBufferLength;
  133. LPWSTR OutputBuffer;
  134. printf("\nCanon local name %ws\n", LocalName);
  135. status = NwLibCanonLocalName(
  136. LocalName,
  137. &OutputBuffer,
  138. &OutputBufferLength
  139. );
  140. if (status == NO_ERROR) {
  141. printf(" got %ws, length %lu\n", OutputBuffer, OutputBufferLength);
  142. (void) LocalFree((HLOCAL) OutputBuffer);
  143. }
  144. if (status == ExpectedError) {
  145. printf(" SUCCESS: Got %lu as expected\n", ExpectedError);
  146. }
  147. else {
  148. printf(" FAILED: Got %lu, expected %lu\n", status, ExpectedError);
  149. }
  150. }
  151. DWORD
  152. TestCanonRemoteName(
  153. IN LPWSTR RemoteName,
  154. IN DWORD ExpectedError
  155. )
  156. {
  157. DWORD status;
  158. DWORD OutputBufferLength;
  159. LPWSTR OutputBuffer;
  160. printf("\nCanon remote name %ws\n", RemoteName);
  161. status = NwLibCanonRemoteName(
  162. RemoteName,
  163. &OutputBuffer,
  164. &OutputBufferLength
  165. );
  166. if (status == NO_ERROR) {
  167. printf(" got %ws, length %lu\n", OutputBuffer, OutputBufferLength);
  168. (void) LocalFree((HLOCAL) OutputBuffer);
  169. }
  170. if (status == ExpectedError) {
  171. printf(" SUCCESS: Got %lu as expected\n", ExpectedError);
  172. }
  173. else {
  174. printf(" FAILED: Got %lu, expected %lu\n", status, ExpectedError);
  175. }
  176. }