コード例 #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(Inclusion.Include, false);
            {
                // create iniFile
                String iniFileContents =
                    "[ALOX]\n"
                    + "TESTML_FORMAT= \"%Sp\"  \n"

                    + "GLOBAL_SOURCE_PATH_TRIM_RULES=  *src.cs/   , true  ;     \\   \n"
                    + "    /usr/lib/libzip/include/  , false, 9, true"
                    + "\n"
                ;

/* SNIPPIT FOR Dox
 * //! [Man_SourcePathTrimming]
 * [ALOX]
 * GLOBAL_SOURCE_PATH_TRIM_RULES= *src.cs/                  , true                ; \
 *                             /usr/lib/libzip/include/  , false, 9, true
 * //! [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(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",
                             "*;**;*alox.u*, incl ;*;**"   // default values, 0, ignore"
                                                           // the * will be removed
                                                           // two illegal rules before and after
                             );
                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("nittests", ml.MemoryLog); ml.MemoryLog._(); ml.AutoSizes.Reset();

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

            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(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();

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

            // ignore case
            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",
                             "*aLOX.U, exc, 2, ign"
                             );
                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();

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

            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(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("");
                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();
                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }
        }