Пример #1
0
 void test1()
 {
    try
    {
       QJsonDocument input = jsonPath( strToJsonDoc( "{\"name\":\"bob\",\"value\":\"valuetext\"}" ), "$.name" );
       QJsonDocument expected = strToJsonDoc( "[ \"bob\" ]" );
       TEST_ASSERT_MSG( input == expected, "output is different than expected" );
    }
    catch ( std::runtime_error& r )
    {
       std::cout << r.what() << "\n";
       TEST_FAIL( "Test throws exception" );
    }
    catch ( ... )
    {
       TEST_FAIL( "Test throws unknown exception" );
    }
 }
Пример #2
0
 void test2()
 {
    try
    {
       QJsonDocument input = jsonPath( strToJsonDoc( "{\"Avatars\":[{\"name\":\"zero\"},{\"name\":\"one\"},{\"name\":\"two\"},{\"name\":\"three\"}]}" ), "$.Avatars[*].name" );
       QJsonDocument expected = strToJsonDoc( "[ \"zero\", \"one\", \"two\", \"three\" ]" );
       TEST_ASSERT_MSG( input == expected, "output is different than expected" );
    }
    catch ( std::runtime_error& r )
    {
       std::cout << r.what() << "\n";
       TEST_FAIL( "Test throws exception" );
    }
    catch ( ... )
    {
       TEST_FAIL( "Test throws unknown exception" );
    }
 }
Пример #3
0
/***********************************************************************
 * Load a JSON block description described by a config file section
 **********************************************************************/
static std::vector<Pothos::PluginPath> blockDescLoader(const std::map<std::string, std::string> &config)
{
    //config file path set by caller
    const auto confFilePathIt = config.find("confFilePath");
    if (confFilePathIt == config.end() or confFilePathIt->second.empty())
        throw Pothos::Exception("missing confFilePath");

    //determine JSON description file path
    const auto jsonIt = config.find("json");
    if (jsonIt == config.end() or jsonIt->second.empty())
        throw Pothos::Exception("JSON file not specified");
    Poco::Path jsonPath(jsonIt->second);
    jsonPath.makeAbsolute(Poco::Path(confFilePathIt->second).makeParent());
    if (not Poco::File(jsonPath).exists())
        throw Pothos::Exception(jsonPath.toString() + " does not exist");

    //open an input file stream
    std::ifstream ifs(Poco::Path::expand(jsonPath.toString()));

    std::vector<Pothos::PluginPath> blockPaths;
    return blockDescParser(ifs, blockPaths);
}