static MFTestResults TestStringValues() { bool bSuccess = true; string stringTest = "Hello World"; int stringLength1 = TestBasicTypes.String_GetLength("Hello World"); int stringLength2 = TestBasicTypes.String_GetLength(stringTest); if (stringLength1 != stringLength2 || stringLength1 != stringTest.Length) { Log.Comment("Error in String_GetLength: " + stringLength1 + " " + stringLength1 + "stringTest.Length is " + stringTest.Length); bSuccess = false; } else { Log.Comment("String_GetLength - succeeded\n"); } string strVersion = TestBasicTypes.GetVersion(); if (strVersion != "Interop Version 1.0") { Log.Comment("Error in GetVersion: " + strVersion + " should be \"Interop Version 1.0\""); bSuccess = false; } else { Log.Comment("GetVersion - succeeded\n"); } return(bSuccess ? MFTestResults.Pass : MFTestResults.Fail); }
static MFTestResults TestSignedValues() { bool bSuccess = true; // Declare parameters for test functions. char param1 = 'a'; sbyte param2 = 1; short param3 = 2; int param4 = 3; long param5 = 4; long correctVal = param1 + param2 + param3 + param4 + param5; long retVal = TestBasicTypes.Add_SignedIntegralValuesByRef(ref param1, ref param2, ref param3, ref param4, ref param5); if (correctVal != retVal) { Log.Comment("Error in Add_SignedIntegralValuesByRef - rRetVal is " + retVal + " Should be " + correctVal + "\n"); bSuccess = false; } else { Log.Comment("Add_SignedIntegralValuesByRef - succeeded\n"); } retVal = TestBasicTypes.Add_SignedIntegralValues('a', 1, 2, 3, 4); if (correctVal != retVal) { Log.Comment("Error in Add_SignedIntegralValues - rRetVal is " + retVal + " Should be " + correctVal + "\n"); bSuccess = false; } else { Log.Comment("Add_SignedIntegralValues - succeeded\n"); } // Circle data passed by reference in varialbles TestBasicTypes.Circle_SignedIntegralValues(ref param1, ref param2, ref param3, ref param4, ref param5); // Should be circular shifted data if (param1 != 1 || param2 != 2 || param3 != 3 || param4 != 4 || param5 != 'a') { Log.Comment("Error in Circle_SignedIntegralValues\n"); bSuccess = false; } else { Log.Comment("Circle_SignedIntegralValues - succeeded\n"); } return(bSuccess ? MFTestResults.Pass : MFTestResults.Fail); }
static MFTestResults TestArrayValues() { bool bSuccess = true; bool[] boolArray = new bool[4];// { true, true, false, true }; // Init boolean somehow to get 3 trues; boolArray[0] = boolArray[1] = boolArray[3] = true; boolArray[2] = false; byte[] byteArray = new byte[10]; long[] longArray = new long[10]; float[] floatArrray = new float[10]; double[] doubleArray = new double[10]; for (int i = 0; i < 10; i++) { byteArray[i] = (byte)i; longArray[i] = i * 10; floatArrray[i] = (float)(i * 2.5); doubleArray[i] = i * 3.5; } int retboolSum = TestBasicTypes.Add_Values_Array_Bool(boolArray); int retbyteSum = TestBasicTypes.Add_Values_Array_Byte(byteArray); int retlongSum = TestBasicTypes.Add_Values_Array_Int64(longArray); float retfloatSum = TestBasicTypes.Add_Values_Array_float(floatArrray); double retdoubleSum = TestBasicTypes.Add_Values_Array_double(doubleArray); if (retbyteSum != 45 || retlongSum != retbyteSum * 10 || retfloatSum != retbyteSum * 2.5 || retdoubleSum != retbyteSum * 3.5) { Log.Comment("Error in testing of arrays\n"); bSuccess = false; } else { Log.Comment("Testing of arrays succeded\n"); bSuccess = true; } return(bSuccess ? MFTestResults.Pass : MFTestResults.Fail); }
// Test that buffer of array does not move during compaction if fixed keyword applied. static MFTestResults TestCompactionForNotFixedArray() { bool retVal = true; // First we create objects and holes that keeps some space that could be used by compaction. // Small count so compaction does not happen. object[] arrayOfArrays = new object[10]; RunAllocations(arrayOfArrays); // This is the array that we expect to move in during compaction. int[] testNativeBuffer = new int[100]; // Fill it, so it is not optimized out for (int i = 0; i < testNativeBuffer.Length; i++) { testNativeBuffer[i] = i; } // Address before compaction uint addrBeforeCompaction = TestBasicTypes.Get_Buffer_Address_Array(testNativeBuffer); // Causes compaction. InitiateCompactoin(); // Address after compaction. uint addrAfterCompaction = TestBasicTypes.Get_Buffer_Address_Array(testNativeBuffer); // Should be different addresses. retVal = addrBeforeCompaction != addrAfterCompaction; if (retVal) { Log.Comment("Testing of buffer move during compaction succeeded"); } else { Log.Comment("Testing of fixed keyword failed"); } return(retVal ? MFTestResults.Pass : MFTestResults.Fail); }
static MFTestResults TestFloatPointValues() { bool bSuccess = true; float param0 = 0.1111F; float param1 = 1.1111F; double param2 = 3.3333; double param3 = 4.4444; double correctVal = param0 + param1 + param2 + param3; double retVal = TestBasicTypes.Add_FloatPointValues(param0, ref param1, param2, ref param3); if (!AreFloatValuesEqaul(correctVal, retVal)) { Log.Comment("Error in Add_FloatPointValues - rRetVal is " + retVal + " Should be " + correctVal + "\n"); bSuccess = false; } else { Log.Comment("Add_FloatPointValues - succeeded\n"); } // Exchange parameters and check if it works; TestBasicTypes.Circle_FloatPointValues(ref param1, ref param2); if (!AreFloatValuesEqaul(param1, 3.3333) || !AreFloatValuesEqaul(param2, 1.1111)) { Log.Comment("Error in Circle_FloatPointValues\n"); bSuccess = false; } else { Log.Comment("Circle_FloatPointValues - succeeded\n"); } return(bSuccess ? MFTestResults.Pass : MFTestResults.Fail); }
static MFTestResults TestUnsignedValues() { bool bSuccess = true; // Declare parameters for test functions. bool param1 = true; byte param2 = 1; ushort param3 = 2; uint param4 = 3; ulong param5 = 4; ulong correctVal = (param1 ? 1u : 0u) + param2 + param3 + param4 + param5; ulong retVal = (ulong)TestBasicTypes.Add_UnsignedIntegralValuesByRef( ref param1, ref param2, ref param3, ref param4, ref param5); if (correctVal != retVal) { Log.Comment("Error in Add_UnsignedIntegralValues by refecrence - rRetVal is " + retVal + " Should be " + correctVal + "\n"); bSuccess = false; } else { Log.Comment("Add_UnsignedIntegralValues by refecrence - succeeded\n"); } correctVal = (param1 ? 1u : 0u) + param2 + param3 + param4 + param5; retVal = TestBasicTypes.Add_UnsignedIntegralValues(true, 1, 2, 3, 4); // Tests passing of data from typed variables. The data type for param4 turns out to be different. ulong retVal1 = TestBasicTypes.Add_UnsignedIntegralValues(param1, param2, param3, param4, param5); if (correctVal != retVal || correctVal != retVal1) { Log.Comment("Error in Add_UnsignedIntegralValues - rRetVal is " + retVal + " Should be " + correctVal + "\n"); bSuccess = false; } else { Log.Comment("Add_UnsignedIntegralValues - succeeded\n"); } // Circle data passed by reference in varialbles TestBasicTypes.Circle_UnsignedIntegralValues(ref param1, ref param2, ref param3, ref param4, ref param5); // Should be circular shifted data if (param2 != 2 || param3 != 3 || param4 != 4 || param5 != 1) { Log.Comment("Error in Circle_SignedIntegralValues\n"); bSuccess = false; } else { Log.Comment("Circle_SignedIntegralValues - succeeded\n"); } return(bSuccess ? MFTestResults.Pass : MFTestResults.Fail); }
// Test that buffer of array actually moves during compaction. unsafe static MFTestResults TestCompactionForFixedArray() { bool retVal = true; // First we create objects and holes that keeps some space that could be used by compaction. // Small count so compaction does not happen. object[] arrayOfArrays = new object[10]; RunAllocations(arrayOfArrays); // This is the array that we expect to move in during compaction. int[] testNativeBuffer = new int[100]; // Fill it, so it is not optimized out for (int i = 0; i < testNativeBuffer.Length; i++) { testNativeBuffer[i] = i; } fixed(int *pFixedArray = testNativeBuffer) { // Address before compaction uint addrBeforeCompaction = TestBasicTypes.Get_Buffer_Address_Array(testNativeBuffer); // Causes compaction. InitiateCompactoin(); // Address after compaction. uint addrAfterCompaction = TestBasicTypes.Get_Buffer_Address_Array(testNativeBuffer); // Should be equal addresses, becuase array was pinned. retVal = addrBeforeCompaction == addrAfterCompaction; // Check that access to the buffer through the reference is the same as through array for (int i = 0; i < testNativeBuffer.Length; i++) { retVal = retVal && (pFixedArray[i] == testNativeBuffer[i]); } // Update the data of array through reference, then check that it was updated properly //Microsoft.SPOT.Math.Randomize(); for (int i = 0; i < testNativeBuffer.Length; i++) { int value = 2 * 500;//Microsoft.SPOT.Math.Random(0x7FFFFFFF); pFixedArray[i] = value; // Check that value is set properly and can be accessed through reference and array if (pFixedArray[i] != value || testNativeBuffer[i] != value) { retVal = false; } } // Test that access through *pFixedArray is the same as pFixedArray[0]; *pFixedArray = 2 * 400; //Microsoft.SPOT.Math.Random(0x7FFFFFFF); if (pFixedArray[0] != *pFixedArray || testNativeBuffer[0] != *pFixedArray) { retVal = false; } } // Since we exited "fixed" block, the testNativeBuffer is now movable. // It is very important to see that now buffer moves, this is the prove that it was unpinned. . uint addrBeforeCompaction1 = TestBasicTypes.Get_Buffer_Address_Array(testNativeBuffer); InitiateCompactoin(); uint addrAfterCompaction1 = TestBasicTypes.Get_Buffer_Address_Array(testNativeBuffer); // Verifies that now buffer moved. retVal = retVal && (addrBeforeCompaction1 != addrAfterCompaction1); if (retVal) { Log.Comment("Testing of fixed keyword succeded"); } else { Log.Comment("Testing of fixed keyword failed"); } return(retVal ? MFTestResults.Pass : MFTestResults.Fail); }