Exemple #1
0
        public void HmdEnumReferenceInlineTest()
        {
            HmdEnum hmdEnum;

            hmdEnum = new HmdEnum(null, "  \n\n full\t\t  high");
            Assert.IsTrue(hmdEnum.IsValidEnumValue("high"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("HIGH"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("full"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("FuLl"));

            hmdEnum = new HmdEnum(null, "  a1234");
            Assert.IsTrue(hmdEnum.IsValidEnumValue("a1234"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("A1234"));
        }
Exemple #2
0
        public void ValidateHmdEnum(HmdEnum hmdEnum, String name, params String[] values)
        {
            Assert.IsTrue(hmdEnum.name.Equals(name, StringComparison.CurrentCultureIgnoreCase));

            Assert.AreEqual(values.Length, hmdEnum.ValueCount);
            for (int i = 0; i < values.Length; i++)
            {
                Assert.IsTrue(hmdEnum.IsValidEnumValue(values[i]));
            }
        }
Exemple #3
0
        public static void TestPropertyParserInlineEnum(String propertyString, params String[] values)
        {
            HmdValueIDProperties valueIDProperties = CallParserWithDefaults(propertyString, TestPropertyDictionary);

            VerifyValueProperties(String.Empty, valueIDProperties, UnrestrictedCount.Instance, HmdType.Enumeration, "");

            //
            // Verify enum values
            //
            HmdEnumReference hmdEnumReference = valueIDProperties.EnumReference;
            HmdEnum          hmdEnum          = hmdEnumReference.TryGetReference;

            Assert.IsNotNull(hmdEnum);
            for (int i = 0; i < values.Length; i++)
            {
                Assert.IsTrue(hmdEnum.IsValidEnumValue(values[i]));
            }
        }
Exemple #4
0
        public Boolean IsValidValue(String value, HmdProperties hmdProperties)
        {
            switch (hmdType)
            {
            case HmdType.String:
                return(true);

            case HmdType.Boolean:
                return(value.Equals("true", StringComparison.CurrentCultureIgnoreCase) ||
                       value.Equals("false", StringComparison.CurrentCultureIgnoreCase));

            case HmdType.Int:
                return(value.IsValidInteger(false, 4));

            case HmdType.Int1:
                return(value.IsValidInteger(false, 1));

            case HmdType.Int2:
                return(value.IsValidInteger(false, 2));

            case HmdType.Int3:
                return(value.IsValidInteger(false, 3));

            case HmdType.Int4:
                return(value.IsValidInteger(false, 4));

            case HmdType.Int5:
                return(value.IsValidInteger(false, 5));

            case HmdType.Int6:
                return(value.IsValidInteger(false, 6));

            case HmdType.Int7:
                return(value.IsValidInteger(false, 7));

            case HmdType.Int8:
                return(value.IsValidInteger(false, 8));

            case HmdType.Int9:
                return(value.IsValidInteger(false, 9));

            case HmdType.Int10:
                return(value.IsValidInteger(false, 10));

            case HmdType.Int11:
                return(value.IsValidInteger(false, 11));

            case HmdType.Int12:
                return(value.IsValidInteger(false, 12));

            case HmdType.Int13:
                return(value.IsValidInteger(false, 13));

            case HmdType.Int14:
                return(value.IsValidInteger(false, 14));

            case HmdType.Int15:
                return(value.IsValidInteger(false, 15));

            case HmdType.Int16:
                return(value.IsValidInteger(false, 16));

            case HmdType.UInt:
                return(value.IsValidInteger(true, 4));

            case HmdType.UInt1:
                return(value.IsValidInteger(true, 1));

            case HmdType.UInt2:
                return(value.IsValidInteger(true, 2));

            case HmdType.UInt3:
                return(value.IsValidInteger(true, 3));

            case HmdType.UInt4:
                return(value.IsValidInteger(true, 4));

            case HmdType.UInt5:
                return(value.IsValidInteger(true, 5));

            case HmdType.UInt6:
                return(value.IsValidInteger(true, 6));

            case HmdType.UInt7:
                return(value.IsValidInteger(true, 7));

            case HmdType.UInt8:
                return(value.IsValidInteger(true, 8));

            case HmdType.UInt9:
                return(value.IsValidInteger(true, 9));

            case HmdType.UInt10:
                return(value.IsValidInteger(true, 10));

            case HmdType.UInt11:
                return(value.IsValidInteger(true, 11));

            case HmdType.UInt12:
                return(value.IsValidInteger(true, 12));

            case HmdType.UInt13:
                return(value.IsValidInteger(true, 13));

            case HmdType.UInt14:
                return(value.IsValidInteger(true, 14));

            case HmdType.UInt15:
                return(value.IsValidInteger(true, 15));

            case HmdType.UInt16:
                return(value.IsValidInteger(true, 16));

            case HmdType.Decimal:
                throw new NotImplementedException();

            case HmdType.Enumeration:
                HmdEnum hmdEnum = enumReference.TryGetReference;
                if (hmdEnum == null)
                {
                    hmdEnum = hmdProperties.TryGetEnum(enumReference.Name);
                    if (hmdEnum == null)
                    {
                        throw new InvalidOperationException(String.Format("Can't resolve enum reference '{0}'", enumReference.Name));
                    }
                    this.enumReference = hmdEnum;
                }
                return(hmdEnum.IsValidEnumValue(value.Trim()));

            case HmdType.Empty:
                throw new InvalidOperationException("Cannot validate the type of a null type");

            default:
                throw new InvalidOperationException(String.Format("HmdType {0} ({1}) is unrecognized", hmdType, (Int32)hmdType));
            }
        }