1e0f08c0ed
Use boost::filesystem::path for all paths, and std::string for all other strings, converting to/from wxString as close to the actual uses of wx as possible. Where possible, replace the uses of non-UI wxWidgets functionality with the additions to the standard library in C++11, or the equivalents in boost. Move the path token management logic to libaegisub (and rewrite it in the process). Add a basic thread pool based on asio and std::thread to libaegisub. This touches nearly every file in the project and a nontrivial amount of code had to be rewritten entirely, so there's probably a lot of broken stuff.
132 lines
4.2 KiB
C++
132 lines
4.2 KiB
C++
// Copyright (c) 2013, Thomas Goyne <plorkyeran@aegisub.org>
|
|
//
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
// copyright notice and this permission notice appear in all copies.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
#include <libaegisub/exception.h>
|
|
#include <libaegisub/fs.h>
|
|
#include <libaegisub/path.h>
|
|
|
|
#include "main.h"
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
using agi::Path;
|
|
|
|
#ifdef _WIN32
|
|
#define DS "\\"
|
|
#else
|
|
#define DS "/"
|
|
#endif
|
|
|
|
TEST(lagi_path, invalid_token_name_throws_internal_error) {
|
|
Path p;
|
|
|
|
// These are InternalError because the tokens are currently always hardcoded
|
|
EXPECT_THROW(p.SetToken("no ?", "path"), agi::InternalError);
|
|
EXPECT_THROW(p.SetToken("?bad", "path"), agi::InternalError);
|
|
}
|
|
|
|
TEST(lagi_path, relative_path_clears_token) {
|
|
Path p;
|
|
|
|
EXPECT_NO_THROW(p.SetToken("?video", "relative/path"));
|
|
EXPECT_STREQ("?video", p.Decode("?video").string().c_str());
|
|
|
|
EXPECT_NO_THROW(p.SetToken("?video", boost::filesystem::current_path()));
|
|
EXPECT_STRNE("?video", p.Decode("?video").string().c_str());
|
|
|
|
EXPECT_NO_THROW(p.SetToken("?video", "relative/path"));
|
|
EXPECT_STREQ("?video", p.Decode("?video").string().c_str());
|
|
}
|
|
|
|
TEST(lagi_path, empty_path_clears_token) {
|
|
Path p;
|
|
|
|
EXPECT_NO_THROW(p.SetToken("?video", boost::filesystem::current_path()));
|
|
EXPECT_STRNE("?video", p.Decode("?video").string().c_str());
|
|
|
|
EXPECT_NO_THROW(p.SetToken("?video", ""));
|
|
EXPECT_STREQ("?video", p.Decode("?video").string().c_str());
|
|
}
|
|
|
|
TEST(lagi_path, decode_sets_uses_right_slashes) {
|
|
Path p;
|
|
|
|
agi::fs::path expected = boost::filesystem::current_path()/"foo/bar.txt";
|
|
expected.make_preferred();
|
|
|
|
EXPECT_NO_THROW(p.SetToken("?video", boost::filesystem::current_path()));
|
|
|
|
agi::fs::path decoded;
|
|
ASSERT_NO_THROW(decoded = p.Decode("?video/foo/bar.txt"));
|
|
EXPECT_STREQ(expected.string().c_str(), decoded.string().c_str());
|
|
}
|
|
|
|
TEST(lagi_path, trailing_slash_on_token_is_optional) {
|
|
Path p;
|
|
|
|
agi::fs::path expected = boost::filesystem::current_path()/"foo.txt";
|
|
expected.make_preferred();
|
|
|
|
EXPECT_NO_THROW(p.SetToken("?audio", boost::filesystem::current_path()));
|
|
|
|
agi::fs::path decoded;
|
|
ASSERT_NO_THROW(decoded = p.Decode("?audiofoo.txt"));
|
|
EXPECT_STREQ(expected.string().c_str(), decoded.string().c_str());
|
|
|
|
ASSERT_NO_THROW(decoded = p.Decode("?audio/foo.txt"));
|
|
EXPECT_STREQ(expected.string().c_str(), decoded.string().c_str());
|
|
}
|
|
|
|
TEST(lagi_path, setting_token_to_file_sets_to_parent_directory_instead) {
|
|
Path p;
|
|
|
|
agi::fs::path file = boost::filesystem::system_complete("data/file");
|
|
ASSERT_NO_THROW(p.SetToken("?script", file));
|
|
EXPECT_STREQ(file.parent_path().string().c_str(), p.Decode("?script").string().c_str());
|
|
|
|
file = boost::filesystem::system_complete("data/dir");
|
|
ASSERT_NO_THROW(p.SetToken("?script", file));
|
|
EXPECT_STREQ(file.string().c_str(), p.Decode("?script").string().c_str());
|
|
}
|
|
|
|
TEST(lagi_path, valid_token_names) {
|
|
Path p;
|
|
|
|
EXPECT_NO_THROW(p.SetToken("?user", ""));
|
|
EXPECT_NO_THROW(p.SetToken("?local", ""));
|
|
EXPECT_NO_THROW(p.SetToken("?data", ""));
|
|
EXPECT_NO_THROW(p.SetToken("?temp", ""));
|
|
EXPECT_NO_THROW(p.SetToken("?dictionary", ""));
|
|
EXPECT_NO_THROW(p.SetToken("?docs", ""));
|
|
EXPECT_NO_THROW(p.SetToken("?audio", ""));
|
|
EXPECT_NO_THROW(p.SetToken("?script", ""));
|
|
EXPECT_NO_THROW(p.SetToken("?video", ""));
|
|
}
|
|
|
|
#define TEST_PLATFORM_PATH_TOKEN(tok) \
|
|
do { \
|
|
agi::fs::path d; \
|
|
ASSERT_NO_THROW(d = p.Decode(tok)); \
|
|
ASSERT_FALSE(d.empty()); \
|
|
ASSERT_STRNE(tok, d.string().c_str()); \
|
|
EXPECT_TRUE(agi::fs::DirectoryExists(d)); \
|
|
} while (false)
|
|
|
|
TEST(lagi_path, platform_paths_have_values_and_exist) {
|
|
Path p;
|
|
TEST_PLATFORM_PATH_TOKEN("?data");
|
|
TEST_PLATFORM_PATH_TOKEN("?user");
|
|
TEST_PLATFORM_PATH_TOKEN("?local");
|
|
TEST_PLATFORM_PATH_TOKEN("?temp");
|
|
}
|