如何从std :: istream测试类读取?(How to test class reading from std::istream?)
如何模拟
std::istream
? 我的意思是运营商>>
。 我测试的对象从这个流中读取两个数字(std::istream&
是这个类的成员)。 我该怎么测试呢? 如何在测试中读取此值?我想测试这些值,或者只测试测试值中定义的读取值以进一步测试。
我用gmock。
How to mock
std::istream
? I mean exactly operator>>
. My tested object reading two numbers from this stream (std::istream&
is a member of this class). How can I test it? How to read this values in test?I'd like to test this values or just only read defined in test values to go further in the test.
I use gmock.
原文:https://stackoverflow.com/questions/35581186
最满意答案
我只是重新阅读文档,似乎我的一般方法是错误的。 我应该首先在沙箱中创建文件,然后将其移动到云端。 换句话说,苹果似乎建议我在任何时候都应该有三个版本的同一个文件:一个在我的应用程序的目录中,一个在我的设备的iCloud恶魔目录(也可以离线访问),一个在云端:
应用程序使用相同的技术来管理iCloud中为本地文件和目录所做的文件和目录。 iCloud中的文件和目录仍然只是文件和目录。 您可以打开它们,创建它们,移动它们,复制它们,从中读取和写入,删除它们,或者您可能想要执行的任何其他操作。 本地文件和目录以及iCloud文件和目录之间的唯一区别是用于访问它们的URL。 相对于您的应用程序的沙盒而言,网址不是与相应的iCloud容器目录相关的iCloud文件和目录的URL。
将文件或目录移动到iCloud:
在应用程序沙箱中本地创建文件或目录。 在使用中,文件或目录必须由文件演示者(如UIDocument对象)进行管理。
使用URLForUbiquityContainerIdentifier:方法来检索要存储项目的iCloud容器目录的URL。 使用容器目录URL构建一个新的URL,该URL指定项目在iCloud中的位置。 调用setUbiquitous:itemAtURL:destinationURL:error:NSFileManager的方法将项目移动到iCloud。 不要从应用程序的主线程调用此方法; 这样做可能会阻止您的主线程延长一段时间,或与您的应用程序自己的文件演示者之一导致死锁。 当您将文件或目录移动到iCloud时,系统将该项目从应用程序沙箱中复制到专用的本地目录中,以便可以由iCloud守护程序进行监视。 即使文件不再在您的沙箱中,您的应用仍然可以完全访问它。 虽然该文件的副本仍然保留在当前设备本地,但该文件也会发送到iCloud,以便可以将其分发到其他设备。 iCloud守护程序处理所有确保本地副本相同的工作。 所以从您的应用程序的角度来看,该文件就在iCloud中。
您对iCloud中的文件或目录所做的所有更改都必须使用文件协调器对象进行。 这些更改包括移动,删除,复制或重命名该项目。 文件协调器确保iCloud守护程序不会同时更改文件或目录,并确保向其他有关方通知您所做的更改。
但是,如果您深入了解有关setUbiquitous的文档,您会发现:
使用此方法将文件从当前位置移动到iCloud。 对于位于应用程序沙箱中的文件 , 这涉及从沙箱目录中物理删除该文件 。 (该系统扩展您的应用程序的沙箱权限,以访问它移动到iCloud的文件。)您还可以使用此方法将文件从iCloud中移出并返回到本地目录。
所以这似乎意味着文件/目录从本地沙箱中删除并移动到云中。
I just re-read the docs and it appears that my general approach is wrong. I should first create the file in the sandbox and then move it to the cloud. In other words, Apple seems to suggest that I should have three versions of the same file at all times: one in the directory of my app, one in the iCloud demon directory of my device (which is also accessible if offline) and one in the cloud:
Apps use the same technologies to manage files and directories in iCloud that they do for local files and directories. Files and directories in iCloud are still just files and directories. You can open them, create them, move them, copy them, read and write from them, delete them, or any of the other operations you might want to do. The only differences between local files and directories and iCloud files and directories is the URL you use to access them. Instead of URLs being relative to your app’s sandbox, URLs for iCloud files and directories are relative to the corresponding iCloud container directory.
To move a file or directory to iCloud:
Create the file or directory locally in your app sandbox. While in use, the file or directory must be managed by a file presenter, such as a UIDocument object.
Use the URLForUbiquityContainerIdentifier: method to retrieve a URL for the iCloud container directory in which you want to store the item. Use the container directory URL to build a new URL that specifies the item’s location in iCloud. Call the setUbiquitous:itemAtURL:destinationURL:error: method of NSFileManager to move the item to iCloud. Never call this method from your app’s main thread; doing so could block your main thread for an extended period of time or cause a deadlock with one of your app’s own file presenters. When you move a file or directory to iCloud, the system copies that item out of your app sandbox and into a private local directory so that it can be monitored by the iCloud daemon. Even though the file is no longer in your sandbox, your app still has full access to it. Although a copy of the file remains local to the current device, the file is also sent to iCloud so that it can be distributed to other devices. The iCloud daemon handles all of the work of making sure that the local copies are the same. So from the perspective of your app, the file just is in iCloud.
All changes you make to a file or directory in iCloud must be made using a file coordinator object. These changes include moving, deleting, copying, or renaming the item. The file coordinator ensures that the iCloud daemon does not change the file or directory at the same time and ensures that other interested parties are notified of the changes you make.
However, if you dig a little deeper into the docs concerning setUbiquitous, you'll find:
Use this method to move a file from its current location to iCloud. For files located in an application’s sandbox, this involves physically removing the file from the sandbox directory. (The system extends your application’s sandbox privileges to give it access to files it moves to iCloud.) You can also use this method to move files out of iCloud and back into a local directory.
So this appears to mean that a file / directory gets deleted form the local sandbox and moved into the cloud.
相关问答
更多-
为什么Apple的PackagedDocument MacOS iCloud示例项目找不到URLForUbiquityContainerIdentifier? 我在问题的最后添加的更多信息让我得出结论,如果MacOS大于10.9(小牛队)即优胜美地或者El,非苹果应用程序现在需要iCloud Drive才能访问iCloud容器匹。 也就是说,在普通的iCloud Yosemite或El Capitan中找不到URLForUbiquityContainerIdentifier 。 我认为PackagedDoc ...
-
如果您是Apple开发人员连接的成员,他们为iPhone开发者许可证支付99美元, iPhone开发中心将拥有iPad支持所需的一切,包括: iPad编程指南 iPad人机接口指南 示例代码 当您到达iPhone开发中心时,点击“iPhone SDK 3.2测试版”。 If you're a member of the Apple Developer Connection who's paid for the $99/year iPhone developer license, the iPhone Dev ...
-
我只是重新阅读文档,似乎我的一般方法是错误的。 我应该首先在沙箱中创建文件,然后将其移动到云端。 换句话说,苹果似乎建议我在任何时候都应该有三个版本的同一个文件:一个在我的应用程序的目录中,一个在我的设备的iCloud恶魔目录(也可以离线访问),一个在云端: 应用程序使用相同的技术来管理iCloud中为本地文件和目录所做的文件和目录。 iCloud中的文件和目录仍然只是文件和目录。 您可以打开它们,创建它们,移动它们,复制它们,从中读取和写入,删除它们,或者您可能想要执行的任何其他操作。 本地文件和目录以及 ...
-
YourKeyboard.h: #import
@protocol YourKeyboardControllerDelegate -(void) buttonTapped: (int) ASCIICode; @end @interface YourKeyboardViewController : UIViewController { id delegate; } @property (nonatom ... -
你看过官方网站还是用户手册 ? 后者非常详细。 Have you looked at the official site, or the user manual? The latter is quite detailed.
-
那是你在找什么? http://www.iostream.eu/zend-framework-cheat-sheet/ 还有流程图 http://tournasdimitrios1.files.wordpress.com/2011/05/zend-framework-sequence_flowchart.jpg http://otroblogmas.com/wp-content/uploads/2010/07/zend-framework-flow-diagram.png is that what you ...
-
Git基础为新手[已关闭](Git Basics for newbies [closed])[2022-01-17]
在别的之前,了解如何配置ssh访问权限(通常不仅仅是git )到你的服务器上,这样你可以运行如下的东西: ssh myserver uptime 并让它运行远程命令而不提示您输入密码。 这会让你的生活更加愉快。 如果我想在我的本地机器上创建一个新的存储库,而不是将其推送到服务器(它已经或者没有这个存储库),那么需要采取哪些措施? 在远程服务器上: 创建目标存储库: $ mkdir -p path/to/repo.git $ cd path/to/repo.git $ git init --bare 在您 ... -
我建议你从Tanenbaum学习MINIX3: http : //www.minix3.org/ 它是一个微内核架构,随着他的书( http://vig.prenhall.com/catalog/academic/product/0,1144,0131429388,00.html ),它真的很棒。 从我的角度来看,研究linux内核对于一个开始来说有点硬核;),从学术观点来看,微内核架构优于单片内核。 此外,与Linux内核不同,只有几千行代码,它的消耗品在一个现实的时间表中。 这是一个真正认真的项目,就我 ...
-
这可能是iOS错误。 请参阅此主题: http : //devforums.apple.com/message/735512#735512 这为我修好了: NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; moc.stalenessInterval = 0; 这没有帮助: [moc refreshObject:myObject ...
-
如何使用Linq轻松解析XML - 需要一些示例代码[关闭](How to use Linq to parse through XML easly - Need some sample code [closed])[2022-11-08]
选择列表 var q = from x in doc.Descendants() select x.Value; 选择特定的节点,例如动物,做doc.Descendants("animal") 选择特定值,例如动物名称, select x.Attribute("name").Value 演示: https : //dotnetfiddle.net/TdCWjE To select a list var q = from x in doc.Descendants() sele ...