test: rtvbatcr.c Source File

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

# rtvbatcr.c

Go to the documentation of this file.

    00001 /*++
    00002
    00003 Copyright (c) 1991  Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     rtvbatcr.c
    00008
    00009 Abstract:
    00010
    00011     NT level registry api test program, basic non-error paths.
    00012
    00013     Do a batch create, VOLATILE.  (Same as rtbatcr, but creates keys volatile.)
    00014
    00015     rtvbatcr    <KeyPath> <KeyName> <basename> <#children> <#values>
    00016
    00017     Will attempt to create key <KeyName> as child of <KeyPath>  If
    00018     <#children> and <#values> are 0, this is all it does.  If <KeyName>
    00019     already exists, it will simply be used.
    00020
    00021     Will create <#children> child cells, with names of the form
    00022     <base>0  <base>1, etc.  Will create <#values> value entries,
    00023     with similar names, for each created child key.  Data of
    00024     values will be a constant string including their name.
    00025
    00026     Example:
    00027
    00028         rtvbatcr    \REGISTRY\MACHINE\TEST bigkey runa_ 100 100
    00029         rtvbatcr    \REGISTRY\MACHINE\TEST\bigkey runa_1 runb_ 100 100
    00030
    00031         Will create bigkey, give it 100 values calls runa_1 through
    00032         runa_100, create 100 subkeys called runa_1 through runa_100
    00033         for each of those children.
    00034
    00035         It will then open bigkey\runa_1, and create 100 subkeys and
    00036         100 values each for that.
    00037
    00038 Author:
    00039
    00040     Bryan Willman (bryanwi)  10-Dec-91
    00041
    00042 Revision History:
    00043
    00044 --*/
    00045
    00046 #include "cmp.h"
    00047 #include <stdio.h>
    00048 #include <stdlib.h>
    00049 #include <string.h>
    00050
    00051 #define WORK_SIZE   1024
    00052
    00053 void __cdecl main(int, char *);
    00054 void processargs();
    00055
    00056 ULONG           failure = 0;
    00057
    00058 UNICODE_STRING  KeyPath;
    00059 UNICODE_STRING  KeyName;
    00060 ULONG           NumberChildren;
    00061 ULONG           NumberValues;
    00062 UCHAR           BaseName[WORK_SIZE];
    00063 UCHAR           formatbuffer[WORK_SIZE];
    00064 STRING          format;
    00065
    00066 UNICODE_STRING  WorkName;
    00067 WCHAR           workbuffer[WORK_SIZE];
    00068
    00069 void
    00070 __cdecl main(
    00071     int argc,
    00072     char *argv[]
    00073     )
    00074 {
    00075     NTSTATUS status;
    00076     OBJECT_ATTRIBUTES ObjectAttributes;
    00077     HANDLE          BaseHandle;
    00078     HANDLE          WorkHandle;
    00079     ULONG           Disposition;
    00080     UNICODE_STRING  ClassName;
    00081     ULONG           i;
    00082     ULONG           j;
    00083     PUCHAR  p;
    00084
    00085     //
    00086     // Process args
    00087     //
    00088
    00089     processargs(argc, argv);
    00090
    00091
    00092     //
    00093     // Set up and create/open KeyPath|KeyName
    00094     //
    00095
    00096     printf("rtvbatcr: starting\n");
    00097
    00098     WorkName.MaximumLength = WORK_SIZE;
    00099     WorkName.Length = 0L;
    00100     WorkName.Buffer = &(workbuffer[0]);
    00101
    00102     RtlCopyString((PSTRING)&WorkName, (PSTRING)&KeyPath);
    00103
    00104     p = WorkName.Buffer;
    00105     p += WorkName.Length;
    00106     *p = '\\';
    00107     p++;
    00108     *p = '\0';
    00109     WorkName.Length += 2;
    00110
    00111     RtlAppendStringToString((PSTRING)&WorkName, (PSTRING)&KeyName);
    00112
    00113     RtlInitUnicodeString(
    00114         &ClassName,
    00115         L"Test Class Name"
    00116         );
    00117
    00118     InitializeObjectAttributes(
    00119         &ObjectAttributes,
    00120         &WorkName,
    00121         0,
    00122         (HANDLE)NULL,
    00123         NULL
    00124         );
    00125     ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
    00126
    00127     status = NtCreateKey(
    00128                 &BaseHandle,
    00129                 MAXIMUM_ALLOWED,
    00130                 &ObjectAttributes,
    00131                 0,
    00132                 &ClassName,
    00133                 REG_OPTION_VOLATILE,
    00134                 &Disposition
    00135                 );
    00136     if (!NT_SUCCESS(status)) {
    00137         printf("rtvbatcr: t0: %08lx\n", status);
    00138         failure++;
    00139         goto punt;
    00140     }
    00141
    00142
    00143     //
    00144     // Create NumberChildren subkeys
    00145     //
    00146
    00147     for (i = 0; i < NumberChildren; i++) {
    00148
    00149         sprintf(formatbuffer, "%s%d", BaseName, i);
    00150         RtlInitString(&format, formatbuffer);
    00151         RtlAnsiStringToUnicodeString(&WorkName, &format, FALSE);
    00152
    00153
    00154         InitializeObjectAttributes(
    00155             &ObjectAttributes,
    00156             &WorkName,
    00157             0,
    00158             BaseHandle,
    00159             NULL
    00160             );
    00161         ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
    00162
    00163         status = NtCreateKey(
    00164                     &WorkHandle,
    00165                     MAXIMUM_ALLOWED,
    00166                     &ObjectAttributes,
    00167                     0,
    00168                     &ClassName,
    00169                     REG_OPTION_VOLATILE,
    00170                     &Disposition
    00171                     );
    00172         if (!NT_SUCCESS(status)) {
    00173             printf("rtvbatcr: t1: status = %08lx i = %d\n", status, i);
    00174             failure++;
    00175         }
    00176
    00177         //
    00178         // Create NumberValues value entries for each (current) key
    00179         //
    00180
    00181         for (j = 0; j < NumberValues; j++) {
    00182
    00183             sprintf(formatbuffer, "%s%d", BaseName, j);
    00184             RtlInitString(&format, formatbuffer);
    00185             RtlAnsiStringToUnicodeString(&WorkName, &format, FALSE);
    00186
    00187             sprintf(
    00188                 formatbuffer, "This is a rtvbatcr value for %s%d", BaseName, j
    00189                 );
    00190
    00191             status = NtSetValueKey(
    00192                         WorkHandle,
    00193                         &WorkName,
    00194                         j,
    00195                         j,
    00196                         formatbuffer,
    00197                         strlen(formatbuffer)+1
    00198                         );
    00199             if (!NT_SUCCESS(status)) {
    00200                 printf("rtvbatcr: t2: status = %08lx j = %d\n", status, j);
    00201                 failure++;
    00202             }
    00203         }
    00204         NtClose(WorkHandle);
    00205     }
    00206
    00207 punt:
    00208     printf("rtvbatcr: %d failures\n", failure);
    00209     exit(failure);
    00210 }
    00211
    00212
    00213 void
    00214 processargs(
    00215     int argc,
    00216     char *argv[]
    00217     )
    00218 {
    00219     ANSI_STRING temp;
    00220
    00221     if ( (argc != 3) && (argc != 6) )
    00222     {
    00223         printf("Usage: %s <KeyPath> <KeyName> [<basename> <#children> <#values>]\n",
    00224                 argv[0]);
    00225         exit(1);
    00226     }
    00227
    00228     RtlInitAnsiString(
    00229         &temp,
    00230         argv[1]
    00231         );
    00232
    00233     RtlAnsiStringToUnicodeString(
    00234         &KeyPath,
    00235         &temp,
    00236         TRUE
    00237         );
    00238
    00239     RtlInitAnsiString(
    00240         &temp,
    00241         argv[2]
    00242         );
    00243
    00244     RtlAnsiStringToUnicodeString(
    00245         &KeyName,
    00246         &temp,
    00247         TRUE
    00248         );
    00249
    00250     if (argc < 6) {
    00251
    00252         NumberChildren = 0;
    00253         NumberValues = 0;
    00254
    00255     } else {
    00256
    00257         strcpy(BaseName, argv[3]);
    00258         NumberChildren = atoi(argv[4]);
    00259         NumberValues = atoi(argv[5]);
    00260
    00261     }
    00262     return;
    00263 }