void TestRegisterPinning(TestCaseSetup& setup) { ExpressionNodeFactory e(setup.GetAllocator(), setup.GetCode()); // Get a direct register and pin it. Storage<T> storage = e.Direct<T>(); ReferenceCounter pin = storage.GetPin(); auto reg = storage.GetDirectRegister(); // Attempt to obtain that specific register should now fail. try { e.Direct<T>(reg); FAIL() << "It should not have been possible to obtain a pinned register"; } catch (std::exception const & e) { std::string msg = e.what(); ASSERT_TRUE(msg.find("Attempted to obtain the pinned register") != std::string::npos) << "Unexpected exception received"; } catch (...) { FAIL() << "Unexpected exception type"; } // Unpin the register and try obtaining it again (should succceed now). pin.Reset(); Storage<T> storage2 = e.Direct<T>(reg); // The new storage should own the register, the old not should not. ASSERT_EQ(storage2.GetStorageClass(), StorageClass::Direct); ASSERT_EQ(storage2.GetDirectRegister(), reg); ASSERT_FALSE((storage.GetStorageClass() == StorageClass::Direct && storage.GetDirectRegister() == reg)); }