Exemplo n.º 1
0
        public void UT_INIT([CallerMemberName] String method = "")
        {
        #if ALOX_DBG_LOG
            // try to clean up, so that ALib is cleaned as well
            if (Log.DebugLogger != null)
            {
                Log.RemoveDebugLogger();
            }
            if (Log.GetLogger("CONSOLE") != null)
            {
                Log.RemoveLogger("CONSOLE");
            }
            if (Log.GetLogger("MEMORY") != null)
            {
                Log.RemoveLogger("MEMORY");
            }

            if (utWriter.logger.GetType() == typeof(CLRDebuggerLogger))
            {
                UT_EQ(0, ALIB.StdOutputStreamsLock.CntAcquirers());
            }
            else
            {
                UT_EQ(1, ALIB.StdOutputStreamsLock.CntAcquirers());
            }
            UT_EQ(0, ALIB.StdOutputStreamsLock.DbgCountAcquirements(null));

            ALox.Reset();
            Log.SetSourcePathTrimRule("*/src.cs/", Inclusion.Include);
            Log.MapThreadName("UT");
        #endif
            UT_PRINT("################### Unit Test: " + this.GetType().Name + "." + method + "() ###################");
        }
Exemplo n.º 2
0
        /** ****************************************************************************************
         * This is for debugging purposes and for configuration output.
         * E.g. this enables the \e Monodevelop IDE to display object descriptions in the debugger.
         * @returns A human readable string representation of this object.
         ******************************************************************************************/
        public override String ToString()
        {
            tAString._()._(FullPath);
            tAString._('[')._(CntLogCalls, 3)._("] ");

            // get verbosities
            tAString._(" { ");
            for (int i = 0; i < Data.Count; i++)
            {
                LoggerData ld = Data[i];
                tAString._(i != 0 ? ", " : "")
                ._('(')
                ._('[')._(ld.CntLogCalls, 3)._("], ");
                ALox.ToString(ld.LoggerVerbosity, ld.Priority, tAString)
                ._(')');
            }
            return(tAString._(" }").ToString());
        }
Exemplo n.º 3
0
        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"
                + "           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);

            iniFile.ReadFile();
            UT_TRUE((IniFile.Status.OK == iniFile.LastStatus));

            // check some values
            AString sv = new AString();

            iniFile.Get("", "CUBA", sv);   UT_EQ("a country", sv);
            iniFile.Get("", "cUbA", sv);   UT_EQ("a country", sv);
            iniFile.Get("", "SIZE", sv);   UT_EQ("25", sv);
            iniFile.Get("", "concat", sv); UT_TRUE(sv.StartsWith("start =5,end   =32"));

            iniFile.Get("ESC", "Blanks", sv);   UT_EQ(" x ", sv);
            iniFile.Get("ESC", "Blanks2", sv);   UT_EQ(" x  y ", sv);
            iniFile.Get("ESC", "Tabs", sv);   UT_EQ("\tx\t", sv);
            iniFile.Get("ESC", "nrslash", sv);   UT_EQ("\n\r//\\", sv);

            iniFile.Get("Great Section", "SectionVar", sv);   UT_EQ("5", sv);
            iniFile.Get("2nd Section", "SectionVar", sv);   UT_EQ("6", sv);
            iniFile.Get("Great Section", "SECTION_CONTINUED", sv);   UT_EQ("yEs", sv);
            iniFile.Get("Great Section", "Tricky", sv);   UT_EQ("backslash\\", sv);

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


            // check if environment variable "home" overwrites ini-file
            AString vIniFile = new AString();   iniFile.Get("", "hOme", vIniFile);               UT_EQ("overwritten_by_environment", vIniFile);
            AString vConfig  = new AString();
            int     prio     = ALIB.Config.Get("", "hOme", vConfig);

            if (prio != Configuration.PrioEnvVars)  // Windows platform?
            {
                prio = ALIB.Config.Get("", "hOmePAth", vConfig);
                iniFile.Get("", "hOmePAth", vIniFile);      UT_EQ("overwritten_by_environment", vIniFile);
            }
            UT_EQ(Configuration.PrioEnvVars, prio);

            UT_TRUE(vConfig.Length() > 0);
            UT_TRUE(!vIniFile.Equals(vConfig));



            // change a value and write a new one
            UT_EQ(Configuration.PrioIniFile, ALIB.Config.Save("New Section", "newvar", new AString("new")));
            ALIB.Config.Get("New Section", "newvar", sv);   UT_EQ("new", sv);

            UT_EQ(Configuration.PrioIniFile, ALIB.Config.Save("", "newvar", new AString("aworx")));
            ALIB.Config.Get("", "newvar", sv);  UT_EQ("aworx", sv);

            double dv;

            UT_EQ(Configuration.PrioIniFile, ALIB.Config.Save("2nd Section", "newvarF", 3.14));
            ALIB.Config.Get("2nd Section", "newvarF", out dv); UT_EQ(3.14, dv);

            int iv;

            UT_EQ(Configuration.PrioIniFile, ALIB.Config.Save("Great Section", "newvarI", 255));
            ALIB.Config.Get("Great Section", "newvarI", out iv); UT_EQ(255, iv);

            UT_EQ(Configuration.PrioIniFile, ALIB.Config.Save("", "size", 42));
            ALIB.Config.Get("", "size", out iv);                 UT_EQ(42, iv);

            UT_EQ(Configuration.PrioIniFile, ALIB.Config.Save("", "newvarList", new AString("val1=5, val2=10, val3=hello"), null, ','));
            ALIB.Config.Get("", "newvarList", out iv);

            UT_EQ(Configuration.PrioIniFile, ALIB.Config.Save("", "commented", new AString("2lines"), new AString("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());

            readBack.ReadFile();

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

            {
                AString msg = new AString();
                foreach (IniFile.Section section in iniFile.Sections)
                {
                    foreach (IniFile.Variable variable in section.Variables)
                    {
                        readBack.Get(section.Name, variable.Name, sv);
                        msg.Clear()._("Reading variable ").Field()._(section.Name)._('/')._(variable.Name)._(": ");
                        msg.Field(40, Alignment.Left)._(variable.Value)._(" / ")._(sv);
                        UT_PRINT(msg);
                        if (!variable.Name.Equals("newvarList"))
                        {
                            UT_EQ(variable.Value, sv);
                        }
                    }
                }
            }

            readBack.Get("New Section", "newvar", sv);   UT_EQ("new", sv);
            readBack.Get("", "newvar", sv);   UT_EQ("aworx", sv);
            readBack.Get("2nd Section", "newvarF", out dv, null);   UT_EQ(3.14, dv);
            readBack.Get("Great Section", "newvarI", out iv, null);   UT_EQ(255, (int)iv);


            ALIB.Config.RemovePlugin(iniFile);


            ALIB.Config.InsertPlugin(readBack, Configuration.PrioIniFile);
            ALIB.Config.Get("New Section", "newvar", sv);   UT_EQ("new", sv);
            ALIB.Config.Get("", "newvar", sv);   UT_EQ("aworx", sv);
            ALIB.Config.Get("2nd Section", "newvarF", out dv, null);   UT_EQ(3.14, dv);
            ALIB.Config.Get("Great Section", "newvarI", out iv, null);   UT_EQ(255, (int)iv);

            ALIB.Config.RemovePlugin(readBack);
        }