/// <summary> /// Create a few test references for unit tests /// </summary> private void CreateTestReferences( out ComReferenceInfo axRefInfo, out ComReferenceInfo tlbRefInfo, out ComReferenceInfo piaRefInfo, out TYPELIBATTR axAttr, out TYPELIBATTR tlbAttr, out TYPELIBATTR piaAttr, out TYPELIBATTR notInProjectAttr) { // doing my part to deplete the worldwide guid reserves... Guid axGuid = Guid.NewGuid(); Guid tlbGuid = Guid.NewGuid(); Guid piaGuid = Guid.NewGuid(); // create reference task items TaskItem axTaskItem = CreateComReferenceTaskItem("axref", axGuid.ToString(), "1", "0", "1033", ComReferenceTypes.aximp); TaskItem tlbTaskItem = CreateComReferenceTaskItem("tlbref", tlbGuid.ToString(), "5", "1", "0", ComReferenceTypes.tlbimp); TaskItem piaTaskItem = CreateComReferenceTaskItem("piaref", piaGuid.ToString(), "999", "444", "123", ComReferenceTypes.primary); // create reference infos axRefInfo = CreateComReferenceInfo(axTaskItem, "AxRefLibName", "AxRefLibPath"); tlbRefInfo = CreateComReferenceInfo(tlbTaskItem, "TlbRefLibName", "TlbRefLibPath"); piaRefInfo = CreateComReferenceInfo(piaTaskItem, "PiaRefLibName", "PiaRefLibPath"); // get the references' typelib attributes axAttr = ResolveComReference.TaskItemToTypeLibAttr(axTaskItem); tlbAttr = ResolveComReference.TaskItemToTypeLibAttr(tlbTaskItem); piaAttr = ResolveComReference.TaskItemToTypeLibAttr(piaTaskItem); // create typelib attributes not matching any of the project refs notInProjectAttr = new TYPELIBATTR(); notInProjectAttr.guid = tlbGuid; notInProjectAttr.wMajorVerNum = 5; notInProjectAttr.wMinorVerNum = 1; notInProjectAttr.lcid = 1033; }
public void CheckAddMissingTlbReference() { TYPELIBATTR axAttr, tlbAttr, piaAttr, notInProjectAttr; ComReferenceInfo axRefInfo, tlbRefInfo, piaRefInfo; CreateTestReferences(out axRefInfo, out tlbRefInfo, out piaRefInfo, out axAttr, out tlbAttr, out piaAttr, out notInProjectAttr); var rcr = new ResolveComReference(); rcr.BuildEngine = new MockEngine(); // populate the ResolveComReference's list of project references rcr.allProjectRefs = new List <ComReferenceInfo>(); rcr.allProjectRefs.Add(axRefInfo); rcr.allProjectRefs.Add(tlbRefInfo); rcr.allProjectRefs.Add(piaRefInfo); rcr.AddMissingTlbReferences(); Assert.Equal(4, rcr.allProjectRefs.Count); // "There should be four references now" ComReferenceInfo newTlbInfo = (ComReferenceInfo)rcr.allProjectRefs[3]; Assert.Equal(axRefInfo.primaryOfAxImpRef, newTlbInfo); // "axRefInfo should hold back reference to tlbRefInfo" Assert.True(ComReference.AreTypeLibAttrEqual(newTlbInfo.attr, axRefInfo.attr)); // "The added reference should have the same attributes as the Ax reference" Assert.Equal(newTlbInfo.typeLibName, axRefInfo.typeLibName); // "The added reference should have the same type lib name as the Ax reference" Assert.Equal(newTlbInfo.strippedTypeLibPath, axRefInfo.strippedTypeLibPath); // "The added reference should have the same type lib path as the Ax reference" Assert.Equal(newTlbInfo.taskItem.ItemSpec, axRefInfo.taskItem.ItemSpec); // "The added reference should have the same task item spec as the Ax reference" Assert.Equal(newTlbInfo.taskItem.GetMetadata(ComReferenceItemMetadataNames.wrapperTool), ComReferenceTypes.primaryortlbimp); // "The added reference should have the tlbimp/primary wrapper tool" rcr.AddMissingTlbReferences(); Assert.Equal(4, rcr.allProjectRefs.Count); // "There should still be four references" }
public void TestCheckForConflictingReferences() { TYPELIBATTR axAttr, tlbAttr, piaAttr, notInProjectAttr; ComReferenceInfo axRefInfo, tlbRefInfo, piaRefInfo; CreateTestReferences(out axRefInfo, out tlbRefInfo, out piaRefInfo, out axAttr, out tlbAttr, out piaAttr, out notInProjectAttr); var rcr = new ResolveComReference(); rcr.BuildEngine = new MockEngine(); // populate the ResolveComReference's list of project references rcr.allProjectRefs = new List <ComReferenceInfo>(); rcr.allProjectRefs.Add(axRefInfo); rcr.allProjectRefs.Add(tlbRefInfo); rcr.allProjectRefs.Add(piaRefInfo); // no conflicts should be found with just the three initial refs Assert.True(rcr.CheckForConflictingReferences()); Assert.Equal(3, rcr.allProjectRefs.Count); ComReferenceInfo referenceInfo; // duplicate refs should not be treated as conflicts referenceInfo = new ComReferenceInfo(tlbRefInfo); rcr.allProjectRefs.Add(referenceInfo); referenceInfo = new ComReferenceInfo(axRefInfo); rcr.allProjectRefs.Add(referenceInfo); referenceInfo = new ComReferenceInfo(piaRefInfo); rcr.allProjectRefs.Add(referenceInfo); Assert.True(rcr.CheckForConflictingReferences()); Assert.Equal(6, rcr.allProjectRefs.Count); // tlb and ax refs with same lib name but different attributes should be considered conflicting // We don't care about typelib name conflicts for PIA refs, because we don't have to create wrappers for them var conflictTlb = new ComReferenceInfo(tlbRefInfo); conflictTlb.attr = notInProjectAttr; rcr.allProjectRefs.Add(conflictTlb); var conflictAx = new ComReferenceInfo(axRefInfo); conflictAx.attr = notInProjectAttr; rcr.allProjectRefs.Add(conflictAx); var piaRef = new ComReferenceInfo(piaRefInfo); piaRef.attr = notInProjectAttr; rcr.allProjectRefs.Add(piaRef); Assert.False(rcr.CheckForConflictingReferences()); // ... and conflicting references should have been removed Assert.Equal(7, rcr.allProjectRefs.Count); Assert.DoesNotContain(conflictTlb, rcr.allProjectRefs); Assert.DoesNotContain(conflictAx, rcr.allProjectRefs); Assert.Contains(piaRef, rcr.allProjectRefs); }
/// <summary> /// Helper function for creating a ComReferenceInfo object using an existing TaskInfo object and /// typelib name/path. The type lib pointer will obviously not be initialized, so this object cannot /// be used in any code that uses it. /// </summary> private ComReferenceInfo CreateComReferenceInfo(ITaskItem taskItem, string typeLibName, string typeLibPath) { var referenceInfo = new ComReferenceInfo(); referenceInfo.taskItem = taskItem; referenceInfo.attr = ResolveComReference.TaskItemToTypeLibAttr(taskItem); referenceInfo.typeLibName = typeLibName; referenceInfo.fullTypeLibPath = typeLibPath; referenceInfo.strippedTypeLibPath = typeLibPath; referenceInfo.typeLibPointer = null; return(referenceInfo); }
/// <summary> /// Helper method that will new up an AX and matching TLB reference, and verify that the AX reference /// sets its RCW appropriately. /// </summary> private void CheckAxReferenceRCWTlbExists(RcwStyle rcwStyle, bool includeVersionInInteropName) { Guid axGuid = Guid.NewGuid(); ComReferenceInfo tlbRefInfo; var rcr = new ResolveComReference(); rcr.BuildEngine = new MockEngine(); rcr.IncludeVersionInInteropName = includeVersionInInteropName; rcr.allProjectRefs = new List <ComReferenceInfo>(); TaskItem axTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.aximp); ComReferenceInfo axRefInfo = CreateComReferenceInfo(axTaskItem, "RefLibName", "RefLibPath"); rcr.allProjectRefs.Add(axRefInfo); switch (rcwStyle) { case RcwStyle.GenerateTlb: break; case RcwStyle.PreexistingTlb: { TaskItem tlbTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.tlbimp, "true"); tlbRefInfo = CreateComReferenceInfo(tlbTaskItem, "RefLibName", "RefLibPath"); rcr.allProjectRefs.Add(tlbRefInfo); break; } case RcwStyle.PreexistingPia: { TaskItem tlbTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.primary, "true"); tlbRefInfo = CreateComReferenceInfo(tlbTaskItem, "RefLibName", "RefLibPath"); rcr.allProjectRefs.Add(tlbRefInfo); break; } } rcr.AddMissingTlbReferences(); Assert.Equal(2, rcr.allProjectRefs.Count); // "Should be two references" tlbRefInfo = rcr.allProjectRefs[1]; var embedInteropTypes = tlbRefInfo.taskItem.GetMetadata(ItemMetadataNames.embedInteropTypes); Assert.Equal("false", embedInteropTypes); // "The tlb wrapper for the activex control should have EmbedInteropTypes=false not " + embedInteropTypes); Assert.True(ComReference.AreTypeLibAttrEqual(tlbRefInfo.attr, axRefInfo.attr)); // "reference information should be the same" Assert.Equal(TlbReference.GetWrapperFileName ( axRefInfo.taskItem.GetMetadata(ComReferenceItemMetadataNames.tlbReferenceName), includeVersionInInteropName, axRefInfo.attr.wMajorVerNum, axRefInfo.attr.wMinorVerNum ), TlbReference.GetWrapperFileName ( tlbRefInfo.typeLibName, includeVersionInInteropName, tlbRefInfo.attr.wMajorVerNum, tlbRefInfo.attr.wMinorVerNum )); // "Expected Ax reference's RCW name to match the new TLB" }