1from CFNetwork import * 2from PyObjCTools.TestSupport import * 3 4class TestCFNetwork (TestCase): 5 def testTypes(self): 6 # XXX: CFNetDiagnosticsRef is not actually a proper type 7 # in Leopard, the result turns out to be a CFDictionaryRef... 8 #self.assertIsCFType(CFNetDiagnosticRef) 9 pass 10 11 def testConstants(self): 12 self.assertEqual(kCFNetDiagnosticNoErr, 0) 13 self.assertEqual(kCFNetDiagnosticErr, -66560) 14 self.assertEqual(kCFNetDiagnosticConnectionUp, -66559) 15 self.assertEqual(kCFNetDiagnosticConnectionIndeterminate, -66558) 16 self.assertEqual(kCFNetDiagnosticConnectionDown, -66557) 17 18 19 def testFuncdtions(self): 20 self.assertResultIsCFRetained(CFNetDiagnosticCreateWithStreams) 21 22 host = CFHostCreateWithName(None, u"www.apple.com") 23 rd, wr = CFStreamCreatePairWithSocketToCFHost(None, host, 80, None, None) 24 self.assertIsInstance(rd, CFReadStreamRef) 25 self.assertIsInstance(wr, CFWriteStreamRef) 26 27 ref = CFNetDiagnosticCreateWithStreams(None, rd, wr) 28 self.assertIsInstance(ref, objc.objc_object) #CFNetDiagnosticRef) 29 30 self.assertResultIsCFRetained(CFNetDiagnosticCreateWithURL) 31 ref = CFNetDiagnosticCreateWithURL(None, CFURLCreateWithString(None, u"http://www.apple.com/", None)) 32 self.assertIsInstance(ref, objc.objc_object) #CFNetDiagnosticRef) 33 34 CFNetDiagnosticSetName(ref, u"hello world") 35 36 sts = CFNetDiagnosticDiagnoseProblemInteractively(ref) 37 self.assertIsInstance(sts, (int, long)) 38 39 self.assertArgIsOut(CFNetDiagnosticCopyNetworkStatusPassively, 1) 40 sts, descr = CFNetDiagnosticCopyNetworkStatusPassively(ref, None) 41 self.assertIsInstance(sts, (int, long)) 42 self.assertIsInstance(descr, unicode) 43 44if __name__ == "__main__": 45 main() 46