Example #1
0
TEST_F(DonutSlotTest, SaveTest)
{
	XValue v;
	timestamp_t t1,t2,t3;
	{
		Slot slot;
		t1 = clock->now();
		clock->tick();
		t2 = clock->now();
		Handler<Object> obj100 = heap->createInt(100);
		slot.store(heap, obj100.get());

		clock->tick();
		t3 = clock->now();
		slot.onForwardNotify(heap);
		Handler<Object> obj200 = heap->createInt(200);
		slot.store(heap, obj200.get());

		clock->seek(t2);
		slot.onBackNotify(heap);
		v = slot.save();
	}
	{
		Slot slot(heap, v);
		ASSERT_EQ(100, slot.load()->toInt(heap));

		clock->seek(t1);
		slot.onBackNotify(heap);

		ASSERT_FALSE(slot.have());
		ASSERT_ANY_THROW(slot.load());

		clock->seek(t2);
		slot.onForwardNotify(heap);
		ASSERT_TRUE(slot.have());
		ASSERT_NO_THROW(slot.load());
		ASSERT_EQ(100, slot.load()->toInt(heap));

		clock->seek(t3);
		slot.onForwardNotify(heap);
		ASSERT_TRUE(slot.have());
		ASSERT_NO_THROW(slot.load());
		ASSERT_EQ(200, slot.load()->toInt(heap));
	}
}