test_win32gui.py :  » Windows » pyExcelerator » pywin32-214 » win32 » test » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Windows » pyExcelerator 
pyExcelerator » pywin32 214 » win32 » test » test_win32gui.py
# tests for win32gui
import unittest
import win32gui
import pywin32_testutil
import operator
import array
import sys

# theoretically should be in pywin32_testutil, but this is the only place
# that currently needs such a function...
def ob2bytes(ob):
    if sys.version_info < (3,0):
        return str(buffer(ob))
    # py3k.
    return bytes(ob)


class TestPyGetString(unittest.TestCase):
    def test_get_string(self):
        # test invalid addresses cause a ValueError rather than crash!
        self.assertRaises(ValueError, win32gui.PyGetString, 0)
        self.assertRaises(ValueError, win32gui.PyGetString, 1)
        self.assertRaises(ValueError, win32gui.PyGetString, 1,1)

class TestPyGetMemory(unittest.TestCase):
    def test_ob(self):
        # Check the PyGetMemory result and a bytes string can be compared
        test_data = pywin32_testutil.str2bytes("\0\1\2\3\4\5\6")
        c = array.array("b", test_data)
        addr, buflen = c.buffer_info()
        got = win32gui.PyGetMemory(addr, buflen)
        self.failUnlessEqual(len(got), len(test_data))
        self.failUnlessEqual(ob2bytes(got), test_data)

    def test_memory_index(self):
        # Check we can index into the buffer object returned by PyGetMemory
        test_data = pywin32_testutil.str2bytes("\0\1\2\3\4\5\6")
        c = array.array("b", test_data)
        addr, buflen = c.buffer_info()
        got = win32gui.PyGetMemory(addr, buflen)
        self.failUnlessEqual(got[0], pywin32_testutil.str2bytes('\0'))

    def test_memory_slice(self):
        # Check we can slice the buffer object returned by PyGetMemory
        test_data = pywin32_testutil.str2bytes("\0\1\2\3\4\5\6")
        c = array.array("b", test_data)
        addr, buflen = c.buffer_info()
        got = win32gui.PyGetMemory(addr, buflen)
        self.failUnlessEqual(got[0:3], pywin32_testutil.str2bytes('\0\1\2'))
    
    def test_real_view(self):
        # Do the PyGetMemory, then change the original memory, then ensure
        # the initial object we fetched sees the new value.
        test_data = pywin32_testutil.str2bytes("\0\1\2\3\4\5\6")
        c = array.array("b", test_data)
        addr, buflen = c.buffer_info()
        got = win32gui.PyGetMemory(addr, buflen)
        self.failUnlessEqual(got[0], pywin32_testutil.str2bytes('\0'))
        new = pywin32_testutil.str2bytes('\1')
        c[0] = 1
        self.failUnlessEqual(got[0], new)

    def test_memory_not_writable(self):
        # Check the buffer object fetched by PyGetMemory isn't writable.
        test_data = pywin32_testutil.str2bytes("\0\1\2\3\4\5\6")
        c = array.array("b", test_data)
        addr, buflen = c.buffer_info()
        got = win32gui.PyGetMemory(addr, buflen)
        new = pywin32_testutil.str2bytes('\1')
        self.failUnlessRaises(TypeError, operator.setitem, got, 0, new)


if __name__=='__main__':
    unittest.main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.