|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2025 Project CHIP Authors |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +#include <pw_unit_test/framework.h> |
| 20 | + |
| 21 | +#include <app/server/Server.h> |
| 22 | +#include <platform/CHIPDeviceLayer.h> |
| 23 | + |
| 24 | +namespace chip { |
| 25 | + |
| 26 | +using namespace chip::DeviceLayer; |
| 27 | + |
| 28 | +namespace app { |
| 29 | +namespace server { |
| 30 | + |
| 31 | +class TestServer : public ::testing::Test |
| 32 | +{ |
| 33 | +public: |
| 34 | + static void SetUpTestSuite() |
| 35 | + { |
| 36 | + ASSERT_EQ(Platform::MemoryInit(), CHIP_NO_ERROR); |
| 37 | + ASSERT_EQ(PlatformMgr().InitChipStack(), CHIP_NO_ERROR); |
| 38 | + } |
| 39 | + static void TearDownTestSuite() |
| 40 | + { |
| 41 | + Platform::MemoryShutdown(); |
| 42 | + PlatformMgr().Shutdown(); |
| 43 | + } |
| 44 | +}; |
| 45 | + |
| 46 | +class TestEventHandler |
| 47 | +{ |
| 48 | +public: |
| 49 | + ChipDeviceEvent mEvent{}; |
| 50 | + |
| 51 | + static void EventHandler(const ChipDeviceEvent * event, intptr_t arg) |
| 52 | + { |
| 53 | + reinterpret_cast<TestEventHandler *>(arg)->mEvent = *event; |
| 54 | + } |
| 55 | +}; |
| 56 | + |
| 57 | +TEST_F(TestServer, TestFactoryResetEvent) |
| 58 | +{ |
| 59 | + TestEventHandler handler; |
| 60 | + PlatformMgr().AddEventHandler(TestEventHandler::EventHandler, reinterpret_cast<intptr_t>(&handler)); |
| 61 | + |
| 62 | + auto & server = Server::GetInstance(); |
| 63 | + |
| 64 | + server.ScheduleFactoryReset(); |
| 65 | + |
| 66 | + PlatformMgr().ScheduleWork([](intptr_t) -> void { PlatformMgr().StopEventLoopTask(); }, (intptr_t) nullptr); |
| 67 | + PlatformMgr().RunEventLoop(); |
| 68 | + |
| 69 | + EXPECT_EQ(handler.mEvent.Type, DeviceEventType::kFactoryReset); |
| 70 | + |
| 71 | + PlatformMgr().RemoveEventHandler(TestEventHandler::EventHandler, reinterpret_cast<intptr_t>(&handler)); |
| 72 | +} |
| 73 | + |
| 74 | +} // namespace server |
| 75 | +} // namespace app |
| 76 | +} // namespace chip |
0 commit comments