Exemplo n.º 1
0
TEST(OptionsTest, test_option_writing)
{
    const Option option_i("my_int", (uint16_t)17);
    EXPECT_TRUE(option_i.getName() == "my_int");
    EXPECT_TRUE(option_i.getValue() == "17");

    const Option option_s("my_string", "Yow.");
    EXPECT_TRUE(option_s.getName() == "my_string");
    EXPECT_TRUE(option_s.getValue() == "Yow.");
    EXPECT_TRUE(option_s.getValue() == "Yow.");
}
Exemplo n.º 2
0
TEST(OptionsTest, test_option_writing)
{
    std::ostringstream ostr_i;
    const std::string ref_i = xml_header + xml_int_ref;
    std::ostringstream ostr_s;
    const std::string ref_s = xml_header + xml_str_ref;

    const Option option_i("my_int", (uint16_t)17);
    EXPECT_TRUE(option_i.getName() == "my_int");
    EXPECT_TRUE(option_i.getValue() == "17");

    const Option option_s("my_string", "Yow.");
    EXPECT_TRUE(option_s.getName() == "my_string");
    EXPECT_TRUE(option_s.getValue() == "Yow.");
    EXPECT_TRUE(option_s.getValue() == "Yow.");
}
Exemplo n.º 3
0
Stage *PipelineReaderXML::parseElement_Writer(const ptree& tree)
{
    Options options;
    StageParserContext context;
    std::string filename;

    map_t attrs;
    collect_attributes(attrs, tree);

    std::vector<Stage *> prevStages;
    for (auto iter = tree.begin(); iter != tree.end(); ++iter)
    {
        const std::string& name = iter->first;
        const ptree& subtree = iter->second;

        if (name == "<xmlattr>")
        {
            // already parsed -- ignore it
        }
        else if (name == "Option")
        {
            Option option = parseElement_Option(subtree);
            if (option.getName() == "filename")
                filename = option.getValue();
            options.add(option);
        }
        else if (name == "Metadata")
        {
            // ignored
        }
        else if (name == "Filter" || name == "Reader")
        {
            context.addStage();
            prevStages.push_back(parseElement_anystage(name, subtree));
        }
        else
        {
            context.addUnknown(name);
        }
    }

    std::string type;
    if (attrs.count("type"))
    {
        type = attrs["type"];
        context.addType();
    }

    context.validate();
    Stage& writer = m_manager.makeWriter(filename, type);
    for (auto sp : prevStages)
        writer.setInput(*sp);
    writer.removeOptions(options);
    writer.addOptions(options);
    return &writer;
}
Exemplo n.º 4
0
Stage *PipelineReaderXML::parseElement_Reader(const ptree& tree)
{
    Options options;
    StageParserContext context;
    std::string filename;
    context.setCardinality(StageParserContext::None);

    map_t attrs;
    collect_attributes(attrs, tree);

    auto iter = tree.begin();
    while (iter != tree.end())
    {
        const std::string& name = iter->first;
        const ptree& subtree = iter->second;

        if (name == "<xmlattr>")
        {
            // already parsed
        }
        else if (name == "Option")
        {
            Option option = parseElement_Option(subtree);
            if (option.getName() == "filename")
                filename = option.getValue();
            options.add(option);
        }
        else if (name == "Metadata")
        {
            // ignored for now
        }
        else
        {
            context.addUnknown(name);
        }
        ++iter;
    }

    std::string type;
    if (attrs.count("type"))
    {
        type = attrs["type"];
    }

    Stage& reader = m_manager.makeReader(filename, type);
    reader.removeOptions(options);
    reader.addOptions(options);

    context.addType();
    context.validate();
    return &reader;
}
Exemplo n.º 5
0
TEST(OptionsTest, json)
{
    // Test that a JSON option will be stringified into the option's underlying
    // value.
    Json::Value inJson;
    inJson["key"] = 42;
    const Option option_j("my_json", inJson);
    EXPECT_TRUE(option_j.getName() == "my_json");

    // Don't string-compare, test JSON-equality, since we don't care exactly
    // how it's stringified.
    Json::Value outJson;
    Json::Reader().parse(option_j.getValue(), outJson);

    EXPECT_EQ(inJson, outJson) << inJson << " != " << outJson;
}