const RootPidStore *RootPidStore::LoadFromDirectory( const std::string &directory, bool validate) { PidStoreLoader loader; string data_source = directory; if (directory.empty()) { data_source = DataLocation(); } return loader.LoadFromDirectory(data_source, validate); }
/** * Check that loading from a directory works. This also tests the override * mechanism. */ void PidStoreTest::testPidStoreDirectoryLoad() { PidStoreLoader loader; auto_ptr<const RootPidStore> root_store(loader.LoadFromDirectory( GetTestDataFile("pids"))); OLA_ASSERT_NOT_NULL(root_store.get()); // check version OLA_ASSERT_EQ(static_cast<uint64_t>(1302986774), root_store->Version()); // Check all the esta pids are there const PidStore *esta_store = root_store->EstaStore(); OLA_ASSERT_NOT_NULL(esta_store); vector<const PidDescriptor*> all_pids; esta_store->AllPids(&all_pids); OLA_ASSERT_EQ(static_cast<size_t>(4), all_pids.size()); // check manufacturer pids const PidStore *open_lighting_store = root_store->ManufacturerStore(ola::OPEN_LIGHTING_ESTA_CODE); OLA_ASSERT_NOT_NULL(open_lighting_store); OLA_ASSERT_EQ(1u, open_lighting_store->PidCount()); // FOO_BAR in the overrides file replaces SERIAL_NUMBER. const PidDescriptor *serial_number = open_lighting_store->LookupPID( "SERIAL_NUMBER"); OLA_ASSERT_NULL(serial_number); const PidDescriptor *foo_bar = open_lighting_store->LookupPID( "FOO_BAR"); OLA_ASSERT_NOT_NULL(foo_bar); OLA_ASSERT_EQ(static_cast<uint16_t>(32768), foo_bar->Value()); OLA_ASSERT_EQ(string("FOO_BAR"), foo_bar->Name()); // check descriptors OLA_ASSERT_TRUE(foo_bar->GetRequest()); OLA_ASSERT_TRUE(foo_bar->GetResponse()); OLA_ASSERT_EQ(static_cast<const Descriptor*>(NULL), foo_bar->SetRequest()); OLA_ASSERT_EQ(static_cast<const Descriptor*>(NULL), foo_bar->SetResponse()); ola::messaging::SchemaPrinter printer; foo_bar->GetResponse()->Accept(&printer); string expected2 = "baz: uint32\n"; OLA_ASSERT_EQ(expected2, printer.AsString()); }
/** * Check that loading a file with an inconsistent descriptor fails. */ void PidStoreTest::testInconsistentData() { PidStoreLoader loader; const RootPidStore *root_store = loader.LoadFromFile( GetTestDataFile("inconsistent_pid.proto")); OLA_ASSERT_NULL(root_store); }
/** * Check that loading a file with an out-of-range ESTA pid fails. */ void PidStoreTest::testPidStoreLoadInvalidEstaPid() { PidStoreLoader loader; const RootPidStore *root_store = loader.LoadFromFile( GetTestDataFile("invalid_esta_pid.proto")); OLA_ASSERT_NULL(root_store); }
/** * Check that loading a file with duplicate pid names fails. */ void PidStoreTest::testPidStoreLoadDuplicateName() { PidStoreLoader loader; const RootPidStore *root_store = loader.LoadFromFile( GetTestDataFile("duplicate_pid_name.proto")); OLA_ASSERT_NULL(root_store); }
/** * Check that loading a file with duplicate manufacturers fails. */ void PidStoreTest::testPidStoreLoadDuplicateManufacturer() { PidStoreLoader loader; const RootPidStore *root_store = loader.LoadFromFile( GetTestDataFile("duplicate_manufacturer.proto")); OLA_ASSERT_NULL(root_store); }
/** * Check that loading a missing file fails. */ void PidStoreTest::testPidStoreLoadMissingFile() { PidStoreLoader loader; const RootPidStore *root_store = loader.LoadFromFile( GetTestDataFile("missing_file_pids.proto")); OLA_ASSERT_NULL(root_store); }
/** * Check that loading from a file works */ void PidStoreTest::testPidStoreFileLoad() { PidStoreLoader loader; auto_ptr<const RootPidStore> root_store( loader.LoadFromFile(GetTestDataFile("test_pids.proto"))); OLA_ASSERT_NOT_NULL(root_store.get()); // check version OLA_ASSERT_EQ(static_cast<uint64_t>(1302986774), root_store->Version()); // Check all the esta pids are there const PidStore *esta_store = root_store->EstaStore(); OLA_ASSERT_NOT_NULL(esta_store); vector<const PidDescriptor*> all_pids; esta_store->AllPids(&all_pids); OLA_ASSERT_EQ(static_cast<size_t>(70), all_pids.size()); // check for device info const PidDescriptor *device_info = esta_store->LookupPID("DEVICE_INFO"); OLA_ASSERT_NOT_NULL(device_info); OLA_ASSERT_EQ(static_cast<uint16_t>(96), device_info->Value()); OLA_ASSERT_EQ(string("DEVICE_INFO"), device_info->Name()); // check descriptors OLA_ASSERT_TRUE(device_info->GetRequest()); OLA_ASSERT_TRUE(device_info->GetResponse()); OLA_ASSERT_EQ(static_cast<const Descriptor*>(NULL), device_info->SetRequest()); OLA_ASSERT_EQ(static_cast<const Descriptor*>(NULL), device_info->SetResponse()); ola::messaging::SchemaPrinter printer; device_info->GetResponse()->Accept(&printer); string expected = ( "protocol_major: uint8\nprotocol_minor: uint8\ndevice_model: uint16\n" "product_category: uint16\nsoftware_version: uint32\n" "dmx_footprint: uint16\ncurrent_personality: uint8\n" "personality_count: uint8\ndmx_start_address: uint16\n" "sub_device_count: uint16\nsensor_count: uint8\n"); OLA_ASSERT_EQ(expected, printer.AsString()); // check manufacturer pids const PidStore *open_lighting_store = root_store->ManufacturerStore(ola::OPEN_LIGHTING_ESTA_CODE); OLA_ASSERT_NOT_NULL(open_lighting_store); OLA_ASSERT_EQ(1u, open_lighting_store->PidCount()); const PidDescriptor *serial_number = open_lighting_store->LookupPID( "SERIAL_NUMBER"); OLA_ASSERT_NOT_NULL(serial_number); OLA_ASSERT_EQ(static_cast<uint16_t>(32768), serial_number->Value()); OLA_ASSERT_EQ(string("SERIAL_NUMBER"), serial_number->Name()); // check descriptors OLA_ASSERT_EQ(static_cast<const Descriptor*>(NULL), serial_number->GetRequest()); OLA_ASSERT_EQ(static_cast<const Descriptor*>(NULL), serial_number->GetResponse()); OLA_ASSERT_TRUE(serial_number->SetRequest()); OLA_ASSERT_TRUE(serial_number->SetResponse()); printer.Reset(); serial_number->SetRequest()->Accept(&printer); string expected2 = "serial_number: uint32\n"; OLA_ASSERT_EQ(expected2, printer.AsString()); }
/** * Check we can load a PidStore from a string */ void PidStoreTest::testPidStoreLoad() { PidStoreLoader loader; // This is a stringstream not a ostringstream as the other end needs an // istream stringstream str; // check that this fails to load const RootPidStore *empty_root_store = loader.LoadFromStream(&str); OLA_ASSERT_EQ(static_cast<const RootPidStore*>(NULL), empty_root_store); // now try a simple pid store config str.clear(); str << "pid {" << endl << " name: \"PROXIED_DEVICES\"" << endl << " value: 16" << endl << " get_request {" << endl << " }" << endl << " get_response {" << endl << " field {" << endl << " type: GROUP" << endl << " name: \"uids\"" << endl << " field {" << endl << " type: UINT16" << endl << " name: \"manufacturer_id\"" << endl << " }" << endl << " field {" << endl << " type: UINT32" << endl << " name: \"device_id\"" << endl << " }" << endl << " }" << endl << " }" << endl << " get_sub_device_range: ROOT_DEVICE" << endl << "}" << endl << "manufacturer {" << endl << " manufacturer_id: 31344" << endl << " manufacturer_name: \"Open Lighting\"" << endl << "}" << endl << "version: 1" << endl; auto_ptr<const RootPidStore> root_store(loader.LoadFromStream(&str)); OLA_ASSERT_TRUE(root_store.get()); // check version OLA_ASSERT_EQ(static_cast<uint64_t>(1), root_store->Version()); // check manufacturer pids const PidStore *open_lighting_store = root_store->ManufacturerStore(ola::OPEN_LIGHTING_ESTA_CODE); OLA_ASSERT_TRUE(open_lighting_store); OLA_ASSERT_EQ(0u, open_lighting_store->PidCount()); // lookup by value OLA_ASSERT_TRUE(root_store->GetDescriptor(16)); OLA_ASSERT_FALSE(root_store->GetDescriptor(17)); OLA_ASSERT_TRUE(root_store->GetDescriptor(16, ola::OPEN_LIGHTING_ESTA_CODE)); OLA_ASSERT_FALSE(root_store->GetDescriptor(17, ola::OPEN_LIGHTING_ESTA_CODE)); // lookup by name OLA_ASSERT_TRUE(root_store->GetDescriptor("PROXIED_DEVICES")); OLA_ASSERT_FALSE(root_store->GetDescriptor("DEVICE_INFO")); OLA_ASSERT_TRUE(root_store->GetDescriptor("PROXIED_DEVICES", ola::OPEN_LIGHTING_ESTA_CODE)); OLA_ASSERT_FALSE(root_store->GetDescriptor("DEVICE_INFO", ola::OPEN_LIGHTING_ESTA_CODE)); // check lookups const PidStore *esta_store = root_store->EstaStore(); OLA_ASSERT_TRUE(esta_store); const PidDescriptor *pid_descriptor = esta_store->LookupPID(16); OLA_ASSERT_TRUE(pid_descriptor); const PidDescriptor *pid_descriptor2 = esta_store->LookupPID( "PROXIED_DEVICES"); OLA_ASSERT_TRUE(pid_descriptor2); OLA_ASSERT_EQ(pid_descriptor, pid_descriptor2); // check name and value OLA_ASSERT_EQ(static_cast<uint16_t>(16), pid_descriptor->Value()); OLA_ASSERT_EQ(string("PROXIED_DEVICES"), pid_descriptor->Name()); // check descriptors OLA_ASSERT_TRUE(pid_descriptor->GetRequest()); OLA_ASSERT_TRUE(pid_descriptor->GetResponse()); OLA_ASSERT_EQ(static_cast<const Descriptor*>(NULL), pid_descriptor->SetRequest()); OLA_ASSERT_EQ(static_cast<const Descriptor*>(NULL), pid_descriptor->SetResponse()); // check GET descriptors const Descriptor *get_request = pid_descriptor->GetRequest(); OLA_ASSERT_EQ(0u, get_request->FieldCount()); const Descriptor *get_response = pid_descriptor->GetResponse(); OLA_ASSERT_EQ(1u, get_response->FieldCount()); const FieldDescriptor *proxied_group = get_response->GetField(0); OLA_ASSERT_TRUE(proxied_group); // this is ugly but it's a test const FieldDescriptorGroup *group_descriptor = dynamic_cast<const FieldDescriptorGroup*>(proxied_group); OLA_ASSERT_TRUE(group_descriptor); // check all the group properties OLA_ASSERT_FALSE(group_descriptor->FixedSize()); OLA_ASSERT_FALSE(group_descriptor->LimitedSize()); OLA_ASSERT_EQ(0u, group_descriptor->MaxSize()); OLA_ASSERT_EQ(2u, group_descriptor->FieldCount()); OLA_ASSERT_TRUE(group_descriptor->FixedBlockSize()); OLA_ASSERT_EQ(6u, group_descriptor->BlockSize()); OLA_ASSERT_EQ(6u, group_descriptor->MaxBlockSize()); OLA_ASSERT_EQ(static_cast<uint16_t>(0), group_descriptor->MinBlocks()); OLA_ASSERT_EQ(FieldDescriptorGroup::UNLIMITED_BLOCKS, group_descriptor->MaxBlocks()); OLA_ASSERT_FALSE(group_descriptor->FixedBlockCount()); // Check this prints correctly ola::messaging::SchemaPrinter printer; get_response->Accept(&printer); string expected = ( "uids {\n manufacturer_id: uint16\n device_id: uint32\n}\n"); OLA_ASSERT_EQ(expected, printer.AsString()); // check sub device ranges OLA_ASSERT_TRUE(pid_descriptor->IsGetValid(0)); OLA_ASSERT_FALSE(pid_descriptor->IsGetValid(1)); OLA_ASSERT_FALSE(pid_descriptor->IsGetValid(512)); OLA_ASSERT_FALSE(pid_descriptor->IsGetValid(ola::rdm::ALL_RDM_SUBDEVICES)); OLA_ASSERT_FALSE(pid_descriptor->IsSetValid(0)); OLA_ASSERT_FALSE(pid_descriptor->IsSetValid(1)); OLA_ASSERT_FALSE(pid_descriptor->IsSetValid(512)); OLA_ASSERT_FALSE(pid_descriptor->IsSetValid(ola::rdm::ALL_RDM_SUBDEVICES)); }
/** * Load all pid definition files in a directory */ const RootPidStore *RootPidStore::LoadFromDirectory( const std::string &directory, bool validate) { PidStoreLoader loader; return loader.LoadFromDirectory(directory, validate); }
/** * Load a pid store from a file */ const RootPidStore *RootPidStore::LoadFromFile(const std::string &file, bool validate) { PidStoreLoader loader; return loader.LoadFromFile(file, validate); }
/** * Check that loading a file with an inconsistent descriptor fails. */ void PidStoreTest::testInconsistentData() { PidStoreLoader loader; const RootPidStore *root_store = loader.LoadFromFile( "./testdata/inconsistent_pid.proto"); CPPUNIT_ASSERT(!root_store); }
/** * Check that loading a file with an out-of-range ESTA pid fails. */ void PidStoreTest::testPidStoreLoadInvalidEstaPid() { PidStoreLoader loader; const RootPidStore *root_store = loader.LoadFromFile( "./testdata/invalid_esta_pid.proto"); CPPUNIT_ASSERT(!root_store); }
/** * Check that loading a file with duplicate pid names fails. */ void PidStoreTest::testPidStoreLoadDuplicateName() { PidStoreLoader loader; const RootPidStore *root_store = loader.LoadFromFile( "./testdata/duplicate_pid_name.proto"); CPPUNIT_ASSERT(!root_store); }
/** * Check that loading a file with duplicate manufacturers fails. */ void PidStoreTest::testPidStoreLoadDuplicateManufacturer() { PidStoreLoader loader; const RootPidStore *root_store = loader.LoadFromFile( "./testdata/duplicate_manufacturer.proto"); CPPUNIT_ASSERT(!root_store); }
/** * Check that loading a missing file fails. */ void PidStoreTest::testPidStoreLoadMissingFile() { PidStoreLoader loader; const RootPidStore *root_store = loader.LoadFromFile( "./testdata/missing_file_pids.proto"); CPPUNIT_ASSERT(!root_store); }