如何从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?(Why does Apple's PackagedDocument MacOS iCloud sample project not find URLForUbiquityContainerIdentifier?)
我在哪里可以找到iPad示例代码[已关闭](Where can I find iPad Sample Code [closed])
iCloud基础和代码示例[关闭](iCloud basics and code sample [closed])
代码示例创建自己的键盘[关闭](code sample to create own keyboard [closed])
Jmeter基础知识与一些示例(Jmeter basics with some sample [closed])
Zend Framework示例代码和备忘单[关闭](Zend Framework Sample Code and Cheat Sheet [closed])
Git基础为新手[已关闭](Git Basics for newbies [closed])
用C编写的低级问题的示例解决方案[关闭](Sample solutions for low-level problems written in C [closed])
iOS:SharedCoreData示例代码(iCloud + CoreData)|(iOS: SharedCoreData Example Code (iCloud + CoreData) | How are changes merged)
如何使用Linq轻松解析XML - 需要一些示例代码[关闭](How to use Linq to parse through XML easly - Need some sample code [closed])
相关文章
更多reading notes for solr source code
Hadoop 0.21如何运行单个test case
java反射详解(一)_Class类
在main方法中开启线程与@Test中开启线程
如何卸载assembly?或者class
Java泛型父类取得子类的泛型参数T的Class类型
ssh 框架下 class 类打包发布
《测试驱动开发(中文版)》(Test-driven development:by example)扫描版[PDF]
【原】storm源码之一个class解决nimbus单点问题
mybatis There is no getter for property named 'xx' in 'class java.lang.String
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!