|
14 | 14 | * See the License for the specific language governing permissions and
|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
| 17 | +#include "app/ConcreteCommandPath.h" |
17 | 18 | #include <app/codegen-data-model/CodegenDataModel.h>
|
18 | 19 |
|
19 | 20 | #include <app/codegen-data-model/tests/AttributeReportIBEncodeDecode.h>
|
| 21 | +#include <app/codegen-data-model/tests/EmberInvokeOverride.h> |
20 | 22 | #include <app/codegen-data-model/tests/EmberReadWriteOverride.h>
|
21 | 23 |
|
22 | 24 | #include <access/AccessControl.h>
|
@@ -69,6 +71,9 @@ constexpr NodeId kTestNodeId = 0xFFFF'1234'ABCD'4321;
|
69 | 71 | constexpr AttributeId kAttributeIdReadOnly = 0x3001;
|
70 | 72 | constexpr AttributeId kAttributeIdTimedWrite = 0x3002;
|
71 | 73 |
|
| 74 | +constexpr CommandId kMockCommandId1 = 0x1234; |
| 75 | +constexpr CommandId kMockCommandId2 = 0x1122; |
| 76 | + |
72 | 77 | constexpr EndpointId kEndpointIdThatIsMissing = kMockEndpointMin - 1;
|
73 | 78 |
|
74 | 79 | constexpr AttributeId kReadOnlyAttributeId = 0x5001;
|
@@ -2430,6 +2435,47 @@ TEST(TestCodegenModelViaMocks, EmberWriteAttributeAccessInterfaceTest)
|
2430 | 2435 | TestEmberScalarNullWrite<int64_t, ZCL_INT64S_ATTRIBUTE_TYPE>();
|
2431 | 2436 | }
|
2432 | 2437 |
|
| 2438 | +TEST(TestCodegenModelViaMocks, EmberInvokeTest) |
| 2439 | +{ |
| 2440 | + // Ember invoke is fully code-generated - there is a single function for Dispatch |
| 2441 | + // that will do a `switch` on the path elements and invoke a corresponding `emberAf*` |
| 2442 | + // callback. |
| 2443 | + // |
| 2444 | + // The only thing that can be validated is that this `DispatchSingleClusterCommand` |
| 2445 | + // is actually invoked. |
| 2446 | + |
| 2447 | + UseMockNodeConfig config(gTestNodeConfig); |
| 2448 | + chip::app::CodegenDataModel model; |
| 2449 | + |
| 2450 | + { |
| 2451 | + const ConcreteCommandPath kCommandPath(kMockEndpoint1, MockClusterId(1), kMockCommandId1); |
| 2452 | + const InvokeRequest kInvokeRequest{ .path = kCommandPath }; |
| 2453 | + chip::TLV::TLVReader tlvReader; |
| 2454 | + |
| 2455 | + const uint32_t kDispatchCountPre = chip::Test::DispatchCount(); |
| 2456 | + |
| 2457 | + // Using a handler set to nullptr as it is not used by the impl |
| 2458 | + ASSERT_EQ(model.Invoke(kInvokeRequest, tlvReader, /* handler = */ nullptr), CHIP_NO_ERROR); |
| 2459 | + |
| 2460 | + EXPECT_EQ(chip::Test::DispatchCount(), kDispatchCountPre + 1); // single dispatch |
| 2461 | + EXPECT_EQ(chip::Test::GetLastDispatchPath(), kCommandPath); // for the right path |
| 2462 | + } |
| 2463 | + |
| 2464 | + { |
| 2465 | + const ConcreteCommandPath kCommandPath(kMockEndpoint1, MockClusterId(1), kMockCommandId2); |
| 2466 | + const InvokeRequest kInvokeRequest{ .path = kCommandPath }; |
| 2467 | + chip::TLV::TLVReader tlvReader; |
| 2468 | + |
| 2469 | + const uint32_t kDispatchCountPre = chip::Test::DispatchCount(); |
| 2470 | + |
| 2471 | + // Using a handler set to nullpotr as it is not used by the impl |
| 2472 | + ASSERT_EQ(model.Invoke(kInvokeRequest, tlvReader, /* handler = */ nullptr), CHIP_NO_ERROR); |
| 2473 | + |
| 2474 | + EXPECT_EQ(chip::Test::DispatchCount(), kDispatchCountPre + 1); // single dispatch |
| 2475 | + EXPECT_EQ(chip::Test::GetLastDispatchPath(), kCommandPath); // for the right path |
| 2476 | + } |
| 2477 | +} |
| 2478 | + |
2433 | 2479 | TEST(TestCodegenModelViaMocks, EmberWriteAttributeAccessInterfaceReturningError)
|
2434 | 2480 | {
|
2435 | 2481 | UseMockNodeConfig config(gTestNodeConfig);
|
|
0 commit comments