1
0
forked from 0ad/0ad

pending improvements and partial fixes to self-tests

fix: g_frequencyFilter is now in globals.cpp instead of in main (since
other modules access it and main.cpp isn't included in the self-test)
fix: globals.h now avoids dragging sdl.h into other projects
allocators: got rid of references to the old master header (must now
include the specific header, e.g. dynarray.h)

This was SVN commit r5534.
This commit is contained in:
janwas 2008-01-03 22:07:18 +00:00
parent 9cea581f43
commit ad55f9f1bc
19 changed files with 61 additions and 71 deletions

View File

@ -1,10 +0,0 @@
// temporary "bridge" header to new lib/allocators location until
// all source files are adapted to match the new headers.
#include "lib/allocators/allocators.h"
#include "lib/allocators/bucket.h"
#include "lib/allocators/dynarray.h"
#include "lib/allocators/headerless.h"
#include "lib/allocators/mem_util.h"
#include "lib/allocators/pool.h"

View File

@ -21,6 +21,12 @@
ERROR_ASSOCIATE(ERR::PATH_ROOT_DIR_ALREADY_SET, "Attempting to set FS root dir more than once", -1);
ERROR_ASSOCIATE(ERR::PATH_NOT_IN_ROOT_DIR, "Accessing a file that's outside of the root dir", -1);
bool exists(const Path& path)
{
return fs::exists(path.external_directory_string());
}
// security check: only allow path_SetRoot once so that malicious code
// cannot circumvent the VFS checks that disallow access to anything above

View File

@ -32,6 +32,8 @@ struct PathTraits
static internal_string_type to_internal(const external_string_type& src);
};
extern bool exists(const Path& path);
namespace ERR
{

View File

@ -1,8 +1,8 @@
#include "lib/self_test.h"
#include "lib/tex/tex.h"
#include "lib/res/graphics/tex_codec.h"
#include "lib/res/graphics/tex_internal.h" // tex_encode
#include "lib/tex/tex_codec.h"
#include "lib/allocators/allocators.h" // DummyDeleter
class TestTex : public CxxTest::TestSuite
{
@ -10,13 +10,12 @@ class TestTex : public CxxTest::TestSuite
{
// generate test data
const size_t size = w*h*bpp/8;
u8* img = new u8[size];
for(size_t i = 0; i < size; i++)
img[i] = rand() & 0xFF;
shared_ptr<u8> img(new u8[size]);
std::generate(img.get(), img.get()+size, rand);
// wrap in Tex
Tex t;
TS_ASSERT_OK(tex_wrap(w, h, bpp, flags, img, &t));
TS_ASSERT_OK(tex_wrap(w, h, bpp, flags, img, 0, &t));
// encode to file format
DynArray da;
@ -24,19 +23,18 @@ class TestTex : public CxxTest::TestSuite
memset(&t, 0, sizeof(t));
// decode from file format
shared_ptr<u8> ptr(&da.base, DummyDeleter());
TS_ASSERT_OK(tex_decode(ptr, da.cur_size, 0, &t));
shared_ptr<u8> ptr(da.base, DummyDeleter<u8>());
TS_ASSERT_OK(tex_decode(ptr, da.cur_size, &t));
// make sure pixel format gets converted completely to plain
TS_ASSERT_OK(tex_transform_to(&t, 0));
// compare img
TS_ASSERT_SAME_DATA(tex_get_data(&t), img, size);
TS_ASSERT_SAME_DATA(tex_get_data(&t), img.get(), size);
// cleanup
tex_free(&t);
TS_ASSERT_OK(da_free(&da));
delete[] img;
}
public:
@ -57,7 +55,7 @@ public:
char extension[30] = {'.'};
strcpy_s(extension+1, 29, c->name);
// .. make sure the c->name hack worked
const TexCodecVTbl* correct_c;
const TexCodecVTbl* correct_c = 0;
TS_ASSERT_OK(tex_codec_for_filename(extension, &correct_c));
TS_ASSERT_EQUALS(c, correct_c);
@ -105,29 +103,31 @@ public:
// have mipmaps be created for a test image; check resulting size and pixels
void test_mipmap_create()
{
u8 img[] = { 0x10,0x20,0x30, 0x40,0x60,0x80, 0xA0,0xA4,0xA8, 0xC0,0xC1,0xC2 };
u8 imgData[] = { 0x10,0x20,0x30, 0x40,0x60,0x80, 0xA0,0xA4,0xA8, 0xC0,0xC1,0xC2 };
shared_ptr<u8> img(imgData, DummyDeleter<u8>());
// assumes 2x2 box filter algorithm with rounding
const u8 mipmap[] = { 0x6C,0x79,0x87 };
static const u8 mipmap[] = { 0x6C,0x79,0x87 };
Tex t;
TS_ASSERT_OK(tex_wrap(2, 2, 24, 0, img, &t));
TS_ASSERT_OK(tex_wrap(2, 2, 24, 0, img, 0, &t));
TS_ASSERT_OK(tex_transform_to(&t, TEX_MIPMAPS));
const u8* const out_img = tex_get_data(&t);
TS_ASSERT_EQUALS((int)tex_img_size(&t), 12+3);
TS_ASSERT_SAME_DATA(out_img, img, 12);
TS_ASSERT_SAME_DATA(out_img, imgData, 12);
TS_ASSERT_SAME_DATA(out_img+12, mipmap, 3);
}
void test_img_size()
{
char dummy_img[100*100*4]; // required
u8 imgStorage[100*100*4]; // (prevent a needless heap alloc)
shared_ptr<u8> img(imgStorage, DummyDeleter<u8>());
Tex t;
TS_ASSERT_OK(tex_wrap(100, 100, 32, TEX_ALPHA, dummy_img, &t));
TS_ASSERT_OK(tex_wrap(100, 100, 32, TEX_ALPHA, img, 0, &t));
TS_ASSERT_EQUALS((int)tex_img_size(&t), 40000);
// DXT rounds up to 4x4 blocks; DXT1a is 4bpp
Tex t2;
TS_ASSERT_OK(tex_wrap(97, 97, 4, DXT1A, dummy_img, &t2));
TS_ASSERT_OK(tex_wrap(97, 97, 4, DXT1A, img, 0, &t2));
TS_ASSERT_EQUALS((int)tex_img_size(&t2), 5000);
}
};

View File

@ -17,7 +17,7 @@
#include <new> // std::bad_alloc
#include "lib/fnv_hash.h"
#include "lib/allocators.h"
#include "lib/allocators/allocators.h" // OverrunProtector
#include "lib/module_init.h"

View File

@ -16,7 +16,7 @@
#include <list>
#include "lib/path_util.h"
#include "lib/allocators.h"
#include "lib/allocators/allocators.h" // HACK, get rid of STATIC_STORAGE
#include "lib/path_util.h" // path_is_subpath
#include "win.h"
#include "winit.h"

View File

@ -12,7 +12,7 @@
#include "counter.h"
#include "lib/bits.h"
#include "lib/allocators.h"
#include "lib/sysdep/cpu.h" // cpu_CAS
#include "tsc.h"
#include "hpet.h"

View File

@ -1,7 +1,7 @@
#include "precompiled.h"
#include "wfilesystem.h"
#include "lib/allocators.h" // single_calloc
#include "lib/allocators/allocators.h" // single_calloc
#include "wposix_internal.h"
#include "wtime_internal.h" // wtime_utc_filetime_to_time_t
#include "crt_posix.h" // _rmdir, _access

View File

@ -11,7 +11,7 @@
#ifndef INCLUDED_TEX_INTERNAL
#define INCLUDED_TEX_INTERNAL
#include "lib/allocators.h" // DynArray
#include "lib/allocators/dynarray.h"
#include "lib/file/io/io.h" // io_Allocate
/**

View File

@ -45,8 +45,6 @@ that of Atlas depending on commandline parameters.
extern bool g_TerrainModified;
extern bool g_GameRestarted;
PIFrequencyFilter g_frequencyFilter;
void kill_mainloop();

View File

@ -9,15 +9,12 @@
#include "ps/CLogger.h"
#include "ps/CConsole.h"
#include "ps/Game.h"
#include "ps/Globals.h" // g_frequencyFilter
#include "ps/GameAttributes.h"
#include "simulation/Simulation.h"
#define LOG_CAT_NET "net"
#include "lib/frequency_filter.h"
extern PIFrequencyFilter g_frequencyFilter;
CNetClient *g_NetClient=NULL;
CNetClient::CServerSession::CServerSession(int sessionID, const CStrW& name):
@ -448,7 +445,7 @@ int CNetClient::StartGame()
debug_printf("Client StartGame - sending end-of-batch ack\n");
// Send an end-of-batch message for turn 0 to signal that we're ready.
CEndCommandBatch *pMsg=new CEndCommandBatch();
pMsg->m_TurnLength=1000/g_frequencyFilter->SmoothedFrequency();
pMsg->m_TurnLength=1000/g_frequencyFilter->StableFrequency();
Push(pMsg);
return 0;
}
@ -474,7 +471,7 @@ void CNetClient::NewTurn()
//debug_printf("In NewTurn - sending ack\n");
CEndCommandBatch *pMsg=new CEndCommandBatch();
pMsg->m_TurnLength=1000/g_frequencyFilter->SmoothedFrequency();
pMsg->m_TurnLength=1000/g_frequencyFilter->StableFrequency(); // JW: it'd probably be nicer to get the FPS as a parameter
Push(pMsg);
}

View File

@ -1,8 +1,8 @@
#include "precompiled.h"
#include "lib/input.h"
#include "Globals.h"
#include "lib/external_libraries/sdl.h"
bool g_app_minimized = false;
bool g_app_has_focus = true;
@ -14,6 +14,7 @@ int g_mouse_x = 50, g_mouse_y = 50;
// (order is given by SDL_BUTTON_* constants).
bool g_mouse_buttons[6] = {0};
PIFrequencyFilter g_frequencyFilter;
// updates the state of the above; never swallows messages.
InReaction GlobalsInputHandler(const SDL_Event_* ev)

View File

@ -1,5 +1,5 @@
#include "lib/input.h"
#include "lib/external_libraries/sdl.h"
#include "lib/frequency_filter.h"
// thin abstraction layer on top of SDL.
// game code should use it instead of SDL_GetMouseState etc. because
@ -15,7 +15,7 @@ extern int g_mouse_x, g_mouse_y;
* it represents a pressed key.
* Updated by GlobalsInputHandler in response to key press/release events.
*/
extern bool g_keys[SDLK_LAST];
extern bool g_keys[];
/**
* g_mouse_buttons: Mouse buttons states, indexed by SDL_BUTTON_* constants.
@ -29,3 +29,5 @@ extern bool g_keys[SDLK_LAST];
extern bool g_mouse_buttons[6];
extern InReaction GlobalsInputHandler(const SDL_Event_* ev);
extern PIFrequencyFilter g_frequencyFilter;

View File

@ -1,21 +1,18 @@
#include "lib/self_test.h"
#include "ps/XML/Xeromyces.h"
#include "lib/res/file/vfs.h"
#include "lib/res/file/path.h"
#include "lib/res/h_mgr.h"
#include "lib/file/vfs/vfs.h"
#include "lib/file/path.h"
class TestXeromyces : public CxxTest::TestSuite
{
public:
void test_paths()
{
TS_ASSERT_OK(file_init());
TS_ASSERT_OK(file_set_root_dir(0, "../data"));
vfs_init();
TS_ASSERT_OK(path_SetRoot(0, "../data"));
PIVFS vfs = CreateVfs();
TS_ASSERT_OK(vfs_mount("", "mods/_test.xero", VFS_MOUNT_RECURSIVE));
TS_ASSERT_OK(vfs_set_write_target("mods/_test.xero"));
TS_ASSERT_OK(vfs->Mount("", "mods/_test.xero"));
char xmbPath[PATH_MAX];
@ -25,8 +22,6 @@ public:
CXeromyces::GetXMBPath("a/b/test1.xml", "a/b/test1.xmb", xmbPath);
TS_ASSERT_STR_EQUALS(xmbPath, "cache/mods/_test.xero/xmb/a/b/test1.xmb");
vfs_shutdown();
path_reset_root_dir();
TS_ASSERT_OK(file_shutdown());
path_ResetRootDir();
}
};

View File

@ -7,8 +7,8 @@ class TestCLogger : public CxxTest::TestSuite
public:
void test_basic()
{
logger->Log(NORMAL, "", "Test 1");
logger->Log(NORMAL, "", "Test 2");
logger->Log(CLogger::Normal, "", "Test 1");
logger->Log(CLogger::Normal, "", "Test 2");
ParseOutput();
@ -29,15 +29,15 @@ public:
std::string clipped (buflen-4, '*');
clipped += "...";
logger->Log(NORMAL, "", msg0.c_str());
logger->Log(NORMAL, "", msg1.c_str());
logger->Log(NORMAL, "", msg2.c_str());
logger->Log(NORMAL, "", msg3.c_str());
logger->Log(CLogger::Normal, "", msg0.c_str());
logger->Log(CLogger::Normal, "", msg1.c_str());
logger->Log(CLogger::Normal, "", msg2.c_str());
logger->Log(CLogger::Normal, "", msg3.c_str());
logger->LogOnce(NORMAL, "", msg0.c_str());
logger->LogOnce(NORMAL, "", msg1.c_str());
logger->LogOnce(NORMAL, "", msg2.c_str());
logger->LogOnce(NORMAL, "", msg3.c_str());
logger->LogOnce(CLogger::Normal, "", msg0.c_str());
logger->LogOnce(CLogger::Normal, "", msg1.c_str());
logger->LogOnce(CLogger::Normal, "", msg2.c_str());
logger->LogOnce(CLogger::Normal, "", msg3.c_str());
ParseOutput();

View File

@ -27,6 +27,7 @@
#include "ps/CLogger.h"
#include "ps/CStr.h"
#include "ps/Game.h"
#include "ps/Globals.h" // g_frequencyFilter
#include "ps/GameSetup/GameSetup.h"
#include "ps/Hotkey.h"
#include "ps/Interact.h"
@ -913,8 +914,6 @@ JSBool ResetGui(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval)
JSBool GetFps( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval )
{
JSU_REQUIRE_NO_PARAMS();
extern PIFrequencyFilter g_frequencyFilter;
*rval = INT_TO_JSVAL(g_frequencyFilter->StableFrequency());
return JS_TRUE;
}

View File

@ -2,7 +2,7 @@
#include "ScriptableComplex.h"
#include "ScriptableComplex.inl"
#include "lib/allocators.h"
#include "lib/allocators/bucket.h"
//-----------------------------------------------------------------------------
// suballocator for CJSComplex.m_Properties elements

View File

@ -11,7 +11,7 @@
#include "graphics/Unit.h"
#include "maths/Bound.h"
#include "graphics/Model.h"
#include "lib/allocators.h"
#include "lib/allocators/allocators.h" // matrix_alloc
#include "lib/timer.h"

View File

@ -8,7 +8,7 @@
#include "graphics/Model.h"
#include "graphics/Terrain.h"
#include "graphics/Unit.h"
#include "lib/allocators.h"
#include "lib/allocators/allocators.h" // matrix_alloc
#include "lib/ogl.h"
#include "lib/timer.h"
#include "maths/Bound.h"