Test : Added testcases in nfa_wlc_act_test.cc, nfa_wlc_api_test.cc, nfa_wlc_main_test.cc
Bug: 371103644
Test: atest libnfc-nci-tests
Change-Id: Ieee68ea0738b81950197e03d30b19ca9c7deab28
diff --git a/libnfc-nci/tests/Android.bp b/libnfc-nci/tests/Android.bp
index 71a9bc2..c4b7211 100644
--- a/libnfc-nci/tests/Android.bp
+++ b/libnfc-nci/tests/Android.bp
@@ -20,6 +20,7 @@
"packages/modules/Nfc/libnfc-nci/src/nfa/ce",
"packages/modules/Nfc/libnfc-nci/src/nfa/dm",
"packages/modules/Nfc/libnfc-nci/src/nfa/hci",
+ "packages/modules/Nfc/libnfc-nci/src/nfa/wlc",
"packages/modules/Nfc/libnfc-nci/src/nfc/tags",
],
cflags: [
diff --git a/libnfc-nci/tests/src/nfa_wlc_act_test.cc b/libnfc-nci/tests/src/nfa_wlc_act_test.cc
new file mode 100644
index 0000000..19400b3
--- /dev/null
+++ b/libnfc-nci/tests/src/nfa_wlc_act_test.cc
@@ -0,0 +1,70 @@
+//
+// Copyright (C) 2025 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "nfa_dm_int.h"
+#include "nfa_rw_int.h"
+#include "nfa_wlc_api.h"
+#include "nfa_wlc_int.h"
+#include "nfc_api.h"
+#include "nfc_int.h"
+
+extern tNFC_CB nfc_cb;
+extern tNFA_WLC_CB nfa_wlc_cb;
+extern tNFA_DM_CB nfa_dm_cb;
+extern tNFA_RW_CB nfa_rw_cb;
+
+static void mock_callback(__attribute__((unused)) tNFA_WLC_EVT event,
+ __attribute__((unused)) tNFA_WLC_EVT_DATA* p_data) {}
+
+TEST(NfaWlcActTest, WlcEnable) {
+ tNFA_WLC_MSG p_data;
+ p_data.enable.p_wlc_cback = mock_callback;
+ EXPECT_TRUE(nfa_wlc_enable(&p_data));
+}
+
+TEST(NfaWlcActTest, WlcStart) {
+ tNFA_WLC_MSG p_data;
+ p_data.start.mode = NFA_WLC_AUTONOMOUS;
+ EXPECT_FALSE(nfa_wlc_start(&p_data));
+ p_data.start.mode = NFA_WLC_NON_AUTONOMOUS;
+ EXPECT_FALSE(nfa_wlc_start(&p_data));
+ nfc_cb.nci_features = NCI_POLL_REMOVAL_DETECTION;
+ nfa_wlc_cb.flags = NFA_WLC_FLAGS_NON_AUTO_MODE_ENABLED;
+ EXPECT_FALSE(nfa_wlc_start(&p_data));
+ nfa_wlc_cb.flags &= ~NFA_WLC_FLAGS_NON_AUTO_MODE_ENABLED;
+ nfa_dm_cb.disc_cb.disc_state = NFA_DM_RFST_LISTEN_ACTIVE;
+ EXPECT_FALSE(nfa_wlc_start(&p_data));
+ nfa_dm_cb.disc_cb.disc_state = NFA_DM_RFST_POLL_ACTIVE;
+ nfa_rw_cb.protocol = NFC_PROTOCOL_UNKNOWN;
+ EXPECT_FALSE(nfa_wlc_start(&p_data));
+ nfa_rw_cb.protocol = NFA_PROTOCOL_ISO_DEP;
+ nfa_rw_cb.flags = NFA_RW_FL_API_BUSY;
+ EXPECT_FALSE(nfa_wlc_start(&p_data));
+ nfa_rw_cb.flags &= ~NFA_RW_FL_API_BUSY;
+ nfa_dm_cb.disc_cb.disc_flags = NFA_DM_DISC_FLAGS_DISABLING;
+ EXPECT_FALSE(nfa_wlc_start(&p_data));
+ nfa_dm_cb.disc_cb.disc_flags &=
+ ~(NFA_DM_DISC_FLAGS_W4_RSP | NFA_DM_DISC_FLAGS_W4_NTF |
+ NFA_DM_DISC_FLAGS_STOPPING | NFA_DM_DISC_FLAGS_DISABLING);
+ EXPECT_TRUE(nfa_wlc_start(&p_data));
+}
+
+TEST(NfaWlcActTest, WlcNonAutoStartWpt) {
+ tNFA_WLC_MSG p_data;
+ EXPECT_TRUE(nfa_wlc_non_auto_start_wpt(&p_data));
+}
\ No newline at end of file
diff --git a/libnfc-nci/tests/src/nfa_wlc_api_test.cc b/libnfc-nci/tests/src/nfa_wlc_api_test.cc
new file mode 100644
index 0000000..d6cb4cb
--- /dev/null
+++ b/libnfc-nci/tests/src/nfa_wlc_api_test.cc
@@ -0,0 +1,50 @@
+//
+// Copyright (C) 2025 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#include "nfa_wlc_api.h"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "nfa_wlc_int.h"
+
+static void mock_callback(__attribute__((unused)) tNFA_WLC_EVT event,
+ __attribute__((unused)) tNFA_WLC_EVT_DATA* p_data) {}
+
+TEST(NfaWlcApiTest, WlcEnable) {
+ EXPECT_EQ(NFA_WlcEnable(nullptr), NFA_STATUS_FAILED);
+ EXPECT_EQ(NFA_WlcEnable(mock_callback), NFA_STATUS_OK);
+}
+
+TEST(NfaWlcApiTest, WlcStart) {
+ tNFA_WLC_MODE mode;
+ mode = 1;
+ EXPECT_EQ(NFA_WlcStart(mode), NFA_STATUS_INVALID_PARAM);
+ mode = 0;
+ EXPECT_EQ(NFA_WlcStart(mode), NFA_STATUS_OK);
+}
+
+TEST(NfaWlcApiTest, WlcStartWPT) {
+ uint8_t power_adj_req;
+ uint8_t wpt_time_int;
+ power_adj_req = 0x15;
+ wpt_time_int = 0;
+ EXPECT_FALSE(NFA_WlcStartWPT(power_adj_req, wpt_time_int));
+ power_adj_req = POWER_ADJ_REQ_DEC_MIN;
+ wpt_time_int = 0x14;
+ EXPECT_FALSE(NFA_WlcStartWPT(power_adj_req, wpt_time_int));
+ wpt_time_int = WPT_DURATION_INT_MAX;
+ EXPECT_EQ(NFA_WlcStartWPT(power_adj_req, wpt_time_int), NFA_STATUS_OK);
+}
\ No newline at end of file
diff --git a/libnfc-nci/tests/src/nfa_wlc_main_test.cc b/libnfc-nci/tests/src/nfa_wlc_main_test.cc
new file mode 100644
index 0000000..40b30d6
--- /dev/null
+++ b/libnfc-nci/tests/src/nfa_wlc_main_test.cc
@@ -0,0 +1,50 @@
+//
+// Copyright (C) 2025 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#include "nfa_wlc_main.cc"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "nfa_wlc_api.h"
+#include "nfa_wlc_int.h"
+
+static void mock_callback(__attribute__((unused)) tNFA_WLC_EVT event,
+ __attribute__((unused)) tNFA_WLC_EVT_DATA* p_data) {}
+
+class NfaWlcMainTest : public ::testing::Test {
+ protected:
+ void SetUp() override { nfa_wlc_init(); }
+};
+
+TEST_F(NfaWlcMainTest, EventNotify) {
+ tNFA_WLC_EVT_DATA wlc_cback_data;
+ nfa_wlc_cb.p_wlc_cback = mock_callback;
+ nfa_wlc_event_notify(NFA_WLC_START_RESULT_EVT, &wlc_cback_data);
+}
+TEST_F(NfaWlcMainTest, EventHandle) {
+ NFC_HDR p_msg;
+ p_msg.event = 0xFF;
+ EXPECT_TRUE(nfa_wlc_handle_event(&p_msg));
+}
+TEST_F(NfaWlcMainTest, Disable) { nfa_wlc_sys_disable(); }
+TEST_F(NfaWlcMainTest, EvtToStr) {
+ EXPECT_EQ(nfa_wlc_evt_2_str(NFA_WLC_API_ENABLE_EVT),
+ "NFA_WLC_API_ENABLE_EVT");
+ EXPECT_EQ(nfa_wlc_evt_2_str(NFA_WLC_API_START_EVT), "NFA_WLC_API_START_EVT");
+ EXPECT_EQ(nfa_wlc_evt_2_str(NFA_WLC_API_NON_AUTO_START_WPT_EVT),
+ "NFA_WLC_API_NON_AUTO_START_WPT_EVT");
+ EXPECT_EQ(nfa_wlc_evt_2_str(NFA_WLC_API_REMOVE_EP_EVT), "Unknown");
+}
\ No newline at end of file