Fix compilation of evoral unit-test

Some of these tests should be moved to libtemoral.
On 64bit Linux the tests pass, except various RangeTests.
This commit is contained in:
Robin Gareus 2022-09-30 04:04:48 +02:00
parent 9a34d15b3c
commit d70ebde1dc
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
10 changed files with 302 additions and 210 deletions

View File

@ -23,14 +23,15 @@ CPPUNIT_TEST_SUITE_REGISTRATION (CurveTest);
#endif
using namespace Evoral;
using namespace Temporal;
// linear y = Y0 + YS * x ; with x = i * (X1 - X0) + X0; and i = [0..1023]
#define VEC1024LINCMP(X0, X1, Y0, YS) \
cl->curve ().get_vector ((X0), (X1), vec, 1024); \
for (int i = 0; i < 1024; ++i) { \
char msg[64]; \
snprintf (msg, 64, "at i=%d (x0=%.1f, x1=%.1f, y0=%.1f, ys=%.3f)", \
i, X0, X1, Y0, YS); \
snprintf (msg, 64, "at i=%d (x0=%s, x1=%s, y0=%.1f, ys=%.3f)", \
i, (X0).str().c_str(), (X1).str().c_str(), Y0, YS); \
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE ( \
msg, \
(Y0) + i * (YS), vec[i], \
@ -47,15 +48,18 @@ CurveTest::trivial ()
cl->create_curve ();
timepos_t t1024 (1024.0);
timepos_t t2047 (2047.0);
// Empty curve
cl->curve().get_vector (1024.0, 2047.0, vec, 1024);
cl->curve().get_vector (t1024, t2047, vec, 1024);
for (int i = 0; i < 1024; ++i) {
CPPUNIT_ASSERT_EQUAL (0.0f, vec[i]);
}
// Single point curve
cl->fast_simple_add(0.0, 42.0);
cl->curve().get_vector (1024.0, 2047.0, vec, 1024);
cl->fast_simple_add(timepos_t (0), 42.0);
cl->curve().get_vector (t1024, t2047, vec, 1024);
for (int i = 0; i < 1024; ++i) {
CPPUNIT_ASSERT_EQUAL (42.0f, vec[i]);
}
@ -66,21 +70,24 @@ CurveTest::rtGet ()
{
float vec[1024];
timepos_t t1024 (1024.0);
timepos_t t2047 (2047.0);
// Create simple control list
boost::shared_ptr<Evoral::ControlList> cl = TestCtrlList();
cl->create_curve ();
cl->fast_simple_add(0.0, 42.0);
cl->fast_simple_add(timepos_t(0), 42.0);
{
// Write-lock list
Glib::Threads::RWLock::WriterLock lm(cl->lock());
// Attempt to get vector in RT (expect failure)
CPPUNIT_ASSERT (!cl->curve().rt_safe_get_vector (1024.0, 2047.0, vec, 1024));
CPPUNIT_ASSERT (!cl->curve().rt_safe_get_vector (t1024, t2047, vec, 1024));
}
// Attempt to get vector in RT (expect success)
CPPUNIT_ASSERT (cl->curve().rt_safe_get_vector (1024.0, 2047.0, vec, 1024));
CPPUNIT_ASSERT (cl->curve().rt_safe_get_vector (t1024, t2047, vec, 1024));
for (int i = 0; i < 1024; ++i) {
CPPUNIT_ASSERT_EQUAL (42.0f, vec[i]);
}
@ -96,46 +103,55 @@ CurveTest::twoPointLinear ()
cl->create_curve ();
cl->set_interpolation (ControlList::Linear);
timepos_t t0 (0);
timepos_t t1024 (1024);
timepos_t t2048 (2048);
timepos_t t2047 (2047);
timepos_t t2049 (2049);
timepos_t t2056 (2056);
timepos_t t4092 (4092);
timepos_t t8192 (8192);
// add two points to curve
cl->fast_simple_add ( 0.0 , 2048.0);
cl->fast_simple_add (8192.0 , 4096.0);
cl->fast_simple_add (t0 , 2048.0);
cl->fast_simple_add (t8192, 4096.0);
cl->curve ().get_vector (1024.0, 2047.0, vec, 1024);
cl->curve ().get_vector (t1024, t2047, vec, 1024);
VEC1024LINCMP (1024.0, 2047.0, 2304.f, .25f);
VEC1024LINCMP (2048.0, 2559.5, 2560.f, .125f);
VEC1024LINCMP ( 0.0, 4092.0, 2048.f, 1.f);
VEC1024LINCMP (t1024, t2047, 2304.f, .25f);
//VEC1024LINCMP (t2048, timepos_t (2559.5), 2560.f, .125f);
VEC1024LINCMP (t0, t4092, 2048.f, 1.f);
// greetings to tartina
cl->curve ().get_vector (2048.0, 2048.0, vec, 1);
cl->curve ().get_vector (t2048, t2048, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 2048..2048", 2560.f, vec[0]);
/* XXX WHAT DO WE EXPECT WITH veclen=1 AND x1 > x0 ? */
#if 0
/* .. interpolated value at (x1+x0)/2 */
cl->curve ().get_vector (2048.0, 2049.0, vec, 1);
cl->curve ().get_vector (2048.0, t2049, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 2048-2049", 2560.125f, vec[0]);
cl->curve ().get_vector (2048.0, 2056.0, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 2048-2049", 2561.f, vec[0]);
#else
/* .. value at x0 */
cl->curve ().get_vector (2048.0, 2049.0, vec, 1);
cl->curve ().get_vector (t2048, t2049, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 , 2048..2049", 2560.f, vec[0]);
cl->curve ().get_vector (2048.0, 2056.0, vec, 1);
cl->curve ().get_vector (t2048, t2056, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 , 2048..2049", 2560.f, vec[0]);
#endif
cl->curve ().get_vector (2048.0, 2048.0, vec, 2);
cl->curve ().get_vector (t2048, t2048, vec, 2);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2048 @ 0", 2560.f, vec[0]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2048 @ 1", 2560.f, vec[1]);
cl->curve ().get_vector (2048.0, 2056.0, vec, 2);
cl->curve ().get_vector (t2048, t2056, vec, 2);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2056 @ 0", 2560.f, vec[0]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=2 , 2048..2056 @ 0", 2562.f, vec[1]);
cl->curve ().get_vector (2048.0, 2056.0, vec, 3);
cl->curve ().get_vector (t2048, t2056, vec, 3);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 , 2048..2056 @ 0", 2560.f, vec[0]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 , 2048..2056 @ 1", 2561.f, vec[1]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 , 2048..2056 @ 2", 2562.f, vec[2]);
@ -143,18 +159,22 @@ CurveTest::twoPointLinear ()
/* check out-of range..
* we expect the first and last value - no interpolation
*/
cl->curve ().get_vector (-1, -1, vec, 1);
timepos_t tm1 (-1);
timepos_t tm999 (-999);
timepos_t t9998 (9998);
timepos_t t9999 (9999);
cl->curve ().get_vector (tm1, tm1, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ -1", 2048.f, vec[0]);
cl->curve ().get_vector (9999.0, 9999.0, vec, 1);
cl->curve ().get_vector (t9999, t9999, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 9999", 4096.f, vec[0]);
cl->curve ().get_vector (-999.0, 0, vec, 13);
cl->curve ().get_vector (tm999, t0, vec, 13);
for (int i = 0; i < 13; ++i) {
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=13 @ -999..0", 2048.f, vec[i]);
}
cl->curve ().get_vector (9998.0, 9999.0, vec, 8);
cl->curve ().get_vector (t9998, t9999, vec, 8);
for (int i = 0; i < 8; ++i) {
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=8 @ 9998..9999", 4096.f, vec[i]);
}
@ -170,26 +190,36 @@ CurveTest::threePointLinear ()
cl->create_curve ();
cl->set_interpolation (ControlList::Linear);
// add 3 points to curve
cl->fast_simple_add ( 0.0 , 2.0);
cl->fast_simple_add ( 100.0 , 4.0);
cl->fast_simple_add ( 200.0 , 0.0);
timepos_t t0 (0);
timepos_t t50 (50);
timepos_t t60 (60);
timepos_t t80 (80);
timepos_t t100 (100);
timepos_t t130 (130);
timepos_t t150 (150);
timepos_t t160 (160);
timepos_t t200 (200);
cl->curve ().get_vector (50.0, 60.0, vec, 1);
// add 3 points to curve
cl->fast_simple_add ( t0 , 2.0);
cl->fast_simple_add (t100 , 4.0);
cl->fast_simple_add (t200 , 0.0);
cl->curve ().get_vector (t50, t60, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 50", 3.f, vec[0]);
cl->curve ().get_vector (100.0, 100.0, vec, 1);
cl->curve ().get_vector (t100, t100, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 100", 4.f, vec[0]);
cl->curve ().get_vector (150.0, 150.0, vec, 1);
cl->curve ().get_vector (t150, t150, vec, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=1 @ 150", 2.f, vec[0]);
cl->curve ().get_vector (130.0, 150.0, vec, 3);
cl->curve ().get_vector (t130, t150, vec, 3);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 130..150 @ 0", 2.8f, vec[0]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 130..150 @ 2", 2.4f, vec[1]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 130..150 @ 3", 2.0f, vec[2]);
cl->curve ().get_vector (80.0, 160.0, vec, 3);
cl->curve ().get_vector (t80, t160, vec, 3);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 80..160 @ 0", 3.6f, vec[0]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 80..160 @ 2", 3.2f, vec[1]);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("veclen=3 80..160 @ 3", 1.6f, vec[2]);
@ -201,20 +231,27 @@ CurveTest::threePointDiscete ()
boost::shared_ptr<Evoral::ControlList> cl = TestCtrlList();
cl->set_interpolation (ControlList::Discrete);
// add 3 points to curve
cl->fast_simple_add ( 0.0 , 2.0);
cl->fast_simple_add ( 100.0 , 4.0);
cl->fast_simple_add ( 200.0 , 0.0);
timepos_t t0 (0);
timepos_t t80 (80);
timepos_t t100 (100);
timepos_t t120 (120);
timepos_t t160 (160);
timepos_t t200 (200);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.));
// add 3 points to curve
cl->fast_simple_add ( t0 , 2.0);
cl->fast_simple_add (t100 , 4.0);
cl->fast_simple_add (t200 , 0.0);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(160.));
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(t160));
}
void
@ -222,75 +259,87 @@ CurveTest::ctrlListEval ()
{
boost::shared_ptr<Evoral::ControlList> cl = TestCtrlList();
cl->fast_simple_add ( 0.0 , 2.0);
timepos_t t0 (0);
timepos_t t80 (80);
timepos_t t100 (100);
timepos_t t120 (120);
timepos_t t160 (160);
timepos_t t200 (200);
timepos_t t250 (250);
timepos_t t300 (300);
timepos_t t350 (350);
timepos_t t400 (400);
timepos_t t999 (999);
cl->fast_simple_add (t0 , 2.0);
cl->set_interpolation (ControlList::Discrete);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(160.));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t160));
cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(160.));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t160));
cl->fast_simple_add ( 100.0 , 4.0);
cl->fast_simple_add (t100 , 4.0);
cl->set_interpolation (ControlList::Discrete);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.));
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
cl->fast_simple_add ( 200.0 , 0.0);
cl->fast_simple_add (t200 , 0.0);
cl->set_interpolation (ControlList::Discrete);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(160.));
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(t160));
cl->fast_simple_add ( 300.0 , 8.0);
cl->fast_simple_add (t300 , 8.0);
cl->set_interpolation (ControlList::Discrete);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.));
CPPUNIT_ASSERT_EQUAL(0.0, cl->unlocked_eval(250.));
CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(999.));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
CPPUNIT_ASSERT_EQUAL(0.0, cl->unlocked_eval(t250));
CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(t999));
cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(160.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(250.));
CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(999.));
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(t160));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t250));
CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(t999));
cl->fast_simple_add ( 400.0 , 9.0);
cl->fast_simple_add (t400 , 9.0);
cl->set_interpolation (ControlList::Discrete);
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(160.));
CPPUNIT_ASSERT_EQUAL(0.0, cl->unlocked_eval(250.));
CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(350.));
CPPUNIT_ASSERT_EQUAL(9.0, cl->unlocked_eval(999.));
CPPUNIT_ASSERT_EQUAL(2.0, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t160));
CPPUNIT_ASSERT_EQUAL(0.0, cl->unlocked_eval(t250));
CPPUNIT_ASSERT_EQUAL(8.0, cl->unlocked_eval(t350));
CPPUNIT_ASSERT_EQUAL(9.0, cl->unlocked_eval(t999));
cl->set_interpolation (ControlList::Linear);
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(80.));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(120.));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(160.));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(250.));
CPPUNIT_ASSERT_EQUAL(8.5, cl->unlocked_eval(350.));
CPPUNIT_ASSERT_EQUAL(9.0, cl->unlocked_eval(999.));
CPPUNIT_ASSERT_EQUAL(3.6, cl->unlocked_eval(t80));
CPPUNIT_ASSERT_EQUAL(3.2, cl->unlocked_eval(t120));
CPPUNIT_ASSERT_EQUAL(1.6, cl->unlocked_eval(t160));
CPPUNIT_ASSERT_EQUAL(4.0, cl->unlocked_eval(t250));
CPPUNIT_ASSERT_EQUAL(8.5, cl->unlocked_eval(t350));
CPPUNIT_ASSERT_EQUAL(9.0, cl->unlocked_eval(t999));
}
void
@ -317,19 +366,19 @@ CurveTest::constrainedCubic ()
Evoral::ParameterDescriptor pd;
pd.lower = 5;
pd.upper = 325;
Evoral::ControlList l(p,pd);
Evoral::ControlList l(p, pd, AudioTime);
size_t i;
l.set_interpolation(Evoral::ControlList::Curved);
for (i=0; i<sizeof(data)/sizeof(data[0]); i++) {
l.add (data[i].x, data[i].y);
l.add (timepos_t (data[i].x), data[i].y);
}
Evoral::Curve curve(l);
float f[121];
curve.get_vector(-10, 110, f, 121);
curve.get_vector(timepos_t (-10), timepos_t (110), f, 121);
const float *g = &f[10]; /* so g starts at x==0 */

View File

@ -28,6 +28,6 @@ private:
boost::shared_ptr<Evoral::ControlList> TestCtrlList() {
Evoral::Parameter param (Evoral::Parameter(0));
const Evoral::ParameterDescriptor desc;
return boost::shared_ptr<Evoral::ControlList> (new Evoral::ControlList(param, desc));
return boost::shared_ptr<Evoral::ControlList> (new Evoral::ControlList(param, desc, Temporal::AudioTime));
}
};

View File

@ -12,7 +12,7 @@ typedef Temporal::Beats Time;
void
NoteTest::copyTest ()
{
Note<Time> a(0, Time(1.0), Time(2.0), 60, 0x40);
Note<Time> a(0, Time::from_double(1.0), Time::from_double(2.0), 60, 0x40);
Note<Time> b(a);
CPPUNIT_ASSERT (a == b);
@ -25,7 +25,7 @@ NoteTest::copyTest ()
void
NoteTest::idTest ()
{
Note<Time> a(0, Time(1.0), Time(2.0), 60, 0x40);
Note<Time> a(0, Time::from_double(1.0), Time::from_double(2.0), 60, 0x40);
CPPUNIT_ASSERT_EQUAL (-1, a.id());
a.set_id(1234);

View File

@ -5,24 +5,30 @@
CPPUNIT_TEST_SUITE_REGISTRATION (RangeTest);
using namespace Evoral;
using namespace Temporal;
void
RangeTest::coalesceTest ()
{
RangeList<int> fred;
fred.add (Range<int> (2, 4));
fred.add (Range<int> (5, 6));
fred.add (Range<int> (6, 8));
timepos_t t2 (2);
timepos_t t4 (4);
timepos_t t5 (5);
timepos_t t6 (6);
timepos_t t8 (8);
RangeList<int>::List jim = fred.get ();
RangeList fred;
fred.add (Range (t2, t4));
fred.add (Range (t5, t6));
fred.add (Range (t6, t8));
RangeList<int>::List::iterator i = jim.begin ();
CPPUNIT_ASSERT_EQUAL (2, i->from);
CPPUNIT_ASSERT_EQUAL (4, i->to);
RangeList::List jim = fred.get ();
RangeList::List::iterator i = jim.begin ();
CPPUNIT_ASSERT_EQUAL (2L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (4L, i->end().samples());
++i;
CPPUNIT_ASSERT_EQUAL (5, i->from);
CPPUNIT_ASSERT_EQUAL (8, i->to);
CPPUNIT_ASSERT_EQUAL (5L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (8L, i->end().samples());
}
/* Basic subtraction of a few smaller ranges from a larger one */
@ -30,67 +36,82 @@ void
RangeTest::subtractTest1 ()
{
timepos_t t0 (0);
timepos_t t2 (2);
timepos_t t4 (4);
timepos_t t7 (7);
timepos_t t8 (8);
timepos_t t10 (10);
/* 01234567890
* fred: |---------|
* jim: |-| ||
* sheila: || || ||
*/
Range<int> fred (0, 10);
Range fred (t0, t10);
RangeList<int> jim;
jim.add (Range<int> (2, 4));
jim.add (Range<int> (7, 8));
RangeList jim;
jim.add (Range (t2, t4));
jim.add (Range (t7, t8));
RangeList<int> sheila = subtract (fred, jim);
RangeList sheila = fred.subtract (jim);
RangeList<int>::List s = sheila.get ();
RangeList::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (3), s.size ());
RangeList<int>::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (0, i->from);
CPPUNIT_ASSERT_EQUAL (1, i->to);
RangeList::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (0L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (1L, i->end().samples()); // XXX -> 2
++i;
CPPUNIT_ASSERT_EQUAL (5, i->from);
CPPUNIT_ASSERT_EQUAL (6, i->to);
CPPUNIT_ASSERT_EQUAL (5L, i->start().samples()); // XXX -> 4
CPPUNIT_ASSERT_EQUAL (6L, i->end().samples()); // XXX -> 7
++i;
CPPUNIT_ASSERT_EQUAL (9, i->from);
CPPUNIT_ASSERT_EQUAL (10, i->to);
CPPUNIT_ASSERT_EQUAL (9L, i->start().samples()); // XXX -> 8
CPPUNIT_ASSERT_EQUAL (10L, i->end().samples());
}
/* Test subtraction of a range B from a range A, where A and B do not overlap */
void
RangeTest::subtractTest2 ()
{
Range<int> fred (0, 10);
timepos_t t0 (0);
timepos_t t10 (10);
timepos_t t12 (12);
timepos_t t19 (19);
RangeList<int> jim;
jim.add (Range<int> (12, 19));
Range fred (t0, t10);
RangeList<int> sheila = subtract (fred, jim);
RangeList jim;
jim.add (Range (t12, t19));
RangeList<int>::List s = sheila.get ();
RangeList sheila = fred.subtract (jim);
RangeList::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (1), s.size ());
RangeList<int>::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (0, i->from);
CPPUNIT_ASSERT_EQUAL (10, i->to);
RangeList::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (0L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (10L, i->end().samples());
}
/* Test subtraction of B from A, where B entirely overlaps A */
void
RangeTest::subtractTest3 ()
{
Range<int> fred (0, 10);
timepos_t t0 (0);
timepos_t t10 (10);
timepos_t t12 (12);
Range fred (t0, t10);
RangeList<int> jim;
jim.add (Range<int> (0, 12));
RangeList jim;
jim.add (Range (t0, t12));
RangeList<int> sheila = subtract (fred, jim);
RangeList sheila = fred.subtract (jim);
RangeList<int>::List s = sheila.get ();
RangeList::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (0), s.size ());
}
@ -100,6 +121,14 @@ RangeTest::subtractTest3 ()
void
RangeTest::subtractTest4 ()
{
timepos_t t0 (0);
timepos_t t2 (2);
timepos_t t4 (4);
timepos_t t7 (7);
timepos_t t8 (8);
timepos_t t9 (9);
timepos_t t10 (10);
/* 01234567890
* fred: |---------|
* jim: |-| ||
@ -107,29 +136,29 @@ RangeTest::subtractTest4 ()
* sheila: || || |
*/
Range<int> fred (0, 10);
Range fred (t0, t10);
RangeList<int> jim;
jim.add (Range<int> (2, 4));
jim.add (Range<int> (7, 8));
jim.add (Range<int> (8, 9));
RangeList jim;
jim.add (Range (t2, t4));
jim.add (Range (t7, t8));
jim.add (Range (t8, t9));
RangeList<int> sheila = subtract (fred, jim);
RangeList sheila = fred.subtract (jim);
RangeList<int>::List s = sheila.get ();
RangeList::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (3), s.size ());
RangeList<int>::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (0, i->from);
CPPUNIT_ASSERT_EQUAL (1, i->to);
RangeList::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (0L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (1L, i->end().samples());
++i;
CPPUNIT_ASSERT_EQUAL (5, i->from);
CPPUNIT_ASSERT_EQUAL (6, i->to);
CPPUNIT_ASSERT_EQUAL (5L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (6L, i->end().samples());
++i;
CPPUNIT_ASSERT_EQUAL (10, i->from);
CPPUNIT_ASSERT_EQUAL (10, i->to);
CPPUNIT_ASSERT_EQUAL (10L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (10L, i->end().samples());
}
/* A bit like subtractTest1, except some of the ranges
@ -139,31 +168,40 @@ RangeTest::subtractTest4 ()
void
RangeTest::subtractTest5 ()
{
timepos_t t0 (0);
timepos_t t1 (1);
timepos_t t4 (4);
timepos_t t6 (6);
timepos_t t7 (7);
timepos_t t9 (9);
timepos_t t12 (12);
timepos_t t42 (42);
/* 01234567890123
* fred: |----------|
* jim: |---| || |------...
* sheila:i | |
*/
Range<int> fred (1, 12);
Range fred (t1, t12);
RangeList<int> jim;
jim.add (Range<int> (0, 4));
jim.add (Range<int> (6, 7));
jim.add (Range<int> (9, 42));
RangeList jim;
jim.add (Range (t0, t4));
jim.add (Range (t6, t7));
jim.add (Range (t9, t42));
RangeList<int> sheila = subtract (fred, jim);
RangeList sheila = fred.subtract (jim);
RangeList<int>::List s = sheila.get ();
RangeList::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (2), s.size ());
RangeList<int>::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (5, i->from);
CPPUNIT_ASSERT_EQUAL (5, i->to);
RangeList::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (5L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (5L, i->end().samples());
++i;
CPPUNIT_ASSERT_EQUAL (8, i->from);
CPPUNIT_ASSERT_EQUAL (8, i->to);
CPPUNIT_ASSERT_EQUAL (8L, i->start().samples());
CPPUNIT_ASSERT_EQUAL (8L, i->end().samples());
}
/* Test coverage() with all possible types of overlap.
@ -172,60 +210,61 @@ RangeTest::subtractTest5 ()
void
RangeTest::coverageTest ()
{
#define coverage(A0, A1, B0, B1) Range(timepos_t(A0), timepos_t(A1)).coverage(timepos_t(B0), timepos_t(B1))
// b starts before a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 1), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 2), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 3), Evoral::OverlapStart);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 5), Evoral::OverlapStart);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 7), Evoral::OverlapExternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 9), Evoral::OverlapExternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 1), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 2), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 3), OverlapStart); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 5), OverlapStart);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 7), OverlapExternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 9), OverlapExternal);
// b starts at a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 3), Evoral::OverlapStart);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 5), Evoral::OverlapStart);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 7), Evoral::OverlapExternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 9), Evoral::OverlapExternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 3), OverlapStart); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 5), OverlapStart);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 7), OverlapExternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 9), OverlapExternal);
// b starts inside a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 4), Evoral::OverlapInternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 6), Evoral::OverlapInternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 7), Evoral::OverlapEnd);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 8), Evoral::OverlapEnd);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 4), OverlapInternal); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 6), OverlapInternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 7), OverlapEnd);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 8), OverlapEnd);
// b starts at end of a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 7), Evoral::OverlapEnd);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 9), Evoral::OverlapEnd);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 7), OverlapEnd); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 9), OverlapEnd); // XXX fails
// b starts after end of a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 8), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 9), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 8), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 9), OverlapNone);
// zero-length range a
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 2, 4), Evoral::OverlapExternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 1, 2), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 3, 3), Evoral::OverlapExternal);
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 8, 9), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 2, 4), OverlapExternal); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 1, 2), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 3, 3), OverlapExternal); // XXX fails
CPPUNIT_ASSERT_EQUAL (coverage(3, 3, 8, 9), OverlapNone);
// negative length range a
// XXX these are debatable - should we just consider start & end to be
// swapped if end < start?
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 1, 2), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 2, 3), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 2, 4), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 3, 3), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 8, 9), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 1, 2), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 2, 3), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 2, 4), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 3, 3), OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(4, 3, 8, 9), OverlapNone);
// negative length range b
// b starts before a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 0), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 1, 0), OverlapNone);
// b starts at a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 2), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 3, 2), OverlapNone);
// b starts inside a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 3), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 4, 3), OverlapNone);
// b starts at end of a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 5), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 7, 5), OverlapNone);
// b starts after end of a
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 7), Evoral::OverlapNone);
CPPUNIT_ASSERT_EQUAL (coverage(3, 7, 8, 7), OverlapNone);
}

View File

@ -74,7 +74,6 @@ SMFTest::takeFiveTest ()
CPPUNIT_ASSERT(!seq->empty());
// Iterate over all notes
bool on = true;
size_t num_notes = 0;
size_t num_sysexes = 0;
for (Sequence<Time>::const_iterator i = seq->begin(Time()); i != seq->end(); ++i) {

View File

@ -24,6 +24,7 @@
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include "temporal/beats.h"
#include "temporal/tempo.h"
#include "evoral/SMF.h"
#include "SequenceTest.h"
@ -63,6 +64,7 @@ public:
typedef Temporal::Beats Time;
void setUp() {
Temporal::TempoMap::fetch();
type_map = new DummyTypeMap();
assert(type_map);
seq = new MySequence<Time>(*type_map);

View File

@ -41,8 +41,8 @@ SequenceTest::preserveEventOrderingTest ()
);
event->buffer()[0] = MIDI_CMD_CONTROL;
event->buffer()[1] = event->time().to_double() / 1000;
event->buffer()[2] = event->time().to_double() / 1000;
event->buffer()[1] = 0; //event->time().to_double() / 1000;
event->buffer()[2] = 0; //event->time().to_double() / 1000;
boost::shared_ptr<Event<Time> > event_ptr(event);
@ -88,10 +88,10 @@ SequenceTest::iteratorSeekTest ()
// Iterate over all notes
bool on = true;
for (Sequence<Time>::const_iterator i = seq->begin(Time(600)); i != seq->end(); ++i) {
for (Sequence<Time>::const_iterator i = seq->begin(Time::from_double(600)); i != seq->end(); ++i) {
if (on) {
CPPUNIT_ASSERT(i->is_note_on());
CPPUNIT_ASSERT_EQUAL(i->time(), Time((num_notes + 6) * 100));
CPPUNIT_ASSERT_EQUAL(i->time(), Time::from_double((num_notes + 6) * 100));
++num_notes;
on = false;
} else {
@ -103,20 +103,20 @@ SequenceTest::iteratorSeekTest ()
CPPUNIT_ASSERT_EQUAL(size_t(6), num_notes);
// Test invalidation
Sequence<Time>::const_iterator i = seq->begin(Time(600));
Sequence<Time>::const_iterator i = seq->begin(Time::from_double(600));
std::set< boost::weak_ptr< Note<Time> > > active_notes;
i.invalidate(&active_notes);
i.get_active_notes(active_notes);
CPPUNIT_ASSERT_EQUAL((size_t)1, active_notes.size());
// Test resuming after invalidation
i = seq->begin(Time(601), false, std::set<Evoral::Parameter>(), &active_notes);
i = seq->begin(Time::from_double(601), false, std::set<Evoral::Parameter>(), &active_notes);
CPPUNIT_ASSERT(i->is_note_off());
on = false;
num_notes = 1;
for (; i != seq->end(); ++i) {
if (on) {
CPPUNIT_ASSERT(i->is_note_on());
CPPUNIT_ASSERT_EQUAL(Time((num_notes + 6) * 100), i->time());
CPPUNIT_ASSERT_EQUAL(Time::from_double((num_notes + 6) * 100), i->time());
++num_notes;
on = false;
} else {
@ -137,6 +137,7 @@ SequenceTest::iteratorSeekTest ()
void
SequenceTest::controlInterpolationTest ()
{
using namespace Temporal;
seq->clear();
static const uint64_t delay = 1000;
@ -149,9 +150,9 @@ SequenceTest::controlInterpolationTest ()
double max = 127.0;
// Make a ramp like /\ from min to max and back to min
c->set_double(min, 0, true);
c->set_double(max, delay, true);
c->set_double(min, 2*delay, true);
c->set_double(min, timepos_t(Time::from_double(0)), true);
c->set_double(max, timepos_t(Time::from_double(delay)), true);
c->set_double(min, timepos_t(Time::from_double(2*delay)), true);
CCTestSink<Time> sink(cc_type);
@ -161,11 +162,11 @@ SequenceTest::controlInterpolationTest ()
sink.write(i->time(), i->event_type(), i->size(), i->buffer());
}
CPPUNIT_ASSERT_EQUAL((size_t)3, sink.events.size());
CPPUNIT_ASSERT_EQUAL(Time(0), sink.events[0].first);
CPPUNIT_ASSERT_EQUAL(Time::from_double(0), sink.events[0].first);
CPPUNIT_ASSERT_EQUAL((uint8_t)0, sink.events[0].second);
CPPUNIT_ASSERT_EQUAL(Time(1000), sink.events[1].first);
CPPUNIT_ASSERT_EQUAL(Time::from_double(1000), sink.events[1].first);
CPPUNIT_ASSERT_EQUAL((uint8_t)127, sink.events[1].second);
CPPUNIT_ASSERT_EQUAL(Time(2000), sink.events[2].first);
CPPUNIT_ASSERT_EQUAL(Time::from_double(2000), sink.events[2].first);
CPPUNIT_ASSERT_EQUAL((uint8_t)0, sink.events[2].second);
sink.events.clear();
CPPUNIT_ASSERT_EQUAL((size_t)0, sink.events.size());
@ -176,7 +177,7 @@ SequenceTest::controlInterpolationTest ()
sink.write(i->time(), i->event_type(), i->size(), i->buffer());
}
CPPUNIT_ASSERT_EQUAL((size_t)(128 * 2 - 1), sink.events.size());
Time last_time(0);
Time last_time = Time::from_double (0);
int16_t last_value = -1;
bool ascending = true;
for (CCTestSink<Time>::Events::const_iterator i = sink.events.begin();

View File

@ -63,7 +63,7 @@ public:
Evoral::ParameterDescriptor desc;
desc.upper = 127;
desc.rangesteps = 128;
boost::shared_ptr<ControlList> list(new ControlList(param, desc));
boost::shared_ptr<ControlList> list(new ControlList(param, desc, Temporal::BeatTime));
return boost::shared_ptr<Control>(new Control(param, desc, list));
}
};
@ -71,7 +71,7 @@ public:
template<typename Time>
class TestSink : public EventSink<Time> {
public:
TestSink() : _last_event_time(-1) {}
TestSink() : _last_event_time(Time::from_double (-1)) {}
/// return value, time, type, size, buffer
sigc::signal<uint32_t, Time, EventType, uint32_t, const uint8_t*> writing;
@ -136,7 +136,7 @@ public:
for (int i = 0; i < 12; i++) {
test_notes.push_back(
boost::shared_ptr<Note<Time> >(
new Note<Time>(0, Time(i * 100), Time(100), 64 + i, 64)));
new Note<Time>(0, Time::from_double(i * 100), Time::from_double(100), 64 + i, 64)));
}
}

View File

@ -6,11 +6,13 @@
#include <cppunit/BriefTestProgressListener.h>
#include "pbd/pbd.h"
#include "temporal/tempo.h"
int
main()
{
if (!PBD::init ()) return 1;
Temporal::init ();
CppUnit::TestResult testresult;

View File

@ -117,7 +117,7 @@ def build(bld):
obj.defines += [ 'PACKAGE="libevoral"' ]
# disable unit-tests -- build is broken with nutempo
if False and bld.env['BUILD_TESTS'] and bld.is_defined('HAVE_CPPUNIT'):
if bld.env['BUILD_TESTS'] and bld.is_defined('HAVE_CPPUNIT'):
# Static library (for unit test code coverage)
obj = bld(features = 'cxx cstlib')
obj.source = lib_source