static void DoUndef (void) /* Process the #undef directive */ { ident Ident; SkipWhitespace (0); if (MacName (Ident)) { UndefineMacro (Ident); } }
/* * Parse the /U option. */ static int parse_U( OPT_STRING **p ) /**********************************/ { char * str; p = p; CmdScanWhitespace(); str = CmdScanString(); if( str == NULL ) { FatalError( "/U requires an argument" ); return( 0 ); } UndefineMacro( str ); return( 1 ); }
void testDumpPolicy(void) { FILE* dumpFile; char dumpFileBuffer[MAX_DUMP_SIZE]; size_t numBytesRead; unlink(TEST_DUMP_FILE); /* Test DumpPolicy() with expandMacros=false */ { const char* expectedDumpResult = "===== Policy:\n" "OpenFile(\"${currentConfigFilePath}\", \"w\")\n" "RenameFile(\"${currentConfigFilePath}\", " "\"${currentConfigFilePath}.bak\")\n" "RemoveFile(\"${currentConfigFilePath}\")\n" "RemoveFile(\"${currentConfigFilePath}.bak\")\n" "OpenFile(\"${plannedConfigFilePath}\", \"w\")\n" "RenameFile(\"${plannedConfigFilePath}\", " "\"${plannedConfigFilePath}.bak\")\n" "RemoveFile(\"${plannedConfigFilePath}\")\n" "RemoveFile(\"${plannedConfigFilePath}.bak\")\n" "OpenFile(\"${passwordFilePath}\", \"w\")\n" "RenameFile(\"${passwordFilePath}.bak\", \"${passwordFilePath}\")\n" "RenameFile(\"${passwordFilePath}\", \"${passwordFilePath}.bak\")\n" "RemoveFile(\"${passwordFilePath}.bak\")\n" "RemoveFile(\"${passwordFilePath}\")\n" "OpenFile(\"${sslKeyFilePath}\", \"r\")\n" "OpenFile(\"${sslTrustStore}/*\", \"w\")\n" "RemoveFile(\"${sslTrustStore}/*\")\n" "OpenFile(\"${crlStore}/*\", \"w\")\n" "RemoveFile(\"${crlStore}/*\")\n" "RemoveFile(\"${localAuthDir}/*\")\n" "\n"; dumpFile = fopen(TEST_DUMP_FILE, "a"); PEGASUS_TEST_ASSERT(dumpFile != 0); DumpPolicy(dumpFile, 0); fclose(dumpFile); dumpFile = fopen(TEST_DUMP_FILE, "rb"); PEGASUS_TEST_ASSERT(dumpFile != 0); memset(dumpFileBuffer, 0, MAX_DUMP_SIZE); numBytesRead = fread(dumpFileBuffer, sizeof(char), MAX_DUMP_SIZE - 1, dumpFile); PEGASUS_TEST_ASSERT(numBytesRead != 0); fclose(dumpFile); PEGASUS_TEST_ASSERT(strcmp(dumpFileBuffer, expectedDumpResult) == 0); unlink(TEST_DUMP_FILE); } /* Test DumpPolicyHelper() with expandMacros=false */ { const char* expectedDumpResult = "Ping()\n" "RenameFile(\"${file1}\", \"${file2}\")\n" "RenameFile(\"file1\", \"${file2}\")\n" "RenameFile(\"file1\", \"file2\")\n"; dumpFile = fopen(TEST_DUMP_FILE, "a"); PEGASUS_TEST_ASSERT(dumpFile != 0); DumpPolicyHelper(dumpFile, _testPolicyTable, _testPolicyTableSize, 0); fclose(dumpFile); dumpFile = fopen(TEST_DUMP_FILE, "rb"); PEGASUS_TEST_ASSERT(dumpFile != 0); memset(dumpFileBuffer, 0, MAX_DUMP_SIZE); numBytesRead = fread(dumpFileBuffer, sizeof(char), MAX_DUMP_SIZE - 1, dumpFile); PEGASUS_TEST_ASSERT(numBytesRead != 0); fclose(dumpFile); PEGASUS_TEST_ASSERT(strcmp(dumpFileBuffer, expectedDumpResult) == 0); unlink(TEST_DUMP_FILE); } /* Test DumpPolicyHelper() with expandMacros=true */ { const char* expectedDumpResult = "Ping()\n" "RenameFile(\"MyFile1\", \"MyFile2\")\n" "RenameFile(\"file1\", \"MyFile2\")\n" "RenameFile(\"file1\", \"file2\")\n"; DefineMacro("file1", "MyFile1"); DefineMacro("file2", "MyFile2"); dumpFile = fopen(TEST_DUMP_FILE, "a"); PEGASUS_TEST_ASSERT(dumpFile != 0); DumpPolicyHelper(dumpFile, _testPolicyTable, _testPolicyTableSize, 1); fclose(dumpFile); UndefineMacro("file1"); UndefineMacro("file2"); dumpFile = fopen(TEST_DUMP_FILE, "rb"); PEGASUS_TEST_ASSERT(dumpFile != 0); memset(dumpFileBuffer, 0, MAX_DUMP_SIZE); numBytesRead = fread(dumpFileBuffer, sizeof(char), MAX_DUMP_SIZE - 1, dumpFile); PEGASUS_TEST_ASSERT(numBytesRead != 0); fclose(dumpFile); PEGASUS_TEST_ASSERT(strcmp(dumpFileBuffer, expectedDumpResult) == 0); unlink(TEST_DUMP_FILE); } }