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

📄 filesystem_traits_unittest_.h

📁 新版本TR1的stl
💻 H
📖 第 1 页 / 共 2 页
字号:

// Updated: 12th March 2007

#if !defined(WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS)
# error This file cannot be directly included, and should only be included within winstl/filesystem/filesystem_traits.hpp
#endif /* !WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS */

#if !defined(STLSOFT_UNITTEST)
# error This file cannot be included when not unit-testing STLSoft
#endif /* !STLSOFT_UNITTEST */

namespace unittest
{
	namespace
	{
		typedef filesystem_traits<char> 	filesystem_traits_a_t;
		typedef filesystem_traits<wchar_t>	filesystem_traits_w_t;

		ss_bool_t test_filesystem_traits_get_full_path_name(unittest_reporter *r)
		{
			ss_bool_t	bSuccess	=	true;

			char		sz1[1 + 4096];
			char		sz2[1 + 4096];
			char		cwd[1 + 4096];

			if(0 == ::GetCurrentDirectoryA(STLSOFT_NUM_ELEMENTS(cwd), cwd))
			{
				r->report("Failed to get current directory", __LINE__);
				bSuccess = false;
			}
			else
			{
				char		*pFile1;
				char		*pFile2;
				ss_size_t	cch1	=	filesystem_traits_a_t::get_full_path_name(".", STLSOFT_NUM_ELEMENTS(sz1), sz1, &pFile1);
				ss_size_t	cch2	=	filesystem_traits_a_t::get_full_path_name(cwd, STLSOFT_NUM_ELEMENTS(sz2), sz2, &pFile2);

				STLSOFT_SUPPRESS_UNUSED(cch1);
				STLSOFT_SUPPRESS_UNUSED(cch2);

				if( 0 != filesystem_traits_a_t::str_compare(sz1, sz2) ||
					0 != filesystem_traits_a_t::str_compare(pFile1, pFile2))
				{
					r->report("Directory equivalence failed", __LINE__);
					bSuccess = false;
				}

				filesystem_traits_a_t::str_cat(filesystem_traits_a_t::ensure_dir_end(cwd), "..\\..");

				cch1	=	filesystem_traits_a_t::get_full_path_name("..\\..", STLSOFT_NUM_ELEMENTS(sz1), sz1, &pFile1);
				cch2	=	filesystem_traits_a_t::get_full_path_name(cwd, STLSOFT_NUM_ELEMENTS(sz2), sz2, &pFile2);

				STLSOFT_SUPPRESS_UNUSED(cch1);
				STLSOFT_SUPPRESS_UNUSED(cch2);

				if( 0 != filesystem_traits_a_t::str_compare(sz1, sz2) ||
					0 != filesystem_traits_a_t::str_compare(pFile1, pFile2))
				{
					r->report("Directory equivalence failed", __LINE__);
					bSuccess = false;
				}
			}

			return bSuccess;
		}

		ss_bool_t test_filesystem_traits_string_handling(unittest_reporter *r)
		{
			ss_bool_t	bSuccess	=	true;

			char	buff1[101];
//			  char	  buff2[101];
//			  char	  buff3[101];

			char	*psz1;
//			  char	  *psz2;
//			  char	  *psz3;

			psz1 = filesystem_traits_a_t::str_copy(buff1, "Hello");
			if(0 != strcmp(buff1, "Hello"))
			{
				r->report("str_copy() failure", __LINE__);
				bSuccess = false;
			}
			if(0 != strcmp(buff1, psz1))
			{
				r->report("str_copy() failure", __LINE__);
				bSuccess = false;
			}
#if 0
	/* static char_type    *str_copy(char_type *dest, char_type const* src) */
	static char_type	*str_n_copy(char_type *dest, char_type const* src, size_type cch);
	static char_type	*str_cat(char_type *dest, char_type const* src);
	static char_type	*str_n_cat(char_type *dest, char_type const* src, size_type cch);
	static int_type 	str_compare(char_type const* s1, char_type const* s2);
	static int_type 	str_compare_no_case(char_type const* s1, char_type const* s2);
	static size_type	str_len(char_type const* src);
	static char_type	*str_chr(char_type const* s, char_type ch);
	static char_type	*str_rchr(char_type const* s, char_type ch);
	static char_type	*str_str(char_type const* s, char_type const* sub);
#endif /* 0 */

			;

			return bSuccess;
		}

		ss_bool_t test_filesystem_traits_filesystem_entry_names(unittest_reporter *r)
		{
			ss_bool_t	bSuccess	=	true;

			if(!test_filesystem_traits_get_full_path_name(r))
			{
				bSuccess = false;
			}

#if 0
	static char_type	*ensure_dir_end(char_type *dir);
	static char_type	*remove_dir_end(char_type *dir);
	static bool_type	has_dir_end(char_type const* dir);
#endif /* 0 */

			// has_dir_end()
			{
				static const char	*ended_dirs[] =
				{
						"\\"
					,	"/"
					,	"a\\"
					,	"a/"
					,	"\\a\\"
					,	"/a/"
					,	"H:\\"
					,	"H:/"
					,	"H:a\\"
					,	"H:a/"
					,	"\\\\a\\"
					,	"\\\\a\b\\"
					,	"\\\\a\b/"
				};

				static const char	*unended_dirs[] =
				{
						"a"
					,	"a"
					,	"\\a"
					,	"/a"
					,	"H:"
					,	"H:"
					,	"H:a"
					,	"H:a"
					,	"H:\\a"
					,	"H:/a"
					,	"\\\\a"
				};

				{ for(size_t i = 0; i < STLSOFT_NUM_ELEMENTS(ended_dirs); ++i)
				{
					if(!filesystem_traits_a_t::has_dir_end(ended_dirs[i]))
					{
						char	message[101];

						wsprintf(message, "\"%s\" not identified by has_dir_end()", ended_dirs[i]);

						r->report(message, __LINE__);
						bSuccess = false;
					}
				}}

				{ for(size_t i = 0; i < STLSOFT_NUM_ELEMENTS(unended_dirs); ++i)
				{
					if(filesystem_traits_a_t::has_dir_end(unended_dirs[i]))
					{
						char	message[101];

						wsprintf(message, "\"%s\" wrongly identified by has_dir_end()", unended_dirs[i]);

						r->report(message, __LINE__);
						bSuccess = false;
					}
				}}
			}

#if 0
	/* static bool_type    is_dots(char_type const* dir); */
	/* static bool_type    is_path_rooted(char_type const* path); */
	/* static bool_type    is_path_absolute(char_type const* path); */
	/* static bool_type    is_path_UNC(char_type const* path); */
	/* static bool_type    is_path_name_separator(char_type ch); */
#endif /* 0 */


			// is_dots()
			if(!filesystem_traits_a_t::is_dots("."))
			{
				r->report("Failed to identify \".\" as a dots directory", __LINE__);
				bSuccess = false;
			}
			if(!filesystem_traits_a_t::is_dots(".."))
			{
				r->report("Failed to identify \".\" as a dots directory", __LINE__);
				bSuccess = false;
			}
			if(filesystem_traits_a_t::is_dots(".a"))
			{
				r->report("Falsely identified \".a\" as a dots directory", __LINE__);
				bSuccess = false;
			}
			if(filesystem_traits_a_t::is_dots("..a"))
			{
				r->report("Falsely identified \"..a\" as a dots directory", __LINE__);
				bSuccess = false;
			}
			if(filesystem_traits_a_t::is_dots("a."))
			{
				r->report("Falsely identified \"a.\" as a dots directory", __LINE__);
				bSuccess = false;
			}
			if(filesystem_traits_a_t::is_dots("..a"))
			{
				r->report("Falsely identified \"a..\" as a dots directory", __LINE__);
				bSuccess = false;
			}

			// is_path_rooted()
			{
				static const char	*rooted_dirs[] =
				{
						"\\"
					,	"/"
					,	"\\a"
					,	"/a"
					,	"\\a\\"
					,	"/a/"
					,	"H:\\"
					,	"H:/"
					,	"H:\\a"
					,	"H:/a"
					,	"\\\\a"
					,	"\\\\a\\"
					,	"\\\\a\b\\"
					,	"\\\\a\b/"
				};

				static const char	*unrooted_dirs[] =
				{
						"a"
					,	"a"
					,	"a\\"
					,	"a/"
					,	"H:"
					,	"H:"
					,	"H:a"
					,	"H:a"
					,	"H:a\\"
					,	"H:a/"
				};

				{ for(size_t i = 0; i < STLSOFT_NUM_ELEMENTS(rooted_dirs); ++i)
				{
					if(!filesystem_traits_a_t::is_path_rooted(rooted_dirs[i]))
					{
						char	message[101];

						wsprintf(message, "\"%s\" not identified by is_path_rooted()", rooted_dirs[i]);

						r->report(message, __LINE__);
						bSuccess = false;
					}
				}}

				{ for(size_t i = 0; i < STLSOFT_NUM_ELEMENTS(unrooted_dirs); ++i)
				{
					if(filesystem_traits_a_t::is_path_rooted(unrooted_dirs[i]))
					{
						char	message[101];

						wsprintf(message, "\"%s\" wrongly identified by is_path_rooted()", unrooted_dirs[i]);

						r->report(message, __LINE__);
						bSuccess = false;
					}
				}}
			}

			// is_path_absolute()
			{
				static const char	*absolute_dirs[] =
				{
						"H:\\"
					,	"H:/"
					,	"H:\\a"
					,	"H:/a"
					,	"\\\\a"
					,	"\\\\a\\"
					,	"\\\\a\b\\"
					,	"\\\\a\b/"
				};

				static const char	*unabsolute_dirs[] =
				{
						"a"
					,	"a"
					,	"a\\"
					,	"a/"
					,	"H:"
					,	"H:"
					,	"H:a"
					,	"H:a"
					,	"H:a\\"
					,	"H:a/"
					,	"\\"
					,	"/"
					,	"\\a"
					,	"/a"
					,	"\\a\\"
					,	"/a/"
				};

⌨️ 快捷键说明

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