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.

190 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. trtl.c
  5. Abstract:
  6. Test program for the NT OS Runtime Library (RTL)
  7. Author:
  8. Steve Wood (stevewo) 31-Mar-1989
  9. Revision History:
  10. --*/
  11. #include <os2.h>
  12. #include <stdio.h>
  13. #include <process.h>
  14. #include "nt.h"
  15. #include "ntrtl.h"
  16. char *TestMemoryStrings[] = {
  17. "",
  18. "1",
  19. "12",
  20. "123",
  21. "1234",
  22. "12345",
  23. "123456",
  24. "1234567",
  25. "12345678",
  26. "123456789",
  27. "123456789A",
  28. NULL
  29. };
  30. BOOLEAN
  31. StringCompare(
  32. IN PSTRING String1,
  33. IN PSTRING String2,
  34. IN BOOLEAN CaseInSensitive,
  35. IN LONG ExpectedResult
  36. )
  37. {
  38. LONG Result = RtlCompareString( String1, String2, CaseInSensitive );
  39. if (Result < 0) {
  40. Result = -1L;
  41. }
  42. else {
  43. if (Result > 0) {
  44. Result = 1L;
  45. }
  46. }
  47. if (Result != ExpectedResult) {
  48. DbgPrint( "RtlCompareString( \"%.*s\", \"%.*s\", %d ) == %ld (%ld)\n",
  49. String1->Length, String1->Buffer,
  50. String2->Length, String2->Buffer,
  51. CaseInSensitive,
  52. Result, ExpectedResult
  53. );
  54. return( FALSE );
  55. }
  56. else {
  57. return( TRUE );
  58. }
  59. }
  60. BOOLEAN
  61. StringEqual(
  62. IN PSTRING String1,
  63. IN PSTRING String2,
  64. IN BOOLEAN CaseInSensitive,
  65. IN BOOLEAN ExpectedResult
  66. )
  67. {
  68. BOOLEAN Result = RtlEqualString( String1, String2, CaseInSensitive );
  69. if (Result != ExpectedResult) {
  70. DbgPrint( "RtlEqualString( \"%.*s\", \"%.*s\", %d ) == %d (%d)\n",
  71. String1->Length, String1->Buffer,
  72. String2->Length, String2->Buffer,
  73. CaseInSensitive,
  74. Result, ExpectedResult );
  75. return( FALSE );
  76. }
  77. else {
  78. return( TRUE );
  79. }
  80. }
  81. VOID
  82. DumpString(
  83. IN PCH StringTitle,
  84. IN PSTRING String
  85. )
  86. {
  87. DbgPrint( "%s: (%d, %d) \"%.*s\"\n", StringTitle,
  88. String->MaximumLength,
  89. String->Length,
  90. String->Length,
  91. String->Buffer );
  92. }
  93. BOOLEAN
  94. TestString( void )
  95. {
  96. BOOLEAN Result;
  97. char buffer5[ 80 ], buffer6[ 15 ], buffer7[ 3 ];
  98. STRING String1, String2, String3, String4;
  99. STRING String5, String6, String7, String8;
  100. // 1 2
  101. //12345678901234567890
  102. //
  103. RtlInitString( &String1, " One" );
  104. RtlInitString( &String2, " Two" );
  105. RtlInitString( &String3, " Three" );
  106. RtlInitString( &String4, " Four" );
  107. String5.Buffer = buffer5;
  108. String5.MaximumLength = sizeof( buffer5 );
  109. String5.Length = 0;
  110. String6.Buffer = buffer6;
  111. String6.MaximumLength = sizeof( buffer6 );
  112. String6.Length = 0;
  113. String7.Buffer = buffer7;
  114. String7.MaximumLength = sizeof( buffer7 );
  115. String7.Length = 0;
  116. String8.Buffer = NULL;
  117. String8.MaximumLength = 0;
  118. String8.Length = 0;
  119. RtlCopyString( &String5, &String1 );
  120. RtlCopyString( &String6, &String2 );
  121. RtlCopyString( &String7, &String3 );
  122. RtlCopyString( &String8, &String4 );
  123. DumpString( "String1", &String1 );
  124. DumpString( "String2", &String2 );
  125. DumpString( "String3", &String3 );
  126. DumpString( "String4", &String4 );
  127. DumpString( "String5", &String5 );
  128. DumpString( "String6", &String6 );
  129. DumpString( "String7", &String7 );
  130. DumpString( "String8", &String8 );
  131. Result = TRUE;
  132. Result &= StringCompare( &String1, &String1, FALSE, 0L );
  133. Result &= StringCompare( &String1, &String2, FALSE, -1L);
  134. Result &= StringCompare( &String1, &String3, FALSE, -1L);
  135. Result &= StringCompare( &String1, &String4, FALSE, 1L );
  136. Result &= StringCompare( &String1, &String5, FALSE, 0L );
  137. Result &= StringCompare( &String1, &String6, FALSE, -1L);
  138. Result &= StringCompare( &String1, &String7, FALSE, -1L);
  139. Result &= StringCompare( &String1, &String8, FALSE, 1L );
  140. Result &= StringEqual( &String1, &String1, FALSE, 1 );
  141. Result &= StringEqual( &String1, &String2, FALSE, 0 );
  142. Result &= StringEqual( &String1, &String3, FALSE, 0 );
  143. Result &= StringEqual( &String1, &String4, FALSE, 0 );
  144. Result &= StringEqual( &String1, &String5, FALSE, 1 );
  145. Result &= StringEqual( &String1, &String6, FALSE, 0 );
  146. Result &= StringEqual( &String1, &String7, FALSE, 0 );
  147. Result &= StringEqual( &String1, &String8, FALSE, 0 );
  148. return( Result );
  149. }
  150. int
  151. _CDECL
  152. main(
  153. int argc,
  154. char *argv[]
  155. )
  156. {
  157. if (!TestString()) {
  158. DbgPrint( "TRTL: TestString failed\n" );
  159. exit( 1 );
  160. }
  161. exit( 0 );
  162. return( 0 );
  163. }