⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maildirstoretest.cpp

📁 MIME解析的代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//// VMime library (http://www.vmime.org)// Copyright (C) 2002-2008 Vincent Richard <vincent@vincent-richard.net>//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License as// published by the Free Software Foundation; either version 2 of// the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// General Public License for more details.//// You should have received a copy of the GNU General Public License along// with this program; if not, write to the Free Software Foundation, Inc.,// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.//// Linking this library statically or dynamically with other modules is making// a combined work based on this library.  Thus, the terms and conditions of// the GNU General Public License cover the whole combination.//#include "tests/testUtils.hpp"#include "vmime/platform.hpp"#include "vmime/net/maildir/maildirStore.hpp"#include "vmime/net/maildir/maildirFormat.hpp"#define VMIME_TEST_SUITE         maildirStoreTest#define VMIME_TEST_SUITE_MODULE  "Net/Maildir"// Shortcuts and helperstypedef vmime::utility::file::path fspath;typedef vmime::utility::file::path::component fspathc;typedef vmime::net::folder::path fpath;typedef vmime::net::folder::path::component fpathc;const fpath operator/(const fpath& path, const std::string& c){	return path / fpathc(c);}/** Test messages */static const vmime::string TEST_MESSAGE_1 =	"From: <test@vmime.org>\r\n"	"Subject: VMime Test\r\n"	"Date: Thu, 01 Mar 2007 09:49:35 +0100\r\n"	"\r\n"	"Hello, world!";/** Maildir trees used in tests.  * Structure:  *  *  .  *  |-- Folder  *  |   `-- SubFolder  *  |       |-- SubSubFolder1  *  |       `-- SubSubFolder2  *  `-- Folder2  *  */// KMail formatstatic const vmime::string TEST_MAILDIR_KMAIL[] =  // directories to create{	"/Folder",	"/Folder/new",	"/Folder/tmp",	"/Folder/cur",	"/.Folder.directory",	"/.Folder.directory/SubFolder",	"/.Folder.directory/SubFolder/new",	"/.Folder.directory/SubFolder/tmp",	"/.Folder.directory/SubFolder/cur",	"/.Folder.directory/.SubFolder.directory",	"/.Folder.directory/.SubFolder.directory/SubSubFolder1",	"/.Folder.directory/.SubFolder.directory/SubSubFolder1/new",	"/.Folder.directory/.SubFolder.directory/SubSubFolder1/tmp",	"/.Folder.directory/.SubFolder.directory/SubSubFolder1/cur",	"/.Folder.directory/.SubFolder.directory/SubSubFolder2",	"/.Folder.directory/.SubFolder.directory/SubSubFolder2/new",	"/.Folder.directory/.SubFolder.directory/SubSubFolder2/tmp",	"/.Folder.directory/.SubFolder.directory/SubSubFolder2/cur",	"/Folder2",	"/Folder2/new",	"/Folder2/tmp",	"/Folder2/cur",	"*"  // end};static const vmime::string TEST_MAILDIRFILES_KMAIL[] =  // files to create and their contents{	"/.Folder.directory/.SubFolder.directory/SubSubFolder2/cur/1043236113.351.EmqD:S", TEST_MESSAGE_1,	"*"  // end};// Courier formatstatic const vmime::string TEST_MAILDIR_COURIER[] =  // directories to create{	"/.Folder",	"/.Folder/new",	"/.Folder/tmp",	"/.Folder/cur",	"/.Folder.SubFolder",	"/.Folder.SubFolder",	"/.Folder.SubFolder/new",	"/.Folder.SubFolder/tmp",	"/.Folder.SubFolder/cur",	"/.Folder.SubFolder.SubSubFolder1",	"/.Folder.SubFolder.SubSubFolder1/new",	"/.Folder.SubFolder.SubSubFolder1/tmp",	"/.Folder.SubFolder.SubSubFolder1/cur",	"/.Folder.SubFolder.SubSubFolder2",	"/.Folder.SubFolder.SubSubFolder2/new",	"/.Folder.SubFolder.SubSubFolder2/tmp",	"/.Folder.SubFolder.SubSubFolder2/cur",	"/.Folder2",	"/.Folder2/new",	"/.Folder2/tmp",	"/.Folder2/cur",	"*"  // end};static const vmime::string TEST_MAILDIRFILES_COURIER[] =  // files to create and their contents{	"/.Folder/maildirfolder", "",	"/.Folder.SubFolder/maildirfolder", "",	"/.Folder.SubFolder.SubSubFolder1/maildirfolder", "",	"/.Folder.SubFolder.SubSubFolder2/maildirfolder", "",	"/.Folder.SubFolder.SubSubFolder2/cur/1043236113.351.EmqD:S", TEST_MESSAGE_1,	"/.Folder2/maildirfolder", "",	"*"  // end};VMIME_TEST_SUITE_BEGIN	VMIME_TEST_LIST_BEGIN		VMIME_TEST(testDetectFormat_KMail)		VMIME_TEST(testDetectFormat_Courier)		VMIME_TEST(testListRootFolders_KMail)		VMIME_TEST(testListAllFolders_KMail)		VMIME_TEST(testListRootFolders_Courier)		VMIME_TEST(testListAllFolders_Courier)		VMIME_TEST(testListMessages_KMail)		VMIME_TEST(testListMessages_Courier)		VMIME_TEST(testRenameFolder_KMail)		VMIME_TEST(testRenameFolder_Courier)		VMIME_TEST(testDestroyFolder_KMail)		VMIME_TEST(testDestroyFolder_Courier)		VMIME_TEST(testFolderExists_KMail)		VMIME_TEST(testFolderExists_Courier)		VMIME_TEST(testCreateFolder_KMail)		VMIME_TEST(testCreateFolder_Courier)	VMIME_TEST_LIST_ENDpublic:	maildirStoreTest()	{		// Temporary directory		m_tempPath = fspath() / fspathc("tmp")   // Use /tmp			/ fspathc("vmime" + vmime::utility::stringUtils::toString(std::time(NULL))				+ vmime::utility::stringUtils::toString(std::rand()));	}	void tearDown()	{		// In case of an uncaught exception		destroyMaildir();	}	void testDetectFormat_KMail()	{		createMaildir(TEST_MAILDIR_KMAIL, TEST_MAILDIRFILES_KMAIL);		vmime::ref <vmime::net::maildir::maildirStore> store =			vmime::dynamicCast <vmime::net::maildir::maildirStore>(createAndConnectStore());		VASSERT_EQ("*", "kmail", store->getFormat()->getName());		destroyMaildir();	}	void testDetectFormat_Courier()	{		createMaildir(TEST_MAILDIR_COURIER, TEST_MAILDIRFILES_COURIER);		vmime::ref <vmime::net::maildir::maildirStore> store =			vmime::dynamicCast <vmime::net::maildir::maildirStore>(createAndConnectStore());		VASSERT_EQ("*", "courier", store->getFormat()->getName());		destroyMaildir();	}	void testListRootFolders_KMail()	{		testListRootFoldersImpl(TEST_MAILDIR_KMAIL, TEST_MAILDIRFILES_KMAIL);	}	void testListRootFolders_Courier()	{		testListRootFoldersImpl(TEST_MAILDIR_COURIER, TEST_MAILDIRFILES_COURIER);	}	void testListRootFoldersImpl(const vmime::string* const dirs, const vmime::string* const files)	{		createMaildir(dirs, files);		// Connect to store		vmime::ref <vmime::net::store> store = createAndConnectStore();		vmime::ref <vmime::net::folder> rootFolder = store->getRootFolder();		// Get root folders, not recursive		const std::vector <vmime::ref <vmime::net::folder> >			rootFolders = rootFolder->getFolders(false);		VASSERT_EQ("1", 2, rootFolders.size());		VASSERT("2", findFolder(rootFolders, fpath() / "Folder") != NULL);		VASSERT("3", findFolder(rootFolders, fpath() / "Folder2") != NULL);		destroyMaildir();	}	void testListAllFolders_KMail()	{		testListAllFoldersImpl(TEST_MAILDIR_KMAIL, TEST_MAILDIRFILES_KMAIL);	}	void testListAllFolders_Courier()	{		testListAllFoldersImpl(TEST_MAILDIR_COURIER, TEST_MAILDIRFILES_COURIER);	}	void testListAllFoldersImpl(const vmime::string* const dirs, const vmime::string* const files)	{		createMaildir(dirs, files);		// Connect to store		vmime::ref <vmime::net::store> store = createAndConnectStore();		vmime::ref <vmime::net::folder> rootFolder = store->getRootFolder();		// Get all folders, recursive		const std::vector <vmime::ref <vmime::net::folder> >			allFolders = rootFolder->getFolders(true);		VASSERT_EQ("1", 5, allFolders.size());		VASSERT("2", findFolder(allFolders, fpath() / "Folder") != NULL);		VASSERT("3", findFolder(allFolders, fpath() / "Folder" / "SubFolder") != NULL);		VASSERT("4", findFolder(allFolders, fpath() / "Folder" / "SubFolder" / "SubSubFolder1") != NULL);		VASSERT("5", findFolder(allFolders, fpath() / "Folder" / "SubFolder" / "SubSubFolder2") != NULL);		VASSERT("6", findFolder(allFolders, fpath() / "Folder2") != NULL);		destroyMaildir();	}	void testListMessages_KMail()	{		testListMessagesImpl(TEST_MAILDIR_KMAIL, TEST_MAILDIRFILES_KMAIL);	}	void testListMessages_Courier()	{		testListMessagesImpl(TEST_MAILDIR_COURIER, TEST_MAILDIRFILES_COURIER);	}	void testListMessagesImpl(const vmime::string* const dirs, const vmime::string* const files)	{		createMaildir(dirs, files);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -