本文整理汇总了C++中Fail函数的典型用法代码示例。如果您正苦于以下问题:C++ Fail函数的具体用法?C++ Fail怎么用?C++ Fail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fail函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
{
Trace("CreateFileA: calling GetLastError() returned [%u] "
"while it should return [%u] for a bad file path name\n",
GetLastError(), ERROR_PATH_NOT_FOUND);
testPass = FALSE;
}
}
else
{
Trace("CreateFileA: managed to create a file with an incorrect "
"filename\n");
testPass = FALSE;
/*this should not happen*/
if(!CloseHandle(hFile))
{
Trace("CreateFileA: Call to CloseHandle Failed with ErrorCode "
"[%u]\n", GetLastError());
}
if(!DeleteFile(sBadFilePath))
{
Trace("CreateFileA: Call to DeleteFile Failed with ErrorCode "
"[%u]\n", GetLastError());
}
}
/*............. Test CreateFileW..................................*/
/* test with an invalid file name */
示例2: main
int __cdecl main(int argc, char *argv[])
{
int err;
WCHAR *wpBuffer = NULL;
char *pChar = NULL;
unsigned long ul = 1234567890UL;
char *pChar10 = "1234567890";
char *pChar2 = "1001001100101100000001011010010";
char *pChar16 = "499602d2";
/*Initialize the PAL environment*/
err = PAL_Initialize(argc, argv);
if(0 != err)
{
return FAIL;
}
wpBuffer = malloc(64 * sizeof(WCHAR));
if(NULL == wpBuffer)
{
Fail("\nFail to allocate the buffer to save a converted "
"wide character string, error code=%d!\n",
GetLastError());
}
/*convert to a 10 base string*/
_ui64tow(ul, wpBuffer, 10);
pChar = convertC(wpBuffer);
if(strcmp(pChar10, pChar))
{
free(wpBuffer);
free(pChar);
Fail("\nFailed to call _ui64tow API to convert an interger "
"to a 10 base wide character string, error code=%d\n",
GetLastError());
}
free(pChar);
free(wpBuffer);
wpBuffer = malloc(64 * sizeof(WCHAR));
if(NULL == wpBuffer)
{
Fail("\nFail to allocate the buffer to save a converted "
"wide character string, error code=%d!\n",
GetLastError());
}
/*convert to a 16 base string*/
_ui64tow(ul, wpBuffer, 16);
pChar = convertC(wpBuffer);
if(strcmp(pChar16, pChar))
{
free(wpBuffer);
free(pChar);
Fail("\nFailed to call _ui64tow API to convert an interger "
"to a 16 base wide character string, error code = %d\n",
GetLastError());
}
free(pChar);
free(wpBuffer);
wpBuffer = malloc(64 * sizeof(WCHAR));
if(NULL == wpBuffer)
{
Fail("\nFail to allocate the buffer to save a converted "
"wide character string, error code=%d!\n",
GetLastError());
}
/*convert to a 2 base string*/
_ui64tow(ul, wpBuffer, 2);
pChar = convertC(wpBuffer);
if(strcmp(pChar2, pChar))
{
free(wpBuffer);
free(pChar);
Fail("\nFailed to call _ui64tow API to convert an interger "
"to a 2 base wide character string, error code=%d\n",
GetLastError());
}
free(pChar);
free(wpBuffer);
PAL_Terminate();
return PASS;
}
示例3: Thread_Client
//.........这里部分代码省略.........
0,
WSA_FLAG_OVERLAPPED );
if( testSockets[0] == INVALID_SOCKET )
{
Trace("Client error: Unexpected failure: "
"WSASocketA"
"(AF_INET,SOCK_DGRAM,IPPROTO_UDP,NULL,0,WSA_FLAG_OVERLAPPED)) "
" returned %d\n",
GetLastError());
threadExitCode=THREAD_FAIL;
ExitThread(0);
}
/* enable non blocking socket */
argp=1;
err = ioctlsocket(testSockets[0], FIONBIO, (u_long FAR *)&argp);
if (err==SOCKET_ERROR )
{
Trace("ERROR: Unexpected failure: "
"ioctlsocket(.., FIONBIO, ..) "
"returned %d\n",
GetLastError() );
/* Do some cleanup */
DoWSATestCleanup( testSockets,
numSockets );
Fail("");
}
/* prepare the sockaddr_in structure */
mySockaddr.sin_family = AF_INET;
mySockaddr.sin_port = getRotorTestPort();
mySockaddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
memset( &(mySockaddr.sin_zero), 0, 8);
/* connect to a server */
err = connect( testSockets[0],
(struct sockaddr *)&mySockaddr,
sizeof(struct sockaddr));
if( err == SOCKET_ERROR )
{
Trace("Client error: Unexpected failure: "
"connect() socket with local server "
"returned %d\n",
GetLastError());
/* Do some cleanup */
CloseSocket( testSockets, numSockets );
threadExitCode=THREAD_FAIL;
ExitThread(0);
}
/* fill the sent buffer with value */
for (i=0;i<255;i++)
示例4: main
int __cdecl main(int argc, char **argv)
{
time_t LTime;
char *DateResult;
TIME_ZONE_INFORMATION tzInformation;
/*
* Initialize the PAL and return FAILURE if this fails
*/
if (PAL_Initialize(argc, argv))
{
return FAIL;
}
// Get the current timezone information
GetTimeZoneInformation(&tzInformation);
/*
* Test #1
*/
/* set the valid date in time_t format, adjusted for current time zone*/
LTime = VAL_SUN_JAN_17_2038 + (tzInformation.Bias * 60);
/* convert it to string using ctime*/
DateResult = ctime( <ime );
/* if it's null, ctime failed*/
if (DateResult == NULL)
{
Fail ("ERROR: (Test #1) ctime returned NULL. Expected string\n");
}
/* test if the entire string can ba access normaly */
if(IsBadReadPtr(DateResult, STR_TIME_SIZE)==0)
{
/* compare result with win2000 result */
if(strcmp( DateResult, STR_SUN_JAN_17_2038)!=0)
{
Fail("ERROR: (Test #1) ctime returned an unexpected string "
"%s, expexted string is %s\n"
,DateResult, STR_SUN_JAN_17_2038);
}
}
else
{
Fail ("ERROR: (Test #1) ctime returned a bad pointer.\n");
}
/*
* Test #2
*/
/* Set the valid date in time_t format, adjusted for current time zone */
LTime = VAL_FRI_JAN_02_1970 + (tzInformation.Bias * 60);
/* convert it to string using ctime */
DateResult = ctime( <ime );
/* if it's null, ctime failed*/
if (DateResult == NULL)
{
Fail ("ERROR: (Test #2) ctime returned NULL. Expected string\n");
}
/* test if the entire string can ba access normaly */
if(IsBadReadPtr(DateResult, STR_TIME_SIZE)==0)
{
/* compare result with win2000 result */
if (strcmp(DateResult, STR_FRI_JAN_02_1970) != 0
&& strcmp(DateResult, STR_FRI_JAN__2_1970) != 0)
{
Fail("ERROR: (Test #2) ctime returned an unexpected string "
"%s, expected string is %s\n"
,DateResult, STR_FRI_JAN_02_1970);
}
}
else
{
Fail ("ERROR: (Test #2) ctime returned a bad pointer.\n");
}
/*
* Test #3
*/
/* specify an invalid time */
LTime = -1;
/* try to convert it */
DateResult = ctime( <ime );
/* Check the result for errors, should fail in this case */
if (DateResult != NULL)
{
Fail ("ERROR: (Test #3) ctime returned something different from NULL.:"
//.........这里部分代码省略.........
示例5: main
int __cdecl main(int argc, char *argv[]) {
/* Define some buffers needed for the function */
char * pResultBuffer = NULL;
int size = 0;
/* A place to stash the returned values */
int ReturnValueForLargeBuffer = 0;
/*
* Initialize the PAL and return FAILURE if this fails
*/
if(0 != (PAL_Initialize(argc, argv)))
{
return FAIL;
}
/* Recieve and allocate the correct amount of memory for the buffer */
size = ReturnValueForLargeBuffer = GetEnvironmentVariable("PATH",
pResultBuffer,
0);
pResultBuffer = malloc(size);
if ( pResultBuffer == NULL )
{
Fail("ERROR: Failed to allocate memory for pResultBuffer pointer. "
"Can't properly exec test case without this.\n");
}
/* Normal case, PATH should fit into this buffer */
ReturnValueForLargeBuffer = GetEnvironmentVariable("PATH",
pResultBuffer,
size);
/* Ensure that it returned a positive value */
if(ReturnValueForLargeBuffer <= 0)
{
free(pResultBuffer);
Fail("The return was %d, which indicates that the function failed.\n",
ReturnValueForLargeBuffer);
}
/* Ensure that it succeeded and copied the correct number of characters.
If this is true, then the return value should be one less of the size of
the buffer. (Doesn't include that NULL byte)
*/
if(ReturnValueForLargeBuffer != size-1)
{
free(pResultBuffer);
Fail("The value returned was %d when it should have been %d. "
"This should be the number of characters copied, minus the "
"NULL byte.\n",ReturnValueForLargeBuffer, size-1);
}
free(pResultBuffer);
PAL_Terminate();
return PASS;
}
示例6: main
int __cdecl main(int argc, char *argv[])
{
FILE *tempFile = NULL;
BOOL bRc = FALSE;
WCHAR* pTemp = NULL;
if (0 != PAL_Initialize(argc,argv))
{
return FAIL;
}
//
// deleting an existing file
//
tempFile = fopen("testFile01.tmp", "w");
if (tempFile == NULL)
{
Fail ("DeleteFileW: ERROR: Couldn't create \"DeleteFileW's"
" testFile.tmp\"\n");
}
fprintf(tempFile, "DeleteFileW test file.\n");
fclose(tempFile);
pTemp = convert("testFile01.tmp");
bRc = DeleteFileW(pTemp);
free(pTemp);
if (bRc != TRUE)
{
Fail ("DeleteFileW: ERROR: Couldn't delete DeleteFileW's"
" \"testFile01.tmp\"\n");
}
//
// deleting a non-existant file : should fail
//
pTemp = convert("testFile02.tmp");
bRc = DeleteFileW(pTemp);
free(pTemp);
if (bRc != FALSE)
{
Fail ("DeleteFileW: ERROR: Was able to delete the non-existant"
" file \"testFile02.tmp\"\n");
}
//
// deleting an open file
//
tempFile = fopen("testFile03.tmp", "w");
if (tempFile == NULL)
{
Fail("DeleteFileW: ERROR: Couldn't create \"DeleteFileW's"
" testFile.tmp\"\n");
}
fprintf(tempFile, "DeleteFileW test file.\n");
fclose(tempFile);
pTemp = convert("testFile03.tmp");
bRc = DeleteFileW(pTemp);
if (bRc != TRUE)
{
Fail("DeleteFileW: ERROR: Couldn't delete DeleteFileW's"
" \"testFile01.tmp\"\n");
free(pTemp);
}
bRc = DeleteFileW(pTemp);
free(pTemp);
//
// delete using wild cards
//
// create the test file
tempFile = fopen("testFile04.tmp", "w");
if (tempFile == NULL)
{
Fail("DeleteFileW: ERROR: Couldn't create DeleteFileW's"
" \"testFile04.tmp\"\n");
}
fprintf(tempFile, "DeleteFileW test file.\n");
fclose(tempFile);
// delete using '?'
pTemp = convert("testFile0?.tmp");
bRc = DeleteFileW(pTemp);
free(pTemp);
if (bRc == TRUE)
{
Fail("DeleteFileW: ERROR: Was able to delete using the"
" \'?\' wildcard\n");
//.........这里部分代码省略.........
示例7: main
/**
* main
*
* executable entry point
*/
INT __cdecl main(INT argc, CHAR **argv)
{
int i;
int err;
struct sockaddr_in mySockaddr;
WSADATA wsaData;
HANDLE ReadEvent;
/* Sockets descriptor */
const int numSockets = 2; /* number of sockets used in this test */
SOCKET testSockets[2];
/* Variables needed for setsockopt */
BOOL bReuseAddr = TRUE;
/* Variables needed for WSARecv */
WSABUF wsaBuf[RECV_BUF_COUNT];
DWORD dwNbrOfBuf = RECV_BUF_COUNT;
DWORD dwNbrOfByteSent;
DWORD dwRecvFlags = 0;
WSAOVERLAPPED wsaOverlapped;
char myBuffer[RECV_BUF_SIZE];
int addrlen = sizeof(struct sockaddr);
/* Socket DLL version */
const WORD wVersionRequested = MAKEWORD(2,2);
/* Sockets initialization to INVALID_SOCKET */
for( i = 0; i < numSockets; i++ )
{
testSockets[i] = INVALID_SOCKET;
}
/* PAL initialization */
if( PAL_Initialize(argc, argv) != 0 )
{
return FAIL;
}
/* Initialize to use winsock2.dll */
err = WSAStartup(wVersionRequested,
&wsaData);
if(err != 0)
{
Fail( "ERROR: Unexpected failure: "
"WSAStartup(%i) "
"returned %d\n",
wVersionRequested,
GetLastError() );
}
/* Confirm that the WinSock DLL supports 2.2.
Note that if the DLL supports versions greater
than 2.2 in addition to 2.2, it will still return
2.2 in wVersion since that is the version we
requested.
*/
if ( wsaData.wVersion != wVersionRequested )
{
Trace("ERROR: Unexpected failure "
"to find a usable version of WinSock DLL\n");
/* Do some cleanup */
DoWSATestCleanup( testSockets,
numSockets );
Fail("");
}
/* create an overlapped UDP socket in AF_INET domain */
testSockets[0] = WSASocketA( AF_INET,
SOCK_DGRAM,
IPPROTO_UDP,
NULL,
0,
WSA_FLAG_OVERLAPPED );
if( testSockets[0] == INVALID_SOCKET )
{
Trace("ERROR: Unexpected failure: "
"WSASocketA"
"(AF_INET,SOCK_DGRAM,IPPROTO_UDP,NULL,0,WSA_FLAG_OVERLAPPED)) "
" returned %d\n",
GetLastError());
/* Do some cleanup */
//.........这里部分代码省略.........
示例8: main
int __cdecl main(int argc, char **argv)
{
SIZE_T i;
DWORD dwRetWFSO;
DWORD dwRetRT;
BOOL bRet = TRUE;
if(0 != (PAL_Initialize(argc, argv)))
{
return (FAIL);
}
/* set results array to FALSE */
for (i = 0; i < NUM_TESTS; i++)
{
bResult[i]=FALSE;
dwThreadId[i]=0;
}
for (i = 0; i < NUM_TESTS; i++)
{
if (NULL != testCases[i].lpThreadId)
{
testCases[i].lpThreadId = &dwThreadId[i];
}
/* pass the index as the thread argument */
hThread[i] = CreateThread( testCases[i].lpThreadAttributes,
testCases[i].dwStackSize,
testCases[i].lpStartAddress,
(LPVOID)i,
testCases[i].dwCreationFlags,
testCases[i].lpThreadId);
if (hThread[i] == NULL)
{
Trace("PALSUITE ERROR: CreateThread('%p' '%d' '%p' '%p' '%d' "
"'%p') call failed.\nGetLastError returned '%u'.\n",
testCases[i].lpThreadAttributes, testCases[i].dwStackSize,
testCases[i].lpStartAddress, (LPVOID)i,
testCases[i].dwCreationFlags,
testCases[i].lpThreadId, GetLastError());
cleanup(i - 1);
Fail("");
}
/* Resume suspended threads */
if (testCases[i].dwCreationFlags == CREATE_SUSPENDED)
{
dwRetRT = ResumeThread (hThread[i]);
if (dwRetRT != 1)
{
Trace ("PALSUITE ERROR: ResumeThread(%p) "
"call returned %d it should have returned %d.\n"
"GetLastError returned %u.\n", hThread[i], dwRetRT,
1, GetLastError());
cleanup(i);
Fail("");
}
}
}
/* cleanup */
for (i = 0; i < NUM_TESTS; i++)
{
dwRetWFSO = WaitForSingleObject(hThread[i], 10000);
if (dwRetWFSO != WAIT_OBJECT_0)
{
Trace ("PALSUITE ERROR: WaitForSingleObject('%p' '%d') "
"call returned %d instead of WAIT_OBJECT_0 ('%d').\n"
"GetLastError returned %u.\n", hThread[i], 10000,
dwRetWFSO, WAIT_OBJECT_0, GetLastError());
cleanup(i);
Fail("");
}
}
if(!cleanup(NUM_TESTS))
{
Fail("");
}
for (i = 0; i < NUM_TESTS; i++)
{
/*
* check to see that all threads were created and were passed
* the array index as an argument.
*/
if (FALSE == bResult[i])
{
bRet = FALSE;
Trace("PALSUITE ERROR: result[%d]=%d. It should be %d\n", i,
FALSE, TRUE);
}
/*
* check to see that lpThreadId received the correct value.
*/
if (0 != dwThreadId[i])
{
if (dwThreadId[i] != dwThreadId1[i])
{
bRet = FALSE;
Trace("PALSUITE ERROR: dwThreadId[%d]=%p and dwThreadId1[%d]"
//.........这里部分代码省略.........
示例9: main
int __cdecl main(int argc, char *argv[])
{
HANDLE FileMappingHandle;
HANDLE OpenFileMappingHandle;
HANDLE lpMapViewAddress;
HANDLE OpenFileMappingHandle2;
HANDLE lpMapViewAddress2;
const int LOWORDERSIZE = 1024;
char MapObject[] = "myMappingObject";
char buf[] = "this is a test";
char ch[1024];
int RetVal = PASS;
/* Initialize the PAL environment.
*/
if(0 != PAL_Initialize(argc, argv))
{
return FAIL;
}
/* Create a named file-mapping object with file handle FileHandle.
*/
FileMappingHandle = CreateFileMapping(
INVALID_HANDLE_VALUE,
NULL, /* not inherited */
PAGE_READWRITE, /* read and write */
0, /* high-order size */
LOWORDERSIZE, /* low-order size */
MapObject); /* named object */
if(NULL == FileMappingHandle)
{
Fail("\nFailed to call CreateFileMapping to create "
"a mapping object!\n");
}
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
Trace("\nFile mapping object already exists!\n");
RetVal = FAIL;
goto CleanUpOne;
}
/* Open a named file-mapping object with FILE_MAP_WRITE access.
*/
OpenFileMappingHandle = OpenFileMapping(
FILE_MAP_WRITE,
FALSE,
MapObject);
if(NULL == OpenFileMappingHandle)
{
Trace("\nFailed to Call OpenFileMapping API!\n");
RetVal = FAIL;
goto CleanUpOne;
}
/* Open a named file-mapping object with
* FILE_MAP_ALL_ACCESS access, to verify
* the FILE_MAP_WRITE access map.
*/
OpenFileMappingHandle2 = OpenFileMapping(
FILE_MAP_ALL_ACCESS,
FALSE,
MapObject);
if(NULL == OpenFileMappingHandle2)
{
Trace("\nFailed to Call OpenFileMapping API!\n");
RetVal = FAIL;
goto CleanUpTwo;
}
/* Create map view of the open mapping that has
* FILE_MAP_WRITE access.
*/
lpMapViewAddress = MapViewOfFile(
OpenFileMappingHandle,
FILE_MAP_WRITE, /* access code */
0, /* high order offset */
0, /* low order offset */
LOWORDERSIZE); /* number of bytes for map */
if(NULL == lpMapViewAddress)
{
Trace("ERROR:%u: Failed to call MapViewOfFile "
"API to map a view of file!\n",
GetLastError());
RetVal = FAIL;
goto CleanUpThree;
}
/* Create map view of the open mapping that has
* FILE_MAP_ALL_ACCESS access.
*/
lpMapViewAddress2 = MapViewOfFile(
OpenFileMappingHandle2,
FILE_MAP_ALL_ACCESS, /* access code */
0, /* high order offset */
//.........这里部分代码省略.........
示例10: CERT_NewTempCertificate
// We assume ext has been zero-initialized by its constructor and otherwise
// not modified.
//
// TODO(perf): This sorting of extensions should be be moved into the
// certificate decoder so that the results are cached with the certificate, so
// that the decoding doesn't have to happen more than once per cert.
Result
BackCert::Init(const SECItem& certDER)
{
// XXX: Currently-known uses of mozilla::pkix create CERTCertificate objects
// for all certs anyway, so the overhead of CERT_NewTempCertificate will be
// reduced to a lookup in NSS's SECItem* -> CERTCertificate cache and
// a CERT_DupCertificate. Eventually, we should parse the certificate using
// mozilla::pkix::der and avoid the need to create a CERTCertificate at all.
nssCert = CERT_NewTempCertificate(CERT_GetDefaultCertDB(),
const_cast<SECItem*>(&certDER),
nullptr, false, true);
if (!nssCert) {
return MapSECStatus(SECFailure);
}
const CERTCertExtension* const* exts = nssCert->extensions;
if (!exts) {
return Success;
}
// We only decode v3 extensions for v3 certificates for two reasons.
// 1. They make no sense in non-v3 certs
// 2. An invalid cert can embed a basic constraints extension and the
// check basic constrains will asume that this is valid. Making it
// posible to create chains with v1 and v2 intermediates with is
// not desirable.
if (! (nssCert->version.len == 1 &&
nssCert->version.data[0] == mozilla::pkix::der::Version::v3)) {
return Fail(RecoverableError, SEC_ERROR_EXTENSION_VALUE_INVALID);
}
const SECItem* dummyEncodedSubjectKeyIdentifier = nullptr;
const SECItem* dummyEncodedAuthorityKeyIdentifier = nullptr;
const SECItem* dummyEncodedAuthorityInfoAccess = nullptr;
const SECItem* dummyEncodedSubjectAltName = nullptr;
for (const CERTCertExtension* ext = *exts; ext; ext = *++exts) {
const SECItem** out = nullptr;
// python DottedOIDToCode.py id-ce 2.5.29
static const uint8_t id_ce[] = {
0x55, 0x1d
};
// python DottedOIDToCode.py id-pe-authorityInfoAccess 1.3.6.1.5.5.7.1.1
static const uint8_t id_pe_authorityInfoAccess[] = {
0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x01
};
if (ext->id.len == PR_ARRAY_SIZE(id_ce) + 1 &&
!memcmp(ext->id.data, id_ce, PR_ARRAY_SIZE(id_ce))) {
switch (ext->id.data[ext->id.len - 1]) {
case 14: out = &dummyEncodedSubjectKeyIdentifier; break; // bug 965136
case 15: out = &encodedKeyUsage; break;
case 17: out = &dummyEncodedSubjectAltName; break; // bug 970542
case 19: out = &encodedBasicConstraints; break;
case 30: out = &encodedNameConstraints; break;
case 32: out = &encodedCertificatePolicies; break;
case 35: out = &dummyEncodedAuthorityKeyIdentifier; break; // bug 965136
case 37: out = &encodedExtendedKeyUsage; break;
case 54: out = &encodedInhibitAnyPolicy; break; // Bug 989051
}
} else if (ext->id.len == PR_ARRAY_SIZE(id_pe_authorityInfoAccess) &&
!memcmp(ext->id.data, id_pe_authorityInfoAccess,
PR_ARRAY_SIZE(id_pe_authorityInfoAccess))) {
// We should remember the value of the encoded AIA extension here, but
// since our TrustDomain implementations get the OCSP URI using
// CERT_GetOCSPAuthorityInfoAccessLocation, we currently don't need to.
out = &dummyEncodedAuthorityInfoAccess;
}
// If this is an extension we don't understand and it's marked critical,
// we must reject this certificate.
// (The only valid explicit value of the critical flag is TRUE because
// it is defined as BOOLEAN DEFAULT FALSE, so we just assume it is true.)
if (!out && ext->critical.data && ext->critical.len > 0) {
return Fail(RecoverableError, SEC_ERROR_UNKNOWN_CRITICAL_EXTENSION);
}
if (out) {
// This is an extension we understand. Save it in results unless we've
// already found the extension previously.
if (*out) {
// Duplicate extension
return Fail(RecoverableError, SEC_ERROR_EXTENSION_VALUE_INVALID);
}
*out = &ext->value;
}
}
return Success;
}
示例11: main
int __cdecl main(int argc, char *argv[])
{
WORD VersionRequested = MAKEWORD(2,2);
WSADATA WsaData;
int err;
int socketID = INVALID_SOCKET;
const char *data = "None-zero length data test";
int nBuffer;
/*Initialize the PAL environment*/
err = PAL_Initialize(argc, argv);
if(0 != err)
{
return FAIL;
}
/*initialize to use winsock2.dll*/
err = WSAStartup(VersionRequested,&WsaData);
if ( err != 0 )
{
Fail("\nFailed to find a usable WinSock DLL!\n");
}
/*Confirm that the WinSock DLL supports 2.2.*/
if ( LOBYTE( WsaData.wVersion ) != 2 ||
HIBYTE( WsaData.wVersion ) != 2 )
{
Trace("\nFailed to find a usable WinSock DLL!\n");
err = WSACleanup();
if(SOCKET_ERROR == err)
{
Trace("\nFailed to call WSACleanup API!\n");
}
Fail("");
}
/*create a datagram socket in AF_INET domain*/
socketID = socket(AF_INET, SOCK_DGRAM, 0);
if(INVALID_SOCKET == socketID)
{
Trace("\nFailed to call socket API to creat a datagram socket!\n");
err = WSACleanup();
if(SOCKET_ERROR == err)
{
Trace("\nFailed to call WSACleanup API!\n");
}
Fail("");
}
nBuffer = strlen(data);
/*call send without calling bind*/
err = send(socketID, data, nBuffer, 0);
if(WSAENOTCONN != GetLastError() || SOCKET_ERROR != err)
{
Trace("\nFailed to call send API for a negative test, "
"call send without calling bind, an error "
"WSAENOTCONN is expected, but no error or no expected "
"error is detected, error code = %u\n",GetLastError());
err = closesocket(socketID);
if(SOCKET_ERROR == err)
{
Trace("\nFailed to call closesocket API!\n");
err = WSACleanup();
if(SOCKET_ERROR == err)
{
Trace("\nFailed to call WSACleanup API!\n");
}
Fail("");
}
err = WSACleanup();
if(SOCKET_ERROR == err)
{
Trace("\nFailed to call WSACleanup API!\n");
}
Fail("");
}
err = closesocket(socketID);
if(SOCKET_ERROR == err)
{
Trace("\nFailed to call closesocket API!\n");
err = WSACleanup();
if(SOCKET_ERROR == err)
{
Trace("\nFailed to call WSACleanup API!\n");
}
Fail("");
}
err = WSACleanup();
if(SOCKET_ERROR == err)
{
Fail("\nFailed to call WSACleanup API!\n");
}
PAL_Terminate();
//.........这里部分代码省略.........
示例12: BuildForward
// Recursively build the path from the given subject certificate to the root.
//
// Be very careful about changing the order of checks. The order is significant
// because it affects which error we return when a certificate or certificate
// chain has multiple problems. See the error ranking documentation in
// pkix/pkix.h.
static Result
BuildForward(TrustDomain& trustDomain,
BackCert& subject,
PRTime time,
EndEntityOrCA endEntityOrCA,
KeyUsages requiredKeyUsagesIfPresent,
KeyPurposeId requiredEKUIfPresent,
const CertPolicyId& requiredPolicy,
/*optional*/ const SECItem* stapledOCSPResponse,
unsigned int subCACount,
/*out*/ ScopedCERTCertList& results)
{
Result rv;
TrustLevel trustLevel;
// If this is an end-entity and not a trust anchor, we defer reporting
// any error found here until after attempting to find a valid chain.
// See the explanation of error prioritization in pkix.h.
rv = CheckIssuerIndependentProperties(trustDomain, subject, time,
endEntityOrCA,
requiredKeyUsagesIfPresent,
requiredEKUIfPresent, requiredPolicy,
subCACount, &trustLevel);
PRErrorCode deferredEndEntityError = 0;
if (rv != Success) {
if (endEntityOrCA == EndEntityOrCA::MustBeEndEntity &&
trustLevel != TrustLevel::TrustAnchor) {
deferredEndEntityError = PR_GetError();
} else {
return rv;
}
}
if (trustLevel == TrustLevel::TrustAnchor) {
// End of the recursion.
// Construct the results cert chain.
results = CERT_NewCertList();
if (!results) {
return MapSECStatus(SECFailure);
}
for (BackCert* cert = &subject; cert; cert = cert->childCert) {
CERTCertificate* dup = CERT_DupCertificate(cert->GetNSSCert());
if (CERT_AddCertToListHead(results.get(), dup) != SECSuccess) {
CERT_DestroyCertificate(dup);
return MapSECStatus(SECFailure);
}
// dup is now owned by results.
}
// This must be done here, after the chain is built but before any
// revocation checks have been done.
SECStatus srv = trustDomain.IsChainValid(results.get());
if (srv != SECSuccess) {
return MapSECStatus(srv);
}
return Success;
}
if (endEntityOrCA == EndEntityOrCA::MustBeCA) {
// Avoid stack overflows and poor performance by limiting cert chain
// length.
static const unsigned int MAX_SUBCA_COUNT = 6;
if (subCACount >= MAX_SUBCA_COUNT) {
return Fail(RecoverableError, SEC_ERROR_UNKNOWN_ISSUER);
}
++subCACount;
} else {
PR_ASSERT(subCACount == 0);
}
// Find a trusted issuer.
// TODO(bug 965136): Add SKI/AKI matching optimizations
ScopedCERTCertList candidates;
if (trustDomain.FindPotentialIssuers(&subject.GetNSSCert()->derIssuer, time,
candidates) != SECSuccess) {
return MapSECStatus(SECFailure);
}
if (!candidates) {
return Fail(RecoverableError, SEC_ERROR_UNKNOWN_ISSUER);
}
PRErrorCode errorToReturn = 0;
for (CERTCertListNode* n = CERT_LIST_HEAD(candidates);
!CERT_LIST_END(n, candidates); n = CERT_LIST_NEXT(n)) {
rv = BuildForwardInner(trustDomain, subject, time, requiredEKUIfPresent,
requiredPolicy, n->cert->derCert, subCACount,
results);
if (rv == Success) {
// If we found a valid chain but deferred reporting an error with the
// end-entity certificate, report it now.
if (deferredEndEntityError != 0) {
//.........这里部分代码省略.........
示例13: Launch
static int Launch()
{
Log(L"Launching browser...");
DWORD processID;
// The interface that allows us to activate the browser
CComPtr<IApplicationActivationManager> activateMgr;
if (FAILED(CoCreateInstance(CLSID_ApplicationActivationManager, nullptr,
CLSCTX_LOCAL_SERVER,
IID_IApplicationActivationManager,
(void**)&activateMgr))) {
Fail(false, L"CoCreateInstance CLSID_ApplicationActivationManager failed.");
return FAILURE;
}
HRESULT hr;
WCHAR appModelID[256];
// Activation is based on the browser's registered app model id
if (!GetDefaultBrowserAppModelID(appModelID, (sizeof(appModelID)/sizeof(WCHAR)))) {
Fail(false, L"GetDefaultBrowserAppModelID failed.");
return FAILURE;
}
Log(L"App model id='%s'", appModelID);
// Hand off focus rights if the terminal has focus to the out-of-process
// activation server (explorer.exe). Without this the metro interface
// won't launch.
hr = CoAllowSetForegroundWindow(activateMgr, nullptr);
if (FAILED(hr)) {
// Log but don't fail. This has happened on vms with certain terminals run by
// QA during mozmill testing.
Log(L"Windows focus rights hand off failed (HRESULT=0x%X). Ignoring.", hr);
}
Log(L"Harness process id: %d", GetCurrentProcessId());
// If provided, validate the firefox path passed in.
int binLen = wcslen(kFirefoxExe);
if (sFirefoxPath.GetLength() && sFirefoxPath.Right(binLen) != kFirefoxExe) {
Log(L"firefoxpath is missing a valid bin name! Assuming '%s'.", kFirefoxExe);
if (sFirefoxPath.Right(1) != L"\\") {
sFirefoxPath += L"\\";
}
sFirefoxPath += kFirefoxExe;
}
// Because we can't pass command line args, we store params in a
// tests.ini file in dist/bin which the browser picks up on launch.
CStringA testFilePath;
if (sFirefoxPath.GetLength()) {
// Use the firefoxpath passed to us by the test harness
int index = sFirefoxPath.ReverseFind('\\');
if (index == -1) {
Fail(false, L"Bad firefoxpath path");
return FAILURE;
}
testFilePath = sFirefoxPath.Mid(0, index);
testFilePath += "\\";
testFilePath += kMetroTestFile;
} else {
// Use the module path
char path[MAX_PATH];
if (!GetModuleFileNameA(nullptr, path, MAX_PATH)) {
Fail(false, L"GetModuleFileNameA errorno=%d", GetLastError());
return FAILURE;
}
char* slash = strrchr(path, '\\');
if (!slash)
return FAILURE;
*slash = '\0'; // no trailing slash
testFilePath = path;
testFilePath += "\\";
sFirefoxPath = testFilePath;
sFirefoxPath += kFirefoxExe;
testFilePath += kMetroTestFile;
}
// Make sure the firefox bin exists
if (GetFileAttributesW(sFirefoxPath) == INVALID_FILE_ATTRIBUTES) {
Fail(false, L"Invalid bin path: '%s'", sFirefoxPath);
return FAILURE;
}
Log(L"Using bin path: '%s'", sFirefoxPath);
Log(L"Writing out tests.ini to: '%s'", CStringW(testFilePath));
HANDLE hTestFile = CreateFileA(testFilePath, GENERIC_WRITE,
0, nullptr, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
nullptr);
if (hTestFile == INVALID_HANDLE_VALUE) {
Fail(false, L"CreateFileA errorno=%d", GetLastError());
return FAILURE;
}
DeleteTestFileHelper dtf(testFilePath);
// nsAppRunner expects the first param to be the bin path, just like a
// normal startup. So prepend our bin path to our param string we write.
//.........这里部分代码省略.........
示例14: main
int __cdecl main(int argc, char *argv[])
{
BOOL bRc = FALSE;
char szDirName[252];
DWORD curDirLen;
char *szTemp = NULL;
char *szTemp2 = NULL;
char szwCurrentDir[MAX_PATH];
char szwSubDir[MAX_PATH];
if (0 != PAL_Initialize(argc,argv))
{
return FAIL;
}
/*
* remove a NULL directory
*/
bRc = RemoveDirectoryA(NULL);
if (bRc != FALSE)
{
Fail("Error[%ul]:RemoveDirectoryA: Failed since it was able to remove a"
" NULL directory name\n", GetLastError());
}
/*
* remove a directory that does not exist
*/
szTemp = (char *) malloc (sizeof("test_directory"));
sprintf(szTemp, "test_directory");
bRc = RemoveDirectoryA(szTemp);
if (bRc != FALSE)
{
free(szTemp);
Fail("Error[%ul]:RemoveDirectoryA: Failed since it was able to remove"
" the non-existant directory \"test_directory\"\n", GetLastError());
}
/*
* remove a symlink to a directory
*/
bRc = CreateDirectoryA(szTemp, NULL);
if (bRc != TRUE)
{
free(szTemp);
Fail("Error[%ul]:RemoveDirectoryA: Failed to create the directory "
"\"test_directory\".\n", GetLastError());
}
char *szSymlinkName = (char *) malloc (sizeof("test_directory_symlink"));
sprintf(szSymlinkName, "test_directory_symlink");
if (symlink(szTemp, szSymlinkName) != 0)
{
Fail("Error:RemoveDirectoryA: Failed to create a symlink to the directory \"test_directory\".\n");
}
bRc = RemoveDirectoryA(szSymlinkName);
if (bRc != FALSE)
{
Fail("Error:RemoveDirectoryA: RemoveDirectoryA should return FALSE when passed a symlink.\n");
}
unlink(szSymlinkName);
/*
* remove a directory that exists
*/
bRc = RemoveDirectoryA(szTemp);
if (bRc == FALSE)
{
free(szTemp);
Fail("Error[%ul]:RemoveDirectoryW: Failed to remove the directory "
"\"test_directory\"\n",
GetLastError());
}
/* Make sure the directory was removed */
if( -1 != GetFileAttributesA(szTemp) )
{
free(szTemp);
Fail("Error[%ul]:RemoveDirectoryA: Able to get the attributes of "
"the removed directory\n" , GetLastError());
}
free(szTemp);
/*
* remove long directory names (245 characters)
*/
curDirLen = GetCurrentDirectoryA(0, NULL) + 1;
memset(szDirName, 0, 252);
memset(szDirName, 'a', 245 - curDirLen);
szTemp = (char *) malloc (sizeof(szDirName));
szTemp = strncpy(szTemp, szDirName, strlen(szDirName) + 1);
bRc = CreateDirectoryA(szTemp, NULL);
if (bRc == FALSE)
{
free(szTemp);
Fail("Error[%ul]:RemoveDirectoryA: Failed to create a directory name "
"245 chars long\n" , GetLastError());
}
//.........这里部分代码省略.........
示例15: main
int __cdecl main(int argc, char *argv[])
{
WORD VersionRequested = MAKEWORD(2, 2);
WSADATA WsaData;
int nLength;
int err;
int InvalidSocketID = -1;
struct sockaddr_in mySockaddr;
char data[BUFFERSIZE];
/*Initialize the PAL environment*/
err = PAL_Initialize(argc, argv);
if(0 != err)
{
return FAIL;
}
/*initialize to use winsock2 .dll*/
err = WSAStartup(VersionRequested, &WsaData);
if(err != 0)
{
Fail("\nFailed to find a usable WinSock DLL!\n");
}
/*Confirm that the WinSock DLL supports 2.2.*/
if(LOBYTE( WsaData.wVersion ) != 2 ||
HIBYTE( WsaData.wVersion ) != 2)
{
Trace("\nFailed to find a usable WinSock DLL!\n");
err = WSACleanup();
if(SOCKET_ERROR == err)
{
Trace("\nFailed to call WSACleanup API!\n");
}
Fail("");
}
nLength = sizeof(struct sockaddr);
memset(data, 0, BUFFERSIZE);
/*retrive data with an invalid socket*/
err = recvfrom(InvalidSocketID, data, BUFFERSIZE, 0,
(struct sockaddr*)&mySockaddr,&nLength);
if(WSAENOTSOCK != GetLastError() || SOCKET_ERROR != err)
{
Trace("\nFailed to call recvfrom API for a negative test "
"by passing an invalid socket descriptor!\n");
err = WSACleanup();
if(SOCKET_ERROR == err)
{
Trace("\nFailed to call WSACleanup API!\n");
}
Fail("");
}
err = WSACleanup();
if(SOCKET_ERROR == err)
{
Fail("\nFailed to call WSACleanup API!\n");
}
PAL_Terminate();
return PASS;
}