public static void TestStringTypes(string sLHS, string sRHS, AzLogFilterCondition.CmpOp cmpop, bool fExpected) { AzLogFilterValue azlfvLHS = new AzLogFilterValue(sLHS); AzLogFilterValue azlfvRHS = new AzLogFilterValue(sRHS); Assert.AreEqual(fExpected, azlfvLHS.FEvaluate(cmpop, azlfvRHS, null)); }
public static void TestCmpOpGenericFromCmpOp(AzLogFilterCondition.CmpOp cmpopIn, AzLogFilterCondition.CmpOp cmpopExpected, bool fNoCaseExpected) { bool fNoCase; Assert.AreEqual(cmpopExpected, AzLogFilterValue.CmpOpGenericFromCmpOp(cmpopIn, out fNoCase)); Assert.AreEqual(fNoCaseExpected, fNoCase); }
public static void TestDateTimeTypes(string sDttmLHS, string sDttmRHS, AzLogFilterCondition.CmpOp cmpop, bool fExpected) { AzLogFilterValue azlfvLHS = new AzLogFilterValue(DateTime.Parse(sDttmLHS)); AzLogFilterValue azlfvRHS = new AzLogFilterValue(DateTime.Parse(sDttmRHS)); Assert.AreEqual(fExpected, azlfvLHS.FEvaluate(cmpop, azlfvRHS, null)); }
/* F E V A L U A T E */ /*---------------------------------------------------------------------------- * %%Function: FEvaluate * %%Qualified: AzLog.AzLogFilter.AzLogFilterValue.FEvaluate * %%Contact: rlittle * * ----------------------------------------------------------------------------*/ public bool FEvaluate(AzLogFilterCondition.CmpOp cmpOp, AzLogFilterValue azlfvRHS, ILogFilterItem ilf) { int nCmp; bool fNoCase; cmpOp = CmpOpGenericFromCmpOp(cmpOp, out fNoCase); if (m_vt != azlfvRHS.m_vt) { throw new Exception("cannot evaluate dissimilar value types"); } if (m_vt == ValueType.String) { nCmp = System.String.Compare(this.String(ilf), azlfvRHS.String(ilf), fNoCase); } else if (m_vt == ValueType.DateTime) { nCmp = DateTime.Compare(this.Dttm(ilf), azlfvRHS.Dttm(ilf)); } else { nCmp = 0; } switch (cmpOp) { case AzLogFilterCondition.CmpOp.Eq: return(nCmp == 0); case AzLogFilterCondition.CmpOp.SEq: return(nCmp == 0); case AzLogFilterCondition.CmpOp.Ne: return(nCmp != 0); case AzLogFilterCondition.CmpOp.SNe: return(nCmp == 0); case AzLogFilterCondition.CmpOp.Gt: return(nCmp > 0); case AzLogFilterCondition.CmpOp.Gte: return(nCmp >= 0); case AzLogFilterCondition.CmpOp.Lt: return(nCmp < 0); case AzLogFilterCondition.CmpOp.Lte: return(nCmp <= 0); } return(false); }
/* C M P O P G E N E R I C F R O M C M P O P */ /*---------------------------------------------------------------------------- * %%Function: CmpOpGenericFromCmpOp * %%Qualified: AzLog.AzLogFilter.AzLogFilterValue.CmpOpGenericFromCmpOp * %%Contact: rlittle * * get the generic compare operation (deals with case insensitive string * variants by filling in fNoCase and returning the appropriate cmpop) * ----------------------------------------------------------------------------*/ private static AzLogFilterCondition.CmpOp CmpOpGenericFromCmpOp(AzLogFilterCondition.CmpOp cmpOp, out bool fNoCase) { fNoCase = (int)cmpOp >= (int)AzLogFilterCondition.CmpOp.SCaseInsensitiveFirst; if (fNoCase) { cmpOp = (AzLogFilterCondition.CmpOp)((int)cmpOp - (int)AzLogFilterCondition.CmpOp.SCaseInsensitiveFirst); } return(cmpOp); }
public static void TestAzLogFilterDateRange(string sDttmRow, AzLogFilterCondition.CmpOp cmpop1, String sCmp1, AzLogFilterCondition.CmpOp cmpop2, string sCmp2, bool fExpected) { AzLogFilter azlf = new AzLogFilter(); TestAzLogFilterValueMock mock = new TestAzLogFilterValueMock(); mock.m_dttmRow = DateTime.Parse(sDttmRow); azlf.Add(new AzLogFilterCondition(AzLogFilterValue.ValueType.DateTime, AzLogFilterValue.DataSource.DttmRow, AzLogEntry.LogColumn.Nil, cmpop1, DateTime.Parse(sCmp1))); azlf.Add(new AzLogFilterCondition(AzLogFilterValue.ValueType.DateTime, AzLogFilterValue.DataSource.DttmRow, AzLogEntry.LogColumn.Nil, cmpop2, DateTime.Parse(sCmp2))); azlf.Add(AzLogFilterOperation.OperationType.And); Assert.AreEqual(fExpected, azlf.FEvaluate(mock)); }