(file) Return to test_provreg.cpp CVS log (file) (dir) Up to [OMI] / omi / provreg / tests

File: [OMI] / omi / provreg / tests / Attic / test_provreg.cpp (download)
Revision: 1.1.1.1 (vendor branch), Wed May 30 21:47:49 2012 UTC (12 years, 1 month ago) by mike
Branch: TOG
CVS Tags: OMI_1_0_2_Branch, OMI_1_0_2, OMI_1_0_1_PRE, OMI_1_0_1, OMI_1_0_0
Changes since 1.1: +0 -0 lines
Initial Import

/*
**==============================================================================
**
** Open Management Infrastructure (OMI)
**
** Copyright (c) Microsoft Corporation
** 
** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
** use this file except in compliance with the License. You may obtain a copy 
** of the License at 
**
**     http://www.apache.org/licenses/LICENSE-2.0 
**
** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
** MERCHANTABLITY OR NON-INFRINGEMENT. 
**
** See the Apache 2 License for the specific language governing permissions 
** and limitations under the License.
**
**==============================================================================
*/

#include <ut/ut.h>
#include <provreg/provreg.h>
#include <provreg/regfile.h>
#include <base/strings.h>
#include <base/dir.h>
#include <unittest/utils.h>
#include <base/paths.h>
#include <algorithm>
#include <base/io.h>

//#define ENABLE_PRINT

static char TEMP_FILE[MAX_PATH_SIZE];

using namespace std;

static FILE* outStream = NULL;

static void setUp()
{
    Strlcpy(TEMP_FILE, GetPath(ID_TMPDIR), sizeof(TEMP_FILE));
    Strlcat(TEMP_FILE, "/test_temp.tmp", sizeof(TEMP_FILE));

#if defined(CONFIG_POSIX)
    // Change directory to PREFIX/unittest.
    char path[MAX_PATH_SIZE];
    Strlcpy(path, CONFIG_PREFIX, sizeof(path));
    Strlcat(path, "/unittest", sizeof(path));
    Chdir(path);
#endif

#if defined(ENABLE_PRINT)
    outStream = stdout;
#else
    outStream = Fopen(NULL_FILE, "w");
#endif
}

static void cleanup()
{
#if defined(ENABLE_PRINT)
    outStream = NULL;
#else
    fclose(outStream);
    outStream = NULL;
#endif
    ut::removeIfExist( TEMP_FILE );
}

#if 0
static void TestProvReg()
{
    /* Relative to 'unittest' directory */
    std::string path = ut::findSampleFile(0,"","../provreg/tests/omiregister.conf");
    ProvReg reg;
    MI_Result r;
    ProvRegEntry* p;
    size_t index = 0;

    /* Load the registrations */
    r = ProvReg_Init(&reg, path.c_str());

    if (r != MI_RESULT_OK)
    {
        fprintf(stdout, "failed to open: %s\n", path.c_str());
        UT_ASSERT_FAILED_MSG("failed to open register.conf");
    }

    /* Check the registrations */
    for (p = reg.head; p; p = p->next, index++)
    {
        switch (index)
        {
            case 0:
            {
                UT_ASSERT(p->provInterface == PROV_INTERFACE_STATIK);
                UT_ASSERT(Zcmp(p->nameSpace, T("root/test")) == 0);
                UT_ASSERT(Zcmp(p->className, T("Dog")) == 0);
                UT_ASSERT(strcmp(p->libraryName, "MyProvider") == 0);
                break;
            }
            case 1:
            {
                UT_ASSERT(p->provInterface == PROV_INTERFACE_STATIK);
                UT_ASSERT(Zcmp(p->nameSpace, T("root/test")) == 0);
                UT_ASSERT(Zcmp(p->className, T("Cat")) == 0);
                UT_ASSERT(strcmp(p->libraryName, "MyProvider") == 0);
                break;
            }
            case 2:
            {
                UT_ASSERT(p->provInterface == PROV_INTERFACE_STATIK);
                UT_ASSERT(Zcmp(p->nameSpace, T("root/test")) == 0);
                UT_ASSERT(Zcmp(p->className, T("Bird")) == 0);
                UT_ASSERT(strcmp(p->libraryName, "MyProvider") == 0);
                break;
            }
            default:
                UT_ASSERT_FAILED_MSG("unexpected branch");
        }
    }

    ProvReg_Dump(&reg, outStream);

    // Find a provider for the given class.
    {
        const ProvRegEntry* entry;
        
        entry = ProvReg_FindProviderForClass(&reg, T("root/test"), 
            T("Bird"));
        UT_ASSERT(entry != NULL);

        entry = ProvReg_FindProviderForClass(&reg, T("blah"), T("blah"));
        UT_ASSERT(entry == NULL);
    }

    // check derived classes
    vector<ut::String>  res;
    ProvRegPosition pos;
    MI_ConstString derived = 0;

    r = ProvReg_BeginClasses( &reg, T("root/test"), T("Animal"), MI_TRUE, &pos );

    UT_ASSERT (MI_RESULT_OK == r);

    for (;;)
    {
        MI_Boolean done;
        r = ProvReg_NextClass( &pos, &derived, &done);

        if (done)
            break;

        UT_ASSERT (MI_RESULT_OK == r);
        res.push_back( derived );
    }

    r = ProvReg_EndClasses(&pos);
    UT_ASSERT(MI_RESULT_OK == r);


    std::sort< vector< ut::String >::iterator >(res.begin(), res.end());

    vector<ut::String>  expected_res;
    expected_res.push_back(T("Bird"));
    expected_res.push_back(T("Cat"));
    expected_res.push_back(T("Dog"));

    UT_ASSERT(expected_res == res);

    ProvReg_Destroy(&reg);
}
#endif

#if 0
static void TestProvRegInvalidConfigFile()
{
    ProvReg reg;
    MI_Result r;

    /* Load the registrations */
    r = ProvReg_Init(&reg, "non-exisiting-file");

    UT_ASSERT (MI_RESULT_OPEN_FAILED == r);
}
#endif

#if 0
static void VerifyInheritanceChain(ProvReg* reg, MI_ConstString ns, MI_ConstString base, MI_Boolean deep, MI_ConstString expected)
{
    // check derived classes
    vector<ut::String>  res;
    ProvRegPosition pos;
    MI_ConstString derived = 0;

    MI_Result r = ProvReg_BeginClasses( reg, ns, base, deep, &pos );

    UT_ASSERT (MI_RESULT_OK == r);

    for (;;)
    {
        MI_Boolean done;
        r = ProvReg_NextClass( &pos, &derived, &done);

        if (done)
            break;

        UT_ASSERT (MI_RESULT_OK == r);
        res.push_back( derived );
    }

    r = ProvReg_EndClasses(&pos);
    UT_ASSERT(MI_RESULT_OK == r);

    std::sort< vector< ut::String >::iterator >(res.begin(), res.end());

    vector<ut::String>  expected_res;
    ut::StringToArray(expected, expected_res);
    std::sort< vector< ut::String >::iterator >(expected_res.begin(), expected_res.end());

    if(expected_res != res)
    {
        UT_ASSERT_FAILED_MSG(string(string("actual result is different from expected: expected {") + 
            ut::StrToChar(ut::ArrayToString(expected_res)) +
            "} but actual is {" +
            ut::StrToChar(ut::ArrayToString(res)) +
            "}").c_str() );
    }
}
#endif

#if 0
static void VerifyAssociationChain(ProvReg* reg, MI_ConstString ns, MI_ConstString cn, MI_ConstString assocClass, MI_ConstString resultClass, MI_ConstString expected)
{
    // check derived classes
    vector<ut::String>  res;
    ProvRegAssocPosition pos;
    MI_ConstString nextClass = 0;

    MI_Result r = ProvReg_BeginAssocClasses( reg, ns, cn, assocClass, resultClass, &pos );

    UT_ASSERT (MI_RESULT_OK == r);

    for (;;)
    {
        MI_Boolean done;
        r = ProvReg_NextAssocClass( &pos, &nextClass, &done);

        if (done)
            break;

        UT_ASSERT (MI_RESULT_OK == r);
        res.push_back( nextClass );
    }

    r = ProvReg_EndAssocClasses(&pos);
    UT_ASSERT(MI_RESULT_OK == r);

    std::sort< vector< ut::String >::iterator >(res.begin(), res.end());

    vector<ut::String>  expected_res;
    ut::StringToArray(expected, expected_res);
    std::sort< vector< ut::String >::iterator >(expected_res.begin(), expected_res.end());

    if(expected_res != res)
    {
        UT_ASSERT_FAILED_MSG(string(string("actual result is different from expected: expected {") + 
            ut::StrToChar(ut::ArrayToString(expected_res)) +
            "} but actual is {" +
            ut::StrToChar(ut::ArrayToString(res)) +
            "}").c_str() );
    }
}
#endif

#if 0
static void TestClassInheritanceTreeMultipleDerived()
{
    const char* content = "# sample config entry\n"
        "statik:namespace           :Dog,Animal,Base    :provider_name\n"
        "statik:another_namespace   :Dog,Animal,Base    :provider_name\n"
        "statik:another_namespace   :Programmer,Person,Base    :software_provider_name\n"
        "statik:another_namespace   :CEO,Manager,Person,Base    :executive_provider_name\n"
        "statik:another_namespace   :stand_alone_Base    :one_more_provider_name\n"
        ;

    // verify inheritance chains:
    // Base -> Dog,Animal,Person,Programmer,Manager,CEO
    // Animal -> Dog
    // Person -> Programmer, Manager, CEO
    // Manager-> CEO
    // CEO, Programmer, Dog ->

    ut::writeFileContent( TEMP_FILE, vector<unsigned char>( reinterpret_cast<const unsigned char*>(content), 
        reinterpret_cast<const unsigned char*>(content)+strlen(content)));

    ProvReg reg;

    UT_ASSERT (MI_RESULT_OK == ProvReg_Init(&reg, TEMP_FILE));

    /////////////////////////////////////////////////////////////////////////////////////////////////
    //  another_namespace
    // deep == true
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Base"), MI_TRUE, T("Dog,Animal,Person,Programmer,Manager,CEO"));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Animal"), MI_TRUE, T("Dog"));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Person"), MI_TRUE, T("Programmer,Manager,CEO"));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Manager"), MI_TRUE, T("CEO"));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("CEO"), MI_TRUE, T(""));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Programmer"), MI_TRUE, T(""));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Dog"), MI_TRUE, T(""));

    // deep == false
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Base"), MI_FALSE, T("Animal,Person"));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Animal"), MI_FALSE, T("Dog"));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Person"), MI_FALSE, T("Programmer,Manager"));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Manager"), MI_FALSE, T("CEO"));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("CEO"), MI_FALSE, T(""));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Programmer"), MI_FALSE, T(""));
    VerifyInheritanceChain(&reg, T("another_namespace"), T("Dog"), MI_FALSE, T(""));

    // ALL CLASSES, deep == true
    VerifyInheritanceChain(&reg, T("another_namespace"), 0, MI_TRUE, T("Dog,Base,Animal,Person,Programmer,Manager,CEO,stand_alone_Base"));

    // ALL CLASSES, deep == false
    VerifyInheritanceChain(&reg, T("another_namespace"), 0, MI_FALSE, T("Base,stand_alone_Base"));

    /////////////////////////////////////////////////////////////////////////////////////////////////
    //  namespace
    // deep == true
    VerifyInheritanceChain(&reg, T("namespace"), T("Base"), MI_TRUE, T("Dog,Animal"));
    VerifyInheritanceChain(&reg, T("namespace"), T("Animal"), MI_TRUE, T("Dog"));
    VerifyInheritanceChain(&reg, T("namespace"), T("Dog"), MI_TRUE, T(""));

    // deep == false
    VerifyInheritanceChain(&reg, T("namespace"), T("Base"), MI_FALSE, T("Animal"));
    VerifyInheritanceChain(&reg, T("namespace"), T("Animal"), MI_FALSE, T("Dog"));
    VerifyInheritanceChain(&reg, T("namespace"), T("Dog"), MI_FALSE, T(""));

    // ALL CLASSES, deep == true
    VerifyInheritanceChain(&reg, T("namespace"), 0, MI_TRUE, T("Dog,Base,Animal"));

    // ALL CLASSES, deep == false
    VerifyInheritanceChain(&reg, T("namespace"), 0, MI_FALSE, T("Base"));

    /////////////////////////////////////////////////////////////////////////////////////////////////
    //  base classes
    const MI_Char* res = 0;
    UT_ASSERT( MI_RESULT_OK == ProvReg_GetDirectBaseClass(&reg, T("another_namespace"), T("Base"), &res) &&
        0 == res );
    UT_ASSERT( MI_RESULT_OK == ProvReg_GetDirectBaseClass(&reg, T("another_namespace"), T("Animal"), &res) &&
        ut::String(T("Base")) == res );
    UT_ASSERT( MI_RESULT_OK == ProvReg_GetDirectBaseClass(&reg, T("another_namespace"), T("Dog"), &res) &&
        ut::String(T("Animal")) == res );
    UT_ASSERT( MI_RESULT_OK == ProvReg_GetDirectBaseClass(&reg, T("another_namespace"), T("Programmer"), &res) &&
        ut::String(T("Person")) == res );

    // different case
    UT_ASSERT( MI_RESULT_OK == ProvReg_GetDirectBaseClass(&reg, T("another_namespace"), T("mAnAger"), &res) &&
        ut::String(T("Person")) == res );

    UT_ASSERT( MI_RESULT_OK == ProvReg_GetDirectBaseClass(&reg, T("Another_Namespace"), T("ceo"), &res) &&
        ut::String(T("Manager")) == res );

    // invalid class
    UT_ASSERT( MI_RESULT_INVALID_CLASS == ProvReg_GetDirectBaseClass(&reg, T("another_namespace"), T("not-existing-class"), &res) );

    // invalid namespace
    UT_ASSERT( MI_RESULT_INVALID_NAMESPACE == ProvReg_GetDirectBaseClass(&reg, T("not-existing-namespace"), T("Base"), &res) );

    ProvReg_Destroy(&reg);
}
#endif

#if 0
static void TestInvalidClassInheritanceTree()
{
    const char* content = "# sample config entry\n"
        "statik:namespace           :Dog,Animal,Base    :provider_name\n"
        "statik:  namespace         :Base,Animal,Dog    :provider_name\n"
        ;

    // entry is invalid - expect error back

    ut::writeFileContent( TEMP_FILE, vector<unsigned char>( reinterpret_cast<const unsigned char*>(content), 
        reinterpret_cast<const unsigned char*>(content)+strlen(content)));

    ProvReg reg;

    UT_ASSERT (MI_RESULT_INVALID_CLASS_HIERARCHY == ProvReg_Init(&reg, TEMP_FILE));
}
#endif

#if 0
static void TestInvalidNamespace()
{
    const char* content = "# sample config entry\n"
        "statik:namespace           :Dog,Animal,Base    :provider_name\n"
        ;

    // entry is invalid - expect error back

    ut::writeFileContent( TEMP_FILE, vector<unsigned char>( reinterpret_cast<const unsigned char*>(content), 
        reinterpret_cast<const unsigned char*>(content)+strlen(content)));

    ProvReg reg;

    UT_ASSERT (MI_RESULT_OK == ProvReg_Init(&reg, TEMP_FILE));


    ProvReg_Destroy(&reg);
}
#endif

#if 0
static void TestAssociations()
{
    const char* content = "# sample config entry\n"
        "# interop namespace\n"
        "statik:interop: Prov_Profile,CIM_RegisteredProfile,CIM_ManagedElement + "
            "Prov_ElementConformsToProfile,CIM_ElementConformsToProfile + "
            "Prov_CS,CIM_ComputerSystem,CIM_ManagedElement:provider_lib\n"
        "statik:interop: Prov_Profile,CIM_RegisteredProfile,CIM_ManagedElement:provider_lib\n"
        "# provider impl namespace\n"
        "statik:provider/impl: Prov_Profile,CIM_RegisteredProfile,CIM_ManagedElement + "
            "Prov_ElementConformsToProfile,CIM_ElementConformsToProfile +"
            "Prov_CS,CIM_ComputerSystem,CIM_ManagedElement:provider_lib\n"

        "statik:provider/impl:Prov_CS,CIM_ComputerSystem,CIM_ManagedElement:provider_lib\n"
        "statik:provider/impl:Prov_CustomCS,Prov_CS,CIM_ComputerSystem,CIM_ManagedElement:provider_lib\n"
        ;

    // verify inheritance chains:
    // CIM_ManagedElement -> CIM_RegisteredProfile, Prov_Profile, CIM_ComputerSystem, Prov_CS
    // CIM_ElementConformsToProfile -> Prov_ElementConformsToProfile
    // CIM_RegisteredProfile -> Prov_Profile
    // CIM_ComputerSystem -> Prov_CS

    ut::writeFileContent( TEMP_FILE, vector<unsigned char>( reinterpret_cast<const unsigned char*>(content), 
        reinterpret_cast<const unsigned char*>(content)+strlen(content)));

    ProvReg reg;

    UT_ASSERT (MI_RESULT_OK == ProvReg_Init(&reg, TEMP_FILE));

    /////////////////////////////////////////////////////////////////////////////////////////////////
    //  interop
    // deep == true
    VerifyInheritanceChain(&reg, T("interop"), T("CIM_ManagedElement"), MI_TRUE, T("CIM_RegisteredProfile,Prov_Profile,CIM_ComputerSystem,Prov_CS"));
    VerifyInheritanceChain(&reg, T("interop"), T("CIM_ElementConformsToProfile"), MI_TRUE, T("Prov_ElementConformsToProfile"));
    VerifyInheritanceChain(&reg, T("interop"), T("CIM_RegisteredProfile"), MI_TRUE, T("Prov_Profile"));
    VerifyInheritanceChain(&reg, T("interop"), T("CIM_ComputerSystem"), MI_TRUE, T("Prov_CS"));

    // deep == false
    VerifyInheritanceChain(&reg, T("interop"), T("CIM_ManagedElement"), MI_FALSE, T("CIM_RegisteredProfile,CIM_ComputerSystem"));
    VerifyInheritanceChain(&reg, T("interop"), T("CIM_ElementConformsToProfile"), MI_FALSE, T("Prov_ElementConformsToProfile"));
    VerifyInheritanceChain(&reg, T("interop"), T("CIM_RegisteredProfile"), MI_FALSE, T("Prov_Profile"));
    VerifyInheritanceChain(&reg, T("interop"), T("CIM_ComputerSystem"), MI_FALSE, T("Prov_CS"));

    // associations
    VerifyAssociationChain(&reg, T("provider/impl"), T("Prov_CustomCS"), 0, 0, T("Prov_ElementConformsToProfile"));
    VerifyAssociationChain(&reg, T("provider/impl"), T("Prov_CustomCS"), T("CIM_ElementConformsToProfile"), 0, T("Prov_ElementConformsToProfile"));
    VerifyAssociationChain(&reg, T("provider/impl"), T("Prov_CustomCS"), T("CIM_ElementConformsToProfile"), T("CIM_RegisteredProfile"), T("Prov_ElementConformsToProfile"));
    VerifyAssociationChain(&reg, T("provider/impl"), T("Prov_CustomCS"), 0, T("CIM_ManagedElement"), T("Prov_ElementConformsToProfile"));

    VerifyAssociationChain(&reg, T("interop"), T("Prov_Profile"), 0, 0, T("Prov_ElementConformsToProfile"));

    ProvReg_Destroy(&reg);
}
#endif

#if 0
static void TestMultipleAssociations()
{
    const char* content = "# sample config entry\n"
        "statik:ns:B,C+xb+X,Z:provider_lib\n"
        "statik:ns:B,C+bx+X,Z:provider_lib\n"
        "statik:ns:B,C+bz+Z:provider_lib\n"
        "statik:ns:A,B,C:provider_lib\n"
        "statik:ns:AA,B,C:provider_lib\n"
        "statik:ns:AAA,B,C:provider_lib\n"
        "statik:ns:X,Z + mx,zn + M,N:provider_lib\n"
        "statik:ns:Z + zn + N:provider_lib\n"
        ;

    ut::writeFileContent( TEMP_FILE, vector<unsigned char>( reinterpret_cast<const unsigned char*>(content), 
        reinterpret_cast<const unsigned char*>(content)+strlen(content)));

    ProvReg reg;

    UT_ASSERT (MI_RESULT_OK == ProvReg_Init(&reg, TEMP_FILE));

    // associations
    VerifyAssociationChain(&reg, T("ns"), T("AAA"), 0,          0, T("xb,bx,bz"));
    VerifyAssociationChain(&reg, T("ns"), T("AAA"), T("bz"),    0, T("bz"));
    VerifyAssociationChain(&reg, T("ns"), T("AAA"), 0,          T("X"), T("xb,bx,bz"));
    VerifyAssociationChain(&reg, T("ns"), T("AAA"), 0,          T("Z"), T("xb,bx,bz"));

    VerifyAssociationChain(&reg, T("ns"), T("X"), 0,        0, T("xb,bx,bz,mx,zn"));
    VerifyAssociationChain(&reg, T("ns"), T("Z"), 0,        0, T("bz,zn"));
    VerifyAssociationChain(&reg, T("ns"), T("X"), T("zn"),  0, T("mx,zn"));
    VerifyAssociationChain(&reg, T("ns"), T("X"), T("bz"),  0, T("bz"));
    VerifyAssociationChain(&reg, T("ns"), T("X"), T("bz"),  T("A"), T("bz"));

    VerifyAssociationChain(&reg, T("ns"), T("C"), 0,        0, T(""));
    VerifyAssociationChain(&reg, T("ns"), T("AAA"), T("mx"),    0, T(""));

    ProvReg_Destroy(&reg);
}
#endif

#if 0
static void TestAssociationsInvalidClass()
{
    const char* content = "# sample config entry\n"
        "statik:ns:B,C+xb+X,Z:provider_lib\n"
        "statik:ns:B,C+bx+X,Z:provider_lib\n"
        "statik:ns:B,C+bz+Z:provider_lib\n"
        "statik:ns:A,B,C:provider_lib\n"
        "statik:ns:AA,B,C:provider_lib\n"
        "statik:ns:AAA,B,C:provider_lib\n"
        "statik:ns:X,Z + mx,zn + M,N:provider_lib\n"
        "statik:ns:Z + zn + N:provider_lib\n"
        ;

    ut::writeFileContent( TEMP_FILE, vector<unsigned char>( reinterpret_cast<const unsigned char*>(content), 
        reinterpret_cast<const unsigned char*>(content)+strlen(content)));

    ProvReg reg;

    UT_ASSERT (MI_RESULT_OK == ProvReg_Init(&reg, TEMP_FILE));

    ProvRegAssocPosition pos;

    UT_ASSERT (MI_RESULT_INVALID_NAMESPACE == ProvReg_BeginAssocClasses( &reg, T("notExistingNamespace"), T("X"), 0, 0, &pos ));
    UT_ASSERT (MI_RESULT_INVALID_CLASS == ProvReg_BeginAssocClasses( &reg, T("ns"), T("noExisitingClass"), 0, 0, &pos ));
    UT_ASSERT (MI_RESULT_INVALID_CLASS == ProvReg_BeginAssocClasses( &reg, T("ns"), T("AA"), T("noExisitingClass"), 0, &pos ));
    UT_ASSERT (MI_RESULT_INVALID_CLASS == ProvReg_BeginAssocClasses( &reg, T("ns"), T("AA"), 0, T("noExisitingClass"), &pos ));

    ProvReg_Destroy(&reg);
}
#endif

#if 0
static void TestAssociationsToTheSameClass()
{
    const char* content = "# sample config entry\n"
        "statik:ns:X+a+X:provider_lib\n"
        ;

    ut::writeFileContent( TEMP_FILE, vector<unsigned char>( reinterpret_cast<const unsigned char*>(content), 
        reinterpret_cast<const unsigned char*>(content)+strlen(content)));

    ProvReg reg;

    UT_ASSERT (MI_RESULT_OK == ProvReg_Init(&reg, TEMP_FILE));

    // associations
    VerifyAssociationChain(&reg, T("ns"), T("X"), 0,          0, T("a"));

    ProvReg_Destroy(&reg);
}
#endif

#if 0
static void TestProvRegHosting()
{
    const char* content = "# sample config entry\n"
        "statik:ns:Default:provider_lib\n"
        "statik:ns:Inproc:provider_lib:@inproc@\t \n"
        "statik:ns:Requestor:provider_lib:\t@requestor@\n"
        "statik:ns:User:provider_lib:a_user \n"
        ;

    ut::writeFileContent( TEMP_FILE, vector<unsigned char>( reinterpret_cast<const unsigned char*>(content), 
        reinterpret_cast<const unsigned char*>(content)+strlen(content)));

    ProvReg reg;

    UT_ASSERT (MI_RESULT_OK == ProvReg_Init(&reg, TEMP_FILE));

    // verify hosting types are set correctly
    const ProvRegEntry* regItem; 
    
    regItem = ProvReg_FindProviderForClass(&reg, T("ns"), T("Default"));
    UT_ASSERT(regItem);
    UT_ASSERT(regItem->hosting == PROV_HOSTING_INPROC);
    UT_ASSERT(regItem->user == 0);

    regItem = ProvReg_FindProviderForClass(&reg, T("ns"), T("Inproc"));
    UT_ASSERT(regItem);
    UT_ASSERT(regItem->hosting == PROV_HOSTING_INPROC);
    UT_ASSERT(regItem->user == 0);

    regItem = ProvReg_FindProviderForClass(&reg, T("ns"), T("Requestor"));
    UT_ASSERT(regItem);
    UT_ASSERT(regItem->hosting == PROV_HOSTING_REQUESTOR);
    UT_ASSERT(regItem->user == 0);

    regItem = ProvReg_FindProviderForClass(&reg, T("ns"), T("user"));
    UT_ASSERT(regItem);
    UT_ASSERT(regItem->hosting == PROV_HOSTING_USER);
    UT_ASSERT(regItem->user != 0);
    UT_ASSERT(string(regItem->user) == "a_user");

    ProvReg_Destroy(&reg);
}
#endif

static void TestRegFile()
{
    RegFile* rf = RegFile_New(
        "./provreg/omiregister/root#cimv2/ConnectorProviderCXX.reg");
    UT_ASSERT(rf != NULL);

#if 0
    RegFile_Print(rf, stdout);
#endif

    RegFile_Delete(rf);
}

static void TestRegNameSpaces()
{
    vector<string> expected;
    vector<string> names;

    Dir* dir = Dir_Open("./provreg/omiregister");
    UT_ASSERT(dir != NULL);

    for (;;)
    {
        DirEnt *ent = Dir_Read(dir);
        if (!ent)
            break;

        if (strcmp(ent->name, "..") == 0 || strcmp(ent->name, ".") == 0)
            continue;

        if (strcmp(ent->name, "CVS") == 0)
            continue;

        names.push_back(ent->name);
    }

    Dir_Close(dir);

    expected.push_back("interop");
    expected.push_back("root");
    expected.push_back("root#cimv2");

    UT_ASSERT(names.size() == 3);
    UT_ASSERT(expected.size() == 3);

    sort(names.begin(), names.end());
    sort(expected.begin(), expected.end());
    UT_ASSERT(names == expected);
}

#if defined(CONFIG_POSIX)
static void TestProvReg2()
{
    ProvReg provReg;
    MI_Result r = ProvReg_Init2(&provReg);
    UT_ASSERT(r == MI_RESULT_OK);

    ProvReg_Destroy(&provReg);
}
#endif

static void RunTests()
{
    // ATTN: These tests tested the now obsolete omiregister.conf.
#if 0
    UT_TEST(TestProvReg);
    UT_TEST(TestProvRegInvalidConfigFile);
    UT_TEST(TestClassInheritanceTreeMultipleDerived);
    UT_TEST(TestInvalidClassInheritanceTree);
    UT_TEST(TestInvalidNamespace);
    UT_TEST(TestAssociations);
    UT_TEST(TestMultipleAssociations);
    UT_TEST(TestAssociationsInvalidClass);
    UT_TEST(TestAssociationsToTheSameClass);
    UT_TEST(TestProvRegHosting);
#endif
    UT_TEST(TestRegFile);
    UT_TEST(TestRegNameSpaces);
#if defined(CONFIG_POSIX)
    UT_TEST(TestProvReg2);
#endif
}

UT_ENTRY_POINT(RunTests);

ViewCVS 0.9.2