如何从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.

相关问答

更多

为什么Apple的PackagedDocument MacOS iCloud示例项目找不到URLForUbiquityContainerIdentifier?(Why does Apple's PackagedDocument MacOS iCloud sample project not find URLForUbiquityContainerIdentifier?)

为什么Apple的PackagedDocument MacOS iCloud示例项目找不到URLForUbiquityContainerIdentifier? 我在问题的最后添加的更多信息让我得出结论,如果MacOS大于10.9(小牛队)即优胜美地或者El,非苹果应用程序现在需要iCloud Drive才能访问iCloud容器匹。 也就是说,在普通的iCloud Yosemite或El Capitan中找不到URLForUbiquityContainerIdentifier 。 我认为Packag...

我在哪里可以找到iPad示例代码[已关闭](Where can I find iPad Sample Code [closed])

如果您是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 iPhon...

iCloud基础和代码示例[关闭](iCloud basics and code sample [closed])

我只是重新阅读文档,似乎我的一般方法是错误的。 我应该首先在沙箱中创建文件,然后将其移动到云端。 换句话说,苹果似乎建议我在任何时候都应该有三个版本的同一个文件:一个在我的应用程序的目录中,一个在我的设备的iCloud恶魔目录(也可以离线访问),一个在云端: 应用程序使用相同的技术来管理iCloud中为本地文件和目录所做的文件和目录。 iCloud中的文件和目录仍然只是文件和目录。 您可以打开它们,创建它们,移动它们,复制它们,从中读取和写入,删除它们,或者您可能想要执行的任何其他操作。 本地文件...

代码示例创建自己的键盘[关闭](code sample to create own keyboard [closed])

YourKeyboard.h: #import <UIKit/UIKit.h> @protocol YourKeyboardControllerDelegate -(void) buttonTapped: (int) ASCIICode; @end @interface YourKeyboardViewController : UIViewController { id<YourKeyboardControllerDelegate> delegate; } @property (no...

Jmeter基础知识与一些示例(Jmeter basics with some sample [closed])

你看过官方网站还是用户手册 ? 后者非常详细。 Have you looked at the official site, or the user manual? The latter is quite detailed.

Zend Framework示例代码和备忘单[关闭](Zend Framework Sample Code and Cheat Sheet [closed])

那是你在找什么? 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...

Git基础为新手[已关闭](Git Basics for newbies [closed])

在别的之前,了解如何配置ssh访问权限(通常不仅仅是git )到你的服务器上,这样你可以运行如下的东西: ssh myserver uptime 并让它运行远程命令而不提示您输入密码。 这会让你的生活更加愉快。 如果我想在我的本地机器上创建一个新的存储库,而不是将其推送到服务器(它已经或者没有这个存储库),那么需要采取哪些措施? 在远程服务器上: 创建目标存储库: $ mkdir -p path/to/repo.git $ cd path/to/repo.git $ git init --bar...

用C编写的低级问题的示例解决方案[关闭](Sample solutions for low-level problems written in C [closed])

我建议你从Tanenbaum学习MINIX3: http : //www.minix3.org/ 它是一个微内核架构,随着他的书( http://vig.prenhall.com/catalog/academic/product/0,1144,0131429388,00.html ),它真的很棒。 从我的角度来看,研究linux内核对于一个开始来说有点硬核;),从学术观点来看,微内核架构优于单片内核。 此外,与Linux内核不同,只有几千行代码,它的消耗品在一个现实的时间表中。 这是一个真正认真的...

iOS:SharedCoreData示例代码(iCloud + CoreData)|(iOS: SharedCoreData Example Code (iCloud + CoreData) | How are changes merged)

这可能是iOS错误。 请参阅此主题: http : //devforums.apple.com/message/735512#735512 这为我修好了: NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; moc.stalenessInterval = 0; 这没有帮助: [moc refreshObject:myOb...

如何使用Linq轻松解析XML - 需要一些示例代码[关闭](How to use Linq to parse through XML easly - Need some sample code [closed])

选择列表 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() ...

相关文章

更多

reading notes for solr source code

solr source code 1 org.apache.solr.common 基本的类对象 ...

Hadoop 0.21如何运行单个test case

研究 Hadoop 0.21代码时,很多情况下需要运行单个test case,如果新增了功能要测试 ...

java反射详解(一)_Class类

Java类用于描述一类事物的共性,该类事物有什么属性,没有什么属性,至于这个属性的值是什么,则是由这个 ...

在main方法中开启线程与@Test中开启线程

用来测试线程同步问题的代码: public class SynchronizeDemo { p ...

如何卸载assembly?或者class

.net的动态编译功能很好,但是有个问题,动态编译的代码,每次执行后,都会产生一个新的assembly ...

Java泛型父类取得子类的泛型参数T的Class类型

import java.lang.reflect.ParameterizedType;import j ...

ssh 框架下 class 类打包发布

ssh 框架下 class 类打包后放到 web-inf/lib 下后 @autowire自动注入似乎 ...

《测试驱动开发(中文版)》(Test-driven development:by example)扫描版[PDF]

中文名: 测试驱动开发(中文版) 原名: Test-driven development:by ...

【原】storm源码之一个class解决nimbus单点问题

一、storm nimbus 单节点问题概述 1、storm集群在生产环境部署之后,通常会是如下的结构 ...

mybatis There is no getter for property named 'xx' in 'class java.lang.String

用mybatis查询时,传入一个字符串传参数,且进行判断时,会报 There is no get ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本