Ejemplo n.º 1
0
    public void Log_SetSourcePathTrimRuleExternal()
    {
        UT_INIT();

        // for the unit tests to reset, we need an extra lox to be able to clear the global rules
        // beforewe initialize our main lox
        Lox clearLox= new Lox("ClearingRules");

        // global rule
        clearLox.ClearSourcePathTrimRules( Reach.Global, false);
        {
            // create iniFile
            String iniFileContents=
                 "[ALOX]\n"
                +"TESTML_FORMAT= \"%Sp\"  \n"

                +"GLOBAL_SOURCE_PATH_TRIM_RULES=  *src.cs/   , true  ;     \\   \n"
                             +"    /usr/local/lib/  , false, 9, true, /usr/lib/"
                +"\n"
               ;
/* SNIPPIT FOR Dox
//! [Man_SourcePathTrimming]
[ALOX]
GLOBAL_SOURCE_PATH_TRIM_RULES= *src.cs/                  , true                ; \
                               /usr/local/lib/  , false, 9, true, /usr/lib/
//! [Man_SourcePathTrimming]
*/
            String fileName= Environment.CurrentDirectory + "/Log_ConfigTrimRules.ini";
            StreamWriter file= new StreamWriter( fileName );
            file.Write( iniFileContents );
            file.Close();

            IniFile iniFile= new IniFile( fileName );
            iniFile.ReadFile();
            //iniFile.WriteFile(); // temporarily enable to see what we have written above

            ALIB.Config.InsertPlugin( iniFile, Configuration.PrioIniFile );

            // test
            Lox lox= new Lox("T_LOX", false );

            lox.SetVerbosity( Lox.CreateConsoleLogger("CONSOLE") , Verbosity.Verbose );
            lox.SetVerbosity( "CONSOLE"                          , Verbosity.Verbose, ALox.InternalDomains );

            MemoryLogger ml= new MemoryLogger("TESTML");

            lox.SetVerbosity(ml, Verbosity.Verbose );

            lox.Info( "" );  UT_EQ("alox.unittests", ml.MemoryLog ); ml.MemoryLog._(); ml.AutoSizes.Reset();

            ALIB.Config.RemovePlugin( iniFile );
            lox.RemoveLogger( ml );
            lox.RemoveLogger( "CONSOLE" );
        }

        // local rule
        clearLox.ClearSourcePathTrimRules( Reach.Global, false);
        ALIB.Config.DefaultValues.Reset();
        {
            // store default values
            Variable var= new Variable();
            var.Define( ALox.ConfigCategoryName, "TESTML_FORMAT" ).Store( "%Sp" );
            var.Define( ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",';')
            .Store( "*;**; *alox.u*, include ;*;**" // default values, 0, ignore"
                                                    // the * will be removed
                                                    // two illegal rules before and after
                                 );

            // test
            Lox lox= new Lox("T_LOX", false );

            lox.SetVerbosity( Lox.CreateConsoleLogger("CONSOLE") , Verbosity.Verbose );
            lox.SetVerbosity( "CONSOLE"                          , Verbosity.Verbose, ALox.InternalDomains );

            MemoryLogger ml= new MemoryLogger("TESTML");

            lox.SetVerbosity(ml, Verbosity.Verbose );

            lox.Info( "" ); UT_EQ( "nittests"  , ml.MemoryLog ); ml.MemoryLog._(); ml.AutoSizes.Reset();

            lox.RemoveLogger( ml );
            lox.RemoveLogger( "CONSOLE" );
        }

        clearLox.ClearSourcePathTrimRules( Reach.Global, false);
        ALIB.Config.DefaultValues.Reset();
        {
            // create iniFile
            IniFile iniFile= new IniFile("*"); // don't read
            Variable var= new Variable();
            iniFile.Store( var.Define( ALox.ConfigCategoryName, "TESTML_FORMAT" ),  "%Sp" );
            iniFile.Store( var.Define( ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",';'),
                           "*alox.u, excl, 2, sens" );

            ALIB.Config.InsertPlugin( iniFile, Configuration.PrioIniFile );


            // test
            Lox lox= new Lox("T_LOX", false );

            lox.SetVerbosity( Lox.CreateConsoleLogger("CONSOLE") , Verbosity.Verbose );
            lox.SetVerbosity( "CONSOLE"                          , Verbosity.Verbose, ALox.InternalDomains );

            MemoryLogger ml= new MemoryLogger("TESTML");

            lox.SetVerbosity(ml, Verbosity.Verbose );

            lox.Info( "" ); UT_EQ( "ox.unittests"  , ml.MemoryLog ); ml.MemoryLog._(); ml.AutoSizes.Reset();

            // overwrite with source priority
            lox.SetSourcePathTrimRule( "*alox.u", Inclusion.Exclude, 0, Case.Ignore, "REPLACE_1/", Reach.Local );
            lox.Info( "" ); UT_EQ( "ox.unittests"  , ml.MemoryLog ); ml.MemoryLog._(); ml.AutoSizes.Reset();
            lox.SetSourcePathTrimRule( "*alox.u", Inclusion.Exclude, 0, Case.Ignore, "REPLACE_2/", Reach.Local, Configuration.PrioProtected );
            lox.Info( "" ); UT_TRUE( ml.MemoryLog.StartsWith( "REPLACE_2/" ) ); ml.MemoryLog._(); ml.AutoSizes.Reset();

            ALIB.Config.RemovePlugin( iniFile );
            lox.RemoveLogger( ml );
            lox.RemoveLogger( "CONSOLE" );
        }

        // ignore case
        clearLox.ClearSourcePathTrimRules( Reach.Global, false);
        ALIB.Config.DefaultValues.Reset();
        {
            // store default values
            Variable var= new Variable();
            var.Define( ALox.ConfigCategoryName, "TESTML_FORMAT" ).Store( "%Sp" );
            var.Define( ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",';')
               .Store( "*aLOX.U, exc, 2, ign"   );


            // test
            Lox lox= new Lox("T_LOX", false );

            lox.SetVerbosity( Lox.CreateConsoleLogger("CONSOLE") , Verbosity.Verbose );
            lox.SetVerbosity( "CONSOLE"                          , Verbosity.Verbose, ALox.InternalDomains );

            MemoryLogger ml= new MemoryLogger("TESTML");

            lox.SetVerbosity(ml, Verbosity.Verbose );

            lox.Info( "" ); UT_EQ( "ox.unittests"  , ml.MemoryLog ); ml.MemoryLog._(); ml.AutoSizes.Reset();

            lox.RemoveLogger( ml );
            lox.RemoveLogger( "CONSOLE" );
        }

        clearLox.ClearSourcePathTrimRules( Reach.Global, false);
        ALIB.Config.DefaultValues.Reset();
        {
            // store default values
            Variable var= new Variable();
            var.Define( ALox.ConfigCategoryName, "TESTML_FORMAT" ).Store( "%Sp" );
            var.Define( ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",';')
               .Store( "*aLOX.U, excl, 2, sens"  );



            // test
            Lox lox= new Lox("T_LOX", false );

            lox.SetVerbosity( Lox.CreateConsoleLogger("CONSOLE") , Verbosity.Verbose );
            lox.SetVerbosity( "CONSOLE"                          , Verbosity.Verbose, ALox.InternalDomains );

            MemoryLogger ml= new MemoryLogger("TESTML");

            lox.SetVerbosity(ml, Verbosity.Verbose );

            lox.Info( "" );
            if( Path.DirectorySeparatorChar == '/' )
                UT_EQ( "src.cs/alox.unittests"  , ml.MemoryLog );
            else
                UT_EQ( "src.cs\\alox.unittests"  , ml.MemoryLog );

            ml.MemoryLog._(); ml.AutoSizes.Reset();
            lox.RemoveLogger( ml );
            lox.RemoveLogger( "CONSOLE" );
        }
    }