test: regtest.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# regtest.c

Go to the documentation of this file.

    00001 /*++
    00002
    00003 Copyright (c) 1991  Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     regtest.c
    00008
    00009 Abstract:
    00010
    00011    Test for quick and dirty registry test (very basic)
    00012
    00013 Author:
    00014
    00015     Bryan M. Willman (bryanwi) 30-Apr-1991
    00016
    00017 Environment:
    00018
    00019     User mode.
    00020
    00021 Revision History:
    00022
    00023 --*/
    00024
    00025 #include "stdio.h"
    00026 #include "nt.h"
    00027
    00028 int strlen(PUCHAR);
    00029 void main();
    00030
    00031 VOID DoTest(HANDLE RootKey);
    00032
    00033 #define MAX_VALUE   256
    00034 UCHAR ValueBuffer[MAX_VALUE];
    00035
    00036 VOID
    00037 main()
    00038 {
    00039     DbgPrint("Machine\n");
    00040     DoTest((HANDLE)REG_LOCAL_MACHINE);
    00041     DbgPrint("User\n");
    00042     DoTest((HANDLE)REG_LOCAL_USER);
    00043 }
    00044 VOID
    00045 DoTest(
    00046     HANDLE  RootKey
    00047     )
    00048 {
    00049     NTSTATUS rc;
    00050     STRING String1;
    00051     UCHAR Value1[] = "This string is value 1.";
    00052     UCHAR Value2[] = "Value 2 is represented by this string.";
    00053     HANDLE Handle1;
    00054     HANDLE Handle2;
    00055     ULONG ValueLength;
    00056     ULONG Type;
    00057     LARGE_INTEGER Time;
    00058
    00059     //
    00060     // Create parent node
    00061     //
    00062
    00063     DbgPrint("Part1\n");
    00064     RtlInitString(&String1,  "Test1");
    00065     rc = NtCreateKey(
    00066         RootKey,
    00067         &String1,
    00068         0,
    00069         NULL,
    00070         GENERIC_READ|GENERIC_WRITE,
    00071         &Handle1
    00072         );
    00073
    00074     if (!NT_SUCCESS(rc)) {
    00075         DbgPrint("1:CreateKey failed rc  = %08lx", rc);
    00076         return;
    00077     }
    00078
    00079     //
    00080     // Set data into parent
    00081     //
    00082
    00083     DbgPrint("Part2\n");
    00084     rc = NtSetValueKey(
    00085         Handle1,
    00086         1,              // type
    00087         Value1,
    00088         strlen(Value1)
    00089         );
    00090
    00091     if (!NT_SUCCESS(rc)) {
    00092         DbgPrint("2:SetValueKey failed rc  = %08lx", rc);
    00093         return;
    00094     }
    00095
    00096     //
    00097     // Query and compare data from parent
    00098     //
    00099
    00100     DbgPrint("Part2b\n");
    00101     ValueLength = MAX_VALUE;
    00102     rc = NtQueryValueKey(
    00103         Handle1,
    00104         &Type,
    00105         ValueBuffer,
    00106         &ValueLength,
    00107         &Time
    00108         );
    00109
    00110     if (!NT_SUCCESS(rc)) {
    00111         DbgPrint("2b:QueryValueKey failed rc  = %08lx", rc);
    00112         return;
    00113     }
    00114
    00115     if (ValueLength != (ULONG)strlen(Value1)) {
    00116         DbgPrint("2b1:Wrong value length\n");
    00117         return;
    00118     } else if (RtlCompareMemory(
    00119                 ValueBuffer, Value1, ValueLength) != ValueLength) {
    00120         DbgPrint("2b2:Wrong value\n");
    00121         return;
    00122     } else if (Type != 1) {
    00123         DbgPrint("2b3:Wrong type\n");
    00124         return;
    00125     }
    00126
    00127
    00128     //
    00129     // Close parent
    00130     //
    00131
    00132     DbgPrint("Part3\n");
    00133     NtCloseKey(Handle1);
    00134
    00135     if (!NT_SUCCESS(rc)) {
    00136         DbgPrint("3:CloseKey failed rc  = %08lx", rc);
    00137         return;
    00138     }
    00139
    00140
    00141     //
    00142     // Reopen parent
    00143     //
    00144
    00145     DbgPrint("Part4\n");
    00146     rc = NtOpenKey(
    00147         RootKey,
    00148         &String1,
    00149         0,
    00150         GENERIC_READ|GENERIC_WRITE,
    00151         &Handle1
    00152         );
    00153
    00154     if (!NT_SUCCESS(rc)) {
    00155         DbgPrint("4:OpenKey failed rc  = %08lx", rc);
    00156         return;
    00157     }
    00158
    00159     //
    00160     // Create child
    00161     //
    00162
    00163     DbgPrint("Part5\n");
    00164     RtlInitString(&String1,  "Test2");
    00165     rc = NtCreateKey(
    00166         Handle1,
    00167         &String1,
    00168         0,
    00169         NULL,
    00170         GENERIC_READ|GENERIC_WRITE,
    00171         &Handle2
    00172         );
    00173
    00174     if (!NT_SUCCESS(rc)) {
    00175         DbgPrint("5:CreateKey failed rc  = %08lx", rc);
    00176         return;
    00177     }
    00178
    00179
    00180     //
    00181     // Set data into child
    00182     //
    00183
    00184     DbgPrint("Part6\n");
    00185     rc = NtSetValueKey(
    00186         Handle2,
    00187         2,              // type
    00188         Value2,
    00189         strlen(Value2)
    00190         );
    00191
    00192     if (!NT_SUCCESS(rc)) {
    00193         DbgPrint("6:SetValueKey failed rc  = %08lx", rc);
    00194         return;
    00195     }
    00196
    00197
    00198     //
    00199     // Query and compare data from child
    00200     //
    00201
    00202     DbgPrint("Part7\n");
    00203     ValueLength = MAX_VALUE;
    00204     rc = NtQueryValueKey(
    00205         Handle2,
    00206         &Type,
    00207         ValueBuffer,
    00208         &ValueLength,
    00209         &Time
    00210         );
    00211
    00212     if (!NT_SUCCESS(rc)) {
    00213         DbgPrint("7:QueryValueKey failed rc  = %08lx", rc);
    00214         return;
    00215     }
    00216
    00217     if (ValueLength != (ULONG)strlen(Value2)) {
    00218         DbgPrint("7.1:Wrong value length\n");
    00219         return;
    00220     } else if (RtlCompareMemory(
    00221                 ValueBuffer, Value2, ValueLength) != ValueLength) {
    00222         DbgPrint("7.2:Wrong value\n");
    00223         return;
    00224     } else if (Type != 2) {
    00225         DbgPrint("7.3:Wrong type\n");
    00226         return;
    00227     }
    00228
    00229
    00230     //
    00231     // Query and compare data from parent again
    00232     //
    00233
    00234     DbgPrint("Part8\n");
    00235     ValueLength = MAX_VALUE;
    00236     rc = NtQueryValueKey(
    00237         Handle1,
    00238         &Type,
    00239         ValueBuffer,
    00240         &ValueLength,
    00241         &Time
    00242         );
    00243
    00244     if (!NT_SUCCESS(rc)) {
    00245         DbgPrint("8:QueryValueKey failed rc  = %08lx", rc);
    00246         return;
    00247     }
    00248
    00249     if (ValueLength != (ULONG)strlen(Value1)) {
    00250         DbgPrint("8.1:Wrong value length\n");
    00251         return;
    00252     } else if (RtlCompareMemory(
    00253                 ValueBuffer, Value1, ValueLength) != ValueLength) {
    00254         DbgPrint("8.2:Wrong value\n");
    00255         return;
    00256     } else if (Type != 1) {
    00257         DbgPrint("8.3:Wrong type\n");
    00258         return;
    00259     }
    00260
    00261
    00262     //
    00263     // Reset parent data
    00264     //
    00265
    00266     DbgPrint("Part9\n");
    00267     rc = NtSetValueKey(
    00268         Handle1,
    00269         1,              // type
    00270         Value2,
    00271         strlen(Value2)
    00272         );
    00273
    00274     if (!NT_SUCCESS(rc)) {
    00275         DbgPrint("9:SetValueKey failed rc  = %08lx", rc);
    00276         return;
    00277     }
    00278
    00279
    00280     //
    00281     // Query and compare reset data
    00282     //
    00283
    00284     DbgPrint("Part10\n");
    00285     ValueLength = MAX_VALUE;
    00286     rc = NtQueryValueKey(
    00287         Handle1,
    00288         &Type,
    00289         ValueBuffer,
    00290         &ValueLength,
    00291         &Time
    00292         );
    00293
    00294     if (!NT_SUCCESS(rc)) {
    00295         DbgPrint("10:QueryValueKey failed rc  = %08lx", rc);
    00296         return;
    00297     }
    00298
    00299     if (ValueLength != (ULONG)strlen(Value2)) {
    00300         DbgPrint("10.1:Wrong value length\n");
    00301         return;
    00302     } else if (RtlCompareMemory(
    00303                 ValueBuffer, Value2, ValueLength) != ValueLength) {
    00304         DbgPrint("10.2:Wrong value\n");
    00305         return;
    00306     } else if (Type != 1) {
    00307         DbgPrint("10.3:Wrong type\n");
    00308         return;
    00309     }
    00310
    00311     //
    00312     // Close off handles and return
    00313     //
    00314
    00315     DbgPrint("Part11\n");
    00316     rc = NtCloseKey(Handle1);
    00317
    00318     if (!NT_SUCCESS(rc)) {
    00319         DbgPrint("11:CloseKey failed rc  = %08lx", rc);
    00320         return;
    00321     }
    00322
    00323     DbgPrint("Part12\n");
    00324     rc = NtCloseKey(Handle2);
    00325     if (!NT_SUCCESS(rc)) {
    00326         DbgPrint("12:CloseKey failed rc  = %08lx", rc);
    00327         return;
    00328     }
    00329
    00330     return;
    00331 }