qstylehints.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qsurface.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qwindow.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtCore\QEvent \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtCore\QMargins \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qgenericmatrix.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qmatrix4x4.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qvector3d.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qvector4d.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qquaternion.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qopenglbuffer.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qopenglframebufferobject.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qopenglfunctions.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qopenglpaintdevice.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qopenglshaderprogram.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qbackingstore.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qpagedpaintdevice.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qpaintengine.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qpainter.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qtextoption.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qpen.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qfontinfo.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qfontmetrics.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qpdfwriter.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qabstracttextdocumentlayout.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qtextlayout.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qtextformat.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qglyphrun.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qrawfont.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qfontdatabase.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qtextcursor.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qtextdocument.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qstatictext.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qsyntaxhighlighter.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qtextobject.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qtextdocumentfragment.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qtextdocumentwriter.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qtextlist.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qtexttable.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qdesktopservices.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qvalidator.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\QGenericPluginFactory \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\QGenericPlugin \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtGui\qtguiversion.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtWidgets\qaccessiblewidget.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtWidgets\qcolordialog.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtWidgets\qdialog.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtWidgets\qwidget.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtWidgets\qsizepolicy.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtWidgets\qerrormessage.h \
		C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtWidgets\qfiledialog.h \
		C:\Qt\Qt5.0.2\5.0.2\mimport unittest
from comtypes.automation import IDispatch
from comtypes.client import CreateObject, GetModule
from comtypes.client.lazybind import Dispatch

# create the typelib wrapper and import it
GetModule("scrrun.dll")
from comtypes.gen.Scripting import IDictionary


class Test(unittest.TestCase):

    def setUp(self):
        self.d = CreateObject("Scripting.Dictionary", dynamic=True)

    def tearDown(self):
        del self.d

    def test_type(self):
        self.assertTrue(isinstance(self.d, Dispatch))

    def test_index_setter(self):
        d = self.d
        d.CompareMode = 42
        d["foo"] = 1
        d["bar"] = "spam foo"
        d["baz"] = 3.14
        self.assertAccessInterface(d)

    def test_named_property_setter(self):
        d = self.d
        d.CompareMode = 42
        d.Item["foo"] = 1
        d.Item["bar"] = "spam foo"
        d.Item["baz"] = 3.14
        self.assertAccessInterface(d)

    def test_reference_passing(self):
        d = self.d

        # Check reference passing
        d["self"] = d
        d[0] = "something nontrivial"
        dself = d["self"]
        dself[1] = "something else nontrivial"
        self.assertEqual(d, dself)
        self.assertEqual(d[0], "something nontrivial")
        self.assertEqual(dself[0], d[0])
        self.assertEqual(d[1], "something else nontrivial")
        self.assertEqual(dself[1], d[1])

    def test_query_interface(self):
        d = self.d
        d.CompareMode = 42
        d.Item["foo"] = 1
        d.Item["bar"] = "spam foo"
        d.Item["baz"] = 3.14

        # This should cast the underlying com object to an IDispatch
        d2 = d.QueryInterface(IDispatch)
        # Which can be cast to the non-dynamic type
        d3 = d2.QueryInterface(IDictionary)
        self.assertEqual(d3.CompareMode, 42)
        self.assertEqual(d3.Item["foo"], 1)
        self.assertEqual(d3.Item["bar"], "spam foo")
        self.assertEqual(d3.Item["baz"], 3.14)

    def test_named_property_no_length(self):
        self.assertRaises(TypeError, len, self.d.Item)

    def test_named_property_not_iterable(self):
        self.assertRaises(TypeError, list, self.d.Item)

    def assertAccessInterface(self, d):
        """ Asserts access via indexing and named property """
        self.assertEqual(d.CompareMode, 42)
        self.assertEqual(d["foo"], 1)
        self.assertEqual(d.Item["foo"], d["foo"])
        self.assertEqual(d.Item("foo"), d["foo"])
        self.assertEqual(d["bar"], "spam foo")
        self.assertEqual(d.Item("bar"), "spam foo")
        self.assertEqual(d["baz"], 3.14)
        self.assertEqual(d.Item("baz"), d["baz"])
        self.assertIsNone(d["asdlfkj"])
        self.assertIsNone(d.Item["asdlfkj"])
        self.assertIsNone(d.Item("asdlfkj"))

        items = iter(d)
        self.assertEqual(items[0], "foo")
        self.assertEqual(items[1], "bar")
        self.assertEqual(items[2], "baz")
        self.assertEqual(items[3], "asdlfkj")


if __name__ == "__main__":
    unittest.main()
