private static void Test_StructValueSettingAsArg(FOS_System.String testName, EHCITestingStruct *rootPtr, byte *bRootPtr) { for (int i = 0; i < sizeof(EHCITestingStruct); i++) { bRootPtr[i] = 0; } rootPtr->u1 = 0xDEADBEEF; if (rootPtr->u1 != 0xDEADBEEF || bRootPtr[0] != 0xEF || bRootPtr[1] != 0xBE || bRootPtr[2] != 0xAD || bRootPtr[3] != 0xDE) { DBGERR(testName, "Getting/setting struct u1 failed!"); } rootPtr->u2 = 0x12345678; if (rootPtr->u1 != 0xDEADBEEF || bRootPtr[0] != 0xEF || bRootPtr[1] != 0xBE || bRootPtr[2] != 0xAD || bRootPtr[3] != 0xDE) { DBGERR(testName, "Getting/setting struct u2 failed! Affected u1 value."); } if (rootPtr->u2 != 0x12345678 || bRootPtr[4] != 0x78 || bRootPtr[5] != 0x56 || bRootPtr[6] != 0x34 || bRootPtr[7] != 0x12) { DBGERR(testName, "Getting/setting struct u2 failed!"); } rootPtr->u3 = 0xBEEFDEAD; if (rootPtr->u1 != 0xDEADBEEF || bRootPtr[0] != 0xEF || bRootPtr[1] != 0xBE || bRootPtr[2] != 0xAD || bRootPtr[3] != 0xDE) { DBGERR(testName, "Getting/setting struct u3 failed! Affected u1 value."); } if (rootPtr->u2 != 0x12345678 || bRootPtr[4] != 0x78 || bRootPtr[5] != 0x56 || bRootPtr[6] != 0x34 || bRootPtr[7] != 0x12) { DBGERR(testName, "Getting/setting struct u3 failed! Affected u2 value."); } if (rootPtr->u3 != 0xBEEFDEAD || bRootPtr[8] != 0xAD || bRootPtr[9] != 0xDE || bRootPtr[10] != 0xEF || bRootPtr[11] != 0xBE) { DBGERR(testName, "Getting/setting struct u3 failed!"); } rootPtr->u4 = 0x09876543; if (rootPtr->u1 != 0xDEADBEEF || bRootPtr[0] != 0xEF || bRootPtr[1] != 0xBE || bRootPtr[2] != 0xAD || bRootPtr[3] != 0xDE) { DBGERR(testName, "Getting/setting struct u4 failed! Affected u1 value."); } if (rootPtr->u2 != 0x12345678 || bRootPtr[4] != 0x78 || bRootPtr[5] != 0x56 || bRootPtr[6] != 0x34 || bRootPtr[7] != 0x12) { DBGERR(testName, "Getting/setting struct u4 failed! Affected u2 value."); } if (rootPtr->u3 != 0xBEEFDEAD || bRootPtr[8] != 0xAD || bRootPtr[9] != 0xDE || bRootPtr[10] != 0xEF || bRootPtr[11] != 0xBE) { DBGERR(testName, "Getting/setting struct u4 failed! Affected u3 value."); } if (rootPtr->u4 != 0x09876543 || bRootPtr[12] != 0x43 || bRootPtr[13] != 0x65 || bRootPtr[14] != 0x87 || bRootPtr[15] != 0x09) { DBGERR(testName, "Getting/setting struct u4 failed!"); } }
public static void Test_StructValueSetting() { FOS_System.String testName = "Strct Value Setting"; DBGMSG(testName, "START"); errors = 0; warnings = 0; uint structSize = (uint)sizeof(EHCITestingStruct); if (structSize != 8 * 4) { DBGERR(testName, ((FOS_System.String) "Struct size incorrect! structSize: ") + structSize); } if (errors == 0) { EHCITestingStruct *rootPtr = (EHCITestingStruct *)FOS_System.Heap.Alloc(structSize); byte *bRootPtr = (byte *)rootPtr; try { DBGMSG(testName, ((FOS_System.String) "rootPtr: ") + (uint)rootPtr); rootPtr->u1 = 0xDEADBEEF; if (rootPtr->u1 != 0xDEADBEEF || bRootPtr[0] != 0xEF || bRootPtr[1] != 0xBE || bRootPtr[2] != 0xAD || bRootPtr[3] != 0xDE) { DBGERR(testName, "Getting/setting struct u1 failed!"); } rootPtr->u2 = 0x12345678; if (rootPtr->u1 != 0xDEADBEEF || bRootPtr[0] != 0xEF || bRootPtr[1] != 0xBE || bRootPtr[2] != 0xAD || bRootPtr[3] != 0xDE) { DBGERR(testName, "Getting/setting struct u2 failed! Affected u1 value."); } if (rootPtr->u2 != 0x12345678 || bRootPtr[4] != 0x78 || bRootPtr[5] != 0x56 || bRootPtr[6] != 0x34 || bRootPtr[7] != 0x12) { DBGERR(testName, "Getting/setting struct u2 failed!"); } rootPtr->u3 = 0xBEEFDEAD; if (rootPtr->u1 != 0xDEADBEEF || bRootPtr[0] != 0xEF || bRootPtr[1] != 0xBE || bRootPtr[2] != 0xAD || bRootPtr[3] != 0xDE) { DBGERR(testName, "Getting/setting struct u3 failed! Affected u1 value."); } if (rootPtr->u2 != 0x12345678 || bRootPtr[4] != 0x78 || bRootPtr[5] != 0x56 || bRootPtr[6] != 0x34 || bRootPtr[7] != 0x12) { DBGERR(testName, "Getting/setting struct u3 failed! Affected u2 value."); } if (rootPtr->u3 != 0xBEEFDEAD || bRootPtr[8] != 0xAD || bRootPtr[9] != 0xDE || bRootPtr[10] != 0xEF || bRootPtr[11] != 0xBE) { DBGERR(testName, "Getting/setting struct u3 failed!"); } rootPtr->u4 = 0x09876543; if (rootPtr->u1 != 0xDEADBEEF || bRootPtr[0] != 0xEF || bRootPtr[1] != 0xBE || bRootPtr[2] != 0xAD || bRootPtr[3] != 0xDE) { DBGERR(testName, "Getting/setting struct u4 failed! Affected u1 value."); } if (rootPtr->u2 != 0x12345678 || bRootPtr[4] != 0x78 || bRootPtr[5] != 0x56 || bRootPtr[6] != 0x34 || bRootPtr[7] != 0x12) { DBGERR(testName, "Getting/setting struct u4 failed! Affected u2 value."); } if (rootPtr->u3 != 0xBEEFDEAD || bRootPtr[8] != 0xAD || bRootPtr[9] != 0xDE || bRootPtr[10] != 0xEF || bRootPtr[11] != 0xBE) { DBGERR(testName, "Getting/setting struct u4 failed! Affected u3 value."); } if (rootPtr->u4 != 0x09876543 || bRootPtr[12] != 0x43 || bRootPtr[13] != 0x65 || bRootPtr[14] != 0x87 || bRootPtr[15] != 0x09) { DBGERR(testName, "Getting/setting struct u4 failed!"); } Test_StructValueSettingAsArg("Strct Val Set by val", *rootPtr); Test_StructValueSettingAsArg("Strct Val Set by ptr", rootPtr, bRootPtr); } catch { errors++; BasicConsole.SetTextColour(BasicConsole.warning_colour); BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message); BasicConsole.SetTextColour(BasicConsole.default_colour); } finally { FOS_System.Heap.Free(rootPtr); } } if (errors > 0) { DBGERR(testName, ((FOS_System.String) "Test failed! Errors: ") + errors + " Warnings: " + warnings); } else { if (warnings > 0) { DBGWRN(testName, ((FOS_System.String) "Test passed with warnings: ") + warnings); } else { DBGMSG(testName, "Test passed."); } } DBGMSG(testName, "END"); BasicConsole.DelayOutput(1); }