コード例 #1
0
        bool ParseTimeZone(string timeZone, TimeZoneDescription tz, out string reason)
        {
            if (string.IsNullOrEmpty(timeZone))
            {
                reason = "TimeZone string is null or empty";
                return(false);
            }

            int i = 0;

            reason = string.Empty;

            // find Std
            while (i < timeZone.Length)
            {
                char nextChar = timeZone[i];
                if (nextChar == '+' || nextChar == '-' || Char.IsDigit(nextChar))
                {
                    break;
                }
                i++;
            }
            tz.Std = timeZone.Substring(0, i);

            // std offset
            int nextPartStart = i;

            while (i < timeZone.Length)
            {
                char nextChar = timeZone[i];
                if (nextChar != ':' && nextChar != '+' && nextChar != '-' && !Char.IsDigit(nextChar))
                {
                    break;
                }
                i++;
            }

            string stdOffsetString = timeZone.Substring(nextPartStart, i - nextPartStart);

            Regex regex = new Regex(@"^[-\+]{0,1}\d{1,2}(:\d{1,2}){0,2}$");

            if (!regex.IsMatch(stdOffsetString))
            {
                reason = string.Format("Standart offset part format is incorrect ({0})", stdOffsetString);
                return(false);
            }

            tz.StdOffset = ShortTimeSpan.FromString(stdOffsetString);

            if (!tz.StdOffset.IsValid())
            {
                reason = string.Format("Standart offset is incorrect ({0})", stdOffsetString);
                return(false);
            }

            nextPartStart = i;
            bool noDstOffset = (i == timeZone.Length);

            // Dst
            while (i < timeZone.Length)
            {
                char nextChar = timeZone[i];
                if (nextChar == '+' || nextChar == '-' || Char.IsDigit(nextChar))
                {
                    break;
                }
                if (nextChar == ',')
                {
                    // comman means "no offset"
                    noDstOffset = true;
                    break;
                }
                i++;
            }

            tz.Dst = timeZone.Substring(nextPartStart, i - nextPartStart);

            if (noDstOffset)
            {
                i++;
            }

            nextPartStart = i;
            if (!noDstOffset)
            {
                while (i < timeZone.Length)
                {
                    char nextChar = timeZone[i];
                    if (nextChar != ':' && nextChar != '+' && nextChar != '-' && !Char.IsDigit(nextChar))
                    {
                        break;
                    }
                    i++;
                }
                string dstOffsetString = timeZone.Substring(nextPartStart, i - nextPartStart);

                if (!regex.IsMatch(dstOffsetString))
                {
                    reason = string.Format("DST offset part format is incorrect ({0})", dstOffsetString);
                    return(false);
                }

                tz.DstOffset = ShortTimeSpan.FromString(dstOffsetString);

                if (!tz.DstOffset.IsValid())
                {
                    reason = string.Format("DST offset is incorrect ({0})", dstOffsetString);
                    return(false);
                }

                nextPartStart = i;
            }
            else
            {
                tz.DstOffset = new ShortTimeSpan(tz.StdOffset.Hour - 1,
                                                 tz.StdOffset.Minute,
                                                 tz.StdOffset.Second);

                tz.DstOffset.OriginalString =
                    string.Format("{0}:{1}:{2}",
                                  tz.DstOffset.Hour.ToString("00"),
                                  tz.DstOffset.Minute.ToString("00"),
                                  tz.DstOffset.Second.ToString("00"));
            }

            bool noStartTime = (i >= timeZone.Length);

            while (i < timeZone.Length)
            {
                char nextChar = timeZone[i];
                if (nextChar == '/' || nextChar == ',')
                {
                    noStartTime = (nextChar == ',');
                    break;
                }
                i++;
            }

            if (!noStartTime)
            {
                tz.Start = timeZone.Substring(nextPartStart, i - nextPartStart);

                if (!IsValidTimeZoneDay(tz.Start))
                {
                    reason = string.Format("Start part format is incorrect ({0})", tz.Start);
                    return(false);
                }
            }

            i++;
            nextPartStart = i;

            if (!noStartTime)
            {
                while (i < timeZone.Length)
                {
                    char nextChar = timeZone[i];
                    if (nextChar == ',')
                    {
                        break;
                    }
                    i++;
                }

                string startTimeString = timeZone.Substring(nextPartStart, i - nextPartStart);

                if (!regex.IsMatch(startTimeString))
                {
                    reason = string.Format("Start time part format is incorrect ({0})", startTimeString);
                    return(false);
                }

                tz.StartTime = ShortTimeSpan.FromString(startTimeString);

                if (!tz.StdOffset.IsValid())
                {
                    reason = string.Format("Start time is incorrect ({0})", startTimeString);
                    return(false);
                }

                i++;
                nextPartStart = i;
            }
            else
            {
                tz.StartTime = new ShortTimeSpan(2, 0, 0);
                tz.StartTime.OriginalString = "02:00:00";
            }

            bool noEndTime = (i > timeZone.Length);

            while (i < timeZone.Length)
            {
                char nextChar = timeZone[i];
                if (nextChar == '/' || nextChar == ',')
                {
                    noEndTime = (nextChar == ',');
                    break;
                }
                i++;
            }

            if (!noEndTime)
            {
                tz.End = timeZone.Substring(nextPartStart, i - nextPartStart);
                if (!IsValidTimeZoneDay(tz.End))
                {
                    reason = string.Format("End part format is incorrect ({0})", tz.End);
                    return(false);
                }
            }

            i++;
            if (i > timeZone.Length)
            {
                noEndTime = true;
            }

            nextPartStart = i;

            if (!noEndTime)
            {
                while (i < timeZone.Length)
                {
                    char nextChar = timeZone[i];
                    if (nextChar == ',')
                    {
                        break;
                    }
                    i++;
                }

                string endTimeString = timeZone.Substring(nextPartStart, i - nextPartStart);

                if (!regex.IsMatch(endTimeString))
                {
                    reason = string.Format("End time part format is incorrect ({0})", endTimeString);
                    return(false);
                }

                tz.EndTime = ShortTimeSpan.FromString(endTimeString);

                if (!tz.StdOffset.IsValid())
                {
                    reason = string.Format("End time is incorrect ({0})", endTimeString);
                    return(false);
                }
            }
            else
            {
                tz.EndTime = new ShortTimeSpan(2, 0, 0);
                tz.EndTime.OriginalString = "02:00:00";
            }

            return(true);
        }
コード例 #2
0
        void ValidateTimeZone(string expected, string actual)
        {
            BeginStep("Validate TimeZone");

            string reason;

            TimeZoneDescription expectedDescription = new TimeZoneDescription();

            ParseTimeZone(expected, expectedDescription, out reason);

            TimeZoneDescription actualDescription = new TimeZoneDescription();
            bool bParseOk = ParseTimeZone(actual, actualDescription, out reason);

            if (!bParseOk)
            {
                throw new AssertException(string.Format("Time zone format is not correct: {0}", reason));
            }

            // STD
            bool bAllEquals = (string.Compare(expectedDescription.Std, actualDescription.Std, true) == 0);

            LogStepEvent(string.Format("Standart time: expected - {0}, actual - {1}", expectedDescription.Std, actualDescription.Std));

            // STD OFFSET
            bool bEquals = (expectedDescription.StdOffset.Equals(actualDescription.StdOffset));

            LogStepEvent(string.Format("Standart time offset: expected - {0}, actual - {1}",
                                       expectedDescription.StdOffset.OriginalString,
                                       actualDescription.StdOffset.OriginalString));

            bAllEquals = bAllEquals && bEquals;

            // DST
            LogStepEvent(string.Format("DST time: expected - {0}, actual - {1}", expectedDescription.Dst, actualDescription.Dst));

            bEquals = (string.Compare(expectedDescription.Std, actualDescription.Std, true) == 0);

            bAllEquals = bAllEquals && bEquals;

            // DST OFFSET

            LogStepEvent(string.Format("DST time offset: expected - {0}, actual - {1}",
                                       expectedDescription.DstOffset.OriginalString,
                                       actualDescription.DstOffset.OriginalString));

            bEquals = (expectedDescription.DstOffset.Equals(actualDescription.DstOffset));

            bAllEquals = bAllEquals && bEquals;

            // START

            LogStepEvent(string.Format("End: expected - {0}, actual - {1}", expectedDescription.Start, actualDescription.Start));

            bEquals = TimeZoneDaysEqual(expectedDescription.Start, actualDescription.Start);

            bAllEquals = bAllEquals && bEquals;

            // START TIME

            LogStepEvent(string.Format("Start time: expected - {0}, actual - {1}",
                                       expectedDescription.StartTime.OriginalString,
                                       actualDescription.StartTime.OriginalString));

            bEquals = (expectedDescription.StartTime.Equals(actualDescription.StartTime));

            bAllEquals = bAllEquals && bEquals;


            // END

            LogStepEvent(string.Format("End: expected - {0}, actual - {1}", expectedDescription.End, actualDescription.End));

            bEquals = TimeZoneDaysEqual(expectedDescription.End, actualDescription.End);

            bAllEquals = bAllEquals && bEquals;

            // END TIME

            LogStepEvent(string.Format("End time: expected - {0}, actual - {1}",
                                       expectedDescription.EndTime.OriginalString,
                                       actualDescription.EndTime.OriginalString));

            bEquals = (expectedDescription.EndTime.Equals(actualDescription.EndTime));

            bAllEquals = bAllEquals && bEquals;

            if (!bAllEquals)
            {
                throw new AssertException("Time zone differs from one was set");
            }

            StepPassed();
        }
コード例 #3
0
        public void GetSystemDateTimeTest()
        {
            RunTest(() =>
            {
                SystemDateTime dateTime = GetSystemDateAndTime();

                Assert(dateTime != null, "Date and time settings not found",
                       "Check that DUT returned date and time settings");

                if (dateTime.TimeZone != null)
                {
                    TimeZoneDescription actualDescription = new TimeZoneDescription();
                    string reason;
                    bool bParseOk = ParseTimeZone(dateTime.TimeZone.TZ, actualDescription, out reason);
                    Assert(bParseOk, string.Format("Time zone format is not correct: {0}", reason),
                           "Validate TimeZone string", string.Format("TimeZone: {0}", dateTime.TimeZone.TZ));
                }
                else
                {
                    WriteStep("Validate TimeZone", "TimeZone is null");
                }

                bool bCorrect = true;

                //
                // ToDo : UTCDateTime should be mandatory for SetDateTimeType.Manual
                // (Release notes to Core Specification 2.0 - Errata)
                //
                //
                //
                string dump = null;
                if (dateTime.DateTimeType == SetDateTimeType.Manual)
                {
                    bCorrect = (dateTime.UTCDateTime != null);
                    dump     = string.Format("DateTimeType: Manual; LocalDateTime: {0}; UTCDateTime: {1}",
                                             dateTime.LocalDateTime == null ? "NOT PRESENT" : "PRESENT",
                                             dateTime.UTCDateTime == null ? "NOT PRESENT" : "PRESENT");
                }
                else
                {
                    dump = "DateTimeType: NTP";
                }

                Assert(bCorrect, "DateTimeType is Manual but UTCDateTime is not set", "Check if settings are self-consistent", dump);

                if (dateTime.LocalDateTime != null)
                {
                    string errorMessage;
                    bool bDateTimeValid = dateTime.LocalDateTime.IsValidDateTime("LocalDateTime", out errorMessage);
                    Assert(bDateTimeValid, errorMessage, "Validate LocalDateTime");
                }
                else
                {
                    WriteStep("Validate LocalDateTime", "LocalDateTime is NULL");
                }

                // UTCDateTime  must be not null (Core Spec 2.0)
                if (dateTime.UTCDateTime != null)
                {
                    string errorMessage;
                    bool bDateTimeValid = dateTime.UTCDateTime.IsValidDateTime("UTCDateTime", out errorMessage);
                    Assert(bDateTimeValid, errorMessage, "Validate UTCDateTime");
                }
                else
                {
                    WriteStep("Validate UTCDateTime", "UTCDateTime is NULL");
                }
            });
        }
コード例 #4
0
        public void SetSystemDateTimeInvalidDateTimeTest()
        {
            RunTest(() =>
            {
                SystemDateTime testDateTimeSettins = new SystemDateTime();
                Proxies.Device.DateTime dateTime   = new Proxies.Device.DateTime();

                Proxies.Device.TimeZone timeZone = new Proxies.Device.TimeZone();

                timeZone.TZ = "PST8PDT,M3.2.0,M11.1.0";

                dateTime.Date = new Date();
                dateTime.Time = new Time();

                dateTime.Date.Day   = 32;
                dateTime.Date.Month = 13;
                dateTime.Date.Year  = 2001;

                dateTime.Time.Hour   = 25;
                dateTime.Time.Minute = 65;
                dateTime.Time.Second = 70;

                testDateTimeSettins.DateTimeType    = SetDateTimeType.Manual;
                testDateTimeSettins.DaylightSavings = false;
                testDateTimeSettins.TimeZone        = timeZone;
                testDateTimeSettins.UTCDateTime     = dateTime;

                bool fault    = false;
                string reason = "The DUT did not return SOAP FAULT";
                try
                {
                    SetSystemDateAndTime(testDateTimeSettins);
                }
                catch (FaultException exc)
                {
                    string faultDump;
                    fault = exc.IsValidOnvifFault("Sender/InvalidArgVal/InvalidDateTime", out faultDump);
                    if (!fault)
                    {
                        reason = string.Format("The SOAP FAULT returned from the DUT is invalid: {0}", faultDump);
                    }
                    SaveStepFault(exc);
                    StepPassed();
                }

                Assert(fault, reason, "Verify that correct SOAP FAULT is returned");

                SystemDateTime actualDateTime = GetSystemDateAndTime();

                Assert(actualDateTime != null, "Date and time settings not found",
                       "Check that DUT returned date and time settings");

                //Assert(actualDateTime.TimeZone != null, "The DUT did not return TimeZone settings",
                //       "Check that DUT returned TimeZone settings");

                //ValidateTimeZone(testDateTimeSettins.TimeZone.TZ, actualDateTime.TimeZone.TZ);

                if (actualDateTime.TimeZone != null)
                {
                    TimeZoneDescription actualDescription = new TimeZoneDescription();
                    string tzdump;
                    bool bParseOk = ParseTimeZone(actualDateTime.TimeZone.TZ, actualDescription, out tzdump);
                    Assert(bParseOk, string.Format("Time zone format is not correct: {0}", tzdump),
                           "Validate TimeZone string", string.Format("TimeZone: {0}", actualDateTime.TimeZone.TZ));
                }
                else
                {
                    WriteStep("Validate TimeZone", "TimeZone is null");
                }

                bool bCorrect = true;
                string dump   = null;

                if (actualDateTime.DateTimeType == SetDateTimeType.Manual)
                {
                    bCorrect = (actualDateTime.UTCDateTime != null);
                    dump     = string.Format("DateTimeType: Manual; LocalDateTime: {0}; UTCDateTime: {1}",
                                             actualDateTime.LocalDateTime == null ? "NOT PRESENT" : "PRESENT",
                                             actualDateTime.UTCDateTime == null ? "NOT PRESENT" : "PRESENT");
                }
                else
                {
                    dump = "DateTimeType: NTP";
                }

                Assert(bCorrect, "DateTimeType is Manual but UTCDateTime is not set", "Check if settings are self-consistent", dump);

                if (actualDateTime.LocalDateTime != null)
                {
                    string errorMessage;
                    bool bDateTimeValid = actualDateTime.LocalDateTime.IsValidDateTime("LocalDateTime", out errorMessage);
                    Assert(bDateTimeValid, errorMessage, "Validate LocalDateTime");
                }
                else
                {
                    WriteStep("Validate LocalDateTime", "LocalDateTime is NULL");
                }

                if (actualDateTime.UTCDateTime != null)
                {
                    string errorMessage;
                    bool bDateTimeValid = actualDateTime.UTCDateTime.IsValidDateTime("UTCDateTime", out errorMessage);
                    Assert(bDateTimeValid, errorMessage, "Validate UTCDateTime");
                }
                else
                {
                    WriteStep("Validate UTCDateTime", "UTCDateTime is NULL");
                }
            });
        }
コード例 #5
0
        public void SetSystemDateTimeInvalidDateTimeTest()
        {
            RunTest(
                () =>
            {
                Proxies.Onvif.DateTime dateTime = new Proxies.Onvif.DateTime();

                Proxies.Onvif.TimeZone timeZone = new Proxies.Onvif.TimeZone();

                timeZone.TZ = "PST8PDT,M3.2.0,M11.1.0";

                dateTime.Date = new Date();
                dateTime.Time = new Time();

                dateTime.Date.Day   = 32;
                dateTime.Date.Month = 13;
                dateTime.Date.Year  = 2001;

                dateTime.Time.Hour   = 25;
                dateTime.Time.Minute = 65;
                dateTime.Time.Second = 70;

                RunStep(() => { Client.SetSystemDateAndTime(SetDateTimeType.Manual, true, timeZone, dateTime); },
                        "Set system date and time - negative test",
                        "Sender/InvalidArgVal/InvalidDateTime", false);


                SystemDateTime actualDateTime = GetSystemDateAndTime();

                Assert(actualDateTime != null, "Date and time settings not found",
                       "Check that DUT returned date and time settings");

                //Assert(actualDateTime.TimeZone != null, "The DUT did not return TimeZone settings",
                //       "Check that DUT returned TimeZone settings");

                //ValidateTimeZone(testDateTimeSettins.TimeZone.TZ, actualDateTime.TimeZone.TZ);

                if (actualDateTime.TimeZone != null)
                {
                    TimeZoneDescription actualDescription = new TimeZoneDescription();
                    string tzdump;
                    bool bParseOk = ParseTimeZone(actualDateTime.TimeZone.TZ, actualDescription, out tzdump);
                    Assert(bParseOk, string.Format("Time zone format is not correct: {0}", tzdump),
                           "Validate TimeZone string", string.Format("TimeZone: {0}", actualDateTime.TimeZone.TZ));
                }
                else
                {
                    WriteStep("Validate TimeZone", "TimeZone is null");
                }

                bool bCorrect = true;
                string dump   = null;

                if (actualDateTime.DateTimeType == SetDateTimeType.Manual)
                {
                    bCorrect = (actualDateTime.UTCDateTime != null);
                    dump     = string.Format("DateTimeType: Manual; LocalDateTime: {0}; UTCDateTime: {1}",
                                             actualDateTime.LocalDateTime == null ? "NOT PRESENT" : "PRESENT",
                                             actualDateTime.UTCDateTime == null ? "NOT PRESENT" : "PRESENT");
                }
                else
                {
                    dump = "DateTimeType: NTP";
                }

                Assert(bCorrect, "DateTimeType is Manual but UTCDateTime is not set", "Check if settings are self-consistent", dump);

                if (actualDateTime.LocalDateTime != null)
                {
                    string errorMessage;
                    bool bDateTimeValid = actualDateTime.LocalDateTime.IsValidDateTime("LocalDateTime", out errorMessage);
                    Assert(bDateTimeValid, errorMessage, "Validate LocalDateTime");
                }
                else
                {
                    WriteStep("Validate LocalDateTime", "LocalDateTime is NULL");
                }

                if (actualDateTime.UTCDateTime != null)
                {
                    string errorMessage;
                    bool bDateTimeValid = actualDateTime.UTCDateTime.IsValidDateTime("UTCDateTime", out errorMessage);
                    Assert(bDateTimeValid, errorMessage, "Validate UTCDateTime");
                }
                else
                {
                    WriteStep("Validate UTCDateTime", "UTCDateTime is NULL");
                }
            },
                () =>
            {
                // set current time
                SetCurrentTime();
            });
        }