(file) Return to main.cpp CVS log (file) (dir) Up to [OMI] / omi / unittest / genoptions

File: [OMI] / omi / unittest / genoptions / Attic / main.cpp (download)
Revision: 1.1.1.1 (vendor branch), Wed May 30 21:47:39 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 <MI.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


extern "C" {
MI_Module* MI_Main(MI_Context* context);
}

const char* arg0;


/*

#pragma include("qualifiers.mof")

// test file for qualifiers
// this mof file declares dirretne types of qualifiers and test 
// progam verifies if they are actually in  schema.c

// test checks that (based on options):
// standard qualifiers are generated 
// boolean qualifiers are generated (TestQ_B, counter)
// Description is generated
// custom string qualifier is generated (TestQ_S)

Qualifier TestQ_B : boolean = true, 
    Scope(class, association, indication, method, property), 
    Flavor(EnableOverride, Restricted);

Qualifier TestQ_S : string = "SSS", 
    Scope(class, association, indication, method, property), 
    Flavor(EnableOverride, Restricted);

[Description ( "DDD" )]
class Test 
{
    [Key, TestQ_B(false), TestQ_S("123")] uint32 kv;
    
    [static] uint64 Foo([out, emBeddedInstance("X")] string embeddedProperty, [counter]uint32 c);
};


*/
static void usage()
{
    printf("usgae: %s <test-case>\n", arg0);
    printf("\tsupported test cases:\n"
        "\tdescription - expecting to find TestClass description 'DDD'\n"
        "\tignore_all - insures no qualifiers are generated.\n"
        );
    exit(0);
}

static void* _FindFeatureDecl(
    MI_FeatureDecl** features,
    MI_Uint32 numFeatures,
    const MI_Char* name)
{
    for( unsigned int i = 0; i < numFeatures; i++ )
    {
        if(strcmp(features[i]->name, name) == 0)
            return features[i];
    }

    return 0;
}

static const MI_Qualifier* _FindQualifier(
    const MI_ClassDecl* cd,
    const char* qn
    )
{
    for( unsigned int i = 0; i < cd->numQualifiers; i++ )
    {
        if(strcmp(cd->qualifiers[i]->name, qn) == 0)
            return cd->qualifiers[i];
    }

    return 0;
}

static void testDescription(MI_Module* module)
{
    // find 'Test' class
    const MI_ClassDecl* cd = 
        (const MI_ClassDecl*) _FindFeatureDecl( 
        (MI_FeatureDecl**)module->schemaDecl->classDecls,
         module->schemaDecl->numClassDecls,
         "Test");

    assert(cd != 0);

    const MI_Qualifier* q= _FindQualifier(cd, "Description");
 
    assert(q != 0);

    assert(strcmp(*(char**)q->value, "DDD") == 0);
}

static void testBoolean(MI_Module* module)
{
    // find 'Test' class
    const MI_ClassDecl* cd = 
        (const MI_ClassDecl*) _FindFeatureDecl( 
        (MI_FeatureDecl**)module->schemaDecl->classDecls,
         module->schemaDecl->numClassDecls,
         "Test");

    assert(cd != 0);

    const MI_PropertyDecl* prop = 
        (const MI_PropertyDecl*) _FindFeatureDecl( 
        (MI_FeatureDecl**)cd->properties,
         cd->numProperties,
         "kv");

    assert(prop != 0);

    const MI_Qualifier* q= _FindQualifier((const MI_ClassDecl*)prop, "TestQ_B");

    assert(q != 0);

    assert( *(MI_Boolean*)q->value  == MI_FALSE);

    // find method Foo, parameter c and check qualifier counter
    const MI_MethodDecl* m = 
        (const MI_MethodDecl*) _FindFeatureDecl( 
        (MI_FeatureDecl**)cd->methods,
         cd->numMethods,
         "Foo");

    assert(m != 0);

    prop = 
        (const MI_PropertyDecl*) _FindFeatureDecl( 
        (MI_FeatureDecl**)m->parameters,
         m->numParameters,
         "c");


    assert(prop != 0);

    q = _FindQualifier((const MI_ClassDecl*)prop, "Counter");

    assert(q != 0);

    assert( *(MI_Boolean*)q->value  == MI_TRUE);

}

static void testIgnoreAll(MI_Module* module)
{
    assert(module->schemaDecl->qualifierDecls == 0);

    // find 'Test' class
    const MI_ClassDecl* cd = //_FindClass(module, "Test");
        (const MI_ClassDecl*) _FindFeatureDecl( 
        (MI_FeatureDecl**)module->schemaDecl->classDecls,
         module->schemaDecl->numClassDecls,
         "Test");

    assert(cd != 0);

    assert(cd->qualifiers == 0);
}

int main(int argc, char* argv[])
{
    MI_Module* module = MI_Main(NULL);
    assert(module != NULL);

    arg0 = argv[0];

    if (argc < 2)
    {
        fprintf(stderr, "Usage: %s test-case\n", arg0);
        fprintf(stderr, "Try '%s -h' for help\n\n", arg0);
        exit(1);
    }

    if (strcmp(argv[1],"description") == 0)
    {
        testDescription(module);
    }
    else if (strcmp(argv[1],"ignore_all") == 0)
    {
        testIgnoreAll(module);
    }
    else if (strcmp(argv[1],"boolean") == 0)
    {
        testBoolean(module);
    }
    else if (strcmp(argv[1],"-h") == 0)
    {
        usage();
    }
    else
    {
        fprintf(stderr, "unknown parameter: %s \n", argv[1]);
        fprintf(stderr, "Try '%s -h' for help\n\n", arg0);
        exit(1);
    }

    return 0;
}

ViewCVS 0.9.2