providermodule.cpp

来自「Pegasus is an open-source implementation」· C++ 代码 · 共 208 行

CPP
208
字号
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/ProviderManager2/Default/ProviderModule.h>#include <iostream>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;// Uses the pegasus/src/Providers/TestProviders/PG_TestPropertyTypes providerstatic const String GOOD_PROVIDER_LIBRARY_NAME = "PG_TestPropertyTypes";static const String GOOD_PROVIDER_NAME = "PG_TestPropertyTypes";static const String BAD_PROVIDER_NAME = "BogusProvider";// Made-up library namestatic const String NONEXISTENT_PROVIDER_LIBRARY_NAME = "BogusLibrary";// Uses the DynLib library from Common/testsstatic const String MISSING_ENTRY_POINT_PROVIDER_LIBRARY_NAME = "TestDynLib";const char* verbose = 0;String getLibraryFileName(const String& libraryName) { #if defined(PEGASUS_OS_VMS)    String prefixDir;# if defined(PEGASUS_USE_RELEASE_DIRS)    prefixDir = String("/wbem_opt/wbem/providers/lib/");# else    const char* tmp = getenv("PEGASUS_HOME");    if (tmp)    {        prefixDir = tmp + String("/bin/");    }# endif    return prefixDir +           FileSystem::buildLibraryFileName(libraryName) + ".exe"; # else    return FileSystem::buildLibraryFileName(libraryName);#endif}void testGoodProvider(){    ProviderModule module(getLibraryFileName(GOOD_PROVIDER_LIBRARY_NAME));    PEGASUS_TEST_ASSERT(module.getFileName() ==        getLibraryFileName(GOOD_PROVIDER_LIBRARY_NAME));    CIMProvider* provider = module.load(GOOD_PROVIDER_NAME);    PEGASUS_ASSERT(provider != 0);    module.unloadModule();    provider = module.load(GOOD_PROVIDER_NAME);    PEGASUS_ASSERT(provider != 0);    // Load incorrect provider name while another provider is loaded    {        Boolean caughtException = false;        try        {            module.load(BAD_PROVIDER_NAME);        }        catch (Exception& e)        {            caughtException = true;            if (verbose)            {                cout << "Got expected exception: " << e.getMessage() << endl;            }        }        PEGASUS_TEST_ASSERT(caughtException);    }    // Load the same provider a second time    provider = module.load(GOOD_PROVIDER_NAME);    PEGASUS_ASSERT(provider != 0);    module.unloadModule();    module.unloadModule();    // Load incorrect provider name while no other provider is loaded    {        Boolean caughtException = false;        try        {            module.load(BAD_PROVIDER_NAME);        }        catch (Exception& e)        {            caughtException = true;            if (verbose)            {                cout << "Got expected exception: " << e.getMessage() << endl;            }        }        PEGASUS_TEST_ASSERT(caughtException);    }}void testNonexistentProvider(){    ProviderModule module(        getLibraryFileName(NONEXISTENT_PROVIDER_LIBRARY_NAME));    Boolean caughtException = false;    try    {        module.load(BAD_PROVIDER_NAME);    }    catch (Exception& e)    {        caughtException = true;        if (verbose)        {            cout << "Got expected exception: " << e.getMessage() << endl;        }    }    PEGASUS_TEST_ASSERT(caughtException);}void testMissingProviderEntryPoint(){    ProviderModule module(        getLibraryFileName(MISSING_ENTRY_POINT_PROVIDER_LIBRARY_NAME));    Boolean caughtException = false;    try    {        module.load(BAD_PROVIDER_NAME);    }    catch (Exception& e)    {        caughtException = true;        if (verbose)        {            cout << "Got expected exception: " << e.getMessage() << endl;        }    }    PEGASUS_TEST_ASSERT(caughtException);}int main(int argc, char** argv){    verbose = getenv ("PEGASUS_TEST_VERBOSE");    try    {        testGoodProvider();        testNonexistentProvider();        testMissingProviderEntryPoint();    }    catch(Exception& e)    {        cout << "Caught unexpected exception: " << e.getMessage() << endl;        return 1;    }    catch(...)    {        cout << "Caught unexpected exception" << endl;        return 1;    }    cout << argv[0] << " +++++ passed all tests" << endl;    return 0;}

⌨️ 快捷键说明

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