⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coretest.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* * =========================================================================== * PRODUCTION $Log: coretest.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 19:09:37  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.90 * PRODUCTION * =========================================================================== *//*  $Id: coretest.cpp,v 1000.1 2004/06/01 19:09:37 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Author:  Denis Vakatov * * File Description: *   TEST for:  NCBI C++ core API * */#include <ncbi_pch.hpp>#include <corelib/ncbiapp.hpp>#include <corelib/ncbienv.hpp>#include <corelib/ncbireg.hpp>#include <algorithm>#include <test/test_assert.h>  /* This header must go last */// This is to use the ANSI C++ standard templates without the "std::" prefix// and to use NCBI C++ entities without the "ncbi::" prefixUSING_NCBI_SCOPE;/////////////////////////////////// I/O stream extensions//static void TestIostream(void){    CNcbiIstrstream is("abc\nx0123456789\ny012345\r \tcba");    string str;    NcbiGetline(is, str, '\n');    assert( is.good() );    assert( str.compare("abc") == 0 );    is >> str;    assert( is.good() );    assert( str.compare("x0123456789") == 0 );    is >> str;    assert( is.good() );    assert( str.compare("y012345") == 0 );    is >> str;    assert( is.eof() );    assert( str.compare("cba") == 0 );    is >> str;    assert( !is.good() );    is.clear();    is >> str;    assert( !is.good() );    str = "0 1 2 3 4 5\n6 7 8 9";    NcbiCout << "String output: "  << str << NcbiEndl;}/////////////////////////////////// Registry//static void TestRegistry(void){    CNcbiRegistry reg;    assert( reg.Empty() );    list<string> sections;    reg.EnumerateSections(&sections);    assert( sections.empty() );    list<string> entries;    reg.EnumerateEntries(NcbiEmptyString, &entries);    assert( entries.empty() );    // Compose a test registry    assert(  reg.Set("Section0", "Name01", "Val01_BAD!!!") );    assert(  reg.Set("Section1 ", "\nName11", "Val11_t") );    assert( !reg.Empty() );    assert(  reg.Get(" Section1", "Name11\t") == "Val11_t" );    assert(  reg.Get("Section1", "Name11",                      CNcbiRegistry::ePersistent).empty() );    assert(  reg.Set("Section1", "Name11", "Val11_t") );    assert( !reg.Set("Section1", "Name11", "Val11_BAD!!!",                      CNcbiRegistry::eNoOverride) );    assert(  reg.Set("   Section2", "\nName21  ", "Val21",                      CNcbiRegistry::ePersistent |                      CNcbiRegistry::eNoOverride) );    assert(  reg.Set("Section2", "Name21", "Val21_t") );    assert( !reg.Empty() );    assert(  reg.Set("Section3", "Name31", "Val31_t") );    assert( reg.Get(" \nSection1", " Name11  ") == "Val11_t" );    assert( reg.Get("Section2", "Name21", CNcbiRegistry::ePersistent) ==             "Val21" );    assert( reg.Get(" Section2", " Name21\n") == "Val21_t" );    assert( reg.Get("SectionX", "Name21").empty() );    assert( reg.Set("Section4", "Name41", "Val410 Val411 Val413",                     CNcbiRegistry::ePersistent) );    assert(!reg.Set("Sect ion4", "Name41", "BAD1",                     CNcbiRegistry::ePersistent) );    assert(!reg.Set("Section4", "Na me41", "BAD2") );    assert( reg.Set("SECTION4", "Name42", "V420 V421\nV422 V423 \"",                     CNcbiRegistry::ePersistent) );    assert( reg.Set("Section4", "NAME43",                     " \tV430 V431  \n V432 V433 ",                     CNcbiRegistry::ePersistent) );    assert( reg.Set("\tSection4", "Name43T",                     " \tV430 V431  \n V432 V433 ",                     CNcbiRegistry::ePersistent | CNcbiRegistry::eTruncate) );    assert( reg.Set("Section4", "Name44", "\n V440 V441 \r\n",                     CNcbiRegistry::ePersistent) );    assert( reg.Set("\r Section4", "  \t\rName45", "\r\n V450 V451  \n  ",                     CNcbiRegistry::ePersistent) );    assert( reg.Set("Section4 \n", "  Name46  ", "\n\nV460\" \n \t \n\t",                     CNcbiRegistry::ePersistent) );    assert( reg.Set(" Section4", "Name46T", "\n\nV460\" \n \t \n\t",                     CNcbiRegistry::ePersistent | CNcbiRegistry::eTruncate) );    assert( reg.Set("Section4", "Name47", "470\n471\\\n 472\\\n473\\",                     CNcbiRegistry::ePersistent) );    assert( reg.Set("Section4", "Name47T", "470\n471\\\n 472\\\n473\\",                     CNcbiRegistry::ePersistent | CNcbiRegistry::eTruncate) );    string xxx("\" V481\" \n\"V482 ");    assert( reg.Set("Section4", "Name48", xxx, CNcbiRegistry::ePersistent) );    assert( reg.Set("Section5", "Name51", "Section5/Name51",                     CNcbiRegistry::ePersistent) );    assert( reg.Set("_Section_5", "Name51", "_Section_5/Name51",                     CNcbiRegistry::ePersistent) );    assert( reg.Set("_Section_5_", "_Name52", "_Section_5_/_Name52",                     CNcbiRegistry::ePersistent) );    assert( reg.Set("_Section_5_", "Name52", "_Section_5_/Name52",                     CNcbiRegistry::ePersistent) );    assert( reg.Set("_Section_5_", "_Name53_", "_Section_5_/_Name53_",                     CNcbiRegistry::ePersistent) );    assert( reg.Set("Section-5.6", "Name-5.6", "Section-5.6/Name-5.6",                     CNcbiRegistry::ePersistent) );    assert( reg.Set("-Section_5", ".Name.5-3", "-Section_5/.Name.5-3",                     CNcbiRegistry::ePersistent) );    // Dump    CNcbiOstrstream os;    assert ( reg.Write(os) );    os << '\0';    const char* os_str = os.str();  os.rdbuf()->freeze(false);    NcbiCerr << "\nRegistry:\n" << os_str << NcbiEndl;    // "Persistent" load    CNcbiIstrstream is1(os_str);    CNcbiRegistry  reg1(is1);    assert(  reg1.Get("Section2", "Name21", CNcbiRegistry::ePersistent) ==              "Val21" );    assert(  reg1.Get("Section2", "Name21") == "Val21" );    assert( !reg1.Set("Section2", "Name21", NcbiEmptyString) );    assert( !reg1.Set("Section2", "Name21", NcbiEmptyString,                       CNcbiRegistry::ePersistent |                       CNcbiRegistry::eNoOverride) );    assert( !reg1.Empty() );    assert(  reg1.Set("Section2", "Name21", NcbiEmptyString,                       CNcbiRegistry::ePersistent) );    // "Transient" load    CNcbiIstrstream is2(os_str);    CNcbiRegistry  reg2(is2, CNcbiRegistry::eTransient);    assert(  reg2.Get("Section2", "Name21",                       CNcbiRegistry::ePersistent).empty() );    assert(  reg2.Get("Section2", "Name21") == "Val21" );    assert( !reg2.Set("Section2", "Name21", NcbiEmptyString,                       CNcbiRegistry::ePersistent) );    assert( !reg2.Set("Section2", "Name21", NcbiEmptyString,                       CNcbiRegistry::ePersistent |                       CNcbiRegistry::eNoOverride) );    assert( !reg2.Empty() );    assert(  reg2.Set("Section2", "Name21", NcbiEmptyString) );    assert( reg.Get("Sect ion4 ", "Name41 ").empty() );    assert( reg.Get("Section4 ", "Na me41 ").empty() );    assert( reg.Get("Section4 ", "Name41 ") == "Val410 Val411 Val413" );    assert( reg.Get("Section4",  " Name42") == "V420 V421\nV422 V423 \"" );    assert( reg.Get("Section4",  "Name43")  == " \tV430 V431  \n V432 V433 ");    assert( reg.Get("Section4",  "Name43T") == "V430 V431  \n V432 V433" );    assert( reg.Get("Section4",  " Name44") == "\n V440 V441 \r\n" );    assert( reg.Get(" SecTIon4", "Name45")  == "\r\n V450 V451  \n  " );    assert( reg.Get("SecTion4 ", "Name46")  == "\n\nV460\" \n \t \n\t" );    assert( reg.Get("Section4",  "NaMe46T") == "\n\nV460\" \n \t \n" );    assert( reg.Get(" Section4", "Name47")  == "470\n471\\\n 472\\\n473\\" );    assert( reg.Get("Section4 ", "NAme47T") == "470\n471\\\n 472\\\n473\\" );    assert( reg.Get("Section4",  "Name48")  == xxx );    assert( reg2.Get("Section4", "Name41")  == "Val410 Val411 Val413" );    assert( reg2.Get("Section4", "Name42")  == "V420 V421\nV422 V423 \"" );    assert( reg2.Get("Section4", "Name43")  == " \tV430 V431  \n V432 V433 ");    assert( reg2.Get("Section4", "Name43T") == "V430 V431  \n V432 V433" );    assert( reg2.Get("Section4", "Name44")  == "\n V440 V441 \r\n" );    assert( reg2.Get("Section4", "NaMe45")  == "\r\n V450 V451  \n  " );    assert( reg2.Get("SecTIOn4", "NAme46")  == "\n\nV460\" \n \t \n\t" );    assert( reg2.Get("Section4", "Name46T") == "\n\nV460\" \n \t \n" );    assert( reg2.Get("Section4", "Name47")  == "470\n471\\\n 472\\\n473\\" );    assert( reg2.Get("Section4", "Name47T") == "470\n471\\\n 472\\\n473\\" );    assert( reg2.Get("Section4", "Name48")  == xxx );    assert( reg2.Get(" Section5",    "Name51 ")   == "Section5/Name51" );    assert( reg2.Get("_Section_5",   " Name51")   == "_Section_5/Name51" );    assert( reg2.Get(" _Section_5_", " _Name52")  == "_Section_5_/_Name52");    assert( reg2.Get("_Section_5_ ", "Name52")    == "_Section_5_/Name52");    assert( reg2.Get("_Section_5_",  "_Name53_ ") == "_Section_5_/_Name53_" );    assert( reg2.Get(" Section-5.6", "Name-5.6 ") == "Section-5.6/Name-5.6");    assert( reg2.Get("-Section_5",   ".Name.5-3") == "-Section_5/.Name.5-3");    // Printout of the whole registry content    assert( reg.Set("Section0", "Name01", "") );    reg.EnumerateSections(&sections);    assert( find(sections.begin(), sections.end(), "Section0")             == sections.end() );    assert( find(sections.begin(), sections.end(), "Section1")             != sections.end() );    assert( !sections.empty() );    NcbiCout << "\nRegistry Content:\n";    for (list<string>::const_iterator itSection = sections.begin();         itSection != sections.end();   itSection++) {        NcbiCout << "Section: " << *itSection << NcbiEndl;        reg.EnumerateEntries(*itSection, &entries);        for (list<string>::const_iterator itEntry = entries.begin();             itEntry != entries.end();   itEntry++) {            NcbiCout << "  Entry: " << *itEntry << NcbiEndl;            NcbiCout << "    Default:    "                     << reg.Get(*itSection, *itEntry) << NcbiEndl;            NcbiCout << "    Persistent: "                     << reg.Get(*itSection, *itEntry,                                CNcbiRegistry::ePersistent) << NcbiEndl;        }    }    reg.Clear();    assert( reg.Empty() );        // Test read/write registry    NcbiCout << endl;    NcbiCout << "---------------------------------------------------" << endl;    CNcbiIstrstream is("\n\############################################\n\#\n\#  Registry file comment\n\#\n\############################################\n\\n\; comment for section1\n\\n\[section1]\n\; This is a comment for n11\n\#\n\#  File comment also\n\#\n\n11 = value11\n\\n\; This is a comment for n12 line 1\n\; This is a comment for n12 line 2\n\\n\n12 = value12\n\\n\; This is a comment for n13\n\n13 = value13\n\; new comment for n13\n\n13 = new_value13\n\\n\[ section2 ]\n\; This is a comment for n21\n\n21 = value21\n\   ; This is a comment for n22\n\n22 = value22\n\[section3]\n\n31 = value31\n\");    reg.Read(is);    reg.Write(NcbiCout);    NcbiCout << "---------------------------------------------------" << endl;    NcbiCout << "File comment:" << endl;    NcbiCout << reg.GetComment() << endl;    NcbiCout << "Section comment:" << endl;    NcbiCout << reg.GetComment("section1") << endl;    NcbiCout << "Entry comment:" << endl;    NcbiCout << reg.GetComment("section1","n12") << endl;    reg.SetComment(" new comment\n# for registry\n\n  # ...\n\n\n");    reg.SetComment(";new comment for section1\n","section1");    reg.SetComment("new comment for section3","section3");    reg.SetComment("new comment for entry n11","section1","n11");    reg.SetComment("  ; new comment for entry n31","section3","n31");    reg.SetComment("","section2","n21");    NcbiCout << "---------------------------------------------------" << endl;    reg.Write(NcbiCout);    NcbiCout << "---------------------------------------------------" << endl;}/////////////////////////////////// Start-up (cmd.-line args, config file)//static void TestStartup(void){    // Command-line arguments    SIZE_TYPE n_args = CNcbiApplication::Instance()->GetArguments().Size();    NcbiCout << NcbiEndl << "Total # of CMD.-LINE ARGS: "             << n_args << NcbiEndl;    for (SIZE_TYPE i = 0;  i < n_args;  i++) {        NcbiCout << " [" << i << "] = \""                 << CNcbiApplication::Instance()->GetArguments()[i]                 << "\"" << NcbiEndl;    }    NcbiCout << NcbiEndl;    // Config.file (registry) content    const CNcbiRegistry& reg = CNcbiApplication::Instance()->GetConfig();    NcbiCout << "REGISTRY (loaded from config file):" <<  NcbiEndl;    if ( reg.Empty() ) {        NcbiCout << "  <empty>"  << NcbiEndl;    } else {        reg.Write(NcbiCout);    }    NcbiCout << NcbiEndl;}/////////////////////////////////// Diagnostics//class CNcbiTestDiag {public:    int i;    CNcbiTestDiag(void) { i = 4321; }};inline CNcbiOstream& operator <<(CNcbiOstream& os, const CNcbiTestDiag& cntd) {    return os << "Output of an serializable class content = " << cntd.i;}static void s_TestDiagHandler(const SDiagMessage& mess){     NcbiCout << "<Installed Handler> " << mess << NcbiEndl;}static void TestDiag(void){    CNcbiDiag diag;    double d = 123.45;    SetDiagPostFlag(eDPF_All);    diag << "[Unset Diag Stream]  Diagnostics double = " << d << Endm;    ERR_POST( "[Unset Diag Stream]  ERR_POST double = " << d );    _TRACE( "[Unset Diag Stream]  Trace double = " << d );    NcbiCout << NcbiEndl             << "FLUSHing memory-stored diagnostics (if any):" << NcbiEndl;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -