首页 \ 问答 \ 如何从std :: istream测试类读取?(How to test class reading from std::istream?)

如何从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
更新时间:2022-05-15 11:05

最满意答案

我只是重新阅读文档,似乎我的一般方法是错误的。 我应该首先在沙箱中创建文件,然后将其移动到云端。 换句话说,苹果似乎建议我在任何时候都应该有三个版本的同一个文件:一个在我的应用程序的目录中,一个在我的设备的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.

相关问答

更多

相关文章

更多

最新问答

更多
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • Java中的不可变类(Immutable class in Java)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • EXCEL VBA 基础教程下载
  • RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
  • 无法在Google Script中返回2D数组?(Can not return 2D Array in Google Script?)
  • JAVA环境变量的设置和对path , classpth ,java_home设置作用和目的?
  • mysql 关于分组查询、时间条件查询
  • 如何使用PowerShell匹配运算符(How to use the PowerShell match operator)
  • Effective C ++,第三版:重载const函数(Effective C++, Third edition: Overloading const function)
  • 如何用DELPHI动态建立MYSQL的数据库和表? 请示出源代码。谢谢!
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 使用前端框架带来哪些好处,相对于使用jquery
  • Ruby将字符串($ 100.99)转换为float或BigDecimal(Ruby convert string ($100.99) to float or BigDecimal)
  • 高考完可以去做些什么?注意什么?
  • 如何声明放在main之后的类模板?(How do I declare a class template that is placed after the main?)
  • 如何使用XSLT基于兄弟姐妹对元素进行分组(How to group elements based on their siblings using XSLT)
  • 在wordpress中的所有页面的标志(Logo in all pages in wordpress)
  • R:使用rollapply对列组进行求和的问题(R: Problems using rollapply to sum groups of columns)
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • python中使用sys模块中sys.exit()好像不能退出?
  • 将Int拆分为3个字节并返回C语言(Splitting an Int to 3 bytes and back in C)
  • 在SD / MMC中启用DDR会导致问题吗?(Enabling DDR in SD/MMC causes problems? CMD 11 gives a response but the voltage switch wont complete)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 如何将字符串转换为Elixir中的函数(how to convert a string to a function in Elixir)