123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- #include "catch.hpp"
- #include "vptr_manager.h"
- #include "shm.h"
- class TestBase3
- {
- public:
- virtual int Do1()
- {
- return a;
- }
- virtual ~TestBase3() = default;
- int a = 2;
- };
- class TestBase4 : virtual public TestBase3
- {
- public:
- virtual int Do1() override
- {
- return 4;
- }
- };
- class TestDrvied1 :virtual public TestBase3, public TestBase4
- {
- public:
- virtual ~TestDrvied1() = default;
- };
- class TestBase
- {
- public:
- virtual int Do1()
- {
- return a;
- }
- virtual ~TestBase() = default;
- int a = 2;
- };
- class TestBase2
- {
- public:
- virtual int Do1()
- {
- return b;
- }
- virtual ~TestBase2() = default;
- int b = 3;
- };
- class TestDrvied :public TestBase, public TestBase2
- {
- public:
- virtual ~TestDrvied() = default;
- };
- TEST_CASE("VptrObjectContainer<TestDrvied>, ShmNew Fix ShmDelete", "[TestDrvied][base]")
- {
- bg::ShmOptions opts(false, "Test", nullptr);
- opts.fix_vptr_on_init = false;
- REQUIRE(bg::ShmInit(opts) == true);
- TestDrvied* drv = bg::ShmNew<TestDrvied>();
- uintptr_t drv_ptr = *reinterpret_cast<uintptr_t*>(drv);
- memset(drv, 0, sizeof(TestDrvied));
- TestBase* base = static_cast<TestBase*>(drv);
- base->a = 2;
- TestBase2* base2 = static_cast<TestBase2*>(drv);
- base2->b = 3;
- REQUIRE(*reinterpret_cast<uintptr_t*>(base) == 0);
- *(uint64_t*)(0x600000006080) = 2;
- bg::ShmFixVptr();
- REQUIRE(*reinterpret_cast<uintptr_t*>(base) == drv_ptr);
- REQUIRE(*reinterpret_cast<uintptr_t*>(base2) != 0);
- REQUIRE(base->Do1() == 2);
- REQUIRE(base2->Do1() == 3);
- bg::ShmDelete(base);
- bg::ShmFini();
- }
- TEST_CASE("VptrObjectContainer<TestDrvied1>, ShmNew Fix ShmDelete")
- {
- bg::ShmOptions opts(false, "Test", nullptr);
- opts.fix_vptr_on_init = false;
- REQUIRE(bg::ShmInit(opts) == true);
- TestDrvied1* drv = bg::ShmNew<TestDrvied1>();
- uintptr_t drv_ptr = *reinterpret_cast<uintptr_t*>(drv);
- TestBase4* base2 = static_cast<TestBase4*>(drv);
- TestBase3* base = static_cast<TestBase3*>(drv);
- REQUIRE(base->Do1() == 4);
- memset(drv, 0, sizeof(TestDrvied));
- base->a = 2;
-
- REQUIRE(*reinterpret_cast<uintptr_t*>(base) == 0);
- *(uint64_t*)(0x600000006080) = 2;
- bg::ShmFixVptr();
- REQUIRE(*reinterpret_cast<uintptr_t*>(base2) == drv_ptr);
- REQUIRE(base->Do1() == 4);
- REQUIRE(base2->Do1() == 4);
- bg::ShmDelete(base);
- bg::ShmFini();
- }
- class TestDrvied3
- {
- public:
- virtual ~TestDrvied3() = default;
- };
- TEST_CASE("VptrObjectContainer<TestDrvied3>, ShmNew Fix ShmDelete")
- {
- bg::ShmOptions opts(false, "Test", nullptr);
- opts.fix_vptr_on_init = false;
- REQUIRE(bg::ShmInit(opts) == true);
- TestDrvied3* drv = bg::ShmNew<TestDrvied3>();
- uintptr_t drv_ptr = *reinterpret_cast<uintptr_t*>(drv);
- memset(drv, 0, sizeof(TestDrvied3));
- REQUIRE(*reinterpret_cast<uintptr_t*>(drv) == 0);
- *(uint64_t*)(0x600000006080) = 2;
- bg::ShmFixVptr();
- REQUIRE(*reinterpret_cast<uintptr_t*>(drv) == drv_ptr);
- bg::ShmDelete(drv);
- bg::ShmFini();
- }
|