def testMapInitUnmapLibrary(self): self.assertEquals(Unmanaged.GetModuleHandle("python26.dll"), IntPtr.Zero, "library already mapped") sr = StubReference(os.path.join("build", "ironclad", "python26.dll")) self.assertNotEquals(Unmanaged.GetModuleHandle("python26.dll"), IntPtr.Zero, "library not mapped by construction") fpCalls = [] @dgt_getfuncptr def GetFuncPtr(name): fpCalls.append(name) return IntPtr.Zero dataCalls = [] @dgt_registerdata def RegisterData(name, _): dataCalls.append(name) sr.Init(GetFuncPtr, RegisterData) self.assertEquals(len(fpCalls) > 0, True, "did not get any addresses") self.assertEquals(len(dataCalls) > 0, True, "did not set any data") sr.Dispose() self.assertEquals(Unmanaged.GetModuleHandle("python26.dll"), IntPtr.Zero, "library not unmapped on dispose") sr.Dispose()
def testUnmapsAutomagically(self): sr = StubReference(os.path.join("build", "ironclad", "python26.dll")) self.assertNotEquals(Unmanaged.GetModuleHandle("python26.dll"), IntPtr.Zero, "library not mapped by construction") del sr gcwait() self.assertEquals(Unmanaged.GetModuleHandle("python26.dll"), IntPtr.Zero, "library not unmapped on finalize")
def testUnmapsAutomagically(self): sr = StubReference(DLL_PATH) self.assertNotEquals(Unmanaged.GetModuleHandle(PYTHON_DLL), IntPtr.Zero, "library not mapped by construction") del sr gcwait() self.assertEquals(Unmanaged.GetModuleHandle(PYTHON_DLL), IntPtr.Zero, "library not unmapped on finalize")
def testUnloadsAutomagically(self): pi = PydImporter() pi.Load("tests\\data\\setvalue.pyd") del pi gcwait() self.assertEquals(Unmanaged.GetModuleHandle("setvalue.pyd"), IntPtr.Zero, "failed to unload on dispose")
def testLoadsModuleAndUnloadsOnDispose(self): mapper = PythonMapper(DLL_PATH) try: origcwd = os.getcwd() mapper.LoadModule(os.path.join("tests", "data", "setvalue.pyd"), "some.module") self.assertEquals(os.getcwd(), origcwd, "failed to restore working directory") self.assertNotEquals(Unmanaged.GetModuleHandle("setvalue.pyd"), IntPtr.Zero, "library not mapped by construction") mapper.Dispose() self.assertEquals(Unmanaged.GetModuleHandle("setvalue.pyd"), IntPtr.Zero, "library not unmapped by Dispose") self.assertEquals(Unmanaged.GetModuleHandle(PYTHON_DLL), IntPtr.Zero, "library not unmapped by Dispose") finally: mapper.Dispose()
def testLoadsStubWhenPassedPathAndUnloadsOnDispose(self): mapper = PythonMapper(DLL_PATH) try: self.assertNotEquals(Unmanaged.GetModuleHandle(PYTHON_DLL), IntPtr.Zero, "library not mapped by construction") self.assertNotEquals(PythonMapper._Py_NoneStruct, IntPtr.Zero, "mapping not set up") # weak side-effect test to hopefully prove that ReadyBuiltinTypes has been called self.assertEquals(CPyMarshal.ReadPtrField(mapper.PyLong_Type, PyTypeObject, "tp_base"), mapper.PyBaseObject_Type) mapper.Dispose() self.assertEquals(Unmanaged.GetModuleHandle(PYTHON_DLL), IntPtr.Zero, "library not unmapped by Dispose") finally: mapper.Dispose()
def testCallsAppropriatelyNamedInitFunctionAndUnloadsWhenDone(self): l = Unmanaged.LoadLibrary("tests\\data\\setvalue.pyd") try: pValue = Unmanaged.GetProcAddress(l, "value") value = CPyMarshal.ReadInt(pValue) self.assertEquals(value, 1, "bad setup") pi = PydImporter() pi.Load("tests\\data\\setvalue.pyd") finally: # lose test reference to setvalue.pyd # only the PydImporter should still have a reference to it Unmanaged.FreeLibrary(l) value = CPyMarshal.ReadInt(pValue) self.assertEquals(value, 2, "PydImporter didn't call correct function") pi.Dispose() self.assertEquals(Unmanaged.GetModuleHandle("setvalue.pyd"), IntPtr.Zero, "failed to unload on dispose") pi.Dispose()