// Copyright (c) 2005-2006 Chris Miceli (cmicel1@cct.lsu.edu) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #if !defined(SAGA_TEST_FILE_HPP) #define SAGA_TEST_FILE_HPP //#include #include #include #include #include #include #include #include #include #include namespace fs = boost::filesystem; #include "test_api.hpp" #include "test_functions.hpp" // test get_url structure. This structure handles all types of tasks and uses // test_functions capable of handling all exceptions for test get_url api function. // first test is for 3 defined types of tasks and second for when no task is used. struct test_file_get_url { // Supported exceptions by api function get_url typedef boost::mpl::vector_c error_codes; static std::string name; //test using generalization for 3 types of defined tasks. template int test(saga::session s, std::string f, Tag tag) { std::string url; saga::task t; saga::file file(s, f); t = file.get_url(url); verify_created_state(t); run_check_state(t); wait_check_state(t); BOOST_CHECK_EQUAL(url, f); return 0; } //test explicitly defined for when no task is in use. int test(saga::session s, std::string f, PlainSync t) { std::string url; saga::file file(s, f); url = file.get_url(); BOOST_CHECK_EQUAL(url, f); return 0; } }; //test_file_get_url // test get_cwd structure. This structure handles all types of tasks and uses // test_functions capable of handling all exceptions for api function get_url. // first test is for 3 defined types of tasks and second for when no task is used. struct test_file_get_cwd { // Supported exceptions by api function get_url typedef boost::mpl::vector_c error_codes; static std::string name; template int test(saga::session s, std::string f, Tag tag) { std::string cwd; saga::task t; saga::file file(s, f); saga::url url(f); t = file.get_cwd(cwd); verify_created_state(t); run_check_state(t); wait_check_state(t); std::string path = std::string(url.get_scheme() +"://" +url.get_host()+"/" +(fs::path(url.get_path())).branch_path().string() +"/"); BOOST_CHECK_EQUAL(cwd, path); return 0; } int test(saga::session s, std::string f, PlainSync t) { std::string cwd; saga::file file(s, f); saga::url url(f); cwd = file.get_cwd(); std::string path = std::string(url.get_scheme() +"://" +url.get_host()+"/" +(fs::path(url.get_path())).branch_path().string() +"/"); BOOST_CHECK_EQUAL(cwd, path); return 0; } }; //test_file_get_cwd // test get_name structure. This structure handles all types of tasks and uses // test_functions capable of handling all exceptions for api function get_name. // first test is for 3 defined types of tasks and second for when no task is used. struct test_file_get_name { // Supported exceptions by api function get_url typedef boost::mpl::vector_c error_codes; static std::string name; template int test(saga::session s, std::string f, Tag tag) { std::string name; saga::url fileurl(f); saga::task t; saga::file file(s, f); t = file.get_name(name); verify_created_state(t); run_check_state(t); wait_check_state(t); BOOST_CHECK_EQUAL(name, (fs::path(fileurl.get_path())).leaf()); return 0; } int test(saga::session s, std::string f, PlainSync t) { std::string name; saga::file file(s, f); saga::url fileurl(f); name = file.get_name(); BOOST_CHECK_EQUAL(name, (fs::path(fileurl.get_path())).leaf()); return 0; } }; //test_file_get_name struct test_file_is_dir { // Supported exceptions by api function get_url typedef boost::mpl::vector_c error_codes; static std::string name; template int test(saga::session s, std::string f, Tag tag) { bool is_dir = true; saga::task t; saga::file file(s, f); t = file.is_dir(is_dir); verify_created_state(t); run_check_state(t); wait_check_state(t); BOOST_CHECK(!is_dir); return 0; } int test(saga::session s, std::string f, PlainSync t) { bool is_dir = false; saga::file file(s, f); is_dir = file.is_dir(); BOOST_CHECK(!is_dir); return 0; } }; //test_file_is_dir // test is_entry structure. This structure handles all types of tasks and uses // test_functions capable of handling all exceptions for api function is_entry. // first test is for 3 defined types of tasks and second for when no task is used. struct test_file_is_entry { // Supported exceptions by api function get_url typedef boost::mpl::vector_c error_codes; static std::string name; template int test(saga::session s, std::string f, Tag tag) { bool is_entry = false; saga::task t; saga::file file(s, f); t = file.is_entry(is_entry); verify_created_state(t); run_check_state(t); wait_check_state(t); BOOST_CHECK(is_entry); return 0; } int test(saga::session s, std::string f, PlainSync t) { bool is_entry = false; saga::file file(s, f); is_entry = file.is_entry(); BOOST_CHECK(is_entry); return 0; } }; //test_file_is_entry #if BOOST_VERSION >= 103400 // test is_link structure. This structure handles all types of tasks and uses // test_functions capable of handling all exceptions for api function is_link. // first test is for 3 defined types of tasks and second for when no task is used. struct test_file_is_link //original takes parameter { // Supported exceptions by api function get_url typedef boost::mpl::vector_c error_codes; static std::string name; template int test(saga::session s, std::string f, Tag tag) { bool is_link = false; saga::task t; saga::file file(s, f); t = file.is_link(is_link); verify_created_state(t); run_check_state(t); wait_check_state(t); BOOST_CHECK(is_link); return 0; } int test(saga::session s, std::string f, PlainSync t) { bool is_link = false; saga::file file(s, f); is_link = file.is_link(); BOOST_CHECK(is_link); return 0; } }; //test_file_is_link #endif // BOOST_VERSION >= 103400 // test read_write structure. This structure handles all types of tasks and uses // test_functions capable of handling all exceptions for api functions read, write // seek, and get_size first test is for 3 defined types of tasks and // second for when no task is used. struct test_file_read_write { typedef boost::mpl::vector_c error_codes; static std::string name; template int test(saga::session s, std::string f, Tag tag) { const char txt[] = "Some test string"; char inbuff[64]; saga::ssize_t writtenbytes = 0; saga::off_t offset = 0; saga::ssize_t readbytes = 0; saga::off_t file_size = 0; saga::file file(s, f); saga::task t1=file.write(writtenbytes, txt, sizeof(txt)); saga::task t2=file.seek(offset, 0, saga::file::Start);; saga::task t3=file.read(readbytes, inbuff, sizeof(inbuff)); saga::task t4=file.get_size(file_size); verify_created_state(t1); run_check_state(t1); wait_check_state(t1); verify_created_state(t2); run_check_state(t2); wait_check_state(t2); verify_created_state(t3); run_check_state(t3); wait_check_state(t3); verify_created_state(t4); run_check_state(t4); wait_check_state(t4); BOOST_CHECK_EQUAL(ssize_t(sizeof(txt)), writtenbytes); BOOST_CHECK_EQUAL(0, offset); BOOST_CHECK_EQUAL(ssize_t(sizeof(txt)), readbytes); BOOST_CHECK_EQUAL(std::string(inbuff), std::string(txt)); BOOST_CHECK_EQUAL(off_t(sizeof(txt)), file_size); return 0; } int test(saga::session s, std::string f, PlainSync t) { const char txt[] = "Some test string"; char inbuff[64]; saga::file file(s, f); BOOST_CHECK_EQUAL(ssize_t(sizeof(txt)), file.write(txt, sizeof(txt))); BOOST_CHECK_EQUAL(off_t(0), file.seek(0, saga::file::Start)); BOOST_CHECK_EQUAL(ssize_t(sizeof(txt)), file.read(inbuff, sizeof(inbuff))); BOOST_CHECK_EQUAL(std::string(inbuff), std::string(txt)); BOOST_CHECK_EQUAL(off_t(sizeof(txt)), file.get_size()); return 0; } }; //test_file_read_write namespace test_file_all { class test_functions { private: saga::test::test_helper_utils * utils_; public: test_functions(saga::test::test_helper_utils * utils) : utils_(utils) {} ~test_functions() {} }; class suite : public boost::unit_test_framework::test_suite { public: struct add_tests { add_tests(suite& outer) : outer_(outer) {} template void operator()(Test) { outer_.add(BOOST_TEST_CASE(boost::bind(&test_api::run_test::execute, outer_.utils_))); } suite& outer_; }; suite (saga::test::test_helper_utils * utils) : test_suite ("saga::get_url test suite"), utils_(utils) { typedef boost::mpl::vector= 103400 test_file_is_link, #endif //BOOST_VERSION >= 103400 test_file_read_write > apitests; boost::mpl::for_each(add_tests(*this)); } saga::test::test_helper_utils *utils_; }; }//End namespace test_file_all #endif // !SAGA_TEST_FILE_HPP