Пример #1
0
    def testWriteByte(self):
        data = Marshal.AllocHGlobal(1)

        CPyMarshal.WriteByte(data, 0)
        self.assertEquals(Marshal.ReadByte(data), 0, "wrong")

        CPyMarshal.WriteByte(data, 255)
        self.assertEquals(Marshal.ReadByte(data), 255, "wrong")

        Marshal.FreeHGlobal(data)
Пример #2
0
    def assertStringObjectHasLength(self, strPtr, length):
        stringObject = Marshal.PtrToStructure(strPtr, PyStringObject)
        self.assertEquals(stringObject.ob_refcnt, 1, "unexpected refcount")
        self.assertEquals(stringObject.ob_size, length, "unexpected ob_size")
        self.assertEquals(stringObject.ob_shash, -1,
                          "unexpected currently-useless-field")
        self.assertEquals(stringObject.ob_sstate, 0,
                          "unexpected currently-useless-field")

        strDataPtr = self.dataPtrFromStrPtr(strPtr)
        terminatorPtr = OffsetPtr(strDataPtr, length)
        self.assertEquals(Marshal.ReadByte(terminatorPtr), 0,
                          "string not terminated")
Пример #3
0
    def testIC_PyFile_AsFile(self, mapper, addToCleanUp, stderr_writes):
        buflen = len(TEST_TEXT) + 10
        buf = Marshal.AllocHGlobal(buflen)
        
        filePtr = mapper.Store(open(*READ_ARGS))
        
        f = mapper.IC_PyFile_AsFile(filePtr)
        self.assertEquals(stderr_writes, [('Warning: creating unmanaged FILE* from managed stream. Please use ironclad.open with this extension.',), ('\n',)])
        self.assertEquals(Unmanaged.fread(buf, 1, buflen, f), len(TEST_TEXT), "didn't get a real FILE")
        ptr = buf
        for c in TEST_TEXT:
            self.assertEquals(Marshal.ReadByte(ptr), ord(c), "got bad data from FILE")
            ptr = OffsetPtr(ptr, 1)

        Marshal.FreeHGlobal(buf)