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

📄 filesystem_traits_unittest_.h

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 H
📖 第 1 页 / 共 2 页
字号:
                { for(size_t i = 0; i < STLSOFT_NUM_ELEMENTS(absolute_dirs); ++i)
                {
                    if(!traits_a_t::is_path_absolute(absolute_dirs[i]))
                    {
                        char    message[101];

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

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

                { for(size_t i = 0; i < STLSOFT_NUM_ELEMENTS(unabsolute_dirs); ++i)
                {
                    if(traits_a_t::is_path_absolute(unabsolute_dirs[i]))
                    {
                        char    message[101];

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

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

            // is_path_UNC()
            {
                static const char   *UNC_dirs[] =
                {
                        "\\\\a"
                    ,   "\\\\a\\"
                    ,   "\\\\a\b\\"
                    ,   "\\\\a\b/"
                };

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

                { for(size_t i = 0; i < STLSOFT_NUM_ELEMENTS(UNC_dirs); ++i)
                {
                    if(!traits_a_t::is_path_UNC(UNC_dirs[i]))
                    {
                        char    message[101];

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

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

                { for(size_t i = 0; i < STLSOFT_NUM_ELEMENTS(unUNC_dirs); ++i)
                {
                    if(traits_a_t::is_path_UNC(unUNC_dirs[i]))
                    {
                        char    message[101];

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

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

            // is_path_name_separator()

            { for(traits_a_t::char_type ch = 0; ch <= ~static_cast<traits_a_t::char_type>(0); ++ch)
            {
                if(traits_a_t::is_path_name_separator(ch))
                {
                    if( '/' != ch &&
                        '\\' != ch)
                    {
                        char    message[101];

                        wsprintf(message, "'%c' (%d) not identified as a path name separator", ch, ch);

                        r->report(message, __LINE__);
                        bSuccess = false;
                    }
                }
                else
                {
                    if('/' == ch)
                    {
                        r->report("'/' not identified as a path name separator", __LINE__);
                        bSuccess = false;
                    }
                    if('\\' == ch)
                    {
                        r->report("'\' not identified as a path name separator", __LINE__);
                        bSuccess = false;
                    }
                }
            }}

#if 0
    static char_type    path_separator();
    static char_type    path_name_separator();
    static char_type const *pattern_all();
    static size_type    path_max();
#endif /* 0 */

#if 0
    static size_type    get_full_path_name(char_type const *fileName, size_type cchBuffer, char_type *buffer, char_type **ppFile);
    static size_type    get_full_path_name(char_type const *fileName, size_type cchBuffer, char_type *buffer);
    static size_type    get_short_path_name(char_type const *fileName, size_type cchBuffer, char_type *buffer);
#endif /* 0 */


            ;

            return bSuccess;
        }

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

            STLSOFT_SUPPRESS_UNUSED(r);

#if 0
    static HANDLE       find_first_file(char_type const *spec, find_data_type *findData);
#if _WIN32_WINNT >= 0x0400
    static HANDLE       find_first_file_ex(char_type const *spec, FINDEX_SEARCH_OPS flags, find_data_type *findData);
#endif /* _WIN32_WINNT >= 0x0400 */
    static bool_type    find_next_file(HANDLE h, find_data_type *findData);
    static void         find_file_close(HANDLE h);
#ifndef _WINSTL_NO_FINDVOLUME_API
    static HANDLE       find_first_volume(char_type *volume_name, size_type cch_volume_name);
    static bool_type    find_next_volume(HANDLE h, char_type *volume_name, size_type cch_volume_name);
    static void         find_volume_close(HANDLE h);
#endif // !_WINSTL_NO_FINDVOLUME_API
#endif /* 0 */


            ;

            return bSuccess;
        }

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

            STLSOFT_SUPPRESS_UNUSED(r);

#if 0
    static size_type    get_module_filename(HINSTANCE hModule, char_type *buffer, size_type cchBuffer);
    static size_type    get_system_directory(char_type *buffer, size_type cchBuffer);
    static size_type    get_windows_directory(char_type *buffer, size_type cchBuffer);
#endif /* 0 */


            ;

            return bSuccess;
        }

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

            traits_a_t::module_type hModule     =   traits_a_t::load_library("KERNEL32");

            if(NULL == hModule)
            {
                r->report("load_library() failed to load KERNEL32", __LINE__);
            }
            else
            {
                FARPROC sym    =   traits_a_t::find_symbol(hModule, "CreateFileA");

                if(NULL == sym)
                {
                    r->report("Failed to find \"CreateFileA\" in KERNEL32 - very suspicious!!", __LINE__);
                }

                traits_a_t::free_library(hModule);
            }

#if 0
    static module_type  load_library(char_type const *name);
    static bool_type    free_library(module_type hModule);
    static void         *find_symbol(module_type hModule, char const *symbolName);
#endif /* 0 */

            ;

            return bSuccess;
        }

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

            STLSOFT_SUPPRESS_UNUSED(r);

#if 0
    static bool_type    set_current_directory(char_type const *dir);
    static size_type    get_current_directory(size_type cchBuffer, char_type *buffer);

    static bool_type    file_exists(char_type const *fileName);
    static bool_type    is_file(char_type const *path);
    static bool_type    is_directory(char_type const *path);
    static bool_type    stat(char_type const *spec, stat_data_type *stat_data);
    static bool_type    fstat(file_handle_type fd, fstat_data_type *fstat_data);
#endif /* 0 */

            ;

            return bSuccess;
        }

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

            STLSOFT_SUPPRESS_UNUSED(r);

#if 0
    static bool_type    create_directory(char_type const *dir);
    static bool_type    create_directory(char_type const *dir, LPSECURITY_ATTRIBUTES lpsa);
    static bool_type    remove_directory(char_type const *dir);

    static bool_type    unlink_file(char_type const *file);
    static bool_type    delete_file(char_type const *file);
    static bool_type    rename_file(char_type const *currentName, char_type const *newName);
    static bool_type    copy_file(char_type const *sourceName, char_type const *newName, bool_type bFailIfExists = false);
#endif /* 0 */

#if 0
    static file_handle_type create_file(char_type const *fileName, size_type desiredAccess, size_type shareMode, LPSECURITY_ATTRIBUTES sa, size_type creationDisposition, size_type flagAndAttributes, HANDLE hTemplateFile);
    static bool_type        close_handle(HANDLE h);
    static bool_type        close_file(file_handle_type h);
#ifdef STLSOFT_CF_64BIT_INT_SUPPORT
    static ws_uint64_t      get_file_size(file_handle_type h);
#endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
#endif /* 0 */

            ;

            return bSuccess;
        }

        ss_bool_t test_winstl_filesystem_traits(unittest_reporter *r)
        {
            using stlsoft::unittest::unittest_initialiser;

            ss_bool_t               bSuccess    =   true;

            unittest_initialiser    init(r, "WinSTL", "filesystem/filesystem_traits", __FILE__);

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

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

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

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

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

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

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

            return bSuccess;
        }

        unittest_registrar    unittest_winstl_filesystem_traits(test_winstl_filesystem_traits);
    }

}// namespace unittest

⌨️ 快捷键说明

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