mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-28 22:05:03 +00:00
Implement attachment target validation
This commit is contained in:
parent
985211760f
commit
70f8c5d220
@ -46,8 +46,11 @@ attachment_target_c::validate() {
|
||||
if ((ac_add != m_command) && (ac_replace != m_command))
|
||||
return;
|
||||
|
||||
// TODO: validate()
|
||||
assert(false);
|
||||
try {
|
||||
m_file_content = mm_file_io_c::slurp(m_file_name);
|
||||
} catch (mtx::mm_io::exception &ex) {
|
||||
mxerror(boost::format(Y("The file '%1%' could not be opened for reading (%2%).\n")) % m_file_name % ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "propedit/attachment_target.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "tests/unit/init.h"
|
||||
#include "tests/unit/util.h"
|
||||
|
||||
namespace {
|
||||
@ -106,4 +107,35 @@ TEST(AttachmentTarget, ParsingInvalidArgumentsForReplace) {
|
||||
EXPECT_THROW(at.parse_spec(attachment_target_c::ac_replace, "gonzo:peter:wuff", no_opt), std::invalid_argument);
|
||||
}
|
||||
|
||||
TEST(AttachmentTarget, ValidateOk) {
|
||||
attachment_target_c at;
|
||||
attachment_target_c::options_t no_opt;
|
||||
|
||||
ASSERT_NO_THROW(at.parse_spec(attachment_target_c::ac_delete, "1", no_opt));
|
||||
ASSERT_NO_THROW(at.validate());
|
||||
|
||||
at = attachment_target_c{};
|
||||
|
||||
ASSERT_NO_THROW(at.parse_spec(attachment_target_c::ac_add, "tests/unit/data/text/chunky_bacon.txt", no_opt));
|
||||
ASSERT_NO_THROW(at.validate());
|
||||
|
||||
at = attachment_target_c{};
|
||||
|
||||
ASSERT_NO_THROW(at.parse_spec(attachment_target_c::ac_replace, "1:tests/unit/data/text/chunky_bacon.txt", no_opt));
|
||||
ASSERT_NO_THROW(at.validate());
|
||||
}
|
||||
|
||||
TEST(AttachmentTarget, ValidateFailure) {
|
||||
attachment_target_c at;
|
||||
attachment_target_c::options_t no_opt;
|
||||
|
||||
ASSERT_NO_THROW(at.parse_spec(attachment_target_c::ac_add, "doesnotexist", no_opt));
|
||||
ASSERT_THROW(at.validate(), mtxut::mxerror_x);
|
||||
|
||||
at = attachment_target_c{};
|
||||
|
||||
ASSERT_NO_THROW(at.parse_spec(attachment_target_c::ac_replace, "1:doesnotexist", no_opt));
|
||||
ASSERT_THROW(at.validate(), mtxut::mxerror_x);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user