X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fmidi%2B%2B2%2Ftest%2FMidnamTest.cpp;h=3d0beeb72f5b25e8dcda2f9ff733016866177a27;hb=ec8a4de01596c162c1529f3021dfc432bf66dfe8;hp=52bf988e9be4debc1465efd85c832b722784d262;hpb=8d0cba3384d862f5df9d5ce0675123c144579cd3;p=ardour.git diff --git a/libs/midi++2/test/MidnamTest.cpp b/libs/midi++2/test/MidnamTest.cpp index 52bf988e9b..3d0beeb72f 100644 --- a/libs/midi++2/test/MidnamTest.cpp +++ b/libs/midi++2/test/MidnamTest.cpp @@ -1,6 +1,7 @@ #include "MidnamTest.hpp" #include +#include #include "pbd/xml++.h" #include "pbd/file_utils.h" @@ -8,16 +9,34 @@ #include "midi++/midnam_patch.h" using namespace std; +using namespace PBD; using namespace MIDI::Name; CPPUNIT_TEST_SUITE_REGISTRATION( MidnamTest ); -static string const prefix = "../../../patchfiles/"; +PBD::Searchpath +test_search_path () +{ +#ifdef PLATFORM_WINDOWS + if (!getenv("MIDIPP_TEST_PATH")) { + std::vector path_tok; + path_tok.push_back (g_win32_get_package_installation_directory_of_module(NULL)); + path_tok.push_back ("share"); + path_tok.push_back ("ardour3"); + path_tok.push_back ("patchfiles"); + return Glib::build_filename (path_tok); + } +#endif + return Glib::getenv("MIDIPP_TEST_PATH"); +} void MidnamTest::protools_patchfile_test() { - XMLTree xmldoc(prefix + "Roland_SC-88_Pro.midnam"); + std::string test_file_path; + + CPPUNIT_ASSERT(find_file (test_search_path (), "Roland_SC-88_Pro.midnam", test_file_path)); + XMLTree xmldoc(test_file_path); boost::shared_ptr result = xmldoc.find( "//MIDINameDocument"); CPPUNIT_ASSERT(result->size() == 1); @@ -25,7 +44,7 @@ MidnamTest::protools_patchfile_test() result = xmldoc.find("//ChannelNameSet"); CPPUNIT_ASSERT(result->size() == 2); - MIDINameDocument doc(prefix + "Roland_SC-88_Pro.midnam"); + MIDINameDocument doc(test_file_path); CPPUNIT_ASSERT(doc.all_models().size() == 1); CPPUNIT_ASSERT(doc.author().find("Mark of the Unicorn") == 0); @@ -82,7 +101,10 @@ MidnamTest::protools_patchfile_test() void MidnamTest::yamaha_PSRS900_patchfile_test() { - XMLTree xmldoc(prefix + "Yamaha_PSR-S900.midnam"); + std::string test_file_path; + + CPPUNIT_ASSERT(find_file (test_search_path (), "Yamaha_PSR-S900.midnam", test_file_path)); + XMLTree xmldoc(test_file_path); boost::shared_ptr result = xmldoc.find( "//MIDINameDocument"); CPPUNIT_ASSERT(result->size() == 1); @@ -90,7 +112,7 @@ MidnamTest::yamaha_PSRS900_patchfile_test() result = xmldoc.find("//ChannelNameSet"); CPPUNIT_ASSERT(result->size() == 3); - MIDINameDocument doc(prefix + "Yamaha_PSR-S900.midnam"); + MIDINameDocument doc(test_file_path); CPPUNIT_ASSERT(doc.all_models().size() == 1); CPPUNIT_ASSERT(doc.author().find("Hans Baier") == 0); @@ -138,13 +160,11 @@ MidnamTest::yamaha_PSRS900_patchfile_test() for(PatchNameList::const_iterator p = list.begin(); p != list.end(); ++p) { if (ns == string("GM+XG")) { - cerr << "got Patch with name " << (*p)->name() << " bank " << (*p)->bank_number() << " program " << (int)(*p)->program_number() << endl; uint8_t msb = (((*p)->bank_number()) >> 7) & 0x7f; CPPUNIT_ASSERT( msb == 0 || msb == 64); } if (ns == string("GM2")) { - cerr << "got Patch with name " << (*p)->name() << " bank " << (*p)->bank_number() << " program " << (int)(*p)->program_number() << endl; CPPUNIT_ASSERT((*p)->bank_number() >= (uint16_t(120) << 7)); } } @@ -152,20 +172,19 @@ MidnamTest::yamaha_PSRS900_patchfile_test() } } -void +void MidnamTest::load_all_midnams_test () { - assert (Glib::file_test (prefix, Glib::FILE_TEST_IS_DIR)); - - Glib::PatternSpec pattern(string("*.midnam")); vector result; - PBD::find_files_matching_pattern (result, prefix, pattern); + PBD::find_files_matching_pattern (result, test_search_path (), "*.midnam"); - cout << "Loading " << result.size() << " MIDI patches from " << prefix << endl; + CPPUNIT_ASSERT(!result.empty()); + + cout << "Loading " << result.size() << " MIDI patches from " << test_search_path ().to_string () << endl; for (vector::iterator i = result.begin(); i != result.end(); ++i) { - cout << "Processing file " << *i << endl; + cout << "Processing file " << Glib::path_get_basename(*i) << endl; boost::shared_ptr document(new MIDINameDocument(*i)); XMLTree xmldoc(*i); @@ -175,9 +194,6 @@ MidnamTest::load_all_midnams_test () result = xmldoc.find("//MasterDeviceNames"); CPPUNIT_ASSERT(result->size() == 1); - result = xmldoc.find("//ChannelNameSet"); - CPPUNIT_ASSERT(result->size() >= 1); - result = xmldoc.find("//PatchBank"); //int banks = result->size(); @@ -189,7 +205,6 @@ MidnamTest::load_all_midnams_test () document->master_device_names_by_model().begin(); string modename = device->second->custom_device_mode_names().front(); - cerr << "modename:" << modename << endl; boost::shared_ptr mode = device->second->custom_device_mode_by_name(modename); CPPUNIT_ASSERT_EQUAL(deviceModeName, mode->name());