开发者

Objective-C: NSInputStream and NSOutputStream for testing purposes

开发者 https://www.devze.com 2023-03-26 18:16 出处:网络
I have an class in my application that is initialized with an NSInputStream. For testing purposes i want to write data on an NSOutputStream which then is received by that input stream.

I have an class in my application that is initialized with an NSInputStream. For testing purposes i want to write data on an NSOutputStream which then is received by that input stream. This should trigger the NSStreamEventHasBytesAvailable event.

The only thing is that i do 开发者_Go百科not know how to set this up. Does anybody has an idea? Or suggestions how to unit test a class with has an NSStream as dependency.

Thanks


This is actually not very tricky, I've described how to do it using the SimpleURLConnection sample code available on the apple developer site.

This is the question and my answer there will work here too.


This is actually really tricky since it appears that you can only create an input stream using a file, a URL or an NSData. You can't connect an input stream to an output stream, although you might be able to write a single class that implements both interfaces.

The easiest way to do the unit test would probably be to create your input stream from an NSData whose bytes you have already read in from the output stream.

0

精彩评论

暂无评论...
验证码 换一张
取 消