test_plugins.cpp
来自「ncbi源码」· C++ 代码 · 共 444 行
CPP
444 行
/* * =========================================================================== * PRODUCTION $Log: test_plugins.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 20:45:07 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13 * PRODUCTION * =========================================================================== *//* $Id: test_plugins.cpp,v 1000.2 2004/06/01 20:45:07 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. * * =========================================================================== * * Authors: Mike DiCuccio * * File Description: * Test application for plugins */#include <ncbi_pch.hpp>#include <corelib/ncbiapp.hpp>#include <corelib/ncbiargs.hpp>#include <corelib/ncbienv.hpp>#include <corelib/ncbireg.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/idocument.hpp>#include <gui/core/plugin_exception.hpp>#include <gui/core/plugin_utils.hpp>#include <gui/plugin/PluginArgSet.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seq/Seq_annot.hpp>#include <objects/seqalign/Seq_align.hpp>#include <objects/seqloc/Seq_id.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objmgr/object_manager.hpp>#include <objmgr/scope.hpp>USING_NCBI_SCOPE;USING_SCOPE(objects);//// a test exception class//class CPluginTestException : EXCEPTION_VIRTUAL_BASE public CException{public: // Enumerated list of document management errors enum EErrCode { eTestFailed }; // Translate the specific error code into a string representations of // that error code. virtual const char* GetErrCodeString(void) const { switch (GetErrCode()) { case eTestFailed: return "eTestFailed"; default: return CException::GetErrCodeString(); } } NCBI_EXCEPTION_DEFAULT(CPluginTestException, CException);};class CPluginTestApp : public CNcbiApplication{public: CPluginTestApp();private: int m_Plugins; virtual void Init(void); virtual int Run(void); virtual void Exit(void); void TestPluginArgSet();};CPluginTestApp::CPluginTestApp() : m_Plugins(0){}void CPluginTestApp::Init(void){ // Create command-line argument descriptions class auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); // Specify USAGE context arg_desc->SetUsageContext(GetArguments().GetProgramBasename(), "Plug-in test application"); // Setup arg.descriptions for this application SetupArgDescriptions(arg_desc.release());}void CPluginTestApp::TestPluginArgSet(void){ {{ // build a list of arguments in a temporary CPluginArgSet CPluginArgSet args; cout << "testing built-in argument types..." << endl; args.AddArgument("int", "Integer", CPluginArg::eInteger); args.AddArgument("double", "Double", CPluginArg::eDouble); args.AddArgument("string", "String", CPluginArg::eString); // make sure these args are invalid if ( CPluginUtils::IsValid(args["int"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Invalid integer argument reports itself as valid"); } else { LOG_POST(Error << " empty integer value correctly reports invalid"); } if ( CPluginUtils::IsValid(args["double"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Invalid double argument reports itself as valid"); } else { LOG_POST(Error << " empty double value correctly reports invalid"); } if ( CPluginUtils::IsValid(args["string"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Invalid string argument reports itself as valid"); } else { LOG_POST(Error << " empty string value correctly reports invalid"); } args["int" ].SetInteger(0); args["double"].SetDouble(0.0); args["string"].SetString("foo"); // make sure these args are valid if ( !CPluginUtils::IsValid(args["int"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Valid integer argument reports itself as invalid"); } else { LOG_POST(Error << " valid integer value correctly reports valid"); } if ( !CPluginUtils::IsValid(args["double"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Valid double argument reports itself as invalid"); } else { LOG_POST(Error << " valid double value correctly reports valid"); } if ( !CPluginUtils::IsValid(args["string"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Valid string argument reports itself as invalid"); } else { LOG_POST(Error << " valid string value correctly reports valid"); } }} // // more complicated validity checks... // // set some values in these arguments CRef<CScope> scope(new CScope(CDocManager::GetObjectManager())); scope->AddDefaults(); CRef<CSeq_id> id(new CSeq_id("ref|NT_029998")); CRef<IDocument> doc(CDocManager::CreateDocument(*scope, *id)); {{ // build a list of arguments in a temporary CPluginArgSet CPluginArgSet args; cout << "testing data model argument types..." << endl; args.AddArgument("bioseq", "Bioseq", CBioseq::GetTypeInfo()); args.AddArgument("seq-align", "Seq-align", CSeq_align::GetTypeInfo()); args.AddArgument("seq-entry", "Seq-entry", CSeq_entry::GetTypeInfo()); args.AddArgument("seq-feat", "Seq-feat", CSeq_feat::GetTypeInfo()); args.AddArgument("seq-loc", "Seq-loc", CSeq_loc::GetTypeInfo()); // make sure these args are invalid if ( CPluginUtils::IsValid(args["bioseq"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Invalid bioseq argument reports itself as valid"); } else { LOG_POST(Error << " invalid bioseq value reports invalid"); } if ( CPluginUtils::IsValid(args["seq-feat"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Invalid seq-feat argument reports itself as valid"); } else { LOG_POST(Error << " invalid seq-feat value reports invalid"); } if ( CPluginUtils::IsValid(args["seq-loc"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Invalid seq-loc argument reports itself as valid"); } else { LOG_POST(Error << " invalid seq-loc value reports invalid"); } if ( CPluginUtils::IsValid(args["seq-entry"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Invalid seq-entry argument reports itself as valid"); } else { LOG_POST(Error << " invalid seq-entry value reports invalid"); } if ( CPluginUtils::IsValid(args["seq-align"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Invalid seq-align argument reports itself as valid"); } else { LOG_POST(Error << " invalid seq-align value reports invalid"); } CRef<CBioseq> bioseq(new CBioseq()); CRef<CSeq_align> align (new CSeq_align()); CRef<CSeq_entry> entry (new CSeq_entry()); CRef<CSeq_feat> feat (new CSeq_feat()); CRef<CSeq_loc> loc (new CSeq_loc()); args["bioseq" ].SetObject(*doc, *bioseq); args["seq-align"].SetObject(*doc, *align); args["seq-entry"].SetObject(*doc, *entry); args["seq-feat" ].SetObject(*doc, *feat); args["seq-loc" ].SetObject(*doc, *loc); // make sure these args are valid if ( !CPluginUtils::IsValid(args["bioseq"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Valid bioseq argument reports itself as invalid"); } else { LOG_POST(Error << " valid bioseq value reports valid"); } if ( !CPluginUtils::IsValid(args["seq-feat"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Valid seq-feat argument reports itself as invalid"); } else { LOG_POST(Error << " valid seq-feat value reports valid"); } if ( !CPluginUtils::IsValid(args["seq-loc"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Valid seq-loc argument reports itself as invalid"); } else { LOG_POST(Error << " valid seq-loc value reports valid"); } if ( !CPluginUtils::IsValid(args["seq-entry"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Valid seq-entry argument reports itself as invalid"); } else { LOG_POST(Error << " valid seq-entry value reports valid"); } if ( !CPluginUtils::IsValid(args["seq-align"]) ) { NCBI_THROW(CPluginTestException, eTestFailed, "Valid seq-align argument reports itself as invalid"); } else { LOG_POST(Error << " valid seq-align value reports valid"); } }} // // optional arguments // {{ CPluginArgSet args; cout << "testing optional argument types..." << endl; args.AddOptionalArgument("foo", "Foo", CPluginArg::eInteger); // test nonexistant argument and catch its exception try { if ( CPluginUtils::IsValid(args["nonexistant"])) { LOG_POST(Error << "found valid nonexistant argument"); } } catch (CPluginException& e) { LOG_POST(Error << "correctly caught CPluginException - message = " << e.what()); } // next, test existant but invalid argument try { if ( CPluginUtils::IsValid(args["foo"])) { LOG_POST(Error << "foo found, is valid"); } else { LOG_POST(Error << "foo found, isn't valid"); } const CPluginArg& arg = args["foo"]; if (arg.IsEmpty()) { LOG_POST(Error << "foo found, is empty"); } } catch (CPluginException& e) { LOG_POST(Error << "caught CPluginException: " << e.what()); throw; } }} cout << "test of CPluginArgSet SUCCEEDED." << endl;}int CPluginTestApp::Run(void){ // Get arguments CArgs args = GetArgs(); // test CPluginArgSet TestPluginArgSet(); return 0;}/////////////////////////////////////////////////////////////////////////////// Cleanupvoid CPluginTestApp::Exit(void){ SetDiagStream(0);}/////////////////////////////////////////////////////////////////////////////// MAINint main(int argc, const char* argv[]){ // Execute main application function return CPluginTestApp().AppMain(argc, argv, 0, eDS_Default, 0);}/* * =========================================================================== * $Log: test_plugins.cpp,v $ * Revision 1000.2 2004/06/01 20:45:07 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13 * * Revision 1.13 2004/05/21 22:27:41 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.12 2004/01/07 17:39:02 vasilche * Fixed include path to genbank loader. * * Revision 1.11 2003/09/29 15:42:05 dicuccio * Deprecated gui/scope.hpp. Merged gui/core/types.hpp into gui/types.hpp * * Revision 1.10 2003/09/04 18:27:33 dicuccio * Use IDocument instead of CDocument * * Revision 1.9 2003/09/04 14:01:52 dicuccio * Introduce IDocument and IView as abstract base classes for CDocument and CView * * Revision 1.8 2003/07/24 02:37:42 ucko * Moved logic for validating arguments into CPluginUtils. * * Revision 1.7 2003/06/25 17:02:55 dicuccio * Split CPluginHandle into a handle (pointer-to-implementation) and * implementation file. Lots of #include file clean-ups. * * Revision 1.6 2003/06/02 16:06:18 dicuccio * Rearranged src/objects/ subtree. This includes the following shifts: * - src/objects/asn2asn --> arc/app/asn2asn * - src/objects/testmedline --> src/objects/ncbimime/test * - src/objects/objmgr --> src/objmgr * - src/objects/util --> src/objmgr/util * - src/objects/alnmgr --> src/objtools/alnmgr * - src/objects/flat --> src/objtools/flat * - src/objects/validator --> src/objtools/validator * - src/objects/cddalignview --> src/objtools/cddalignview * In addition, libseq now includes six of the objects/seq... libs, and libmmdb * replaces the three libmmdb? libs. * * Revision 1.5 2003/05/19 13:36:00 dicuccio * Moved gui/core/plugin/ -> gui/plugin/. Merged gui/core/algo, gui/core/doc/, * and gui/core/view/ into one library (gui/core/) * * Revision 1.4 2003/05/09 16:50:28 dicuccio * Previous log message should have been: * Revised all tests - made reporting more explicit. Added tests for optional and * default arguments, explicitly test IsValid() and IsEmpty() * * Revision 1.3 2003/05/09 16:48:25 dicuccio * Added explicit verification that default set-constraint string arguments will * ave their menu values shown * * Revision 1.2 2003/04/25 14:15:24 dicuccio * Fix compilation errors resulting from changes to plugin API * * Revision 1.1 2003/03/20 19:57:28 dicuccio * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?