|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Project CHIP Authors |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#include "lib/support/logging/TextOnlyLogging.h" |
| 19 | +#include <app/AttributePathExpandIterator-Checked.h> |
| 20 | + |
| 21 | +namespace chip { |
| 22 | +namespace app { |
| 23 | +AttributePathExpandIteratorChecked::AttributePathExpandIteratorChecked(InteractionModel::DataModel * dataModel, |
| 24 | + SingleLinkedListNode<AttributePathParams> * attributePath) : |
| 25 | + mDataModelIterator(dataModel, attributePath), |
| 26 | + mEmberIterator(dataModel, attributePath) |
| 27 | +{ |
| 28 | + CheckOutputsIdentical("Constructor"); |
| 29 | +} |
| 30 | + |
| 31 | +bool AttributePathExpandIteratorChecked::Next() |
| 32 | +{ |
| 33 | + bool dmResult = mDataModelIterator.Next(); |
| 34 | + bool emResult = mEmberIterator.Next(); |
| 35 | + |
| 36 | + CheckOutputsIdentical("Next"); |
| 37 | + |
| 38 | + VerifyOrDie(dmResult == emResult); |
| 39 | + |
| 40 | + return emResult; |
| 41 | +} |
| 42 | + |
| 43 | +bool AttributePathExpandIteratorChecked::Get(ConcreteAttributePath & aPath) |
| 44 | +{ |
| 45 | + CheckOutputsIdentical("Get"); |
| 46 | + return mEmberIterator.Get(aPath); |
| 47 | +} |
| 48 | + |
| 49 | +void AttributePathExpandIteratorChecked::ResetCurrentCluster() |
| 50 | +{ |
| 51 | + mDataModelIterator.ResetCurrentCluster(); |
| 52 | + mEmberIterator.ResetCurrentCluster(); |
| 53 | + |
| 54 | + CheckOutputsIdentical("ResetCurrentCluster"); |
| 55 | +} |
| 56 | + |
| 57 | +void AttributePathExpandIteratorChecked::ResetTo(SingleLinkedListNode<AttributePathParams> * paths) |
| 58 | + |
| 59 | +{ |
| 60 | + mDataModelIterator.ResetTo(paths); |
| 61 | + mEmberIterator.ResetTo(paths); |
| 62 | + CheckOutputsIdentical("ResetTo"); |
| 63 | +} |
| 64 | + |
| 65 | +void AttributePathExpandIteratorChecked::CheckOutputsIdentical(const char * msg) |
| 66 | +{ |
| 67 | + ConcreteAttributePath dmPath; |
| 68 | + ConcreteAttributePath emPath; |
| 69 | + |
| 70 | + bool dmResult = mDataModelIterator.Get(dmPath); |
| 71 | + bool emResult = mEmberIterator.Get(emPath); |
| 72 | + |
| 73 | + if (dmResult == emResult) |
| 74 | + { |
| 75 | + // We check for: |
| 76 | + // - either failed result (in which case path should not matter) |
| 77 | + // - or exact match of paths on success |
| 78 | + // |
| 79 | + // NOTE: extra logic because mExpanded is NOT considered in operator== (ugly...) |
| 80 | + if ((dmResult == false) || ((dmPath == emPath) && (dmPath.mExpanded == emPath.mExpanded))) |
| 81 | + { |
| 82 | + // outputs are identical. All is good |
| 83 | + return; |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + ChipLogProgress(Test, "Different paths in DM vs EMBER (%d and %d) in %s", dmResult, emResult, msg); |
| 88 | + ChipLogProgress(Test, " DM PATH: 0x%X/" ChipLogFormatMEI "/" ChipLogFormatMEI " (%s)", dmPath.mEndpointId, |
| 89 | + ChipLogValueMEI(dmPath.mClusterId), ChipLogValueMEI(dmPath.mAttributeId), |
| 90 | + dmPath.mExpanded ? "EXPANDED" : "NOT expanded"); |
| 91 | + ChipLogProgress(Test, " EMBER PATH: 0x%X/" ChipLogFormatMEI "/" ChipLogFormatMEI " (%s)", emPath.mEndpointId, |
| 92 | + ChipLogValueMEI(emPath.mClusterId), ChipLogValueMEI(emPath.mAttributeId), |
| 93 | + emPath.mExpanded ? "EXPANDED" : "NOT expanded"); |
| 94 | + |
| 95 | + chipDie(); |
| 96 | +} |
| 97 | + |
| 98 | +} // namespace app |
| 99 | +} // namespace chip |
0 commit comments