1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2025-03-22 13:19:40 +01:00

experimental patch for unhook exclusivity bug

added multi-hook single-remove test cases (crummy but works)

--HG--
extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40178
This commit is contained in:
David Anderson 2006-01-24 20:02:19 +00:00
parent 15bf3f5ea8
commit b6f713be5f
4 changed files with 113 additions and 3 deletions

View File

@ -419,6 +419,11 @@ namespace SourceHook
for (CVfnPtr::IfaceListIter iface_iter = vfnptr_iter->m_Ifaces.begin();
iface_iter != vfnptr_iter->m_Ifaces.end();)
{
if (iface_iter->m_Ptr != adjustediface)
{
iface_iter++;
continue;
}
List<HookInfo> &hooks =
post ? iface_iter->m_PostHooks.m_List : iface_iter->m_PreHooks.m_List;

View File

@ -77,6 +77,7 @@ DO_TEST(Bail);
DO_TEST(Reentr);
DO_TEST(Manual);
DO_TEST(Recall);
DO_TEST(Multi);
int main(int argc, char *argv[])
{

View File

@ -262,9 +262,6 @@
<File
RelativePath=".\testbail.cpp">
</File>
<File
RelativePath=".\testbail.h">
</File>
<File
RelativePath=".\testbail2.cpp">
</File>
@ -280,6 +277,9 @@
GeneratePreprocessedFile="0"/>
</FileConfiguration>
</File>
<File
RelativePath=".\testmulti.cpp">
</File>
<File
RelativePath=".\testrecall.cpp">
</File>
@ -314,6 +314,9 @@
<File
RelativePath=".\sourcehook_test.h">
</File>
<File
RelativePath=".\testbail.h">
</File>
<File
RelativePath="testevents.h">
</File>

View File

@ -0,0 +1,101 @@
#include <string>
#include "sourcehook.h"
#include "sourcehook_test.h"
#include "testevents.h"
namespace
{
SourceHook::ISourceHook *g_SHPtr;
SourceHook::Plugin g_PLID;
unsigned int g_callcount[10];
class VMultiTest
{
public:
VMultiTest(unsigned int index) : m_idx(index)
{
}
public:
virtual void HookTarget()
{
}
virtual void Notify()
{
g_callcount[this->m_idx]++;
}
private:
unsigned int m_idx;
};
void HookFunction()
{
VMultiTest *pv = META_IFACEPTR(VMultiTest);
pv->Notify();
}
SH_DECL_HOOK0_void(VMultiTest, HookTarget, SH_NOATTRIB, false);
};
bool TestMulti(std::string &error)
{
GET_SHPTR(g_SHPtr);
g_PLID = 1337;
VMultiTest **pv = new VMultiTest *[10];
for (unsigned int i=0; i<10; i++)
pv[i] = new VMultiTest(i);
for (unsigned int i=0; i<10; i++)
SH_ADD_HOOK_STATICFUNC(VMultiTest, HookTarget, pv[i], HookFunction, false);
pv[0]->HookTarget();
if (g_callcount[0] != 1)
{
error.assign("g_callcount[0] != 0");
return false;
}
for (unsigned int i=1; i<10; i++)
{
if (g_callcount[i])
{
error.assign("g_callcount[n] != 0");
return false;
}
}
SH_REMOVE_HOOK_STATICFUNC(VMultiTest, HookTarget, pv[0], HookFunction, false);
for (unsigned int i=1; i<10; i++)
pv[i]->HookTarget();
if (g_callcount[0] != 1)
{
error.assign("g_callcount[0] != 0");
return false;
}
for (unsigned int i=1; i<10; i++)
{
if (g_callcount[i] != 1)
{
char err[256];
_snprintf(err, sizeof(err)-1, "g_callcount[%d] != 1", i);
error.assign(err);
return false;
}
}
for (unsigned int i=1; i<10; i++)
{
SH_REMOVE_HOOK_STATICFUNC(VMultiTest, HookTarget, pv[1], HookFunction, false);
delete pv[i];
}
delete [] pv;
return true;
}