/*++ Copyright (c) 1992 Microsoft Corporation Module Name: regtest.c Abstract: These are a few tests of the dos/win30 (/os2) registry apis. The syntax is: RegTest [/T|/Q|/S|/O|/C] [] depends on the first parm: /T - has no other parms (Test) /Q: /Q (Query) /S: /S (Set) /O /O (Open) /C /C (Create) If no parms are specified, /T is the default. Author: Dave Steckler (davidst) - 3/30/92 Revision History: --*/ #include #include #ifdef WIN #include #endif #include #include #include #include #define MAX_VALUE_LEN 128 #undef PAPI #ifdef WIN #define PAPI far #define strlen lstrlen // main() needs to be redefined for Windows (to not confuse the C7 linker) #define main c_main #else #define PAPI #define LONG long #define DWORD unsigned long #endif int main(int argc, char **argv); void UsageAndExit(void); void DoTest(void); void DoQuery( HKEY Key, char PAPI *pSubkey ); void DoSet( HKEY Key, char PAPI *pSubkey, char PAPI *pValue ); HKEY DoOpen( HKEY Key, char PAPI *pSubkey ); HKEY DoCreate( HKEY Key, char PAPI *pSubkey ); int main( int argc, char **argv ) { int ParmCount; if (argc == 1) { DoTest(); return 0; } for (--argc, ParmCount=1 ; argc ; argc--) { switch (argv[ParmCount][1]) { case 't': case 'T': DoTest(); return 0; case 'q': case 'Q': if (!argv[ParmCount+1]) { UsageAndExit(); } DoQuery( HKEY_CLASSES_ROOT, argv[ParmCount+1] ); return 0; case 's': case 'S': if (!argv[ParmCount+1] || !argv[ParmCount+2]) { UsageAndExit(); } DoSet( HKEY_CLASSES_ROOT, argv[ParmCount+1], argv[ParmCount+2] ); return 0; case 'o': case 'O': if (!argv[ParmCount+1]) { UsageAndExit(); } DoOpen( HKEY_CLASSES_ROOT, argv[ParmCount+1] ); return 0; case 'c': case 'C': if (!argv[ParmCount+1]) { UsageAndExit(); } DoCreate( HKEY_CLASSES_ROOT, argv[ParmCount+1] ); return 0; default: UsageAndExit(); } } printf("\n\n\001\001\001 - Test completed successfully!\n"); return 0; } void UsageAndExit( void ) { printf(" RegTest [/T|/Q|/S|/O|/C] []\n"); printf("\n"); printf(" depends on the first parm:\n"); printf("\n"); printf(" /T - has no other parms (Test)\n"); printf("\n"); printf(" /Q: /Q (Query)\n"); printf(" /S: /S (Set)\n"); printf(" /O /O (Open)\n"); printf(" /C /C (Create)\n"); printf("\n"); printf(" If no parms are specified, /T is the default. \n"); exit(1); } #define NUM_KEYS 20 char PAPI *ppKeyNameList[NUM_KEYS]= { "Row\\Row", "RowYourBoat", "Gently\\Down\\The\\Stream", "Merrily", "Merrily\\Merrily\\Merrily", "LifeIsBut", "A", "Dream\\One\\More\\Time", "Oh\\Theres\\A", "Hole", "In", "TheOzone", "OverMy", "Head", "And", "its", "Growing\\Bigger", "Every", "Day", "And\\Were\\All\\Going\\To\\GetSkin\\Cancer\\and\\die." }; HKEY KeyArray[NUM_KEYS]; void DoTest(void) { LONG Status; int i; static char String[256]; static char Value[128]; DWORD ValueLen; // // Add all the keys and set their values to their offset in the array. // for (i=0 ; i=0 ; i--) { if (KeyArray[i]) { ValueLen = 128; Status = RegQueryValue( KeyArray[i], NULL, Value, &ValueLen ); if (Status != ERROR_SUCCESS) { printf("*** Error %ld querying key %s.\n", *ppKeyNameList[i]); exit(1); } RpcItoa(i, String, 10); if (strcmp(String, Value) != 0) { printf("*** Error on key %s.\n", *ppKeyNameList[i]); printf(" Expected query value: %s. Actual %s.\n",String,Value); exit(1); } } } // // Now close all these keys. // for (i=0; i %ld (0x%lx).\n", Status, Status); } } void DoSet( HKEY Key, char PAPI *pSubkey, char PAPI *pValue ) { LONG Status; printf("SET: Setting value of %s to %s.\n", pSubkey, pValue); Status = RegSetValue( Key, pSubkey, REG_SZ, pValue, strlen(pValue)+1 ); if (Status != ERROR_SUCCESS) { printf("*** Set unsuccessful. RegSetValue -> %ld (0x%lx).\n", Status, Status); } } HKEY DoOpen( HKEY Key, char PAPI *pSubkey ) { LONG Status; HKEY ResultKey; printf("Open: Opening key %s.\n", pSubkey); Status = RegOpenKey( Key, pSubkey, &ResultKey ); if (Status == ERROR_SUCCESS) { return ResultKey; } else { printf("*** Open unsuccessful. RegOpenKey -> %ld (0x%lx).\n", Status, Status); return 0; } } HKEY DoCreate( HKEY Key, char PAPI *pSubkey ) { LONG Status; HKEY ResultKey; printf("Create: Creating key %s.\n", pSubkey); Status = RegCreateKey( Key, pSubkey, &ResultKey ); if (Status == ERROR_SUCCESS) { return ResultKey; } else { printf("*** Create unsuccessful. RegCreateKey -> %ld (0x%lx).\n", Status, Status); return 0; } } #ifdef WIN void __far I_RpcWinAssert(char __far *con, char __far *file, int line) { printf("Assertion failed: %s(%u) : %s\n", file, line, con); } #endif