TEST(SlottedPage, ForeignRecords)
{
    SlottedPage* slottedPage = static_cast<SlottedPage*>(malloc(kPageSize));
    slottedPage->initialize();

    // Make foreign record and check
    uint16_t freeBytes = slottedPage->getBytesFreeForRecord();
    RecordId rid = slottedPage->insertForeigner(Record("fear not this night"), TupleId(8129));
    ASSERT_EQ(slottedPage->lookup(rid), Record("fear not this night"));
    ASSERT_EQ(slottedPage->isReference(rid), kInvalidTupleId);
    ASSERT_EQ(1u, slottedPage->getAllRecords(kInvalidPageId).size());
    ASSERT_EQ(TupleId(8129), slottedPage->getAllRecords(kInvalidPageId)[0].first);
    ASSERT_EQ(Record("fear not this night"), slottedPage->getAllRecords(kInvalidPageId)[0].second);

    // Update the foreign record
    slottedPage->updateForeigner(rid, TupleId(8129), Record("but i am afraid of the dark"));
    ASSERT_EQ(slottedPage->lookup(rid), Record("but i am afraid of the dark"));
    ASSERT_EQ(slottedPage->isReference(rid), kInvalidTupleId);
    ASSERT_EQ(1u, slottedPage->getAllRecords(kInvalidPageId).size());
    ASSERT_EQ(TupleId(8129), slottedPage->getAllRecords(kInvalidPageId)[0].first);
    ASSERT_EQ(Record("but i am afraid of the dark"), slottedPage->getAllRecords(kInvalidPageId)[0].second);

    // Remove foreign record
    slottedPage->remove(rid);
    ASSERT_EQ(slottedPage->getBytesFreeForRecord(), freeBytes);
    ASSERT_EQ(slottedPage->countAllRecords(), 0u);

    free(slottedPage);
}
TEST(SlottedPage, ReferenceRecords)
{
    SlottedPage* slottedPage = static_cast<SlottedPage*>(malloc(kPageSize));
    slottedPage->initialize();

    TupleId tid = TupleId(8129);
    RecordId rid = slottedPage->insert(Record("most awesome paper ever: a system for visualizing human behavior based on car metaphors"));

    // Make reference and check
    slottedPage->updateToReference(rid, tid);
    ASSERT_EQ(tid, slottedPage->isReference(rid));
    ASSERT_EQ(slottedPage->getAllRecords(kInvalidPageId).size(), 0u);
    ASSERT_EQ(slottedPage->countAllRecords(), 1u);

    // Remove reference
    slottedPage->remove(rid);
    ASSERT_EQ(slottedPage->getAllRecords(kInvalidPageId).size(), 0u);
    ASSERT_EQ(slottedPage->countAllRecords(), 0u);

    free(slottedPage);
}