TEST_F(TableMergerTest, MergeFileOverlay) {
    ResourceTable finalTable;
    TableMergerOptions tableMergerOptions;
    tableMergerOptions.autoAddOverlay = false;
    TableMerger merger(mContext.get(), &finalTable, tableMergerOptions);

    ResourceFile fileDesc;
    fileDesc.name = test::parseNameOrDie(u"@xml/foo");
    test::TestFile fileA("path/to/fileA.xml.flat");
    test::TestFile fileB("path/to/fileB.xml.flat");

    ASSERT_TRUE(merger.mergeFile(fileDesc, &fileA));
    ASSERT_TRUE(merger.mergeFileOverlay(fileDesc, &fileB));
}
示例#2
0
int main(int argc, char *argv[])
{
    QString title;
    title = title + "********************************************************************* \n";
    title = title + " * Compare Insert XML 1.0                                            * \n";
    title = title + " * This tool compares two insert XML files (A and B) for incremental * \n";
    title = title + " * changes.                                                          * \n";
    title = title + " *                                                                   * \n";
    title = title + " * The tool informs of lookup values in A that are not in B.         * \n";
    title = title + " * The tool can also create a combined file C that appends           * \n";
    title = title + " * not found values.                                                 * \n";
    title = title + " *                                                                   * \n";
    title = title + " * Nomenclature:                                                     * \n";
    title = title + " *   TNF: Lookup table not found.                                    * \n";
    title = title + " *   VNF: Value not found.                                           * \n";
    title = title + " *   VNS: The values is not the same.                                * \n";
    title = title + " *                                                                   * \n";
    title = title + " * This tool is usefull when dealing with multiple versions of an    * \n";
    title = title + " * ODK survey that must be combined in one common database.          * \n";
    title = title + " *                                                                   * \n";
    title = title + " * This tool is part of ODK Tools (c) ILRI-RMG, 2015                 * \n";
    title = title + " * Author: Carlos Quiros ([email protected] / [email protected]) * \n";
    title = title + " ********************************************************************* \n";

    TCLAP::CmdLine cmd(title.toUtf8().constData(), ' ', "1.0");

    TCLAP::ValueArg<std::string> aArg("a","inputa","Input insert XML file A",true,"","string");
    TCLAP::ValueArg<std::string> bArg("b","inputb","Input insert XML file B",true,"","string");
    TCLAP::ValueArg<std::string> cArg("c","outputc","Output insert XML file C",false,"./combined-insert.xml","string");

    cmd.add(aArg);
    cmd.add(bArg);
    cmd.add(cArg);


    //Parsing the command lines
    cmd.parse( argc, argv );

    //Getting the variables from the command
    QString inputA = QString::fromUtf8(aArg.getValue().c_str());
    QString inputB = QString::fromUtf8(bArg.getValue().c_str());
    QString outputC = QString::fromUtf8(cArg.getValue().c_str());

    if (inputA != inputB)
    {
        if ((QFile::exists(inputA)) && (QFile::exists(inputB)))
        {
            //Openning and parsing input file A
            QDomDocument docA("inputA");
            QFile fileA(inputA);
            if (!fileA.open(QIODevice::ReadOnly))
            {
                log("Cannot open input file A");
                return 1;
            }
            if (!docA.setContent(&fileA))
            {
                log("Cannot parse document for input file A");
                fileA.close();
                return 1;
            }
            fileA.close();

            //Openning and parsing input file B
            QDomDocument docB("inputB");
            QFile fileB(inputB);
            if (!fileB.open(QIODevice::ReadOnly))
            {
                log("Cannot open input file B");
                return 1;
            }
            if (!docB.setContent(&fileB))
            {
                log("Cannot parse document for input file B");
                fileB.close();
                return 1;
            }
            fileB.close();

            QDomElement rootA = docA.documentElement();
            QDomElement rootB = docB.documentElement();
            if ((rootA.tagName() == "insertValuesXML") && (rootB.tagName() == "insertValuesXML"))
            {
                //Comparing lookup tables
                if ((!rootA.firstChild().isNull()) && (!rootB.firstChild().isNull()))
                    qDebug() << "Comparing lookup tables";
                compareLKPTables(rootA.firstChild(),docB);

                //Create the manifext file. If exist it get overwriten
                if (QFile::exists(outputC))
                    QFile::remove(outputC);
                QFile file(outputC);
                if (file.open(QIODevice::WriteOnly | QIODevice::Text))
                {
                    QTextStream out(&file);
                    out.setCodec("UTF-8");
                    docB.save(out,1,QDomNode::EncodingFromTextStream);
                    file.close();
                }
                else
                    log("Error: Cannot create XML combined file");

            }
            else
            {
                if (!(rootA.tagName() == "ODKImportXML"))
                {
                    log("Input document A is not a insert XML file");
                    return 1;
                }
                if (!(rootB.tagName() == "ODKImportXML"))
                {
                    log("Input document B is not a insert XML file");
                    return 1;
                }
            }

        }
        else
        {
            if (!QFile::exists(inputA))
            {
                log("Input file A does not exists");
                return 1;
            }
            if (!QFile::exists(inputB))
            {
                log("Input file B does not exists");
                return 1;
            }
        }
    }
    else
    {
        log("Input files A and B are the same. No point in comparing them.");
        return 1;
    }

    return 0;
}