2010-05-21 03:13:36 +02:00
|
|
|
// Copyright (c) 2010, Amar Takhar <verm@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.
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include "main.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
|
|
|
|
#include <libaegisub/access.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <libaegisub/fs.h>
|
2010-05-21 03:13:36 +02:00
|
|
|
|
2012-01-12 23:31:54 +01:00
|
|
|
using namespace agi;
|
2010-05-21 03:13:36 +02:00
|
|
|
using namespace agi::acs;
|
2013-01-04 16:01:50 +01:00
|
|
|
using namespace agi::fs;
|
2010-05-21 03:13:36 +02:00
|
|
|
|
|
|
|
// Yes, this is a horrifying use of macros, since these are all void static
|
|
|
|
// methods I couldn't think of a better way to test these without massive code
|
|
|
|
// duplication.
|
2013-01-04 16:01:50 +01:00
|
|
|
#define DO_TEST(func, name, fail, fail_ex, pass) \
|
|
|
|
TEST(lagi_acs, name) { \
|
|
|
|
EXPECT_THROW(func(fail), fail_ex); \
|
2010-05-21 03:13:36 +02:00
|
|
|
EXPECT_NO_THROW(func(pass)); \
|
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#define EX_FileNotFound(func, pass) \
|
|
|
|
DO_TEST(func, func##ExFileNotFound, "data/nonexistent", FileNotFound, pass)
|
|
|
|
|
2012-01-12 23:31:54 +01:00
|
|
|
#define EX_Fatal(func, fail, pass) \
|
2013-01-04 16:01:50 +01:00
|
|
|
DO_TEST(func, func##ExFatal, fail, Fatal, pass)
|
2010-05-21 03:13:36 +02:00
|
|
|
|
2012-01-12 23:31:54 +01:00
|
|
|
#define EX_NotAFile(func, fail, pass) \
|
2013-01-04 16:01:50 +01:00
|
|
|
DO_TEST(func, func##ExNotAFile, fail, NotAFile, pass)
|
2010-05-21 03:13:36 +02:00
|
|
|
|
2012-01-12 23:31:54 +01:00
|
|
|
#define EX_NotADirectory(func, fail, pass) \
|
2013-01-04 16:01:50 +01:00
|
|
|
DO_TEST(func, func##ExNotADirectory, fail, NotADirectory, pass)
|
2010-05-21 03:13:36 +02:00
|
|
|
|
2012-01-12 23:31:54 +01:00
|
|
|
#define EX_Read(func, fail, pass) \
|
2013-01-04 16:01:50 +01:00
|
|
|
DO_TEST(func, func##ExReadDenied, fail, ReadDenied, pass)
|
2010-05-21 03:13:36 +02:00
|
|
|
|
2012-01-12 23:31:54 +01:00
|
|
|
#define EX_Write(func, fail, pass) \
|
2013-01-04 16:01:50 +01:00
|
|
|
DO_TEST(func, func##ExWriteDenied, fail, WriteDenied, pass)
|
2010-05-21 03:13:36 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
EX_FileNotFound(CheckFileRead, "data/file")
|
2012-01-12 23:31:54 +01:00
|
|
|
EX_Read(CheckFileRead, "data/file_access_denied", "data/file")
|
|
|
|
EX_NotAFile(CheckFileRead, "data/dir", "data/file")
|
2013-01-04 16:01:50 +01:00
|
|
|
TEST(lagi_acs, CheckFileRead) {
|
2010-05-21 03:13:36 +02:00
|
|
|
EXPECT_NO_THROW(CheckFileRead("data/file"));
|
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
EX_FileNotFound(CheckFileWrite, "data/file")
|
2012-01-12 23:31:54 +01:00
|
|
|
EX_Read(CheckFileWrite, "data/file_access_denied", "data/file")
|
|
|
|
EX_NotAFile(CheckFileWrite, "data/dir", "data/file")
|
|
|
|
EX_Write(CheckFileWrite, "data/file_read_only", "data/file")
|
2013-01-04 16:01:50 +01:00
|
|
|
TEST(lagi_acs, CheckFileWrite) {
|
2010-05-21 03:13:36 +02:00
|
|
|
EXPECT_NO_THROW(CheckFileRead("data/file"));
|
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
EX_FileNotFound(CheckDirRead, "data/dir")
|
2012-01-12 23:31:54 +01:00
|
|
|
EX_Read(CheckDirRead, "data/dir_access_denied", "data/dir")
|
|
|
|
EX_NotADirectory(CheckDirRead, "data/file", "data/dir")
|
2013-01-04 16:01:50 +01:00
|
|
|
TEST(lagi_acs, CheckDirRead) {
|
2010-05-21 03:13:36 +02:00
|
|
|
EXPECT_NO_THROW(CheckDirRead("data/dir"));
|
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
EX_FileNotFound(CheckDirWrite, "data/dir")
|
2012-01-12 23:31:54 +01:00
|
|
|
EX_Read(CheckDirWrite, "data/dir_access_denied", "data/dir")
|
|
|
|
EX_NotADirectory(CheckDirWrite, "data/file", "data/dir")
|
|
|
|
EX_Write(CheckDirWrite, "data/dir_read_only", "data/dir")
|
2013-01-04 16:01:50 +01:00
|
|
|
TEST(lagi_acs, CheckDirWrite) {
|
2010-05-21 03:13:36 +02:00
|
|
|
EXPECT_NO_THROW(CheckDirWrite("data/dir"));
|
|
|
|
}
|