[英]Boost unit testing main function?
在使用boost進行測試時,如何定義自己的main()
函數?
Boost正在使用它自己的主要功能,但是我使用的是自定義內存管理器,它需要在分配任何內存之前進行初始化,否則我會收到錯誤。
我不相信你真的需要自己的主力。 我認為你的全球裝備要好得多:
struct AllocatorSetup {
AllocatorSetup() { /* setup your allocator here */ }
~AllocatorSetup() { /* shutdown your allocator/check memory leaks here */ }
};
BOOST_GLOBAL_FIXTURE( AllocatorSetup );
你必須定義
BOOST_TEST_NO_MAIN
在提升包括之前。
BOOST_TEST_MAIN
是默認值。 http://www.boost.org/doc/libs/1_36_0/libs/test/doc/html/utf/compilation.html
你可以定義一個靜態對象,他的構造函數將在main之前執行:
class Alloc_Setup {
Alloc_Setup() {
// Your init code
}
~Alloc_Setup() {
// Your cleanup
}
};
Alloc_Setup setup;
int main() {} // (generated by boost)
內存可以在main
之前分配:
static int* x = new int(1);
int main() { return *x; }
你也可以讓你的記憶管理器成為一個全局變量,
但是你不能強制執行特定的全局變量初始化順序。 (至少在標准C ++中)
在Windows中,您可以將內存管理器放入DLL中,它將在調用應用程序入口點之前進行初始化,但仍然可以在之前分配內存 - 另一個DLL或DLL的CRT。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.