Changeset View
Changeset View
Standalone View
Standalone View
source/lib/file/vfs/tests/test_vfs_populate.h
- This file was added.
/* Copyright (C) 2020 Wildfire Games. | |||||
* | |||||
* Permission is hereby granted, free of charge, to any person obtaining | |||||
* a copy of this software and associated documentation files (the | |||||
* "Software"), to deal in the Software without restriction, including | |||||
* without limitation the rights to use, copy, modify, merge, publish, | |||||
* distribute, sublicense, and/or sell copies of the Software, and to | |||||
* permit persons to whom the Software is furnished to do so, subject to | |||||
* the following conditions: | |||||
* | |||||
* The above copyright notice and this permission notice shall be included | |||||
* in all copies or substantial portions of the Software. | |||||
* | |||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||||
*/ | |||||
#include "lib/self_test.h" | |||||
#include "lib/file/vfs/vfs_populate.h" | |||||
#include "lib/os_path.h" | |||||
static OsPath CACHE_PATH_HIGH(DataDir()/"_testcache1"); | |||||
static OsPath CACHE_PATH_LOW(DataDir()/"_testcache2"); | |||||
extern PIVFS g_VFS; | |||||
class TestVfsPopulate : public CxxTest::TestSuite | |||||
{ | |||||
void initVfs() | |||||
{ | |||||
// Initialise VFS: | |||||
// Make sure the required directories doesn't exist when we start, | |||||
// in case the previous test aborted and left them full of junk | |||||
if(DirectoryExists(CACHE_PATH_HIGH)) | |||||
DeleteDirectory(CACHE_PATH_HIGH); | |||||
if(DirectoryExists(CACHE_PATH_LOW)) | |||||
DeleteDirectory(CACHE_PATH_LOW); | |||||
g_VFS = CreateVfs(); | |||||
} | |||||
void deinitVfs() | |||||
{ | |||||
g_VFS.reset(); | |||||
DeleteDirectory(CACHE_PATH_LOW); | |||||
DeleteDirectory(CACHE_PATH_HIGH); | |||||
} | |||||
public: | |||||
void setUp() | |||||
{ | |||||
initVfs(); | |||||
} | |||||
void tearDown() | |||||
{ | |||||
deinitVfs(); | |||||
} | |||||
void test_RealPriority() | |||||
{ | |||||
g_VFS->Mount(L"cache", CACHE_PATH_LOW, 0, 0); | |||||
OsPath realPath; | |||||
g_VFS->GetDirectoryRealPath(L"cache", realPath); | |||||
TS_ASSERT_EQUALS(realPath, CACHE_PATH_LOW); | |||||
// Higher priority: overwritten. | |||||
g_VFS->Mount(L"cache", CACHE_PATH_HIGH, 0, 1); | |||||
g_VFS->GetDirectoryRealPath(L"cache", realPath); | |||||
TS_ASSERT_EQUALS(realPath, CACHE_PATH_HIGH); | |||||
// Same priority: nothing happens | |||||
g_VFS->Mount(L"cache", CACHE_PATH_LOW, 0, 1); | |||||
g_VFS->GetDirectoryRealPath(L"cache", realPath); | |||||
TS_ASSERT_EQUALS(realPath, CACHE_PATH_HIGH); | |||||
// Lower priority: nothing happens | |||||
g_VFS->Mount(L"cache", CACHE_PATH_LOW, 0, 0); | |||||
g_VFS->GetDirectoryRealPath(L"cache", realPath); | |||||
TS_ASSERT_EQUALS(realPath, CACHE_PATH_HIGH); | |||||
}; | |||||
}; |
Wildfire Games · Phabricator