我有一个使用DLL文件的EXE文件,该文件使用另一个DLL文件.出现这种情况:
在DLL文件1中:
class abc
{
static bool FindSubFolders(const std::string & sFolderToCheck,
std::vector< std::string > & vecSubFoldersFound);
}
Run Code Online (Sandbox Code Playgroud)
在DLL文件2中:
void aFunction()
{
std::vector<std::string> folders;
std::string sLocation;
...
abc::FindSubFolders(sLocation, folders)
}
Run Code Online (Sandbox Code Playgroud)
在发布模式下,一切正常.但是在调试模式下,我std::strings在文件夹向量中的一个析构函数中出现断言失败(当文件夹在aFunction结尾处超出范围时):
dbgheap.c : line 1274
/*
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
_ASSERTE(_CrtIsValidHeapPointer(pUserData));
Run Code Online (Sandbox Code Playgroud)
我假设这是因为内存已经分配在DLL文件1的堆上,但是在DLL文件2中被释放.
评论dbgheap.c似乎非常坚持这是一个问题.
为什么这是一个问题,如果我忽略它似乎工作正常?是否有一种非断言失败的方式来做到这一点?
我是单元测试的新手,我正在学习如何使用NUnit和Moq.NUnit提供Assert了在单元测试中测试条件的语法,而Moq提供了一些Verify功能.在某种程度上,这些似乎提供了相同的功能.
我怎么知道何时使用Assert或更合适Verify?
也许Assert更好地确认状态,并且Verify更好地确认行为(古典与模仿)?
是否有类似于CollectionAssert.AreEquivalent()的东西,它适用于嵌套集合?
以下代码......
CollectionAssert.AreEquivalent (
new Dictionary<int, Dictionary<int, string>>
{
{ 1, new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } },
{ 2, new Dictionary < int, string > { { 20, "eggs" }, { 21, "eels" } } },
{ 3, new Dictionary < int, string > { { 30, "hovercraft" } } }
},
new Dictionary<int, Dictionary<int, string>>
{
{ 1, new Dictionary < int, string > …Run Code Online (Sandbox Code Playgroud) 通常的做法可能是在应用程序开发期间将断言放入代码中以检查输入参数,数据完整性等.
我测试我的应用程序,但是,鉴于我不是Knuth(并且他写了1美元的支票),而且我不能像一些医疗和太空系统软件公司那样雇用一支庞大的全职QA团队,我假设所有应用程序总是会有大量的错误,这些错误在测试或质量检查期间从未见过.假设在其他方面似乎非常不诚实.因此,在测试应用程序(显然删除导致任何先前看到的ASSERT失败的所有错误)并准备好将应用程序发送给Apple之后,应该如何处理发布/分发版本中的所有ASSERT检查?请假或禁止?
这里有一个理由让他们离开:如果一个应用程序对某些用户来说很不稳定,那么该应用程序可能会被这些用户评为1星级,而没有人告诉开发人员为什么足够详细.但是如果应用程序因ASSERT故障而崩溃,那么应用程序可能仍然会被评为1星级,但是如果有足够多的用户选择进入,开发人员可能通过iTunes和iTunes Connect间接获得一些故障转储,以找出问题所在.如果苹果公司因全新的ASSERT崩溃而被Apple拒绝,这将阻止该应用程序的恶劣版本进入客户的设备.
我正在学习C并在C中尝试粗略实现链表.长话短说我有一个只包含一个void指针(元素)的结构和另一个指向下一个节点的指针.(代码要遵循)我的问题是,当通过时头节点和其他一些节点成新函数,有没有办法确保两个元素属于同一类型?两个节点应该能够保存任何类型的数据.我已经尝试与sizeof()进行比较,但我无法顺从void指针.提前致谢!
struct Node{
void* element;
struct Node* next;
}
Run Code Online (Sandbox Code Playgroud)
这是节点的代码,我只需要一种方法将它们与assert进行比较,以确保链接列表具有所有相同的元素类型!谢谢!
在Symfony中,我可以使用以下方法接受MIME类型:
/**
* @Assert\File( maxSize="10M", mimeTypes={"application/pdf", "image/png"} )
*/
public $file;
Run Code Online (Sandbox Code Playgroud)
但是如何从该列表中排除某些内容?比方说,我想允许除PHP文件之外的所有上传?
为什么assertjava中有关键字,而不是方法?
方法断言可能如下所示:
public static void assert(boolean condition) {
if(!condition) {
throw new AssertionError();
}
}
Run Code Online (Sandbox Code Playgroud) 背景: 在Objective-C中,我将创建包含调试信息的断言:
NSAssert(poetCount > 5, "Expected poetCount > 5; Actual: %d", poetCount);
Run Code Online (Sandbox Code Playgroud)
但是,assertSwift中的全局函数似乎不允许这样,因为message参数是一个StaticString.所以我不能这样做:
assert(NSFileManager.defaultManager().fileExistsAtPath(fullpath),
"Expected: File to Exist @ \(fullpath)")
Run Code Online (Sandbox Code Playgroud)
问题:是否存在assert不需要静态字符串的替代函数,或者NSAssert如果我想提供额外信息以使调试更容易,我应该继续使用吗?
我正在尝试找到一种更好的方法来断言给定数据帧的Python/Pandas中的列数据类型.
例如:
import pandas as pd
t = pd.DataFrame({'a':[1,2,3], 'b':[2,6,0.75], 'c':['foo','bar','beer']})
Run Code Online (Sandbox Code Playgroud)
我想声明数据框中的特定列是数字.这就是我所拥有的:
numeric_cols = ['a', 'b'] # These will be given
assert [x in ['int64','float'] for x in [t[y].dtype for y in numeric_cols]]
Run Code Online (Sandbox Code Playgroud)
最后一个断言行不会感觉非常pythonic.也许是这样,我只是在一条难以理解的线上塞满了它.有没有更好的办法?我想写一些类似的东西:
assert t[numeric_cols].dtype.isnumeric()
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到类似的东西.
这就像断言甚至没有被调用.我很迷惑.
版本
:~/code/x/test$ php -v
PHP 7.0.11-1+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.11-1+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies
Run Code Online (Sandbox Code Playgroud)
剧本
:~/code/x/test$ cat x.php
<?php
print ("Hello\n");
assert_options(ASSERT_ACTIVE,true);
assert_options(ASSERT_BAIL,true);
assert(false);
assert(true);
print ("Bye\n");
Run Code Online (Sandbox Code Playgroud)
当我运行它
:~/code/x/test$ php x.php
Hello
Bye
Run Code Online (Sandbox Code Playgroud)
我本来希望程序以异常终止.我疯了吗?