Java 类com.sun.jna.platform.win32.Guid 实例源码

项目:ui-automation    文件:SelectionItem.java   
/**
 * Gets the selection container
 * @return The selection container
 * @throws AutomationException Something has gone wrong in automation
 */
public AutomationElement getSelectionContainer() throws AutomationException {
    PointerByReference pbr = new PointerByReference();

    final int res = this.getPattern().getCurrentSelectionContainer(pbr);
    if (res != 0) {
        throw new AutomationException(res);
    }

    Unknown unkConditionA = makeUnknown(pbr.getValue());
    PointerByReference pUnknownA = new PointerByReference();

    WinNT.HRESULT resultA = unkConditionA.QueryInterface(new Guid.REFIID(IUIAutomationElement.IID), pUnknownA);
    if (COMUtils.SUCCEEDED(resultA)) {
        return new AutomationElement(convertPointerToElementInterface(pUnknownA));
    } else {
        throw new AutomationException(resultA.intValue());
    }
}
项目:ui-automation    文件:Grid.java   
/**
 * Gets the element associated with the grid cell
 * @param x X position
 * @param y Y position
 * @return The Element from the grid
 * @throws AutomationException Something amiss with automation
 */
public AutomationElement getItem(int x, int y) throws AutomationException {
    PointerByReference cell = this.getRawItem(x, y);

    Unknown uRoot = makeUnknown(cell.getValue());

    PointerByReference pbr = new PointerByReference();

    WinNT.HRESULT result0 = uRoot.QueryInterface(new Guid.REFIID(IUIAutomationElement.IID), pbr);

    if (COMUtils.SUCCEEDED(result0)) {
        return new AutomationElement(convertPointerToElementInterface(pbr));
    } else {
        throw new AutomationException(result0.intValue());
    }
}
项目:ui-automation    文件:AutomationMainMenu.java   
/**
 * Gets the raw pattern from the given element.
 * @param item The Element
 * @return The raw collapse pattern
 * @throws AutomationException Failed to get pattern
 */
public IUIAutomationExpandCollapsePattern getExpandCollapsePatternFromItem(AutomationElement item)
                    throws AutomationException {
    PointerByReference pElement = item.getPattern(PatternID.ExpandCollapse.getValue());

    Unknown unkConditionA = makeUnknown(pElement.getValue());

    PointerByReference pUnknownA = new PointerByReference();

    WinNT.HRESULT resultA = unkConditionA.QueryInterface(new Guid.REFIID(IUIAutomationExpandCollapsePattern.IID), pUnknownA);
    if (COMUtils.SUCCEEDED(resultA)) {
        return IUIAutomationExpandCollapsePatternConverter.PointerToInterface(pUnknownA);
    } else {
        throw new AutomationException("QueryInterface failed");
    }
}
项目:ui-automation    文件:GridPatternTest.java   
@Test
@Ignore("Need to build up the mocking")
public void test_getItem_Throws_Exception_When_Pattern_Returns_Error_From_GetItem() throws Exception {
    Grid pattern = new Grid(rawPattern);

    Grid spyPattern = Mockito.spy(pattern);

    doAnswer(invocation -> new WinNT.HRESULT(0)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    IUIAutomationGridPattern mockGrid = Mockito.mock(IUIAutomationGridPattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    AutomationElement element = spyPattern.getItem(0,0);
}
项目:ui-automation    文件:UIAutomationTest.java   
@Test
public void testCreateFalseCondtion() {
    UIAutomation instance = UIAutomation.getInstance();

    try {
        PointerByReference condition = instance.createFalseCondition();

        Unknown unk = new Unknown(condition.getValue());

        PointerByReference pUnknown1 = new PointerByReference();

        WinNT.HRESULT result = unk.QueryInterface(new Guid.REFIID(IUIAutomationCondition.IID), pUnknown1);

        assertTrue("Create FalseCondition:" + COMUtils.SUCCEEDED(result), COMUtils.SUCCEEDED(result));
    } catch (AutomationException ex) {
        assertTrue("Ouch", false);
    }
}
项目:ui-automation    文件:UIAutomationTest.java   
@Test
public void testCreatePropertyCondition() {
    UIAutomation instance = UIAutomation.getInstance();

    Variant.VARIANT.ByValue variant = new Variant.VARIANT.ByValue();
    WTypes.BSTR sysAllocated = OleAuto.INSTANCE.SysAllocString("SOMETHING");
    variant.setValue(Variant.VT_BSTR, sysAllocated);

    try {
        try {
            PointerByReference pCondition = instance.createPropertyCondition(PropertyID.AutomationId.getValue(), variant);

            Unknown unk = new Unknown(pCondition.getValue());

            PointerByReference pUnknown1 = new PointerByReference();

            WinNT.HRESULT result = unk.QueryInterface(new Guid.REFIID(IUIAutomationCondition.IID), pUnknown1);

            assertTrue("CreatePropertyCondition:" + COMUtils.SUCCEEDED(result), COMUtils.SUCCEEDED(result));
        } catch (AutomationException ex) {
            assertTrue("Exception", false);
        }
    } finally {
        OleAuto.INSTANCE.SysFreeString(sysAllocated);
    }
}
项目:ui-automation    文件:UIAutomationTest.java   
@Test
public void testCreateTrueCondition() {
    UIAutomation instance = UIAutomation.getInstance();

    try {
        PointerByReference pCondition = instance.createTrueCondition();
        PointerByReference first = new PointerByReference();

        // Check whether it is a condition

        Unknown unk = new Unknown(pCondition.getValue());
        PointerByReference pUnk = new PointerByReference();

        Guid.REFIID refiid3 = new Guid.REFIID(IUIAutomationCondition.IID);

        PointerByReference pUnknown1 = new PointerByReference();

        WinNT.HRESULT result = unk.QueryInterface(refiid3, pUnknown1);

        assertTrue("Create TrueCondition:" + COMUtils.SUCCEEDED(result), COMUtils.SUCCEEDED(result));
    } catch (AutomationException ex) {
        assertTrue("Exception", false);
    }
}
项目:consulo-unity3d    文件:Unity3dPackageWatcher.java   
@Nullable
private static String getUnityUserPath()
{
    if(SystemInfo.isWinVistaOrNewer)
    {
        PointerByReference pointerByReference = new PointerByReference();
        WinNT.HRESULT hresult = Shell32.INSTANCE.SHGetKnownFolderPath(Guid.GUID.fromString("{A520A1A4-1780-4FF6-BD18-167343C5AF16}"), 0, null, pointerByReference);

        if(hresult.longValue() != 0)
        {
            return null;
        }
        return pointerByReference.getValue().getWideString(0) + "\\Unity";
    }
    else if(SystemInfo.isMac)
    {
        return SystemProperties.getUserHome() + "/Library/Unity";
    }
    else if(SystemInfo.isLinux)
    {
        return SystemProperties.getUserHome() + "/.config/unity3d";
    }

    return null;
}
项目:ui-automation    文件:Text.java   
/**
 * Gets the text from the pattern.
 *
 * @return The text.
 * @throws AutomationException Something has gone wrong
 */
public String getText() throws AutomationException {
    PointerByReference pbr = new PointerByReference();

    final int res = this.getPattern().getDocumentRange(pbr);
    if (res != 0) {
        throw new AutomationException(res);
    }

    Unknown unkConditionA = makeUnknown(pbr.getValue());
    PointerByReference pUnknownA = new PointerByReference();

    WinNT.HRESULT resultA = unkConditionA.QueryInterface(new Guid.REFIID(IUIAutomationTextRange.IID), pUnknownA);
    if (COMUtils.SUCCEEDED(resultA)) {
        IUIAutomationTextRange range = convertPointerToInterface(pUnknownA);

        PointerByReference sr = new PointerByReference();

        final int res1 = range.getText(-1, sr);
        if (res1 != 0) {
            throw new AutomationException(res1);
        }

        return sr.getValue().getWideString(0);
    } else {
        throw new AutomationException(resultA.intValue());
    }
}
项目:ui-automation    文件:BaseAutomation.java   
/**
 * Convert a raw PointerByReference to a IUIAutomationElement.
 *
 * @param pbr The raw pointer.
 * @return The IUIAutomationElement.
 * @throws AutomationException Automation library has thrown an error.
 */
public IUIAutomationElement getAutomationElementFromReference(final PointerByReference pbr)
        throws AutomationException {
    Unknown uElement = makeUnknown(pbr.getValue());

    WinNT.HRESULT result0 = uElement.QueryInterface(new Guid.REFIID(IUIAutomationElement.IID), pbr);

    if (COMUtils.FAILED(result0)) {
        throw new AutomationException(result0.intValue());
    }

    return IUIAutomationElementConverter.PointerToInterface(pbr);
}
项目:ui-automation    文件:BaseAutomation.java   
/**
 * Convert a raw PointerByReference to a IUIAutomationElementArray.
 * @param pbr The raw pointer.
 * @return The IUIAutomationElementArray.
 * @throws AutomationException Automation library has thrown an error.
 */
public IUIAutomationElementArray getAutomationElementArrayFromReference(final PointerByReference pbr)
        throws AutomationException {
    Unknown uElement = this.makeUnknown(pbr.getValue());
    PointerByReference pUnknown = new PointerByReference();

    WinNT.HRESULT result0 = uElement.QueryInterface(new Guid.REFIID(IUIAutomationElementArray.IID), pUnknown);

    if (COMUtils.FAILED(result0)) {
        throw new AutomationException(result0.intValue());
    }

    return IUIAutomationElementArrayConverter.PointerToInterface(pUnknown);
}
项目:ui-automation    文件:BaseAutomation.java   
/**
 * Turns a collection (array) of automation elements, into a collection.
 *
 * @param collection The ElementArray.
 * @return The List.
 * @throws AutomationException Error in the automation library.
 */
public List<AutomationElement> collectionToList(final IUIAutomationElementArray collection)
        throws AutomationException {

    IntByReference ibr = new IntByReference();

    final int res = collection.getLength(ibr);
    if (res != 0) {
        throw new AutomationException(res);
    }

    List<AutomationElement> list = new ArrayList<>();

    for (int count = 0; count < ibr.getValue(); count++) {

        PointerByReference pbr = new PointerByReference();

        final int res1 = collection.getElement(count, pbr);
        if (res1 != 0) {
            throw new AutomationException(res1);
        }

        Unknown uElement = new Unknown(pbr.getValue());

        WinNT.HRESULT result0 = uElement.QueryInterface(new Guid.REFIID(IUIAutomationElement.IID), pbr);

        if (COMUtils.SUCCEEDED(result0)) {
            IUIAutomationElement element =
                    IUIAutomationElementConverter.PointerToInterface(pbr);

            list.add(new AutomationElement(element));
        }
    }

    return list;
}
项目:ui-automation    文件:BaseAutomation.java   
/**
 * Gets the raw pointer to the element.
 *
 * @param element The underlying element.
 * @return Pointer The raw pointer.
 * @throws AutomationException An error has occurred in the automation library.
 */
protected Pointer getPointerFromElement(final IUIAutomationElement element)
        throws AutomationException {
    PointerByReference pElement = new PointerByReference();

    WinNT.HRESULT result1 = element.QueryInterface(new Guid.REFIID(IUIAutomationElement.IID), pElement);
    if (!COMUtils.SUCCEEDED(result1)) {
        throw new AutomationException(result1.intValue());
    }

    return pElement.getValue();
}
项目:ui-automation    文件:AutomationElement.java   
/**
 * Gets the IUIAutomationElement3 interface, if possible
 * @return The IUIAutomationElement3 interface
 * @throws AutomationException Not able to convert interface
 */
public final IUIAutomationElement3 getElement3() throws AutomationException {

    PointerByReference pUnknown = new PointerByReference();

    WinNT.HRESULT result = this.element.QueryInterface(
            new Guid.REFIID(IUIAutomationElement3.IID), pUnknown);

    if (COMUtils.SUCCEEDED(result)) {
        return IUIAutomationElement3Converter.PointerToInterface(pUnknown);
    }

    throw new AutomationException("Failed to convert to IUIAutomationElement6");
}
项目:ui-automation    文件:AutomationElement.java   
/**
 * Gets the IUIAutomationElement6 interface, if possible
 * @return The IUIAutomationElement6 interface
 * @throws AutomationException Not able to convert interface
 */
public final IUIAutomationElement6 getElement6() throws AutomationException {

    PointerByReference pUnknown = new PointerByReference();

    WinNT.HRESULT result = this.element.QueryInterface(
            new Guid.REFIID(IUIAutomationElement6.IID), pUnknown);

    if (COMUtils.SUCCEEDED(result)) {
        return IUIAutomationElement6Converter.PointerToInterface(pUnknown);
    }

    throw new AutomationException("Failed to convert to IUIAutomationElement6");
}
项目:ui-automation    文件:SelectionPatternTest.java   
@Test
@Ignore("Needs better tests")
public void test_That_getPattern_Gets_Pattern_When_No_Pattern_Set() throws Exception {
    doAnswer(invocation -> new WinNT.HRESULT(0)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Selection pattern = new Selection();

    Selection spyPattern = Mockito.spy(pattern);

    IUIAutomationSelectionPattern mockPattern = Mockito.mock(IUIAutomationSelectionPattern.class);

    IUIAutomationElementArray mockArray = Mockito.mock(IUIAutomationElementArray.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    doReturn(mockPattern)
            .when(spyPattern)
            .convertPointerToInterface(any());

    doReturn(mockArray)
            .when(spyPattern)
            .convertPointerToElementArray(any());

    spyPattern.getCurrentSelection();

    verify(spyPattern, atLeastOnce()).getCurrentSelection();
}
项目:ui-automation    文件:UIAutomationTest.java   
@Test
public void testCreateNotCondition() {
    UIAutomation instance = UIAutomation.getInstance();

    Variant.VARIANT.ByValue variant = new Variant.VARIANT.ByValue();
    WTypes.BSTR sysAllocated = OleAuto.INSTANCE.SysAllocString("SOMETHING");
    variant.setValue(Variant.VT_BSTR, sysAllocated);

    try {
        try {
            // Create first condition to use
            PointerByReference pCondition =
                    instance.createPropertyCondition(PropertyID.AutomationId.getValue(), variant);

            // Create the actual condition
            PointerByReference notCondition =
                    instance.createNotCondition(pCondition);

            // Checking
            Unknown unk = new Unknown(notCondition.getValue());

            PointerByReference pUnknown1 = new PointerByReference();

            WinNT.HRESULT result = unk.QueryInterface(new Guid.REFIID(IUIAutomationCondition.IID), pUnknown1);

            assertTrue("CreateNotCondition:" + COMUtils.SUCCEEDED(result), COMUtils.SUCCEEDED(result));
        } catch (AutomationException ex) {
            assertTrue("Exception", false);
        }
    } finally {
        OleAuto.INSTANCE.SysFreeString(sysAllocated);
    }
}
项目:ui-automation    文件:UIAutomationTest.java   
@Test
public void testCreateAndCondition() {
    UIAutomation instance = UIAutomation.getInstance();

    Variant.VARIANT.ByValue variant = new Variant.VARIANT.ByValue();
    WTypes.BSTR sysAllocated = OleAuto.INSTANCE.SysAllocString("SOMETHING");
    variant.setValue(Variant.VT_BSTR, sysAllocated);

    try {
        try {
            // Create first condition to use
            PointerByReference pCondition0 =
                    instance.createPropertyCondition(PropertyID.AutomationId.getValue(), variant);

            // Create first condition to use
            PointerByReference pCondition1 =
                    instance.createPropertyCondition(PropertyID.AutomationId.getValue(), variant);

            // Create the actual condition
            PointerByReference andCondition =
                    instance.createAndCondition(pCondition0, pCondition1);

            // Checking
            Unknown unk = new Unknown(andCondition.getValue());
            PointerByReference pUnk = new PointerByReference();

            PointerByReference pUnknown1 = new PointerByReference();

            WinNT.HRESULT result = unk.QueryInterface(new Guid.REFIID(IUIAutomationCondition.IID), pUnknown1);

            assertTrue("CreateAndCondition:" + COMUtils.SUCCEEDED(result), COMUtils.SUCCEEDED(result));
        } catch (AutomationException ex) {
            assertTrue("Exception", false);
        }
    } finally {
        OleAuto.INSTANCE.SysFreeString(sysAllocated);
    }
}
项目:ui-automation    文件:UIAutomationTest.java   
@Test
public void testCreateOrCondition() {
    UIAutomation instance = UIAutomation.getInstance();

    Variant.VARIANT.ByValue variant = new Variant.VARIANT.ByValue();
    WTypes.BSTR sysAllocated = OleAuto.INSTANCE.SysAllocString("SOMETHING");
    variant.setValue(Variant.VT_BSTR, sysAllocated);

    try {
        try {
            // Create first condition to use
            PointerByReference pCondition0 =
                    instance.createPropertyCondition(PropertyID.AutomationId.getValue(), variant);

            // Create first condition to use
            PointerByReference pCondition1 =
                    instance.createPropertyCondition(PropertyID.AutomationId.getValue(), variant);

            // Create the actual condition
            PointerByReference condition =
                    instance.createOrCondition(pCondition0, pCondition1);

            // Checking
            Unknown unk = new Unknown(condition.getValue());
            PointerByReference pUnk = new PointerByReference();

            PointerByReference pUnknown1 = new PointerByReference();

            WinNT.HRESULT result = unk.QueryInterface(new Guid.REFIID(IUIAutomationCondition.IID), pUnknown1);

            assertTrue("CreateOrCondition:" + COMUtils.SUCCEEDED(result), COMUtils.SUCCEEDED(result));
        } catch (AutomationException ex) {
            assertTrue("Exception", false);
        }
    } finally {
        OleAuto.INSTANCE.SysFreeString(sysAllocated);
    }
}
项目:ui-automation    文件:BasePattern.java   
/**
 * Gets the raw pointer to the pattern.
 * @param pbr The raw pointer
 * @return Result of the call from the COM library
 */
public WinNT.HRESULT getRawPatternPointer(
        final PointerByReference pbr) {
    Unknown uElement = makeUnknown(this.pattern);
    return uElement.QueryInterface(new Guid.REFIID(this.IID), pbr);
}
项目:ui-automation    文件:Text.java   
/**
 * Gets the selection.
 *
 * @return String of the selection
 * @throws AutomationException Something has gone wrong
 */
public String getSelection() throws AutomationException {
    PointerByReference pbr = new PointerByReference();

    final int res = this.getPattern().getSelection(pbr);
    if (res != 0) {
        throw new AutomationException(res);
    }

    Unknown unkConditionA = makeUnknown(pbr.getValue());
    PointerByReference pUnknownA = new PointerByReference();

    String selectionResult = "";

    WinNT.HRESULT resultA = unkConditionA.QueryInterface(new Guid.REFIID(IUIAutomationTextRangeArray.IID), pUnknownA);
    if (COMUtils.SUCCEEDED(resultA)) {
        IUIAutomationTextRangeArray selection =
                convertPointerToArrayInterface(pUnknownA);

        // OK, now what?
        IntByReference ibr = new IntByReference();
        final int res1 = selection.getLength(ibr);
        if (res1 != 0) {
            throw new AutomationException(res1);
        }

        int count = ibr.getValue();

        for (int i = 0; i < count; i++) {
            PointerByReference pbr0 = new PointerByReference();

            final int res2 = selection.getElement(i, pbr0);
            if (res2 != 0) {
                throw new AutomationException(res2);
            }

            Unknown unknown = makeUnknown(pbr0.getValue());
            PointerByReference pUnknown = new PointerByReference();

            WinNT.HRESULT result = unknown.QueryInterface(new Guid.REFIID(IUIAutomationTextRange.IID), pUnknown);
            if (COMUtils.SUCCEEDED(result)) {
                IUIAutomationTextRange range =
                        convertPointerToInterface(pUnknown);

                PointerByReference sr = new PointerByReference();

                final int res3 = range.getText(-1, sr);
                if (res3 != 0) {
                    throw new AutomationException(res3);
                }

                selectionResult = sr.getValue().getWideString(0);
            } else {
                throw new AutomationException(result.intValue());
            }
        }
    } else {
        throw new AutomationException(resultA.intValue());
    }

    return selectionResult;
}
项目:ui-automation    文件:GridPatternTest.java   
@Test(expected=AutomationException.class)
public void test_That_getPattern_Throws_Exception_When_Pattern_Returns_Error() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Grid pattern = new Grid();

    Grid spyPattern = Mockito.spy(new Grid());

    IUIAutomationGridPattern mockGrid = Mockito.mock(IUIAutomationGridPattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    spyPattern.getItem(0,0);

    verify(mockGrid, atLeastOnce()).getItem(any(), any(),any());
}
项目:ui-automation    文件:TogglePatternTest.java   
@Test(expected=AutomationException.class)
public void test_That_getPattern_Throws_Exception_When_Pattern_Returns_Error() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Toggle pattern = new Toggle();

    Toggle spyPattern = Mockito.spy(new Toggle());

    IUIAutomationTogglePattern mockRange = Mockito.mock(IUIAutomationTogglePattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    spyPattern.toggle();

    verify(spyPattern, atLeastOnce()).toggle();
}
项目:ui-automation    文件:TogglePatternTest.java   
@Test
public void test_That_getPattern_Gets_Pattern_When_No_Pattern_Set() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Toggle pattern = new Toggle();

    Toggle spyPattern = Mockito.spy(new Toggle());

    IUIAutomationTogglePattern mockRange = Mockito.mock(IUIAutomationTogglePattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    doReturn(mockRange)
            .when(spyPattern)
            .convertPointerToInterface(any());

    spyPattern.toggle();

    verify(spyPattern, atLeastOnce()).toggle();
}
项目:ui-automation    文件:TextPatternTest.java   
@Test(expected=AutomationException.class)
public void test_GetSelection_Throws_Exception_When_GetRange_Length_Fails() throws Exception {
    doAnswer(invocation -> 0).when(rawPattern).getSelection(any());

    doAnswer(invocation -> new WinNT.HRESULT(0)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Text pattern = new Text(rawPattern);

    Text spyPattern = Mockito.spy(new Text(rawPattern));

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    IUIAutomationTextRangeArray mockRangeArray = Mockito.mock(IUIAutomationTextRangeArray.class);

    doAnswer(invocation -> 1).when(mockRangeArray).getLength(any());

    doReturn(mockRangeArray)
            .when(spyPattern)
            .convertPointerToArrayInterface(any());

    String text = spyPattern.getSelection();

    assertTrue(text.equals(""));
}
项目:ui-automation    文件:TextPatternTest.java   
@Test(expected=AutomationException.class)
public void test_GetText_Throws_Exception_When_QueryInterface_Returns_Error() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Text pattern = new Text(rawPattern);

    Text spyPattern = Mockito.spy(new Text(rawPattern));

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    IUIAutomationTextRange mockRange = Mockito.mock(IUIAutomationTextRange.class);

    String text = spyPattern.getText();

    assertTrue(text.equals(""));
}
项目:ui-automation    文件:TablePatternTest.java   
@Test(expected=AutomationException.class)
public void test_That_getPattern_Throws_Exception_When_Pattern_Returns_Error() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Table pattern = new Table();

    Table spyPattern = Mockito.spy(pattern);

    IUIAutomationTablePattern mockRange = Mockito.mock(IUIAutomationTablePattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    spyPattern.getRowOrColumnMajor();

    verify(mockRange, atLeastOnce()).getCurrentRowOrColumnMajor(any());
}
项目:ui-automation    文件:TablePatternTest.java   
@Test
public void test_That_getPattern_Gets_Pattern_When_No_Pattern_Set() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Table pattern = new Table();

    Table spyPattern = Mockito.spy(pattern);

    IUIAutomationTablePattern mockRange = Mockito.mock(IUIAutomationTablePattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    doReturn(mockRange)
            .when(spyPattern)
            .convertPointerToInterface(any());

    spyPattern.getRowOrColumnMajor();

    verify(mockRange, atLeastOnce()).getCurrentRowOrColumnMajor(any());
}
项目:ui-automation    文件:SelectionPatternTest.java   
@Test(expected=AutomationException.class)
public void test_That_getPattern_Throws_Exception_When_Pattern_Returns_Error() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Selection pattern = new Selection();

    Selection spyPattern = Mockito.spy(pattern);

    IUIAutomationSelectionPattern mockPattern = Mockito.mock(IUIAutomationSelectionPattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    spyPattern.getCurrentSelection();

    verify(spyPattern, atLeastOnce()).getCurrentSelection();
}
项目:ui-automation    文件:ValuePatternTest.java   
@Test(expected=AutomationException.class)
@Ignore("Throws Mockito exception")
public void test_That_getPattern_Throws_Exception_When_Pattern_Returns_Error() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Value pattern = new Value();

    Value spyPattern = Mockito.spy(pattern);

    IUIAutomationValuePattern mockPattern = Mockito.mock(IUIAutomationValuePattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any(Pointer.class));

    doReturn(mockPattern)
            .when(spyPattern)
            .convertPointerToInterface(any(PointerByReference.class));

    spyPattern.value();

    verify(mockPattern, atLeastOnce()).getValue(any());
}
项目:ui-automation    文件:RangePatternTest.java   
@Test(expected=AutomationException.class)
public void test_That_getPattern_Throws_Exception_When_Pattern_Returns_Error() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Range pattern = new Range();

    Range spyPattern = Mockito.spy(new Range());

    IUIAutomationRangeValuePattern mockRange = Mockito.mock(IUIAutomationRangeValuePattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    spyPattern.getValue();

    verify(mockRange, atLeastOnce()).getValue(any());
}
项目:ui-automation    文件:RangePatternTest.java   
@Test
public void test_That_getPattern_Gets_Pattern_When_No_Pattern_Set() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Range pattern = new Range();

    Range spyPattern = Mockito.spy(new Range());

    IUIAutomationRangeValuePattern mockRange = Mockito.mock(IUIAutomationRangeValuePattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    doReturn(mockRange)
            .when(spyPattern)
            .convertPointerToInterface(any());

    spyPattern.getValue();

    verify(mockRange, atLeastOnce()).getValue(any());
}
项目:ui-automation    文件:StylesPatternTest.java   
@Test(expected=AutomationException.class)
public void test_That_getPattern_Throws_Exception_When_Pattern_Returns_Error() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Styles pattern = new Styles();

    Styles spyPattern = Mockito.spy(pattern);

    IUIAutomationStylesPattern mockPattern = Mockito.mock(IUIAutomationStylesPattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    spyPattern.getStyleName();

    verify(spyPattern, atLeastOnce()).getStyleName();
}
项目:ui-automation    文件:InvokePatternTest.java   
@Test(expected=AutomationException.class)
public void test_That_getPattern_Throws_Exception_When_Pattern_Returns_Error() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Invoke pattern = new Invoke();

    Invoke spyPattern = Mockito.spy(new Invoke());

    IUIAutomationInvokePattern mockRange = Mockito.mock(IUIAutomationInvokePattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    spyPattern.invoke();

    verify(mockRange, atLeastOnce()).invoke();
}
项目:ui-automation    文件:InvokePatternTest.java   
@Test
public void test_That_getPattern_Gets_Pattern_When_No_Pattern_Set() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Invoke pattern = new Invoke();

    Invoke spyPattern = Mockito.spy(new Invoke());

    IUIAutomationInvokePattern mockRange = Mockito.mock(IUIAutomationInvokePattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    doReturn(mockRange)
            .when(spyPattern)
            .convertPointerToInterface(any());

    spyPattern.invoke();

    verify(mockRange, atLeastOnce()).invoke();
}
项目:ui-automation    文件:SelectionItemPatternTest.java   
@Test(expected=AutomationException.class)
@Ignore("Fails after mockito upgrade")
public void test_That_getPattern_Throws_Exception_When_Pattern_Returns_Error() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    SelectionItem pattern = new SelectionItem();

    SelectionItem spyPattern = Mockito.spy(pattern);

    IUIAutomationSelectionItemPattern mockPattern = Mockito.mock(IUIAutomationSelectionItemPattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any(Pointer.class));

    doReturn(mockPattern)
            .when(spyPattern)
            .convertPointerToInterface(any(PointerByReference.class));

    spyPattern.select();

    verify(spyPattern, atLeastOnce()).select();
}
项目:ui-automation    文件:SelectionPatternTest2.java   
@Test
@Ignore("Needs better tests")
public void test_getCurrentSelection() throws Exception {

    doAnswer(invocation -> 0).when(rawPattern).getCurrentSelection(any());

    doAnswer(invocation -> new WinNT.HRESULT(0)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Selection pattern = new Selection(rawPattern);

    Selection spyPattern = Mockito.spy(new Selection(rawPattern));

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    IUIAutomationElementArray mockArray = Mockito.mock(IUIAutomationElementArray.class);

    doReturn(mockArray)
            .when(spyPattern)
            .convertPointerToElementArray(any());

    spyPattern.getCurrentSelection();
}
项目:ui-automation    文件:ValuePatternTest2.java   
@Test(expected=AutomationException.class)
@Ignore("Throws Mockito exception")
public void test_That_getPattern_Throws_Exception_When_Pattern_Returns_Error() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Value pattern = new Value();

    Value spyPattern = Mockito.spy(pattern);

    IUIAutomationValuePattern mockPattern = Mockito.mock(IUIAutomationValuePattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any(Pointer.class));

    doReturn(mockPattern)
            .when(spyPattern)
            .convertPointerToInterface(any(PointerByReference.class));

    spyPattern.value();

    verify(mockPattern, atLeastOnce()).getValue(any());
}
项目:ui-automation    文件:GridPatternTest.java   
@Test
@Ignore("Mocking issues, need to be sorted")
public void test_That_getPattern_Gets_Pattern_When_No_Pattern_Set() throws Exception {

    doAnswer(invocation -> new WinNT.HRESULT(0)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Grid pattern = new Grid();

    Grid spyPattern = Mockito.spy(new Grid());

    IUIAutomationGridPattern mockGrid = Mockito.mock(IUIAutomationGridPattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    doReturn(mockGrid)
            .when(spyPattern)
            .convertPointerToInterface(any());

    IUIAutomationElement mockElement = Mockito.mock(IUIAutomationElement.class);

    doReturn(mockElement)
            .when(spyPattern)
            .convertPointerToElementInterface(any());

    spyPattern.getItem(0,0);

    verify(mockGrid, atLeastOnce()).getItem(any(), any(),any());
}
项目:ui-automation    文件:TextPatternTest.java   
@Test(expected=AutomationException.class)
@Ignore("Failures after Mockito upgrade")
public void test_GetSelection_Throws_Exception_When_Error_Returned() throws Exception {
    doAnswer(invocation -> 0).when(rawPattern).getSelection(any(PointerByReference.class));

    doAnswer(invocation -> new WinNT.HRESULT(-1)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    Text pattern = new Text(rawPattern);

    String text = pattern.getSelection();

    assertTrue(text.equals(""));
}