当前位置: 首页>>代码示例>>C++>>正文


C++ PidStoreLoader::LoadFromStream方法代码示例

本文整理汇总了C++中PidStoreLoader::LoadFromStream方法的典型用法代码示例。如果您正苦于以下问题:C++ PidStoreLoader::LoadFromStream方法的具体用法?C++ PidStoreLoader::LoadFromStream怎么用?C++ PidStoreLoader::LoadFromStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PidStoreLoader的用法示例。


在下文中一共展示了PidStoreLoader::LoadFromStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testPidStoreLoad

/**
 * 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);
//.........这里部分代码省略.........
开发者ID:DanielAeolusLaude,项目名称:ola,代码行数:101,代码来源:PidStoreTest.cpp


注:本文中的PidStoreLoader::LoadFromStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。