/***************************************************************************
 * tabtimetest.cpp
 *
 * This file is part of KTabEdit, a KDE tabulature editor
 *
 * copyright (C) 2007- the KTabEdit development team <mrgwen@gmail.com>
 ***************************************************************************/

/***************************************************************************
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * See the file COPYING for more information.
 ***************************************************************************/

#include "tabtimetest.h"

#include "src/header.h"

#include "src/tablature/tabbeateffects.h"
#include "src/tablature/tabchord.h"
#include "src/tablature/tabduration.h"

#include "src/tablature/tabbend.h"
#include "src/tablature/tabdynamic.h"

#include "src/tablature/tabgracenotetransition.h"
#include "src/tablature/tabgracenote.h"

#include "src/tablature/tabharmonic.h"
#include "src/tablature/tabslide.h"
#include "src/tablature/tabtrill.h"
#include "src/tablature/tabnoteeffect.h"

#include "src/tablature/tabnote.h"

#include "src/tablature/tabmixtablechanges.h"
#include "src/tablature/tabtimes.h"
#include "src/tablature/tabbarproperties.h"

#include "src/tablature/tabbar.h"

#include "src/tablature/trackmidiproperties.h"
#include "src/tablature/timesignature.h"
#include "src/tablature/trackproperties.h"

#include "src/tablature/tabtrack.h"

#include "src/tablature/songkey.h"
#include "src/tablature/tablyrics.h"
#include "src/tablature/tabproperties.h"

#include "src/tablature/tabsong.h"

void TabTimeTest::testCopyConstructor()
{
	TabTimes time1;
	TabNote* note = new TabNote;
	
	note->setFret(5);
	time1.setString(2, note);
	
	TabTimes time2(time1);
	
	QCOMPARE( time2.string(2) != note, true);
	QCOMPARE( *time2.string(2) == *note, true);
}

void TabTimeTest::testString()
{
	TabTimes time;
	QCOMPARE( time.fret(2), (uchar)0);
	
	time.setFret(2, 5);
	QCOMPARE( time.fret(2), (uchar)5);
}

void TabTimeTest::testNoteExist()
{
	TabTimes time;
	TabNote* note = new TabNote;
	QCOMPARE( time.isNoteExist(3), false );
	
	note->setFret(5);
	time.setString(2, note);
	QCOMPARE( time.isNoteExist(2), true );
}

void TabTimeTest::testFret()
{
	TabTimes time;
	QCOMPARE( time.fret(2), (uchar)0 );
	
	time.setFret(2, 10);
	QCOMPARE( time.fret(2), (uchar)10 );
}

void TabTimeTest::testDuration()
{
	TabTimes time;
	QCOMPARE( time.duration(), NoneDuration );
	
	time.setDuration(Quarter);
	QCOMPARE( time.duration(), Quarter );
	QCOMPARE( time.realDuration(), (double)Quarter );
	
	time.setNTuplet(3);
	QCOMPARE( time.realDuration(), (double)Quarter / 3.0 );
	
	time.setNTuplet(1);
	time.setDotted(true);
	QCOMPARE( time.realDuration(), (double)Quarter + (Quarter / 2.0) );
}

void TabTimeTest::testRest()
{
	TabTimes time;
	QCOMPARE( time.isRest(), false );
	
	time.setRest(true);
	QCOMPARE( time.isRest(), true );
}

void TabTimeTest::testNote()
{
	TabTimes time;
	TabNote* note = new TabNote;
	QCOMPARE( time.isNoteEmpty(1), false );
	QCOMPARE( time.isNoteDeadNote(1), false );
	QCOMPARE( time.isNoteGhostNote(1), false );
	QCOMPARE( time.isTieNote(1), false );
	
	note->setFret(5);
	note->setDeadNote(true);
	note->setGhostNote(true);
	note->setTieNote(true);
	time.setString(2, note);
	QCOMPARE( time.isNoteEmpty(2), true );
	QCOMPARE( time.isNoteDeadNote(2), true );
	QCOMPARE( time.isNoteGhostNote(2), true );
	QCOMPARE( time.isTieNote(2), true );
}

void TabTimeTest::testDotted()
{
	TabTimes time;
	QCOMPARE( time.isDotted(), false );
	
	time.setDotted(true);
	QCOMPARE( time.isDotted(), true );
}

void TabTimeTest::testTuplet()
{
	TabTimes time;
	QCOMPARE( time.nTuplet(), (uint)1 );
	
	time.setNTuplet(3);
	QCOMPARE( time.nTuplet(), (uint)3 );
}

void TabTimeTest::testText()
{
	TabTimes time;
	QCOMPARE( time.text(), QString() );
	
	time.setText("Hello");
	QCOMPARE( time.text(), QString("Hello") );
}

void TabTimeTest::testChord()
{
	TabTimes time;
	TabChord* chord = new TabChord;
	QCOMPARE( time.isChord(), false );
	QCOMPARE( time.hasChord(), false );
	QCOMPARE( time.tabChord(), (const TabChord*)0x0 );
	
	time.setTabChord(chord);
	QCOMPARE( time.tabChord(), chord );
	
	time.setName("Hello");
	QCOMPARE( time.name(), QString("Hello") );
	
	time.setSharp(true);
	QCOMPARE( time.isSharp(), true );
	
	time.setRoot(1);
	QCOMPARE( time.root(), (uchar)1 );
	
	time.setType(2);
	QCOMPARE( time.type(), (uchar)2 );
	
	time.setNineElevenThirteen(TabChord::thirteen);
	QCOMPARE( time.nineElevenThirteen(), TabChord::thirteen );
	
	time.setBass(3);
	QCOMPARE( time.bass(), (uchar)3 );
	
	time.setAugmentedDiminished(TabChord::augmented);
	QCOMPARE( time.augmentedDiminished(), TabChord::augmented );
	
	time.setAddedNote(4);
	QCOMPARE( time.addedNote(), (uchar)4 );
	
	time.setTonalityFive(4);
	QCOMPARE( time.tonalityFive(), (uchar)4 );
	
	time.setTonalityNine(5);
	QCOMPARE( time.tonalityNine(), (uchar)5 );
	
	time.setTonalityEleven(6);
	QCOMPARE( time.tonalityEleven(), (uchar)6 );
	
	time.setBaseFret(7);
	QCOMPARE( time.baseFret(), (long)7 );
	
	time.setFretChord(1, 8);
	QCOMPARE(time.fretChord(1), (long)8 );
	
	time.setNumBarres(9);
	QCOMPARE( time.numBarres(), (uchar)9 );
	
	time.setBarreFret(1, 10);
	QCOMPARE( time.barreFret(1), (uchar)10 );
	
	time.setBarreStart(1, 11);
	QCOMPARE( time.barreStart(1), (uchar)11);
	
	time.setBarreEnd(1, 12);
	QCOMPARE( time.barreEnd(1), (uchar)12);
	
	time.setFingering(1, 13);
	QCOMPARE( time.fingering(1), (uchar)13);
	
	time.setShowDiagram(true);
	QCOMPARE( time.isShowDiagram(), true );
}

void TabTimeTest::testEffect()
{
	TabTimes time;
	TabBeatEffects* effect = new TabBeatEffects;
	TabBend* bend = new TabBend;
	QCOMPARE( *time.effect(), TabBeatEffects() );
	
	effect->setRasgueado(true);
	time.setEffect(effect);
	QCOMPARE( time.effect() , effect);
	
	time.setRasgueado(false);
	QCOMPARE( time.isRasgueado(), false );
	
	time.setPickStroke(UpWard);
	QCOMPARE( time.pickstroke(), UpWard );
	
	time.setTremolo(5);
	QCOMPARE( time.tremolo(), (int)5 );
	
	time.setTapping(true);
	QCOMPARE( time.isTapping(), true );
	
	time.setPopping(true);
	QCOMPARE( time.isPopping(), true );
	
	time.setSlapping(true);
	QCOMPARE( time.isSlapping(), true );
	
	time.setStroke(true);
	QCOMPARE( time.isStroke(), true );
	
	time.setUpStroke(6);
	QCOMPARE( time.upStroke(), (int)6 );
	
	time.setDownStroke(7);
	QCOMPARE( time.downStroke(), (int)7 );
	
	time.setVibrato(true);
	QCOMPARE( time.isVibrato(), true );
	
	time.setWideVibrato(true);
	QCOMPARE( time.isWideVibrato(), true );
	
	time.setNaturalHarmonic(true);
	QCOMPARE( time.isNaturalHarmonic(), true );
	
	time.setArtificialHarmonic(true);
	QCOMPARE( time.isArtificialHarmonic(), true );
	
	time.setFadeIn(true);
	QCOMPARE( time.isFadeIn(), true );
	
	QCOMPARE( *time.bend(), TabBend() );
	
	bend->setBendValue(50);
	time.setBend(bend);
	QCOMPARE( time.bend(), bend );
	
	time.setBendType(TabBend::Bend);
	QCOMPARE( time.bendType(), TabBend::Bend );
	
	time.setBendValue(25);
	QCOMPARE( time.bendValue(), (int)25 );
	QCOMPARE( time.bendValueToString(), QString("1/4") );
	
	QList<TabBendPoint> list;
	list.push_front(TabBendPoint());
	list.push_front(TabBendPoint());
	list.push_front(TabBendPoint());
	time.setBendPoint(list);
	QCOMPARE( time.bendPoint(), list );
}

void TabTimeTest::testOperators()
{
	TabTimes time1;
	TabTimes time2;
	QCOMPARE( time1 == time2, true );
	QCOMPARE( time1 != time2, false );
	
	time1.setFret(1, 20);
	time2.setFret(2, 10);
	QCOMPARE( time1 == time2, false );
	QCOMPARE( time1 != time2, true );
}

QTEST_MAIN(TabTimeTest)
#include "tabtimetest.moc"
