//////////
// #02 - Save the processed bxml file to disk (should match cgc_Test_Bxml_2_1 in Bxml_test2.h)
//////
bool iivvmt_testBxml_2(u64 lnHandleLog, SBxml* bxml)
{
    u64		lnBytesWritten, lnBytesRead, lnErrorOffset, lnErrorCode, lnSha1As64Bit;
    u32		lnSha1As32Bit;
    u8		sha20Bytes[20];
    s8*		lcFileOut;
    SBxml*	bxml2;


    // Tell which test we're running
    vvm_resourcePrintf(IDS_VVM_TEST_BXML_2);

    // Save the current state to see how she fared
    lcFileOut = oss_sharedAsciiGetTempFilename();
    if (!lcFileOut)
    {
        // Unable to allocate the temporary filename
        vvm_resourcePrintf(IDS_VVM_TEST_BXML_UNABLE_TO_GET_TEMP_FILE);
        vvm_resourcePrintf(IDS_VVM_TEST_FAIL);
        return(false);
    }

    // Save the file to disk
    vvm_bxmlSave(bxml, lcFileOut, sizeof(lcFileOut) - 1, true, true, &lnBytesWritten);

    // Try to read it back in, and compare the memory
    bxml2 = vvm_bxmlLoad(lcFileOut, strlen(lcFileOut), &lnBytesRead, &lnErrorOffset, &lnErrorCode);

    // Clean house
    oss_sharedAsciiDeleteFile(lcFileOut);
    oss_free(lcFileOut);

    // Did we read it back in correctly?
    if (!bxml2 || lnErrorCode != 0 || lnBytesRead != lnBytesWritten)
    {
        // Unable to load the temporary file back in correctly
        vvm_resourcePrintf(IDS_VVM_TEST_BXML_UNABLE_TO_RELOAD_TEMP_FILE);
        vvm_resourcePrintf(IDS_VVM_TEST_FAIL);
        return(false);
    }
    // If we get here, file was loaded properly

    // Grab the SHA-1 value from the loaded file
    lnSha1As64Bit	= vvm_bxmlNodeSha1(bxml2, sha20Bytes);
    lnSha1As32Bit	= vvm_sha1Compute32BitFromSha1(sha20Bytes);
    if (lnSha1As64Bit != cgnTestBxmlDotHNodeSha1As64Bit || lnSha1As32Bit != cgnTestBxmlDotHNodeSha1As32Bit)
    {
        // The file does not match the expected SHA-1 value
        vvm_resourcePrintf(IDS_VVM_TEST_BXML_RELOAD_DOES_NOT_MATCH);
        vvm_resourcePrintf(IDS_VVM_TEST_FAIL);
        return(false);
    }
    // If we get here, we're good, the re-loaded file matched the form with which it was
    // saved, and the SHA-1 validation upon reload indicated they were identical.
    // In short, it's time to do a little dance! Woo hoo! :-)

    // Delete the loaded node
    vvm_bxmlNodeDelete(bxml2, true);
    bxml2 = NULL;

    // If we get here, we're good
    vvm_resourcePrintf(IDS_VVM_TEST_PASS);
    return(true);
}
Example #2
0
	//////////
	// #02 - Create a canvas, load an image, validate SHA-1, scale it a couple times and validate SHA-1s
	//////
		bool iivvmt_testCanvas_2(u64 lnHandleLog)
		{
			s64			lnResult;
			u64			lnSha1As64Bit;
			u32			lnSha1As32Bit, lnWidth, lnHeight;
			u8			sha20Bytes[20];
			s8*			lcTemp;
			SCanvas*	canvas;
			SCanvas*	canvasScaled1;
			SCanvas*	canvasScaled2;


			// Tell which test we're running
			vvm_resourcePrintf(IDS_VVM_TEST_CANVAS_1);


			//////////
			// Create the standard canvas
			//////
				lcTemp = oss_sharedAsciiGetTempFilename();
				if (!oss_sharedAsciiWriteOutFile(lcTemp, (s8*)&cgc_Test2_Canvas[0], sizeof(cgc_Test2_Canvas)))
				{
					// Failure writing out the temp file
// TODO: localization here
					vvm_resourcePrintf(IDS_VVM_TEST_CANVAS_CANNOT_CREATE/*IDS_VVM_TEST_CANVAS_CANNOT_SAVE_TEST_BITMAP_TO_DISK*/);
					vvm_resourcePrintf(IDS_VVM_TEST_FAIL);
					return(false);
				}

				// Attempt to load it as a valid bitmap
				lnResult = (s64)oss_loadBitmapFromDisk(lcTemp, &canvas, &lnWidth, &lnHeight, rgba(0,0,0,255));

				// Delete the temp file
				oss_sharedAsciiDeleteFile(lcTemp);

				// Did the bitmap load okay?
				if (lnResult < 0 || !canvas)
				{
					// Failure creating the canvas
					vvm_resourcePrintf(IDS_VVM_TEST_CANVAS_CANNOT_CREATE);
					vvm_resourcePrintf(IDS_VVM_TEST_FAIL);
					return(false);
				}

				// For debugging:
				oss_saveBitmapToDisk(canvas, canvas->bd, "\\temp\\canvas2.bmp");


			//////////
			// Create a canvas for scaling
			//////
				canvasScaled1 = oss_requestCanvas(0, lnWidth - 1, lnHeight - 1, rgba(0,0,0,255), true, true);
				if (!canvasScaled1)
				{
					// Failure creating the canvas
					vvm_resourcePrintf(IDS_VVM_TEST_CANVAS_SCALED_CANNOT_CREATE);
					vvm_resourcePrintf(IDS_VVM_TEST_FAIL);
					return(false);
				}


			//////////
			// Create another canvas for scaling
			//////
				canvasScaled2 = oss_requestCanvas(0, lnWidth + 1, lnHeight + 1, rgba(0,0,0,255), true, true);
				if (!canvasScaled2)
				{
					// Failure creating the canvas
					vvm_resourcePrintf(IDS_VVM_TEST_CANVAS_SCALED_CANNOT_CREATE);
					vvm_resourcePrintf(IDS_VVM_TEST_FAIL);
					return(false);
				}


			//////////
			// Was it valid?
			//////
				oss_sha1ComputeSha1((s8*)canvas->bd, canvas->width * canvas->height * sizeof(SRGBA), sha20Bytes);
				lnSha1As64Bit = oss_sha1Compute64BitFromSha1(sha20Bytes);
				lnSha1As32Bit = oss_sha1Compute32BitFromSha1(sha20Bytes);
				if (lnSha1As64Bit != cgn_Test2_Canvas_Sha1As64Bit || lnSha1As32Bit != cgn_Test2_Canvas_Sha1As32Bit)
				{
					// The gradient does not match the expected SHA-1 value
					vvm_resourcePrintf(IDS_VVM_TEST_CANVAS_INVALID_GRADIENT);
					vvm_resourcePrintf(IDS_VVM_TEST_FAIL);
					return(false);
				}


			//////////
			// Scale the gradient
			//////
				oss_canvasScale(canvasScaled1, canvas);
				// For debugging:
				oss_saveBitmapToDisk(canvasScaled1, canvasScaled1->bd, "\\temp\\canvas2Scaled1.bmp");


			//////////
			// Was it valid?
			//////
				oss_sha1ComputeSha1((s8*)canvasScaled1->bd, canvasScaled1->width * canvasScaled1->height * sizeof(SRGBA), sha20Bytes);
				lnSha1As64Bit = oss_sha1Compute64BitFromSha1(sha20Bytes);
				lnSha1As32Bit = oss_sha1Compute32BitFromSha1(sha20Bytes);
				if (lnSha1As64Bit != cgn_Test2_CanvasScaled1_Sha1As64Bit || lnSha1As32Bit != cgn_Test2_CanvasScaled1_Sha1As32Bit)
				{
					// The gradient does not match the expected SHA-1 value
					vvm_resourcePrintf(IDS_VVM_TEST_CANVAS_SCALED_INVALID_GRADIENT);
					vvm_resourcePrintf(IDS_VVM_TEST_FAIL);
					return(false);
				}


			//////////
			// Scale the gradient
			//////
				oss_canvasScale(canvasScaled2, canvas);
				// For debugging:
				oss_saveBitmapToDisk(canvasScaled2, canvasScaled2->bd, "\\temp\\canvas2Scaled2.bmp");


			//////////
			// Was it valid?
			//////
				oss_sha1ComputeSha1((s8*)canvasScaled2->bd, canvasScaled2->width * canvasScaled2->height * sizeof(SRGBA), sha20Bytes);
				lnSha1As64Bit = oss_sha1Compute64BitFromSha1(sha20Bytes);
				lnSha1As32Bit = oss_sha1Compute32BitFromSha1(sha20Bytes);
				if (lnSha1As64Bit != cgn_Test2_CanvasScaled2_Sha1As64Bit || lnSha1As32Bit != cgn_Test2_CanvasScaled2_Sha1As32Bit)
				{
					// The gradient does not match the expected SHA-1 value
					vvm_resourcePrintf(IDS_VVM_TEST_CANVAS_SCALED_INVALID_GRADIENT);
					vvm_resourcePrintf(IDS_VVM_TEST_FAIL);
					return(false);
				}


			// If we get here, we're good
			vvm_resourcePrintf(IDS_VVM_TEST_PASS);
			return(true);
		}