Esempio n. 1
0
    public bool PosTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest1: Ensure GetHashCode() successful.");
        Version TestVersion = null;

        try
        {
            for (int i = 0; i < 50; i++)
            {
                int intMajor = TestLibrary.Generator.GetInt32(-55);
                int intMinor = TestLibrary.Generator.GetInt32(-55);
                int intBuild = TestLibrary.Generator.GetInt32(-55);
                int intRevision = TestLibrary.Generator.GetInt32(-55);
                TestVersion = new Version(intMajor, intMinor, intBuild, intRevision);
                int accumulator = 0;
                accumulator |= (TestVersion.Major & 0x0000000F) << 28;
                accumulator |= (TestVersion.Minor & 0x000000FF) << 20;
                accumulator |= (TestVersion.Build & 0x000000FF) << 12;
                accumulator |= (TestVersion.Revision & 0x00000FFF);

                if (TestVersion.GetHashCode() != accumulator)
                {
                    TestLibrary.TestFramework.LogError("P01.1", "GetHashCode() failed!" + TestVersion.ToString());
                    retVal = false;
                    return retVal;
                }
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e + TestVersion.ToString());
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
Esempio n. 2
0
    public void TestGetHashCode()
    {
        var x = new Version(2, 3);
        var y = new Version(2, 3);
        Assert.Equal(x.GetHashCode(), y.GetHashCode());

        x = new Version(2, 3, 4);
        y = new Version(2, 3, 4);
        Assert.Equal(x.GetHashCode(), y.GetHashCode());

        x = new Version(2, 3, 4, 0x000E000F);
        y = new Version(2, 3, 4, 0x000E000F);
        Assert.Equal(x.GetHashCode(), y.GetHashCode());

        x = new Version(5, 5);
        y = new Version(5, 4);
        Assert.NotEqual(x.GetHashCode(), y.GetHashCode());

        x = new Version(10, 10, 10);
        y = new Version(10, 10, 2);
        Assert.NotEqual(x.GetHashCode(), y.GetHashCode());

        x = new Version(10, 10, 10, 10);
        y = new Version(10, 10, 10, 3);
        Assert.NotEqual(x.GetHashCode(), y.GetHashCode());

        x = new Version(10, 10, 10, 10);
        y = new Version(10, 10);
        Assert.NotEqual(x.GetHashCode(), y.GetHashCode());
    }
		public void HashCode ()
		{
			Version v1 = new Version ("1.2.3.4");
			Version v2 = new Version (1, 2, 3, 4);
			Assert.AreEqual (v1.GetHashCode (), v2.GetHashCode (), "HashCode");
		}
Esempio n. 4
0
        public static void TestEqualsGetHashCode(Assert assert)
        {
            assert.Expect(9);

            var v1 = new Version(100, 200, 300, (400 << 16) + 500);
            var v2 = new Version(100, 200, 300, (400 << 16) + 500);
            var v3 = new Version(101, 200, 300, (400 << 16) + 500);
            var o = new object();
            object o2 = v2;

            assert.Ok(v1.Equals(v2), "v1.Equals(v2)");
            assert.NotOk(v1.Equals(v3), "v1.Equals(v3)");
            assert.NotOk(v1.Equals(o), "v1.Equals(o)");
            assert.NotOk(v1.Equals(null), "v1.Equals(null)");
            assert.NotOk(v1.Equals(100), "v1.Equals(100)");
            assert.Ok(v1.Equals(o2), "v1.Equals(o2)");

            assert.Equal(v1.GetHashCode(), 1283637748, "v1.GetHashCode()");
            assert.Equal(v2.GetHashCode(), 1283637748, "v2.GetHashCode()");
            assert.Equal(v3.GetHashCode(), 1552073204, "v3.GetHashCode()");
        }
Esempio n. 5
0
 public override int GetHashCode()
 {
     // Note: purposely skipping publicKeyToken, processor architecture and culture as they
     // are less likely to make things not equal than name and version.
     return(m_name.GetHashCode() ^ m_version.GetHashCode());
 }
Esempio n. 6
0
        public static void TestEqualsGetHashCode()
        {
            var v1 = new Version(100, 200, 300, (400 << 16) + 500);
            var v2 = new Version(100, 200, 300, (400 << 16) + 500);
            var v3 = new Version(101, 200, 300, (400 << 16) + 500);
            var o = new object();
            object o2 = v2;

            Assert.True(v1.Equals(v2), "v1.Equals(v2)");
            Assert.False(v1.Equals(v3), "v1.Equals(v3)");
            Assert.False(v1.Equals(o), "v1.Equals(o)");
            Assert.False(v1.Equals(null), "v1.Equals(null)");
            Assert.False(v1.Equals(100), "v1.Equals(100)");
            Assert.True(v1.Equals(o2), "v1.Equals(o2)");

            Assert.AreEqual(v1.GetHashCode(), 1283637748, "v1.GetHashCode()");
            Assert.AreEqual(v2.GetHashCode(), 1283637748, "v2.GetHashCode()");
            Assert.AreEqual(v3.GetHashCode(), 1552073204, "v3.GetHashCode()");
        }
Esempio n. 7
0
        public static void Equals(Version version1, object obj, bool expected)
        {
            Version version2 = obj as Version;

            Assert.Equal(expected, version1.Equals(version2));
            Assert.Equal(expected, version1.Equals(obj));

            Assert.Equal(expected, version1 == version2);
            Assert.Equal(!expected, version1 != version2);

            if (version2 != null)
            {
                Assert.Equal(expected, version1.GetHashCode().Equals(version2.GetHashCode()));
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Calculates the product id.
 /// </summary>
 /// <param name="productGuid">The product GUID.</param>
 /// <param name="version">The version.</param>
 /// <returns></returns>
 public static Guid CalculateProductId(Guid productGuid, Version version)
 {
     return WixGuid.HashGuidByInteger(productGuid, version.GetHashCode() + 1);
 }
Esempio n. 9
0
 public override int GetHashCode()
 {
     return(version?.GetHashCode() ?? 0);
 }
Esempio n. 10
0
 // Override the Object.GetHashCode() method:
 public override int GetHashCode()
 {
     return(Version.GetHashCode());
 }
 public bool runTest()
   {
   Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   int iCountErrors = 0;
   int iCountTestcases = 0;
   try
     {
     Version vTest1 = new Version (5,5);
     Version vTest2 = new Version (5,4);
     strLoc = "Loc_100vy";
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_100aa! Expected==false");
       }
     strLoc = "Loc_300vy";
     vTest2 = new Version (5,5);
     iCountTestcases++;
     if (vTest1.GetHashCode() != vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_300aa! Expected==true");
       }
     vTest1 = new Version (10,10,10);
     vTest2 = new Version (10,10,2);
     strLoc = "Loc_400vy";
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_400aa! Expected==false");
       }
     strLoc = "Loc_600vy";
     vTest2 = new Version (10,10,10);
     iCountTestcases++;
     if (vTest1.GetHashCode() != vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_600aa! Expected==true");
       }
     vTest1 = new Version (550,500,2,7);
     vTest2 = new Version (550,500,2,5);
     strLoc = "Loc_700vy";
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_700aa! Expected==false");
       }
     strLoc = "Loc_600vy";
     vTest2 = new Version (550,500,2,7);
     iCountTestcases++;
     if (vTest1.GetHashCode() != vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_900aa! Expected==true");
       }
     strLoc = "Loc_100bb";
     vTest1 = new Version (550,500);
     vTest2 = new Version (550,500,2,7);
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_100xx! Expected==false");
       }
     strLoc = "Loc_110zz";
     vTest1 = new Version (Int32.MaxValue,500);
     vTest2 = new Version (550,500,2,0);
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_100xx! Expected==false");
       }
     strLoc = "Loc_120zz";
     vTest1 = new Version (5,5);
     vTest2 = new Version (5,5,0,0);
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_120xx! Expected==false value==" + vTest1.Equals(vTest2));
       }
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 )
     {
     Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
     return true;
     }
   else
     {
     Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }