/*
 * SPDX-License-Identifier: GPL-3.0-only
 * MuseScore-Studio-CLA-applies
 *
 * MuseScore Studio
 * Music Composition & Notation
 *
 * Copyright (C) 2021 MuseScore Limited and others
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include <gtest/gtest.h>

#include "engraving/dom/engravingitem.h"

#include "utils/scorerw.h"

using namespace mu::engraving;

static const String DATA_DIR("all_elements_data/");

class Engraving_EIDTests : public ::testing::Test
{
};

TEST_F(Engraving_EIDTests, testRegisteredItems)
{
    MasterScore* score = ScoreRW::readScore(DATA_DIR + u"random_elements.mscx");
    EXPECT_TRUE(score);

    auto checkRegister = [&](EngravingItem* item) {
        EID eid = item->eid();
        if (eid.isValid()) {
            EngravingObject* registeredItem = item->masterScore()->eidRegister()->itemFromEID(item->eid());
            EXPECT_TRUE(registeredItem);
            EXPECT_EQ(registeredItem, item);
        }
    };

    score->scanElements(checkRegister);
    for (MeasureBase* mb = score->first(); mb; mb = mb->next()) {
        checkRegister(mb);
    }

    delete score;
}
