/**
             * Virtual method that copies the values of an entry to the given \p variable.
             *
             * @param parent    The plug-in we belong to.
             * @param variable  The variable to fill with our values.
             */
            public virtual void ToVariable( InMemoryPlugin parent, Variable variable )
            {
                ALIB.ASSERT( Delim != '\0' || Values.Count <= 1);
                if ( Delim != '\0' )
                    variable.Delim= Delim;
                if ( FormatHints != 0 )
                    variable.FormatHints= FormatHints;
                if ( FormatAttrAlignment != null )
                    variable.FormatAttrAlignment= FormatAttrAlignment;

                variable.Comments._()._( Comments );
                foreach( AString val in Values )
                    variable.AddString( val );
            }
    bool  Load( Variable variable, bool searchOnly= false )
    {
        if ( args == null )
            return false;

        int   optionLength=   variable.Fullname.Length();
        Substring actVar=     new Substring();

        for ( int i= 0; i < args.Length ; i++ )
        {
            // remove whitespaces (if somebody would work with quotation marks...)
            // and request '-' and allow a second '-'
            if ( !actVar.Set( args[i] ).Trim().Consume('-') )
                continue;
            actVar.Consume( '-' );

            if ( variable.Fullname.CompareTo( args[i], Case.Ignore, actVar.Start, optionLength, 0, optionLength ) == 0)
            {
                //again, lets trim before searching the = sign (really almost unnecessary)
                actVar.Start+= optionLength;
                if ( actVar.IsEmpty() )
                {
                    if ( !searchOnly )
                        variable.AddString();
                    return true;
                }

                if ( actVar.Consume( '=', Case.Sensitive, Whitespaces.Trim ) )
                {
                    if ( !searchOnly )
                    {
                        actVar.Trim();
                        StringConverter.LoadFromString( variable, actVar );

                    }
                    return true;
                }
             }
        }

        return false;
    }
    void    LoadFromString( Variable variable, Object src )
    {
        variable.ClearValues();
        AString varValue= variable.AddString();

        Substring subs= null;
        if( src is Substring)
            subs= (Substring) src;
        else if ( src is AString )
        {
            subs= tmpSubs;
            subs.Set( (AString) src );
        }
        else
        {
            tmpAS._()._( src );
            tmpSubs.Set( tmpAS );
            subs= tmpSubs;
        }

        // tokenize
        bool inQuote=      false;
        bool lastWasSlash= false;
        int  idx=          0;
        while( idx < subs.Length()  )
        {
            char c= subs.CharAt( idx++ );

            if( lastWasSlash )
            {
                lastWasSlash= false;
                continue;
            }

            if( c== '\\' )
            {
                lastWasSlash= true;
                continue;
            }

            if( c== '"' )
            {
                inQuote= !inQuote;
                continue;
            }

            if( !inQuote && c == variable.Delim )
            {
                tmpSubs2.Set( subs, 0, idx - 1 );
                InternalizeValue( tmpSubs2, varValue );
                varValue= variable.AddString();
                subs.Consume( idx );
                subs.TrimStart();
                idx= 0;
            }
        }
        if ( subs.IsNotEmpty() )
        {
            InternalizeValue( subs, varValue );
        }
    }
Пример #4
0
        /** ****************************************************************************************
         * Invokes grand-parent's method and in addition, de-registers with
         * \ref cs::aworx::lib::ALIB::StdOutputStreamsLock "ALIB.StdOutputStreamsLock"
         * @param acquirer The acquirer to remove.
         * @return The new number of \e acquirers set.
         ******************************************************************************************/
        public override int   RemoveAcquirer( ThreadLock acquirer )
        {
            // d-register with ALIB lockers (if not done yet)
            if ( usesStdStreams )
            {
                ALIB.Lock.Acquire();
                    int  stdStreamLockRegistrationCounter= --this.stdStreamLockRegistrationCounter;
                ALIB.Lock.Release();

                if ( stdStreamLockRegistrationCounter == 0 )
                    ALIB.StdOutputStreamsLock.RemoveAcquirer( this );
            }

            Variable variable= new Variable();

            // export autosizes to configuration
            variable.Define( ALox.AUTO_SIZES, GetName() );
            AutoSizes.Export( variable.AddString() );
            variable.Store();

            // export "max elapsed time" to configuration
            variable.Define( ALox.MAX_ELAPSED_TIME, GetName() );
            AString destVal=  variable.Load() != 0  ?  variable.GetString()
                                                    :  variable.AddString();
            destVal._()._( MetaInfo.MaxElapsedTime.InSeconds() );
            variable.Store();

            // call parents' implementation
            return base.RemoveAcquirer( acquirer );
        }
Пример #5
0
    // #############################################################################################
    // Reimplementing interface of grand-parent class SmartLock
    // #############################################################################################

        /** ****************************************************************************************
         * Invokes grand-parent's method and in addition, if field #usesStdStreams is set,
         * registers with
         * \ref cs::aworx::lib::ALIB::StdOutputStreamsLock "ALIB.StdOutputStreamsLock", respectively
         *
         * @param newAcquirer The acquirer to add.
         * @return The new number of \e acquirers set.
         ******************************************************************************************/
        public override int   AddAcquirer( ThreadLock newAcquirer )
        {
            // register with ALIB lockers (if not done yet)
            if ( usesStdStreams )
            {
                ALIB.Lock.Acquire();
                    int  stdStreamLockRegistrationCounter= this.stdStreamLockRegistrationCounter++;
                ALIB.Lock.Release();
                if ( stdStreamLockRegistrationCounter == 0 )
                    ALIB.StdOutputStreamsLock.AddAcquirer( this );
            }

            Variable variable= new Variable();

            // import autosizes from configuration (last session)
            if ( variable.Define( ALox.AUTO_SIZES, GetName()).Load() != 0 )
                AutoSizes.Import( variable.GetString() );

            // import "max elapsed time" from configuration (last session)
            if ( variable.Define( ALox.MAX_ELAPSED_TIME, GetName()).Load()  != 0 )
            {
                long maxInSecs= variable.GetInteger();
                Substring attrValue= new Substring();
                if ( variable.GetAttribute( "limit", attrValue ) )
                {
                    long maxMax;
                    attrValue.ConsumeLong( out maxMax );
                    if ( maxInSecs > maxMax )
                        maxInSecs= maxMax;
                }
                MetaInfo.MaxElapsedTime.FromSeconds( maxInSecs );
            }

            // Variable  <name>_FORMAT / <typeName>_FORMAT:
            ALIB.ASSERT_WARNING( ALox.FORMAT.DefaultValue == null,
                                 "Default value of variable FORMAT should be kept null" );
            if(    0 ==  variable.Define( ALox.FORMAT, GetName()     ).Load()
                && 0 ==  variable.Define( ALox.FORMAT, GetTypeName() ).Load() )
            {
                // no variable created, yet. Let's create a 'personal' one on our name
                variable.Define( ALox.FORMAT, GetName() );
                variable.AddString( MetaInfo.Format            );
                variable.AddString( MetaInfo.VerbosityError    );
                variable.AddString( MetaInfo.VerbosityWarning  );
                variable.AddString( MetaInfo.VerbosityInfo     );
                variable.AddString( MetaInfo.VerbosityVerbose  );
                variable.Store();
            }
            else
            {
                                           MetaInfo.Format          ._()._( variable.GetString(0) );
                if( variable.Size() >= 2 ) MetaInfo.VerbosityError  = variable.GetString(1).ToString();
                if( variable.Size() >= 3 ) MetaInfo.VerbosityWarning= variable.GetString(2).ToString();
                if( variable.Size() >= 4 ) MetaInfo.VerbosityInfo   = variable.GetString(3).ToString();
                if( variable.Size() >= 5 ) MetaInfo.VerbosityVerbose= variable.GetString(4).ToString();
            }
        
            // Variable  <name>_FORMAT_DATE_TIME / <typeName>_FORMAT_DATE_TIME:
            ALIB.ASSERT_WARNING( ALox.FORMAT_DATE_TIME.DefaultValue == null,
                                 "Default value of variable FORMAT_DATE_TIME should be kept null" );
            if(    0 ==  variable.Define( ALox.FORMAT_DATE_TIME, GetName()     ).Load()
                && 0 ==  variable.Define( ALox.FORMAT_DATE_TIME, GetTypeName() ).Load() )
            {
                // no variable created, yet. Let's create a 'personal' one on our name
                variable.Define( ALox.FORMAT_DATE_TIME, GetName() );
                variable.AddString( MetaInfo.DateFormat        );
                variable.AddString( MetaInfo.TimeOfDayFormat   );
                variable.AddString( MetaInfo.TimeElapsedDays   );
                variable.Store();
            }
            else
            {
                                           MetaInfo.DateFormat      = variable.GetString(0).ToString();
                if( variable.Size() >= 2 ) MetaInfo.TimeOfDayFormat = variable.GetString(1).ToString();
                if( variable.Size() >= 3 ) MetaInfo.TimeElapsedDays = variable.GetString(2).ToString();
            }
        
            // Variable  <name>FORMAT_TIME_DIFF / <typeName>FORMAT_TIME_DIFF:
            ALIB.ASSERT_WARNING( ALox.FORMAT_TIME_DIFF.DefaultValue == null,
                                 "Default value of variable FORMAT_TIME_DIFF should be kept null" );
            if(    0 ==  variable.Define( ALox.FORMAT_TIME_DIFF, GetName()     ).Load()
                && 0 ==  variable.Define( ALox.FORMAT_TIME_DIFF, GetTypeName() ).Load() )
            {
                // no variable created, yet. Let's create a 'personal' one on our name
                variable.Define( ALox.FORMAT_TIME_DIFF, GetName() );
                variable.AddInteger   ( MetaInfo.TimeDiffMinimum);
                variable.AddString( MetaInfo.TimeDiffNone   );
                variable.AddString( MetaInfo.TimeDiffNanos  );
                variable.AddString( MetaInfo.TimeDiffMicros );
                variable.AddString( MetaInfo.TimeDiffMillis );
                variable.AddString( MetaInfo.TimeDiffSecs   );
                variable.AddString( MetaInfo.TimeDiffMins   );
                variable.AddString( MetaInfo.TimeDiffHours  );
                variable.AddString( MetaInfo.TimeDiffDays   );
                variable.Store();
            }
            else
            {
                                           MetaInfo.TimeDiffMinimum= variable.GetInteger   (0);
                if( variable.Size() >= 2 ) MetaInfo.TimeDiffNone   = variable.GetString(1).ToString();
                if( variable.Size() >= 3 ) MetaInfo.TimeDiffNanos  = variable.GetString(2).ToString();
                if( variable.Size() >= 4 ) MetaInfo.TimeDiffMicros = variable.GetString(3).ToString();
                if( variable.Size() >= 5 ) MetaInfo.TimeDiffMillis = variable.GetString(4).ToString();
                if( variable.Size() >= 6 ) MetaInfo.TimeDiffSecs   = variable.GetString(5).ToString();
                if( variable.Size() >= 7 ) MetaInfo.TimeDiffMins   = variable.GetString(6).ToString();
                if( variable.Size() >= 8 ) MetaInfo.TimeDiffHours  = variable.GetString(7).ToString();
                if( variable.Size() >= 9 ) MetaInfo.TimeDiffDays   = variable.GetString(8).ToString();
            }

            // Variable  <name>FORMAT_MULTILINE / <typeName>FORMAT_MULTILINE:
            ALIB.ASSERT_WARNING( ALox.FORMAT_MULTILINE.DefaultValue == null,
                                 "Default value of variable FORMAT_MULTILINE should be kept null" );
            if(    0 ==  variable.Define( ALox.FORMAT_MULTILINE, GetName()     ).Load()
                && 0 ==  variable.Define( ALox.FORMAT_MULTILINE, GetTypeName() ).Load() )
            {
                // no variable created, yet. Let's create a 'personal' one on our name
                variable.Define( ALox.FORMAT_MULTILINE, GetName() );
                variable.AddInteger( MultiLineMsgMode );
                variable.AddString ( FmtMultiLineMsgHeadline   );
                variable.AddString ( FmtMultiLinePrefix  );
                variable.AddString ( FmtMultiLineSuffix );
                variable.Store();
            }
            else
            {
                                           MultiLineMsgMode=        (int) variable.GetInteger(0)  ;
                if( variable.Size() >= 2 ) FmtMultiLineMsgHeadline= variable.GetString(1).ToString();
                if( variable.Size() >= 3 ) FmtMultiLinePrefix     = variable.GetString(2).ToString();
                if( variable.Size() >= 4 ) FmtMultiLineSuffix     = variable.GetString(3).ToString();
                if( variable.Size() >= 5 ) { if (variable.GetString(4).Equals( "nulled" , Case.Ignore ) )
                                                MultiLineDelimiter= null;
                                             else
                                                MultiLineDelimiter= variable.GetString(4).ToString();
                                           }
                if( variable.Size() >= 6 ) MultiLineDelimiterRepl = variable.GetString(5).ToString();
            }

            // call parents' implementation
            return base.AddAcquirer( newAcquirer );
        }
public void IniFileTest()
{
    // write sample config file
    //UT_PRINT(""); UT_PRINT( "### Configuration with IniFile ###" );
    String iniFileContents=
     "##########################################################################"  +"\n"
    +"## unit test config file"                                                    +"\n"
    +"##########################################################################"  +"\n"
    +"// this is also a comment"                                                   +"\n"
    +"; and this is as well"                                                       +"\n"
    +""                                                                            +"\n"
    +"HOME= overwritten_by_environment"                                            +"\n"
    +"HOMEPATH= overwritten_by_environment"                                        +"\n"
    +""                                                                            +"\n"
    +"concat=    start =5,          \\"                                            +"\n"
    +"           end   =32,       \\"                                              +"\n"
    +"           \\#no comment,   \\"                                              +"\n"
    +"           \\;nocomment,   \\"                                               +"\n"
    +"           ;a comment,   \\"                                                 +"\n"
    +"           getsLonger,    \\"                                                +"\n"
    +"           getsLongerxxx,   \\"                                              +"\n"
    +"           getsshorter,    \\"                                               +"\n"
    +"           getsLongerxxxxx,  \\"                                             +"\n"
    +"           getsLongerxxxxxxxxx,  \\"                                         +"\n"
    +"           getsshorterxx,    \\"                                             +"\n"
    +"           last"                                                             +"\n"
    +""                                                                            +"\n"
    +""                                                                            +"\n"
    +"CUBA=a country"                                                              +"\n"
    +"# The size "                                                                 +"\n"
    +" SIZE=  25 "                                                                 +"\n"
    +""                                                                            +"\n"
    +"# doble comment line"                                                        +"\n"
    +"# double, i meant"                                                           +"\n"
    +"2Comments= much talk"                                                        +"\n"
    +""                                                                            +"\n"
    +"# A great section"                                                           +"\n"
    +"[Great Section] "                                                            +"\n"
    +"SectionVar=5"                                                                +"\n"
    +"Double=12.3"                                                                 +"\n"
    +"Tricky=  backslash\\\\"                                                      +"\n"
    +"# A 2nd section"                                                             +"\n"
    +"[2nd Section] "                                                              +"\n"
    +"SectionVar=6"                                                                +"\n"
    +""                                                                            +"\n"
    +""                                                                            +"\n"
    +"[Great Section] "                                                            +"\n"
    +"SECTION_CONTINUED   = yEs"                                                   +"\n"
    +""                                                                            +"\n"
    +""                                                                            +"\n"
    +"[ESC] "                                                                      +"\n"
    +"Blanks=  \" x \""                                                            +"\n"
    +"Blanks2= \" x \" \\"                                                         +"\n"
    +"         \" y \" "                                                           +"\n"
    +"Tabs=\t\t\\tx\\t"                                                            +"\n"
    +"nrslash= \"\\n\\r//\\\\\""                                                   +"\n"
   ;

    String fileName= Environment.CurrentDirectory + "/unittest_testiniFile.cfg";

    // write sample config file
    {
        StreamWriter file= new StreamWriter( fileName );
        file.Write( iniFileContents );
        file.Close();
    }

    IniFile iniFile= new IniFile( fileName );
    UT_TRUE( (IniFile.Status.OK == iniFile.LastStatus) );

    // check some values
    Variable var= new Variable();
    iniFile.Load( var.Define( "",    "CUBA") );         UT_EQ( "a country",      var.GetString() );
    iniFile.Load( var.Define( "",    "cUbA") );         UT_EQ( "a country",      var.GetString() );
    iniFile.Load( var.Define( "",    "SIZE") );         UT_EQ( "25",             var.GetString() );
    iniFile.Load( var.Define( "",    "concat", ',') );  UT_EQ( 11 , var.Size());
                                                        UT_EQ( "start =5"       , var.GetString(0) );
                                                        UT_EQ( "end   =32"      , var.GetString(1) );
                                                        UT_EQ( "#no comment"    , var.GetString(2) );
                                                        UT_EQ( ";nocomment"     , var.GetString(3) );

    iniFile.Load( var.Define( "ESC", "Blanks"  ) );   UT_EQ( " x "      , var.GetString() );
    iniFile.Load( var.Define( "ESC", "Blanks2" ) );   UT_EQ( " x  y "   , var.GetString() );
    iniFile.Load( var.Define( "ESC", "Tabs"    ) );   UT_EQ( "\tx\t"    , var.GetString() );
    iniFile.Load( var.Define( "ESC", "nrslash" ) );   UT_EQ( "\n\r//\\" , var.GetString() );

    iniFile.Load( var.Define( "Great Section",  "SectionVar"       ) );   UT_EQ( "5"  , var.GetString() );
    iniFile.Load( var.Define( "2nd Section",    "SectionVar"       ) );   UT_EQ( "6"  , var.GetString() );
    iniFile.Load( var.Define( "Great Section",  "SECTION_CONTINUED") );   UT_EQ( "yEs", var.GetString() );
    iniFile.Load( var.Define( "Great Section",  "Tricky"           ) );   UT_EQ( "backslash\\", var.GetString() );

    // add it to ALIB config
    ALox.Init();
    ALIB.Config.InsertPlugin( iniFile, Configuration.PrioIniFile );
    ALIB.Config.Load( var.Define( "",               "CUBA"              ) );   UT_EQ( "a country"  , var.GetString() );
    ALIB.Config.Load( var.Define( "",               "cUbA"              ) );   UT_EQ( "a country"  , var.GetString() );
    ALIB.Config.Load( var.Define( "",               "SIZE"              ) );   UT_EQ( "25"         , var.GetString() );
    ALIB.Config.Load( var.Define( "",               "concat"            ) );   UT_EQ( 11 , var.Size());
                                                                               UT_EQ( "start =5"   , var.GetString(0) );
                                                                               UT_EQ( "end   =32"  , var.GetString(1) );
    ALIB.Config.Load( var.Define( "Great Section",  "SectionVar"        ) );   UT_EQ( "5"          , var.GetString() );
    ALIB.Config.Load( var.Define( "2nd Section",    "SectionVar"        ) );   UT_EQ( "6"          , var.GetString() );
    ALIB.Config.Load( var.Define( "Great Section",  "SECTION_CONTINUED" ) );   UT_EQ( "yEs"        , var.GetString() );
    ALIB.Config.Load( var.Define( "Great Section",  "Tricky"            ) );   UT_EQ( "backslash\\", var.GetString() );
    ALIB.Config.Load( var.Define( "Great Section",  "SECTION_CONTINUED" ) );   UT_TRUE( var.IsTrue() );


    // check if environment variable "home" overwrites INI file
    AString vIniFile= new AString();   iniFile.Load( var.Define( "", "hOme" ) );               UT_EQ( "overwritten_by_environment", var.GetString() );
    int prio= ALIB.Config.Load( var.Define("", "hOme" ));
    if (prio != Configuration.PrioEnvironment ) // Windows platform?
    {
        prio= ALIB.Config.Load( var.Define("", "hOmePAth") );
        iniFile.Load( var.Define( "", "hOmePAth") );    UT_EQ( "overwritten_by_environment", var.GetString() );
    }
    UT_EQ( Configuration.PrioEnvironment, prio );

    UT_TRUE( var.GetString().Length() > 0 );
    UT_TRUE( !vIniFile.Equals( var.GetString()) );

    // change a value and write a new one
    var.Define( "New Section",  "newvar");
    var.Priority= Configuration.PrioIniFile;
    UT_EQ( Configuration.PrioIniFile, ALIB.Config.Store( var, "new" ) );
    ALIB.Config.Load  ( var.Define("New Section",  "newvar") );  UT_EQ( "new",   var.GetString() );

    var.Define( "",             "newvar");
    var.Priority= Configuration.PrioIniFile;
    UT_EQ( Configuration.PrioIniFile, ALIB.Config.Store( var, "aworx") );
    ALIB.Config.Load  ( var.Define("",             "newvar") );  UT_EQ( "aworx", var.GetString() );


    var.Define( "",   "newvarList", ',');
    var.AddString("val1=5");
    var.AddString("val2=10");
    var.AddString("val3=hello");
    var.Priority= Configuration.PrioIniFile;
    UT_EQ( Configuration.PrioIniFile, ALIB.Config.Store(var) );
    ALIB.Config.Load (  var.Define( "",  "newvarList")   );

    var.Define( "",   "commented", ',', "2lines" );
    var.Priority= Configuration.PrioIniFile;
    UT_EQ( Configuration.PrioIniFile, ALIB.Config.Store(  var,  "this is c-line 1 \nand this line 2" ) );

    // write the file
    iniFile.FileName._(".writeback.txt");
    iniFile.WriteFile();

    // load the written file into another config
    IniFile readBack= new IniFile( iniFile.FileName.ToString() );
    Variable varBack= new Variable();

    // compare all
    UT_TRUE( (IniFile.Status.OK == readBack.LastStatus) );

    {
        AString msg= new AString();
        Substring orig= new Substring();
        Substring back= new Substring();
        foreach ( IniFile.Section section in iniFile.Sections )
        {
            foreach ( IniFile.Entry entry in section.Entries )
            {
                msg.Clear()._( "Reading variable " ).Field()._( section.Name )._( '/' )._( entry.Name );
                UT_PRINT( msg );


                char delim= '\0';
                if(     entry.Name.Equals("concat")
                    ||  entry.Name.Equals("newvarList")       )
                    delim= ',';

                iniFile .Load( var    .Define( section.Name, entry.Name, delim) );
                readBack.Load( varBack.Define( section.Name, entry.Name, delim) );

                UT_EQ( var.Size(), varBack.Size() );
                for ( int i= 0; i< var.Size(); i++ )
                {
                    int idx= var.GetString(i).IndexOf('=');
                    if( idx < 0 )
                    {
                        UT_EQ( var.GetString(i), varBack.GetString(i) );
                    }
                    else
                    {
                        int idxBack= varBack.GetString(i).IndexOf('=');
                        orig.Set( var    .GetString(i), 0, idx     );
                        back.Set( varBack.GetString(i), 0, idxBack );
                        UT_EQ( orig.Trim().ToString(), back.Trim().ToString() );
                        orig.Set( var    .GetString(i), idx     +1 );
                        back.Set( varBack.GetString(i), idxBack +1 );
                        UT_EQ( orig.Trim().ToString(), back.Trim().ToString() );
                    }
                }
            }
        }
    }

    readBack.Load ( var.Define( "New Section",  "newvar" ) );   UT_EQ( "new"  , var.GetString() );
    readBack.Load ( var.Define( "",             "newvar" ) );   UT_EQ( "aworx", var.GetString() );


    ALIB.Config.RemovePlugin( iniFile );


    ALIB.Config.InsertPlugin( readBack, Configuration.PrioIniFile );
    ALIB.Config.Load ( var.Define( "New Section",  "newvar") );   UT_EQ( "new"   , var.GetString() );
    ALIB.Config.Load ( var.Define( "",             "newvar") );   UT_EQ( "aworx" , var.GetString() );

    ALIB.Config.RemovePlugin( readBack );
}
public void ConfigDefaultAndProtected()
{
    UT_INIT();

    String[] args=
    {
        "COMMANDLINE",
        "--TEST_VARIABLE=fromCommandLine",
    };

    Configuration cfg= new Configuration();
    cfg.SetCommandLineArgs( args );

    Variable var= new Variable();

    // command line
    UT_EQ( Configuration.PrioCmdLine,    cfg.Load  ( var.Define( "TEST",      "VARIABLE" ) ) );   UT_EQ( "fromCommandLine"    ,var.GetString() );

    // set default, does not overwrite
    cfg.DefaultValues.Store( var.Define("TEST", "VARIABLE"), "not overwriting" );
    UT_EQ( Configuration.PrioCmdLine,    cfg.Load  ( var.Define( "TEST",      "VARIABLE" ) ) );   UT_EQ( "fromCommandLine"    ,var.GetString() );

    // set protected, overwrites command line
    cfg.ProtectedValues.Store( var.Define("TEST", "VARIABLE"), "does overwrite" );
    UT_EQ( Configuration.PrioProtected,  cfg.Load  ( var.Define( "TEST",      "VARIABLE" ) ) );   UT_EQ( "does overwrite"     ,var.GetString() );

    // set default, something else
    cfg.DefaultValues.Store( var.Define("TEST", "VAR2"), "this is var 2" );
    UT_EQ( Configuration.PrioDefault,    cfg.Load  ( var.Define( "TEST",      "VAR2"     ) ) );   UT_EQ( "this is var 2"      ,var.GetString() );

    // set and remove an entry using plugin interface
    var.Define( "TEST", "Remove" );     UT_EQ( 0, var.Size() );     UT_EQ( -1                           ,var.Priority );
    cfg.DefaultValues.Load( var );      UT_EQ( 0, var.Size() );     UT_EQ( -1                           ,var.Priority );
    var.AddString("To be deleted");     UT_EQ( 1, var.Size() );     UT_EQ( -1                           ,var.Priority );
    cfg.DefaultValues.Store( var );     UT_EQ( 1, var.Size() );     UT_EQ( -1                           ,var.Priority );
    var.Define( "TEST", "Remove" );     UT_EQ( 0, var.Size() );     UT_EQ( -1                           ,var.Priority );
    cfg.DefaultValues.Load( var );      UT_EQ( 1, var.Size() );     UT_EQ( -1                           ,var.Priority );
    var.ClearValues();                  UT_EQ( 0, var.Size() );     UT_EQ( -1                           ,var.Priority );
    cfg.DefaultValues.Store( var );     UT_EQ( 0, var.Size() );     UT_EQ( -1                           ,var.Priority );
    var.Define( "TEST", "Remove" );     UT_EQ( 0, var.Size() );     UT_EQ( -1                           ,var.Priority );
    cfg.DefaultValues.Load( var );      UT_EQ( 0, var.Size() );     UT_EQ( -1                           ,var.Priority );

    // set and remove an entry using configuration interface
    cfg              .Load ( var );     UT_EQ( 0, var.Size() );     UT_EQ(  0                           ,var.Priority );
    cfg              .Store( var );     UT_EQ( 0, var.Size() );     UT_EQ(  0                           ,var.Priority );
    var.AddString("To be deleted");     UT_EQ( 1, var.Size() );     UT_EQ(  0                           ,var.Priority );
    cfg              .Store( var );     UT_EQ( 1, var.Size() );     UT_EQ( Configuration.PrioDefault    ,var.Priority );
    var.Define( "TEST", "Remove" );     UT_EQ( 0, var.Size() );     UT_EQ( -1                           ,var.Priority );
    cfg              .Load ( var );     UT_EQ( 1, var.Size() );     UT_EQ( Configuration.PrioDefault    ,var.Priority );
    var.Define( "TEST", "Remove" );     UT_EQ( 0, var.Size() );     UT_EQ( -1                           ,var.Priority );
    cfg              .Store( var );     UT_EQ( 0, var.Size() );     UT_EQ( Configuration.PrioDefault    ,var.Priority );
    cfg              .Load ( var );     UT_EQ( 0, var.Size() );     UT_EQ( 0                            ,var.Priority );
    var.Define( "TEST", "Remove" );     UT_EQ( 0, var.Size() );     UT_EQ( -1                           ,var.Priority );
    cfg              .Load ( var );     UT_EQ( 0, var.Size() );     UT_EQ( 0                            ,var.Priority );

    // protected
    var.Define( "TEST", "Protected");   UT_EQ( 0, var.Size() );                 UT_EQ( -1                          ,var.Priority );
    var.DefaultValue._( "Default"  );
    var.StoreDefault( "def par");       UT_EQ( "def par",   var.GetString() );  UT_EQ( Configuration.PrioDefault   ,var.Priority );

    var.ClearValues();
    var.AddString( "def var" );
    var.StoreDefault();                 UT_EQ( "def var",   var.GetString() );  UT_EQ( Configuration.PrioDefault   ,var.Priority );

    var.ClearValues();
    var.StoreDefault();                 UT_EQ( "Default",   var.GetString() );  UT_EQ( Configuration.PrioDefault   ,var.Priority );

    var.ClearValues();
    var.AddString( "def var" );
    var.Protect();                      UT_EQ( "def var",   var.GetString() );  UT_EQ( Configuration.PrioProtected ,var.Priority );
    var.Protect("prot par");            UT_EQ( "prot par",  var.GetString() );  UT_EQ( Configuration.PrioProtected ,var.Priority );
    var.ClearValues();
    var.Protect();                      UT_EQ( "Default",   var.GetString() );  UT_EQ( Configuration.PrioProtected ,var.Priority );
    var.DefaultValue.SetNull();
    var.ClearValues();
    var.Protect();                      UT_EQ( 0, var.Size()                );  UT_EQ( Configuration.PrioProtected ,var.Priority );
    var.Load();                         UT_EQ( "Default",   var.GetString() );  UT_EQ( Configuration.PrioDefault   ,var.Priority );

}
Пример #8
0
    /** ****************************************************************************************
     * Helper method of #dumpStateOnLoggerRemoval to recursively collect domain settings.
     * @param domain    The actual domain.
     * @param loggerNo  The number of the logger
     * @param variable  The AString to collect the information.
     ******************************************************************************************/
    #if ALOX_DBG_LOG || ALOX_REL_LOG
    protected void verbositySettingToVariable( Domain domain, int loggerNo, Variable variable )
    {
        variable.AddString()._( domain.FullPath )
                            ._('=')
                            ._( domain.GetVerbosity( loggerNo ).ToString() );

        // loop over all sub domains (recursion)
        foreach( Domain subDomain in domain.SubDomains )
            verbositySettingToVariable( subDomain, loggerNo, variable );
    }