Leaked source code of windows server 2003
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.

331 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. regtest.c
  5. Abstract:
  6. Test for quick and dirty registry test (very basic)
  7. Author:
  8. Bryan M. Willman (bryanwi) 30-Apr-1991
  9. Environment:
  10. User mode.
  11. Revision History:
  12. --*/
  13. #include "stdio.h"
  14. #include "nt.h"
  15. int strlen(PUCHAR);
  16. void main();
  17. VOID DoTest(HANDLE RootKey);
  18. #define MAX_VALUE 256
  19. UCHAR ValueBuffer[MAX_VALUE];
  20. VOID
  21. main()
  22. {
  23. DbgPrint("Machine\n");
  24. DoTest((HANDLE)REG_LOCAL_MACHINE);
  25. DbgPrint("User\n");
  26. DoTest((HANDLE)REG_LOCAL_USER);
  27. }
  28. VOID
  29. DoTest(
  30. HANDLE RootKey
  31. )
  32. {
  33. NTSTATUS rc;
  34. STRING String1;
  35. UCHAR Value1[] = "This string is value 1.";
  36. UCHAR Value2[] = "Value 2 is represented by this string.";
  37. HANDLE Handle1;
  38. HANDLE Handle2;
  39. ULONG ValueLength;
  40. ULONG Type;
  41. LARGE_INTEGER Time;
  42. //
  43. // Create parent node
  44. //
  45. DbgPrint("Part1\n");
  46. RtlInitString(&String1, "Test1");
  47. rc = NtCreateKey(
  48. RootKey,
  49. &String1,
  50. 0,
  51. NULL,
  52. GENERIC_READ|GENERIC_WRITE,
  53. &Handle1
  54. );
  55. if (!NT_SUCCESS(rc)) {
  56. DbgPrint("1:CreateKey failed rc = %08lx", rc);
  57. return;
  58. }
  59. //
  60. // Set data into parent
  61. //
  62. DbgPrint("Part2\n");
  63. rc = NtSetValueKey(
  64. Handle1,
  65. 1, // type
  66. Value1,
  67. strlen(Value1)
  68. );
  69. if (!NT_SUCCESS(rc)) {
  70. DbgPrint("2:SetValueKey failed rc = %08lx", rc);
  71. return;
  72. }
  73. //
  74. // Query and compare data from parent
  75. //
  76. DbgPrint("Part2b\n");
  77. ValueLength = MAX_VALUE;
  78. rc = NtQueryValueKey(
  79. Handle1,
  80. &Type,
  81. ValueBuffer,
  82. &ValueLength,
  83. &Time
  84. );
  85. if (!NT_SUCCESS(rc)) {
  86. DbgPrint("2b:QueryValueKey failed rc = %08lx", rc);
  87. return;
  88. }
  89. if (ValueLength != (ULONG)strlen(Value1)) {
  90. DbgPrint("2b1:Wrong value length\n");
  91. return;
  92. } else if (RtlCompareMemory(
  93. ValueBuffer, Value1, ValueLength) != ValueLength) {
  94. DbgPrint("2b2:Wrong value\n");
  95. return;
  96. } else if (Type != 1) {
  97. DbgPrint("2b3:Wrong type\n");
  98. return;
  99. }
  100. //
  101. // Close parent
  102. //
  103. DbgPrint("Part3\n");
  104. NtCloseKey(Handle1);
  105. if (!NT_SUCCESS(rc)) {
  106. DbgPrint("3:CloseKey failed rc = %08lx", rc);
  107. return;
  108. }
  109. //
  110. // Reopen parent
  111. //
  112. DbgPrint("Part4\n");
  113. rc = NtOpenKey(
  114. RootKey,
  115. &String1,
  116. 0,
  117. GENERIC_READ|GENERIC_WRITE,
  118. &Handle1
  119. );
  120. if (!NT_SUCCESS(rc)) {
  121. DbgPrint("4:OpenKey failed rc = %08lx", rc);
  122. return;
  123. }
  124. //
  125. // Create child
  126. //
  127. DbgPrint("Part5\n");
  128. RtlInitString(&String1, "Test2");
  129. rc = NtCreateKey(
  130. Handle1,
  131. &String1,
  132. 0,
  133. NULL,
  134. GENERIC_READ|GENERIC_WRITE,
  135. &Handle2
  136. );
  137. if (!NT_SUCCESS(rc)) {
  138. DbgPrint("5:CreateKey failed rc = %08lx", rc);
  139. return;
  140. }
  141. //
  142. // Set data into child
  143. //
  144. DbgPrint("Part6\n");
  145. rc = NtSetValueKey(
  146. Handle2,
  147. 2, // type
  148. Value2,
  149. strlen(Value2)
  150. );
  151. if (!NT_SUCCESS(rc)) {
  152. DbgPrint("6:SetValueKey failed rc = %08lx", rc);
  153. return;
  154. }
  155. //
  156. // Query and compare data from child
  157. //
  158. DbgPrint("Part7\n");
  159. ValueLength = MAX_VALUE;
  160. rc = NtQueryValueKey(
  161. Handle2,
  162. &Type,
  163. ValueBuffer,
  164. &ValueLength,
  165. &Time
  166. );
  167. if (!NT_SUCCESS(rc)) {
  168. DbgPrint("7:QueryValueKey failed rc = %08lx", rc);
  169. return;
  170. }
  171. if (ValueLength != (ULONG)strlen(Value2)) {
  172. DbgPrint("7.1:Wrong value length\n");
  173. return;
  174. } else if (RtlCompareMemory(
  175. ValueBuffer, Value2, ValueLength) != ValueLength) {
  176. DbgPrint("7.2:Wrong value\n");
  177. return;
  178. } else if (Type != 2) {
  179. DbgPrint("7.3:Wrong type\n");
  180. return;
  181. }
  182. //
  183. // Query and compare data from parent again
  184. //
  185. DbgPrint("Part8\n");
  186. ValueLength = MAX_VALUE;
  187. rc = NtQueryValueKey(
  188. Handle1,
  189. &Type,
  190. ValueBuffer,
  191. &ValueLength,
  192. &Time
  193. );
  194. if (!NT_SUCCESS(rc)) {
  195. DbgPrint("8:QueryValueKey failed rc = %08lx", rc);
  196. return;
  197. }
  198. if (ValueLength != (ULONG)strlen(Value1)) {
  199. DbgPrint("8.1:Wrong value length\n");
  200. return;
  201. } else if (RtlCompareMemory(
  202. ValueBuffer, Value1, ValueLength) != ValueLength) {
  203. DbgPrint("8.2:Wrong value\n");
  204. return;
  205. } else if (Type != 1) {
  206. DbgPrint("8.3:Wrong type\n");
  207. return;
  208. }
  209. //
  210. // Reset parent data
  211. //
  212. DbgPrint("Part9\n");
  213. rc = NtSetValueKey(
  214. Handle1,
  215. 1, // type
  216. Value2,
  217. strlen(Value2)
  218. );
  219. if (!NT_SUCCESS(rc)) {
  220. DbgPrint("9:SetValueKey failed rc = %08lx", rc);
  221. return;
  222. }
  223. //
  224. // Query and compare reset data
  225. //
  226. DbgPrint("Part10\n");
  227. ValueLength = MAX_VALUE;
  228. rc = NtQueryValueKey(
  229. Handle1,
  230. &Type,
  231. ValueBuffer,
  232. &ValueLength,
  233. &Time
  234. );
  235. if (!NT_SUCCESS(rc)) {
  236. DbgPrint("10:QueryValueKey failed rc = %08lx", rc);
  237. return;
  238. }
  239. if (ValueLength != (ULONG)strlen(Value2)) {
  240. DbgPrint("10.1:Wrong value length\n");
  241. return;
  242. } else if (RtlCompareMemory(
  243. ValueBuffer, Value2, ValueLength) != ValueLength) {
  244. DbgPrint("10.2:Wrong value\n");
  245. return;
  246. } else if (Type != 1) {
  247. DbgPrint("10.3:Wrong type\n");
  248. return;
  249. }
  250. //
  251. // Close off handles and return
  252. //
  253. DbgPrint("Part11\n");
  254. rc = NtCloseKey(Handle1);
  255. if (!NT_SUCCESS(rc)) {
  256. DbgPrint("11:CloseKey failed rc = %08lx", rc);
  257. return;
  258. }
  259. DbgPrint("Part12\n");
  260. rc = NtCloseKey(Handle2);
  261. if (!NT_SUCCESS(rc)) {
  262. DbgPrint("12:CloseKey failed rc = %08lx", rc);
  263. return;
  264. }
  265. return;
  266. }