Esempio n. 1
0
        public void ConfigureConsoleLogging()
        {
            MOCK_ConfigureConsoleLogging((int verbosity, int stream, int color, string timefmt, string fmt) =>
            {
                Assert.Equal((int)Yogi.Verbosity.Info, verbosity);
                Assert.Equal((int)Yogi.Stream.Stderr, stream);
                Assert.Equal(0, (int)color);
                Assert.Null(timefmt);
                Assert.Null(fmt);
                return((int)Yogi.ErrorCode.Ok);
            });

            Yogi.ConfigureConsoleLogging(Yogi.Verbosity.Info, Yogi.Stream.Stderr, false);

            MOCK_ConfigureConsoleLogging((int verbosity, int stream, int color, string timefmt, string fmt) =>
            {
                Assert.Equal((int)Yogi.Verbosity.Trace, verbosity);
                Assert.Equal((int)Yogi.Stream.Stdout, stream);
                Assert.Equal(1, (int)color);
                Assert.Equal("foo", timefmt);
                Assert.Equal("bar", fmt);
                return((int)Yogi.ErrorCode.Ok);
            });

            Yogi.ConfigureConsoleLogging(Yogi.Verbosity.Trace, Yogi.Stream.Stdout, true, "foo", "bar");
        }
Esempio n. 2
0
        public void SetupHookLogging()
        {
            bool called = false;

            Yogi.SetupHookLogging(Yogi.Verbosity.Debug,
                                  (severity, timestamp, tid, file, line, comp, msg) =>
            {
                Assert.IsType <Yogi.Verbosity>(severity);
                Assert.Equal(Yogi.Verbosity.Warning, severity);
                Assert.IsType <Yogi.Timestamp>(timestamp);
                Assert.True(timestamp <= Yogi.CurrentTime);
                Assert.IsType <int>(tid);
                Assert.True(tid > 0);
                Assert.IsType <string>(file);
                Assert.NotEmpty(file);
                Assert.IsType <int>(line);
                Assert.True(line > 0);
                Assert.IsType <string>(comp);
                Assert.NotEmpty(comp);
                Assert.IsType <string>(msg);
                Assert.NotEmpty(msg);
                called = true;
            }
                                  );

            Yogi.AppLogger.Log(Yogi.Verbosity.Warning, "A warning");
            Assert.True(called);
        }
Esempio n. 3
0
        public void Log()
        {
            var logger = new Yogi.Logger("My logger");

            bool called = false;

            Yogi.SetupHookLogging(Yogi.Verbosity.Debug,
                                  (severity, timestamp, tid, file, line, comp, msg) =>
            {
                Assert.Equal(Yogi.Verbosity.Warning, severity);
                Assert.Equal("My logger", comp);
                Assert.Equal("Hey dude", msg);
                Assert.Equal(GetMyFilename(), file);
                Assert.True(line > 0);
                called = true;
            }
                                  );

            logger.Log(Yogi.Verbosity.Warning, "Hey dude");
            Assert.True(called);

            called = false;
            Yogi.SetupHookLogging(Yogi.Verbosity.Debug,
                                  (severity, timestamp, tid, file, line, comp, msg) =>
            {
                Assert.Equal("my file", file);
                Assert.Equal(123, line);
                called = true;
            }
                                  );

            logger.Log(Yogi.Verbosity.Warning, "Hey dude", file: "my file", line: 123);
            Assert.True(called);
        }
Esempio n. 4
0
        public void ConfigureFileLogging()
        {
            MOCK_ConfigureFileLogging((int verbosity, string filename, ref IntPtr genfn, ref int genfnsize,
                                       string timefmt, string fmt) =>
            {
                Assert.Equal((int)Yogi.Verbosity.Info, verbosity);
                Assert.Equal("foo", filename);
                Assert.Null(timefmt);
                Assert.Null(fmt);
                genfn     = helloBytes;
                genfnsize = helloSize;
                return((int)Yogi.ErrorCode.Ok);
            });

            Assert.Equal("hello", Yogi.ConfigureFileLogging(Yogi.Verbosity.Info, "foo"));


            MOCK_ConfigureFileLogging((int verbosity, string filename, ref IntPtr genfn, ref int genfnsize,
                                       string timefmt, string fmt) =>
            {
                Assert.Equal((int)Yogi.Verbosity.Trace, verbosity);
                Assert.Equal("moo", filename);
                Assert.Equal("foo", timefmt);
                Assert.Equal("bar", fmt);
                genfn     = helloBytes;
                genfnsize = helloSize;
                return((int)Yogi.ErrorCode.Ok);
            });

            Assert.Equal("hello", Yogi.ConfigureFileLogging(Yogi.Verbosity.Trace, "moo", "foo", "bar"));
        }
Esempio n. 5
0
        public void RaiseSignal()
        {
            bool called = false;

            Yogi.RaiseSignalFnDelegate fn = () =>
            {
                called = true;
            };

            MOCK_RaiseSignal((int signal, IntPtr sigarg, RaiseSignalFnDelegate fn_, IntPtr userarg) =>
            {
                Assert.Equal((int)Yogi.Signals.Term, signal);
                Assert.NotNull(fn_);
                fn_(sigarg, userarg);
                return((int)Yogi.ErrorCode.Ok);
            });

            Yogi.RaiseSignal(Yogi.Signals.Term, fn);
            Assert.True(called);

            called = false;

            Yogi.RaiseSignalFnDelegate <string> fn2 = (string sigarg) =>
            {
                Assert.Null(sigarg);
                called = true;
            };

            Yogi.RaiseSignal(Yogi.Signals.Term, fn);
            Assert.True(called);
        }
Esempio n. 6
0
        public void ConfigureHookLogging()
        {
            bool called = false;

            Yogi.LogToHookFnDelegate fn = (Yogi.Verbosity severity, Yogi.Timestamp timestamp, int tid, string file,
                                           int line, string comp, string msg) =>
            {
                Assert.Equal(Yogi.Verbosity.Trace, severity);
                Assert.Equal(12345L, timestamp.DurationSinceEpoch.NanosecondsCount);
                Assert.Equal(555, tid);
                Assert.Equal("foo", file);
                Assert.Equal(111, line);
                Assert.Equal("bar", comp);
                Assert.Equal("hello", msg);
                called = true;
            };

            MOCK_ConfigureHookLogging((int verbosity, ConfigureHookLoggingFnDelegate fn_, IntPtr userarg) =>
            {
                Assert.Equal((int)Yogi.Verbosity.Info, verbosity);
                Assert.NotNull(fn_);
                fn_((int)Yogi.Verbosity.Trace, 12345, 555, "foo", 111, "bar", "hello", userarg);
                return((int)Yogi.ErrorCode.Ok);
            });

            Yogi.ConfigureHookLogging(Yogi.Verbosity.Info, fn);
            Assert.True(called);
        }
Esempio n. 7
0
 public void SetupConsoleLogging()
 {
     Yogi.SetupConsoleLogging(Yogi.Verbosity.Info, Yogi.Stream.Stdout, true);
     Yogi.AppLogger.Log(Yogi.Verbosity.Warning, "Warning message");
     Yogi.SetupConsoleLogging(Yogi.Verbosity.Debug, Yogi.Stream.Stdout, false, "%S.%3",
                              "$t - $m");
     Yogi.AppLogger.Log(Yogi.Verbosity.Error, "Error message");
 }
Esempio n. 8
0
        public void Dispose()
        {
            Yogi.DisableConsoleLogging();
            Yogi.DisableHookLogging();
            Yogi.DisableFileLogging();

            GC.Collect();
        }
Esempio n. 9
0
        public void DisableHookLogging()
        {
            MOCK_ConfigureHookLogging((int verbosity, ConfigureHookLoggingFnDelegate fn_, IntPtr userarg) =>
            {
                Assert.Equal((int)Yogi.Verbosity.None, verbosity);
                return((int)Yogi.ErrorCode.Ok);
            });

            Yogi.DisableHookLogging();
        }
Esempio n. 10
0
        public void ConfigureHookLoggingWithNullFn()
        {
            MOCK_ConfigureHookLogging((int verbosity, ConfigureHookLoggingFnDelegate fn, IntPtr userarg) =>
            {
                Assert.Null(fn);
                return((int)Yogi.ErrorCode.Ok);
            });

            Yogi.ConfigureHookLogging(Yogi.Verbosity.Info, null);
        }
Esempio n. 11
0
        public void DisableConsoleLogging()
        {
            MOCK_ConfigureConsoleLogging((int verbosity, int stream, int color, string timefmt, string fmt) =>
            {
                Assert.Equal((int)Yogi.Verbosity.None, verbosity);
                return((int)Yogi.ErrorCode.Ok);
            });

            Yogi.DisableConsoleLogging();
        }
Esempio n. 12
0
        public void DisableFileLogging()
        {
            MOCK_ConfigureFileLogging((int verbosity, string filename, ref IntPtr genfn, ref int genfnsize,
                                       string timefmt, string fmt) =>
            {
                Assert.Equal((int)Yogi.Verbosity.None, verbosity);
                return((int)Yogi.ErrorCode.Ok);
            });

            Yogi.DisableFileLogging();
        }
Esempio n. 13
0
        public void DisableHookLoggingError()
        {
            MOCK_ConfigureHookLogging((int verbosity, ConfigureHookLoggingFnDelegate fn_, IntPtr userarg) =>
            {
                return((int)Yogi.ErrorCode.Unknown);
            });

            Assert.ThrowsAny <Yogi.FailureException>(() =>
            {
                Yogi.DisableHookLogging();
            });
        }
Esempio n. 14
0
        public void DisableConsoleLoggingError()
        {
            MOCK_ConfigureConsoleLogging((int verbosity, int stream, int color, string timefmt, string fmt) =>
            {
                return((int)Yogi.ErrorCode.Unknown);
            });

            Assert.ThrowsAny <Yogi.FailureException>(() =>
            {
                Yogi.DisableConsoleLogging();
            });
        }
Esempio n. 15
0
        public void ConfigureConsoleLoggingError()
        {
            MOCK_ConfigureConsoleLogging((int verbosity, int stream, int color, string timefmt, string fmt) =>
            {
                return((int)Yogi.ErrorCode.Unknown);
            });

            Assert.ThrowsAny <Yogi.FailureException>(() =>
            {
                Yogi.ConfigureConsoleLogging(Yogi.Verbosity.Info, Yogi.Stream.Stderr, false);
            });
        }
Esempio n. 16
0
        public void DisableFileLoggingError()
        {
            MOCK_ConfigureFileLogging((int verbosity, string filename, ref IntPtr genfn, ref int genfnsize,
                                       string timefmt, string fmt) =>
            {
                return((int)Yogi.ErrorCode.Unknown);
            });

            Assert.ThrowsAny <Yogi.FailureException>(() =>
            {
                Yogi.DisableFileLogging();
            });
        }
Esempio n. 17
0
        public void SetupFileLogging()
        {
            var filePrefix = Path.Combine(tempDir, "logfile_%Y_");

            var filename = Yogi.SetupFileLogging(Yogi.Verbosity.Info, filePrefix + "1");

            Assert.DoesNotContain("%Y", filename);
            Assert.True(File.Exists(filename));

            filename = Yogi.SetupFileLogging(Yogi.Verbosity.Info, filePrefix + "2", "%S.%3",
                                             "$t - $m");
            Assert.DoesNotContain("%Y", filename);
            Assert.True(File.Exists(filename));
        }
Esempio n. 18
0
        public void ConfigureHookLoggingError()
        {
            MOCK_ConfigureHookLogging((int verbosity, ConfigureHookLoggingFnDelegate fn_, IntPtr userarg) =>
            {
                return((int)Yogi.ErrorCode.Unknown);
            });

            Yogi.LogToHookFnDelegate fn = (Yogi.Verbosity severity, Yogi.Timestamp timestamp, int tid, string file,
                                           int line, string comp, string msg) =>
            { };

            Assert.ThrowsAny <Yogi.FailureException>(() =>
            {
                Yogi.ConfigureHookLogging(Yogi.Verbosity.Info, fn);
            });
        }
Esempio n. 19
0
        public void RaiseSignalError()
        {
            MOCK_RaiseSignal((int signal, IntPtr sigarg, RaiseSignalFnDelegate fn_, IntPtr userarg) =>
            {
                return((int)Yogi.ErrorCode.Unknown);
            });

            Assert.ThrowsAny <Yogi.FailureException>(() =>
            {
                Yogi.RaiseSignal(Yogi.Signals.Term);
            });

            Assert.ThrowsAny <Yogi.FailureException>(() =>
            {
                Yogi.RaiseSignal(Yogi.Signals.Term, "foo");
            });
        }
Esempio n. 20
0
        public void RaiseSignalNoHandler()
        {
            bool called = false;

            MOCK_RaiseSignal((int signal, IntPtr sigarg, RaiseSignalFnDelegate fn_, IntPtr userarg) =>
            {
                called = true;
                return((int)Yogi.ErrorCode.Ok);
            });

            Yogi.RaiseSignal(Yogi.Signals.Term);
            Assert.True(called);

            called = false;
            Yogi.RaiseSignal(Yogi.Signals.Term, "foo");
            Assert.True(called);
        }
        public void AwaitSignal()
        {
            var sigset = new Yogi.SignalSet(context, Yogi.Signals.Term | Yogi.Signals.Usr5);

            bool called = false;

            sigset.AwaitSignalAsync((res, signal) => {
                Assert.IsType <Yogi.Success>(res);
                Assert.Equal(Yogi.ErrorCode.Ok, res.ErrorCode);
                Assert.Equal(Yogi.Signals.Term, signal);
                called = true;
            });
            GC.Collect();
            Yogi.RaiseSignal(Yogi.Signals.Term, "123");
            GC.Collect();
            context.Poll();
            GC.Collect();
            Assert.True(called);

            called = false;
            sigset.AwaitSignalAsync <string>((res, signal, sigarg) => {
                Assert.IsType <Yogi.Success>(res);
                Assert.Equal(Yogi.ErrorCode.Ok, res.ErrorCode);
                Assert.Equal(Yogi.Signals.Term, signal);
                Assert.Null(sigarg);
                called = true;
            });
            Yogi.RaiseSignal(Yogi.Signals.Term);
            context.Poll();
            Assert.True(called);

            called = false;
            sigset.AwaitSignalAsync <string>((res, signal, sigarg) => {
                Assert.IsType <Yogi.Success>(res);
                Assert.Equal(Yogi.ErrorCode.Ok, res.ErrorCode);
                Assert.Equal(Yogi.Signals.Term, signal);
                Assert.Equal("Hello", sigarg);
                called = true;
            });
            Yogi.RaiseSignal(Yogi.Signals.Term, "Hello");
            context.Poll();
            Assert.True(called);
        }
        public void RaiseSignalCleanupHandler()
        {
            bool called = false;

            Yogi.RaiseSignal(Yogi.Signals.Usr1, () => {
                called = true;
            });
            Assert.True(called);

            called = false;
            Yogi.RaiseSignal <string>(Yogi.Signals.Usr2, null, (sigarg) => {
                Assert.Null(sigarg);
                called = true;
            });
            Assert.True(called);

            called = false;
            Yogi.RaiseSignal(Yogi.Signals.Usr2, "Hello", (sigarg) => {
                Assert.Equal("Hello", sigarg);
                called = true;
            });
            Assert.True(called);
        }
Esempio n. 23
0
        public void GetSchema()
        {
            var scm = Yogi.GetSchema(Yogi.Schema.BranchEvent);

            Assert.NotEmpty(scm);
        }